| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class GoldCornGetRecordServiceImpl implements GoldCornGetRecordService { |
| | |
| | | return goldCornGetRecordDao.sumEventCount(createDaoQuery(goldCornGetRecordQuery)); |
| | | } |
| | | |
| | | @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))); |
| | | } |
| | | |
| | | |
| | | } |