diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/AppLineTopologyDiagramVO.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/AppLineTopologyDiagramVO.java new file mode 100644 index 0000000..7728776 --- /dev/null +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/AppLineTopologyDiagramVO.java @@ -0,0 +1,45 @@ +package com.njcn.csdevice.pojo.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.njcn.db.bo.BaseEntity; +import lombok.Data; + +/** + * + * Description: + * 接口文档访问地址:http://serverIP:port/swagger-ui.html + * Date: 2023/3/27 10:18【需求编号】 + * + * @author clam + * @version V1.0.0 + */ + +/** + * 项目拓扑图关系表 + */ +@Data +public class AppLineTopologyDiagramVO { + /** + * 拓扑图Id + */ + private String id; + + /** + * 监测点ID + */ + private String lineId; + + /** + * 0:删除 1:正常 + */ + private String status; + + private Double lng; + + private Double lat; + + private String linePostion; + + +} \ No newline at end of file diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/AppTopologyDiagramVO.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/AppTopologyDiagramVO.java index 47ec5fa..d50e10f 100644 --- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/AppTopologyDiagramVO.java +++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/vo/AppTopologyDiagramVO.java @@ -60,7 +60,7 @@ public class AppTopologyDiagramVO extends BaseEntity { private List csLineTopologyTemplateVOList; - private List appsLineTopologyDiagramPO; + private List appsLineTopologyDiagramPO; } \ No newline at end of file diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/AppLineTopologyDiagramMapper.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/AppLineTopologyDiagramMapper.java index 31725cf..e89f80a 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/AppLineTopologyDiagramMapper.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/AppLineTopologyDiagramMapper.java @@ -2,6 +2,10 @@ package com.njcn.csdevice.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO; +import com.njcn.csdevice.pojo.vo.AppLineTopologyDiagramVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * @@ -13,4 +17,5 @@ import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO; * @version V1.0.0 */ public interface AppLineTopologyDiagramMapper extends BaseMapper { + List queryByTopoId(@Param("id") String id); } \ No newline at end of file diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/AppLineTopologyDiagramMapper.xml b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/AppLineTopologyDiagramMapper.xml index f6e1577..0ad16d3 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/AppLineTopologyDiagramMapper.xml +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/AppLineTopologyDiagramMapper.xml @@ -16,4 +16,8 @@ id, line_id, `status`, create_by, create_time, update_by, update_time + + \ No newline at end of file diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/AppLineTopologyDiagramService.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/AppLineTopologyDiagramService.java index 85f1d51..e42a570 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/AppLineTopologyDiagramService.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/AppLineTopologyDiagramService.java @@ -2,6 +2,7 @@ package com.njcn.csdevice.service; import com.baomidou.mybatisplus.extension.service.IService; import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO; +import com.njcn.csdevice.pojo.vo.AppLineTopologyDiagramVO; import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO; import com.njcn.csdevice.pojo.vo.CsLineTopologyTemplateVO; @@ -21,5 +22,5 @@ public interface AppLineTopologyDiagramService extends IService queryByTopoId(String id); + List queryByTopoId(String id); } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/AppLineTopologyDiagramServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/AppLineTopologyDiagramServiceImpl.java index eaa247e..f75a5c7 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/AppLineTopologyDiagramServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/AppLineTopologyDiagramServiceImpl.java @@ -8,6 +8,7 @@ import com.njcn.csdevice.mapper.AppLineTopologyDiagramMapper; import com.njcn.csdevice.pojo.param.AppTopologyDiagramQueryParm; import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO; import com.njcn.csdevice.pojo.po.CsLinePO; +import com.njcn.csdevice.pojo.vo.AppLineTopologyDiagramVO; import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO; import com.njcn.csdevice.pojo.vo.CsLineTopologyTemplateVO; import com.njcn.csdevice.service.AppLineTopologyDiagramService; @@ -16,6 +17,7 @@ import com.njcn.csdevice.service.CsLinePOService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -55,8 +57,9 @@ public class AppLineTopologyDiagramServiceImpl extends ServiceImpl queryByTopoId(String id) { - List list = this.lambdaQuery().eq(AppLineTopologyDiagramPO::getId, id).list(); - return list; + public List queryByTopoId(String id) { + List result = new ArrayList<>(); + result = this.getBaseMapper().queryByTopoId( id); + return result; } } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java index b079f04..174d999 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/handler/MqttMessageHandler.java @@ -1,5 +1,6 @@ package com.njcn.csharmonic.handler; +import cn.hutool.core.collection.CollectionUtil; import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.github.tocrhz.mqtt.annotation.MqttSubscribe; import com.github.tocrhz.mqtt.annotation.NamedValue; @@ -15,10 +16,16 @@ import com.njcn.system.pojo.po.EleEpdPqd; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author xuyang @@ -35,6 +42,7 @@ public class MqttMessageHandler { private final ILineTargetService lineTargetService; private final CsStatisticalSetFeignClient csStatisticalSetFeignClient; private final StableDataService stableDataService; + private final DecimalFormat df = new DecimalFormat("#0.00"); /** * 实时数据应答 */ @@ -51,16 +59,61 @@ public class MqttMessageHandler { @MqttSubscribe(value = "/zl/askDevData/{devId}",qos = 1) public void responseTopoData(String topic, @NamedValue("devId") String devId, MqttMessage message, @Payload String payload) { List result = new ArrayList<>(); + List tempList = new ArrayList<>(); + //1.查询拓扑图配置的指标:拓扑图扑图配置:7677f94c749dedaff30f911949cbd724 List data = csStatisticalSetFeignClient.queryStatisticalSelect("7677f94c749dedaff30f911949cbd724").getData(); data.forEach(temp->{ CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam(); commonStatisticalQueryParam.setDevId(devId); commonStatisticalQueryParam.setStatisticalId(temp.getId()); - commonStatisticalQueryParam.setValueType("cp95"); + commonStatisticalQueryParam.setValueType("avg"); List thdDataVOS = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam); - result.addAll(thdDataVOS); + tempList.addAll(thdDataVOS); }); + //过滤M相 + List m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); + m.stream().forEach(temp->{ + Stream.of("A","B","C").forEach(phase->{ + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(temp,thdDataVO); + thdDataVO.setPhase(phase); + result.add(thdDataVO); + }); + }); + //过滤谐波电流,谐波电压畸变率求平均值 + List thdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "ThdPhI(%)")).collect(Collectors.toList()); + Map> collect = thdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); + collect.forEach((k,v)->{ + if(!CollectionUtil.isEmpty(v)){ + double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(v.get(0),thdDataVO); + thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); + thdDataVO.setPhase("avg"); + result.add(thdDataVO); + + } + }); + + List thdV = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "ThdPhV(%)")).collect(Collectors.toList()); + Map> collect1 = thdV.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); + collect1.forEach((k,v)->{ + if(!CollectionUtil.isEmpty(v)){ + double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble(); + ThdDataVO thdDataVO = new ThdDataVO(); + BeanUtils.copyProperties(v.get(0),thdDataVO); + thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); + thdDataVO.setPhase("avg"); + result.add(thdDataVO); + + } + }); + + List notM = tempList.stream().filter(temp -> !Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList()); + + result.addAll(notM); + Gson gson = new Gson(); 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 7e0933b..c78a6bb 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 @@ -154,11 +154,22 @@ public class StableDataServiceImpl implements StableDataService { @Override public List queryFisrtCommonStatistical(CommonStatisticalQueryParam commonStatisticalQueryParam) { - Optional.ofNullable(commonStatisticalQueryParam.getDevId()).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.DEVICE_LOSE)); + List collect = new ArrayList<>(); + List csLinePOList = new ArrayList<>(); + if(Objects.isNull(commonStatisticalQueryParam.getDevId())){ + if(!CollectionUtil.isEmpty(commonStatisticalQueryParam.getLineList())){ + collect =commonStatisticalQueryParam.getLineList(); + csLinePOList = csLineFeignClient.queryLineById(collect).getData(); + }else { + throw new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR); + } + }else { + csLinePOList = csLineFeignClient.queryLineByDevId(commonStatisticalQueryParam.getDevId()).getData(); - List csLinePOList = csLineFeignClient.queryLineByDevId(commonStatisticalQueryParam.getDevId()).getData(); + } Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR)); - List collect = csLinePOList.stream().map(CsLinePO::getLineId).collect(Collectors.toList()); + collect = csLinePOList.stream().map(CsLinePO::getLineId).collect(Collectors.toList()); + EleEpdPqd data = epdFeignClient.selectById(commonStatisticalQueryParam.getStatisticalId()).getData(); @@ -166,17 +177,18 @@ public class StableDataServiceImpl implements StableDataService { String frequency = Optional.ofNullable(commonStatisticalQueryParam.getFrequency()).orElse(""); List deviceRtData = commonService.getDeviceRtData(collect, data.getClassId(), data.getName()+frequency, data.getPhase(), commonStatisticalQueryParam.getValueType()); + List finalCsLinePOList = csLinePOList; List collect1 = deviceRtData.stream().map(temp -> { ThdDataVO vo = new ThdDataVO(); vo.setLineId(temp.getLineId()); vo.setPhase(temp.getPhaseType()); - String position = csLinePOList.stream().filter(csLinePO -> Objects.equals(csLinePO.getLineId(), vo.getLineId())).collect(Collectors.toList()).get(0).getPosition(); + 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().atZone(ZoneId.systemDefault()).toLocalDateTime()); vo.setStatMethod(temp.getValueType()); vo.setStatisticalData(BigDecimal.valueOf(temp.getValue()).setScale(4, RoundingMode.UP).doubleValue()); vo.setStatisticalIndex(data.getId()); - vo.setStatisticalName(temp.getStatisticalName()); + vo.setStatisticalName(data.getName()+"("+data.getUnit()+")"); return vo; }).collect(Collectors.toList());