1.dao层继承MongoRepository
public interface PFlowLineStationHourDao extends MongoRepository<PFlowLineStationHourEntity, Long>{
}
2.service层注入PFlowLineStationHourDao ,MongoTemplate
例:
@Service
public class PFlowLineServiceImpl implements PFlowLineService{
@Autowired
public PFlowLineStationHourDao pFlowLineStationHourDao;
@Autowired
private MongoTemplate mongoTemplate;
public List<?> queryPFlowLineStationHour(PFlowQueryParam param) {
Query query = new Query();
if(param.getDates().size()>0){
query.addCriteria(Criteria.where("yearMonthDate").in(param.getDates()));
}else{
int beginDate = Integer.parseInt(DateUtil.getYearMonthDayFormat(DateUtil.getDayBefore(param.getBegintime())));
int endDate = Integer.parseInt(DateUtil.getYearMonthDayFormat(DateUtil.getDayAfter(param.getEndtime())));
query.addCriteria(Criteria.where("yearMonthDate").gte(beginDate).lte(endDate));
}
if(param.getLineCodes().size()>0){
query.addCriteria(Criteria.where("lineCode").in(param.getLineCodes()));
}
if(param.getStationnames().size()>0){
query.addCriteria(Criteria.where("stationname").in(param.getStationnames()));
}
if(param.getAreacodes().size()>0){
query.addCriteria(Criteria.where("areacode").in(param.getAreacodes()));
}
return mongoTemplate.find(query, PFlowLineStationHourEntity.class);
}
}