From 77c274b7243e19e0556d322549351c5b14291d06 Mon Sep 17 00:00:00 2001 From: "zhaokaiyao@91isoft.com" <6922339zky> Date: Thu, 9 Sep 2021 22:29:34 +0800 Subject: [PATCH] commit --- .../service/impl/ImportExcelServiceImpl.java | 366 ++++++++++-------- 1 file changed, 200 insertions(+), 166 deletions(-) diff --git a/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/service/impl/ImportExcelServiceImpl.java b/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/service/impl/ImportExcelServiceImpl.java index ab9b75b9..3169c12a 100644 --- a/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/service/impl/ImportExcelServiceImpl.java +++ b/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/service/impl/ImportExcelServiceImpl.java @@ -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.service.impl.SarStandardsInfoServiceImpl; 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; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -34,7 +36,6 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.InputStream; -import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Pattern; @@ -82,12 +83,12 @@ public class ImportExcelServiceImpl extends ServiceImpl> getExcelData(MultipartFile file, MultipartFile file2) { - List dates=new ArrayList<>(); - for(int i=1669;i<2023;i++){ - dates.add("-"+i); - dates.add("—"+i); - dates.add("- "+i); - dates.add("— "+i); + List dates = new ArrayList<>(); + for (int i = 1669; i < 2023; i++) { + dates.add("-" + i); + dates.add("—" + i); + dates.add("- " + i); + dates.add("— " + i); } if (file == null || file.getSize() == 0) { @@ -138,10 +139,10 @@ public class ImportExcelServiceImpl extends ServiceImpl { //判断是否是正确的数据 String[] as = items.split(","); - if (!inDate(as[0],dates)) { + if (!inDate(as[0], dates)) { ImportDto importDto = getImportDto(as); error.add(importDto); - middle.put(as[0].trim(), "error-"+error.size()); + middle.put(as[0].trim(), "error-" + error.size()); } else { //数据二次拆解 针对标准进行拆解 String[] step2 = as[0].trim().split(" "); @@ -149,15 +150,15 @@ public class ImportExcelServiceImpl extends ServiceImpl{ - String[] fj=items2.split(","); - if (fj.length>2) { + fujian.forEach(items2 -> { + String[] fj = items2.split(","); + if (fj.length > 2) { if (null != middle.get(null != fj[2] ? fj[2].trim() : "")) { //对应数据位置 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; } - private boolean inDate(String as,List dates) { + private boolean inDate(String as, List dates) { if (null != as && !"".equals(as)) { for (String s : dates) { if (s.equals(as.trim())) { @@ -282,13 +283,13 @@ public class ImportExcelServiceImpl extends ServiceImpl error=new ArrayList<>(); + private List error = new ArrayList<>(); + + private List fileError = new ArrayList<>(); - private List fileError=new ArrayList<>(); @Override public List storageExclData(Map> importListMap) { @@ -297,75 +298,72 @@ public class ImportExcelServiceImpl extends ServiceImpl{ + importListMap.get("HWBZ").forEach(item -> { String standID = UUIDUtils.randomUUID20(); SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID); // // - if (sarStandardsInfo!=null) - { + if (sarStandardsInfo != null) { SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID); - sarStandardsInfo.setValidFlag("0"); - sarStandardsInfo.setStandType("FOREIGN"); - QueryWrapper standSaveWrapper = new QueryWrapper<>(); - standSaveWrapper - .eq("STAND_SORT",sarStandardsInfo.getStandSort()) - .eq("STAND_NUMBER",sarStandardsInfo.getStandNumber()) - .eq("STAND_YEAR",sarStandardsInfo.getStandYear()); + sarStandardsInfo.setValidFlag("0"); + sarStandardsInfo.setStandType("FOREIGN"); + QueryWrapper standSaveWrapper = new QueryWrapper<>(); + standSaveWrapper + .eq("STAND_SORT", sarStandardsInfo.getStandSort()) + .eq("STAND_NUMBER", sarStandardsInfo.getStandNumber()) + .eq("STAND_YEAR", sarStandardsInfo.getStandYear()); - SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); - if (one!=null){ - sarStandardsInfo.setId(one.getId()); + SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); + if (one != null) { + sarStandardsInfo.setId(one.getId()); - sarStandardsInfoService.update(sarStandardsInfo,standSaveWrapper); - QueryWrapper standAttrWrapper = new QueryWrapper<>(); - standAttrWrapper.eq("STAND_ID",one.getId()); + sarStandardsInfoService.update(sarStandardsInfo, standSaveWrapper); + QueryWrapper 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"+"\'"; + 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 (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("标准号无法解析"); 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(); SarStandardsInfo sarStandardsInfo = parseImportDtoToStandardsInfo(item, standID); - if (sarStandardsInfo!=null){ + if (sarStandardsInfo != null) { SarStandAttrInfo sarStandAttrInfo = parseImportDtoToStandAttrInfo(item, standID); sarStandardsInfo.setValidFlag("0"); @@ -374,44 +372,44 @@ public class ImportExcelServiceImpl extends ServiceImpl standSaveWrapper = new QueryWrapper<>(); standSaveWrapper - .eq("STAND_SORT",sarStandardsInfo.getStandSort()) - .eq("STAND_NUMBER",sarStandardsInfo.getStandNumber()) - .eq("STAND_YEAR",sarStandardsInfo.getStandYear()); + .eq("STAND_SORT", sarStandardsInfo.getStandSort()) + .eq("STAND_NUMBER", sarStandardsInfo.getStandNumber()) + .eq("STAND_YEAR", sarStandardsInfo.getStandYear()); SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); - if (one!=null){ + if (one != null) { sarStandardsInfo.setId(one.getId()); - sarStandardsInfoService.update(sarStandardsInfo,standSaveWrapper); + sarStandardsInfoService.update(sarStandardsInfo, standSaveWrapper); QueryWrapper standAttrWrapper = new QueryWrapper<>(); - standAttrWrapper.eq("STAND_ID",one.getId()); + standAttrWrapper.eq("STAND_ID", one.getId()); sarStandAttrInfo.setStandId(one.getId()); - sarStandAttrInfoService.update(sarStandAttrInfo,standAttrWrapper); - }else { + sarStandAttrInfoService.update(sarStandAttrInfo, standAttrWrapper); + } else { sarStandardsInfoService.save(sarStandardsInfo); - String field="ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ"; - String value="\'"+sarStandAttrInfo.getId()+"\'"+","+"\'"+sarStandAttrInfo.getStandId()+"\'"+","+"\'"+"0"+"\'"; + String field = "ID,STAND_ID,VALID_FLAG,DTBJH,SSRQ"; + String value = "\'" + sarStandAttrInfo.getId() + "\'" + "," + "\'" + sarStandAttrInfo.getStandId() + "\'" + "," + "\'" + "0" + "\'"; - if (sarStandAttrInfo.getDtbjh()!=null){ - value+=","+"\'"+sarStandAttrInfo.getDtbjh()+"\'"; + if (sarStandAttrInfo.getDtbjh() != null) { + value += "," + "\'" + sarStandAttrInfo.getDtbjh() + "\'"; } - if (sarStandAttrInfo.getSsrq()!=null){ - value+=","+"\'"+sarStandAttrInfo.getSsrq()+"\'"; + if (sarStandAttrInfo.getSsrq() != null) { + value += "," + "\'" + sarStandAttrInfo.getSsrq() + "\'"; } - sarStandAttrInfoDao.insertStandAttr(field,value); + sarStandAttrInfoDao.insertStandAttr(field, value); } - }else { + } else { item.setErrorStr("标准号无法解析"); error.add(item); - importListMap.replace("error",error); + importListMap.replace("error", error); } @@ -421,12 +419,12 @@ public class ImportExcelServiceImpl extends ServiceImpl{ - String standId=UUIDUtils.randomUUID20(); + importListMap.get("QYBZ").forEach(item -> { + String standId = UUIDUtils.randomUUID20(); SarBussionessStand sarBussionessStand = parseImportDtoToSarBussionessStand(item, standId); - if (sarBussionessStand!=null) { + if (sarBussionessStand != null) { SarBussStandAttrInfo sarBussStandAttrInfo = parseImportDtoToSarBussStandAttrInfo(item, standId); @@ -475,46 +473,94 @@ public class ImportExcelServiceImpl extends ServiceImpl analysis = analysisStandId(importDto); - if (analysis==null){ + if (analysis == null) { return null; - }else { + } - SarStandardsInfo sarStandardsInfo = new SarStandardsInfo(); - sarStandardsInfo.setId(standId); + SarStandardsInfo sarStandardsInfoEO = new SarStandardsInfo(); + sarStandardsInfoEO.setId(standId); - sarStandardsInfo.setStandSort(analysis.get("sort")); - sarStandardsInfo.setStandNumber(analysis.get("number")); - sarStandardsInfo.setStandYear(analysis.get("year")); + sarStandardsInfoEO.setStandSort(analysis.get("sort")); + sarStandardsInfoEO.setStandNumber(analysis.get("number")); + sarStandardsInfoEO.setStandYear(analysis.get("year")); - sarStandardsInfo.setStandName(importDto.getStandName()); - sarStandardsInfo.setStandEnName(importDto.getStandNameEN()); + sarStandardsInfoEO.setStandName(importDto.getStandName()); + 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 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(); @@ -529,33 +575,30 @@ public class ImportExcelServiceImpl extends ServiceImpl fileMap = new HashMap<>(); - /** * * @Param: [standId, fileMap] fileMap */ - fileMap.put("GLWJ",fileInfo.getAttId()); + fileMap.put("GLWJ", fileInfo.getAttId()); try { - sarStandardsInfoService.createStandFile(standId,fileMap); + sarStandardsInfoService.createStandFile(standId, fileMap); } catch (Exception e) { importDto.setErrorStr("创建标准文件异常"); fileError.add(importDto); @@ -564,19 +607,18 @@ public class ImportExcelServiceImpl extends ServiceImpl analysis = analysisStandId(importDto); - if (analysis==null){ + if (analysis == null) { return null; - }else { + } else { SarBussionessStand sarBussionessStand = new SarBussionessStand(); sarBussionessStand.setId(standId); sarBussionessStand.setStandSort(analysis.get("sort")); @@ -606,31 +645,28 @@ public class ImportExcelServiceImpl extends ServiceImpl fileMap = new HashMap<>(); + if (file.exists()) { + AttFileVo fileInfo = attFileEOService.saveFileInfo(file); + HashMap fileMap = new HashMap<>(); + /** + * * @Param: [standId, fileMap] fileMap + */ + fileMap.put("GLWJBUSS", fileInfo.getAttId()); + try { + sarBussionessStandService.createStandFile(standId, fileMap); + } catch (Exception e) { + importDto.setErrorStr("创建标准文件异常"); + fileError.add(importDto); + e.printStackTrace(); + System.out.println("创建标准文件异常"); + } - /** - * * @Param: [standId, fileMap] fileMap - */ - fileMap.put("GLWJBUSS",fileInfo.getAttId()); - try { - sarBussionessStandService.createStandFile(standId,fileMap); - } catch (Exception e) { - importDto.setErrorStr("创建标准文件异常"); + sarBussStandAttrInfo.setGlwj(fileInfo.getAttId()); + + } else { + importDto.setErrorStr("文件不存在"); fileError.add(importDto); - e.printStackTrace(); - System.out.println("创建标准文件异常"); } - sarBussStandAttrInfo.setGlwj(fileInfo.getAttId()); - - }else { - importDto.setErrorStr("文件不存在"); + } catch (Exception e) { + importDto.setErrorStr("路径错误!"); fileError.add(importDto); + e.printStackTrace(); } - }catch (Exception e){ - importDto.setErrorStr("路径错误!"); - fileError.add(importDto); - e.printStackTrace(); - } - - } return sarBussStandAttrInfo; } - public HashMap analysisStandId(ImportDto importDto){ + public HashMap analysisStandId(ImportDto importDto) { HashMap result = new HashMap<>(); - if(importDto.getStandId()==null){ + if (importDto.getStandId() == null) { importDto.setErrorStr("标准号为空"); error.add(importDto); return null; - }else { + } else { String standId = importDto.getStandId(); //格式 非空格字符+空格+非空格字符+‘-’或‘—’或空格+年份 如Q/FT F003—2001 Pattern pattern = Pattern.compile("^\\S*\\s\\S*[\\u2014\\u002d\\s]\\d{4}$"); - if (!pattern.matcher(standId).matches()){ + if (!pattern.matcher(standId).matches()) { importDto.setErrorStr("标准号无法解析"); error.add(importDto); return null; } - String sort=""; - String number=""; - String year=""; + String sort = ""; + String number = ""; + String year = ""; String[] split = importDto.getStandId().split("[\\u2014\\u002d\\s]");//以空格或'-'或'—'分割 // 多种格式(╯‵□′)╯︵┻━┻ Q-FL T015-2021 Q/ FL T015-2021 Q/FL T015-2021 int length = split.length; - number=split[length-2]; - year=split[length-1]; - for (int i = 0; i < length-2; i++) { - sort+=split[i]; + number = split[length - 2]; + year = split[length - 1]; + for (int i = 0; i < length - 2; i++) { + sort += split[i]; } - result.put("sort",sort); - result.put("number",number); - result.put("year",year); + result.put("sort", sort); + result.put("number", number); + result.put("year", year); return result; }