|
@@ -11,6 +11,7 @@ import com.zcxk.core.utils.ZoniotStringUtils;
|
|
|
import com.zcxk.rmcp.api.dto.meterReadRecord.MeterReadRecordDto;
|
|
|
import com.zcxk.rmcp.api.dto.meterReadRecord.MeterReadRecordUpdateDto;
|
|
|
import com.zcxk.rmcp.api.enums.ReadStatusEnum;
|
|
|
+import com.zcxk.rmcp.api.vo.MeterReadRecordAggregaVo;
|
|
|
import com.zcxk.rmcp.api.vo.MeterReadRecordVo;
|
|
|
import com.zcxk.rmcp.core.mongo.MeterReadRecord;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
@@ -146,6 +147,27 @@ public class MeterReadRecordDao extends BaseDao<MeterReadRecord, String> impleme
|
|
|
return PageResult.builder(durationData.getMappedResults(), pageable.getPageNumber() + 1, pageable.getPageSize(), total);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @author Andy
|
|
|
+ * @description 聚合小区每天用水量
|
|
|
+ * @date 9:27 2021/7/28
|
|
|
+ * @param year :年, statDay:具体日期
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public List<MeterReadRecordAggregaVo> aggregationCommunityWaterConsumption(int year, String statDay){
|
|
|
+ AggregationOptions aggregationOptions = AggregationOptions.builder().allowDiskUse(true).build();
|
|
|
+ List<AggregationOperation> queryCondition = groupCondition(year, statDay, statDay,
|
|
|
+ Aggregation.group("tenantId", "companyOrgId", "deptOrgId", "communityId", "data.readDate")
|
|
|
+ .sum("$data.lastCost").as("cost"));
|
|
|
+ AggregationResults<MeterReadRecordAggregaVo> durationData =
|
|
|
+ mongoTemplate.aggregate(Aggregation.newAggregation(queryCondition).withOptions(aggregationOptions),
|
|
|
+ MeterReadRecord.class, MeterReadRecordAggregaVo.class);
|
|
|
+ for (MeterReadRecordAggregaVo mappedResult : durationData.getMappedResults()) {
|
|
|
+ System.out.println(mappedResult.toString());
|
|
|
+ }
|
|
|
+ return durationData.getMappedResults();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @author Andy
|
|
|
* @description 查询条件
|
|
@@ -200,6 +222,26 @@ public class MeterReadRecordDao extends BaseDao<MeterReadRecord, String> impleme
|
|
|
return commonOperations;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @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, String readDateBeginDate, String readDateEndDate, GroupOperation groupOperation){
|
|
|
+ Criteria criteria = new Criteria();
|
|
|
+ criteria.and("year").is(year);
|
|
|
+ Criteria unwindCriteria = null;
|
|
|
+ if (readDateBeginDate.equals(readDateEndDate)) {
|
|
|
+ unwindCriteria = Criteria.where("data.readDate").is(readDateBeginDate);
|
|
|
+ } else {
|
|
|
+ unwindCriteria = Criteria.where("data.readDate").gte(readDateBeginDate).lte(readDateEndDate);
|
|
|
+ }
|
|
|
+ return aggrQueryCondition(criteria, "data", unwindCriteria, groupOperation);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @author Andy
|
|
|
* @description 获取总条数
|