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.*;
|
import java.lang.Long;
|
|
import org.yeshi.utils.mongo.MongodbBaseDao;
|
|
import java.lang.String;
|
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
|
|
import java.lang.Integer;
|
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord;
|
|
|
@Repository
|
public class GoldCornGetRecordDao extends MongodbBaseDao<GoldCornGetRecord> {
|
|
public void updateSelective(GoldCornGetRecord bean) {
|
Query query = new Query();
|
Update update = new Update();
|
query.addCriteria(Criteria.where("id").is(bean.getId()));
|
if (bean.getUid() != null) {
|
update.set("uid", bean.getUid());
|
}
|
if (bean.getDay() != null) {
|
update.set("day", bean.getDay());
|
}
|
if (bean.getCornNum() != null) {
|
update.set("cornNum", bean.getCornNum());
|
}
|
if (bean.getFromUid() != null) {
|
update.set("fromUid", bean.getFromUid());
|
}
|
if (bean.getFromId() != null) {
|
update.set("fromId", bean.getFromId());
|
}
|
if (bean.getType() != null) {
|
update.set("type", bean.getType());
|
}
|
if (bean.getRemarks() != null) {
|
update.set("remarks", bean.getRemarks());
|
}
|
if (bean.getCreateTime() != null) {
|
update.set("createTime", bean.getCreateTime());
|
}
|
update.set("updateTime", new Date());
|
update(query, update);
|
}
|
|
|
public List<GoldCornGetRecord> list(DaoQuery daoQuery) {
|
Query query = getQuery(daoQuery);
|
if (daoQuery.sortList != null && daoQuery.sortList.size() > 0) {
|
query.with(Sort.by(daoQuery.sortList));
|
}
|
query.skip(daoQuery.start);
|
query.limit(daoQuery.count);
|
return findList(query);
|
}
|
|
public long count(DaoQuery daoQuery) {
|
Query query = getQuery(daoQuery);
|
return count(query);
|
}
|
|
/**
|
* @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));
|
}
|
if (daoQuery.day != null) {
|
andList.add(Criteria.where("day").is(daoQuery.day));
|
}
|
|
if (daoQuery.dayList != null && daoQuery.dayList.size() > 0) {
|
Criteria[] ors = new Criteria[daoQuery.dayList.size()];
|
for (int i = 0; i < ors.length; i++) {
|
ors[i] = Criteria.where("day").is(daoQuery.dayList.get(i));
|
}
|
andList.add(new Criteria().orOperator(ors));
|
}
|
|
if (daoQuery.fromUid != null) {
|
andList.add(Criteria.where("fromUid").is(daoQuery.fromUid));
|
}
|
if (daoQuery.fromId != null) {
|
andList.add(Criteria.where("fromId").is(daoQuery.fromId));
|
}
|
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));
|
}
|
Criteria[] ands = new Criteria[andList.size()];
|
andList.toArray(ands);
|
if (ands.length > 0) {
|
return new Criteria().andOperator(ands);
|
}
|
return new Criteria();
|
}
|
|
private Query getQuery(DaoQuery daoQuery) {
|
Query query = new Query();
|
query.addCriteria(getCriteria(daoQuery));
|
return query;
|
}
|
|
public static class DaoQuery {
|
public Long uid;
|
public String day;
|
public List<String> dayList;
|
public Long fromUid;
|
public String fromId;
|
public GoldCornGetType type;
|
public Boolean doubles;
|
public Date maxCreateTime;
|
public Date minCreateTime;
|
public int start;
|
public int count;
|
public List<Sort.Order> sortList;
|
}
|
}
|