package com.yeshi.buwan.dao.recommend;
|
|
import com.yeshi.buwan.domain.recommend.HomeRecommendSpecial;
|
import com.yeshi.buwan.dao.base.MongodbBaseDao;
|
import org.springframework.data.domain.Sort;
|
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 java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
@Repository
|
public class HomeRecommendSpecialDao extends MongodbBaseDao<HomeRecommendSpecial> {
|
|
public List<HomeRecommendSpecial> list(List<String> ids) {
|
Query query = new Query();
|
List<Criteria> orList = new ArrayList<>();
|
|
if (ids != null) {
|
for (String id : ids) {
|
orList.add(Criteria.where("id").is(id));
|
}
|
}
|
|
Criteria criteria = new Criteria();
|
if (orList.size() > 0) {
|
Criteria[] ors = new Criteria[orList.size()];
|
orList.toArray(ors);
|
criteria = criteria.orOperator(ors);
|
}
|
query.addCriteria(criteria);
|
return findList(query);
|
}
|
|
public List<HomeRecommendSpecial> list(DaoQuery daoQuery) {
|
Query query = new Query();
|
List<Criteria> andList = new ArrayList<>();
|
|
if (daoQuery.systemId != null) {
|
andList.add(Criteria.where("systemId").is(daoQuery.systemId));
|
}
|
|
Criteria criteria = new Criteria();
|
if (andList.size() > 0) {
|
Criteria[] ands = new Criteria[andList.size()];
|
andList.toArray(ands);
|
criteria = criteria.andOperator(ands);
|
}
|
|
query.addCriteria(criteria);
|
|
query.skip(daoQuery.start);
|
query.limit(daoQuery.count);
|
query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "weight")));
|
|
return findList(query);
|
}
|
|
public void updateSelective(HomeRecommendSpecial 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.getSystemId() != null) {
|
update.set("systemId", bean.getSystemId());
|
}
|
if (bean.getBannerSizeRate() != null) {
|
update.set("bannerSizeRate", bean.getBannerSizeRate());
|
}
|
if (bean.getWeight() != null) {
|
update.set("weight", bean.getWeight());
|
}
|
if (bean.getCreateTime() != null) {
|
update.set("createTime", bean.getCreateTime());
|
}
|
update.set("updateTime", new Date());
|
update(query, update);
|
}
|
|
|
public static class DaoQuery {
|
public String systemId;
|
public int start;
|
public int count;
|
}
|
|
|
}
|