diff --git a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimitUtil.java b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimitUtil.java index d01247fd9..ec8329141 100644 --- a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimitUtil.java +++ b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimitUtil.java @@ -56,7 +56,7 @@ public class COverlimitUtil { /** - * 电压限值 + * 电压偏差限值 * */ public static void voltageDeviation(Overlimit overlimit,Float voltageLevel) { diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/TerminalBaseServiceImpl.java b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/TerminalBaseServiceImpl.java index b09efaa57..c91e963c3 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/TerminalBaseServiceImpl.java +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/TerminalBaseServiceImpl.java @@ -1792,6 +1792,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl imple DeviceBak deviceBak = new DeviceBak(); deviceBak.setId(temp.getId()); deviceBak.setDevId(oracleTerminalExcel.getDeviceId()); + deviceBakService.removeById(oracleTerminalExcel.getDeviceId()); deviceBakService.saveOrUpdate(deviceBak); } //添加终端索引 @@ -1907,6 +1908,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl imple LineBak lineBak = new LineBak(); lineBak.setId(temp.getId()); lineBak.setLineId(oracleTerminalExcel.getId()); + lineBakService.removeById(oracleTerminalExcel.getId()); lineBakService.save(lineBak); OverLimitExcel overLimitExcel = overLimitList.get(0); Overlimit overlimit = new Overlimit(); diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/THDistortionServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/THDistortionServiceImpl.java index 022c34406..d4294834c 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/THDistortionServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/THDistortionServiceImpl.java @@ -34,6 +34,7 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -51,38 +52,36 @@ public class THDistortionServiceImpl implements THDistortionService { private final THDistortionMapper thDistortionMapper; - private final InfluxDbUtils influxDbUtils; - private final RMpVThdMapper rMpVThdMapper; + private final LineFeignClient lineFeignClient; + private final IRStatDataVDService statDataVDService; @Override public List getTHDistortionData(DeviceInfoParam.BusinessParam thDistortionParam) { List thDistortionVOS = new ArrayList<>(); - List lineList = new ArrayList<>(); //按照条件获取实际运行终端综合信息 List deviceList = generalDeviceInfoClient.getPracticalRunDeviceInfo(new DeviceInfoParam(thDistortionParam.getStatisticalType(), thDistortionParam.getDeptIndex(), generalInfo.getMicroServiceName(), thDistortionParam.getScale(), thDistortionParam.getManufacturer(), thDistortionParam.getLoadType())).getData(); //组装监测点Top层集合 for (GeneralDeviceDTO generalDeviceDTO : deviceList) { - if (CollectionUtils.isEmpty(generalDeviceDTO.getDeviceIndexes())) { + List lineIndexes = generalDeviceDTO.getLineIndexes(); + if (CollectionUtils.isEmpty(lineIndexes)) { continue; } THDistortionVO thDistortionVO = new THDistortionVO(); thDistortionVO.setId(generalDeviceDTO.getIndex()); thDistortionVO.setName(generalDeviceDTO.getName()); - if (!CollectionUtils.isEmpty(generalDeviceDTO.getLineIndexes())) { - List lineIndexes = generalDeviceDTO.getLineIndexes(); - //查找畸变率 - List condition = getCondition(lineIndexes, thDistortionParam.getSearchBeginTime(), thDistortionParam.getSearchEndTime()); - thDistortionVO.setDistortion(roundHalfUp(condition.stream().mapToDouble(PublicDTO::getData).average().orElse(3.14159))); - //组装父级数据树 - List treeList = getTreeData(lineIndexes, thDistortionParam); - thDistortionVO.setChildren(treeList); + //查找畸变率 + List condition = getCondition(lineIndexes, thDistortionParam.getSearchBeginTime(), thDistortionParam.getSearchEndTime()); + thDistortionVO.setDistortion(roundHalfUp(condition.stream().mapToDouble(PublicDTO::getData).average().orElse(3.14159))); + //组装父级数据树 + List treeList = getTreeData(lineIndexes, condition); + thDistortionVO.setChildren(treeList); + - } thDistortionVOS.add(thDistortionVO); } @@ -135,10 +134,10 @@ public class THDistortionServiceImpl implements THDistortionService { /*监测点ID扁平化*/ List collect = deviceList.stream().map(GeneralDeviceDTO::getLineIndexes).flatMap(Collection::stream).distinct().collect(Collectors.toList()); QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.select ("measurement_point_id","max(v_thd) as v_thd") + wrapper.select("measurement_point_id", "max(v_thd) as v_thd") .in("measurement_point_id", collect) .between("data_date", statisticsBizBaseParam.getStartTime(), statisticsBizBaseParam.getEndTime()) - .eq("data_type", 0).groupBy ("measurement_point_id") + .eq("data_type", 0).groupBy("measurement_point_id") .orderByDesc("v_thd"); List rMpVThdList = rMpVThdMapper.selectList(wrapper); rMpVThdVOList = rMpVThdList.stream().limit(topNum).map(rMpVThd -> { @@ -193,7 +192,7 @@ public class THDistortionServiceImpl implements THDistortionService { /** * 获取父级每层数据 */ - private List getTreeData(List lineIndexes, DeviceInfoParam.BusinessParam thDistortionParam) { + private List getTreeData(List lineIndexes,List condition) { //监测点集合 List monitorList = thDistortionMapper.getLineData(lineIndexes); //母线集合 @@ -205,21 +204,18 @@ public class THDistortionServiceImpl implements THDistortionService { //供电公司集合 List powerCompanyList = thDistortionMapper.getLineInfoByList(substationList.stream().map(THDistortionVO::getPid).distinct().collect(Collectors.toList())); - //查询监测点谐波畸变率 - List condition = getCondition(lineIndexes, thDistortionParam.getSearchBeginTime(), thDistortionParam.getSearchEndTime()); - if (!CollectionUtils.isEmpty(monitorList)) { - //根据监测点集合组装谐波畸变率 - monitorList.stream().map(list1 -> condition.stream().filter(list2 -> Objects.equals(list1.getId(), list2.getId())).findAny().map(m -> { - list1.setDistortion(roundHalfUp(m.getData())); - return list1; - })).collect(Collectors.toList()); - // busBarList.stream().peek(item -> item.setChildren(getChildCategoryList(item, monitorList))).collect(Collectors.toList()); - // deviceList.stream().peek(item -> item.setChildren(getChildCategoryList(item, busBarList))).collect(Collectors.toList()); - // substationList.stream().peek(item -> item.setChildren(getChildesList(item, monitorList))).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(monitorList)) { + Map map = condition.stream().collect(Collectors.toMap(PublicDTO::getId, Function.identity())); + + for(THDistortionVO thDistortionVO:monitorList) { + if (map.containsKey(thDistortionVO.getId())) { + thDistortionVO.setDistortion(map.get(thDistortionVO.getId()).getData()); + } + } setChildesList(substationList, monitorList); setFatherDistortion(substationList); - powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList()); + powerCompanyList = powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList()); setFatherDistortion(powerCompanyList); } @@ -229,7 +225,7 @@ public class THDistortionServiceImpl implements THDistortionService { /** * 四舍五入保留两位小数 */ - private Double roundHalfUp (double num) { + private Double roundHalfUp(double num) { if (num == 3.14159) { return num; } @@ -248,33 +244,22 @@ public class THDistortionServiceImpl implements THDistortionService { */ private List getCondition(List lineIndexes, String startTime, String endTime) { List publicDTOList = new ArrayList<>(); - List phasicType = new ArrayList<>(); - phasicType.add(Param.PHASIC_TYPEA); - phasicType.add(Param.PHASIC_TYPEB); - phasicType.add(Param.PHASIC_TYPEC); //数据库查询 - List info = statDataVDService.list(new LambdaQueryWrapper() - .in(RStatDataVD::getLineId, lineIndexes) - .ge(StrUtil.isNotBlank(startTime), RStatDataVD::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime))) - .le(StrUtil.isNotBlank(endTime), RStatDataVD::getTime, DateUtil.endOfDay(DateUtil.parse(endTime))) + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.select("max(v_thd) vThd,measurement_point_id").lambda() + .in(RMpVThd::getMeasurementPointId, lineIndexes) + .ge(StrUtil.isNotBlank(startTime), RMpVThd::getDataDate, DateUtil.beginOfDay(DateUtil.parse(startTime))) + .le(StrUtil.isNotBlank(endTime), RMpVThd::getDataDate, DateUtil.endOfDay(DateUtil.parse(endTime))) + .eq(RMpVThd::getDataType, 0).groupBy(RMpVThd::getMeasurementPointId); -// .eq(RStatDataVD::getQualityFlag, 1) - .eq(RStatDataVD::getQualityFlag, 0) - .in(RStatDataVD::getPhasicType, phasicType) - .eq(RStatDataVD::getValueType, Param.VALUE_TYPEAVG) - ); + List info = rMpVThdMapper.selectList(queryWrapper); if (CollUtil.isNotEmpty(info)) { - //根据id分组,先乘以100.在取平均值,在四舍五入 - Map> collect = info.stream().filter(x -> x.getVThd() != null).collect(Collectors.groupingBy(RStatDataVD::getLineId, Collectors.mapping(RStatDataVD::getVThd, Collectors.toList()))); - Map vthdMap = info.stream().filter(x -> x.getVThd() != null).collect(Collectors.groupingBy(RStatDataVD::getLineId, - Collectors.averagingDouble(x -> x.getVThd().setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()))); - PublicDTO publicDTO; - for (Map.Entry entry : vthdMap.entrySet()) { - publicDTO = new PublicDTO(); - publicDTO.setId(entry.getKey()); - publicDTO.setData(entry.getValue()); + info.forEach(item->{ + PublicDTO publicDTO = new PublicDTO(); + publicDTO.setId(item.getMeasurementPointId()); + publicDTO.setData(item.getVThd()); publicDTOList.add(publicDTO); - } + }); } return publicDTOList; }