新增物接入流程
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
package com.njcn.access.handler;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
||||
import com.github.tocrhz.mqtt.annotation.NamedValue;
|
||||
import com.github.tocrhz.mqtt.annotation.Payload;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.pojo.dto.*;
|
||||
import com.njcn.algorithm.api.DevModelFeignClient;
|
||||
import com.njcn.algorithm.api.EquipmentFeignClient;
|
||||
import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm;
|
||||
import com.njcn.algorithm.pojo.vo.CsDevModelPageVO;
|
||||
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年03月23日 09:41
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class MqttMessageHandler {
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final DevModelFeignClient devModelFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 接收装置接入响应
|
||||
* 1.收到注册信息,修改装置出厂表,装置的状态,调整为注册;然后开始接入流程
|
||||
* 2.询问当前装置类型的模板。有则完成接入;没有则告警出来,需要人工手动上传模板信息
|
||||
* @param topic
|
||||
* @param message
|
||||
* @param payload
|
||||
*/
|
||||
@MqttSubscribe(value = "/device/register/{nDid}",qos = 1)
|
||||
public void devOperation(String topic, MqttMessage message, @NamedValue("nDid") String nDid, @Payload String payload){
|
||||
Gson gson = new Gson();
|
||||
RegisterDTO.RegisterResponse registerDTO = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), RegisterDTO.RegisterResponse.class);
|
||||
if (registerDTO.getCode() == 200){
|
||||
//todo 调整装置出厂表状态
|
||||
|
||||
|
||||
PublicDto publicDto = new PublicDto();
|
||||
publicDto.setMid(Long.toString(Instant.now().toEpochMilli()));
|
||||
publicDto.setNDid(nDid);
|
||||
publicDto.setTimestamp(Instant.now().toEpochMilli());
|
||||
publicDto.setType("CMD_DEV_DATA");
|
||||
AccessDto accessDto = new AccessDto();
|
||||
accessDto.setNDid(nDid);
|
||||
accessDto.setDevType(registerDTO.getParam().getDev_type());
|
||||
publicDto.setParam(accessDto);
|
||||
publisher.send("/platform/devcmd/"+nDid,new Gson().toJson(publicDto),1,false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置类型模板相应
|
||||
* 1.判断网关的类型
|
||||
* 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
||||
* 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
||||
* @param topic
|
||||
* @param message
|
||||
* @param nDid
|
||||
* @param payload
|
||||
*/
|
||||
@MqttSubscribe(value = "/device/devack/{nDid}",qos = 1)
|
||||
public void devModelOperation(String topic, MqttMessage message, @NamedValue("nDid") String nDid, @Payload String payload){
|
||||
Gson gson = new Gson();
|
||||
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
||||
HttpResult<CsEquipmentDeliveryVO> pojo = equipmentFeignClient.queryEquipmentByndid(nDid);
|
||||
if (!Objects.isNull(pojo)){
|
||||
String devType = pojo.getData().getDevType();
|
||||
if (Objects.equals(devType,"直连设备")){
|
||||
List<DevModelDto> list = modelDto.getDevMod();
|
||||
list.forEach(item->{
|
||||
//todo 根据条件查询库中是否有符合条件的数据
|
||||
DictData dicData = dicDataFeignClient.getDicDataByCode(item.getDevType()).getData();
|
||||
CsDevModelQueryListParm csDevModelQueryListParm = new CsDevModelQueryListParm();
|
||||
if (Objects.isNull(dicData)) {
|
||||
log.info("新增模板失败,获取装置类型字典数据为空,请先录入装置类型!");
|
||||
return;
|
||||
} else {
|
||||
csDevModelQueryListParm.setDevType( dicData.getId());
|
||||
}
|
||||
csDevModelQueryListParm.setVersionNo(item.getVersionNo());
|
||||
csDevModelQueryListParm.setVersionDate(item.getVersionDate());
|
||||
CsDevModelPageVO csDevModelPageVO = devModelFeignClient.queryDevModelOne(csDevModelQueryListParm).getData();
|
||||
if (Objects.isNull(csDevModelPageVO)){
|
||||
log.info("模板不存在,请先录入模板数据!");
|
||||
return;
|
||||
} else {
|
||||
//todo 录入装置和模板的关系表
|
||||
System.out.println("录入装置和模板的关系表");
|
||||
}
|
||||
});
|
||||
} else if (Objects.equals(devType,"网关")){
|
||||
//todo 处理待定
|
||||
System.out.println("网关设备判断");
|
||||
}
|
||||
} else {
|
||||
log.info("通过nDid未找到相关装置信息");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user