From 36681e15e12aaa9135f69260472de65303cdcba3 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 26 四月 2022 19:10:45 +0800 Subject: [PATCH] 任务优化 --- app/src/main/java/com/yeshi/makemoney/app/dao/msg/AppPageNotifyMsgDao.java | 73 +++++++++++++++++++++--------------- 1 files changed, 42 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/yeshi/makemoney/app/dao/msg/AppPageNotifyMsgDao.java b/app/src/main/java/com/yeshi/makemoney/app/dao/msg/AppPageNotifyMsgDao.java index 5f0b618..f42b27c 100644 --- a/app/src/main/java/com/yeshi/makemoney/app/dao/msg/AppPageNotifyMsgDao.java +++ b/app/src/main/java/com/yeshi/makemoney/app/dao/msg/AppPageNotifyMsgDao.java @@ -1,5 +1,6 @@ package com.yeshi.makemoney.app.dao.msg; +import com.yeshi.makemoney.app.entity.SystemEnum; import com.yeshi.makemoney.app.entity.msg.AppPageNotifyMsg; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.query.Criteria; @@ -14,88 +15,98 @@ @Repository -public class AppPageNotifyMsgDao extends MongodbBaseDao<AppPageNotifyMsg>{ +public class AppPageNotifyMsgDao extends MongodbBaseDao<AppPageNotifyMsg> { - public void updateSelective(AppPageNotifyMsg bean) { + public void updateSelective(AppPageNotifyMsg bean) { Query query = new Query(); - Update update=new Update(); + Update update = new Update(); query.addCriteria(Criteria.where("id").is(bean.getId())); - if(bean.getSystem() != null) { + if (bean.getSystem() != null) { update.set("system", bean.getSystem()); } - if(bean.getType() != null) { + if (bean.getType() != null) { update.set("type", bean.getType()); } - if(bean.getShow() != null) { + if (bean.getShow() != null) { update.set("show", bean.getShow()); } - if(bean.getCanClose() != null) { + if (bean.getCanClose() != null) { update.set("canClose", bean.getCanClose()); } - if(bean.getContent() != null) { + if (bean.getContent() != null) { update.set("content", bean.getContent()); } - if(bean.getContentUrl() != null) { + if (bean.getContentUrl() != null) { update.set("contentUrl", bean.getContentUrl()); } - if(bean.getMd5() != null) { + if (bean.getMd5() != null) { update.set("md5", bean.getMd5()); } - if(bean.getStartTime() != null) { + if (bean.getStartTime() != null) { update.set("startTime", bean.getStartTime()); } - if(bean.getEndTime() != null) { + if (bean.getEndTime() != null) { update.set("endTime", bean.getEndTime()); } - if(bean.getCreateTime() != null) { + if (bean.getCreateTime() != null) { update.set("createTime", bean.getCreateTime()); } update.set("updateTime", new Date()); update(query, update); - } + } - public List<AppPageNotifyMsg> list(DaoQuery daoQuery){ + public List<AppPageNotifyMsg> list(DaoQuery daoQuery) { Query query = getQuery(daoQuery); - if (daoQuery.sortList!=null && daoQuery.sortList.size()>0){ + 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); + public long count(DaoQuery daoQuery) { + Query query = getQuery(daoQuery); return count(query); - } + } - private Query getQuery(DaoQuery daoQuery){ - List<Criteria> andList=new ArrayList<>(); - if(daoQuery.type!=null){ + private Query getQuery(DaoQuery daoQuery) { + List<Criteria> andList = new ArrayList<>(); + if (daoQuery.type != null) { andList.add(Criteria.where("type").is(daoQuery.type)); } - if(daoQuery.show!=null){ + if (daoQuery.show != null) { andList.add(Criteria.where("show").is(daoQuery.show)); } - if(daoQuery.content!=null){ + if (daoQuery.system != null) { + andList.add(Criteria.where("system").is(daoQuery.system)); + } + + if (daoQuery.date != null) { + andList.add(Criteria.where("startTime").lte(daoQuery.date).and("endTime").gt(daoQuery.date)); + } + + if (daoQuery.content != null) { andList.add(Criteria.where("content").regex(daoQuery.content)); } - Query query=new Query(); - Criteria[] ands=new Criteria[andList.size()]; + Query query = new Query(); + Criteria[] ands = new Criteria[andList.size()]; andList.toArray(ands); - if(ands.length>0){ + if (ands.length > 0) { query.addCriteria(new Criteria().andOperator(ands)); } return query; - } + } - public static class DaoQuery{ + public static class DaoQuery { public AppPageNotifyMsg.AppPageNotifyMsgType type; public Boolean show; + public SystemEnum system; + public Date date; public String content; public int start; public int count; public List<Sort.Order> sortList; - } + } } -- Gitblit v1.8.0