解析模板

This commit is contained in:
2023-07-31 14:36:15 +08:00
parent acf4ebb33d
commit 344172c61d
6 changed files with 200 additions and 11 deletions

View File

@@ -17,7 +17,7 @@ public enum AccessResponseEnum {
NDID_NO_FIND("A0301", "nDid在平台端未找到或者已注册"), NDID_NO_FIND("A0301", "nDid在平台端未找到或者已注册"),
MISSING_CLIENT("A0302","设备客户端不在线!"), MISSING_CLIENT("A0302","设备客户端不在线!"),
MODEL_REPEAT("A0302", "模板重复,请勿重复录入!"), MODEL_REPEAT("A0302", "模板存在,请勿重复录入!"),
MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"), MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"),
MESSAGE_TYPE_ERROR("A0303","报文消息类型Type错误!"), MESSAGE_TYPE_ERROR("A0303","报文消息类型Type错误!"),

View File

@@ -0,0 +1,69 @@
package com.njcn.access.enums;
/**
* @author xuyang
*/
public interface DataModel {
/**
* 数据模型
*/
String APF = "Apf";
String DVR = "Dvr";
String EPD = "Epd";
String PQD = "Pqd";
String BMD = "Bmd";
String EVT = "Evt";
String ALM = "Alm";
String STS = "Sts";
String DI = "Di";
String DO = "Do";
String PARM = "Parm";
String SET = "Set";
String INSET = "InSet";
String CTRL = "Ctrl";
/**
* 数据模型临时表
*/
String APF_DATA = "apf_data";
String DVR_DATA = "dvr_data";
String EPD_DATA = "epd_data";
String PQD_DATA = "pqd_data";
String BMD_DATA = "bmd_data";
String EVT_DATA = "evt_data";
String ALM_DATA = "alm_data";
String STS_DATA = "sts_data";
String DI_DATA = "di_data";
String DO_DATA = "do_data";
String PARM_DATA = "parm_data";
String SET_DATA = "set_data";
String INSET_DATA = "inset_data";
String CTRL_DATA = "ctrl_data";
}

View File

@@ -33,6 +33,10 @@ public class EvtDto implements Serializable {
@NotNull(message = "事件类别,不为空") @NotNull(message = "事件类别,不为空")
private String eventType; private String eventType;
@SerializedName("Phase")
@NotNull(message = "相别,不为空")
private String phase;
@SerializedName("Parm") @SerializedName("Parm")
private List<EvtParamDto> param; private List<EvtParamDto> param;
} }

View File

