| | |
| | | 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.iqiyi.entity.IqiyiAlbum2; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiVideoInfo; |
| | | 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; |
| | |
| | | public class IqiyiAlbum2Dao extends MongodbBaseDao<IqiyiAlbum2> { |
| | | |
| | | //根据专辑ID查询 |
| | | public List<IqiyiAlbum2> listByAid(long aid, int start, int count) { |
| | | public List<IqiyiAlbum2> listByAid(Iqiyi2AlbumQuery albumQuery, int sortName, int start, int count) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("featureAlbumId").is(aid)); |
| | | 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<>(); |
| | | orders.add(new Sort.Order(Sort.Direction.ASC, "order")); |
| | | query.with(new Sort(orders)); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |