package com.ks.app.dao.config; 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 com.ks.app.entity.config.SystemConfigKey; import com.ks.app.entity.SystemEnum; import java.util.Date; import org.yeshi.utils.mongo.MongodbBaseDao; import java.lang.String; import com.ks.app.entity.config.SystemConfig; import java.util.ArrayList; @Repository public class SystemConfigDao extends MongodbBaseDao{ public void updateSelective(SystemConfig bean) { Query query = new Query(); Update update=new Update(); query.addCriteria(Criteria.where("id").is(bean.getId())); if(bean.getName() != null) { update.set("name", bean.getName()); } if(bean.getKey() != null) { update.set("key", bean.getKey()); } if(bean.getSystem() != null) { update.set("system", bean.getSystem()); } if(bean.getValue() != null) { update.set("value", bean.getValue()); } 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 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); } private Query getQuery(DaoQuery daoQuery){ List andList=new ArrayList<>(); if(daoQuery.name!=null){ andList.add(Criteria.where("name").regex(daoQuery.name)); } if(daoQuery.key!=null){ andList.add(Criteria.where("key").is(daoQuery.key)); } if(daoQuery.system!=null){ andList.add(Criteria.where("system").is(daoQuery.system)); } if(daoQuery.value!=null){ andList.add(Criteria.where("value").regex(daoQuery.value)); } Query query=new Query(); Criteria[] ands=new Criteria[andList.size()]; andList.toArray(ands); if(ands.length>0){ query.addCriteria(new Criteria().andOperator(ands)); } return query; } public static class DaoQuery{ public String name; public SystemConfigKey key; public SystemEnum system; public String value; public int start; public int count; public List sortList; } }