admin
2021-09-03 b41a6efe17ba61d150c5a9b7309651cebae54e0d
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.yeshi.buwan.dao.live;
 
import com.yeshi.buwan.domain.live.TVLiveCategory;
import com.yeshi.buwan.domain.live.TVLiveChannel;
import com.yeshi.buwan.dao.base.MongodbBaseDao;
import com.yeshi.buwan.query.BaseQuery;
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 TVLiveChannelDao extends MongodbBaseDao<TVLiveChannel> {
 
    public void updateSelective(TVLiveChannel 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.gethPicture() != null) {
            update.set("hPicture", bean.gethPicture());
        }
        if (bean.getvPicture() != null) {
            update.set("vPicture", bean.getvPicture());
        }
        if (bean.getNowProgram() != null) {
            update.set("nowProgram", bean.getNowProgram());
        }
        if (bean.getNowProgramTime() != null) {
            update.set("nowProgramTime", bean.getNowProgramTime());
        }
        if (bean.getNextProgram() != null) {
            update.set("nextProgram", bean.getNextProgram());
        }
        if (bean.getNextProgramTime() != null) {
            update.set("nextProgramTime", bean.getNextProgramTime());
        }
        if (bean.getState() != null) {
            update.set("state", bean.getState());
        }
        if (bean.getCreateTime() != null) {
            update.set("createTime", bean.getCreateTime());
        }
        update.set("updateTime", new Date());
        update(query, update);
    }
 
 
    public List<TVLiveChannel> listByIds(List<String> ids) {
        if (ids == null || ids.size() == 0)
            return null;
        Criteria[] ors = new Criteria[ids.size()];
        for (int i = 0; i < ors.length; i++) {
            ors[i] = Criteria.where("_id").is(ids.get(i));
        }
        Query query = new Query();
        query.addCriteria(new Criteria().orOperator(ors));
        return findList(query);
    }
 
    private Query getQuery(DaoQuery daoQuery) {
        Query query = BaseQuery.createBaseMongoQuery(daoQuery, daoQuery.sortList);
        List<Criteria> andList = new ArrayList<>();
        if (daoQuery.name != null) {
            andList.add(Criteria.where("name").regex(daoQuery.name));
        }
        if (daoQuery.state != null) {
            andList.add(Criteria.where("state").is(daoQuery.state));
        }
        Criteria[] ands = new Criteria[andList.size()];
        andList.toArray(ands);
        query.addCriteria(new Criteria().andOperator(ands));
        return query;
 
    }
 
 
    public List<TVLiveChannel> list(DaoQuery daoQuery) {
        return findList(getQuery(daoQuery));
    }
 
    public long count(DaoQuery daoQuery) {
        return count(getQuery(daoQuery));
    }
 
 
    public static class DaoQuery extends BaseQuery {
        public String name;
        public Integer state;
        public List<Sort.Order> sortList;
    }
 
}