| | |
| | | package com.zhitan.peakvalley.service.impl; |
| | | |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.zhitan.common.enums.ElectricityTypeEnum; |
| | | import com.zhitan.common.enums.TimeType; |
| | | import com.zhitan.common.utils.DateUtils; |
| | | import com.zhitan.model.domain.vo.ModelNodeIndexInfor; |
| | | import com.zhitan.costmanagement.mapper.CostPriceRelevancyMapper; |
| | | import com.zhitan.model.domain.vo.ModelNodeIndexInfo; |
| | | import com.zhitan.model.mapper.ModelNodeMapper; |
| | | import com.zhitan.peakvalley.domain.ElectricityDataItem; |
| | | import com.zhitan.peakvalley.domain.dto.ElectricityDataItemListDTO; |
| | |
| | | private ModelNodeMapper modelNodeMapper; |
| | | @Resource |
| | | private PeakValleyMapper electricityDataItemMapper; |
| | | |
| | | @Resource |
| | | CostPriceRelevancyMapper costPriceRelevancyMapper; |
| | | |
| | | /** |
| | | * 查询统计数据 |
| | | * |
| | | * @param dto 请求参数 |
| | | * @return 结果 |
| | | * 查询尖峰平谷统计数据 |
| | | * @param dto 请求参数,包含模型代码、节点ID、查询时间、时间类型等 |
| | | * @return 按时间段分隔的统计结果列表 |
| | | * |
| | | * 业务步骤: |
| | | * 1. 根据查询时间确定起止时间范围 |
| | | * 2. 查询模型节点关联的指标信息 |
| | | * 3. 根据指标ID集合查询原始数据 |
| | | * 4. 按时间分组处理数据 |
| | | * 5. 循环遍历时间区间,统计各时段的费用和用电量 |
| | | */ |
| | | @Override |
| | | public List<PeakValleyHourDataVO> getDataStatistics(ElectricityDataItemListDTO dto) { |
| | |
| | | |
| | | Map<String, List<ElectricityDataItem>> electricityDataMap = new HashMap<>(); |
| | | // 查询点位信息 |
| | | List<ModelNodeIndexInfor> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | List<ModelNodeIndexInfo> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | if (CollectionUtils.isNotEmpty(nodeIndexInfoList)) { |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfor::getIndexId).collect(Collectors.toSet()); |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfo::getIndexId).collect(Collectors.toSet()); |
| | | List<ElectricityDataItem> dataItemList = electricityDataItemMapper.getDataStatistics(indexSet, startTime, endTime, timeType); |
| | | |
| | | electricityDataMap = dataItemList.stream() |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 按天维度进行尖峰平谷分时段分析 |
| | | * @param dto 请求参数,包含模型代码、节点ID、查询时间等 |
| | | * @return 包含日统计总览和图表数据的VO对象 |
| | | * |
| | | * 业务步骤: |
| | | * 1. 初始化统计容器和时间范围 |
| | | * 2. 查询关联指标并获取原始数据 |
| | | * 3. 按天聚合数据并计算各时段费用和用电量 |
| | | * 4. 生成费用/用电量折线图数据 |
| | | * 5. 计算总消耗量及各时段占比 |
| | | * 6. 汇总生成最终结果对象 |
| | | */ |
| | | @Override |
| | | public PeakValleyDayVO segmentAnalysisDay(PeakValleyDTO dto) { |
| | | PeakValleyDayVO peakValleyVO = new PeakValleyDayVO(); |
| | |
| | | |
| | | Map<String, List<ElectricityDataItem>> electricityDataMap = new HashMap<>(); |
| | | // 查询点位信息 |
| | | List<ModelNodeIndexInfor> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | List<ModelNodeIndexInfo> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | if (CollectionUtils.isNotEmpty(nodeIndexInfoList)) { |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfor::getIndexId).collect(Collectors.toSet()); |
| | | List<ElectricityDataItem> dataItemList = electricityDataItemMapper.getDataStatistics(indexSet, startTime, endTime, timeType); |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfo::getIndexId).collect(Collectors.toSet()); |
| | | // 根据小时数据计算天的数据 |
| | | List<ElectricityDataItem> dataItemList = electricityDataItemMapper.getDataStatistics(indexSet, startTime, endTime, TimeType.HOUR.name()); |
| | | |
| | | electricityDataMap = dataItemList.stream() |
| | | .collect(Collectors.groupingBy(li -> DateUtil.formatDateTime(li.getDataTime()))); |
| | | } |
| | | while (!startTime.after(endTime)) { |
| | | String mapKey = DateUtil.formatDateTime(startTime); |
| | | List<ElectricityDataItem> dataItemList = electricityDataMap.get(mapKey); |
| | | |
| | | Date nextTime = DateUtil.offsetDay(startTime, 1); |
| | | List<ElectricityDataItem> dataItemList = new ArrayList<>(); |
| | | for (Map.Entry<String, List<ElectricityDataItem>> entry : electricityDataMap.entrySet()) { |
| | | String key = entry.getKey(); |
| | | if ((DateUtils.parseDate(key).after(startTime) || DateUtils.parseDate(key).equals(startTime)) && DateUtils.parseDate(key).before(nextTime)) { |
| | | List<ElectricityDataItem> list = entry.getValue(); |
| | | dataItemList.addAll(list); |
| | | } |
| | | } |
| | | |
| | | BigDecimal sharpFee = BigDecimal.ZERO; |
| | | BigDecimal sharpPower = BigDecimal.ZERO; |
| | |
| | | AtomicReference<BigDecimal> tipCount = new AtomicReference<>(BigDecimal.ZERO); |
| | | AtomicReference<BigDecimal> troughCount = new AtomicReference<>(BigDecimal.ZERO); |
| | | AtomicReference<BigDecimal> peakCount = new AtomicReference<>(BigDecimal.ZERO); |
| | | |
| | | |
| | | reportVOList.stream().forEach(r->{ |
| | | PeakValleyLineChatVO costVO = new PeakValleyLineChatVO(); |
| | | PeakValleyLineChatVO powerConsumptionVO = new PeakValleyLineChatVO(); |
| | | |
| | | |
| | | /** |
| | | * 用电量 |
| | | */ |
| | |
| | | peakFreeCount.set(peakFreeCount.get().add(r.getPeakFee())); |
| | | }); |
| | | |
| | | peakValleyDayTotalVO.setPeakPowerCost(peakFreeCount.get().doubleValue()); |
| | | peakValleyDayTotalVO.setPeakPowerCost(peakFreeCount.get().doubleValue()); |
| | | peakValleyDayTotalVO.setPeakPowerConsumption(peakCount.get().doubleValue()); |
| | | peakValleyDayTotalVO.setFlatPowerCost(flatFreeCount.get().doubleValue()); |
| | | peakValleyDayTotalVO.setFlatPowerConsumption(flatCount.get().doubleValue()); |
| | |
| | | peakValleyDayTotalVO.setTipPowerCostProportion(0); |
| | | peakValleyDayTotalVO.setTroughPowerCostProportion(0); |
| | | } |
| | | |
| | | peakValleyDayTotalVO.setTotalCost(powerTotal.doubleValue()); |
| | | peakValleyDayTotalVO.setTotalPowerConsumption(freeTotal.doubleValue()); |
| | | |
| | | // peakValleyDayTotalVO.setTotalCost(powerTotal.doubleValue()); |
| | | // peakValleyDayTotalVO.setTotalPowerConsumption(freeTotal.doubleValue()); |
| | | peakValleyDayTotalVO.setTotalCost(freeTotal.doubleValue()); |
| | | peakValleyDayTotalVO.setTotalPowerConsumption(powerTotal.doubleValue()); |
| | | peakValleyVO.setTotalVO(peakValleyDayTotalVO); |
| | | peakValleyVO.setCostList(costList); |
| | | peakValleyVO.setPowerConsumptionList(powerConsumptionList); |
| | | |
| | | |
| | | return peakValleyVO; |
| | | } |
| | | |
| | | /** |
| | | * 按小时维度进行尖峰平谷分时段分析 |
| | | * @param dto 请求参数,包含模型代码、节点ID、查询时间等 |
| | | * @return 包含小时级数据和可视化图表的VO对象 |
| | | * |
| | | * 业务步骤: |
| | | * 1. 初始化统计容器和时间范围 |
| | | * 2. 查询关联指标并获取原始数据 |
| | | * 3. 按小时统计各时段费用和用电量 |
| | | * 4. 生成用电量折线图数据 |
| | | * 5. 计算总用电量及各时段占比饼图数据 |
| | | * 6. 汇总生成最终结果对象 |
| | | */ |
| | | @Override |
| | | public PeakValleyHourVO segmentAnalysisHour(PeakValleyDTO dto) { |
| | | PeakValleyHourVO peakValleyVO = new PeakValleyHourVO(); |
| | |
| | | |
| | | Map<String, List<ElectricityDataItem>> electricityDataMap = new HashMap<>(); |
| | | // 查询点位信息 |
| | | List<ModelNodeIndexInfor> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | List<ModelNodeIndexInfo> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | if (CollectionUtils.isNotEmpty(nodeIndexInfoList)) { |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfor::getIndexId).collect(Collectors.toSet()); |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfo::getIndexId).collect(Collectors.toSet()); |
| | | List<ElectricityDataItem> dataItemList = electricityDataItemMapper.getDataStatistics(indexSet, startTime, endTime, timeType); |
| | | |
| | | electricityDataMap = dataItemList.stream() |
| | |
| | | return peakValleyVO; |
| | | } |
| | | |
| | | /** |
| | | * 导出小时级尖峰平谷分析数据 |
| | | * @param dto 请求参数,包含模型代码、节点ID、查询时间等 |
| | | * @return 小时级详细统计数据列表 |
| | | * |
| | | * 业务步骤: |
| | | * 1. 初始化时间范围 |
| | | * 2. 查询关联指标并获取原始数据 |
| | | * 3. 按小时统计各时段数据 |
| | | * 4. 生成可导出的详细数据列表 |
| | | */ |
| | | @Override |
| | | public List<PeakValleyHourDataVO> segmentAnalysisHourExport(PeakValleyDTO dto) { |
| | | List<PeakValleyHourDataVO> reportVOList = new ArrayList<>(); |
| | |
| | | |
| | | Map<String, List<ElectricityDataItem>> electricityDataMap = new HashMap<>(); |
| | | // 查询点位信息 |
| | | List<ModelNodeIndexInfor> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | List<ModelNodeIndexInfo> nodeIndexInfoList = modelNodeMapper.selectIndexByModelCodeAndNodeId(dto.getModelCode(), dto.getNodeId()); |
| | | if (CollectionUtils.isNotEmpty(nodeIndexInfoList)) { |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfor::getIndexId).collect(Collectors.toSet()); |
| | | Set<String> indexSet = nodeIndexInfoList.stream().map(ModelNodeIndexInfo::getIndexId).collect(Collectors.toSet()); |
| | | List<ElectricityDataItem> dataItemList = electricityDataItemMapper.getDataStatistics(indexSet, startTime, endTime, timeType); |
| | | |
| | | electricityDataMap = dataItemList.stream() |
| | |
| | | |
| | | return reportVOList; |
| | | } |
| | | |
| | | /** |
| | | * 自定义时段的尖峰平谷分析(预留接口) |
| | | * @param dto 请求参数,包含自定义时间范围等 |
| | | * @return 分析结果对象 |
| | | * |
| | | * 当前实现:暂未开发,返回空值 |
| | | */ |
| | | @Override |
| | | public PeakValleyDayVO segmentAnalysisDayCustomize(PeakValleyDTO dto) { |
| | | return null; |
| | | } |
| | | } |