From 3af30403b78321125b75b4b2ee107f76cb1a2f05 Mon Sep 17 00:00:00 2001 From: cdf <857448963@qq.com> Date: Tue, 11 Apr 2023 16:18:14 +0800 Subject: [PATCH] ... --- .../harmonic/service/THDistortionService.java | 17 ++-- .../service/impl/THDistortionServiceImpl.java | 96 ++++++------------- 2 files changed, 41 insertions(+), 72 deletions(-) diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/THDistortionService.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/THDistortionService.java index b20520f07..1516f643e 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/THDistortionService.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/THDistortionService.java @@ -17,6 +17,7 @@ public interface THDistortionService { /** * 功能描述: 获取谐波总畸变率 + * * @param thDistortionParam * @return */ @@ -25,16 +26,18 @@ public interface THDistortionService { /** * 功能描述: 获取总畸变率图表 + * * @param thDistortionCensusParam * @return */ THDistortionCensusVO getTHDistortionCensus(DeviceInfoParam.BusinessParam thDistortionCensusParam); + /** - * @Description: 谐波总畸变率前topNum列表 - * @Param: [statisticsBizBaseParam] - * @return: java.util.List - * @Author: clam - * @Date: 2022/11/7 - */ - List getTHDTopTenData(StatisticsBizBaseParam statisticsBizBaseParam,Integer topNum); + * @Description: 谐波总畸变率前topNum列表 + * @Param: [statisticsBizBaseParam] + * @return: java.util.List + * @Author: clam + * @Date: 2022/11/7 + */ + List getTHDTopTenData(StatisticsBizBaseParam statisticsBizBaseParam, Integer topNum); } 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 06d13b8d5..ec3d0dbdd 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 @@ -57,6 +57,7 @@ public class THDistortionServiceImpl implements THDistortionService { private final RMpVThdMapper rMpVThdMapper; private final LineFeignClient lineFeignClient; private final IRStatDataVDService statDataVDService; + @Override public List getTHDistortionData(DeviceInfoParam.BusinessParam thDistortionParam) { List thDistortionVOS = new ArrayList<>(); @@ -72,7 +73,7 @@ public class THDistortionServiceImpl implements THDistortionService { THDistortionVO thDistortionVO = new THDistortionVO(); thDistortionVO.setId(generalDeviceDTO.getIndex()); thDistortionVO.setName(generalDeviceDTO.getName()); - if (!CollectionUtils.isEmpty(generalDeviceDTO.getLineIndexes())){ + if (!CollectionUtils.isEmpty(generalDeviceDTO.getLineIndexes())) { List lineIndexes = generalDeviceDTO.getLineIndexes(); //查找畸变率 @@ -121,33 +122,33 @@ public class THDistortionServiceImpl implements THDistortionService { * @Date: 2022/10/10 */ @Override - public List getTHDTopTenData(StatisticsBizBaseParam statisticsBizBaseParam,Integer topNum) { + public List getTHDTopTenData(StatisticsBizBaseParam statisticsBizBaseParam, Integer topNum) { - List rMpVThdVOList = new ArrayList<> (); - DeviceInfoParam deviceInfoParam = new DeviceInfoParam (); - deviceInfoParam.setDeptIndex (statisticsBizBaseParam.getId ()); - deviceInfoParam.setStatisticalType (new SimpleDTO ()); - deviceInfoParam.setServerName (generalInfo.getMicroServiceName()); - deviceInfoParam.setPowerFlag (0); - deviceInfoParam.setMonitorFlag (0); + List rMpVThdVOList = new ArrayList<>(); + DeviceInfoParam deviceInfoParam = new DeviceInfoParam(); + deviceInfoParam.setDeptIndex(statisticsBizBaseParam.getId()); + deviceInfoParam.setStatisticalType(new SimpleDTO()); + deviceInfoParam.setServerName(generalInfo.getMicroServiceName()); + deviceInfoParam.setPowerFlag(0); + deviceInfoParam.setMonitorFlag(0); /*获取按部门分类的实际所有终端综合信息*/ - List deviceList = generalDeviceInfoClient.getPracticalAllDeviceInfoAsDept (deviceInfoParam).getData (); + List deviceList = generalDeviceInfoClient.getPracticalAllDeviceInfoAsDept(deviceInfoParam).getData(); /*监测点ID扁平化*/ - List collect = deviceList.stream ( ).map (GeneralDeviceDTO::getLineIndexes).flatMap (Collection::stream).distinct ( ).collect (Collectors.toList ( )); + List collect = deviceList.stream().map(GeneralDeviceDTO::getLineIndexes).flatMap(Collection::stream).distinct().collect(Collectors.toList()); QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.in ("measurement_point_id",collect) - .between ("data_date", statisticsBizBaseParam.getStartTime (), statisticsBizBaseParam.getEndTime ()) - .eq("data_type",1) - .orderByDesc ("v_thd"); - List rMpVThdList = rMpVThdMapper.selectList (wrapper); - rMpVThdVOList = rMpVThdList.stream ( ).limit (topNum).map (rMpVThd -> { - RMpVThdVO rMpVThdVO = new RMpVThdVO ( ); - BeanUtils.copyProperties (rMpVThd, rMpVThdVO); + wrapper.in("measurement_point_id", collect) + .between("data_date", statisticsBizBaseParam.getStartTime(), statisticsBizBaseParam.getEndTime()) + .eq("data_type", 1) + .orderByDesc("v_thd"); + List rMpVThdList = rMpVThdMapper.selectList(wrapper); + rMpVThdVOList = rMpVThdList.stream().limit(topNum).map(rMpVThd -> { + RMpVThdVO rMpVThdVO = new RMpVThdVO(); + BeanUtils.copyProperties(rMpVThd, rMpVThdVO); /*查询监测点详情获取名称*/ - LineDetailDataVO data = lineFeignClient.getLineDetailData (rMpVThd.getMeasurementPointId ( )).getData ( ); - rMpVThdVO.setName (data.getLineName ()); + LineDetailDataVO data = lineFeignClient.getLineDetailData(rMpVThd.getMeasurementPointId()).getData(); + rMpVThdVO.setName(data.getLineName()); return rMpVThdVO; - }).collect (Collectors.toList ( )); + }).collect(Collectors.toList()); return rMpVThdVOList; } @@ -174,6 +175,7 @@ public class THDistortionServiceImpl implements THDistortionService { private List getChildCategoryList(THDistortionVO item, List child) { return child.stream().filter(allItem -> allItem.getPid().equals(item.getId())).collect(Collectors.toList()); } + private void setChildesList(List item, List childes) { //groupLine变电站索引和监测点集合 Map> groupLine; @@ -215,7 +217,7 @@ public class THDistortionServiceImpl implements THDistortionService { // 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()); - setChildesList(substationList,monitorList); + setChildesList(substationList, monitorList); setFatherDistortion(substationList); powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList()); setFatherDistortion(powerCompanyList); @@ -227,13 +229,14 @@ public class THDistortionServiceImpl implements THDistortionService { /** * influxDB查询畸变率 + * * @param lineIndexes * @param startTime * @param endTime */ private List getCondition(List lineIndexes, String startTime, String endTime) { List publicDTOList = new ArrayList<>(); - List phasicType=new ArrayList<>(); + List phasicType = new ArrayList<>(); phasicType.add(Param.PHASIC_TYPEA); phasicType.add(Param.PHASIC_TYPEB); phasicType.add(Param.PHASIC_TYPEC); @@ -247,11 +250,11 @@ public class THDistortionServiceImpl implements THDistortionService { .in(RStatDataVD::getPhasicType, phasicType) .eq(RStatDataVD::getValueType, Param.VALUE_TYPEAVG) ); - if (CollUtil.isNotEmpty(info)){ + if (CollUtil.isNotEmpty(info)) { //根据id分组,先乘以100.在取平均值,在四舍五入 - Map vthdMap = info.stream().filter(x-> x.getVThd()!=null).collect(Collectors.groupingBy(RStatDataVD::getLineId, - Collectors.averagingDouble(x->x.getVThd().multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()))); - PublicDTO publicDTO ; + Map vthdMap = info.stream().filter(x -> x.getVThd() != null).collect(Collectors.groupingBy(RStatDataVD::getLineId, + Collectors.averagingDouble(x -> x.getVThd().multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()))); + PublicDTO publicDTO; for (Map.Entry entry : vthdMap.entrySet()) { publicDTO = new PublicDTO(); publicDTO.setId(entry.getKey()); @@ -260,43 +263,6 @@ public class THDistortionServiceImpl implements THDistortionService { } } return publicDTOList; - - //组装sql语句 -// StringBuilder string = new StringBuilder(); -// string.append(Param.QualityFlag + "='1' and (" + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEA + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEB + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEC + "') and "+ Param.VALUETYPE + "='AVG' and "); -// StringBuilder timeId = new StringBuilder(); -// timeId.append(Param.TIME + " >= '" + startTime + Param.START_TIME + "' and " + Param.TIME + " <= '" + endTime + Param.END_TIME + "' and ("); -// for (int i = 0; i < lineIndexes.size(); i++) { -// if (lineIndexes.size() - i != 1) { -// timeId.append(Param.LINE_ID + "='").append(lineIndexes.get(i)).append("' or "); -// } else { -// timeId.append(Param.LINE_ID + "='").append(lineIndexes.get(i)).append("')"); -// } -// } -// // String a = "SELECT MEAN(V_THD) AS distortion FROM Data_V WHERE QualityFlag='1' and (phasic_type='A' or phasic_type='B' or phasic_type='C')and value_type='AVG' and time >= '2022-03-20 00:00:00' and time <= '2022-03-21 23:59:59' and (lineid ='1e3b8531483b2a8cbee6747f1f641cf9') group by lineid;"; -// //sql语句 -// String sql = "SELECT MEAN(" + Param.V_THD + ")*100 AS distortion FROM Data_V WHERE " + string + timeId + " group by " + Param.LINE_ID; -// //结果集 -// QueryResult result = influxDbUtils.query(sql); -// //处理结果集 -// List list = result.getResults().get(0).getSeries(); -// if (!CollectionUtils.isEmpty(list)){ -// list.forEach(po->{ -// PublicDTO publicDTO = new PublicDTO(); -// List> valueList = po.getValues(); -// String index = po.getTags().get(Param.LINE_ID); -// if (!CollectionUtils.isEmpty(valueList)){ -// for (List value : valueList) { -// //谐波畸变率 保留两位小数 -// Double distortion = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); -// publicDTO.setId(index); -// publicDTO.setData(distortion); -// } -// } -// publicDTOList.add(publicDTO); -// }); -// } -// return publicDTOList; }