MQTT通讯功能联调
This commit is contained in:
@@ -44,6 +44,24 @@ public enum AccessEnum {
|
||||
TIME_OUT(406,"请求超出了等待时间"),
|
||||
OTHER_ERROR(500,"其他错误"),
|
||||
|
||||
/**
|
||||
* 平台主动获取装置数据
|
||||
*/
|
||||
SOFT_INFO(1,"软件信息"),
|
||||
L_DEV_INFO(2,"逻辑设备信息"),
|
||||
EPD(3,"电能数据"),
|
||||
PQD(4,"电能质量数据"),
|
||||
BMD(5,"基础测量数据"),
|
||||
EVT(6,"事件"),
|
||||
ALM(7,"告警"),
|
||||
STS(8,"状态"),
|
||||
DI(9,"开入"),
|
||||
DO(10,"开出"),
|
||||
PARM(11,"参数"),
|
||||
Set(12,"定值"),
|
||||
INSET(13,"内部定值"),
|
||||
CTRL(14,"控制"),
|
||||
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
@@ -53,6 +53,10 @@ public enum AccessResponseEnum {
|
||||
MODEL_MISS("A0308","模板信息缺失!"),
|
||||
MODEL_VERSION_ERROR("A0308","询问装置模板信息错误"),
|
||||
|
||||
CLDID_IS_NULL("A0309","逻辑子设备标识为空"),
|
||||
LDEVINFO_IS_NULL("A0309","逻辑设备信息为空"),
|
||||
SOFTINFO_IS_NULL("A0309","软件信息为空"),
|
||||
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -48,13 +49,13 @@ public class DevAccessParam implements Serializable {
|
||||
private String position;
|
||||
|
||||
@ApiModelProperty("电压等级")
|
||||
private String volGrade;
|
||||
private Double volGrade;
|
||||
|
||||
@ApiModelProperty("PT变比")
|
||||
private String ptRatio;
|
||||
private Double ptRatio;
|
||||
|
||||
@ApiModelProperty("CT变比")
|
||||
private String ctRatio;
|
||||
private Double ctRatio;
|
||||
|
||||
@ApiModelProperty("中心点经度")
|
||||
@NotNull(message = "中心点经度不能为空")
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.njcn.access.pojo;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/9 10:00
|
||||
*/
|
||||
@Data
|
||||
public class RspDataDto {
|
||||
|
||||
@SerializedName("Cldid")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("DataType")
|
||||
private Integer dataType;
|
||||
|
||||
@SerializedName("DataAttr")
|
||||
private Integer dataAttr;
|
||||
|
||||
@SerializedName("DsNameIdx")
|
||||
private Integer dsNameIdx;
|
||||
|
||||
@SerializedName("DataArray")
|
||||
private Object dataArray;
|
||||
|
||||
|
||||
/**
|
||||
* 软件信息
|
||||
*/
|
||||
@Data
|
||||
public static class SoftInfo {
|
||||
|
||||
@SerializedName("OpAttr")
|
||||
private String opAttr;
|
||||
|
||||
@SerializedName("OsName")
|
||||
private String osName;
|
||||
|
||||
@SerializedName("OsVersion")
|
||||
private String osVersion;
|
||||
|
||||
@SerializedName("AppVersion")
|
||||
private String appVersion;
|
||||
|
||||
@SerializedName("AppDate")
|
||||
private String appDate;
|
||||
|
||||
@SerializedName("AppCheck")
|
||||
private String appCheck;
|
||||
|
||||
@SerializedName("SoftUpdate")
|
||||
private String softUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 软件信息
|
||||
*/
|
||||
@Data
|
||||
public static class LdevInfo {
|
||||
|
||||
@SerializedName("Cldid")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("VolGrade")
|
||||
private Double volGrade;
|
||||
|
||||
@SerializedName("ConType")
|
||||
@ApiModelProperty("接线方式")
|
||||
private Integer conType;
|
||||
|
||||
@SerializedName("PtRatio")
|
||||
private Double ptRatio;
|
||||
|
||||
@SerializedName("CtRatio")
|
||||
private Double ctRatio;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import com.njcn.access.annotation.ParamName;
|
||||
import com.njcn.access.pojo.dto.devModel.DataArrayDto;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/8 10:35
|
||||
*/
|
||||
@Data
|
||||
public class AskDataDto {
|
||||
|
||||
@ParamName("Cldid")
|
||||
private Integer clDid;
|
||||
|
||||
@ParamName("DataType")
|
||||
private Integer dataType;
|
||||
|
||||
@ParamName("DataAttr")
|
||||
private Integer dataAttr;
|
||||
|
||||
@ParamName("Operate")
|
||||
private Integer operate;
|
||||
|
||||
@ParamName("StartTime")
|
||||
private Integer startTime;
|
||||
|
||||
@ParamName("EndTime")
|
||||
private Integer endTime;
|
||||
|
||||
@ParamName("DataArray")
|
||||
private DataArrayDto dataArray;
|
||||
}
|
||||
@@ -18,4 +18,6 @@ public class CsModelDto {
|
||||
|
||||
private Integer did;
|
||||
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ModelDto implements Serializable {
|
||||
@SerializedName("Type")
|
||||
@ApiModelProperty("消息类型")
|
||||
@NotNull(message = "消息类型不能为空")
|
||||
private String type;
|
||||
private Integer type;
|
||||
|
||||
@SerializedName("Msg")
|
||||
@ApiModelProperty("报文内容")
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.njcn.access.pojo.dto.devModel;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.hpsf.Decimal;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -18,23 +20,26 @@ import java.io.Serializable;
|
||||
public class LDevInfoDto implements Serializable {
|
||||
|
||||
@SerializedName("OpAttr")
|
||||
@NotEmpty(message = "读写操作属性,不可为空")
|
||||
private String opAttr;
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@ApiModelProperty(value = "逻辑子设备Id")
|
||||
private Integer cldId;
|
||||
|
||||
@SerializedName("VolGrade")
|
||||
@ApiModelProperty(value = "电压等级")
|
||||
private String volGrade;
|
||||
private Double volGrade;
|
||||
|
||||
@SerializedName("ConType")
|
||||
@ApiModelProperty(value = "接线方式")
|
||||
private String conType;
|
||||
private Integer conType;
|
||||
|
||||
@SerializedName("PtRatio")
|
||||
@ApiModelProperty(value = "PT变比")
|
||||
private String ptRatio;
|
||||
private BigDecimal ptRatio;
|
||||
|
||||
@SerializedName("CtRatio")
|
||||
@ApiModelProperty(value = "CT变比")
|
||||
private String ctRatio;
|
||||
private BigDecimal ctRatio;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ 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.csdevice.enums.DeviceOperate;
|
||||
import com.njcn.web.advice.DeviceLog;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@@ -37,6 +39,7 @@ public class CsDeviceController extends BaseController {
|
||||
@PostMapping("/register")
|
||||
@ApiOperation("直连设备状态判断")
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||
@DeviceLog(operateType = DeviceOperate.JUDGE_ONLINE)
|
||||
public HttpResult<String> devRegister(@RequestParam String nDid){
|
||||
csDeviceService.devRegister(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, "设备MQTT通讯状态!");
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/csSoftInfo")
|
||||
public class CsSoftInfoController extends BaseController {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.njcn.access.handler;
|
||||
|
||||
import com.alibaba.excel.util.CollectionUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
||||
import com.github.tocrhz.mqtt.annotation.NamedValue;
|
||||
import com.github.tocrhz.mqtt.annotation.Payload;
|
||||
@@ -9,7 +11,9 @@ import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.RspDataDto;
|
||||
import com.njcn.access.pojo.dto.*;
|
||||
import com.njcn.access.pojo.dto.devModel.LDevInfoDto;
|
||||
import com.njcn.access.pojo.dto.heart.HeartBeatDto;
|
||||
import com.njcn.access.pojo.param.ReqAndResParam;
|
||||
import com.njcn.access.pojo.po.CsLineModel;
|
||||
@@ -143,40 +147,43 @@ public class MqttMessageHandler {
|
||||
public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||
Gson gson = new Gson();
|
||||
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
||||
List<DevModInfoDto> list = modelDto.getMsg().getDevMod();
|
||||
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
log.error(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_VERSION_ERROR);
|
||||
}
|
||||
//校验前置传递的装置模板库中是否存在
|
||||
List<CsModelDto> modelList = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Integer did = null;
|
||||
for (DevCfgDto item2 : list2) {
|
||||
if (Objects.equals(item.getDevType(),item2.getDevType())){
|
||||
did = item2.getDid();
|
||||
if (Objects.equals(modelDto.getType(),Integer.parseInt(TypeEnum.TYPE_18.getCode()))){
|
||||
List<DevModInfoDto> list = modelDto.getMsg().getDevMod();
|
||||
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
log.error(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_VERSION_ERROR);
|
||||
}
|
||||
//校验前置传递的装置模板库中是否存在
|
||||
List<CsModelDto> modelList = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Integer did = null;
|
||||
for (DevCfgDto item2 : list2) {
|
||||
if (Objects.equals(item.getDevType(),item2.getDevType())){
|
||||
did = item2.getDid();
|
||||
}
|
||||
}
|
||||
}
|
||||
CsModelDto csModelDto = new CsModelDto();
|
||||
CsDevModelPO po = devModelFeignClient.findModel(item.getDevType(),item.getVersionNo(),item.getVersionDate()).getData();
|
||||
if (Objects.isNull(po)){
|
||||
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
|
||||
}
|
||||
csModelDto.setDevType(po.getDevTypeName());
|
||||
csModelDto.setModelId(po.getId());
|
||||
csModelDto.setDid(did);
|
||||
modelList.add(csModelDto);
|
||||
});
|
||||
//存储模板id
|
||||
String key2 = "MODEL" + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key2,modelList,600L);
|
||||
//存储监测点模板信息,用于界面回显
|
||||
List<String> modelId = modelList.stream().map(CsModelDto::getModelId).collect(Collectors.toList());
|
||||
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
||||
String key = "LINE" + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
||||
CsModelDto csModelDto = new CsModelDto();
|
||||
CsDevModelPO po = devModelFeignClient.findModel(item.getDevType(),item.getVersionNo(),item.getVersionDate()).getData();
|
||||
if (Objects.isNull(po)){
|
||||
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
|
||||
}
|
||||
csModelDto.setDevType(po.getDevTypeName());
|
||||
csModelDto.setModelId(po.getId());
|
||||
csModelDto.setDid(did);
|
||||
csModelDto.setType(po.getType());
|
||||
modelList.add(csModelDto);
|
||||
});
|
||||
//存储模板id
|
||||
String key2 = "MODEL" + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key2,modelList,600L);
|
||||
//存储监测点模板信息,用于界面回显
|
||||
List<String> modelId = modelList.stream().map(CsModelDto::getModelId).collect(Collectors.toList());
|
||||
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
||||
String key = "LINE" + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,20 +197,39 @@ public class MqttMessageHandler {
|
||||
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void devAccessOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||
log.info("收到接入应答响应--->" + nDid);
|
||||
Gson gson = new Gson();
|
||||
ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
if (Objects.equals(res.getType(),Integer.parseInt(TypeEnum.TYPE_20.getCode()))){
|
||||
//修改装置状态
|
||||
equipmentFeignClient.updateStatusBynDid(nDid, AccessEnum.ACCESS.getCode());
|
||||
//装置接入之后再设置心跳时间,超时改为掉线
|
||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||
} else {
|
||||
log.info(AccessResponseEnum.MESSAGE_TYPE_ERROR.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
|
||||
switch (res.getType()){
|
||||
case 8453:
|
||||
log.info("收到接入应答响应--->" + nDid);
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
//修改装置状态
|
||||
equipmentFeignClient.updateStatusBynDid(nDid, AccessEnum.ACCESS.getCode());
|
||||
//装置接入之后再设置心跳时间,超时改为掉线
|
||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||
} else {
|
||||
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
|
||||
}
|
||||
break;
|
||||
case 4614:
|
||||
log.info("设备数据应答--->" + nDid);
|
||||
RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class);
|
||||
switch (rspDataDto.getDataType()){
|
||||
case 1:
|
||||
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
|
||||
redisUtil.saveByKeyWithExpire("SOFTINFO"+nDid,softInfo,60L);
|
||||
break;
|
||||
case 2:
|
||||
List<RspDataDto.LdevInfo> ldevInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
|
||||
//fixme 默认第一个监测点是负载侧,第二个是电网测,后期数据错误可以在移动端调整
|
||||
redisUtil.saveByKeyWithExpire("LINEDATA"+nDid,ldevInfo,60L);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
public interface CsSoftInfoMapper extends BaseMapper<CsSoftInfoPO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
public interface ICsSoftInfoService extends IService<CsSoftInfoPO> {
|
||||
|
||||
}
|
||||
@@ -870,7 +870,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
CsLineModel csLineModel = new CsLineModel();
|
||||
csLineModel.setLineId(IdUtil.fastSimpleUUID());
|
||||
csLineModel.setPid(pId);
|
||||
//fixme 默认第一个监测点是负载侧,第二个是电网测
|
||||
//fixme 默认第一个监测点是负载侧,第二个是电网测,后期数据错误可以在移动端调整
|
||||
if (Objects.equals(item.getClDid(),1)){
|
||||
csLineModel.setName("负载侧监测点");
|
||||
csLineModel.setPosition(dicDataFeignClient.getDicDataByCode(DicDataEnum.LOAD_SIDE.getCode()).getData().getId());
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.excel.util.CollectionUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.param.DevAccessParam;
|
||||
import com.njcn.access.pojo.RspDataDto;
|
||||
import com.njcn.access.pojo.dto.AccessDto;
|
||||
import com.njcn.access.pojo.dto.AskDataDto;
|
||||
import com.njcn.access.pojo.dto.CsModelDto;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
import com.njcn.access.service.ICsDeviceService;
|
||||
import com.njcn.access.service.ICsSoftInfoService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
@@ -23,6 +29,7 @@ import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
@@ -30,10 +37,10 @@ import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -74,6 +81,10 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
private final ICsTopicService csTopicService;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final ICsSoftInfoService csSoftInfoService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void devRegister(String nDid) {
|
||||
@@ -130,6 +141,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void devAccess(DevAccessParam devAccessParam) {
|
||||
try {
|
||||
String version = csTopicService.getVersion(devAccessParam.getNDid());
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(devAccessParam.getNDid()).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
List<AppLineTopologyDiagramPO> appLineTopologyDiagramPoList = new ArrayList<>();
|
||||
@@ -141,18 +153,55 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csLedgerParam.setLevel(2);
|
||||
csLedgerParam.setSort(0);
|
||||
csLedgerFeignClient.add(csLedgerParam);
|
||||
//2.监测点表录入关系
|
||||
//todo 获取逻辑设备信息,更新监测点pt、ct相关信息 LdevInfo
|
||||
devAccessParam.getList().forEach(item->{
|
||||
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey("MODEL" + devAccessParam.getNDid()));
|
||||
Integer clDid = null;
|
||||
//2.新增装置-模板关系、获取电能质量的逻辑设备id
|
||||
for (CsModelDto item : modelId) {
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
csDevModelRelationAddParm.setModelId(item.getModelId());
|
||||
csDevModelRelationAddParm.setDid(item.getDid());
|
||||
devModelRelationFeignClient.addDevModelRelation(csDevModelRelationAddParm);
|
||||
if (Objects.equals(item.getType(),1)){
|
||||
clDid = item.getDid();
|
||||
}
|
||||
}
|
||||
if (Objects.isNull(clDid)){
|
||||
throw new BusinessException(AccessResponseEnum.CLDID_IS_NULL);
|
||||
}
|
||||
askDevData(devAccessParam.getNDid(),AccessEnum.L_DEV_INFO.getCode(),version,clDid);
|
||||
List<RspDataDto.LdevInfo> list = new ArrayList<>();
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
String key = "LINEDATA" + devAccessParam.getNDid();
|
||||
list = objectToList2(redisUtil.getObjectByKey(key));
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
throw new BusinessException(AccessResponseEnum.LDEVINFO_IS_NULL);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//3.监测点表录入关系
|
||||
for (DevAccessParam.LineParam item : devAccessParam.getList()) {
|
||||
String location = dicDataFeignClient.getDicDataById(item.getPosition()).getData().getCode();
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
CsLinePO po = new CsLinePO();
|
||||
po.setLineId(id);
|
||||
po.setName(item.getName());
|
||||
po.setPosition(item.getPosition());
|
||||
//todo 目前电压等级、ct、pt数据不确定 后期补
|
||||
// po.setVolGrade(item.getVolGrade());
|
||||
// po.setPtRatio(item.getPtRatio());
|
||||
// po.setCtRatio(item.getCtRatio());
|
||||
if (Objects.equals(DicDataEnum.LOAD_SIDE.getCode(),location)){
|
||||
RspDataDto.LdevInfo po1 = list.stream().filter(s -> Objects.equals(s.getClDid(),1)).findFirst().orElse(null);
|
||||
po.setVolGrade(po1.getVolGrade());
|
||||
po.setPtRatio(po1.getPtRatio());
|
||||
po.setCtRatio(po1.getCtRatio());
|
||||
po.setConType(po1.getConType());
|
||||
} else if (Objects.equals(DicDataEnum.GRID_SIDE.getCode(),location)){
|
||||
RspDataDto.LdevInfo po1 = list.stream().filter(s -> Objects.equals(s.getClDid(),2)).findFirst().orElse(null);
|
||||
po.setVolGrade(po1.getVolGrade());
|
||||
po.setPtRatio(po1.getPtRatio());
|
||||
po.setCtRatio(po1.getCtRatio());
|
||||
po.setConType(po1.getConType());
|
||||
}
|
||||
po.setStatus(1);
|
||||
csLinePoList.add(po);
|
||||
CsLedgerParam param = new CsLedgerParam();
|
||||
@@ -169,20 +218,10 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
appLineTopologyDiagramPo.setLng(item.getLng());
|
||||
appLineTopologyDiagramPo.setStatus("1");
|
||||
appLineTopologyDiagramPoList.add(appLineTopologyDiagramPo);
|
||||
});
|
||||
}
|
||||
csLineFeignClient.addLineList(csLinePoList);
|
||||
//3.监测点拓扑图表录入关系
|
||||
//4.监测点拓扑图表录入关系
|
||||
csLineTopologyFeignClient.addList(appLineTopologyDiagramPoList);
|
||||
//4.新增装置-模板关系
|
||||
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey("MODEL" + devAccessParam.getNDid()));
|
||||
modelId.forEach(item->{
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
csDevModelRelationAddParm.setModelId(item.getModelId());
|
||||
csDevModelRelationAddParm.setDid(item.getDid());
|
||||
devModelRelationFeignClient.addDevModelRelation(csDevModelRelationAddParm);
|
||||
});
|
||||
redisUtil.delete("MODEL" + devAccessParam.getNDid());
|
||||
//5.修改装置状态
|
||||
equipmentFeignClient.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
|
||||
//6.绑定装置和人的关系
|
||||
@@ -192,14 +231,33 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
po.setSubUserId(RequestUtil.getUserIndex());
|
||||
po.setDeviceId(vo.getId());
|
||||
csDeviceUserFeignClient.add(Collections.singletonList(po));
|
||||
//7.删除redis监测点模板信息
|
||||
redisUtil.delete("LINE" + devAccessParam.getNDid());
|
||||
//todo 录入软件信息 SoftInfo
|
||||
|
||||
askDevData(devAccessParam.getNDid(),AccessEnum.SOFT_INFO.getCode(),version,0);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
String key = "SOFTINFO" + devAccessParam.getNDid();
|
||||
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(redisUtil.getObjectByKey(key)), RspDataDto.SoftInfo.class);
|
||||
if (Objects.isNull(softInfo)){
|
||||
throw new BusinessException(AccessResponseEnum.SOFTINFO_IS_NULL);
|
||||
}
|
||||
//记录设备软件信息
|
||||
CsSoftInfoPO csSoftInfoPo = new CsSoftInfoPO();
|
||||
BeanUtils.copyProperties(softInfo,csSoftInfoPo);
|
||||
csSoftInfoService.save(csSoftInfoPo);
|
||||
//更新设备表软件信息
|
||||
equipmentFeignClient.updateSoftInfoBynDid(devAccessParam.getNDid(),csSoftInfoPo.getId());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//todo 9.记录注册日志
|
||||
|
||||
//删除redis监测点模板信息
|
||||
redisUtil.delete("MODEL" + devAccessParam.getNDid());
|
||||
redisUtil.delete("LINE" + devAccessParam.getNDid());
|
||||
redisUtil.delete("LINEDATA" + devAccessParam.getNDid());
|
||||
redisUtil.delete("SOFTINFO" + devAccessParam.getNDid());
|
||||
//发起自动接入请求
|
||||
devAccess(devAccessParam.getNDid());
|
||||
//devAccess(devAccessParam.getNDid(),version);
|
||||
//todo 10.记录接入日志
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -208,8 +266,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
}
|
||||
|
||||
|
||||
public void devAccess(String nDid) {
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
public void devAccess(String nDid,String version) {
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(1);
|
||||
reqAndResParam.setDid(0);
|
||||
@@ -263,4 +320,42 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
return urlList;
|
||||
}
|
||||
|
||||
public List<RspDataDto.LdevInfo> objectToList2(Object object) {
|
||||
List<RspDataDto.LdevInfo> urlList = new ArrayList<>();
|
||||
if (object != null) {
|
||||
if (object instanceof ArrayList<?>) {
|
||||
for (Object o : (List<?>) object) {
|
||||
urlList.add((RspDataDto.LdevInfo) o);
|
||||
}
|
||||
}
|
||||
}
|
||||
return urlList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台向设备发送数据命令
|
||||
*/
|
||||
public void askDevData(String nDid,Integer dataType,String version,Integer did){
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(1);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_6.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
AskDataDto askDataDto = new AskDataDto();
|
||||
askDataDto.setClDid(-1);
|
||||
askDataDto.setDataAttr(0);
|
||||
askDataDto.setOperate(1);
|
||||
askDataDto.setStartTime(-1);
|
||||
askDataDto.setEndTime(-1);
|
||||
if (Objects.equals(dataType,AccessEnum.SOFT_INFO.getCode())){
|
||||
reqAndResParam.setDid(did);
|
||||
askDataDto.setDataType(1);
|
||||
} else if (Objects.equals(dataType,AccessEnum.L_DEV_INFO.getCode())){
|
||||
reqAndResParam.setDid(did);
|
||||
askDataDto.setDataType(2);
|
||||
}
|
||||
reqAndResParam.setMsg(askDataDto);
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, PubUtils.obj2json(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.mapper.CsSoftInfoMapper;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
import com.njcn.access.service.ICsSoftInfoService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
@Service
|
||||
public class CsSoftInfoServiceImpl extends ServiceImpl<CsSoftInfoMapper, CsSoftInfoPO> implements ICsSoftInfoService {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user