代码优化
This commit is contained in:
@@ -88,22 +88,26 @@ public class AccessApplicationRunner implements ApplicationRunner {
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": reboot : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
try {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": reboot : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
}
|
||||
csDeviceService.autoAccess(item.getNdid(),version,1);
|
||||
}
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
});
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,22 +82,26 @@ public class AutoAccessTimer implements ApplicationRunner {
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": auto : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
try {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": auto : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
}
|
||||
csDeviceService.autoAccess(item.getNdid(),version,1);
|
||||
}
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
});
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,6 +597,77 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置重新接入系统,需要校验所用的模板
|
||||
* @param nDid
|
||||
* @param version
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean autoAccess(String nDid,String version,Integer mid) {
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
boolean result = false;
|
||||
Map<Integer,String> modelMap = new HashMap<>();
|
||||
try {
|
||||
//删除缓存数据
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||
//询问装置当前所用模板
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
||||
//接收到模板,判断模板是否存在,替换模板,发起接入
|
||||
Thread.sleep(2000);
|
||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||
if (CollUtil.isNotEmpty(modelId)) {
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
//重新录入装置和模板关系信息
|
||||
for (CsModelDto item : modelId) {
|
||||
CsDevModelRelationPO po = new CsDevModelRelationPO();
|
||||
po.setDevId(vo.getId());
|
||||
po.setModelId(item.getModelId());
|
||||
po.setDid(item.getDid());
|
||||
po.setUpdateTime(LocalDateTime.now());
|
||||
csDevModelRelationService.addRelation(po);
|
||||
modelMap.put(item.getType(),item.getModelId());
|
||||
}
|
||||
//修改监测点使用的模板和数据集
|
||||
List<CsLinePO> lineList;
|
||||
Object object = redisUtil.getObjectByKey("accessLineInfo:" + nDid);
|
||||
if (Objects.isNull(object)) {
|
||||
lineList = csLineFeignClient.findByNdid(nDid).getData();
|
||||
for (CsLinePO item : lineList) {
|
||||
if (item.getClDid() == 0) {
|
||||
updateLineIds(modelMap.get(0),item.getClDid(),nDid);
|
||||
} else {
|
||||
updateLineIds(modelMap.get(1),item.getClDid(),nDid);
|
||||
}
|
||||
}
|
||||
}
|
||||
//发起接入
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_5.getCode())),1,false);
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
result = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "装置接入失败");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装报文
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user