admin
2021-08-27 8fee151ffae0c3818694b7318583814bf92663e2
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
package com.yeshi.buwan.dao.juhe.pptv;
 
import com.yeshi.buwan.dao.base.MongodbBaseDao;
import com.yeshi.buwan.videos.pptv.PPTVQuery;
import com.yeshi.buwan.videos.pptv.entity.PPTVSeriesProgramMap;
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.stereotype.Repository;
 
import java.util.ArrayList;
import java.util.List;
 
@Repository
public class PPTVSeriesProgramMapDao extends MongodbBaseDao<PPTVSeriesProgramMap> {
 
    public List<PPTVSeriesProgramMap> list(PPTVQuery pptvQuery) {
        Query query = new Query();
        List<Criteria> whereList = new ArrayList<>();
        if (pptvQuery.programCode != null) {
            whereList.add(Criteria.where("programCode").is(pptvQuery.programCode));
        }
 
        if (pptvQuery.infoId != null) {
            whereList.add(Criteria.where("infoId").is(pptvQuery.infoId));
        }
 
        if (pptvQuery.seriesCode != null) {
            whereList.add(Criteria.where("seriesCode").is(pptvQuery.seriesCode));
        }
        query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "rank")));
        Criteria[] wheres = new Criteria[whereList.size()];
        whereList.toArray(wheres);
        query.addCriteria(new Criteria().andOperator(wheres));
        query.skip(pptvQuery.start);
        query.limit(pptvQuery.count);
 
        return findList(query);
    }
 
    /**
     * 获取最近最近的节目
     *
     * @param infoId
     * @return
     */
    public PPTVSeriesProgramMap getLatestByInfoId(String infoId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("infoId").is(infoId));
        query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "rank")));
        return findOne(query);
    }
 
    public long count(PPTVQuery pptvQuery) {
        Query query = new Query();
        List<Criteria> whereList = new ArrayList<>();
        if (pptvQuery.programCode != null) {
            whereList.add(Criteria.where("programCode").is(pptvQuery.programCode));
        }
 
        if (pptvQuery.infoId != null) {
            whereList.add(Criteria.where("infoId").is(pptvQuery.infoId));
        }
 
        if (pptvQuery.seriesCode != null) {
            whereList.add(Criteria.where("seriesCode").is(pptvQuery.seriesCode));
        }
        Criteria[] wheres = new Criteria[whereList.size()];
        whereList.toArray(wheres);
        query.addCriteria(new Criteria().andOperator(wheres));
        return count(query);
    }
 
 
}