From b2e95978391f7ac48b876c96ccc64541a6f6cb07 Mon Sep 17 00:00:00 2001 From: xy <748613696@qq.com> Date: Thu, 11 Jun 2026 21:33:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(logs):=20=E9=87=8D=E6=9E=84=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=9C=8D=E5=8A=A1=E7=9B=B8=E5=85=B3=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=92=8C=E7=BA=BF=E8=B7=AF=E6=95=B0=E6=8D=AE=E5=88=86=E6=9E=90?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将CsLogsPOMapper.xml从cs-device模块迁移至cs-system模块 - 更新CsLogsFeignClient的服务器配置从CS_DEVICE_BOOT到CS_SYSTEM_BOOT - 优化CsGroupServiceImpl中的设备线路查询逻辑,直接使用敏感用户ID获取线路数据 - 在StableDataServiceImpl中新增电网侧和负荷侧字典常量定义 - 重构线路数据过滤逻辑,按电网侧和负荷侧分别处理数据 - 添加数据分组处理机制,区分治理前后数据并设置相应标识 --- .../service/impl/CsGroupServiceImpl.java | 7 +- .../service/impl/StableDataServiceImpl.java | 117 +++++++++++------- .../njcn/cssystem/api/CsLogsFeignClient.java | 2 +- .../mapper/mapping/CsLogsPOMapper.xml | 4 +- 4 files changed, 76 insertions(+), 54 deletions(-) rename {cs-device/cs-device-boot/src/main/java/com/njcn/csdevice => cs-system/cs-system-boot/src/main/java/com/njcn/cssystem}/mapper/mapping/CsLogsPOMapper.xml (90%) diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java index 139ac13..d0b46e9 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java @@ -1337,12 +1337,7 @@ public class CsGroupServiceImpl extends ServiceImpl impl result.put("before", new ArrayList<>()); result.put("after", new ArrayList<>()); String sensitiveUserId = param.getSensitiveUserId(); - List devList = csLineFeignClient.getDevBySensitiveUser(Collections.singletonList(sensitiveUserId)).getData(); - if (CollUtil.isEmpty(devList)) { - return result; - } - List devIds = devList.stream().map(CsEquipmentDeliveryPO::getId).collect(Collectors.toList()); - List linePOList = csLineFeignClient.getLinesByDevList(devIds).getData(); + List linePOList = csLineFeignClient.getLinesByDevList(Collections.singletonList(sensitiveUserId)).getData(); DictData loadSideDictData = dicDataFeignClient.getDicDataByCode(LOAD_SIDE_DICT_CODE).getData(); DictData gridSideDictData = dicDataFeignClient.getDicDataByCode(GRID_SIDE_DICT_CODE).getData(); CsLinePO gridSideLine = linePOList.stream().filter(linePO -> linePO.getPosition().equals(gridSideDictData.getId())).findFirst().orElse(null); diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/StableDataServiceImpl.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/StableDataServiceImpl.java index 12a7736..4a8166e 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/StableDataServiceImpl.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/StableDataServiceImpl.java @@ -28,6 +28,7 @@ import com.njcn.system.api.CsStatisticalSetFeignClient; import com.njcn.system.api.DicDataFeignClient; import com.njcn.system.api.EpdFeignClient; import com.njcn.system.enums.DicDataEnum; +import com.njcn.system.pojo.po.DictData; import com.njcn.system.pojo.po.EleEpdPqd; import lombok.RequiredArgsConstructor; import org.influxdb.dto.QueryResult; @@ -63,6 +64,8 @@ public class StableDataServiceImpl implements StableDataService { private final CsStatisticalSetFeignClient csStatisticalSetFeignClient; private final InfluxDbParamUtil influxDbParamUtil; private final EquipmentFeignClient equipmentFeignClient; + private final String GRID_SIDE_DICT_CODE = "Grid_Side"; + private final String LOAD_SIDE_DICT_CODE = "Load_Side"; @Override @@ -251,56 +254,80 @@ public class StableDataServiceImpl implements StableDataService { if(CollectionUtil.isEmpty(csLinePOList)){ throw new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR); } - String areaId = dicDataFeignClient.getDicDataByCode(DicDataEnum.OUTPUT_SIDE.getCode()).getData().getId(); - Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR)); - List csLinePOList1 = csLinePOList.stream().filter(temp -> Objects.equals(areaId, temp.getPosition())).collect(Collectors.toList()); + DictData loadSideDictData = dicDataFeignClient.getDicDataByCode(LOAD_SIDE_DICT_CODE).getData(); + DictData gridSideDictData = dicDataFeignClient.getDicDataByCode(GRID_SIDE_DICT_CODE).getData(); + CsLinePO gridSideLine = csLinePOList.stream().filter(linePO -> linePO.getPosition().equals(gridSideDictData.getId())).findFirst().orElse(null); + CsLinePO loadSideLine = csLinePOList.stream().filter(linePO -> linePO.getPosition().equals(loadSideDictData.getId())).findFirst().orElse(null); + List csLinePOList1 = new ArrayList<>(); + csLinePOList1.add(gridSideLine);csLinePOList1.add(loadSideLine); List data = csStatisticalSetFeignClient.queryStatisticalSelect(Collections.singletonList(commonStatisticalQueryParam.getStatisticalId())).getData(); if(CollectionUtil.isNotEmpty(data)){ - List finalCsLinePOList = csLinePOList; data.forEach(epdPqd->{ - String frequency = Optional.ofNullable(commonStatisticalQueryParam.getFrequency()).orElse(""); - if(StringUtils.isEmpty(commonStatisticalQueryParam.getFrequency())){ - frequency =""; - }else { - frequency = "_"+commonStatisticalQueryParam.getFrequency(); - } - String finalFrequency1 = frequency; - List commonQueryParams = csLinePOList1.stream().map(temp -> { - CommonQueryParam commonQueryParam = new CommonQueryParam(); - commonQueryParam.setLineId(temp.getLineId()); - commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId())); - if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) { - commonQueryParam.setColumnName(epdPqd.getName()+ finalFrequency1); - } else { - commonQueryParam.setColumnName(epdPqd.getOtherName()+ finalFrequency1); + String frequency = Optional.ofNullable(commonStatisticalQueryParam.getFrequency()).orElse(""); + if(StringUtils.isEmpty(commonStatisticalQueryParam.getFrequency())){ + frequency =""; + }else { + frequency = "_"+commonStatisticalQueryParam.getFrequency(); } - commonQueryParam.setPhasic(epdPqd.getPhase()); - commonQueryParam.setStartTime(commonStatisticalQueryParam.getStartTime() + " 00:00:00"); - commonQueryParam.setEndTime(commonStatisticalQueryParam.getEndTime() + " 23:59:59"); - commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType().toUpperCase()); - commonQueryParam.setProcess(data1.get(0).getProcess()+""); - commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId())); + String finalFrequency1 = frequency; + List commonQueryParams = csLinePOList1.stream().map(temp -> { + CommonQueryParam commonQueryParam = new CommonQueryParam(); + commonQueryParam.setLineId(temp.getLineId()); + commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId())); + if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) { + commonQueryParam.setColumnName(epdPqd.getName()+ finalFrequency1); + } else { + commonQueryParam.setColumnName(epdPqd.getOtherName()+ finalFrequency1); + } + commonQueryParam.setPhasic(epdPqd.getPhase()); + commonQueryParam.setStartTime(commonStatisticalQueryParam.getStartTime() + " 00:00:00"); + commonQueryParam.setEndTime(commonStatisticalQueryParam.getEndTime() + " 23:59:59"); + commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType().toUpperCase()); + commonQueryParam.setProcess(data1.get(0).getProcess()+""); + commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId())); - return commonQueryParam; - }).collect(Collectors.toList()); - List deviceRtData = commonService.getDeviceRtDataByTime(commonQueryParams); - - List collect1 = deviceRtData.stream().map(temp -> { - ThdDataVO vo = new ThdDataVO(); - vo.setLineId(temp.getLineId()); - vo.setPhase(temp.getPhaseType()); - String position = finalCsLinePOList.stream().filter(csLinePO -> Objects.equals(csLinePO.getLineId(), vo.getLineId())).collect(Collectors.toList()).get(0).getPosition(); - vo.setPosition(position); - vo.setTime(temp.getTime()); - vo.setStatMethod(temp.getValueType()); - vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); - vo.setStatisticalIndex(epdPqd.getId()); - vo.setUnit(epdPqd.getUnit()); - vo.setStatisticalName(epdPqd.getName()); - vo.setAnotherName(epdPqd.getShowName()); - return vo; - }).collect(Collectors.toList()); - result.addAll(collect1); + return commonQueryParam; + }).collect(Collectors.toList()); + List deviceRtData = commonService.getDeviceRtDataByTime(commonQueryParams); + if (CollectionUtil.isNotEmpty(deviceRtData)) { + Map > map = deviceRtData.stream().collect(Collectors.groupingBy(StatisticalDataDTO::getLineId)); + map.forEach((key, value) -> { + if (!Objects.isNull(loadSideLine) && Objects.equals(key, loadSideLine.getLineId())) { + List collect1 = value.stream().map(temp -> { + ThdDataVO vo = new ThdDataVO(); + vo.setLineId(temp.getLineId()); + vo.setPhase(temp.getPhaseType()); + vo.setPosition(loadSideLine.getPosition()); + vo.setTime(temp.getTime()); + vo.setStatMethod(temp.getValueType()); + vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); + vo.setStatisticalIndex(epdPqd.getId()); + vo.setUnit(epdPqd.getUnit()); + vo.setStatisticalName(epdPqd.getName()); + vo.setAnotherName("治理前"); + return vo; + }).collect(Collectors.toList()); + result.addAll(collect1); + } + if (!Objects.isNull(gridSideLine) && Objects.equals(key, gridSideLine.getLineId())) { + List collect1 = value.stream().map(temp -> { + ThdDataVO vo = new ThdDataVO(); + vo.setLineId(temp.getLineId()); + vo.setPhase(temp.getPhaseType()); + vo.setPosition(gridSideLine.getPosition()); + vo.setTime(temp.getTime()); + vo.setStatMethod(temp.getValueType()); + vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); + vo.setStatisticalIndex(epdPqd.getId()); + vo.setUnit(epdPqd.getUnit()); + vo.setStatisticalName(epdPqd.getName()); + vo.setAnotherName("治理后"); + return vo; + }).collect(Collectors.toList()); + result.addAll(collect1); + } + }); + } }); } return result; diff --git a/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/api/CsLogsFeignClient.java b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/api/CsLogsFeignClient.java index b684195..a248891 100644 --- a/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/api/CsLogsFeignClient.java +++ b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/api/CsLogsFeignClient.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody; /** * @author xy */ -@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/cslog", fallbackFactory = CsLogsClientFallbackFactory.class,contextId = "cslog") +@FeignClient(value = ServerInfo.CS_SYSTEM_BOOT, path = "/cslog", fallbackFactory = CsLogsClientFallbackFactory.class,contextId = "cslog") public interface CsLogsFeignClient { @PostMapping("/add") diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/CsLogsPOMapper.xml b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/mapping/CsLogsPOMapper.xml similarity index 90% rename from cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/CsLogsPOMapper.xml rename to cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/mapping/CsLogsPOMapper.xml index 80c396c..c054caf 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/CsLogsPOMapper.xml +++ b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/mapping/CsLogsPOMapper.xml @@ -1,7 +1,7 @@ - - + +