解析模板
This commit is contained in:
@@ -1,23 +1,48 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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.service.ICsDevModelService;
|
||||
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.pojo.param.CsDevModelAddParm;
|
||||
import com.njcn.csdevice.pojo.po.CsDevModelPO;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
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.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.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDateTime;
|
||||
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
|
||||
* @createTime 2023/7/3 15:40
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
|
||||
@Autowired
|
||||
public CsDevModelServiceImpl csDevModelService;
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
private final DevModelFeignClient devModelFeignClient;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void addModel(MultipartFile file) {
|
||||
String json = null;
|
||||
try {
|
||||
@@ -48,9 +79,9 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
//String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_");
|
||||
String filePath = "";
|
||||
//1.录入cs_dev_model表,记录装置型号和模板记录
|
||||
addCsDevModel(templateDto,filePath);
|
||||
|
||||
|
||||
CsDevModelPO csDevModelPo = csDevModelService.addCsDevModel(templateDto,filePath);
|
||||
//2.录入字典数据
|
||||
csDevModelService.analysisDict(templateDto);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
@@ -61,15 +92,96 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
/**
|
||||
* 新增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.setDevTypeName(templateDto.getDevType());
|
||||
csDevModelAddParm.setName(templateDto.getDevType());
|
||||
csDevModelAddParm.setVersionNo(templateDto.getVersion());
|
||||
csDevModelAddParm.setTime(templateDto.getTime());
|
||||
csDevModelAddParm.setFilePath(filePath);
|
||||
CsDevModelPO csDevModel = devModelFeignClient.addDevModel(csDevModelAddParm).getData();
|
||||
return csDevModel;
|
||||
return devModelFeignClient.addDevModel(csDevModelAddParm).getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字典数据
|
||||
* 根据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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user