模板解析功能提交

This commit is contained in:
2023-05-18 16:30:13 +08:00
parent 5c49f0b198
commit a16f49c888
47 changed files with 923 additions and 181 deletions

View File

@@ -12,5 +12,5 @@ public interface IAccessService {
* 3.装置响应则修改装置状态3分钟未响应则生成告警信息
* @param nDid 网关识别码
*/
Boolean add(String nDid);
void add(String nDid);
}

View File

@@ -1,8 +1,11 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.access.pojo.po.CsEpdPqdPO;
import java.util.List;
/**
* <p>
* 服务类
@@ -11,6 +14,7 @@ import com.njcn.access.pojo.po.CsEpdPqdPO;
* @author xuyang
* @since 2023-05-11
*/
public interface ICsEpdPqdService extends IService<CsEpdPqdPO> {
public interface ICsEpdPqdService {
void saveData(List<CsEpdPqdPO> list);
}

View File

@@ -0,0 +1,17 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsNetDevPO;
/**
* <p>
* 联网设备表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface ICsNetDevService {
boolean saveData(CsNetDevPO csNetDevPo);
}

View File

@@ -0,0 +1,18 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsPrjInfoPO;
import com.njcn.access.pojo.po.CsSoftInfoPO;
/**
* <p>
* 工程信息表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface ICsPrjInfoService {
CsPrjInfoPO saveData(CsPrjInfoPO csPrjInfoPO);
}

View File

@@ -0,0 +1,17 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsSoftInfoPO;
/**
* <p>
* 系统软件表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface ICsSoftInfoService {
CsSoftInfoPO saveData(CsSoftInfoPO csSoftInfoPo);
}

View File

@@ -14,5 +14,5 @@ public interface IDevModelService {
* 2.将文件上传至文件服务器保存起来,先以装置型号-版本号-时间作为名称名称
* @param devModelParam 模板文件参数
*/
HttpResult<String> add(DevModelParam devModelParam);
void add(DevModelParam devModelParam);
}

View File

