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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.yeshi.buwan.dao.juhe.iqiyi;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.yeshi.buwan.dao.base.MongodbBaseDao;
import com.yeshi.buwan.videos.iqiyi.entity.IqiyiAlbum2;
import com.yeshi.buwan.query.Iqiyi2AlbumQuery;
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 IqiyiAlbum2Dao extends MongodbBaseDao<IqiyiAlbum2> {
 
    //根据专辑ID查询
    public List<IqiyiAlbum2> listByAid(Iqiyi2AlbumQuery albumQuery, int sortName, int start, int count) {
        Query query = new Query();
        Criteria where = new Criteria();
        List<Criteria> whereList = new ArrayList<>();
        if (albumQuery.getFeatureAlbumId() != null)
            whereList.add(Criteria.where("featureAlbumId").is(albumQuery.getFeatureAlbumId()));
        if (albumQuery.getContentType() != null)
            whereList.add(Criteria.where("contentType").is(albumQuery.getContentType()));
 
        if (albumQuery.getChannelId() != null)
            whereList.add(Criteria.where("channelId").is(albumQuery.getChannelId()));
        if (whereList.size() > 0) {
            Criteria[] arrays = new Criteria[whereList.size()];
            whereList.toArray(arrays);
            where = where.andOperator(arrays);
        }
 
        query.addCriteria(where);
        query.skip(start);
        query.limit(count);
        List<Sort.Order> orders = new ArrayList<>();
        if (IqiyiAlbum2.SORT_ORDER == sortName)
            orders.add(new Sort.Order(Sort.Direction.ASC, "order"));
        else if (IqiyiAlbum2.SORT_PERIOD == sortName)
            orders.add(new Sort.Order(Sort.Direction.DESC, "period"));
        else if (IqiyiAlbum2.SORT_ID == sortName) {
            orders.add(new Sort.Order(Sort.Direction.ASC, "id"));
        }
 
        query.with( new Sort(orders));
        return findList(query);
    }
 
    /**
     * 根据Aid查询数量
     *
     * @param albumQuery
     * @return
     */
    public long countByAid(Iqiyi2AlbumQuery albumQuery) {
        Query query = new Query();
        Criteria where = new Criteria();
        List<Criteria> whereList = new ArrayList<>();
        if (albumQuery.getFeatureAlbumId() != null)
            whereList.add(Criteria.where("featureAlbumId").is(albumQuery.getFeatureAlbumId()));
        if (albumQuery.getContentType() != null)
            whereList.add(Criteria.where("contentType").is(albumQuery.getContentType()));
 
        if (albumQuery.getChannelId() != null)
            whereList.add(Criteria.where("channelId").is(albumQuery.getChannelId()));
        if (whereList.size() > 0) {
            Criteria[] arrays = new Criteria[whereList.size()];
            whereList.toArray(arrays);
            where = where.andOperator(arrays);
        }
        query.addCriteria(where);
        return count(query);
    }
 
    /**
     * 根据专辑名称计数
     *
     * @param aid
     * @return
     */
    public long countVideoByAid(long aid) {
        Query query = new Query();
        query.addCriteria(Criteria.where("featureAlbumId").is(aid).andOperator(Criteria.where("contentType").is(1)));
        return count(query);
    }
 
    public List<IqiyiAlbum2> listByChannelId(int channelId, Long albumId, Integer contentType, int start, int count) {
        Query query = new Query();
        List<Criteria> andCriteria = new ArrayList<>();
        Criteria criteria = Criteria.where("channelId").is(channelId);
        andCriteria.add(criteria);
        if (albumId != null) {
            andCriteria.add(Criteria.where("featureAlbumId").is(albumId));
        }
        if (contentType != null) {
            andCriteria.add(Criteria.where("contentType").is(contentType));
        }
        Criteria[] wheres = new Criteria[andCriteria.size()];
        andCriteria.toArray(wheres);
        query.addCriteria(new Criteria().andOperator(wheres));
        query.skip(start);
        query.limit(count);
        return findList(query);
    }
 
    /**
     * 根据ID查询
     *
     * @param id
     * @return
     */
    public long countById(Long id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("id").is(id));
        return count(query);
    }
 
    /**
     * 获取无效列表
     *
     * @param start
     * @param count
     * @return
     */
    public List<Long> listInvalid(int start, int count) {
        List<Long> idsList = new ArrayList<>();
 
        BasicDBObject where = new BasicDBObject();
        where.put("platformId", 15);
        where.put("availableStatus", new BasicDBObject("$ne", 1));
 
        BasicDBObject query = new BasicDBObject("playControls", new BasicDBObject("$elemMatch", where));
        BasicDBList condList = new BasicDBList();
        condList.add(query);
        condList.add(new BasicDBObject("effect", new BasicDBObject("$ne", 1)));
        condList.add(new BasicDBObject("supportDrm", new BasicDBObject("$eq", true)));
        query = new BasicDBObject("$or", condList);
        DBCursor cursor = mongoTemplate.getCollection(mongoTemplate.getCollectionName(IqiyiAlbum2.class)).find(query, new BasicDBObject("_id", 1)).skip(start).limit(count);
        if (cursor != null && cursor.hasNext() && cursor.size() > 0) {
            String json = JSON.toJSONString(cursor, true);
            JSONArray array = JSON.parseArray(json);
            for (int i = 0; i < array.size(); i++) {
                idsList.add(array.getJSONObject(i).getLong("_id"));
            }
        }
        return idsList;
    }
 
 
    /**
     * 根据ID查询
     *
     * @param ids
     * @return
     */
    public List<IqiyiAlbum2> listByIds(List<Long> ids) {
        Query query = new Query();
        List<Criteria> whereList = new ArrayList<>();
        for (Long id : ids)
            whereList.add(Criteria.where("id").is(id));
        Criteria[] wheres = new Criteria[whereList.size()];
        whereList.toArray(wheres);
        query.addCriteria(new Criteria().orOperator(wheres));
        return findList(query);
    }
 
 
}