新增物接入流程
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
/**
|
||||
* @author 徐扬
|
||||
*/
|
||||
public interface IAccessService {
|
||||
|
||||
/**
|
||||
* 设备注册(1.判断此装置是否完成出厂设置 2.判断此装置是否能正常通讯)
|
||||
* 1.根据nDid获取装置的信息(设备型号、网关识别码)
|
||||
* 2.发送MQTT信息给装置
|
||||
* 3.装置响应则修改装置状态;3分钟未响应则生成告警信息
|
||||
* @param nDid 网关识别码
|
||||
*/
|
||||
void add(String nDid);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.njcn.access.pojo.param.DevModelParam;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface IDevModelService {
|
||||
|
||||
/**
|
||||
* 直连装置录入模板信息
|
||||
* 1.解析模板文件,将数据录入库中
|
||||
* 2.将文件上传至文件服务器保存起来,先以装置型号-版本号-时间作为名称名称
|
||||
* @param devModelParam 模板文件参数
|
||||
*/
|
||||
HttpResult<String> add(DevModelParam devModelParam);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.njcn.access.service.serviceImpl;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.pojo.dto.AccessDto;
|
||||
import com.njcn.access.pojo.dto.PublicDto;
|
||||
import com.njcn.access.service.IAccessService;
|
||||
import com.njcn.algorithm.api.EquipmentFeignClient;
|
||||
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/3/31 9:21
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class AccessServiceImpl implements IAccessService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccessServiceImpl.class);
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
@Override
|
||||
public void add(String nDid) {
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
if (Objects.isNull(vo)){
|
||||
logger.error("平台侧无此网关信息,请先录入!");
|
||||
return;
|
||||
}
|
||||
PublicDto publicDto = new PublicDto();
|
||||
publicDto.setMid(Long.toString(Instant.now().toEpochMilli()));
|
||||
publicDto.setNDid(nDid);
|
||||
publicDto.setTimestamp(Instant.now().toEpochMilli());
|
||||
publicDto.setType("CMD_DEV_REGISTER");
|
||||
AccessDto accessDto = new AccessDto();
|
||||
accessDto.setNDid(nDid);
|
||||
accessDto.setDevType(vo.getDevModel());
|
||||
publicDto.setParam(accessDto);
|
||||
publisher.send("/platform/register/"+nDid,new Gson().toJson(publicDto),1,false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.njcn.access.service.serviceImpl;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.pojo.dto.devModel.*;
|
||||
import com.njcn.access.pojo.param.DevModelParam;
|
||||
import com.njcn.access.service.IDevModelService;
|
||||
import com.njcn.access.utils.JsonUtil;
|
||||
import com.njcn.algorithm.api.DevModelFeignClient;
|
||||
import com.njcn.algorithm.pojo.param.CsDevModelAddParm;
|
||||
import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm;
|
||||
import com.njcn.algorithm.pojo.vo.CsDevModelPageVO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/4/10 10:37
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DevModelServiceImpl implements IDevModelService {
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
private final DevModelFeignClient devModelFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HttpResult<String> add(DevModelParam devModelParam) {
|
||||
String json = null;
|
||||
try {
|
||||
json = JsonUtil.convertStreamToString(devModelParam.getFile().getInputStream());
|
||||
|
||||
Gson gson = new Gson();
|
||||
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
|
||||
ParamDto pojo = templateDto.getParam();
|
||||
//网关模板
|
||||
NetDevModDto po1 = pojo.getDataArray().get(0).getTemplate().getNetDevModDto();
|
||||
//装置信息模板
|
||||
DevCfgDetailDto po2 = pojo.getDataArray().get(0).getTemplate().getDevCfgDetailDto();
|
||||
//装置数据模板
|
||||
List<DevModDetailDto> po3 = pojo.getDataArray().get(0).getTemplate().getDevModDetailDto();
|
||||
|
||||
String name = po3.get(0).getName();
|
||||
String version = po3.get(0).getVersion();
|
||||
String time = po3.get(0).getTime();
|
||||
String devType = po3.get(0).getDevType();
|
||||
String devTypeId = "";
|
||||
|
||||
DictData dicData = dicDataFeignClient.getDicDataByCode(devType).getData();
|
||||
if (Objects.isNull(dicData)) {
|
||||
log.info("新增模板失败,获取装置类型字典数据为空,请先录入装置类型!");
|
||||
return HttpResultUtil.assembleResult(CommonResponseEnum.NO_DATA.getCode(), null, "获取装置类型字典数据为空!");
|
||||
} else {
|
||||
devTypeId = dicData.getId();
|
||||
}
|
||||
CsDevModelQueryListParm csDevModelQueryListParm = new CsDevModelQueryListParm();
|
||||
csDevModelQueryListParm.setDevType(devTypeId);
|
||||
csDevModelQueryListParm.setVersionNo(version);
|
||||
csDevModelQueryListParm.setVersionDate(time);
|
||||
csDevModelQueryListParm.setName(name);
|
||||
CsDevModelPageVO vo = devModelFeignClient.queryDevModelOne(csDevModelQueryListParm).getData();
|
||||
if (!Objects.isNull(vo)){
|
||||
log.info("新增模板失败,新增的模板在库中存在!");
|
||||
return HttpResultUtil.assembleResult(AccessResponseEnum.MODEL_REPEAT.getCode(), null, AccessResponseEnum.MODEL_REPEAT.getMessage());
|
||||
} else {
|
||||
CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
|
||||
csDevModelAddParm.setName(name);
|
||||
csDevModelAddParm.setDevType(devTypeId);
|
||||
csDevModelAddParm.setVersionNo(version);
|
||||
csDevModelAddParm.setVersionDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time));
|
||||
String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_");
|
||||
log.info("文件路径为:" + filePath);
|
||||
csDevModelAddParm.setFilePath(filePath);
|
||||
//新增cs_dev_model表数据
|
||||
devModelFeignClient.addDevModel(csDevModelAddParm);
|
||||
//新增cs_data_set
|
||||
|
||||
//新增cs_data_array
|
||||
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("文件转成json出现异常");
|
||||
e.getMessage();
|
||||
} catch (ParseException e) {
|
||||
log.error("时间转换出现异常");
|
||||
e.getMessage();
|
||||
}
|
||||
return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), null, CommonResponseEnum.SUCCESS.getMessage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user