From 4286ae309c64fe2d0eef729e6b92a5945f403b33 Mon Sep 17 00:00:00 2001 From: "zhaokaiyao@91isoft.com" <6922339zky> Date: Sun, 17 Oct 2021 19:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E5=87=86excl=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ImportExcelController.java | 23 +- .../service/impl/ImportExcelServiceImpl.java | 286 +++++++++++------- 2 files changed, 198 insertions(+), 111 deletions(-) diff --git a/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/controller/ImportExcelController.java b/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/controller/ImportExcelController.java index 1a36d323..7ba28226 100644 --- a/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/controller/ImportExcelController.java +++ b/adc-da-slrs/src/main/java/com/adc/da/slrs/ImportExcelDatas/controller/ImportExcelController.java @@ -4,6 +4,7 @@ import com.adc.da.base.web.BaseController; import com.adc.da.common.ReadExcel; import com.adc.da.http.ResponseMessage; import com.adc.da.slrs.ImportExcelDatas.comment.ExclErrorOut; +import com.adc.da.slrs.ImportExcelDatas.comment.ExclExport; import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto; import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService; import com.adc.da.slrs.ImportExcelDatas.service.impl.ImportExcelServiceImpl; @@ -34,7 +35,7 @@ import java.util.Map; @RestController @Api(description = "|SarStandPutTime|") -@RequestMapping("/ImportExcel") +@RequestMapping("/api/ImportExcel") public class ImportExcelController extends BaseController { @Autowired @@ -43,14 +44,24 @@ public class ImportExcelController extends BaseController { @Autowired private ExclErrorOut exclErrorOut; - @ApiOperation("批量删除用户收藏") + + @ApiOperation("从excl中导入标准信息") @PostMapping("/import") public void deleteList(MultipartFile file, MultipartFile file2, HttpServletResponse response, HttpServletRequest request) throws IOException { Map> mapMap=importExcelService.getExcelData(file,file2); + /** + * 导入系统 + */ List errorList = importExcelService.storageExclData(mapMap); +// mapMap.put("导入后的信息",errorList); // List guonei= mapMap.get("GNBZ"); // List haiwai = mapMap.get("HWBZ"); // List qibiao = mapMap.get("QYBZ"); + + + /** + * 生成错误表格 + */ OutputStream os = null; Workbook workbook = null; try { @@ -61,7 +72,11 @@ public class ImportExcelController extends BaseController { response.setContentType("application/force-download"); //导出数据 String headStr="标准号,标准名称,英文名称,发布时间,实施时间,标准状态,代替标准号,附件路径,错误原因"; - workbook = exclErrorOut.exportDatas(errorList,headStr); +// workbook = exclErrorOut.exportDatas(guonei,headStr); + + ExclExport exclExport = new ExclExport(); + workbook = exclExport.exportData(mapMap, headStr); + os = response.getOutputStream(); workbook.write(os); os.flush(); @@ -75,8 +90,8 @@ public class ImportExcelController extends BaseController { } - // return responseMessage; + } } 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 5175ea6c..98ded226 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 @@ -2,7 +2,6 @@ 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.http.Result; import com.adc.da.slrs.ImportExcelDatas.dao.ImportExcelDao; import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto; import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService; @@ -10,9 +9,7 @@ import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand; import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService; import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo; import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService; -import com.adc.da.sys.dao.DicTypeEODao; import com.adc.da.sys.entity.DicTypeEO; -import com.adc.da.sys.entity.DictionaryEO; import com.adc.da.sys.service.impl.DicTypeEOServiceImpl; import com.adc.da.util.UUIDUtils; import com.adc.da.utils.util.InitStandAttrUtil; @@ -26,13 +23,13 @@ import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.InputStream; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; @Service @@ -70,6 +67,7 @@ public class ImportExcelServiceImpl extends ServiceImpl middle = new HashMap<>(); datas.forEach(items -> { + System.out.print("."); //判断是否是正确的数据 String[] as = items.split(","); - if (!inDate(as[0], dates)) { + if( as.length < 8){ + ImportDto importDto = new ImportDto(); + importDto.setErrorStr(items); + error.add(importDto); + + } else if (!inDate(as[0], dates) ) { ImportDto importDto = getImportDto(as); error.add(importDto); - middle.put(as[0].trim(), "error-" + error.size()); + middle.put(as[7].trim(), "error-" + error.size()); } else { //数据二次拆解 针对标准进行拆解 String[] step2 = as[0].trim().split(" "); @@ -131,15 +135,15 @@ public class ImportExcelServiceImpl extends ServiceImpl { String[] fj = items2.split(","); if (fj.length > 2) { - if (null != middle.get(null != fj[2] ? fj[2].trim() : "")) { + if (null != middle.get(null != fj[1] ? fj[1].trim() : "")) { //对应数据位置 - String[] location = middle.get(fj[2].trim()).split("-"); + String[] location = middle.get(fj[1].trim()).split("-"); +// List importDtos = res.get(location[0]); + res.get(location[0]).get(Integer.parseInt(location[1]) - 1).setPath(fj[3]); } } @@ -189,10 +195,15 @@ public class ImportExcelServiceImpl extends ServiceImpl error = new ArrayList<>(); - private List fileError = new ArrayList<>(); @Autowired private ISarStandardsInfoService sarStandardsInfoService; @@ -278,12 +289,38 @@ public class ImportExcelServiceImpl extends ServiceImpl error = new ArrayList<>(); + + private List fileError = new ArrayList<>(); + + private HashSet sarSort = new HashSet<>(); + + + @Override public List storageExclData(Map> importListMap) { - +//TODO 利用stream把list变为set +// List list = dicTypeEOService.list(); +// list.stream().flatMap(dicTypeEO -> { +// return dicTypeEO; +// }.co) + List isExist = dicTypeEOService.getTypeIdByDicIdAndTypeName("JKSADFH564S", null, null, null); + isExist.forEach(item->{ + sarSort.add(item.getDicTypeCode()); + }); error = importListMap.get("error"); + + AtomicInteger QYBZcount= new AtomicInteger(); + AtomicInteger QYBZcountUpdate= new AtomicInteger(); + AtomicInteger HWBZcount= new AtomicInteger(); + AtomicInteger HWBZcountUpdate= new AtomicInteger(); + AtomicInteger GNBZcount= new AtomicInteger(); + AtomicInteger GNBZcountUpdate= new AtomicInteger(); + /** * 初始化国内外标准属性字段 */ @@ -296,24 +333,26 @@ public class ImportExcelServiceImpl extends ServiceImpl { + if (true ) { + String standID = UUIDUtils.randomUUID20(); - String standID = UUIDUtils.randomUUID20(); + //使用初始化的属性字段映射 获得key值,value为"" + Map mapField = standAttrMap; + SarStandardsInfo ForeignEO = parseImportDtoToStandardsInfo(item,mapField, standID); - //使用初始化的属性字段映射 获得key值,value为"" - Map mapField = standAttrMap; - SarStandardsInfo ForeignEO = parseImportDtoToStandardsInfo(item,mapField, standID); + if (ForeignEO != null) { + ForeignEO.setValidFlag("0"); + ForeignEO.setStandType("FOREIGN"); + QueryWrapper standSaveWrapper = new QueryWrapper<>(); + standSaveWrapper + .eq("STAND_SORT", ForeignEO.getStandSort()) + .eq("STAND_NUMBER", ForeignEO.getStandNumber()) + .eq("STAND_YEAR", ForeignEO.getStandYear()); - if (ForeignEO != null) { - ForeignEO.setValidFlag("0"); - ForeignEO.setStandType("FOREIGN"); - QueryWrapper standSaveWrapper = new QueryWrapper<>(); - standSaveWrapper - .eq("STAND_SORT", ForeignEO.getStandSort()) - .eq("STAND_NUMBER", ForeignEO.getStandNumber()) - .eq("STAND_YEAR", ForeignEO.getStandYear()); - - SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); + SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); @@ -322,6 +361,9 @@ public class ImportExcelServiceImpl extends ServiceImpl { - String standID = UUIDUtils.randomUUID20(); - //使用初始化的属性字段映射 获得key值,value为"" - Map mapStandField = standAttrMap; - SarStandardsInfo InlandEO = parseImportDtoToStandardsInfo(item, mapStandField,standID); - - if (InlandEO != null) { - InlandEO.setValidFlag("0"); - InlandEO.setStandType("INLAND"); + if (true) { + String standID = UUIDUtils.randomUUID20(); + //使用初始化的属性字段映射 获得key值,value为"" + Map mapStandField = standAttrMap; + SarStandardsInfo InlandEO = parseImportDtoToStandardsInfo(item, mapStandField, standID); + + if (InlandEO != null) { - QueryWrapper standSaveWrapper = new QueryWrapper<>(); - standSaveWrapper - .eq("STAND_SORT", InlandEO.getStandSort()) - .eq("STAND_NUMBER", InlandEO.getStandNumber()) - .eq("STAND_YEAR", InlandEO.getStandYear()); + InlandEO.setValidFlag("0"); + InlandEO.setStandType("INLAND"); - SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); - if (one != null) { + QueryWrapper standSaveWrapper = new QueryWrapper<>(); + standSaveWrapper + .eq("STAND_SORT", InlandEO.getStandSort()) + .eq("STAND_NUMBER", InlandEO.getStandNumber()) + .eq("STAND_YEAR", InlandEO.getStandYear()); - InlandEO.setId(one.getId()); - try { - sarStandardsInfoService.updateSarStandardsInfo(InlandEO); - } catch (Exception e) { - item.setErrorStr("国内标准更新失败"); - error.add(item); - e.printStackTrace(); + SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper); + if (one != null) { + + + InlandEO.setId(one.getId()); + try { + sarStandardsInfoService.updateSarStandardsInfo(InlandEO); + } catch (Exception e) { + item.setErrorStr("国内标准更新失败"); + error.add(item); + e.printStackTrace(); + } + + + } else { + + + try { + sarStandardsInfoService.createSarStandardsInfo(InlandEO); + } catch (Exception e) { + item.setErrorStr("国内标准新增失败"); + error.add(item); + e.printStackTrace(); + } } - - } else { - - - try { - sarStandardsInfoService.createSarStandardsInfo(InlandEO); - } catch (Exception e) { - item.setErrorStr("国内标准新增失败"); - error.add(item); - e.printStackTrace(); - } + item.setErrorStr("标准号无法解析"); + error.add(item); + importListMap.replace("error", error); } - } else { - item.setErrorStr("标准号无法解析"); - error.add(item); - importListMap.replace("error", error); - } + } }); @@ -420,38 +472,61 @@ public class ImportExcelServiceImpl extends ServiceImpl{ bussAttrMap.put(item,""); }); + importListMap.get("QYBZ").forEach(item -> { - String standId = UUIDUtils.randomUUID20(); - SarBussionessStand BussEO = parseImportDtoToSarBussionessStand(item, bussAttrMap,standId); - if (BussEO != null) { - try { - QueryWrapper saveWrapper = new QueryWrapper<>(); - saveWrapper.eq("STAND_CODE", item.getStandId()); - SarBussionessStand one = sarBussionessStandService.getOne(saveWrapper); - if (one != null) { - BussEO.setId(one.getId()); - sarBussionessStandService.updateSarBussionessStand(BussEO); - } else { - sarBussionessStandService.createSarBussionessStand(BussEO); + if (true){ +// if (item.getStandId().contains("Q/FT T396—2021") ){ + + String standId = UUIDUtils.randomUUID20(); + SarBussionessStand BussEO = parseImportDtoToSarBussionessStand(item, bussAttrMap,standId); + + if (BussEO != null) { + + try { + QueryWrapper saveWrapper = new QueryWrapper<>(); + saveWrapper.eq("STAND_CODE", item.getStandId()); + SarBussionessStand one = sarBussionessStandService.getOne(saveWrapper); + if (one != null) { + BussEO.setId(one.getId()); + sarBussionessStandService.updateSarBussionessStand(BussEO); + QYBZcountUpdate.getAndIncrement(); + QYBZcount.getAndIncrement(); + System.out.println("企业标准执行更新====第: "+QYBZcount+"行"); + + } else { + sarBussionessStandService.createSarBussionessStand(BussEO); + QYBZcount.getAndIncrement(); + System.out.println("企业标准执行新增第: "+QYBZcount+"行"); + } + + + } catch (Exception e) { + item.setErrorStr("数据格式错误"); + error.add(item); + + e.printStackTrace(); + } - - } catch (Exception e) { - item.setErrorStr("数据格式错误"); - error.add(item); - - e.printStackTrace(); - } - } + }); error.addAll(fileError); + System.out.println("执行结束"); + System.out.println("执行国内标准"+GNBZcount+"条"); + System.out.println("国内标准执行更新"+GNBZcountUpdate+"条"); + System.out.println("执行国外标准"+HWBZcount+"条"); + System.out.println("海外标准执行更新"+HWBZcountUpdate+"条"); + System.out.println("执行企业标准"+QYBZcount+"条"); + System.out.println("企业标准执行更新"+QYBZcountUpdate+"条"); + + return error; } @@ -464,13 +539,10 @@ public class ImportExcelServiceImpl extends ServiceImpl fieldMap, String standId) { - - HashMap analysis = analysisStandId(importDto); if (analysis == null) { return null; } - SarStandardsInfo sarStandardsInfoEO = new SarStandardsInfo(); sarStandardsInfoEO.setId(standId); @@ -507,21 +579,21 @@ public class ImportExcelServiceImpl extends ServiceImpl isExist = dicTypeEOService.getTypeIdByDicIdAndTypeName("JKSADFH564S", null, sort, null); - if (isExist == null || isExist.isEmpty() || isExist.size()==0){ +// List isExist = dicTypeEOService.getTypeIdByDicIdAndTypeName("JKSADFH564S", null, sort, null); + if (!sarSort.contains(sort)){ DicTypeEO dicTypeVO = new DicTypeEO(); dicTypeVO.setId(null); @@ -682,6 +754,7 @@ public class ImportExcelServiceImpl extends ServiceImpl0){ + sarSort.add(sort); importDto.setErrorStr("标准类别不存在,已新增"); }else { importDto.setErrorStr("标准类别不存在,新增失败"); @@ -692,7 +765,6 @@ public class ImportExcelServiceImpl extends ServiceImpl