1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.yeshi.buwan.dao.recommend;
 
import com.yeshi.buwan.dao.base.MongodbBaseDao;
import com.yeshi.buwan.domain.recommend.SuperHomeRecommendSpecial;
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 SuperHomeRecommendSpecialDao extends MongodbBaseDao<SuperHomeRecommendSpecial> {
 
 
    public List<SuperHomeRecommendSpecial> list(SuperHomeRecommendSpecialDao.DaoQuery daoQuery) {
        Query query = new Query();
        List<Criteria> andList = new ArrayList<>();
 
        if (daoQuery.specialId != null) {
            andList.add(Criteria.where("specialId").is(daoQuery.specialId));
        }
 
        if (daoQuery.detailSystemId != null) {
            andList.add(Criteria.where("detailSystemId").is(daoQuery.detailSystemId));
        }
 
 
        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(SuperHomeRecommendSpecial bean) {
        Query query = new Query();
        Update update = new Update();
        query.addCriteria(Criteria.where("id").is(bean.getId()));
        if (bean.getSpecialId() != null) {
            update.set("specialId", bean.getSpecialId());
        }
        if (bean.getDetailSystemId() != null) {
            update.set("detailSystemId", bean.getDetailSystemId());
        }
        if (bean.getShowName() != null) {
            update.set("showName", bean.getShowName());
        }
        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 specialId;
        public String detailSystemId;
        public int start;
        public int count;
    }
}