This commit is contained in:
zhaokaiyao@91isoft.com
2021-09-09 22:29:34 +08:00
parent 6cf59f9a45
commit 77c274b724
@@ -19,8 +19,10 @@ import com.adc.da.slrs.sarStandardsInfo.dao.SarStandardsInfoDao;
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo; import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
import com.adc.da.slrs.sarStandardsInfo.service.impl.SarStandardsInfoServiceImpl; import com.adc.da.slrs.sarStandardsInfo.service.impl.SarStandardsInfoServiceImpl;
import com.adc.da.util.UUIDUtils; import com.adc.da.util.UUIDUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -34,7 +36,6 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -82,12 +83,12 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
@Override @Override
public Map<String, List<ImportDto>> getExcelData(MultipartFile file, MultipartFile file2) { public Map<String, List<ImportDto>> getExcelData(MultipartFile file, MultipartFile file2) {
List<String> dates=new ArrayList<>(); List<String> dates = new ArrayList<>();
for(int i=1669;i<2023;i++){ for (int i = 1669; i < 2023; i++) {
dates.add("-"+i); dates.add("-" + i);
dates.add("—"+i); dates.add("—" + i);
dates.add("- "+i); dates.add("- " + i);
dates.add("— "+i); dates.add("— " + i);
} }
if (file == null || file.getSize() == 0) { if (file == null || file.getSize() == 0) {
@@ -138,10 +139,10 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
datas.forEach(items -> { datas.forEach(items -> {
//判断是否是正确的数据 //判断是否是正确的数据
String[] as = items.split(","); String[] as = items.split(",");
if (!inDate(as[0],dates)) { if (!inDate(as[0], dates)) {
ImportDto importDto = getImportDto(as); ImportDto importDto = getImportDto(as);
error.add(importDto); error.add(importDto);
middle.put(as[0].trim(), "error-"+error.size()); middle.put(as[0].trim(), "error-" + error.size());
} else { } else {
//数据二次拆解 针对标准进行拆解 //数据二次拆解 针对标准进行拆解
String[] step2 = as[0].trim().split(" "); String[] step2 = as[0].trim().split(" ");
@@ -149,15 +150,15 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
if (isCheck(GNS, step2[0].trim())) { if (isCheck(GNS, step2[0].trim())) {
ImportDto importDto = getImportDto(as); ImportDto importDto = getImportDto(as);
InCountry.add(importDto); InCountry.add(importDto);
middle.put(as[0].trim(), "GNBZ-"+InCountry.size()); middle.put(as[0].trim(), "GNBZ-" + InCountry.size());
} else if (isCheck(QBS, step2[0].trim())) { } else if (isCheck(QBS, step2[0].trim())) {
ImportDto importDto = getImportDto(as); ImportDto importDto = getImportDto(as);
QiBiao.add(importDto); QiBiao.add(importDto);
middle.put(as[0].trim(), "QYBZ-"+QiBiao.size()); middle.put(as[0].trim(), "QYBZ-" + QiBiao.size());
} else { } else {
ImportDto importDto = getImportDto(as); ImportDto importDto = getImportDto(as);
OutCountry.add(importDto); OutCountry.add(importDto);
middle.put(as[0].trim(), "HWBZ-"+OutCountry.size()); middle.put(as[0].trim(), "HWBZ-" + OutCountry.size());
} }
} }
}); });
@@ -166,22 +167,22 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
res.put("QYBZ", QiBiao); res.put("QYBZ", QiBiao);
res.put("HWBZ", OutCountry); res.put("HWBZ", OutCountry);
fujian.forEach(items2 ->{ fujian.forEach(items2 -> {
String[] fj=items2.split(","); String[] fj = items2.split(",");
if (fj.length>2) { if (fj.length > 2) {
if (null != middle.get(null != fj[2] ? fj[2].trim() : "")) { if (null != middle.get(null != fj[2] ? fj[2].trim() : "")) {
//对应数据位置 //对应数据位置
String[] location = middle.get(fj[2].trim()).split("-"); String[] location = middle.get(fj[2].trim()).split("-");
res.get(location[0]).get(Integer.parseInt(location[1])-1).setPath(fj[3]); res.get(location[0]).get(Integer.parseInt(location[1]) - 1).setPath(fj[3]);
} }
} }
} ); });
return res; return res;
} }
private boolean inDate(String as,List<String> dates) { private boolean inDate(String as, List<String> dates) {
if (null != as && !"".equals(as)) { if (null != as && !"".equals(as)) {
for (String s : dates) { for (String s : dates) {
if (s.equals(as.trim())) { if (s.equals(as.trim())) {
@@ -282,13 +283,13 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
} }
@Value("file.importPath") @Value("file.importPath")
private String importPath; private String importPath;
private List<ImportDto> error=new ArrayList<>(); private List<ImportDto> error = new ArrayList<>();
private List<ImportDto> fileError = new ArrayList<>();
private List<ImportDto> fileError=new ArrayList<>();
@Override @Override
public List<ImportDto> storageExclData(Map<String, List<ImportDto>> importListMap) { public List<ImportDto> storageExclData(Map<String, List<ImportDto>> importListMap) {
@@ -297,75 +298,72 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
/** /**
* 海外标准 * 海外标准
*/ */
importListMap.get("HWBZ").forEach(item->{ importListMap.get("HWBZ").forEach(item -> {
String standID = UUIDUtils.randomUUID20(); String standID = UUIDUtils.randomUUID20();
SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID); SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID);
// //
// //
if (sarStandardsInfo!=null) if (sarStandardsInfo != null) {
{
SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID); SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID);
sarStandardsInfo.setValidFlag("0"); sarStandardsInfo.setValidFlag("0");
sarStandardsInfo.setStandType("FOREIGN"); sarStandardsInfo.setStandType("FOREIGN");
QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>(); QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>();
standSaveWrapper standSaveWrapper
.eq("STAND_SORT",sarStandardsInfo.getStandSort()) .eq("STAND_SORT", sarStandardsInfo.getStandSort())
.eq("STAND_NUMBER",sarStandardsInfo.getStandNumber()) .eq("STAND_NUMBER", sarStandardsInfo.getStandNumber())
.eq("STAND_YEAR",sarStandardsInfo.getStandYear()); .eq("STAND_YEAR", sarStandardsInfo.getStandYear());
SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper);
if (one!=null){ if (one != null) {
sarStandardsInfo.setId(one.getId()); sarStandardsInfo.setId(one.getId());
sarStandardsInfoService.update(sarStandardsInfo,standSaveWrapper); sarStandardsInfoService.update(sarStandardsInfo, standSaveWrapper);
QueryWrapper<SarStandAttrInfo> standAttrWrapper = new QueryWrapper<>(); QueryWrapper<SarStandAttrInfo> standAttrWrapper = new QueryWrapper<>();
standAttrWrapper.eq("STAND_ID",one.getId()); standAttrWrapper.eq("STAND_ID", one.getId());
sarStandAttrInfo.setStandId(one.getId()); sarStandAttrInfo.setStandId(one.getId());
sarStandAttrInfoService.update(sarStandAttrInfo,standAttrWrapper); sarStandAttrInfoService.update(sarStandAttrInfo, standAttrWrapper);
}else { } else {
sarStandardsInfoService.save(sarStandardsInfo); sarStandardsInfoService.save(sarStandardsInfo);
String field="ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ"; String field = "ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ";
String value="\'"+sarStandAttrInfo.getId()+"\'"+","+ "\'"+sarStandAttrInfo.getStandId()+"\'"+","+"\'"+"0"+"\'"; String value = "\'" + sarStandAttrInfo.getId() + "\'" + "," + "\'" + sarStandAttrInfo.getStandId() + "\'" + "," + "\'" + "0" + "\'";
if (sarStandAttrInfo.getDtbjh() != null) {
value += "," + "\'" + sarStandAttrInfo.getDtbjh() + "\'";
}
if (sarStandAttrInfo.getSsrq() != null) {
value += "," + "\'" + sarStandAttrInfo.getSsrq() + "\'";
}
sarStandAttrInfoDao.insertStandAttr(field, value);
if (sarStandAttrInfo.getDtbjh()!=null){
value+=","+"\'"+sarStandAttrInfo.getDtbjh()+"\'";
} }
if (sarStandAttrInfo.getSsrq()!=null){
value+=","+"\'"+sarStandAttrInfo.getSsrq()+"\'";
}
sarStandAttrInfoDao.insertStandAttr(field,value);
} else {
}
}else{
item.setErrorStr("标准号无法解析"); item.setErrorStr("标准号无法解析");
error.add(item); error.add(item);
importListMap.replace("error",error); importListMap.replace("error", error);
} }
}); });
/** /**
* 国内标准 * 国内标准
*/ */
importListMap.get("GNBZ").forEach(item->{ importListMap.get("GNBZ").forEach(item -> {
String standID = UUIDUtils.randomUUID20(); String standID = UUIDUtils.randomUUID20();
SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID); SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID);
if (sarStandardsInfo!=null){ if (sarStandardsInfo != null) {
SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID); SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID);
sarStandardsInfo.setValidFlag("0"); sarStandardsInfo.setValidFlag("0");
@@ -374,44 +372,44 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>(); QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>();
standSaveWrapper standSaveWrapper
.eq("STAND_SORT",sarStandardsInfo.getStandSort()) .eq("STAND_SORT", sarStandardsInfo.getStandSort())
.eq("STAND_NUMBER",sarStandardsInfo.getStandNumber()) .eq("STAND_NUMBER", sarStandardsInfo.getStandNumber())
.eq("STAND_YEAR",sarStandardsInfo.getStandYear()); .eq("STAND_YEAR", sarStandardsInfo.getStandYear());
SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper);
if (one!=null){ if (one != null) {
sarStandardsInfo.setId(one.getId()); sarStandardsInfo.setId(one.getId());
sarStandardsInfoService.update(sarStandardsInfo,standSaveWrapper); sarStandardsInfoService.update(sarStandardsInfo, standSaveWrapper);
QueryWrapper<SarStandAttrInfo> standAttrWrapper = new QueryWrapper<>(); QueryWrapper<SarStandAttrInfo> standAttrWrapper = new QueryWrapper<>();
standAttrWrapper.eq("STAND_ID",one.getId()); standAttrWrapper.eq("STAND_ID", one.getId());
sarStandAttrInfo.setStandId(one.getId()); sarStandAttrInfo.setStandId(one.getId());
sarStandAttrInfoService.update(sarStandAttrInfo,standAttrWrapper); sarStandAttrInfoService.update(sarStandAttrInfo, standAttrWrapper);
}else { } else {
sarStandardsInfoService.save(sarStandardsInfo); sarStandardsInfoService.save(sarStandardsInfo);
String field="ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ"; String field = "ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ";
String value="\'"+sarStandAttrInfo.getId()+"\'"+","+"\'"+sarStandAttrInfo.getStandId()+"\'"+","+"\'"+"0"+"\'"; String value = "\'" + sarStandAttrInfo.getId() + "\'" + "," + "\'" + sarStandAttrInfo.getStandId() + "\'" + "," + "\'" + "0" + "\'";
if (sarStandAttrInfo.getDtbjh()!=null){ if (sarStandAttrInfo.getDtbjh() != null) {
value+=","+"\'"+sarStandAttrInfo.getDtbjh()+"\'"; value += "," + "\'" + sarStandAttrInfo.getDtbjh() + "\'";
} }
if (sarStandAttrInfo.getSsrq()!=null){ if (sarStandAttrInfo.getSsrq() != null) {
value+=","+"\'"+sarStandAttrInfo.getSsrq()+"\'"; value += "," + "\'" + sarStandAttrInfo.getSsrq() + "\'";
} }
sarStandAttrInfoDao.insertStandAttr(field,value); sarStandAttrInfoDao.insertStandAttr(field, value);
} }
}else { } else {
item.setErrorStr("标准号无法解析"); item.setErrorStr("标准号无法解析");
error.add(item); error.add(item);
importListMap.replace("error",error); importListMap.replace("error", error);
} }
@@ -421,12 +419,12 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
/** /**
* 企业标准 * 企业标准
*/ */
importListMap.get("QYBZ").forEach(item->{ importListMap.get("QYBZ").forEach(item -> {
String standId=UUIDUtils.randomUUID20(); String standId = UUIDUtils.randomUUID20();
SarBussionessStand sarBussionessStand = parseImportDtoToSarBussionessStand(item, standId); SarBussionessStand sarBussionessStand = parseImportDtoToSarBussionessStand(item, standId);
if (sarBussionessStand!=null) { if (sarBussionessStand != null) {
SarBussStandAttrInfo sarBussStandAttrInfo = parseImportDtoToSarBussStandAttrInfo(item, standId); SarBussStandAttrInfo sarBussStandAttrInfo = parseImportDtoToSarBussStandAttrInfo(item, standId);
@@ -475,46 +473,94 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
} }
public SarStandardsInfo parseImportDtoToStandardsInfo(ImportDto importDto, String standId) {
public SarStandardsInfo parseImportDtoToStandardsInfo(ImportDto importDto,String standId){
HashMap<String, String> analysis = analysisStandId(importDto); HashMap<String, String> analysis = analysisStandId(importDto);
if (analysis==null){ if (analysis == null) {
return null; return null;
}else { }
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo(); SarStandardsInfo sarStandardsInfoEO = new SarStandardsInfo();
sarStandardsInfo.setId(standId); sarStandardsInfoEO.setId(standId);
sarStandardsInfo.setStandSort(analysis.get("sort")); sarStandardsInfoEO.setStandSort(analysis.get("sort"));
sarStandardsInfo.setStandNumber(analysis.get("number")); sarStandardsInfoEO.setStandNumber(analysis.get("number"));
sarStandardsInfo.setStandYear(analysis.get("year")); sarStandardsInfoEO.setStandYear(analysis.get("year"));
sarStandardsInfo.setStandName(importDto.getStandName()); sarStandardsInfoEO.setStandName(importDto.getStandName());
sarStandardsInfo.setStandEnName(importDto.getStandNameEN()); sarStandardsInfoEO.setStandEnName(importDto.getStandNameEN());
String issueDate = importDto.getPublishTime().substring(0, 9); /**
sarStandardsInfo.setIssueTime(issueDate);//标准发布日期 * 截取发布日期 年月日
*/
String issueDate = importDto.getPublishTime().substring(0, 9);
sarStandardsInfoEO.setIssueTime(issueDate);//标准发布日期
String standStatus = importDto.getStandStatus();
if ("有效".equals(standStatus)) {
sarStandardsInfoEO.setTextStatus("vsaga7nwub");//现行有效
}
/**
* 标准属性字段
*/
HashMap<String, String> attrInfoMap = new HashMap<>();
attrInfoMap.put("DTBJH", importDto.getReplaceId());
attrInfoMap.put("SSRQ", importDto.getImplementedTime().substring(0, 9));
/**
* 文件
*/
if (importDto.getPath() != null) {
String path[] = importDto.getPath().split("/");
String realPath = "";
for (int i = 4; i < path.length; i++) {
realPath = realPath + "/" + path[i];
String standStatus = importDto.getStandStatus();
if ("有效".equals(standStatus)) {
sarStandardsInfo.setTextStatus("vsaga7nwub");//现行有效
} }
return sarStandardsInfo;
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) {
attrInfoMap.put("FBGJBD", fileInfo.getAttId());
} else {
attrInfoMap.put("GLWJ", fileInfo.getAttId());
}
} else {
importDto.setErrorStr("文件不存在");
fileError.add(importDto);
}
} catch (Exception e) {
importDto.setErrorStr("文件打开失败");
fileError.add(importDto);
e.printStackTrace();
}
} }
// attrInfoMap.put("")
Gson gson = new Gson();
String attrInfoJson = gson.toJson(attrInfoMap);
sarStandardsInfoEO.setSarStandAttrEOStr(attrInfoJson);
return sarStandardsInfoEO;
} }
public SarStandAttrInfo parseImportDtoToStandAttrInfo(ImportDto importDto,String standId) { public SarStandAttrInfo parseImportDtoToStandAttrInfo(ImportDto importDto, String standId) {
SarStandAttrInfo sarStandAttrInfo = new SarStandAttrInfo(); SarStandAttrInfo sarStandAttrInfo = new SarStandAttrInfo();
@@ -529,33 +575,30 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
// Arrays.stream(path).limit(2,path.length); // Arrays.stream(path).limit(2,path.length);
if (importDto.getPath()!=null) if (importDto.getPath() != null) {
{
String path[] = importDto.getPath().split("/"); String path[] = importDto.getPath().split("/");
String realPath=""; String realPath = "";
for (int i = 4; i < path.length; i++) { for (int i = 4; i < path.length; i++) {
realPath=realPath+"/"+path[i]; realPath = realPath + "/" + path[i];
} }
try { try {
// File file = new File("C:\\Users\\22501\\Desktop\\foton\\2021\\" + realPath); // File file = new File("C:\\Users\\22501\\Desktop\\foton\\2021\\" + realPath);
// File file = new File(importPath + realPath); // File file = new File(importPath + realPath);
File file = new File("/home/file/2021/" + realPath); File file = new File("/home/file/2021/" + realPath);
if (file.exists()){ if (file.exists()) {
AttFileVo fileInfo = attFileEOService.saveFileInfo(file); AttFileVo fileInfo = attFileEOService.saveFileInfo(file);
HashMap<String, String> fileMap = new HashMap<>(); HashMap<String, String> fileMap = new HashMap<>();
/** /**
* * @Param: [standId, fileMap] fileMap<field,fileIds> * * @Param: [standId, fileMap] fileMap<field,fileIds>
*/ */
fileMap.put("GLWJ",fileInfo.getAttId()); fileMap.put("GLWJ", fileInfo.getAttId());
try { try {
sarStandardsInfoService.createStandFile(standId,fileMap); sarStandardsInfoService.createStandFile(standId, fileMap);
} catch (Exception e) { } catch (Exception e) {
importDto.setErrorStr("创建标准文件异常"); importDto.setErrorStr("创建标准文件异常");
fileError.add(importDto); fileError.add(importDto);
@@ -564,19 +607,18 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
} }
sarStandAttrInfo.setGlwj(fileInfo.getAttId()); sarStandAttrInfo.setGlwj(fileInfo.getAttId());
}else { } else {
importDto.setErrorStr("文件不存在"); importDto.setErrorStr("文件不存在");
fileError.add(importDto); fileError.add(importDto);
} }
}catch (Exception e){ } catch (Exception e) {
importDto.setErrorStr("文件打开失败"); importDto.setErrorStr("文件打开失败");
fileError.add(importDto); fileError.add(importDto);
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -585,16 +627,13 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
} }
public SarBussionessStand parseImportDtoToSarBussionessStand(ImportDto importDto, String standId) {
public SarBussionessStand parseImportDtoToSarBussionessStand(ImportDto importDto,String standId){
HashMap<String, String> analysis = analysisStandId(importDto); HashMap<String, String> analysis = analysisStandId(importDto);
if (analysis==null){ if (analysis == null) {
return null; return null;
}else { } else {
SarBussionessStand sarBussionessStand = new SarBussionessStand(); SarBussionessStand sarBussionessStand = new SarBussionessStand();
sarBussionessStand.setId(standId); sarBussionessStand.setId(standId);
sarBussionessStand.setStandSort(analysis.get("sort")); sarBussionessStand.setStandSort(analysis.get("sort"));
@@ -606,31 +645,28 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
sarBussionessStand.setPutTime(importDto.getImplementedTime()); sarBussionessStand.setPutTime(importDto.getImplementedTime());
sarBussionessStand.setReplacedStandNum(importDto.getReplaceId()); sarBussionessStand.setReplacedStandNum(importDto.getReplaceId());
sarBussionessStand.setValidFlag(0); sarBussionessStand.setValidFlag(0);
if ("有效".equals(importDto.getStandStatus())){ if ("有效".equals(importDto.getStandStatus())) {
sarBussionessStand.setTextStatusBuss("vsaga7nwub"); sarBussionessStand.setTextStatusBuss("vsaga7nwub");
} }
return sarBussionessStand; return sarBussionessStand;
} }
} }
public SarBussStandAttrInfo parseImportDtoToSarBussStandAttrInfo(ImportDto importDto,String standId){ public SarBussStandAttrInfo parseImportDtoToSarBussStandAttrInfo(ImportDto importDto, String standId) {
SarBussStandAttrInfo sarBussStandAttrInfo = new SarBussStandAttrInfo(); SarBussStandAttrInfo sarBussStandAttrInfo = new SarBussStandAttrInfo();
sarBussStandAttrInfo.setId(UUIDUtils.randomUUID20()); sarBussStandAttrInfo.setId(UUIDUtils.randomUUID20());
sarBussStandAttrInfo.setStandId(standId); sarBussStandAttrInfo.setStandId(standId);
sarBussStandAttrInfo.setValidFlag("0"); sarBussStandAttrInfo.setValidFlag("0");
if (importDto.getPath() != null) {
if (importDto.getPath()!=null)
{
String path[] = importDto.getPath().split("/"); String path[] = importDto.getPath().split("/");
String realPath=""; String realPath = "";
for (int i = 4; i < path.length; i++) { for (int i = 4; i < path.length; i++) {
realPath=realPath+"/"+path[i]; realPath = realPath + "/" + path[i];
} }
@@ -640,77 +676,75 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
// File file = new File(importPath + realPath); // File file = new File(importPath + realPath);
File file = new File("/home/file/2021/" + realPath); File file = new File("/home/file/2021/" + realPath);
if (file.exists()){ if (file.exists()) {
AttFileVo fileInfo = attFileEOService.saveFileInfo(file); AttFileVo fileInfo = attFileEOService.saveFileInfo(file);
HashMap<String, String> fileMap = new HashMap<>(); 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());
* * @Param: [standId, fileMap] fileMap<field,fileIds>
*/ } else {
fileMap.put("GLWJBUSS",fileInfo.getAttId()); importDto.setErrorStr("文件不存在");
try {
sarBussionessStandService.createStandFile(standId,fileMap);
} catch (Exception e) {
importDto.setErrorStr("创建标准文件异常");
fileError.add(importDto); fileError.add(importDto);
e.printStackTrace();
System.out.println("创建标准文件异常");
} }
sarBussStandAttrInfo.setGlwj(fileInfo.getAttId()); } catch (Exception e) {
importDto.setErrorStr("路径错误!");
}else {
importDto.setErrorStr("文件不存在");
fileError.add(importDto); fileError.add(importDto);
e.printStackTrace();
} }
}catch (Exception e){
importDto.setErrorStr("路径错误!");
fileError.add(importDto);
e.printStackTrace();
}
} }
return sarBussStandAttrInfo; return sarBussStandAttrInfo;
} }
public HashMap<String,String> analysisStandId(ImportDto importDto){ public HashMap<String, String> analysisStandId(ImportDto importDto) {
HashMap<String, String> result = new HashMap<>(); HashMap<String, String> result = new HashMap<>();
if(importDto.getStandId()==null){ if (importDto.getStandId() == null) {
importDto.setErrorStr("标准号为空"); importDto.setErrorStr("标准号为空");
error.add(importDto); error.add(importDto);
return null; return null;
}else { } else {
String standId = importDto.getStandId(); String standId = importDto.getStandId();
//格式 非空格字符+空格+非空格字符+‘-’或‘—’或空格+年份 如Q/FT F003—2001 //格式 非空格字符+空格+非空格字符+‘-’或‘—’或空格+年份 如Q/FT F003—2001
Pattern pattern = Pattern.compile("^\\S*\\s\\S*[\\u2014\\u002d\\s]\\d{4}$"); Pattern pattern = Pattern.compile("^\\S*\\s\\S*[\\u2014\\u002d\\s]\\d{4}$");
if (!pattern.matcher(standId).matches()){ if (!pattern.matcher(standId).matches()) {
importDto.setErrorStr("标准号无法解析"); importDto.setErrorStr("标准号无法解析");
error.add(importDto); error.add(importDto);
return null; return null;
} }
String sort=""; String sort = "";
String number=""; String number = "";
String year=""; String year = "";
String[] split = importDto.getStandId().split("[\\u2014\\u002d\\s]");//以空格或'-'或'—'分割 String[] split = importDto.getStandId().split("[\\u2014\\u002d\\s]");//以空格或'-'或'—'分割
// 多种格式(╯‵□′)╯︵┻━┻ Q-FL T015-2021 Q/ FL T015-2021 Q/FL T015-2021 // 多种格式(╯‵□′)╯︵┻━┻ Q-FL T015-2021 Q/ FL T015-2021 Q/FL T015-2021
int length = split.length; int length = split.length;
number=split[length-2]; number = split[length - 2];
year=split[length-1]; year = split[length - 1];
for (int i = 0; i < length-2; i++) { for (int i = 0; i < length - 2; i++) {
sort+=split[i]; sort += split[i];
} }
result.put("sort",sort); result.put("sort", sort);
result.put("number",number); result.put("number", number);
result.put("year",year); result.put("year", year);
return result; return result;
} }