package com.yeshi.buwan.dao.live; 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.yeshi.buwan.domain.live.TVLiveProgramResource; import com.yeshi.buwan.dao.base.MongodbBaseDao; import java.util.Date; import com.yeshi.buwan.domain.live.TVLiveProgramResource.TVLiveProgramResourceType; import java.lang.String; import java.util.ArrayList; @Repository public class TVLiveProgramResourceDao extends MongodbBaseDao { public void updateSelective(TVLiveProgramResource bean) { Query query = new Query(); Update update = new Update(); query.addCriteria(Criteria.where("id").is(bean.getId())); if (bean.getChannelId() != null) { update.set("channelId", bean.getChannelId()); } if (bean.getUrl() != null) { update.set("url", bean.getUrl()); } if (bean.getType() != null) { update.set("type", bean.getType()); } 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(new Sort(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.channelId != null) { andList.add(Criteria.where("channelId").is(daoQuery.channelId)); } if (daoQuery.url != null) { andList.add(Criteria.where("url").is(daoQuery.url)); } if (daoQuery.type != null) { andList.add(Criteria.where("type").is(daoQuery.type)); } if (daoQuery.minCreateTime != null) { andList.add(Criteria.where("createTime").gte(daoQuery.minCreateTime)); } if (daoQuery.maxCreateTime != null) { andList.add(Criteria.where("createTime").lt(daoQuery.maxCreateTime)); } 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 channelId; public String url; public TVLiveProgramResource.TVLiveProgramResourceType type; public Date minCreateTime; public Date maxCreateTime; public int start; public int count; public List sortList; } }