@@ -35,11 +35,11 @@ public class SetDto implements Serializable {
@SerializedName("MaxNum") @SerializedName("MaxNum")
@ApiModelProperty("设置最大值") @ApiModelProperty("设置最大值")
private Integer maxNum; private Double maxNum;
@SerializedName("MinNum") @SerializedName("MinNum")
@ApiModelProperty("设置最小值") @ApiModelProperty("设置最小值")
private Integer minNum; private Double minNum;
@SerializedName("DefaultValue") @SerializedName("DefaultValue")
@NotNull(message = "参数缺省值") @NotNull(message = "参数缺省值")

View File

@@ -38,6 +38,10 @@ public class ApfDto implements Serializable {
@ApiModelProperty("单位") @ApiModelProperty("单位")
private String unit; private String unit;
@SerializedName("Phase")
@ApiModelProperty("相别")
private String phase;
@SerializedName("StatMethod") @SerializedName("StatMethod")
@ApiModelProperty("数据统计方法(max,min,avg,cp95)") @ApiModelProperty("数据统计方法(max,min,avg,cp95)")
private List<String> statMethod; private List<String> statMethod;

View File

@@ -1,23 +1,48 @@
package com.njcn.access.service.impl; package com.njcn.access.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.enums.DataModel;
import com.njcn.access.enums.TypeEnum;
import com.njcn.access.pojo.dto.data.EpdPqdDto;
import com.njcn.access.pojo.dto.data.EvtDto;
import com.njcn.access.pojo.dto.data.EvtParamDto;
import com.njcn.access.pojo.dto.devModel.ApfDto;
import com.njcn.access.pojo.dto.devModel.TemplateDto; import com.njcn.access.pojo.dto.devModel.TemplateDto;
import com.njcn.access.service.ICsDevModelService; import com.njcn.access.service.ICsDevModelService;
import com.njcn.access.utils.JsonUtil; import com.njcn.access.utils.JsonUtil;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.LogUtil;
import com.njcn.csdevice.api.DevModelFeignClient; import com.njcn.csdevice.api.DevModelFeignClient;
import com.njcn.csdevice.pojo.param.CsDevModelAddParm; import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
import com.njcn.csdevice.pojo.po.CsDevModelPO; import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.oss.utils.FileStorageUtil; import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.DictTreeFeignClient; import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.pojo.param.EleEpdPqdParam;
import com.njcn.system.pojo.po.Dic;
import com.njcn.system.pojo.po.EleEpdPqd;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.sql.Date; import java.sql.Date;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/** /**
* 类的介绍: * 类的介绍:
@@ -26,18 +51,24 @@ import java.time.format.DateTimeFormatter;
* @version 1.0.0 * @version 1.0.0
* @createTime 2023/7/3 15:40 * @createTime 2023/7/3 15:40
*/ */
@Slf4j
@Service @Service
@AllArgsConstructor @AllArgsConstructor
public class CsDevModelServiceImpl implements ICsDevModelService { public class CsDevModelServiceImpl implements ICsDevModelService {
@Autowired
public CsDevModelServiceImpl csDevModelService;
private final FileStorageUtil fileStorageUtil; private final FileStorageUtil fileStorageUtil;
private final DevModelFeignClient devModelFeignClient; private final DevModelFeignClient devModelFeignClient;
private final DictTreeFeignClient dictTreeFeignClient; private final EpdFeignClient epdFeignClient;
private final DicDataFeignClient dicDataFeignClient;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = {Exception.class})
public void addModel(MultipartFile file) { public void addModel(MultipartFile file) {
String json = null; String json = null;
try { try {
@@ -48,9 +79,9 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
//String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_"); //String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_");
String filePath = ""; String filePath = "";
//1.录入cs_dev_model表记录装置型号和模板记录 //1.录入cs_dev_model表记录装置型号和模板记录
addCsDevModel(templateDto,filePath); CsDevModelPO csDevModelPo = csDevModelService.addCsDevModel(templateDto,filePath);
//2.录入字典数据
csDevModelService.analysisDict(templateDto);
} catch (IOException e) { } catch (IOException e) {
@@ -61,15 +92,96 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
/** /**
* 新增cs_dev_model数据 * 新增cs_dev_model数据
*/ */
private CsDevModelPO addCsDevModel(TemplateDto templateDto, String filePath){ public CsDevModelPO addCsDevModel(TemplateDto templateDto, String filePath){
CsDevModelPO po = devModelFeignClient.findModel(templateDto.getDevType(),templateDto.getVersion(),templateDto.getTime()).getData();
if (!Objects.isNull(po)){
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
}
CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm(); CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
csDevModelAddParm.setDevTypeName(templateDto.getDevType()); csDevModelAddParm.setDevTypeName(templateDto.getDevType());
csDevModelAddParm.setName(templateDto.getDevType()); csDevModelAddParm.setName(templateDto.getDevType());
csDevModelAddParm.setVersionNo(templateDto.getVersion()); csDevModelAddParm.setVersionNo(templateDto.getVersion());
csDevModelAddParm.setTime(templateDto.getTime()); csDevModelAddParm.setTime(templateDto.getTime());
csDevModelAddParm.setFilePath(filePath); csDevModelAddParm.setFilePath(filePath);
CsDevModelPO csDevModel = devModelFeignClient.addDevModel(csDevModelAddParm).getData(); return devModelFeignClient.addDevModel(csDevModelAddParm).getData();
return csDevModel;
} }
/**
* 解析字典数据
* 根据data_type和name来判断字典是否已经录入,录入过的就不在录入
*/
public void analysisDict(TemplateDto templateDto){
List<EleEpdPqdParam> result = new ArrayList<>();
List<String> dataList = templateDto.getDataList();
if (CollectionUtil.isNotEmpty(dataList)){
dataList.forEach(item->{
switch (item) {
case DataModel.APF:
log.info("处理apf字典数据");
List<ApfDto> apfList = templateDto.getApfDto();
apfList.forEach(apf->{
String id = dicDataFeignClient.getDicDataByCode(item).getData().getId();
String classId = dicDataFeignClient.getDicDataByCode(DataModel.APF_DATA).getData().getId();
List<EleEpdPqd> list = epdFeignClient.judgeExist(apf.getName(),id).getData();
if (CollectionUtil.isEmpty(list)){
EleEpdPqdParam eleEpdPqdParam = new EleEpdPqdParam();
eleEpdPqdParam.setName(apf.getName());
eleEpdPqdParam.setOtherName(apf.getName());
eleEpdPqdParam.setShowName(apf.getName());
eleEpdPqdParam.setSort(apf.getIdx());
eleEpdPqdParam.setType(apf.getType());
eleEpdPqdParam.setUnit(apf.getUnit());
eleEpdPqdParam.setStatMethod(apf.getStatMethod());
eleEpdPqdParam.setDataType(id);
if (Objects.isNull(apf.getPhase())){
eleEpdPqdParam.setPhase("M");
} else {
eleEpdPqdParam.setPhase(apf.getPhase());
}
eleEpdPqdParam.setClassId(classId);
result.add(eleEpdPqdParam);
}
});
break;
case DataModel.EVT:
log.info("处理evt字典数据");
List<EvtDto> evtList = templateDto.getEvtDto();
evtList.forEach(evt->{
String id = dicDataFeignClient.getDicDataByCode(item).getData().getId();
String classId = dicDataFeignClient.getDicDataByCode(DataModel.EVT_DATA).getData().getId();
List<EleEpdPqd> list = epdFeignClient.judgeExist(evt.getName(),id).getData();
if (CollectionUtil.isEmpty(list)){
EleEpdPqdParam eleEpdPqdParam = new EleEpdPqdParam();
eleEpdPqdParam.setName(evt.getName());
eleEpdPqdParam.setOtherName(evt.getName());
eleEpdPqdParam.setShowName(evt.getName());
eleEpdPqdParam.setSort(evt.getIdx());
eleEpdPqdParam.setEventType(evt.getEventType());
eleEpdPqdParam.setDataType(id);
if (Objects.isNull(evt.getPhase())){
eleEpdPqdParam.setPhase("M");
} else {
eleEpdPqdParam.setPhase(evt.getPhase());
}
eleEpdPqdParam.setClassId(classId);
EleEpdPqd po = epdFeignClient.add(eleEpdPqdParam).getData();
if (CollectionUtil.isNotEmpty(evt.getParam())){
evt.getParam().forEach(param->{
});
}
}
});
break;
default:
break;
}
});
}
if (CollectionUtil.isNotEmpty(result)){
epdFeignClient.addByModel(result);
}
}
} }