提交一次接线图实时调试

This commit is contained in:
2025-12-19 09:56:53 +08:00
parent 46aef0d97f
commit efdb1781da
20 changed files with 681 additions and 50 deletions

View File

@@ -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<RealTimeDataVo> realTimeDataVoList;
}

View File

@@ -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<DiagramElement> 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<String> lineList;
private String lineName;
@JsonProperty("UID")
private List<List<String>> uid;
@JsonProperty("UIDNames")
private List<String> uidNames;
private List<String> unit;
}
}

View File

@@ -42,6 +42,9 @@ public class CsRtDataVO {
@ApiModelProperty("指标显示名称")
private String statisticalName;
@ApiModelProperty("指标单位")
private String unit;
@ApiModelProperty("指标名称")
private String target;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<CsRtDataVO> 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<StatisticalDataDTO> 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<String> lineIdList = Arrays.stream(payload.substring(1, payload.length() - 1).split(","))
.map(String::trim)
.collect(Collectors.toList());
List<CsRtDataVO> lineData = lineTargetService.getLineDataNew(pageId);
List<CsRtDataVO> 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<String> lineIdList = Arrays.stream(payload.substring(1, payload.length() - 1).split(","))
.map(String::trim)
.collect(Collectors.toList());
// 目前暂且查最近的60条记录
List<CsWarnDescVO> 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<ThdDataVO> result = new ArrayList<>();
List<ThdDataVO> tempList = new ArrayList<>();
//1.查询拓扑图配置的指标:拓扑图扑图配置7677f94c749dedaff30f911949cbd724
List<EleEpdPqd> 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<ThdDataVO> thdDataVOList = stableDataService.QuerySqlData(frequencyStatisticalQueryParam);
tempList.addAll(thdDataVOList);
}else {
} else {
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
commonStatisticalQueryParam.setDevId(devId);
commonStatisticalQueryParam.setStatisticalId(temp.getId());
commonStatisticalQueryParam.setValueType("avg");
List<ThdDataVO> listFuture= stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
tempList.addAll(listFuture);
}
@@ -231,23 +269,23 @@ public class MqttMessageHandler {
//过滤M相
List<ThdDataVO> 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<ThdDataVO> apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> 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<ThdDataVO> apfRmsI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_RmsI_TolOut(A)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> 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<ThdDataVO> apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList());
Map<String, List<ThdDataVO>> 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);

View File

@@ -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<CsEventPO> {
List<CsWarnDescVO> getEventDesc(@Param("lineIdList")List<String> lineIdList, @Param("count")int count);
}

View File

@@ -15,4 +15,26 @@
<!--@mbg.generated-->
id, line_id, device_id, start_time, tag, wave_id
</sql>
<select id="getEventDesc" resultType="com.njcn.csharmonic.pojo.vo.CsWarnDescVO">
SELECT
t1.line_id id,
t2.NAME,
t1.start_time timeId,
t1.amplitude,
t1.persist_time
FROM
cs_event t1,
cs_line t2
WHERE
t1.line_id = t2.line_id
and t1.line_id in
<foreach collection="lineIdList" item="lineId" separator="," open="(" close=")">
#{lineId}
</foreach>
and t1.type = 0
LIMIT 60
</select>
</mapper>

View File

@@ -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<CsEventPO>{
List<EventStatisticsVo> getEventStatistics(CsEventUserQueryParam param);
List<CsWarnDescVO> getEventDesc(List<String> lineIdList);
}

View File

@@ -23,4 +23,9 @@ public interface ILineTargetService {
*/
List<CsRtDataVO> getLineData(String id);
/**
* 获取绑定指标的数据
* @param id
*/
List<CsRtDataVO> getLineDataNew(String id);
}

View File

@@ -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<CsEventPOMapper, CsEventPO
return Collections.emptyList();
}
@Override
public List<CsWarnDescVO> getEventDesc(List<String> lineIdList) {
List<CsWarnDescVO> 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) {

View File

@@ -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<CsRtDataVO> getLineDataNew(String id) {
List<CsRtDataVO> 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<String> 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<ZuTaiDTO>(){}.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;
}
}

View File

@@ -18,7 +18,7 @@ public enum CsSystemResponseEnum {
SAME_DATA_ERROR("A0301","数据重复"),
CS_SYSTEM_COMMON_ERROR("A00302","治理系统模块异常"),
BIND_TARGET_ERROR("A00601","指标参数绑定异常"),
;

View File

@@ -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;
}

View File

@@ -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<EleEpdTreeVO> children;
}

View File

@@ -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;
/**
* <p>
* 前端控制器
* </p>
*
* @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<List<EleEpdTreeVO>> eleEpdChooseTree(){
String methodDescribe = getMethodDescribe("eleEpdChooseTree");
List<EleEpdTreeVO> res = eleEpdPqdService.eleEpdChooseTree();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
}

View File

@@ -0,0 +1,19 @@
package com.njcn.cssystem.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.cssystem.pojo.po.EleEpdPqd;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-24
*/
public interface EleEpdPqdMapper extends BaseMapper<EleEpdPqd> {
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.cssystem.mapper.EleEpdPqdMapper">
</mapper>

View File

@@ -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;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2023-05-24
*/
public interface IEleEpdPqdService extends IService<EleEpdPqd> {
List<EleEpdTreeVO> eleEpdChooseTree();
}

View File

@@ -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;
/**
* <p>
* 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-24
*/
@Service
@RequiredArgsConstructor
public class EleEpdPqdServiceImpl extends ServiceImpl<EleEpdPqdMapper, EleEpdPqd> implements IEleEpdPqdService {
private final DicDataFeignClient dicDataFeignClient;
private final String STR_ONE = "#";
private final String STR_TWO = "$";
@Override
public List<EleEpdTreeVO> eleEpdChooseTree() {
DictData dic = dicDataFeignClient.getDicDataByNameAndTypeName(DicDataTypeEnum.CS_DATA_TYPE.getName(), DicDataEnum.EPD.getName()).getData();
LambdaQueryWrapper<EleEpdPqd> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(EleEpdPqd::getDataType, dic.getId()).orderByAsc(EleEpdPqd::getSort);
List<EleEpdPqd> list = this.getBaseMapper().selectList(lambdaQueryWrapper);
Map<String, List<EleEpdPqd>> map = list.stream().collect(Collectors.groupingBy(EleEpdPqd::getName, LinkedHashMap::new, Collectors.toList()));
List<EleEpdTreeVO> 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<EleEpdTreeVO> 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<EleEpdPqd> value, EleEpdTreeVO reportTreeItem, String key) {
List<EleEpdTreeVO> phaseTree = new ArrayList<>();
value.forEach(item -> {
if (Objects.nonNull(item.getPhase()) && !"M".equals(item.getPhase())) {
List<EleEpdTreeVO> 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<EleEpdTreeVO> statTree = new ArrayList<>();
assStatMethod(item, statTree, key, "T");
reportTreeItem.setChildren(statTree);
}
});
}
private void assStatMethod(EleEpdPqd item, List<EleEpdTreeVO> statTree, String oneKey, String twoKey) {
//存在向别为M但是Stat_Method不为空
if (StrUtil.isNotBlank(item.getStatMethod())) {
String[] arr = item.getStatMethod().split(",");
List<String> 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);
});
}
}
}
}