暂态事件处理
This commit is contained in:
@@ -20,6 +20,8 @@ public enum AccessResponseEnum {
|
||||
MODEL_REPEAT("A0302", "模板存在,请勿重复录入!"),
|
||||
MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"),
|
||||
|
||||
DICT_ANALYSIS_ERROR("A0303","字典解析错误!"),
|
||||
MODEL_ANALYSIS_ERROR("A0303","模板解析错误!"),
|
||||
MESSAGE_TYPE_ERROR("A0303","报文消息类型Type错误!"),
|
||||
DEV_TYPE_ERROR("A0303","装置类型错误!"),
|
||||
DEV_NOT_FIND("A0303","装置类型未找到!"),
|
||||
@@ -58,6 +60,8 @@ public enum AccessResponseEnum {
|
||||
LDEVINFO_IS_NULL("A0309","逻辑设备信息为空"),
|
||||
SOFTINFO_IS_NULL("A0309","软件信息为空"),
|
||||
|
||||
LINE_POSITION_REPEAT("A0310","监测点位置重复")
|
||||
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@@ -62,6 +62,7 @@ public enum TypeEnum {
|
||||
DATA_12("12","定值Set"),
|
||||
DATA_13("13","内部定值InSet"),
|
||||
DATA_14("14","控制Ctrl"),
|
||||
DATA_16("16","波形文件"),
|
||||
|
||||
/**
|
||||
* 数据模型列表
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/22 11:36
|
||||
*/
|
||||
@Data
|
||||
public class EventDto {
|
||||
|
||||
@SerializedName("Mid")
|
||||
private Integer mid;
|
||||
|
||||
@SerializedName("Did")
|
||||
@ApiModelProperty("逻辑设备 治理逻辑设备为1 电能质量设备为2")
|
||||
private Integer did;
|
||||
|
||||
@SerializedName("Pri")
|
||||
private Integer pri;
|
||||
|
||||
@SerializedName("Type")
|
||||
private Integer type;
|
||||
|
||||
@SerializedName("Msg")
|
||||
private Msg msg;
|
||||
|
||||
@Data
|
||||
public static class Msg{
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@ApiModelProperty("逻辑子设备 治理逻辑设备为0 电能质量设备为1、2")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("DataType")
|
||||
private Integer dataType;
|
||||
|
||||
@SerializedName("DataAttr")
|
||||
@ApiModelProperty("数据属性:无-0、实时-1、统计-2")
|
||||
private Integer dataAttr;
|
||||
|
||||
@SerializedName("DsNameIdx")
|
||||
private Integer dsNameIdx;
|
||||
|
||||
@SerializedName("DataArray")
|
||||
private List<DataArray> dataArray;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DataArray{
|
||||
|
||||
@SerializedName("Idx")
|
||||
private Integer idx;
|
||||
|
||||
@SerializedName("Name")
|
||||
private String name;
|
||||
|
||||
@SerializedName("DataTimeSec")
|
||||
private Long dataTimeSec;
|
||||
|
||||
@SerializedName("DataTimeUSec")
|
||||
private Long dataTimeUSec;
|
||||
|
||||
@SerializedName("Type")
|
||||
@ApiModelProperty("事件类型")
|
||||
private String type;
|
||||
|
||||
@SerializedName("Parm")
|
||||
private List<Param> param;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Param{
|
||||
|
||||
@SerializedName("Name")
|
||||
private String name;
|
||||
|
||||
@SerializedName("Type")
|
||||
private String type;
|
||||
|
||||
@SerializedName("Unit")
|
||||
private String unit;
|
||||
|
||||
@SerializedName("Data")
|
||||
private Object data;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.njcn.access.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 事件参数表
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-05-19
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@TableName("cs_evt_parm")
|
||||
public class CsEvtParmPO extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* pid
|
||||
*/
|
||||
@MppMultiId(value = "pid")
|
||||
private String pid;
|
||||
|
||||
/**
|
||||
* 事件信息名称
|
||||
*/
|
||||
@MppMultiId(value = "name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 参数类型“string”“float”
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 参数单位
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 参数值
|
||||
*/
|
||||
private String data;
|
||||
|
||||
}
|
||||
@@ -25,8 +25,11 @@ import com.njcn.csdevice.api.DataSetFeignClient;
|
||||
import com.njcn.csdevice.api.DevModelFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsDataSet;
|
||||
import com.njcn.csdevice.pojo.po.CsDevModelPO;
|
||||
import com.njcn.mq.constant.BusinessTopic;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.mq.template.AppAutoDataMessageTemplate;
|
||||
import com.njcn.mq.template.AppEventMessageTemplate;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -65,9 +68,11 @@ public class MqttMessageHandler {
|
||||
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
|
||||
private final AppAutoDataMessageTemplate appAutoDataMessageTemplate;
|
||||
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
private final AppEventMessageTemplate appEventMessageTemplate;
|
||||
|
||||
@Autowired
|
||||
Validator validator;
|
||||
@@ -293,12 +298,33 @@ public class MqttMessageHandler {
|
||||
}
|
||||
break;
|
||||
case 4866:
|
||||
//处理主动上送数据
|
||||
AutoDataDto dataDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), AutoDataDto.class);
|
||||
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(dataDto));
|
||||
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject, AppAutoDataMessage.class);
|
||||
appAutoDataMessage.setId(nDid);
|
||||
appAutoDataMessageTemplate.sendMember(appAutoDataMessage);
|
||||
switch (dataDto.getMsg().getDataAttr()) {
|
||||
//暂态事件、录波处理
|
||||
//todo 后期告警可能也是在这处理,通过是告警还是事件来区分暂态和稳态
|
||||
case 0:
|
||||
log.info("处理事件");
|
||||
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
||||
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
||||
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
||||
appEventMessage.setId(nDid);
|
||||
appEventMessageTemplate.sendMember(appEventMessage);
|
||||
break;
|
||||
//实时数据
|
||||
case 1:
|
||||
log.info("处理实时数据");
|
||||
break;
|
||||
//处理主动上送的统计数据
|
||||
case 2:
|
||||
log.info("处理统计数据");
|
||||
JSONObject jsonObject2 = JSONObject.parseObject(JSON.toJSONString(dataDto));
|
||||
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject2, AppAutoDataMessage.class);
|
||||
appAutoDataMessage.setId(nDid);
|
||||
appAutoDataMessageTemplate.sendMember(appAutoDataMessage);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//mid大于0,则需要应答设备侧
|
||||
if (dataDto.getMid() > 0){
|
||||
ReqAndResDto.Res response = new ReqAndResDto.Res();
|
||||
|
||||
@@ -85,8 +85,8 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
analysisDataSet(templateDto,csDevModelPo.getId());
|
||||
//3.录入监测点模板表(记录当前模板有几个监测点,治理类型的模板目前规定1个监测点,电能质量模板根据逻辑子设备来)
|
||||
addCsLineModel(templateDto,csDevModelPo.getId());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_ANALYSIS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
Gson gson = new Gson();
|
||||
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
|
||||
analysisDict(templateDto);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(AccessResponseEnum.DICT_ANALYSIS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,6 +201,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEvtParam.setPid(po.getId());
|
||||
eleEvtParam.setData(param.getData());
|
||||
eleEvtParam.setName(param.getName());
|
||||
eleEvtParam.setShowName(param.getName());
|
||||
eleEvtParam.setType(param.getType());
|
||||
eleEvtParam.setUnit(param.getUnit());
|
||||
eleEvtFeignClient.add(eleEvtParam);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.excel.util.CollectionUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -46,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -228,6 +230,11 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
appLineTopologyDiagramPo.setStatus("1");
|
||||
appLineTopologyDiagramPoList.add(appLineTopologyDiagramPo);
|
||||
}
|
||||
List<String> position = csLinePoList.stream().map(CsLinePO::getPosition).collect(Collectors.toList());
|
||||
List<String> lineList = position.stream().filter(e-> Collections.frequency(position,e) > 1).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(lineList)){
|
||||
throw new BusinessException(AccessResponseEnum.LINE_POSITION_REPEAT);
|
||||
}
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
//4.监测点拓扑图表录入关系
|
||||
appLineTopologyDiagramService.saveBatch(appLineTopologyDiagramPoList);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.common.reflect.TypeToken;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
@@ -11,6 +12,7 @@ import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.dto.mqtt.MqttClientDto;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import io.lettuce.core.protocol.CompleteableCommand;
|
||||
import okhttp3.Credentials;
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -25,8 +27,9 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -56,12 +59,34 @@ public class AppTest
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ReqAndResDto reqAndResParam = new ReqAndResDto();
|
||||
reqAndResParam.setMid(1);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(4866);
|
||||
publisher.send("/Dev/Data1/V1/123", new Gson().toJson(reqAndResParam),1,false);
|
||||
// ReqAndResDto reqAndResParam = new ReqAndResDto();
|
||||
// reqAndResParam.setMid(1);
|
||||
// reqAndResParam.setDid(0);
|
||||
// reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
// reqAndResParam.setType(4866);
|
||||
// publisher.send("/Dev/Data1/V1/123", new Gson().toJson(reqAndResParam),1,false);
|
||||
|
||||
// String key = String.valueOf(IdUtil.getSnowflake().nextId());
|
||||
// System.out.println("key==:" + key);
|
||||
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
CsLinePO po1 = new CsLinePO();
|
||||
po1.setPosition("1");
|
||||
CsLinePO po2= new CsLinePO();
|
||||
po2.setPosition("2");
|
||||
CsLinePO po3= new CsLinePO();
|
||||
po3.setPosition("3");
|
||||
CsLinePO po4= new CsLinePO();
|
||||
po4.setPosition("1");
|
||||
|
||||
csLinePoList.add(po1);
|
||||
csLinePoList.add(po2);
|
||||
csLinePoList.add(po3);
|
||||
csLinePoList.add(po4);
|
||||
List<String> l = csLinePoList.stream().map(CsLinePO::getPosition).collect(Collectors.toList());
|
||||
System.out.println("l===:" + l);
|
||||
List<String> lineList = l.stream().filter(e-> Collections.frequency(l,e) > 1).distinct().collect(Collectors.toList());
|
||||
System.out.println("lineList==:" + lineList);
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user