From 6cc97918a5a42e37a3c3867cc5b78a0b9fd43a24 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 29 四月 2022 19:55:41 +0800 Subject: [PATCH] 功能完善 --- app/src/main/java/com/yeshi/makemoney/app/dao/goldcorn/GoldCornGetRecordDao.java | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 43 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/yeshi/makemoney/app/dao/goldcorn/GoldCornGetRecordDao.java b/app/src/main/java/com/yeshi/makemoney/app/dao/goldcorn/GoldCornGetRecordDao.java index 8dd8731..e03f451 100644 --- a/app/src/main/java/com/yeshi/makemoney/app/dao/goldcorn/GoldCornGetRecordDao.java +++ b/app/src/main/java/com/yeshi/makemoney/app/dao/goldcorn/GoldCornGetRecordDao.java @@ -1,14 +1,16 @@ package com.yeshi.makemoney.app.dao.goldcorn; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Repository; -import java.util.List; +import java.util.*; import java.lang.Long; -import java.util.Date; import org.yeshi.utils.mongo.MongodbBaseDao; @@ -17,7 +19,6 @@ import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType; import java.lang.Integer; -import java.util.ArrayList; import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord; @@ -73,7 +74,34 @@ return count(query); } - private Query getQuery(DaoQuery daoQuery) { + /** + * @return java.util.Map<com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType , java.lang.Long> + * @author hxh + * @description 缁熻浜嬩欢鏁伴噺 + * @date 10:48 2022/4/28 + * @param: daoQuery + **/ + public Map<GoldCornGetType, Long> sumEventCount(DaoQuery daoQuery) { + List<AggregationOperation> list = new ArrayList<>(); + list.add(Aggregation.match(getCriteria(daoQuery))); + list.add(Aggregation.group("type").sum("eventCount").as("eventCount")); + list.add(Aggregation.project("type", "eventCount")); + AggregationResults<Map> results = aggregate(list, Map.class); + List<Map> mapList = results.getMappedResults(); + Map<GoldCornGetType, Long> resultMap = new HashMap<>(); + if (mapList != null) { + for (Map map : mapList) { + GoldCornGetType type = GoldCornGetType.valueOf(map.get("_id")+""); + Long count = (Long) map.get("eventCount"); + count = count == null ? 0L : count; + resultMap.put(type, count); + } + } + return resultMap; + } + + + private Criteria getCriteria(DaoQuery daoQuery) { List<Criteria> andList = new ArrayList<>(); if (daoQuery.uid != null) { andList.add(Criteria.where("uid").is(daoQuery.uid)); @@ -99,18 +127,26 @@ if (daoQuery.type != null) { andList.add(Criteria.where("type").is(daoQuery.type)); } + if (daoQuery.doubles != null) { + andList.add(Criteria.where("isDubble").is(daoQuery.doubles)); + } if (daoQuery.maxCreateTime != null) { andList.add(Criteria.where("createTime").lt(daoQuery.maxCreateTime)); } if (daoQuery.minCreateTime != null) { andList.add(Criteria.where("createTime").gte(daoQuery.minCreateTime)); } - Query query = new Query(); Criteria[] ands = new Criteria[andList.size()]; andList.toArray(ands); if (ands.length > 0) { - query.addCriteria(new Criteria().andOperator(ands)); + return new Criteria().andOperator(ands); } + return new Criteria(); + } + + private Query getQuery(DaoQuery daoQuery) { + Query query = new Query(); + query.addCriteria(getCriteria(daoQuery)); return query; } @@ -121,6 +157,7 @@ public Long fromUid; public String fromId; public GoldCornGetType type; + public Boolean doubles; public Date maxCreateTime; public Date minCreateTime; public int start; -- Gitblit v1.8.0