diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/dto/RealTimeDataDTO.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/dto/RealTimeDataDTO.java new file mode 100644 index 0000000..d1336b5 --- /dev/null +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/dto/RealTimeDataDTO.java @@ -0,0 +1,22 @@ +package com.njcn.csharmonic.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Description: + * Date: 2025/09/18 下午 2:00【需求编号】 + * + * @author clam + * @version V1.0.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class RealTimeDataDTO { + private Integer code; + private String message; + private Integer type =1; +// private List realTimeDataVoList; +} diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/dto/ZuTaiNewDTO.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/dto/ZuTaiNewDTO.java new file mode 100644 index 0000000..6fccdf5 --- /dev/null +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/dto/ZuTaiNewDTO.java @@ -0,0 +1,49 @@ +package com.njcn.csharmonic.pojo.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/6/14 20:07 + */ +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ZuTaiNewDTO { + + private List json; + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DiagramElement{ + + private String id; + private String title; + private String keyId; + private String type; + private boolean resize; + private boolean rotate; + private boolean lock; + private boolean active; + private boolean hide; + private String tag; + private boolean use_proportional_scaling; + private String lineId; + private List lineList; + private String lineName; + @JsonProperty("UID") + private List> uid; + @JsonProperty("UIDNames") + + private List uidNames; + private List unit; + + } + +} diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/CsRtDataVO.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/CsRtDataVO.java index 581c539..ec16444 100644 --- a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/CsRtDataVO.java +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/CsRtDataVO.java @@ -42,6 +42,9 @@ public class CsRtDataVO { @ApiModelProperty("指标显示名称") private String statisticalName; + @ApiModelProperty("指标单位") + private String unit; + @ApiModelProperty("指标名称") private String target; diff --git a/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/CsWarnDescVO.java b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/CsWarnDescVO.java new file mode 100644 index 0000000..8f4646b --- /dev/null +++ b/cs-harmonic/cs-harmonic-api/src/main/java/com/njcn/csharmonic/pojo/vo/CsWarnDescVO.java @@ -0,0 +1,49 @@ +package com.njcn.csharmonic.pojo.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 组态下事件描述实体 + */ +@Data +public class CsWarnDescVO implements Serializable { + + /** + * id + */ + private String id; + + + /** + * 名称,比如监测点名称 + */ + private String name; + + + /** + * 发生时间 + */ + private String timeId; + + + /** + * 事件描述eventDesc + */ + private String eventDesc; + + + /** + * 持续时间 + */ + private Double persistTime; + + /** + * 暂降幅值 + */ + private Double amplitude; + + + +} diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/LineTargetController.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/LineTargetController.java index 6e1d419..8b632a2 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/LineTargetController.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/controller/LineTargetController.java @@ -13,10 +13,7 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; 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 c8fa8ed..d23c19a 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,6 +1,7 @@ package com.njcn.csharmonic.handler; import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.fasterxml.jackson.core.JsonProcessingException; import com.github.tocrhz.mqtt.annotation.MqttSubscribe; @@ -16,8 +17,11 @@ import com.njcn.csdevice.api.EquipmentFeignClient; import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO; import com.njcn.csharmonic.param.CommonStatisticalQueryParam; import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam; +import com.njcn.csharmonic.pojo.dto.RealTimeDataDTO; import com.njcn.csharmonic.pojo.vo.CsRtDataVO; +import com.njcn.csharmonic.pojo.vo.CsWarnDescVO; import com.njcn.csharmonic.pojo.vo.ThdDataVO; +import com.njcn.csharmonic.service.CsEventPOService; import com.njcn.csharmonic.service.ILineTargetService; import com.njcn.csharmonic.service.StableDataService; import com.njcn.csharmonic.service.TemperatureService; @@ -34,12 +38,10 @@ import org.apache.commons.lang.StringUtils; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -64,7 +66,7 @@ public class MqttMessageHandler { private final TemperatureService temperatureService; private final DevCapacityFeignClient devCapacityFeignClient; - private final DecimalFormat df = new DecimalFormat("#0.000"); + private final DecimalFormat df = new DecimalFormat("#0.000"); private final ChannelObjectUtil channelObjectUtil; private final EquipmentFeignClient equipmentFeignClient; private final CsTopicFeignClient csTopicFeignClient; @@ -72,26 +74,61 @@ public class MqttMessageHandler { private static Integer mid = 1; private final FileFeignClient fileFeignClient; + CsEventPOService csEventPOService; + /** * 实时数据应答 */ - @MqttSubscribe(value = "/zl/askRtData/{pageId}",qos = 1) + @MqttSubscribe(value = "/zl/askRtData/{pageId}", qos = 1) public void responseRtData(String topic, @NamedValue("pageId") String pageId, MqttMessage message, @Payload String payload) { List list = lineTargetService.getLineData(pageId); Gson gson = new Gson(); - publisher.send("/zl/rtData/"+pageId,gson.toJson(list),1,false); + publisher.send("/zl/rtData/" + pageId, gson.toJson(list), 1, false); } - @MqttSubscribe(value = "/zl/askTemperData/{devId}",qos = 1) + @MqttSubscribe(value = "/zl/askTemperData/{devId}", qos = 1) public void responseTemperData(String topic, @NamedValue("devId") String devId, MqttMessage message, @Payload String payload) { List statisticalDataDTOS = temperatureService.queryTemperature(devId); - statisticalDataDTOS.stream().forEach(temp->{ + statisticalDataDTOS.stream().forEach(temp -> { temp.setClDid(getCldidName(temp.getClDid())); }); Gson gson = new Gson(); - publisher.send("/zl/TemperData/"+devId,gson.toJson(statisticalDataDTOS),1,false); + publisher.send("/zl/TemperData/" + devId, gson.toJson(statisticalDataDTOS), 1, false); } + + /** + * 物联平台的组态实时数据调试 + */ + @MqttSubscribe(value = "/zl/askCSConfigRtData/{pageId}", qos = 1) + public void responseCSConfigRtData(String topic, @NamedValue("pageId") String pageId, MqttMessage message, @Payload String payload) { + List lineIdList = Arrays.stream(payload.substring(1, payload.length() - 1).split(",")) + .map(String::trim) + .collect(Collectors.toList()); + List lineData = lineTargetService.getLineDataNew(pageId); + List collect = lineData.stream().filter(temp -> (!CollectionUtils.isEmpty(lineIdList)) && lineIdList.contains(temp.getLineId())).collect(Collectors.toList()); + RealTimeDataDTO recallReplyDTO = new RealTimeDataDTO(); + recallReplyDTO.setCode(200); + recallReplyDTO.setMessage(JSONObject.toJSONString(collect)); + Gson gson = new Gson(); + publisher.send("/zl/csConfigRtData/" + pageId, gson.toJson(recallReplyDTO), 1, false); + } + + @MqttSubscribe(value = "/zl/askCSConfigWarnData/{pageId}", qos = 1) + public void responseCSConfigWarnData(String topic, @NamedValue("pageId") String pageId, MqttMessage message, @Payload String payload) { + List lineIdList = Arrays.stream(payload.substring(1, payload.length() - 1).split(",")) + .map(String::trim) + .collect(Collectors.toList()); + // 目前暂且查最近的60条记录 + List csWarnDescVOList = csEventPOService.getEventDesc(lineIdList); + RealTimeDataDTO recallReplyDTO = new RealTimeDataDTO(); + recallReplyDTO.setCode(200); + recallReplyDTO.setMessage(JSONObject.toJSONString(csWarnDescVOList)); + Gson gson = new Gson(); + publisher.send("/zl/TemperData/" + pageId, gson.toJson(recallReplyDTO), 1, false); + } + + /** * 实时数据应答 */ @@ -195,20 +232,21 @@ public class MqttMessageHandler { // } // publisher.send("/zl/devData/"+devId,topoDataJson,1,false); // } + /** * 实时数据应答 */ - @MqttSubscribe(value = "/zl/askDevData/{devId}/{typeId}",qos = 1) - public void responseTopoDataByType(String topic, @NamedValue("devId") String devId,@NamedValue("typeId") String typeId, MqttMessage message, @Payload String payload) { - String topoDataJson =redisUtil.getStringByKey (devId+"#"+typeId); - if(StringUtils.isEmpty(topoDataJson)){ + @MqttSubscribe(value = "/zl/askDevData/{devId}/{typeId}", qos = 1) + public void responseTopoDataByType(String topic, @NamedValue("devId") String devId, @NamedValue("typeId") String typeId, MqttMessage message, @Payload String payload) { + String topoDataJson = redisUtil.getStringByKey(devId + "#" + typeId); + if (StringUtils.isEmpty(topoDataJson)) { List result = new ArrayList<>(); List tempList = new ArrayList<>(); //1.查询拓扑图配置的指标:拓扑图扑图配置:7677f94c749dedaff30f911949cbd724 List data = csStatisticalSetFeignClient.queryStatisticalSelect(typeId).getData(); - data.forEach(temp->{ - if(Objects.nonNull(temp.getHarmStart())&&Objects.nonNull(temp.getHarmEnd())){ + data.forEach(temp -> { + if (Objects.nonNull(temp.getHarmStart()) && Objects.nonNull(temp.getHarmEnd())) { FrequencyStatisticalQueryParam frequencyStatisticalQueryParam = new FrequencyStatisticalQueryParam(); frequencyStatisticalQueryParam.setDevId(devId); frequencyStatisticalQueryParam.setStatisticalId(temp.getId()); @@ -218,12 +256,12 @@ public class MqttMessageHandler { List thdDataVOList = stableDataService.QuerySqlData(frequencyStatisticalQueryParam); tempList.addAll(thdDataVOList); - }else { + } else { CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam(); commonStatisticalQueryParam.setDevId(devId); commonStatisticalQueryParam.setStatisticalId(temp.getId()); commonStatisticalQueryParam.setValueType("avg"); - List listFuture= stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam); + List listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam); tempList.addAll(listFuture); } @@ -231,23 +269,23 @@ public class MqttMessageHandler { //过滤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->{ + m.stream().forEach(temp -> { + Stream.of("A", "B", "C").forEach(phase -> { ThdDataVO thdDataVO = new ThdDataVO(); - BeanUtils.copyProperties(temp,thdDataVO); + BeanUtils.copyProperties(temp, thdDataVO); thdDataVO.setPhase(phase); result.add(thdDataVO); }); }); //如果是基础数据则添加拓扑图的数据 - if(Objects.equals("fc8c86dbc3f2d9810f5cd8f53c295415",typeId)){ + if (Objects.equals("fc8c86dbc3f2d9810f5cd8f53c295415", typeId)) { List apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList()); Map> collect3 = apfThdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); - collect3.forEach((k,v)->{ - if(!CollectionUtil.isEmpty(v)){ + collect3.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); + BeanUtils.copyProperties(v.get(0), thdDataVO); thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); thdDataVO.setPhase("avg"); result.add(thdDataVO); @@ -255,11 +293,11 @@ public class MqttMessageHandler { }); List apfRmsI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_RmsI_TolOut(A)")).collect(Collectors.toList()); Map> collect2 = apfRmsI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); - collect2.forEach((k,v)->{ - if(!CollectionUtil.isEmpty(v)){ + collect2.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); + BeanUtils.copyProperties(v.get(0), thdDataVO); thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); thdDataVO.setPhase("avg"); result.add(thdDataVO); @@ -267,11 +305,11 @@ public class MqttMessageHandler { }); List apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList()); Map> collect4 = apfThdISys.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId)); - collect4.forEach((k,v)->{ - if(!CollectionUtil.isEmpty(v)){ + collect4.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); + BeanUtils.copyProperties(v.get(0), thdDataVO); thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble))); thdDataVO.setPhase("avg"); result.add(thdDataVO); @@ -279,16 +317,16 @@ public class MqttMessageHandler { } }); Double capacity = devCapacityFeignClient.getDevCapacity(devId).getData(); - apfRmsI.forEach(temp->{ + apfRmsI.forEach(temp -> { ThdDataVO thdDataVO = new ThdDataVO(); - BeanUtils.copyProperties(temp,thdDataVO); + BeanUtils.copyProperties(temp, thdDataVO); thdDataVO.setUnit("%"); thdDataVO.setStatisticalName("load_Rate"); thdDataVO.setAnotherName("负载率"); - if (capacity<=0){ + if (capacity <= 0) { thdDataVO.setStatisticalData(3.1415926); - }else { - double v = temp.getStatisticalData()*100 / capacity; + } else { + double v = temp.getStatisticalData() * 100 / capacity; thdDataVO.setStatisticalData(Double.valueOf(df.format(v))); } result.add(thdDataVO); @@ -299,14 +337,13 @@ public class MqttMessageHandler { result.addAll(notM); Gson gson = new Gson(); topoDataJson = gson.toJson(result); - redisUtil.saveByKeyWithExpire(devId+"#"+typeId, (Object) topoDataJson, 30L); + redisUtil.saveByKeyWithExpire(devId + "#" + typeId, (Object) topoDataJson, 30L); } - publisher.send("/zl/devData/"+devId+"/"+typeId,topoDataJson,1,false); + publisher.send("/zl/devData/" + devId + "/" + typeId, topoDataJson, 1, false); } - - public String getCldidName( String cldid) { + public String getCldidName(String cldid) { switch (cldid) { case "0": @@ -361,7 +398,7 @@ public class MqttMessageHandler { /** * 处理补召数据 */ - @MqttSubscribe(value = "/makeUpData/{nDid}/{lineId}",qos = 1) + @MqttSubscribe(value = "/makeUpData/{nDid}/{lineId}", qos = 1) public void responseRtData(String topic, @NamedValue("nDid") String nDid, @NamedValue("lineId") String lineId, MqttMessage message, @Payload String payload) { //下载文件 fileFeignClient.downloadMakeUpFile(nDid); diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/CsEventPOMapper.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/CsEventPOMapper.java index 1a8bced..611307e 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/CsEventPOMapper.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/CsEventPOMapper.java @@ -2,6 +2,10 @@ package com.njcn.csharmonic.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.njcn.csharmonic.pojo.po.CsEventPO; +import com.njcn.csharmonic.pojo.vo.CsWarnDescVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * @@ -12,4 +16,5 @@ import com.njcn.csharmonic.pojo.po.CsEventPO; * @version V1.0.0 */ public interface CsEventPOMapper extends BaseMapper { + List getEventDesc(@Param("lineIdList")List lineIdList, @Param("count")int count); } \ No newline at end of file diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/mapping/CsEventPOMapper.xml b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/mapping/CsEventPOMapper.xml index d7665a1..fc11b8a 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/mapping/CsEventPOMapper.xml +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/mapper/mapping/CsEventPOMapper.xml @@ -15,4 +15,26 @@ id, line_id, device_id, start_time, tag, wave_id + + + + \ No newline at end of file diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java index 02df09f..7594573 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/CsEventPOService.java @@ -10,6 +10,7 @@ import com.njcn.csharmonic.param.DataParam; import com.njcn.csharmonic.pojo.param.EventStatisticParam; import com.njcn.csharmonic.pojo.po.CsEventPO; import com.njcn.csharmonic.pojo.vo.CsEventVO; +import com.njcn.csharmonic.pojo.vo.CsWarnDescVO; import com.njcn.csharmonic.pojo.vo.EventDetailVO; import com.njcn.csharmonic.pojo.vo.EventStatisticsVo; import com.njcn.event.file.pojo.dto.WaveDataDTO; @@ -69,4 +70,5 @@ public interface CsEventPOService extends IService{ List getEventStatistics(CsEventUserQueryParam param); + List getEventDesc(List lineIdList); } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/ILineTargetService.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/ILineTargetService.java index e8c0a26..ff095e2 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/ILineTargetService.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/ILineTargetService.java @@ -23,4 +23,9 @@ public interface ILineTargetService { */ List getLineData(String id); + /** + * 获取绑定指标的数据 + * @param id + */ + List getLineDataNew(String id); } diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java index 3efcd1f..305e1c4 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/CsEventPOServiceImpl.java @@ -29,6 +29,7 @@ import com.njcn.csharmonic.param.DataParam; import com.njcn.csharmonic.pojo.param.EventStatisticParam; import com.njcn.csharmonic.pojo.po.CsEventPO; import com.njcn.csharmonic.pojo.vo.CsEventVO; +import com.njcn.csharmonic.pojo.vo.CsWarnDescVO; import com.njcn.csharmonic.pojo.vo.EventDetailVO; import com.njcn.csharmonic.pojo.vo.EventStatisticsVo; import com.njcn.csharmonic.service.CsEventPOService; @@ -401,6 +402,23 @@ public class CsEventPOServiceImpl extends ServiceImpl getEventDesc(List lineIdList) { + List csWarnDescVOList = new ArrayList<>(); + if(CollUtil.isEmpty(lineIdList)){ + return csWarnDescVOList; + } + /** + * todo.. 目前且先查最近的60条 + */ + csWarnDescVOList = this.baseMapper.getEventDesc(lineIdList,60); + // 处理下描述 + for (CsWarnDescVO csWarnDescVO : csWarnDescVOList) { + csWarnDescVO.setEventDesc("电压暂态事件,持续时间"+csWarnDescVO.getPersistTime()+"秒,电压降至"+csWarnDescVO.getAmplitude()+"%。"); + } + return csWarnDescVOList; + } + public String getTag(Integer type) { String tag; switch (type) { diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/LineTargetServiceImpl.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/LineTargetServiceImpl.java index 3944421..989092b 100644 --- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/LineTargetServiceImpl.java +++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/LineTargetServiceImpl.java @@ -2,6 +2,9 @@ package com.njcn.csharmonic.service.impl; import cn.hutool.core.util.ObjectUtil; import com.alibaba.nacos.shaded.com.google.gson.Gson; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.reflect.TypeToken; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.csdevice.api.*; @@ -12,10 +15,12 @@ import com.njcn.csdevice.pojo.vo.DataArrayTreeVO; import com.njcn.csdevice.pojo.vo.LineTargetVO; import com.njcn.csharmonic.enums.CsHarmonicResponseEnum; import com.njcn.csharmonic.pojo.dto.ZuTaiDTO; +import com.njcn.csharmonic.pojo.dto.ZuTaiNewDTO; import com.njcn.csharmonic.pojo.vo.CsRtDataVO; import com.njcn.csharmonic.service.CsPagePOService; import com.njcn.csharmonic.service.ILineTargetService; import com.njcn.csharmonic.util.InfluxDbParamUtil; +import com.njcn.cssystem.enums.CsSystemResponseEnum; import com.njcn.influx.pojo.dto.StatisticalDataDTO; import com.njcn.influx.service.CommonService; import com.njcn.oss.utils.FileStorageUtil; @@ -34,10 +39,7 @@ import java.io.InputStreamReader; import java.math.BigDecimal; import java.math.RoundingMode; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -137,6 +139,50 @@ public class LineTargetServiceImpl implements ILineTargetService { return result; } + + @Override + public List getLineDataNew(String id) { + List result = new ArrayList<>(); + String path = csPagePOService.queryById(id).getPath(); + InputStream inputStream = fileStorageUtil.getFileStream(path); + ZuTaiNewDTO zuTaiDto = analysisJsonNew(inputStream); + + zuTaiDto.getJson().forEach(item->{ + if (!CollectionUtils.isEmpty(item.getUidNames())){ + for (int i = 0; i < item.getUidNames().size(); i++) { + String temp = item.getUidNames().get(i); + String targetTag = null; + String phasic = null; + String dataType = null; +// String[] tmepUidName = temp.split(" / "); +// if(tmepUidName.length==2){ +// targetTag = tmepUidName[0]; +// phasic = "T"; +// dataType = tmepUidName[1]; +// }else if (tmepUidName.length==3){ +// targetTag = tmepUidName[0]; +// phasic = tmepUidName[1]; +// dataType = tmepUidName[2]; +// } + + if (CollectionUtils.isEmpty(item.getUid()) || org.springframework.util.StringUtils.isEmpty(item.getLineId())){ + throw new BusinessException(CsSystemResponseEnum.BIND_TARGET_ERROR); + } + List tempUid = item.getUid().get(i); + String s = tempUid.get(tempUid.size() - 1); + String[] tempTable = s.replace("$", "").split("#"); + result.add(getLineRtDataNew(item.getId(),item.getLineId(),tempTable[3],tempTable[0],tempTable[1],tempTable[2].toUpperCase(),temp,item.getUnit().get(i))); +// result.add(getLineRtData(item.getId(),item.getLineId(),tempUid.get(3),tempUid.get(0),tempUid.get(1),tempUid.get(2).toUpperCase(),temp,"%")); + } + + } + + + }); + return result; + } + + /** * 解析json文件 */ @@ -149,6 +195,28 @@ public class LineTargetServiceImpl implements ILineTargetService { return gson.fromJson(text, new TypeToken(){}.getType()); } + /** + * 解析json文件 + */ + public ZuTaiNewDTO analysisJsonNew(InputStream inputStream) { + ObjectMapper mapper = new ObjectMapper(); + + String text = new BufferedReader( + new InputStreamReader(inputStream, StandardCharsets.UTF_8)) + .lines() + .collect(Collectors.joining("\n")); + + + ZuTaiNewDTO config = null; + try { + config = mapper.readValue(text, ZuTaiNewDTO.class); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + return config; + } + /** * 通过orm框架获取数据 * @param id 图元Id @@ -179,4 +247,74 @@ public class LineTargetServiceImpl implements ILineTargetService { csRtDataVO.setId(id); return csRtDataVO; } + + + /** + * 通过orm框架获取数据 + * @param id 图元Id + * @param lineId 监测点Id + * @param tableName 表名称 + * @param columnName 字段名称 + * @param phasic 相别 + * @param dataType 数据类型 + * @param target 数据名称 + * @return + */ + public CsRtDataVO getLineRtDataNew(String id,String lineId, String tableName, String columnName, String phasic, String dataType, String target,String uint) { + CsRtDataVO csRtDataVO = new CsRtDataVO(); + StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,tableName,columnName,phasic,dataType,null); + if(Objects.isNull(statisticalDataDTO)){ + statisticalDataDTO = new StatisticalDataDTO(); + statisticalDataDTO.setLineId(lineId); + statisticalDataDTO.setPhaseType(phasic); + statisticalDataDTO.setValueType(dataType); + statisticalDataDTO.setValue(3.1415926); + } else { + statisticalDataDTO.setValue(BigDecimal.valueOf(statisticalDataDTO.getValue()).setScale(4, RoundingMode.HALF_UP).doubleValue()); + } + String targetTag = null; + String targetPhasic = null; + String targetDataType = null; + + String[] tmepUidName = target.split(" / "); + if(tmepUidName.length==2){ + targetTag = tmepUidName[0]; + targetDataType = getDataType(tmepUidName[1]) ; + }else if (tmepUidName.length==3){ + targetTag = tmepUidName[0]; + targetPhasic = tmepUidName[1]; + targetDataType =getDataType(tmepUidName[2]) ; + } else if (tmepUidName.length==4) { + targetTag = tmepUidName[1]; + targetPhasic = tmepUidName[2]; + targetDataType =getDataType(tmepUidName[3]) ; + } + statisticalDataDTO.setStatisticalName((Objects.isNull(targetPhasic)?"":targetPhasic+"相_")+targetTag+"_"+targetDataType); + statisticalDataDTO.setTarget(columnName + "$" + phasic + "$" + dataType); + BeanUtils.copyProperties(statisticalDataDTO,csRtDataVO); + csRtDataVO.setId(id); + csRtDataVO.setUnit(uint); + return csRtDataVO; + } + + public String getDataType(String statItem){ + String valueTypeName = ""; + switch (statItem) { + case "max": + valueTypeName = "最大值"; + break; + case "min": + valueTypeName = "最小值"; + break; + case "avg": + valueTypeName = "平均值"; + break; + case "cp95": + valueTypeName = "cp95值"; + break; + default: + break; + } + return valueTypeName; + } } diff --git a/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/enums/CsSystemResponseEnum.java b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/enums/CsSystemResponseEnum.java index ccb6491..1f1f557 100644 --- a/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/enums/CsSystemResponseEnum.java +++ b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/enums/CsSystemResponseEnum.java @@ -18,7 +18,7 @@ public enum CsSystemResponseEnum { SAME_DATA_ERROR("A0301","数据重复"), CS_SYSTEM_COMMON_ERROR("A00302","治理系统模块异常"), - + BIND_TARGET_ERROR("A00601","指标参数绑定异常"), ; diff --git a/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/pojo/po/EleEpdPqd.java b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/pojo/po/EleEpdPqd.java index 205928e..c980547 100644 --- a/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/pojo/po/EleEpdPqd.java +++ b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/pojo/po/EleEpdPqd.java @@ -146,5 +146,35 @@ public class EleEpdPqd { */ private String defaultValue; + /** + * 状态(0:删除 1:正常) + */ + private Integer status; + + /** + * 报表数据来源(mysql表名) + */ + private String resourcesId; + + /** + * 限值名称 + */ + private String limitName; + + /** + * 限值表名 + */ + private String limitTable; + + /** + * 超标判断方式 + */ + private String formula; + + /** + * 二次值转一次值公式 + */ + private String primaryFormula; + } diff --git a/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/pojo/vo/EleEpdTreeVO.java b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/pojo/vo/EleEpdTreeVO.java new file mode 100644 index 0000000..cecbbb8 --- /dev/null +++ b/cs-system/cs-system-api/src/main/java/com/njcn/cssystem/pojo/vo/EleEpdTreeVO.java @@ -0,0 +1,27 @@ +package com.njcn.cssystem.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class EleEpdTreeVO { + + @ApiModelProperty(name = "id",value = "模板索引") + private String id; + + @ApiModelProperty(name = "name",value = "模板字段名") + private String name; + + @ApiModelProperty(name = "showName",value = "模板中文展示名") + private String showName; + + @ApiModelProperty(name = "flag",value = "用于标识最底层对象 1.表示已经没有子级") + private Integer flag; + + @ApiModelProperty(name = "unit",value = "单位") + private String unit; + + private List children; +} \ No newline at end of file diff --git a/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/controller/zutai/EleEpdPqdController.java b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/controller/zutai/EleEpdPqdController.java new file mode 100644 index 0000000..ebf90aa --- /dev/null +++ b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/controller/zutai/EleEpdPqdController.java @@ -0,0 +1,54 @@ +package com.njcn.cssystem.controller.zutai; + + +import com.njcn.common.pojo.annotation.OperateInfo; +import com.njcn.common.pojo.enums.common.LogEnum; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.HttpResultUtil; +import com.njcn.cssystem.pojo.vo.EleEpdTreeVO; +import com.njcn.cssystem.service.IEleEpdPqdService; +import com.njcn.web.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + *

+ * 前端控制器 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +@Slf4j +@RestController +@RequestMapping("/csDictData") +@Api(tags = "指标数据字典") +@AllArgsConstructor +public class EleEpdPqdController extends BaseController { + + private final IEleEpdPqdService eleEpdPqdService; + + /** + * 获取电能质量指标模板树 + * @author cdf + * @date 2022/8/16 + */ + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @GetMapping("/eleEpdChooseTree") + @ApiOperation("获取电能质量指标模板树") + public HttpResult> eleEpdChooseTree(){ + String methodDescribe = getMethodDescribe("eleEpdChooseTree"); + List res = eleEpdPqdService.eleEpdChooseTree(); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe); + } + +} + diff --git a/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/EleEpdPqdMapper.java b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/EleEpdPqdMapper.java new file mode 100644 index 0000000..d60a130 --- /dev/null +++ b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/EleEpdPqdMapper.java @@ -0,0 +1,19 @@ +package com.njcn.cssystem.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.cssystem.pojo.po.EleEpdPqd; + + +/** + *

+ * Mapper 接口 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +public interface EleEpdPqdMapper extends BaseMapper { + + + +} diff --git a/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/mapping/EleEpdPqdMapper.xml b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/mapping/EleEpdPqdMapper.xml new file mode 100644 index 0000000..2b9988b --- /dev/null +++ b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/mapper/mapping/EleEpdPqdMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/service/IEleEpdPqdService.java b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/service/IEleEpdPqdService.java new file mode 100644 index 0000000..9d18cb5 --- /dev/null +++ b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/service/IEleEpdPqdService.java @@ -0,0 +1,21 @@ +package com.njcn.cssystem.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.cssystem.pojo.po.EleEpdPqd; +import com.njcn.cssystem.pojo.vo.EleEpdTreeVO; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +public interface IEleEpdPqdService extends IService { + + + List eleEpdChooseTree(); +} diff --git a/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/service/impl/EleEpdPqdServiceImpl.java b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/service/impl/EleEpdPqdServiceImpl.java new file mode 100644 index 0000000..25e62f1 --- /dev/null +++ b/cs-system/cs-system-boot/src/main/java/com/njcn/cssystem/service/impl/EleEpdPqdServiceImpl.java @@ -0,0 +1,128 @@ +package com.njcn.cssystem.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.cssystem.mapper.EleEpdPqdMapper; +import com.njcn.cssystem.pojo.po.EleEpdPqd; +import com.njcn.cssystem.pojo.vo.EleEpdTreeVO; +import com.njcn.cssystem.service.IEleEpdPqdService; +import com.njcn.system.api.DicDataFeignClient; +import com.njcn.system.enums.DicDataEnum; +import com.njcn.system.enums.DicDataTypeEnum; +import com.njcn.system.pojo.po.DictData; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + *

+ * 服务实现类 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +@Service +@RequiredArgsConstructor +public class EleEpdPqdServiceImpl extends ServiceImpl implements IEleEpdPqdService { + + private final DicDataFeignClient dicDataFeignClient; + + private final String STR_ONE = "#"; + + private final String STR_TWO = "$"; + + @Override + public List eleEpdChooseTree() { + DictData dic = dicDataFeignClient.getDicDataByNameAndTypeName(DicDataTypeEnum.CS_DATA_TYPE.getName(), DicDataEnum.EPD.getName()).getData(); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(EleEpdPqd::getDataType, dic.getId()).orderByAsc(EleEpdPqd::getSort); + List list = this.getBaseMapper().selectList(lambdaQueryWrapper); + Map> map = list.stream().collect(Collectors.groupingBy(EleEpdPqd::getName, LinkedHashMap::new, Collectors.toList())); + + List tree = new ArrayList<>(); + map.forEach((key, value) -> { + + EleEpdTreeVO reportTreeVO = new EleEpdTreeVO(); + reportTreeVO.setName(value.get(0).getOtherName()); + reportTreeVO.setShowName(value.get(0).getShowName()); + + //存在1-50次 2-50次情况 + if (Objects.nonNull(value.get(0).getHarmStart()) && Objects.nonNull(value.get(0).getHarmEnd())) { + List reHarm = new ArrayList<>(); + for (int i = value.get(0).getHarmStart(); i <= value.get(0).getHarmEnd(); i++) { + EleEpdTreeVO reportTreeCount = new EleEpdTreeVO(); + reportTreeCount.setName(value.get(0).getOtherName() + "_" + i); + reportTreeCount.setShowName(i + "次" + value.get(0).getShowName()); + reportTreeVO.setFlag(1); + assPhase(value, reportTreeCount, reportTreeCount.getName()); + reHarm.add(reportTreeCount); + } + reportTreeVO.setChildren(reHarm); + } else { + assPhase(value, reportTreeVO, value.get(0).getOtherName()); + } + tree.add(reportTreeVO); + }); + return tree; + } + + /*组装相别*/ + private void assPhase(List value, EleEpdTreeVO reportTreeItem, String key) { + List phaseTree = new ArrayList<>(); + value.forEach(item -> { + if (Objects.nonNull(item.getPhase()) && !"M".equals(item.getPhase())) { + List statTree = new ArrayList<>(); + EleEpdTreeVO reportTreePhase = new EleEpdTreeVO(); + reportTreePhase.setName(item.getPhase()); + reportTreePhase.setShowName(item.getPhase()); +// reportTreePhase.setUnit(item.getUnit()); + assStatMethod(item, statTree, key, item.getPhase()); + reportTreePhase.setChildren(statTree); + phaseTree.add(reportTreePhase); + reportTreeItem.setChildren(phaseTree); + + } else { + List statTree = new ArrayList<>(); + assStatMethod(item, statTree, key, "T"); + reportTreeItem.setChildren(statTree); + } + }); + + } + + private void assStatMethod(EleEpdPqd item, List statTree, String oneKey, String twoKey) { + //存在向别为M但是Stat_Method不为空 + if (StrUtil.isNotBlank(item.getStatMethod())) { + String[] arr = item.getStatMethod().split(","); + List stat = Stream.of(arr).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(stat)) { + stat.forEach(statItem -> { + EleEpdTreeVO reportTreeStat = new EleEpdTreeVO(); + reportTreeStat.setUnit(item.getUnit()); + String tem = ""; + if (Objects.nonNull(item.getLimitName())) { + tem = STR_ONE + item.getLimitName(); + } else { + tem = "#NO"; + } + if (StrUtil.isNotBlank(twoKey)) { + reportTreeStat.setName(STR_TWO + oneKey + STR_ONE + twoKey + STR_ONE + statItem + STR_ONE + item.getClassId().trim() + tem.trim() + STR_TWO); + } else { + reportTreeStat.setName(STR_TWO + oneKey + STR_ONE + statItem + STR_ONE + item.getClassId().trim() + tem.trim() + STR_TWO); + } + + reportTreeStat.setShowName(statItem); + statTree.add(reportTreeStat); + }); + } + } + } + +} +