diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/WlRecordServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/WlRecordServiceImpl.java index 700d826..fbd10d6 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/WlRecordServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/WlRecordServiceImpl.java @@ -455,108 +455,154 @@ public class WlRecordServiceImpl extends ServiceImpl i //格式化前端参数 formatQueryParamList(commonStatisticalQueryParam); if(commonStatisticalQueryParam.getList() != null && !commonStatisticalQueryParam.getList().isEmpty()){ - for (CommonStatisticalQueryParam param : commonStatisticalQueryParam.getList()){ - if(param.getStatisticalId() == null){ - continue; + for (CommonStatisticalQueryParam param : commonStatisticalQueryParam.getList()){ + if(param.getStatisticalId() == null){ + continue; + } + List eleEpdPqds = csStatisticalSetFeignClient.queryStatisticalSelect(param.getStatisticalId()).getData(); + for(WlRecord wl : data){ + List finalCsLinePOList = csLineFeignClient.queryLineById(Arrays.asList(wl.getLineId())).getData(); + CsDataSet csDataSet = csDataSetMapper.selectOne(new LambdaQueryWrapper().eq(CsDataSet::getId,finalCsLinePOList.get(0).getDataSetId())); + if(StrUtil.isBlank(csDataSet.getDataLevel())){ + throw new BusinessException("当前测点数据集主要信息缺失,请联系管理员排查(测点表里面数据集id缺失)"); } - List eleEpdPqds = csStatisticalSetFeignClient.queryStatisticalSelect(param.getStatisticalId()).getData(); - for(WlRecord wl : data){ - List finalCsLinePOList = csLineFeignClient.queryLineById(Arrays.asList(wl.getLineId())).getData(); - CsDataSet csDataSet = csDataSetMapper.selectOne(new LambdaQueryWrapper().eq(CsDataSet::getId,finalCsLinePOList.get(0).getDataSetId())); - if(StrUtil.isBlank(csDataSet.getDataLevel())){ - throw new BusinessException("当前测点数据集主要信息缺失,请联系管理员排查(测点表里面数据集id缺失)"); - } - Double ct = Double.valueOf(wlRecord.getCt())/wlRecord.getCt1(); - Double pt =Double.valueOf(wlRecord.getPt())/wlRecord.getPt1(); + Double ct = Double.valueOf(wlRecord.getCt())/wlRecord.getCt1(); + Double pt =Double.valueOf(wlRecord.getPt())/wlRecord.getPt1(); - List data1 = equipmentFeignClient.queryDeviceById(Stream.of(wl.getDevId()).collect(Collectors.toList())).getData(); - eleEpdPqds.forEach(epdPqd->{ - List commonQueryParams = finalCsLinePOList.stream().map(temp -> { - CommonQueryParam commonQueryParam = new CommonQueryParam(); - commonQueryParam.setLineId(temp.getLineId()); - commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId())); - commonQueryParam.setColumnName(epdPqd.getName()+ (param.getFrequency() == null ? "":"_"+param.getFrequency())); - commonQueryParam.setPhasic(epdPqd.getPhase()); - commonQueryParam.setStartTime(LocalDateTimeUtil.format(wl.getStartTime(), DateTimeFormatter.ofPattern(DataParam.timeFormat))); - commonQueryParam.setEndTime(LocalDateTimeUtil.format(wl.getEndTime(), DateTimeFormatter.ofPattern(DataParam.timeFormat))); - commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType()); - commonQueryParam.setProcess(data1.get(0).getProcess()+""); - commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId())); - return commonQueryParam; - }).collect(Collectors.toList()); - List deviceRtData = commonService.getDeviceRtDataByTime(commonQueryParams); - //此处设空时为了有多段时将线条断开前端显示 - if(!CollectionUtils.isEmpty(deviceRtData)){ - deviceRtData.get(deviceRtData.size()-1).setValue(null); - } - List collect1 = deviceRtData.stream().map(temp -> { - String unit; - ThdDataVO vo = new ThdDataVO(); - vo.setLineId(temp.getLineId()); - vo.setPhase(Objects.equals("M",temp.getPhaseType())?null: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()); - if(temp.getValue()!=null) { - double re; - if (Objects.equals("Primary",commonStatisticalQueryParam.getDataLevel())) { - if (Objects.equals("Primary",csDataSet.getDataLevel())) { - vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); - unit = epdPqd.getUnit(); - } else { - if (HarmonicConstant.POWER_LIST.contains(epdPqd.getShowName())) { - re = DataChangeUtil.secondaryToPrimary(epdPqd.getPrimaryFormula(), temp.getValue(), pt, ct) / 1000; - vo.setStatisticalData(Double.valueOf(df.format(re))); - unit = "k" + epdPqd.getUnit(); - } else { - vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); - unit = epdPqd.getUnit(); - } - } - } else { - if (Objects.equals("Primary",csDataSet.getDataLevel())) { - if (HarmonicConstant.POWER_LIST.contains(epdPqd.getShowName())) { - re = DataChangeUtil.primaryToSecondary(epdPqd.getPrimaryFormula(), temp.getValue(), pt, ct); - vo.setStatisticalData(Double.valueOf(df.format(re))); - } else { - vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); - } - } else { - vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); - } + List data1 = equipmentFeignClient.queryDeviceById(Stream.of(wl.getDevId()).collect(Collectors.toList())).getData(); + eleEpdPqds.forEach(epdPqd->{ + List commonQueryParams = finalCsLinePOList.stream().map(temp -> { + CommonQueryParam commonQueryParam = new CommonQueryParam(); + commonQueryParam.setLineId(temp.getLineId()); + commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId())); + commonQueryParam.setColumnName(epdPqd.getName()+ (param.getFrequency() == null ? "":"_"+param.getFrequency())); + commonQueryParam.setPhasic(epdPqd.getPhase()); + commonQueryParam.setStartTime(LocalDateTimeUtil.format(wl.getStartTime(), DateTimeFormatter.ofPattern(DataParam.timeFormat))); + commonQueryParam.setEndTime(LocalDateTimeUtil.format(wl.getEndTime(), DateTimeFormatter.ofPattern(DataParam.timeFormat))); + commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType()); + commonQueryParam.setProcess(data1.get(0).getProcess()+""); + commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId())); + return commonQueryParam; + }).collect(Collectors.toList()); + List deviceRtData = commonService.getDeviceRtDataByTime(commonQueryParams); + //此处设空时为了有多段时将线条断开前端显示 + if(!CollectionUtils.isEmpty(deviceRtData)){ + deviceRtData.get(deviceRtData.size()-1).setValue(null); + } + List collect1 = deviceRtData.stream().map(temp -> { + String unit; + ThdDataVO vo = new ThdDataVO(); + vo.setLineId(temp.getLineId()); + vo.setPhase(Objects.equals("M",temp.getPhaseType())?null: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()); + if(temp.getValue()!=null) { + double re = 0; + if (Objects.equals("Primary",commonStatisticalQueryParam.getDataLevel())) { + if (Objects.equals("Primary",csDataSet.getDataLevel())) { + vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); unit = epdPqd.getUnit(); + } else { + if(Objects.nonNull(epdPqd.getPrimaryFormula())){ + switch (epdPqd.getPrimaryFormula()) { + case "*PT": + re = temp.getValue() * pt / 1000; + unit = "k" + epdPqd.getUnit(); + break; + case "*CT": + re = temp.getValue() * ct; + unit = epdPqd.getUnit(); + break; + case "*PT*CT": + re = temp.getValue() * pt * ct / 1000; + unit = "k" + epdPqd.getUnit(); + break; + default: + re = temp.getValue(); + unit = epdPqd.getUnit(); + break; + } + vo.setStatisticalData(Double.valueOf(df.format(re))); + }else { + re = temp.getValue(); + unit = epdPqd.getUnit(); + vo.setStatisticalData(Double.valueOf(df.format(re))); + } + } } else { - vo.setStatisticalData(null); - if (Objects.equals("Primary",commonStatisticalQueryParam.getDataLevel())) { - if (Objects.equals("Primary",csDataSet.getDataLevel())) { - unit = epdPqd.getUnit(); - } else { - if (HarmonicConstant.POWER_LIST.contains(epdPqd.getShowName())) { - unit = "k" + epdPqd.getUnit(); - } else { - unit = epdPqd.getUnit(); + if (Objects.equals("Primary",csDataSet.getDataLevel())) { + if(Objects.nonNull(epdPqd.getPrimaryFormula())){ + switch (epdPqd.getPrimaryFormula()) { + case "*PT": + re = temp.getValue() / pt; + break; + case "*CT": + re = temp.getValue() / ct; + break; + case "*PT*CT": + re = temp.getValue() / pt / ct; + break; + default: + re = temp.getValue(); + break; } + vo.setStatisticalData(Double.valueOf(df.format(re))); + }else { + re = temp.getValue(); + vo.setStatisticalData(Double.valueOf(df.format(re))); } } else { - unit = epdPqd.getUnit(); + vo.setStatisticalData(Double.valueOf(df.format(temp.getValue()))); } + unit = epdPqd.getUnit(); } - vo.setUnit(unit); - vo.setStatisticalIndex(epdPqd.getId()); - vo.setStatisticalName(epdPqd.getName()); - vo.setAnotherName(epdPqd.getShowName()); - return vo; - }).collect(Collectors.toList()); - result.addAll(collect1); - }); - } + } else { + vo.setStatisticalData(null); + if (Objects.equals("Primary",commonStatisticalQueryParam.getDataLevel())) { + if (Objects.equals("Primary",csDataSet.getDataLevel())) { + unit = epdPqd.getUnit(); + } else { + if(Objects.nonNull(epdPqd.getPrimaryFormula())){ + switch (epdPqd.getPrimaryFormula()) { + case "*PT": + unit = "k" + epdPqd.getUnit(); + break; + case "*CT": + unit = epdPqd.getUnit(); + break; + case "*PT*CT": + unit = "k" + epdPqd.getUnit(); + break; + default: + unit = epdPqd.getUnit(); + break; + } + }else { + unit = epdPqd.getUnit(); + } + } + } else { + unit = epdPqd.getUnit(); + } + } + vo.setUnit(unit); + vo.setStatisticalIndex(epdPqd.getId()); + vo.setStatisticalName(epdPqd.getName()); + vo.setAnotherName(epdPqd.getShowName()); + return vo; + }).collect(Collectors.toList()); + result.addAll(collect1); + }); } + } } return result; } + @Override public WlRecord findDevBaseData(WlRecordParam.Record param) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();