From d5d7d0eadc9758b638fc1f3a410539eb2cbdc9b5 Mon Sep 17 00:00:00 2001 From: MrZhai Date: Mon, 7 Mar 2022 18:06:23 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=AC=AC=E4=B8=89=E6=96=B9=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=AF=BC=E5=85=A5=EF=BC=8C=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=BE=80=E6=9D=A5=E5=8D=95=E4=BD=8D=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BAjson=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thrsys/ThrCorpImportLogController.java | 58 +++++++- .../ThrProductsImportLogController.java | 128 +++++------------- .../sale/admin/dao/thrsys/ThrCorpDao.java | 7 + .../sale/admin/dao/thrsys/ThrProductsDao.java | 7 + .../admin/service/thrsys/ThrCorpService.java | 7 + .../thrsys/impl/ThrCorpServiceImpl.java | 13 ++ .../thread/ThrProductsImportService.java | 30 ++-- .../mybatis/mapper/thrsys/ThrCorpDao.xml | 18 +++ .../mybatis/mapper/thrsys/ThrProductsDao.xml | 21 +++ 9 files changed, 181 insertions(+), 108 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrCorpImportLogController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrCorpImportLogController.java index b7d35b1..c27b019 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrCorpImportLogController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrCorpImportLogController.java @@ -1,6 +1,10 @@ package com.glxp.sale.admin.controller.thrsys; +import cn.hutool.core.io.IoUtil; +import cn.hutool.json.JSONUtil; import com.github.pagehelper.PageInfo; +import com.glxp.sale.admin.constant.BasicProcessStatus; +import com.glxp.sale.admin.entity.thrsys.ThrCorpEntity; import com.glxp.sale.admin.entity.thrsys.ThrCorpImportDetailEntity; import com.glxp.sale.admin.entity.thrsys.ThrCorpImportLogEntity; import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest; @@ -8,21 +12,25 @@ import com.glxp.sale.admin.req.info.DeleteRequest; import com.glxp.sale.admin.res.PageSimpleResponse; import com.glxp.sale.admin.service.thrsys.ThrCorpImportDetailService; import com.glxp.sale.admin.service.thrsys.ThrCorpImportLogService; +import com.glxp.sale.admin.service.thrsys.ThrCorpService; +import com.glxp.sale.admin.util.CustomUtil; import com.glxp.sale.common.enums.ResultEnum; import com.glxp.sale.common.res.BaseResponse; import com.glxp.sale.common.util.ResultVOUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.File; +import java.util.Date; import java.util.List; /** * 第三方数据往来单位导入日志 */ +@Slf4j @RestController public class ThrCorpImportLogController { @@ -30,6 +38,8 @@ public class ThrCorpImportLogController { ThrCorpImportLogService thrCorpImportLogService; @Resource ThrCorpImportDetailService thrCorpImportDetailService; + @Resource + ThrCorpService thrCorpService; @GetMapping("/udiwms/thrCorp/importLog/filter") public BaseResponse filter(FilterUdiIpLogRequest filterUdiIpLogRequest, @@ -83,5 +93,45 @@ public class ThrCorpImportLogController { return ResultVOUtils.success("删除成功"); } + @PostMapping("/udiwms/thrCorp/importLog/uploadCorps") + public BaseResponse uploadCorps(@RequestParam("file") List files) { + String filePath = "D:\\udiwms\\filePath\\"; + File createFile = new File(filePath); + if (!createFile.exists()) { + createFile.mkdirs(); + } + for (int i = 0; i < files.size(); i++) { + MultipartFile file = files.get(i); + if (file.isEmpty()) { + return ResultVOUtils.error(500, "上传第" + (i++) + "个文件失败"); + } + String fileName = file.getOriginalFilename(); + try { + String fileType = fileName.substring(fileName.lastIndexOf(".")); + if (!".json".equals(fileType.toLowerCase())) { + return ResultVOUtils.error(500, "请上传json文件"); + } + //导入数据 + String jsonData = IoUtil.read(file.getInputStream()).toString(); + List thrCorpEntities = JSONUtil.toList(jsonData, ThrCorpEntity.class); + + //导入日志 + ThrCorpImportLogEntity importLog = new ThrCorpImportLogEntity(); + String genKey = CustomUtil.getId(); + importLog.setGenKey(genKey); + importLog.setFromType("文件导入"); + importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS); + + importLog.setUpdateTime(new Date(System.currentTimeMillis())); + thrCorpImportLogService.insertImportLog(importLog); + thrCorpService.importJsonData(thrCorpEntities); + importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); + thrCorpImportLogService.updateImportLog(importLog); + } catch (Exception e) { + log.error("产品信息导入失败", e); + } + } + return ResultVOUtils.success("上传成功"); + } } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrProductsImportLogController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrProductsImportLogController.java index 681c170..8d1ff8d 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrProductsImportLogController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/thrsys/ThrProductsImportLogController.java @@ -1,35 +1,35 @@ package com.glxp.sale.admin.controller.thrsys; +import cn.hutool.core.io.IoUtil; +import cn.hutool.json.JSONUtil; import com.github.pagehelper.PageInfo; +import com.glxp.sale.admin.constant.BasicProcessStatus; +import com.glxp.sale.admin.entity.thrsys.ThrProductsEntity; import com.glxp.sale.admin.entity.thrsys.ThrProductsImportDetailEntity; import com.glxp.sale.admin.entity.thrsys.ThrProductsImportLogEntity; import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest; import com.glxp.sale.admin.req.inout.DeleteRequest; -import com.glxp.sale.admin.req.thrsys.PostThrProductsRequest; import com.glxp.sale.admin.res.PageSimpleResponse; -import com.glxp.sale.admin.res.basic.ErpProductsResponse; -import com.glxp.sale.admin.service.param.SystemParamConfigService; import com.glxp.sale.admin.service.thrsys.ThrProductsImportDetailService; import com.glxp.sale.admin.service.thrsys.ThrProductsImportLogService; import com.glxp.sale.admin.thread.ThrProductsImportService; +import com.glxp.sale.admin.util.CustomUtil; import com.glxp.sale.common.enums.ResultEnum; import com.glxp.sale.common.res.BaseResponse; import com.glxp.sale.common.util.ResultVOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Row; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; +import java.util.Date; import java.util.List; +@Slf4j @RestController public class ThrProductsImportLogController { @@ -97,7 +97,7 @@ public class ThrProductsImportLogController { //产品信息导入 @PostMapping("/udiwms/thrProducts/importLog/upload") public BaseResponse uploadPi(@RequestParam("file") List files, @RequestParam("thirdSys") String thirdSys) { - String filePath = "D:\\1s\\udiwms\\filePath\\"; + String filePath = "D:\\udiwms\\filePath\\"; File createFile = new File(filePath); if (!createFile.exists()) { createFile.mkdirs(); @@ -109,92 +109,28 @@ public class ThrProductsImportLogController { } String fileName = file.getOriginalFilename(); try { - InputStream inputStream = file.getInputStream(); - Workbook workbook = null; - String filetype = fileName.substring(fileName.lastIndexOf(".")); - - if (".xls".equals(filetype)) { - workbook = new HSSFWorkbook(inputStream); - } else if (".xlsx".equals(filetype)) { - workbook = new XSSFWorkbook(inputStream); - } else { - return ResultVOUtils.error(500, "请上传excel文件"); + String fileType = fileName.substring(fileName.lastIndexOf(".")); + if (!".json".equals(fileType.toLowerCase())) { + return ResultVOUtils.error(500, "请上传json文件"); } - Sheet sheet = null; - Row row = null; - List erpProductsResponses = new ArrayList<>(); - for (int j = 0; j < workbook.getNumberOfSheets(); j++) { - sheet = workbook.getSheetAt(j); - if (sheet == null) { - continue; - } - // 滤过第一行标题 - row = sheet.getRow(0); - if ((row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null - || row.getCell(3) == null || row.getCell(4) == null || row.getCell(5) == null) || - (!"产品ID".equals(row.getCell(0).getStringCellValue()) - || !"产品名称".equals(row.getCell(1).getStringCellValue()) - || !"计量单位".equals(row.getCell(2).getStringCellValue()) - || !"规格型号".equals(row.getCell(3).getStringCellValue()) - || !"注册证号".equals(row.getCell(4).getStringCellValue()) - || !"生产厂家".equals(row.getCell(5).getStringCellValue()))) { - return ResultVOUtils.error(500, "文件格式错误!"); - } - for (int k = sheet.getFirstRowNum(); k <= sheet.getLastRowNum(); k++) { - row = sheet.getRow(k); - if (row == null || row.getRowNum() <= 0) { - continue; - } - if (filterEmpty(row)) { - continue; - } - ErpProductsResponse erpProductsResponse = new ErpProductsResponse(); - Cell cell = row.getCell(0); - if (cell != null) { - cell.setCellType(CellType.STRING); - erpProductsResponse.setCode(cell.getStringCellValue()); - } - Cell cell2 = row.getCell(1); - if (cell2 != null) { - cell2.setCellType(CellType.STRING); - erpProductsResponse.setName(cell2.getStringCellValue()); - } - Cell cell3 = row.getCell(2); - if (cell3 != null) { - cell3.setCellType(CellType.STRING); - erpProductsResponse.setMeasname(cell3.getStringCellValue()); - } - Cell cell4 = row.getCell(3); - if (cell4 != null) { - cell4.setCellType(CellType.STRING); - erpProductsResponse.setSpec(cell4.getStringCellValue()); - } - Cell cell5 = row.getCell(4); - if (cell5 != null) { - cell5.setCellType(CellType.STRING); - erpProductsResponse.setRegisterNo(cell5.getStringCellValue()); - } - Cell cell6 = row.getCell(5); - if (cell6 != null) { - cell6.setCellType(CellType.STRING); - erpProductsResponse.setManufactory(cell6.getStringCellValue()); - } - Cell cell7 = row.getCell(6); - if (cell7 != null) { - cell7.setCellType(CellType.STRING); - erpProductsResponse.setSupName(cell7.getStringCellValue()); - } - erpProductsResponses.add(erpProductsResponse); - } - } - PostThrProductsRequest postThrProductsRequest = new PostThrProductsRequest(); - postThrProductsRequest.setDatas(erpProductsResponses); - postThrProductsRequest.setUploadType("文件导入"); - postThrProductsRequest.setThirdSys(thirdSys); - thrProductsImportService.importThrProduct(postThrProductsRequest); - workbook.close(); - } catch (IOException e) { - e.printStackTrace(); + //导入数据 + String jsonData = IoUtil.read(file.getInputStream()).toString(); + List thrProductsEntities = JSONUtil.toList(jsonData, ThrProductsEntity.class); + + //导入日志 + ThrProductsImportLogEntity importLog = new ThrProductsImportLogEntity(); + String genKey = CustomUtil.getId(); + importLog.setGenKey(genKey); + importLog.setFromType("文件导入"); + importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_UNPROCESS); + + importLog.setUpdateTime(new Date(System.currentTimeMillis())); + thrProductsImportLogService.insertImportLog(importLog); + thrProductsImportService.importJsonData(thrProductsEntities); + importLog.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS); + thrProductsImportLogService.updateImportLog(importLog); + } catch (Exception e) { + log.error("产品信息导入失败", e); } } return ResultVOUtils.success("上传成功"); diff --git a/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrCorpDao.java b/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrCorpDao.java index fa4bc5b..de05094 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrCorpDao.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrCorpDao.java @@ -23,4 +23,11 @@ public interface ThrCorpDao { boolean deleteByUnitId(@Param("unitId") String unitId); boolean deleteAll(); + + /** + * 导入第三方往来单位数据 + * + * @param thrCorpEntities + */ + void importThrCorps(@Param("thrCorpEntities") List thrCorpEntities); } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrProductsDao.java b/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrProductsDao.java index 9ec7c30..e4db410 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrProductsDao.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/dao/thrsys/ThrProductsDao.java @@ -24,4 +24,11 @@ public interface ThrProductsDao { boolean deleteById(@Param("id") String id); boolean deleteAll(); + + /** + * 导入第三方产品信息 + * + * @param thrProductsEntities + */ + void importThrProducts(@Param("thrProductsEntities") List thrProductsEntities); } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/ThrCorpService.java b/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/ThrCorpService.java index 93dd4ff..43b8944 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/ThrCorpService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/ThrCorpService.java @@ -21,4 +21,11 @@ public interface ThrCorpService { boolean deleteByUnitId(String id); boolean deleteAll(); + + /** + * 导入第三方往来单位数据 + * + * @param thrCorpEntities + */ + void importJsonData(List thrCorpEntities); } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/impl/ThrCorpServiceImpl.java b/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/impl/ThrCorpServiceImpl.java index b4fdfbb..8647e83 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/impl/ThrCorpServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/service/thrsys/impl/ThrCorpServiceImpl.java @@ -5,12 +5,15 @@ import com.glxp.sale.admin.dao.thrsys.ThrCorpDao; import com.glxp.sale.admin.entity.thrsys.ThrCorpEntity; import com.glxp.sale.admin.req.thrsys.FilterThrCorpRequest; import com.glxp.sale.admin.service.thrsys.ThrCorpService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collections; import java.util.List; +@Slf4j @Service public class ThrCorpServiceImpl implements ThrCorpService { @@ -59,4 +62,14 @@ public class ThrCorpServiceImpl implements ThrCorpService { public boolean deleteAll() { return thrCorpDao.deleteAll(); } + + @Override + @Async + public void importJsonData(List thrCorpEntities) { + try { + thrCorpDao.importThrCorps(thrCorpEntities); + } catch (Exception e) { + log.error("导入第三方往来单位数据异常", e); + } + } } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/thread/ThrProductsImportService.java b/api-admin/src/main/java/com/glxp/sale/admin/thread/ThrProductsImportService.java index bbc19a0..2c8b2ab 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/thread/ThrProductsImportService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/thread/ThrProductsImportService.java @@ -1,24 +1,22 @@ package com.glxp.sale.admin.thread; import com.glxp.sale.admin.constant.BasicProcessStatus; -import com.glxp.sale.admin.entity.thrsys.*; -import com.glxp.sale.admin.req.basic.FilterUdiIpLogRequest; +import com.glxp.sale.admin.dao.thrsys.ThrProductsDao; +import com.glxp.sale.admin.entity.thrsys.ThrProductsEntity; +import com.glxp.sale.admin.entity.thrsys.ThrProductsImportLogEntity; import com.glxp.sale.admin.req.thrsys.PostThrProductsRequest; import com.glxp.sale.admin.res.basic.ErpProductsResponse; -import com.glxp.sale.admin.service.thrsys.*; +import com.glxp.sale.admin.service.thrsys.ThrProductsImportLogService; import com.glxp.sale.admin.util.CustomUtil; -import com.glxp.sale.common.enums.ResultEnum; -import com.glxp.sale.common.util.ResultVOUtils; -import org.springframework.beans.BeanUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +@Slf4j @Service public class ThrProductsImportService { @@ -26,6 +24,8 @@ public class ThrProductsImportService { private ThrProductsDlService thrProductsDlService; @Resource ThrProductsImportLogService thrProductsImportLogService; + @Resource + ThrProductsDao thrProductsDao; @Async public void importThrProduct(PostThrProductsRequest postThrProductsRequest) { @@ -59,4 +59,18 @@ public class ThrProductsImportService { thrProductsImportLogService.updateImportLog(thrProductsImportLogEntity); } } + + /** + * 批量导入产品信息 + * + * @param thrCorpEntities + */ + @Async + public void importJsonData(List thrProductsEntities) { + try { + thrProductsDao.importThrProducts(thrProductsEntities); + } catch (Exception e) { + log.error("导入产品信息异常", e); + } + } } diff --git a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml index 88823d6..94f6695 100644 --- a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml +++ b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml @@ -98,5 +98,23 @@ WHERE id = #{id} + + replace INTO thr_corp + (id, unitId, name, spell, addr, creditNo, + contact, mobile, thirdSysFk, updateTime) + values + + (#{item.id}, + #{item.unitId}, + #{item.name}, + #{item.spell}, + #{item.addr}, + #{item.creditNo}, + #{item.contact}, + #{item.mobile}, + #{item.thirdSysFk}, #{item.updateTime}) + + \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml index 30be09d..4fc5f96 100644 --- a/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml +++ b/api-admin/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml @@ -117,4 +117,25 @@ DELETE FROM thr_products + + + replace INTO thr_products + (id, code, name, measname, spec, registerNo, manufactory, + cplb, flbm, qxlb, ybbm, sptm, tyshxydm, zczbhhzbapzbh, ylqxzcrbarmc, ylqxzcrbarywmc, cpms, + thirdSysFk, updateTime, supName) + values + + (#{item.id}, + #{item.code}, + #{item.name}, + #{item.measname}, + #{item.spec}, + #{item.registerNo}, + #{item.manufactory}, + #{item.cplb}, #{item.flbm}, #{item.qxlb}, #{item.ybbm}, #{item.sptm}, + #{item.tyshxydm}, #{item.zczbhhzbapzbh}, #{item.ylqxzcrbarmc}, #{item.ylqxzcrbarywmc}, #{item.cpms}, + #{item.thirdSysFk}, #{item.updateTime}, #{item.supName}) + + \ No newline at end of file