1.代码优化
2.便携式设备接入生成定值
This commit is contained in:
@@ -14,6 +14,7 @@ import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
|||||||
import com.njcn.access.enums.AccessEnum;
|
import com.njcn.access.enums.AccessEnum;
|
||||||
import com.njcn.access.enums.AccessResponseEnum;
|
import com.njcn.access.enums.AccessResponseEnum;
|
||||||
import com.njcn.access.enums.TypeEnum;
|
import com.njcn.access.enums.TypeEnum;
|
||||||
|
import com.njcn.access.mapper.OverlimitMapper;
|
||||||
import com.njcn.access.pojo.RspDataDto;
|
import com.njcn.access.pojo.RspDataDto;
|
||||||
import com.njcn.access.pojo.dto.*;
|
import com.njcn.access.pojo.dto.*;
|
||||||
import com.njcn.access.pojo.dto.file.FileDto;
|
import com.njcn.access.pojo.dto.file.FileDto;
|
||||||
@@ -31,6 +32,8 @@ import com.njcn.common.pojo.exception.BusinessException;
|
|||||||
import com.njcn.csdevice.api.*;
|
import com.njcn.csdevice.api.*;
|
||||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||||
import com.njcn.csdevice.pojo.po.*;
|
import com.njcn.csdevice.pojo.po.*;
|
||||||
|
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||||
|
import com.njcn.device.biz.utils.COverlimitUtil;
|
||||||
import com.njcn.mq.message.AppAutoDataMessage;
|
import com.njcn.mq.message.AppAutoDataMessage;
|
||||||
import com.njcn.mq.message.AppEventMessage;
|
import com.njcn.mq.message.AppEventMessage;
|
||||||
import com.njcn.mq.message.AppFileMessage;
|
import com.njcn.mq.message.AppFileMessage;
|
||||||
@@ -89,6 +92,7 @@ public class MqttMessageHandler {
|
|||||||
private final CsLineFeignClient csLineFeignClient;
|
private final CsLineFeignClient csLineFeignClient;
|
||||||
private final DevCapacityFeignClient devCapacityFeignClient;
|
private final DevCapacityFeignClient devCapacityFeignClient;
|
||||||
private final EquipmentFeignClient equipmentFeignClient;
|
private final EquipmentFeignClient equipmentFeignClient;
|
||||||
|
private final OverlimitMapper overlimitMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
Validator validator;
|
Validator validator;
|
||||||
|
|
||||||
@@ -197,20 +201,107 @@ public class MqttMessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 装置类型模板应答
|
||||||
|
// * 1.判断网关的类型
|
||||||
|
// * 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
||||||
|
// * 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
||||||
|
// * @param topic
|
||||||
|
// * @param message
|
||||||
|
// * @param nDid
|
||||||
|
// * @param payload
|
||||||
|
// */
|
||||||
|
// @MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
||||||
|
// @Transactional(rollbackFor = Exception.class)
|
||||||
|
// public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||||
|
// log.info("收到当前设备所用模板响应--->" + nDid);
|
||||||
|
// DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
|
// try{
|
||||||
|
// logDto.setUserName(RequestUtil.getUsername());
|
||||||
|
// logDto.setLoginName(RequestUtil.getLoginName());
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logDto.setUserName("系统重启或定时任务创建");
|
||||||
|
// logDto.setLoginName(null);
|
||||||
|
// }
|
||||||
|
// logDto.setOperate(nDid + "设备类型模板应答");
|
||||||
|
// logDto.setResult(1);
|
||||||
|
// //业务处理
|
||||||
|
// Gson gson = new Gson();
|
||||||
|
// ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
||||||
|
// 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());
|
||||||
|
// logDto.setResult(0);
|
||||||
|
// logDto.setFailReason(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
|
||||||
|
// csLogsFeignClient.addUserLog(logDto);
|
||||||
|
// //有异常删除缓存的模板信息
|
||||||
|
// redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
|
// 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());
|
||||||
|
// logDto.setResult(0);
|
||||||
|
// logDto.setFailReason(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||||
|
// csLogsFeignClient.addUserLog(logDto);
|
||||||
|
// //有异常删除缓存的模板信息
|
||||||
|
// redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
|
// throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
|
||||||
|
// }
|
||||||
|
// if (Objects.equals(po.getType(),0)){
|
||||||
|
// List<CsDataSet> dataSetList = dataSetFeignClient.getModuleDataSet(po.getId()).getData();
|
||||||
|
// if (CollectionUtils.isEmpty(dataSetList)){
|
||||||
|
// logDto.setResult(0);
|
||||||
|
// logDto.setFailReason(AccessResponseEnum.MODULE_NUMBER_IS_NULL.getMessage());
|
||||||
|
// csLogsFeignClient.addUserLog(logDto);
|
||||||
|
// //有异常删除缓存的模板信息
|
||||||
|
// redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
|
// throw new BusinessException(AccessResponseEnum.MODULE_NUMBER_IS_NULL);
|
||||||
|
// }
|
||||||
|
// csModelDto.setModuleNumber(dataSetList.size());
|
||||||
|
// }
|
||||||
|
// csModelDto.setDevType(po.getDevTypeName());
|
||||||
|
// csModelDto.setModelId(po.getId());
|
||||||
|
// csModelDto.setDid(did);
|
||||||
|
// csModelDto.setType(po.getType());
|
||||||
|
// modelList.add(csModelDto);
|
||||||
|
// });
|
||||||
|
// //存储模板id
|
||||||
|
// String key2 = AppRedisKey.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 = AppRedisKey.LINE + nDid;
|
||||||
|
// redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
||||||
|
// //csLogsFeignClient.addUserLog(logDto);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 装置类型模板应答
|
* 设备响应
|
||||||
* 1.判断网关的类型
|
|
||||||
* 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
|
||||||
* 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
|
||||||
* @param topic
|
* @param topic
|
||||||
* @param message
|
* @param message
|
||||||
|
* @param version
|
||||||
* @param nDid
|
* @param nDid
|
||||||
* @param payload
|
* @param payload
|
||||||
*/
|
*/
|
||||||
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
public void devAccessOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||||
log.info("收到当前设备所用模板响应--->" + nDid);
|
//日志实体
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
try{
|
try{
|
||||||
logDto.setUserName(RequestUtil.getUsername());
|
logDto.setUserName(RequestUtil.getUsername());
|
||||||
@@ -219,12 +310,22 @@ public class MqttMessageHandler {
|
|||||||
logDto.setUserName("系统重启或定时任务创建");
|
logDto.setUserName("系统重启或定时任务创建");
|
||||||
logDto.setLoginName(null);
|
logDto.setLoginName(null);
|
||||||
}
|
}
|
||||||
logDto.setOperate(nDid + "设备类型模板应答");
|
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
//业务处理
|
//业务处理
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
|
||||||
|
redisUtil.saveByKeyWithExpire("devResponse",res.getCode(),5L);
|
||||||
|
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||||
|
switch (res.getType()){
|
||||||
|
/**
|
||||||
|
* 装置类型模板应答
|
||||||
|
* 1.判断网关的类型
|
||||||
|
* 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
||||||
|
* 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
||||||
|
*/
|
||||||
|
case 4611:
|
||||||
|
log.info("{},装置模板应答,应答code {}",nDid,res.getCode());
|
||||||
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
||||||
if (Objects.equals(modelDto.getType(),Integer.parseInt(TypeEnum.TYPE_18.getCode()))){
|
|
||||||
List<DevModInfoDto> list = modelDto.getMsg().getDevMod();
|
List<DevModInfoDto> list = modelDto.getMsg().getDevMod();
|
||||||
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
||||||
if (CollectionUtils.isEmpty(list)){
|
if (CollectionUtils.isEmpty(list)){
|
||||||
@@ -282,40 +383,10 @@ public class MqttMessageHandler {
|
|||||||
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
||||||
String key = AppRedisKey.LINE + nDid;
|
String key = AppRedisKey.LINE + nDid;
|
||||||
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
||||||
//csLogsFeignClient.addUserLog(logDto);
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备接入平台应答
|
|
||||||
* @param topic
|
|
||||||
* @param message
|
|
||||||
* @param version
|
|
||||||
* @param nDid
|
|
||||||
* @param payload
|
|
||||||
*/
|
|
||||||
@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){
|
|
||||||
//日志实体
|
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
|
||||||
try{
|
|
||||||
logDto.setUserName(RequestUtil.getUsername());
|
|
||||||
logDto.setLoginName(RequestUtil.getLoginName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logDto.setUserName("系统重启或定时任务创建");
|
|
||||||
logDto.setLoginName(null);
|
|
||||||
}
|
|
||||||
logDto.setResult(1);
|
|
||||||
//业务处理
|
|
||||||
Gson gson = new Gson();
|
|
||||||
ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
|
|
||||||
redisUtil.saveByKeyWithExpire("devResponse",res.getCode(),5L);
|
|
||||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
|
||||||
switch (res.getType()){
|
|
||||||
case 4613:
|
case 4613:
|
||||||
logDto.setOperate(nDid + "设备接入");
|
logDto.setOperate(nDid + "设备接入");
|
||||||
log.info("{}收到接入应答响应,应答code {}",nDid,res.getCode());
|
log.info("{},收到接入应答响应,应答code {}",nDid,res.getCode());
|
||||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||||
int mid = 1;
|
int mid = 1;
|
||||||
//修改装置状态
|
//修改装置状态
|
||||||
@@ -362,10 +433,11 @@ public class MqttMessageHandler {
|
|||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
break;
|
break;
|
||||||
case 4614:
|
case 4614:
|
||||||
log.info("设备数据应答--->" + nDid);
|
|
||||||
RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class);
|
RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class);
|
||||||
|
if (!Objects.isNull(rspDataDto.getDataType())) {
|
||||||
switch (rspDataDto.getDataType()){
|
switch (rspDataDto.getDataType()){
|
||||||
case 1:
|
case 1:
|
||||||
|
log.info("{},设备数据应答--->更新设备软件信息", nDid);
|
||||||
logDto.setOperate(nDid + "更新设备软件信息");
|
logDto.setOperate(nDid + "更新设备软件信息");
|
||||||
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
|
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
|
||||||
//记录设备软件信息
|
//记录设备软件信息
|
||||||
@@ -396,8 +468,8 @@ public class MqttMessageHandler {
|
|||||||
List<RspDataDto.LdevInfo> devInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
|
List<RspDataDto.LdevInfo> devInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
|
||||||
if (CollectionUtil.isNotEmpty(devInfo)){
|
if (CollectionUtil.isNotEmpty(devInfo)){
|
||||||
if (Objects.equals(res.getDid(),1)){
|
if (Objects.equals(res.getDid(),1)){
|
||||||
logDto.setOperate(nDid + "更新治理监测点信息和设备容量");
|
log.info("{},设备数据应答--->更新治理监测点信息和设备容量", nDid);
|
||||||
List<CsDevCapacityPO> list = new ArrayList<>();
|
List<CsDevCapacityPO> list3 = new ArrayList<>();
|
||||||
devInfo.forEach(item->{
|
devInfo.forEach(item->{
|
||||||
//1.更新治理监测点信息
|
//1.更新治理监测点信息
|
||||||
CsLineParam csLineParam = new CsLineParam();
|
CsLineParam csLineParam = new CsLineParam();
|
||||||
@@ -408,7 +480,7 @@ public class MqttMessageHandler {
|
|||||||
csDevCapacity.setLineId(nDid.concat("0"));
|
csDevCapacity.setLineId(nDid.concat("0"));
|
||||||
csDevCapacity.setCldid(item.getClDid());
|
csDevCapacity.setCldid(item.getClDid());
|
||||||
csDevCapacity.setCapacity(Objects.isNull(item.getCapacityA())?0.0:item.getCapacityA());
|
csDevCapacity.setCapacity(Objects.isNull(item.getCapacityA())?0.0:item.getCapacityA());
|
||||||
list.add(csDevCapacity);
|
list3.add(csDevCapacity);
|
||||||
} else {
|
} else {
|
||||||
csLineParam.setLineId(nDid.concat(item.getClDid().toString()));
|
csLineParam.setLineId(nDid.concat(item.getClDid().toString()));
|
||||||
}
|
}
|
||||||
@@ -417,13 +489,19 @@ public class MqttMessageHandler {
|
|||||||
csLineParam.setCtRatio(item.getCtRatio());
|
csLineParam.setCtRatio(item.getCtRatio());
|
||||||
csLineParam.setConType(item.getConType());
|
csLineParam.setConType(item.getConType());
|
||||||
csLineFeignClient.updateLine(csLineParam);
|
csLineFeignClient.updateLine(csLineParam);
|
||||||
|
//生成监测点限值
|
||||||
|
Overlimit overlimit = COverlimitUtil.globalAssemble(item.getVolGrade().floatValue(),10f,10f,10f,0,0);
|
||||||
|
overlimit.setId(nDid.concat(item.getClDid().toString()));
|
||||||
|
overlimitMapper.deleteById(nDid.concat(item.getClDid().toString()));
|
||||||
|
overlimitMapper.insert(overlimit);
|
||||||
});
|
});
|
||||||
if (CollectionUtil.isNotEmpty(list)) {
|
if (CollectionUtil.isNotEmpty(list3)) {
|
||||||
devCapacityFeignClient.addList(list);
|
devCapacityFeignClient.addList(list3);
|
||||||
//3.更新设备模块个数
|
//3.更新设备模块个数
|
||||||
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
|
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
|
||||||
}
|
}
|
||||||
} else if (Objects.equals(res.getDid(),2)) {
|
} else if (Objects.equals(res.getDid(),2)) {
|
||||||
|
log.info("{},设备数据应答--->更新电网侧、负载侧监测点信息", nDid);
|
||||||
logDto.setOperate(nDid + "更新电网侧、负载侧监测点信息");
|
logDto.setOperate(nDid + "更新电网侧、负载侧监测点信息");
|
||||||
//1.更新电网侧、负载侧监测点相关信息
|
//1.更新电网侧、负载侧监测点相关信息
|
||||||
devInfo.forEach(item->{
|
devInfo.forEach(item->{
|
||||||
@@ -443,18 +521,19 @@ public class MqttMessageHandler {
|
|||||||
logDto.setUserName("询问装置项目列表");
|
logDto.setUserName("询问装置项目列表");
|
||||||
logDto.setOperate("监测点:" + (nDid + rspDataDto.getClDid()) + "询问项目列表");
|
logDto.setOperate("监测点:" + (nDid + rspDataDto.getClDid()) + "询问项目列表");
|
||||||
List<RspDataDto.ProjectInfo> projectInfoList = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.ProjectInfo.class);
|
List<RspDataDto.ProjectInfo> projectInfoList = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.ProjectInfo.class);
|
||||||
String key = AppRedisKey.PROJECT_INFO + nDid + rspDataDto.getClDid();
|
String key3 = AppRedisKey.PROJECT_INFO + nDid + rspDataDto.getClDid();
|
||||||
redisUtil.saveByKeyWithExpire(key,projectInfoList,60L);
|
redisUtil.saveByKeyWithExpire(key3,projectInfoList,60L);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4663:
|
case 4663:
|
||||||
log.info("装置操作应答");
|
log.info("装置操作应答");
|
||||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||||
String key = AppRedisKey.CONTROL + nDid;
|
String key4 = AppRedisKey.CONTROL + nDid;
|
||||||
redisUtil.saveByKeyWithExpire(key,"success",10L);
|
redisUtil.saveByKeyWithExpire(key4,"success",10L);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -529,7 +608,8 @@ public class MqttMessageHandler {
|
|||||||
switch (dataDto.getMsg().getDataAttr()) {
|
switch (dataDto.getMsg().getDataAttr()) {
|
||||||
//暂态事件、录波处理、工程信息
|
//暂态事件、录波处理、工程信息
|
||||||
case 0:
|
case 0:
|
||||||
log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
log.info(nDid + "处理事件");
|
||||||
|
//log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||||
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
||||||
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
||||||
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
||||||
@@ -648,7 +728,7 @@ public class MqttMessageHandler {
|
|||||||
public void devErrorInfo(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
|
public void devErrorInfo(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
|
||||||
//解析数据
|
//解析数据
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
//log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||||
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
||||||
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
||||||
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
||||||
@@ -721,7 +801,7 @@ public class MqttMessageHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
reqAndResParam.setMsg(askDataDto);
|
reqAndResParam.setMsg(askDataDto);
|
||||||
log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
//log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
||||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
//1.装置心跳断连
|
//1.装置心跳断连
|
||||||
//2.MQTT客户端不在线
|
//2.MQTT客户端不在线
|
||||||
private void executeMainTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
private void executeMainTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||||
System.out.println("正在执行主任务...");
|
log.info("正在执行主任务...");
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
logDto.setUserName("装置失去心跳触发");
|
logDto.setUserName("装置失去心跳触发");
|
||||||
//判断mqtt
|
//判断mqtt
|
||||||
@@ -133,7 +133,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(5000);
|
||||||
Object object = redisUtil.getObjectByKey("online" + nDid);
|
Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||||
if (Objects.nonNull(object)) {
|
if (Objects.nonNull(object)) {
|
||||||
scheduler.shutdown();
|
scheduler.shutdown();
|
||||||
@@ -165,7 +165,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
addLogs(dto);
|
addLogs(dto);
|
||||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||||
System.out.println(nDid + "执行重连定时任务...");
|
log.info(nDid + "执行重连定时任务...");
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
logDto.setOperate(nDid + "重连定时任务");
|
logDto.setOperate(nDid + "重连定时任务");
|
||||||
//判断客户端
|
//判断客户端
|
||||||
@@ -173,7 +173,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
if (mqttClient) {
|
if (mqttClient) {
|
||||||
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(5000);
|
||||||
Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||||
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.njcn.access.mapper;
|
package com.njcn.access.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,6 +14,8 @@ import com.njcn.device.biz.pojo.po.Overlimit;
|
|||||||
*
|
*
|
||||||
* @author xy
|
* @author xy
|
||||||
*/
|
*/
|
||||||
|
@DS("sjzx")
|
||||||
|
@Mapper
|
||||||
public interface OverlimitMapper extends BaseMapper<Overlimit> {
|
public interface OverlimitMapper extends BaseMapper<Overlimit> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ public class CsDataSetServiceImpl extends ServiceImpl<CsDataSetMapper, CsDataSet
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CsDataSet> getDataSetData(String modelId) {
|
public List<CsDataSet> getDataSetData(String modelId) {
|
||||||
return this.lambdaQuery().eq(CsDataSet::getPid, modelId).list();
|
return this.lambdaQuery().eq(CsDataSet::getPid, modelId).eq(CsDataSet::getDataType,"Stat").list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ import com.njcn.csdevice.pojo.param.CsLedgerParam;
|
|||||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||||
import com.njcn.csdevice.pojo.po.*;
|
import com.njcn.csdevice.pojo.po.*;
|
||||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
|
||||||
import com.njcn.device.biz.utils.COverlimitUtil;
|
|
||||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import com.njcn.system.api.DicDataFeignClient;
|
import com.njcn.system.api.DicDataFeignClient;
|
||||||
@@ -80,7 +78,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
private final ChannelObjectUtil channelObjectUtil;
|
private final ChannelObjectUtil channelObjectUtil;
|
||||||
private final CsLineFeignClient csLineFeignClient;
|
private final CsLineFeignClient csLineFeignClient;
|
||||||
private final DataSetFeignClient dataSetFeignClient;
|
private final DataSetFeignClient dataSetFeignClient;
|
||||||
private final OverlimitMapper overlimitMapper;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
@@ -372,7 +369,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
public String wlDevRegister(String nDid) {
|
public String wlDevRegister(String nDid) {
|
||||||
try {
|
String result = "fail";
|
||||||
// 设备状态判断
|
// 设备状态判断
|
||||||
checkDeviceStatus(nDid);
|
checkDeviceStatus(nDid);
|
||||||
// 询问设备支持的主题信息,并将支持的主题入库
|
// 询问设备支持的主题信息,并将支持的主题入库
|
||||||
@@ -402,12 +399,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
//2.根据模板获取监测点个数,插入监测点表
|
//2.根据模板获取监测点个数,插入监测点表
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||||
if (CollUtil.isEmpty(modelList)){
|
if (CollUtil.isEmpty(modelList)) {
|
||||||
try {
|
|
||||||
throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto);
|
throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto);
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
||||||
list.forEach(item->{
|
list.forEach(item->{
|
||||||
@@ -435,13 +428,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
csLedgerService.addLedgerTree(param);
|
csLedgerService.addLedgerTree(param);
|
||||||
});
|
});
|
||||||
csLineService.saveBatch(csLinePoList);
|
csLineService.saveBatch(csLinePoList);
|
||||||
//生成监测点限值
|
redisUtil.saveByKeyWithExpire("accessLineInfo:" + nDid,csLinePoList,30L);
|
||||||
for(CsLinePO csLinePO: csLinePoList){
|
|
||||||
Overlimit overlimit = COverlimitUtil.globalAssemble(csLinePO.getVolGrade().floatValue(),10f,10f,10f,0,1);
|
|
||||||
overlimit.setId(csLinePO.getLineId());
|
|
||||||
overlimitMapper.deleteById(csLinePO.getLineId());
|
|
||||||
overlimitMapper.insert(overlimit);
|
|
||||||
}
|
|
||||||
//4.生成装置和模板的关系表
|
//4.生成装置和模板的关系表
|
||||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||||
@@ -464,16 +451,19 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
//8.删除redis监测点模板信息
|
//8.删除redis监测点模板信息
|
||||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||||
|
//判断接入状态
|
||||||
|
Thread.sleep(5000);
|
||||||
|
Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||||
|
if (Objects.nonNull(object)) {
|
||||||
|
result = "success";
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logDto.setResult(0);
|
logDto.setResult(0);
|
||||||
logDto.setFailReason(e.getMessage());
|
logDto.setFailReason(e.getMessage());
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
throw new BusinessException(CommonResponseEnum.FAIL);
|
throw new BusinessException(AccessResponseEnum.ACCESS_ERROR);
|
||||||
}
|
|
||||||
return "success";
|
|
||||||
} catch (BusinessException e) {
|
|
||||||
throw new BusinessException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -549,13 +539,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
try {
|
try {
|
||||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
//询问装置当前所用模板
|
//询问装置当前所用模板
|
||||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
||||||
reqAndResParam.setMid(mid);
|
|
||||||
reqAndResParam.setDid(0);
|
|
||||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
|
||||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_3.getCode()));
|
|
||||||
reqAndResParam.setExpire(-1);
|
|
||||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
|
||||||
//接收到模板,判断模板是否存在,替换模板,发起接入
|
//接收到模板,判断模板是否存在,替换模板,发起接入
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||||
@@ -572,7 +556,10 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
modelMap.put(item.getType(),item.getModelId());
|
modelMap.put(item.getType(),item.getModelId());
|
||||||
}
|
}
|
||||||
//修改监测点使用的模板和数据集
|
//修改监测点使用的模板和数据集
|
||||||
List<CsLinePO> lineList = csLineFeignClient.findByNdid(nDid).getData();
|
List<CsLinePO> lineList;
|
||||||
|
Object object = redisUtil.getObjectByKey("accessLineInfo:" + nDid);
|
||||||
|
if (Objects.isNull(object)) {
|
||||||
|
lineList = csLineFeignClient.findByNdid(nDid).getData();
|
||||||
for (CsLinePO item : lineList) {
|
for (CsLinePO item : lineList) {
|
||||||
if (item.getClDid() == 0) {
|
if (item.getClDid() == 0) {
|
||||||
updateLineIds(modelMap.get(0),item.getClDid(),nDid);
|
updateLineIds(modelMap.get(0),item.getClDid(),nDid);
|
||||||
@@ -580,9 +567,9 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
updateLineIds(modelMap.get(1),item.getClDid(),nDid);
|
updateLineIds(modelMap.get(1),item.getClDid(),nDid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//发起接入
|
//发起接入
|
||||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_5.getCode()));
|
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_5.getCode())),1,false);
|
||||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
|
||||||
//录波任务倒计时
|
//录波任务倒计时
|
||||||
redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
||||||
result = true;
|
result = true;
|
||||||
@@ -593,6 +580,19 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装报文
|
||||||
|
*/
|
||||||
|
public ReqAndResDto.Req getJson(Integer mid, String code) {
|
||||||
|
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||||
|
reqAndResParam.setMid(mid);
|
||||||
|
reqAndResParam.setDid(0);
|
||||||
|
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||||
|
reqAndResParam.setExpire(-1);
|
||||||
|
reqAndResParam.setType(Integer.parseInt(code));
|
||||||
|
return reqAndResParam;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改监测点的模板id和数据集id
|
* 修改监测点的模板id和数据集id
|
||||||
*/
|
*/
|
||||||
@@ -605,8 +605,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
csLineFeignClient.updateIds(csLineParam);
|
csLineFeignClient.updateIds(csLineParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台对设备发起主题询问命令
|
* 平台对设备发起主题询问命令
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class RtServiceImpl implements IRtService {
|
|||||||
AppAutoDataMessage.DataArray item = appAutoDataMessage.getMsg().getDataArray().get(0);
|
AppAutoDataMessage.DataArray item = appAutoDataMessage.getMsg().getDataArray().get(0);
|
||||||
//fixme 这边先根据数据集的名称来返回对应实体,这边感觉不太合适,后期有好方案再调整
|
//fixme 这边先根据数据集的名称来返回对应实体,这边感觉不太合适,后期有好方案再调整
|
||||||
//基础数据
|
//基础数据
|
||||||
if (Objects.equals(dataSet.getName(),"Ds$Pqd$Rt$Basic$01")) {
|
if (dataSet.getName().contains("Ds$Pqd$Rt$Basic$")) {
|
||||||
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType());
|
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType());
|
||||||
baseRealDataSet.setLineId(lineId);
|
baseRealDataSet.setLineId(lineId);
|
||||||
baseRealDataSet.setPt(po.getPtRatio().floatValue());
|
baseRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||||
|
|||||||
Reference in New Issue
Block a user