From 0e9b6603d4ae9d11c1fbc90257ce816c5807b8ff Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 28 十月 2022 16:55:02 +0800 Subject: [PATCH] 批量添加结算消息 --- app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetRecordServiceImpl.java | 150 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 139 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetRecordServiceImpl.java b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetRecordServiceImpl.java index 86d6371..aad4516 100644 --- a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetRecordServiceImpl.java +++ b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornGetRecordServiceImpl.java @@ -2,10 +2,13 @@ import com.yeshi.makemoney.app.dao.goldcorn.GoldCornGetRecordDao; import com.yeshi.makemoney.app.dao.goldcorn.GoldCornGetRecordDao.DaoQuery; +import com.yeshi.makemoney.app.entity.SystemEnum; import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord; +import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType; import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetRecordException; import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService; import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetRecordQuery; +import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; @@ -14,9 +17,13 @@ import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; +import org.yeshi.utils.TimeUtil; +import org.yeshi.utils.statistic.BaseStatisticTimeQuery; +import org.yeshi.utils.statistic.StatisticNumberResult; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; @Service public class GoldCornGetRecordServiceImpl implements GoldCornGetRecordService { @@ -24,13 +31,21 @@ @Resource private GoldCornGetRecordDao goldCornGetRecordDao; - @Override - public List<GoldCornGetRecord> list(GoldCornGetRecordQuery goldCornGetRecordQuery, int page, int pageSize) { + private DaoQuery createDaoQuery(GoldCornGetRecordQuery goldCornGetRecordQuery) { DaoQuery daoQuery = new DaoQuery(); daoQuery.type = goldCornGetRecordQuery.getType(); daoQuery.uid = goldCornGetRecordQuery.getUid(); + daoQuery.day = goldCornGetRecordQuery.getDay(); + daoQuery.doubles = goldCornGetRecordQuery.getDoubles(); + daoQuery.dayList = goldCornGetRecordQuery.getDayList(); daoQuery.minCreateTime = goldCornGetRecordQuery.toStartTime(); daoQuery.maxCreateTime = goldCornGetRecordQuery.toEndTime(); + return daoQuery; + } + + @Override + public List<GoldCornGetRecord> list(GoldCornGetRecordQuery goldCornGetRecordQuery, int page, int pageSize) { + DaoQuery daoQuery = createDaoQuery(goldCornGetRecordQuery); daoQuery.start = (page - 1) * pageSize; daoQuery.count = pageSize; @@ -40,11 +55,7 @@ @Override public long count(GoldCornGetRecordQuery goldCornGetRecordQuery) { - DaoQuery daoQuery = new DaoQuery(); - daoQuery.type = goldCornGetRecordQuery.getType(); - daoQuery.uid = goldCornGetRecordQuery.getUid(); - daoQuery.minCreateTime = goldCornGetRecordQuery.toStartTime(); - daoQuery.maxCreateTime = goldCornGetRecordQuery.toEndTime(); + DaoQuery daoQuery = createDaoQuery(goldCornGetRecordQuery); return goldCornGetRecordDao.count(daoQuery); } @@ -84,13 +95,14 @@ } @Override - public Long getGoldCornByDay(Long uid, String day) { + public Long getGoldCornByDay(Long uid, Date day) { List<Criteria> andList = new ArrayList<>(); if (uid != null) { andList.add(Criteria.where("uid").is(uid)); } + if (day != null) { - andList.add(Criteria.where("day").is(day)); + andList.add(Criteria.where("day").is(GoldCornUtil.getFormatDay(day))); } Criteria[] ands = new Criteria[andList.size()]; @@ -135,6 +147,9 @@ @Override public Map<Long, Integer> sumGoldCornByFromUids(Long uid, List<Long> fromUidList, String day) { + if (fromUidList == null || fromUidList.size() == 0) { + return new HashMap<>(); + } Criteria[] ands = new Criteria[3]; ands[0] = Criteria.where("day").is(day); ands[1] = Criteria.where("uid").is(uid); @@ -143,7 +158,7 @@ for (int i = 0; i < ors.length; i++) { ors[i] = Criteria.where("fromUid").is(fromUidList.get(i)); } - ands[3] = new Criteria().orOperator(ors); + ands[2] = new Criteria().orOperator(ors); List<AggregationOperation> list = new ArrayList<>(); list.add(Aggregation.match(new Criteria().andOperator(ands))); @@ -153,11 +168,124 @@ Map<Long, Integer> map = new HashMap<>(); if (mapList != null) { for (Map m : mapList) { - map.put((long) m.get("fromUid"), (int) m.get("cornNum")); + map.put((long) m.get("_id"), (int) m.get("cornNum")); } } return map; } + @Override + public int getContinueDay(Long uid, GoldCornGetType type, Date deadDate) { + List<AggregationOperation> list = new ArrayList<>(); + list.add(Aggregation.match(Criteria.where("uid").is(uid).and("type").is(type).and("createTime").lte(deadDate))); + list.add(Aggregation.group("day").max("createTime").as("createTime")); + list.add(Aggregation.sort(Sort.Direction.DESC, "createTime")); + //鏈�澶ч檺鍒朵负365澶� + list.add(Aggregation.limit(365)); + list.add(Aggregation.project("day")); + AggregationResults<Map<String, String>> results = goldCornGetRecordDao.aggregate(list, Map.class); + List<Map<String, String>> resultList = results.getMappedResults(); + //鑾峰彇杩炵画鐨勫ぉ鏁� + String format = "yyyy-MM-dd"; + Date lastDay = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(deadDate.getTime(), format), format)); + int continueDay = 0; + for (Map<String, String> day : resultList) { + Long timestamp = TimeUtil.convertToTimeTemp(day.get("_id"), format); + long cha = lastDay.getTime() - timestamp; + if (cha <= 1000 * 60 * 60 * 24L) { + continueDay++; + } else { + break; + } + lastDay = new Date(timestamp); + } + return continueDay; + } + + @Override + public Map<GoldCornGetType, Long> sumEventCount(GoldCornGetRecordQuery goldCornGetRecordQuery) { + return goldCornGetRecordDao.sumEventCount(createDaoQuery(goldCornGetRecordQuery)); + } + + @Override + public Map<String, Long> sumGoldCornNum(GoldCornGetRecordQuery goldCornGetRecordQuery) { + + List<AggregationOperation> list = new ArrayList<>(); + list.add(Aggregation.match(goldCornGetRecordDao.getCriteria(createDaoQuery(goldCornGetRecordQuery)))); + list.add(Aggregation.group("day").sum("cornNum").as("cornNum")); + AggregationResults<Map<String, Object>> results = goldCornGetRecordDao.aggregate(list, Map.class); + List<Map<String, Object>> resultList = results.getMappedResults(); + Map<String, Long> resultMap = new HashMap<>(); + for (Map<String, Object> result : resultList) { + String day = result.get("_id") + ""; + Long count = Long.parseLong(result.get("cornNum") + ""); + resultMap.put(day, count); + } + return resultMap; + } + + @Override + public List<Long> listUids(Date minCreateTime, Date maxCreateTime, int page, int pageSize) { + List<AggregationOperation> list = new ArrayList<>(); + list.add(Aggregation.match(Criteria.where("createTime").gte(minCreateTime).lt(maxCreateTime))); + list.add(Aggregation.group("uid")); + list.add(Aggregation.sort(Sort.Direction.DESC, "_id")); + list.add(Aggregation.skip(Long.parseLong((page - 1) * pageSize + ""))); + list.add(Aggregation.limit(pageSize)); + AggregationResults<Map<String, Object>> results = goldCornGetRecordDao.aggregate(list, Map.class); + List<Map<String, Object>> resultList = results.getMappedResults(); + List<Long> uidList = new ArrayList<>(); + for (Map<String, Object> result : resultList) { + Long uid = Long.parseLong(result.get("_id") + ""); + uidList.add(uid); + } + return uidList; + } + + @Override + public Map<Long, Boolean> isSignIned(List<Long> uidList, String day) { + DaoQuery daoQuery = new DaoQuery(); + daoQuery.type = GoldCornGetType.signIn; + daoQuery.day = day; + daoQuery.uidList = uidList; + + List<AggregationOperation> list = new ArrayList<>(); + list.add(Aggregation.match(goldCornGetRecordDao.getCriteria(daoQuery))); + list.add(Aggregation.group("uid")); + + + AggregationResults<Map<String, Object>> results = goldCornGetRecordDao.aggregate(list, Map.class); + List<Map<String, Object>> resultList = results.getMappedResults(); + Set<Long> signInedList = new HashSet<>(); + for (Map<String, Object> result : resultList) { + Long uid = Long.parseLong(result.get("_id") + ""); + signInedList.add(uid); + } + + return uidList.stream().collect(Collectors.toMap(uid -> uid, uid -> signInedList.contains(uid))); + } + + @Override + public List<StatisticNumberResult> statistic(SystemEnum system, BaseStatisticTimeQuery query) { + GoldCornGetRecordQuery q = new GoldCornGetRecordQuery(); + q.setStartTime(TimeUtil.getGernalTime(query.getStartTime().getTime(), "yyyy.MM.dd HH:mm:ss")); + q.setEndTime(TimeUtil.getGernalTime(query.getEndTime().getTime(), "yyyy.MM.dd HH:mm:ss")); + q.setFormat("yyyy.MM.dd HH:mm:ss"); + Map<String, Long> map = sumGoldCornNum(q); + List<StatisticNumberResult> resultList = new ArrayList<>(); + for (String key : map.keySet()) { + StatisticNumberResult numberResult = new StatisticNumberResult(); + numberResult.setTime(key); + numberResult.setNumber(map.get(key)); + resultList.add(numberResult); + } + + Comparator<StatisticNumberResult> cm = (o1, o2) -> + GoldCornUtil.convertFormatDay(o1.getTime()).getTime() - GoldCornUtil.convertFormatDay(o2.getTime()).getTime() > 0 ? 1 : -1; + + Collections.sort(resultList, cm); + return resultList; + } + } \ No newline at end of file -- Gitblit v1.8.0