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);
|
}
|
|
|
}
|