excl批量导入标准

This commit is contained in:
zhaokaiyao@91isoft.com
2021-09-09 23:06:19 +08:00
parent 77c274b724
commit ea9e2b31cc
@@ -2,24 +2,14 @@ package com.adc.da.slrs.ImportExcelDatas.service.impl;
import com.adc.da.att.service.IAttFileEOService;
import com.adc.da.att.vo.AttFileVo;
import com.adc.da.mq.CreateStandMQService;
import com.adc.da.slrs.ImportExcelDatas.dao.ImportExcelDao;
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
import com.adc.da.slrs.sarBussStandAttrInfo.dao.SarBussStandAttrInfoDao;
import com.adc.da.slrs.sarBussStandAttrInfo.entity.SarBussStandAttrInfo;
import com.adc.da.slrs.sarBussStandAttrInfo.service.impl.SarBussStandAttrInfoServiceImpl;
import com.adc.da.slrs.sarBussionessStand.dao.SarBussionessStandDao;
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
import com.adc.da.slrs.sarBussionessStand.service.impl.SarBussionessStandServiceImpl;
import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao;
import com.adc.da.slrs.sarStandAttrInfo.entity.SarStandAttrInfo;
import com.adc.da.slrs.sarStandAttrInfo.service.impl.SarStandAttrInfoServiceImpl;
import com.adc.da.slrs.sarStandardsInfo.dao.SarStandardsInfoDao;
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
import com.adc.da.slrs.sarStandardsInfo.service.impl.SarStandardsInfoServiceImpl;
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
import com.adc.da.util.UUIDUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
@@ -46,32 +36,17 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
@Autowired
private IAttFileEOService attFileEOService;
@Autowired
private CreateStandMQService createStandMQService;
// @Autowired
// private CreateStandMQService createStandMQService;
//
// @Autowired
// private SarStandardsInfoServiceImpl sarStandardsInfoService;
//
//
//
// @Autowired
// private SarBussionessStandServiceImpl sarBussionessStandService;
@Autowired
private SarStandardsInfoServiceImpl sarStandardsInfoService;
@Autowired
private SarStandardsInfoDao sarStandardInfoDao;
@Autowired
private SarStandAttrInfoDao sarStandAttrInfoDao;
@Autowired
private SarBussionessStandDao sarBussionessStandDao;
@Autowired
private SarBussStandAttrInfoDao sarBussStandAttrInfoDao;
@Autowired
private SarBussionessStandServiceImpl sarBussionessStandService;
@Autowired
private SarBussStandAttrInfoServiceImpl sarBussStandAttrInfoService;
@Autowired
private SarStandAttrInfoServiceImpl sarStandAttrInfoService;
private final static String GN = "GB,GB/T,QC/T,GJB,JB,JT,HG,YV,SY,SH,GA,HJ,QB,JG,NB,JC,YS/T,FZ/T,TB/T,JJG,SJ/T,T/TBPS" +
@@ -290,6 +265,10 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
private List<ImportDto> fileError = new ArrayList<>();
@Autowired
private ISarStandardsInfoService sarStandardsInfoService;
private ISarBussionessStandService sarBussionessStandService;
@Override
public List<ImportDto> storageExclData(Map<String, List<ImportDto>> importListMap) {
@@ -302,53 +281,50 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
String standID = UUIDUtils.randomUUID20();
SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID);
SarStandardsInfo ForeignEO = parseImportDtoToStandardsInfo(item, standID);
//
//
if (sarStandardsInfo != null) {
SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID);
if (ForeignEO != null) {
sarStandardsInfo.setValidFlag("0");
sarStandardsInfo.setStandType("FOREIGN");
ForeignEO.setValidFlag("0");
ForeignEO.setStandType("FOREIGN");
QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>();
standSaveWrapper
.eq("STAND_SORT", sarStandardsInfo.getStandSort())
.eq("STAND_NUMBER", sarStandardsInfo.getStandNumber())
.eq("STAND_YEAR", sarStandardsInfo.getStandYear());
.eq("STAND_SORT", ForeignEO.getStandSort())
.eq("STAND_NUMBER", ForeignEO.getStandNumber())
.eq("STAND_YEAR", ForeignEO.getStandYear());
SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper);
if (one != null) {
sarStandardsInfo.setId(one.getId());
sarStandardsInfoService.update(sarStandardsInfo, standSaveWrapper);
QueryWrapper<SarStandAttrInfo> standAttrWrapper = new QueryWrapper<>();
standAttrWrapper.eq("STAND_ID", one.getId());
sarStandAttrInfo.setStandId(one.getId());
sarStandAttrInfoService.update(sarStandAttrInfo, standAttrWrapper);
} else {
sarStandardsInfoService.save(sarStandardsInfo);
String field = "ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ";
String value = "\'" + sarStandAttrInfo.getId() + "\'" + "," + "\'" + sarStandAttrInfo.getStandId() + "\'" + "," + "\'" + "0" + "\'";
if (sarStandAttrInfo.getDtbjh() != null) {
value += "," + "\'" + sarStandAttrInfo.getDtbjh() + "\'";
if (one != null) {
ForeignEO.setId(one.getId());
try {
sarStandardsInfoService.updateSarStandardsInfo(ForeignEO);
} catch (Exception e) {
item.setErrorStr("标准更新失败");
error.add(item);
e.printStackTrace();
}
} else {
try {
sarStandardsInfoService.createSarStandardsInfo(ForeignEO);
} catch (Exception e) {
item.setErrorStr("标准新增失败");
error.add(item);
e.printStackTrace();
}
}
if (sarStandAttrInfo.getSsrq() != null) {
value += "," + "\'" + sarStandAttrInfo.getSsrq() + "\'";
}
sarStandAttrInfoDao.insertStandAttr(field, value);
}
} else {
item.setErrorStr("标准号无法解析");
error.add(item);
importListMap.replace("error", error);
}
@@ -361,50 +337,46 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
importListMap.get("GNBZ").forEach(item -> {
String standID = UUIDUtils.randomUUID20();
SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID);
SarStandardsInfo InlandEO = parseImportDtoToStandardsInfo(item, standID);
if (sarStandardsInfo != null) {
SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID);
if (InlandEO != null) {
sarStandardsInfo.setValidFlag("0");
sarStandardsInfo.setStandType("INLAND");
InlandEO.setValidFlag("0");
InlandEO.setStandType("INLAND");
QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>();
standSaveWrapper
.eq("STAND_SORT", sarStandardsInfo.getStandSort())
.eq("STAND_NUMBER", sarStandardsInfo.getStandNumber())
.eq("STAND_YEAR", sarStandardsInfo.getStandYear());
.eq("STAND_SORT", InlandEO.getStandSort())
.eq("STAND_NUMBER", InlandEO.getStandNumber())
.eq("STAND_YEAR", InlandEO.getStandYear());
SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper);
if (one != null) {
sarStandardsInfo.setId(one.getId());
sarStandardsInfoService.update(sarStandardsInfo, standSaveWrapper);
QueryWrapper<SarStandAttrInfo> standAttrWrapper = new QueryWrapper<>();
standAttrWrapper.eq("STAND_ID", one.getId());
sarStandAttrInfo.setStandId(one.getId());
sarStandAttrInfoService.update(sarStandAttrInfo, standAttrWrapper);
InlandEO.setId(one.getId());
try {
sarStandardsInfoService.updateSarStandardsInfo(InlandEO);
} catch (Exception e) {
item.setErrorStr("国内标准更新失败");
error.add(item);
e.printStackTrace();
}
} else {
sarStandardsInfoService.save(sarStandardsInfo);
String field = "ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ";
String value = "\'" + sarStandAttrInfo.getId() + "\'" + "," + "\'" + sarStandAttrInfo.getStandId() + "\'" + "," + "\'" + "0" + "\'";
if (sarStandAttrInfo.getDtbjh() != null) {
value += "," + "\'" + sarStandAttrInfo.getDtbjh() + "\'";
try {
sarStandardsInfoService.createSarStandardsInfo(InlandEO);
} catch (Exception e) {
item.setErrorStr("国内标准新增失败");
error.add(item);
e.printStackTrace();
}
if (sarStandAttrInfo.getSsrq() != null) {
value += "," + "\'" + sarStandAttrInfo.getSsrq() + "\'";
}
sarStandAttrInfoDao.insertStandAttr(field, value);
}
} else {
item.setErrorStr("标准号无法解析");
@@ -422,32 +394,19 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
importListMap.get("QYBZ").forEach(item -> {
String standId = UUIDUtils.randomUUID20();
SarBussionessStand sarBussionessStand = parseImportDtoToSarBussionessStand(item, standId);
if (sarBussionessStand != null) {
SarBussStandAttrInfo sarBussStandAttrInfo = parseImportDtoToSarBussStandAttrInfo(item, standId);
SarBussionessStand BussEO = parseImportDtoToSarBussionessStand(item, standId);
if (BussEO != null) {
try {
QueryWrapper<SarBussionessStand> saveWrapper = new QueryWrapper<>();
saveWrapper.eq("STAND_CODE", item.getStandId());
SarBussionessStand one = sarBussionessStandService.getOne(saveWrapper);
if (one != null) {
sarBussionessStand.setId(one.getId());
sarBussionessStandService.update(sarBussionessStand, saveWrapper);
QueryWrapper<SarBussStandAttrInfo> bussAttrWrapper = new QueryWrapper<>();
bussAttrWrapper.eq("STAND_ID", one.getId());
sarBussStandAttrInfo.setStandId(one.getId());
sarBussStandAttrInfoService.update(sarBussStandAttrInfo, bussAttrWrapper);
sarBussStandAttrInfoDao.updateStandInfo(one.getId(), "GLWJBUSS", sarBussStandAttrInfo.getGlwj());
BussEO.setId(one.getId());
sarBussionessStandService.updateSarBussionessStand(BussEO);
} else {
sarBussionessStandService.save(sarBussionessStand);
sarBussStandAttrInfoService.save(sarBussStandAttrInfo);
sarBussStandAttrInfoDao.updateStandInfo(sarBussStandAttrInfo.getStandId(), "GLWJBUSS", sarBussStandAttrInfo.getGlwj());
sarBussionessStandService.createSarBussionessStand(BussEO);
}
@@ -464,15 +423,17 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
});
//
// String head="standId,standName,standNameEN,publishTime,implementedTime" +
// ",standStatus,replaceId,path";
// String headStr="标准号,标准名称,英文名称,发布时间,实施时间,标准状态,代替标准号,附件路径";
error.addAll(fileError);
return error;
}
/**
* 整理为标准信息实体
* @param importDto
* @param standId
* @return
*/
public SarStandardsInfo parseImportDtoToStandardsInfo(ImportDto importDto, String standId) {
@@ -549,9 +510,8 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
}
// attrInfoMap.put("")
Gson gson = new Gson();
String attrInfoJson = gson.toJson(attrInfoMap);
sarStandardsInfoEO.setSarStandAttrEOStr(attrInfoJson);
sarStandardsInfoEO.setSarStandAttrEOStr(attrInfoJson);//新增修改时属性表信息
return sarStandardsInfoEO;
@@ -559,74 +519,12 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
}
public SarStandAttrInfo parseImportDtoToStandAttrInfo(ImportDto importDto, String standId) {
SarStandAttrInfo sarStandAttrInfo = new SarStandAttrInfo();
sarStandAttrInfo.setId(UUIDUtils.randomUUID20());
sarStandAttrInfo.setStandId(standId);
sarStandAttrInfo.setDtbjh(importDto.getReplaceId());
String ssrqDate = importDto.getImplementedTime().substring(0, 9);
sarStandAttrInfo.setSsrq(ssrqDate);
sarStandAttrInfo.setValidFlag("0");
// Arrays.stream(path).limit(2,path.length);
if (importDto.getPath() != null) {
String path[] = importDto.getPath().split("/");
String realPath = "";
for (int i = 4; i < path.length; i++) {
realPath = realPath + "/" + path[i];
}
try {
// File file = new File("C:\\Users\\22501\\Desktop\\foton\\2021\\" + realPath);
// File file = new File(importPath + realPath);
File file = new File("/home/file/2021/" + realPath);
if (file.exists()) {
AttFileVo fileInfo = attFileEOService.saveFileInfo(file);
HashMap<String, String> fileMap = new HashMap<>();
/**
* * @Param: [standId, fileMap] fileMap<field,fileIds>
*/
fileMap.put("GLWJ", fileInfo.getAttId());
try {
sarStandardsInfoService.createStandFile(standId, fileMap);
} catch (Exception e) {
importDto.setErrorStr("创建标准文件异常");
fileError.add(importDto);
e.printStackTrace();
System.out.println("创建标准文件异常");
}
sarStandAttrInfo.setGlwj(fileInfo.getAttId());
} else {
importDto.setErrorStr("文件不存在");
fileError.add(importDto);
}
} catch (Exception e) {
importDto.setErrorStr("文件打开失败");
fileError.add(importDto);
e.printStackTrace();
}
}
return sarStandAttrInfo;
}
/**
* 整理为企业标准实体
* @param importDto
* @param standId
* @return
*/
public SarBussionessStand parseImportDtoToSarBussionessStand(ImportDto importDto, String standId) {
@@ -648,6 +546,54 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
if ("有效".equals(importDto.getStandStatus())) {
sarBussionessStand.setTextStatusBuss("vsaga7nwub");
}
/**
* 企业标准属性字段
*/
HashMap<String, String> attrInfoMap = new HashMap<>();
if (importDto.getPath() != null) {
String path[] = importDto.getPath().split("/");
String realPath = "";
for (int i = 4; i < path.length; i++) {
realPath = realPath + "/" + path[i];
}
try {
// File file = new File("C:\\Users\\22501\\Desktop\\foton\\2021\\" + realPath);
// File file = new File(importPath + realPath);
File file = new File("/home/file/2021/" + realPath);
if (file.exists()) {
AttFileVo fileInfo = attFileEOService.saveFileInfo(file);
if (importDto.getImplementedTime()!=null && importDto.getImplementedTime()!=""){
attrInfoMap.put("FBGBUSS",fileInfo.getAttId());
}else {
attrInfoMap.put("GLWJBUSS",fileInfo.getAttId());
}
} else {
importDto.setErrorStr("文件不存在");
fileError.add(importDto);
}
} catch (Exception e) {
importDto.setErrorStr("路径错误!");
fileError.add(importDto);
e.printStackTrace();
}
}
return sarBussionessStand;
}
@@ -655,63 +601,6 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
}
public SarBussStandAttrInfo parseImportDtoToSarBussStandAttrInfo(ImportDto importDto, String standId) {
SarBussStandAttrInfo sarBussStandAttrInfo = new SarBussStandAttrInfo();
sarBussStandAttrInfo.setId(UUIDUtils.randomUUID20());
sarBussStandAttrInfo.setStandId(standId);
sarBussStandAttrInfo.setValidFlag("0");
if (importDto.getPath() != null) {
String path[] = importDto.getPath().split("/");
String realPath = "";
for (int i = 4; i < path.length; i++) {
realPath = realPath + "/" + path[i];
}
try {
// File file = new File("C:\\Users\\22501\\Desktop\\foton\\2021\\" + realPath);
// File file = new File(importPath + realPath);
File file = new File("/home/file/2021/" + realPath);
if (file.exists()) {
AttFileVo fileInfo = attFileEOService.saveFileInfo(file);
HashMap<String, String> fileMap = new HashMap<>();
/**
* * @Param: [standId, fileMap] fileMap<field,fileIds>
*/
fileMap.put("GLWJBUSS", fileInfo.getAttId());
try {
sarBussionessStandService.createStandFile(standId, fileMap);
} catch (Exception e) {
importDto.setErrorStr("创建标准文件异常");
fileError.add(importDto);
e.printStackTrace();
System.out.println("创建标准文件异常");
}
sarBussStandAttrInfo.setGlwj(fileInfo.getAttId());
} else {
importDto.setErrorStr("文件不存在");
fileError.add(importDto);
}
} catch (Exception e) {
importDto.setErrorStr("路径错误!");
fileError.add(importDto);
e.printStackTrace();
}
}
return sarBussStandAttrInfo;
}
public HashMap<String, String> analysisStandId(ImportDto importDto) {
HashMap<String, String> result = new HashMap<>();