@@ -1,18 +1,26 @@
package com.njcn.access.service.serviceImpl;
import com.alibaba.csp.sentinel.util.TimeUtil;
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.handler.MqttMessageHandler;
import com.njcn.access.pojo.dto.AccessDto;
import com.njcn.access.pojo.param.ReqAndResParam;
import com.njcn.access.service.IAccessService;
import com.njcn.algorithm.api.CsEdDataFeignClient;
import com.njcn.algorithm.api.EquipmentFeignClient;
import com.njcn.algorithm.pojo.po.CsEdDataPO;
import com.njcn.algorithm.pojo.vo.CsEdDataVO;
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.PubUtils;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,18 +47,49 @@ public class AccessServiceImpl implements IAccessService {
private final CsEdDataFeignClient csEdDataFeignClient;
private final DicDataFeignClient dicDataFeignClient;
private final RedisUtil redisUtil;
@Override
public Boolean add(String nDid) {
public void add(String nDid) {
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
System.out.println("vo==:" + vo);
if (Objects.isNull(vo.getNdid())){
logger.error("平台侧无此网关信息,请先录入!");
return false;
throw new BusinessException(AccessResponseEnum.NDID_NO_FIND);
} else {
HttpResult<CsEdDataVO> result = csEdDataFeignClient.findByDevTypeId(vo.getDevModel());
System.out.println("result==:" + result);
String typeId = result.getData().getType();
if(Objects.isNull(typeId)) {
logger.error("平台侧无此装置类型,请先录入!");
throw new BusinessException(AccessResponseEnum.DEV_TYPE_NOT_FIND);
} else {
String type = dicDataFeignClient.getDicDataById(typeId).getData().getCode();
if (Objects.equals(DicDataEnum.GATEWAY_DEV.getCode(),type)) {
//处理网关设备
System.out.println("网关");
} else if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),type)) {
//处理直连设备
zhiLianRegister(nDid,vo.getDevModel());
} else {
logger.error("请求注册的装置类型错误(不是网关或者直连设备),请核查!");
throw new BusinessException(AccessResponseEnum.DEV_TYPE_ERROR);
}
}
}
try {
Thread.sleep(2000);
//这边使用redis缓存来判断装置是否连接MQTT
if(Objects.isNull(redisUtil.getObjectByKey(nDid))) {
logger.error("未收到装置注册响应,请核查!");
throw new BusinessException(AccessResponseEnum.NO_RECEIVE_FROM_DEV);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void zhiLianRegister(String nDid,String devType) {
ReqAndResParam.Req reqAndResParam = new ReqAndResParam.Req();
reqAndResParam.setMid(1);
reqAndResParam.setDid("0");
@@ -59,9 +98,8 @@ public class AccessServiceImpl implements IAccessService {
reqAndResParam.setExpire(-1);
AccessDto accessDto = new AccessDto();
accessDto.setNDid(nDid);
accessDto.setDevType(vo.getDevModel());
accessDto.setDevType(devType);
reqAndResParam.setMsg(accessDto);
publisher.send("/platform/register/"+nDid, PubUtils.obj2json(reqAndResParam),1,false);
return true;
}
}

View File

@@ -1,11 +1,13 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsEpdPqdMapper;
import com.njcn.access.pojo.po.CsEpdPqdPO;
import com.njcn.access.service.ICsEpdPqdService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 服务实现类
@@ -15,6 +17,10 @@ import org.springframework.stereotype.Service;
* @since 2023-05-11
*/
@Service
public class CsEpdPqdServiceImpl extends ServiceImpl<CsEpdPqdMapper, CsEpdPqdPO> implements ICsEpdPqdService {
public class CsEpdPqdServiceImpl extends MppServiceImpl<CsEpdPqdMapper, CsEpdPqdPO> implements ICsEpdPqdService {
@Override
public void saveData(List<CsEpdPqdPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
}

View File

@@ -0,0 +1,39 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.mapper.CsNetDevMapper;
import com.njcn.access.pojo.po.CsNetDevPO;
import com.njcn.access.service.ICsNetDevService;
import com.njcn.common.pojo.exception.BusinessException;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Objects;
/**
* <p>
* 联网设备表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
@Service
public class CsNetDevServiceImpl extends ServiceImpl<CsNetDevMapper, CsNetDevPO> implements ICsNetDevService {
@Override
public boolean saveData(CsNetDevPO csNetDevPo) {
LambdaQueryWrapper<CsNetDevPO> lambdaQueryWrapper = new LambdaQueryWrapper<CsNetDevPO>();
lambdaQueryWrapper.eq(CsNetDevPO::getDevType,csNetDevPo.getDevType())
.eq(CsNetDevPO::getTime,csNetDevPo.getTime())
.eq(CsNetDevPO::getVersion,csNetDevPo.getVersion())
.eq(CsNetDevPO::getStatus,1);
CsNetDevPO po = this.baseMapper.selectOne(lambdaQueryWrapper);
if (!Objects.isNull(po)){
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
}
return this.save(csNetDevPo);
}
}

View File

@@ -0,0 +1,25 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.mapper.CsPrjInfoMapper;
import com.njcn.access.pojo.po.CsPrjInfoPO;
import com.njcn.access.service.ICsPrjInfoService;
import org.springframework.stereotype.Service;
/**
* <p>
* 工程信息表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
@Service
public class CsPrjInfoServiceImpl extends ServiceImpl<CsPrjInfoMapper, CsPrjInfoPO> implements ICsPrjInfoService {
@Override
public CsPrjInfoPO saveData(CsPrjInfoPO csPrjInfoPo) {
this.save(csPrjInfoPo);
return csPrjInfoPo;
}
}

View File

@@ -0,0 +1,25 @@
package com.njcn.access.service.serviceImpl;
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-05-17
*/
@Service
public class CsSoftInfoServiceImpl extends ServiceImpl<CsSoftInfoMapper, CsSoftInfoPO> implements ICsSoftInfoService {
@Override
public CsSoftInfoPO saveData(CsSoftInfoPO entity) {
this.save(entity);
return entity;
}
}

View File

@@ -1,33 +1,37 @@
package com.njcn.access.service.serviceImpl;
import cn.hutool.core.date.DatePattern;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.pojo.dto.data.BmdDto;
import com.njcn.access.pojo.dto.data.EpdPqdDto;
import com.njcn.access.pojo.dto.devModel.*;
import com.njcn.access.pojo.param.DevModelParam;
import com.njcn.access.service.IDevModelService;
import com.njcn.access.pojo.po.*;
import com.njcn.access.service.*;
import com.njcn.access.utils.JsonUtil;
import com.njcn.algorithm.api.CsDictFeignClient;
import com.njcn.algorithm.api.DevModelFeignClient;
import com.njcn.algorithm.pojo.dto.CsDictDTO;
import com.njcn.algorithm.pojo.param.CsDevModelAddParm;
import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm;
import com.njcn.algorithm.pojo.po.CsDevModelPO;
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.common.pojo.exception.BusinessException;
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.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 类的介绍:
@@ -47,71 +51,37 @@ public class DevModelServiceImpl implements IDevModelService {
private final DicDataFeignClient dicDataFeignClient;
private final CsDictFeignClient csDictFeignClient;
private final ICsNetDevService csNetDevService;
private final ICsSoftInfoService csSoftInfoService;
private final ICsPrjInfoService csPrjInfoService;
private final ICsEpdPqdService csEpdPqdService;
@Override
@Transactional(rollbackFor = Exception.class)
public HttpResult<String> add(DevModelParam devModelParam) {
public void add(DevModelParam devModelParam) {
String json = null;
try {
json = JsonUtil.convertStreamToString(devModelParam.getFile().getInputStream());
Gson gson = new Gson();
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
//新增网关信息描述表
// insertNetDevMod(templateDto.getNetDevModDto());
//模板文件存入文件服务器
//String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_");
String filePath = "";
//新增设备数据模板
insertDevMod(templateDto.getDevModDto(),filePath);
// 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表数据
// CsDevModelPO csDevModelPO = devModelFeignClient.addDevModel(csDevModelAddParm).getData();
// //新增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());
}
/**
@@ -126,4 +96,115 @@ public class DevModelServiceImpl implements IDevModelService {
// });
// }
/**
* 新增直连设备、网关模板信息
*/
public void insertNetDevMod(NetDevModDto netDevModDto) {
SoftInfoDto softInfoDto = netDevModDto.getDataList().get(0).getSoftInfoDto();
PrjInfoDto prjInfoDto = netDevModDto.getDataList().get(0).getPrjInfoDto();
CsNetDevPO csNetDevPo = new CsNetDevPO();
BeanUtils.copyProperties(netDevModDto,csNetDevPo);
csNetDevPo.setTime(LocalDate.parse(netDevModDto.getTime(), DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
csNetDevPo.setStatus(1);
if (!Objects.isNull(softInfoDto)){
CsSoftInfoPO csSoftInfoPo = new CsSoftInfoPO();
BeanUtils.copyProperties(softInfoDto,csSoftInfoPo);
csSoftInfoPo.setAppDate(LocalDateTime.parse(softInfoDto.getAppDate(), DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
String softInfoId = csSoftInfoService.saveData(csSoftInfoPo).getId();
csNetDevPo.setSoftInfoId(softInfoId);
}
if (!Objects.isNull(prjInfoDto)){
CsPrjInfoPO csPrjInfoPo = new CsPrjInfoPO();
BeanUtils.copyProperties(prjInfoDto,csPrjInfoPo);
String prjInfoId = csPrjInfoService.saveData(csPrjInfoPo).getId();
csNetDevPo.setPrjInfoId(prjInfoId);
}
csNetDevService.saveData(csNetDevPo);
}
/**
* 新增数据模板(装置类型分类)
*/
public void insertDevMod(DevModDto devModDto,String filePath) {
// String devType = devModDto.getDevType();
// String version = devModDto.getVersion();
// String time = devModDto.getTime();
// CsDevModelPO csDevModelPo = devModelFeignClient.findModel(devType,version,time).getData();
// if (!Objects.isNull(csDevModelPo)){
// throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
// }
// //录入基础模板数据
// CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
// csDevModelAddParm.setDevType(devType);
// csDevModelAddParm.setName(devType);
// csDevModelAddParm.setVersionNo(version);
// csDevModelAddParm.setVersionDate(LocalDateTime.parse(time, DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
// csDevModelAddParm.setFilePath(filePath);
// SoftInfoDto softInfoDto = devModDto.getDataList().get(0).getSoftInfoDto();
// //录入系统软件表
// if (!Objects.isNull(softInfoDto)){
// CsSoftInfoPO csSoftInfoPo = new CsSoftInfoPO();
// BeanUtils.copyProperties(softInfoDto,csSoftInfoPo);
// csSoftInfoPo.setAppDate(LocalDateTime.parse(softInfoDto.getAppDate(), DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
// String softInfoId = csSoftInfoService.saveData(csSoftInfoPo).getId();
// csDevModelAddParm.setSoftInfoId(softInfoId);
// }
// devModelFeignClient.addDevModel(csDevModelAddParm);
//录入字典数据
//录入EPD
List<EpdPqdDto> epdDto = devModDto.getDataList().get(0).getEpdDto();
if (!CollectionUtils.isEmpty(epdDto)){
insertEpdPqd(epdDto);
}
//录入PQD
List<EpdPqdDto> pqdDto = devModDto.getDataList().get(0).getPqdDto();
if (!CollectionUtils.isEmpty(pqdDto)){
insertEpdPqd(pqdDto);
}
//录入Bmd
List<BmdDto> bmdDto = devModDto.getDataList().get(0).getBmdDto();
if (!CollectionUtils.isEmpty(bmdDto)){
insertEpdPqd(pqdDto);
}
}
/**
* EPD、PQD字典录入
*/
public void insertEpdPqd(List<EpdPqdDto> epdPqdDto) {
List<CsEpdPqdPO> list = epdPqdDto.stream().map(item->{
CsEpdPqdPO csEpdPqdPo = new CsEpdPqdPO();
BeanUtils.copyProperties(item,csEpdPqdPo);
CsDictDTO csDictDTO = csDictFeignClient.getOwnAndFatherData(item.getName()).getData();
if (Objects.isNull(item.getPhase())){
csEpdPqdPo.setPhase("M");
}
if (!CollectionUtils.isEmpty(item.getStatMethod())){
csEpdPqdPo.setStatMethod(item.getStatMethod().stream().map(String::valueOf).collect(Collectors.joining(",")));
}
csEpdPqdPo.setAnotherName(csDictDTO.getName());
csEpdPqdPo.setClassId(csDictDTO.getFatherName());
return csEpdPqdPo;
}).collect(Collectors.toList());
csEpdPqdService.saveData(list);
}
/**
* Bmd字典录入
*/
public void insertBmd(List<BmdDto> bmdDto) {
List<CsBmdPO> list = bmdDto.stream().map(item->{
CsBmdPO csBmdPo = new CsBmdPO();
BeanUtils.copyProperties(item,csBmdPo);
CsDictDTO csDictDTO = csDictFeignClient.getOwnAndFatherData(item.getName()).getData();
return csBmdPo;
}).collect(Collectors.toList());
}
}