| | |
| | | package com.yeshi.fanli.dao.user.invite;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.data.mongodb.core.MongoTemplate;
|
| | | 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.stereotype.Repository;
|
| | |
|
| | | import com.yeshi.fanli.entity.bus.user.vip.TeamDailyRecord;
|
| | | import com.mongodb.BasicDBObject;
|
| | | import com.mongodb.DBObject;
|
| | | import com.yeshi.fanli.dao.MongodbBaseDao;
|
| | | import com.yeshi.fanli.entity.bus.user.invite.TeamDailyRecord;
|
| | |
|
| | | @Repository
|
| | | public class TeamDailyRecordDao {
|
| | | public class TeamDailyRecordDao extends MongodbBaseDao<TeamDailyRecord> {
|
| | |
|
| | | @Resource
|
| | | private MongoTemplate mongoTemplate;
|
| | | private static String collectionName = "teamDailyRecord";
|
| | |
|
| | | /**
|
| | | * 新增
|
| | | * |
| | | * @param record
|
| | | */
|
| | | public void save(TeamDailyRecord record) {
|
| | | if (record == null) {
|
| | | return;
|
| | | }
|
| | | mongoTemplate.save(record);
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 选择性更新
|
| | | * @param record
|
| | |
| | | if (record.getBeyondSuperVIP() != null)
|
| | | update.set("beyondSuperVIP", record.getBeyondSuperVIP());
|
| | | update.set("updateTime", new Date());
|
| | | mongoTemplate.updateMulti(query, update, TeamDailyRecord.class);
|
| | | update(query, update);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | *
|
| | | * @return
|
| | | */
|
| | | public List<TeamDailyRecord> getbyUid(Long uid) {
|
| | | public List<TeamDailyRecord> getByUid(Long uid) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("uid").is(uid));
|
| | | return mongoTemplate.find(query, TeamDailyRecord.class);
|
| | | return findList(query);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | *
|
| | | * @return
|
| | | */
|
| | | public List<TeamDailyRecord> getbyUid(Long uid, Date minTime) {
|
| | | public List<TeamDailyRecord> listByUid(Long uid, Date minDate, Date maxDate) {
|
| | | List<Criteria> list = new ArrayList<Criteria>();
|
| | | list.add(Criteria.where("uid").is(uid));
|
| | | if (minDate != null)
|
| | | list.add(Criteria.where("countDay").gte(minDate));
|
| | | if (maxDate != null)
|
| | | list.add(Criteria.where("countDay").lte(maxDate));
|
| | | |
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("uid").is(uid));
|
| | | query.addCriteria(Criteria.where("countDay").lte(minTime));
|
| | | return mongoTemplate.find(query, TeamDailyRecord.class);
|
| | | if (list.size() > 0) {
|
| | | Criteria[] cas = new Criteria[list.size()];
|
| | | for (int i = 0; i < list.size(); i++)
|
| | | cas[i] = list.get(i);
|
| | | query.addCriteria(new Criteria().andOperator(cas));
|
| | | }
|
| | | return findList(query);
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 统计年月
|
| | | * @param uid
|
| | | * @param minDate
|
| | | * @param maxDate
|
| | | * @return
|
| | | */
|
| | | public List<TeamDailyRecord> sumGroupByYearMonth(Long uid, Date minDate, Date maxDate) {
|
| | | List<TeamDailyRecord> listDailyCount = new ArrayList<>();
|
| | | // 统计方法
|
| | | String reduce = "function(doc, aggr){"
|
| | | + " aggr.firstDaRen += doc.firstDaRen;"
|
| | | + " aggr.secondDaRen += doc.secondDaRen;"
|
| | | + " aggr.firstHighVIP += doc.firstHighVIP;"
|
| | | + " aggr.secondHighVIP += doc.secondHighVIP;"
|
| | | + " aggr.firstSuperVIP += doc.firstSuperVIP;"
|
| | | + " aggr.secondSuperVIP += doc.secondSuperVIP;"
|
| | | + "}";
|
| | |
|
| | | // 查询条件
|
| | | List<Criteria> list = new ArrayList<Criteria>();
|
| | | list.add(Criteria.where("uid").is(uid));
|
| | | if (minDate != null)
|
| | | list.add(Criteria.where("countDay").gte(minDate));
|
| | | if (maxDate != null)
|
| | | list.add(Criteria.where("countDay").lte(maxDate));
|
| | |
|
| | | Query query = new Query();
|
| | | if (list.size() > 0) {
|
| | | Criteria[] cas = new Criteria[list.size()];
|
| | | for (int i = 0; i < list.size(); i++)
|
| | | cas[i] = list.get(i);
|
| | | query.addCriteria(new Criteria().andOperator(cas));
|
| | | }
|
| | |
|
| | | BasicDBObject agg = new BasicDBObject("yearMonth", "");
|
| | |
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | map.put("firstDaRen", 0);
|
| | | map.put("firstHighVIP", 0);
|
| | | map.put("firstSuperVIP", 0);
|
| | | map.put("secondDaRen", 0);
|
| | | map.put("secondHighVIP", 0);
|
| | | map.put("secondSuperVIP", 0);
|
| | | BasicDBObject dbObject = new BasicDBObject(map);
|
| | | DBObject result = mongoTemplate.getCollection(collectionName).group(agg, query.getQueryObject(), dbObject, reduce);
|
| | | Map<String, BasicDBObject> mapResult = result.toMap();
|
| | | if (mapResult.size() > 0) {
|
| | | for (int i = 0; i < mapResult.size(); i++) {
|
| | | BasicDBObject object = mapResult.get(i + "");
|
| | | |
| | | TeamDailyRecord record = new TeamDailyRecord();
|
| | | record.setFirstDaRen(new BigDecimal(object.get("firstDaRen").toString()).intValue());
|
| | | record.setFirstHighVIP(new BigDecimal(object.get("firstHighVIP").toString()).intValue());
|
| | | record.setFirstSuperVIP(new BigDecimal(object.get("firstSuperVIP").toString()).intValue());
|
| | | record.setSecondDaRen(new BigDecimal(object.get("secondDaRen").toString()).intValue());
|
| | | record.setSecondHighVIP(new BigDecimal(object.get("secondHighVIP").toString()).intValue());
|
| | | record.setSecondSuperVIP(new BigDecimal(object.get("secondSuperVIP").toString()).intValue());
|
| | | listDailyCount.add(record);
|
| | | }
|
| | | }
|
| | | return listDailyCount;
|
| | | }
|
| | | }
|