|
@@ -158,27 +158,103 @@ public class MeterReadRecordDao extends BaseDao<MeterReadRecord, String> impleme
|
|
|
* @param year :年, statDay:具体日期
|
|
|
* @return void
|
|
|
**/
|
|
|
- public List<MeterReadRecordAggregationVo> aggregationCommunityWaterConsumption(int year, int statDay, int pageNum, int pageSzie){
|
|
|
+ public List<MeterReadRecordAggregationVo> aggregationCommunityWaterConsumption(int year, int statDay, int pageNum, int pageSize){
|
|
|
AggregationOptions aggregationOptions = AggregationOptions.builder().allowDiskUse(true).build();
|
|
|
List<AggregationOperation> queryCondition = groupCondition(year, statDay, statDay,
|
|
|
Aggregation.group("tenantId", "companyOrgId", "deptOrgId", "communityId", "categoryId", "data.readDate")
|
|
|
.sum("$data.lastCost").as("waterConsumption"));
|
|
|
// 分页条件
|
|
|
- queryCondition.add(Aggregation.skip(pageNum > 1 ?(pageNum-1) * pageSzie : 0));
|
|
|
- queryCondition.add(Aggregation.limit(pageSzie));
|
|
|
+ queryCondition.add(Aggregation.skip(pageNum > 1 ?(pageNum-1) * pageSize : 0));
|
|
|
+ queryCondition.add(Aggregation.limit(pageSize));
|
|
|
AggregationResults<MeterReadRecordAggregationVo> durationData =
|
|
|
mongoTemplate.aggregate(Aggregation.newAggregation(queryCondition).withOptions(aggregationOptions),
|
|
|
MeterReadRecord.class, MeterReadRecordAggregationVo.class);
|
|
|
return durationData.getMappedResults();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description 查询结算期的用水量
|
|
|
+ * @author hym
|
|
|
+ * @updateTime 2021/7/28 10:25
|
|
|
+ * @throws
|
|
|
+ */
|
|
|
+
|
|
|
+ public List<MeterReadRecord> querySettlementWaterConsumption(Device device, Date clearingStartDate, Date clearingEndDate) {
|
|
|
+ Criteria criteria = new Criteria();
|
|
|
+ criteria.and("deviceId").is(device.getId());
|
|
|
+ Criteria criteria1 = Criteria.where("data.readDate").lte(Integer.valueOf(
|
|
|
+ DateUtil.formatDate(clearingEndDate,"yyyyMMdd")));
|
|
|
+ Criteria criteria2 = Criteria.where("data.readDate").gte(Integer.valueOf(
|
|
|
+ DateUtil.formatDate(clearingStartDate,"yyyyMMdd")));
|
|
|
+ Criteria dayCritera = new Criteria();
|
|
|
+ dayCritera.orOperator(criteria1,criteria2);
|
|
|
+ List<AggregationOperation> countQuery =aggrQueryCondition(criteria,"data",
|
|
|
+ dayCritera,null);
|
|
|
+
|
|
|
+ AggregationOptions aggregationOptions = AggregationOptions.builder().allowDiskUse(true).build();
|
|
|
+ AggregationResults<MeterReadRecord> aggregate = mongoTemplate.aggregate(Aggregation.newAggregation(countQuery).withOptions(aggregationOptions)
|
|
|
+ , MeterReadRecord.class, MeterReadRecord.class);
|
|
|
+ return aggregate.getMappedResults();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @author Andy
|
|
|
- * @description 查询条件
|
|
|
- * @date 10:37 2021/7/23
|
|
|
- * @param dto, query
|
|
|
- * @return java.util.List<org.springframework.data.mongodb.core.aggregation.AggregationOperation>
|
|
|
+ * @description 根据设备ID和读表日期小于endDate,查询设备数据
|
|
|
+ * @date 17:25 2021/8/2
|
|
|
+ * @param id, endDate
|
|
|
+ * @return java.util.List<com.zcxk.rmcp.core.mongo.MeterReadRecord>
|
|
|
+ **/
|
|
|
+ public List<MeterReadRecord> queryDeviceMeterReadRecordWithCondtion(Long id, int endDate) {
|
|
|
+ return listSingleDeviceTimeData(id, null, endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author Andy
|
|
|
+ * @description 根据设备ID和读表日期大于startDate且小于endDate,查询设备记录
|
|
|
+ * @date 17:26 2021/8/2
|
|
|
+ * @param id, startDate, endDate
|
|
|
+ * @return java.util.List<com.zcxk.rmcp.core.mongo.MeterReadRecord>
|
|
|
+ **/
|
|
|
+ public List<MeterReadRecord> queryDeviceMeterReadRecordWithCondtion(Long id, Integer startDate, Integer endDate) {
|
|
|
+ return listSingleDeviceTimeData(id, startDate, endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author Andy
|
|
|
+ * @description 根据设备ID和读表日期大于startDate且小于endDate, 查询设备数据
|
|
|
+ * @date 17:26 2021/8/2
|
|
|
+ * @param deviceId, startDate, endDate
|
|
|
+ * @return java.util.List<com.zcxk.rmcp.core.mongo.MeterReadRecord>
|
|
|
**/
|
|
|
+ public List<MeterReadRecord> listSingleDeviceTimeData(Long deviceId, Integer startDate, Integer endDate){
|
|
|
+ Criteria criteria = new Criteria();
|
|
|
+ criteria.and("deviceId").is(deviceId);
|
|
|
+ Criteria dayCritera = new Criteria();
|
|
|
+ if (startDate != null && endDate != null) {
|
|
|
+ dayCritera.and("data.readDate").gte(startDate).lte(endDate);
|
|
|
+ } else if (startDate != null) {
|
|
|
+ dayCritera.and("data.readDate").gte(startDate);
|
|
|
+ } else if (endDate != null) {
|
|
|
+ dayCritera.and("data.readDate").lte(endDate);
|
|
|
+ }
|
|
|
+ List<AggregationOperation> countQuery = aggrQueryCondition(criteria,"data",
|
|
|
+ dayCritera,null);
|
|
|
+ countQuery.add(Aggregation.sort(Sort.Direction.DESC,"data.readTime"));
|
|
|
+ AggregationOptions aggregationOptions = AggregationOptions.builder().allowDiskUse(true).build();
|
|
|
+ AggregationResults<MeterReadRecord> aggregate = mongoTemplate.aggregate(Aggregation.newAggregation(countQuery).withOptions(aggregationOptions)
|
|
|
+ , MeterReadRecord.class, MeterReadRecord.class);
|
|
|
+ return aggregate.getMappedResults();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author Andy
|
|
|
+ * @description 查询条件
|
|
|
+ * @date 10:37 2021/7/23
|
|
|
+ * @param dto, query
|
|
|
+ * @return java.util.List<org.springframework.data.mongodb.core.aggregation.AggregationOperation>
|
|
|
+ **/
|
|
|
private List<AggregationOperation> queryCondition(MeterReadRecordDto dto, UserCondition userCondition){
|
|
|
LocalDate localDate;
|
|
|
List<AggregationOperation> commonOperations = new ArrayList<>();
|
|
@@ -228,12 +304,12 @@ public class MeterReadRecordDao extends BaseDao<MeterReadRecord, String> impleme
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @author Andy
|
|
|
- * @description 分组查询
|
|
|
- * @date 18:36 2021/7/27
|
|
|
- * @param year, beginDate, endDate, groupOperation
|
|
|
- * @return java.util.List<org.springframework.data.mongodb.core.aggregation.AggregationOperation>
|
|
|
- **/
|
|
|
+ * @author Andy
|
|
|
+ * @description 分组查询
|
|
|
+ * @date 18:36 2021/7/27
|
|
|
+ * @param year, beginDate, endDate, groupOperation
|
|
|
+ * @return java.util.List<org.springframework.data.mongodb.core.aggregation.AggregationOperation>
|
|
|
+ **/
|
|
|
private List<AggregationOperation> groupCondition(int year, int readDateBeginDate, int readDateEndDate, GroupOperation groupOperation){
|
|
|
Criteria criteria = new Criteria();
|
|
|
criteria.and("year").is(year);
|
|
@@ -247,12 +323,12 @@ public class MeterReadRecordDao extends BaseDao<MeterReadRecord, String> impleme
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @author Andy
|
|
|
- * @description 获取总条数
|
|
|
- * @date 10:34 2021/7/23
|
|
|
- * @param commonOperations
|
|
|
- * @return int
|
|
|
- **/
|
|
|
+ * @author Andy
|
|
|
+ * @description 获取总条数
|
|
|
+ * @date 10:34 2021/7/23
|
|
|
+ * @param commonOperations
|
|
|
+ * @return int
|
|
|
+ **/
|
|
|
private int getAggregationCount(List<AggregationOperation> commonOperations) {
|
|
|
List<AggregationOperation> countQuery = new ArrayList<>(commonOperations);
|
|
|
countQuery.add(Aggregation.count().as("count"));
|
|
@@ -264,45 +340,4 @@ public class MeterReadRecordDao extends BaseDao<MeterReadRecord, String> impleme
|
|
|
List<Map> mappedResults = aggregate.getMappedResults();
|
|
|
return CollectionUtils.isEmpty(mappedResults) ? 0 : ZoniotIntegerUtils.parseInt(mappedResults.get(0).get("count"));
|
|
|
}
|
|
|
- /**
|
|
|
- *
|
|
|
- * @description 查询结算期的用水量
|
|
|
- * @author hym
|
|
|
- * @updateTime 2021/7/28 10:25
|
|
|
- * @throws
|
|
|
- */
|
|
|
-
|
|
|
- public List<MeterReadRecord> querySettlementWaterConsumption(Device device, Date clearingStartDate, Date clearingEndDate) {
|
|
|
-
|
|
|
-
|
|
|
- Criteria criteria = new Criteria();
|
|
|
- criteria.and("deviceId").is(device.getId());
|
|
|
- Criteria criteria1 = Criteria.where("data.readDate").lte(Integer.valueOf(
|
|
|
- DateUtil.formatDate(clearingEndDate,"yyyyMMdd")));
|
|
|
- Criteria criteria2 = Criteria.where("data.readDate").gte(Integer.valueOf(
|
|
|
- DateUtil.formatDate(clearingStartDate,"yyyyMMdd")));
|
|
|
- Criteria dayCritera = new Criteria();
|
|
|
- dayCritera.orOperator(criteria1,criteria2);
|
|
|
- List<AggregationOperation> countQuery =aggrQueryCondition(criteria,"data",
|
|
|
- dayCritera,null);
|
|
|
-
|
|
|
- AggregationOptions aggregationOptions = AggregationOptions.builder().allowDiskUse(true).build();
|
|
|
- AggregationResults<MeterReadRecord> aggregate = mongoTemplate.aggregate(Aggregation.newAggregation(countQuery).withOptions(aggregationOptions)
|
|
|
- , MeterReadRecord.class, MeterReadRecord.class);
|
|
|
- return aggregate.getMappedResults();
|
|
|
- }
|
|
|
-
|
|
|
- public List<MeterReadRecord> queryDeviceMeterReadRecordWithCondtion(Long id, int endDate) {
|
|
|
- Criteria criteria = new Criteria();
|
|
|
- criteria.and("deviceId").is(id);
|
|
|
- Criteria dayCritera = new Criteria();
|
|
|
- dayCritera.and("data.readDate").lte(endDate);
|
|
|
- List<AggregationOperation> countQuery =aggrQueryCondition(criteria,"data",
|
|
|
- dayCritera,null);
|
|
|
- countQuery.add(Aggregation.sort(Sort.Direction.DESC,"data.readTime"));
|
|
|
- AggregationOptions aggregationOptions = AggregationOptions.builder().allowDiskUse(true).build();
|
|
|
- AggregationResults<MeterReadRecord> aggregate = mongoTemplate.aggregate(Aggregation.newAggregation(countQuery).withOptions(aggregationOptions)
|
|
|
- , MeterReadRecord.class, MeterReadRecord.class);
|
|
|
- return aggregate.getMappedResults();
|
|
|
- }
|
|
|
}
|