package com.yeshi.makemoney.app.dao.goldcorn;
|
|
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 java.util.Date;
|
|
import org.yeshi.utils.mongo.MongodbBaseDao;
|
|
import java.lang.Boolean;
|
import java.lang.String;
|
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornTaskTypeInfo;
|
import com.yeshi.makemoney.app.entity.SystemEnum;
|
|
import java.util.ArrayList;
|
|
|
@Repository
|
public class GoldCornTaskTypeInfoDao extends MongodbBaseDao<GoldCornTaskTypeInfo> {
|
|
public void updateSelective(GoldCornTaskTypeInfo 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.getIcon() != null) {
|
update.set("icon", bean.getIcon());
|
}
|
if (bean.getSystem() != null) {
|
update.set("system", bean.getSystem());
|
}
|
if (bean.getType() != null) {
|
update.set("type", bean.getType());
|
}
|
|
if (bean.getOrder() != null) {
|
update.set("order", bean.getOrder());
|
}
|
|
if (bean.getCreateTime() != null) {
|
update.set("createTime", bean.getCreateTime());
|
}
|
if (bean.getShow() != null) {
|
update.set("show", bean.getShow());
|
}
|
if (bean.getStartTime() != null) {
|
update.set("startTime", bean.getStartTime());
|
}
|
if (bean.getEndTime() != null) {
|
update.set("endTime", bean.getEndTime());
|
}
|
update.set("updateTime", new Date());
|
update(query, update);
|
}
|
|
|
public List<GoldCornTaskTypeInfo> 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<Criteria> andList = new ArrayList<>();
|
if (daoQuery.system != null) {
|
andList.add(Criteria.where("system").is(daoQuery.system));
|
}
|
if (daoQuery.type != null) {
|
andList.add(Criteria.where("type").is(daoQuery.type));
|
}
|
if (daoQuery.show != null) {
|
andList.add(Criteria.where("show").is(daoQuery.show));
|
}
|
|
if (daoQuery.showTime != null) {
|
andList.add(Criteria.where("startTime").lte(daoQuery.showTime).and("endTime").gt(daoQuery.showTime));
|
}
|
|
if (daoQuery.type != null) {
|
andList.add(Criteria.where("type").is(daoQuery.type));
|
}
|
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 SystemEnum system;
|
public GoldCornGetType type;
|
public Boolean show;
|
public Date showTime;
|
public int start;
|
public int count;
|
public List<Sort.Order> sortList;
|
}
|
}
|