From f1281a97a2ce145bbdeda8a8494ca63525b80592 Mon Sep 17 00:00:00 2001 From: "hongxi.lian" Date: Fri, 24 Nov 2023 16:44:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE=20?= =?UTF-8?q?=E7=89=A9=E6=96=99=E7=AE=A1=E7=90=86=20=E7=89=A9=E5=93=81?= =?UTF-8?q?=E6=B8=85=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wms/controller/bom/BomController.java | 16 +-- .../controller/bom/vo/BomImportErrorVO.java | 63 +++++++++ .../module/wms/convert/bom/BomConvert.java | 8 +- .../module/wms/service/bom/BomService.java | 2 +- .../wms/service/bom/BomServiceImpl.java | 132 +++++++++--------- 5 files changed, 142 insertions(+), 79 deletions(-) create mode 100644 win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/vo/BomImportErrorVO.java diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/BomController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/BomController.java index 7e8ae589..60fed1c7 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/BomController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/BomController.java @@ -9,13 +9,8 @@ import com.win.framework.operatelog.core.annotations.OperateLog; import com.win.module.system.api.user.AdminUserApi; import com.win.module.system.api.user.dto.AdminUserRespDTO; import com.win.module.wms.controller.bom.vo.*; -import com.win.module.wms.controller.itembasic.vo.ItembasicExcelVO; -import com.win.module.wms.controller.itempackaging.vo.ItempackagingRespVO; import com.win.module.wms.convert.bom.BomConvert; -import com.win.module.wms.convert.itembasic.ItembasicConvert; -import com.win.module.wms.convert.itempackaging.ItempackagingConvert; import com.win.module.wms.dal.dataobject.bom.BomDO; -import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.service.bom.BomService; import io.swagger.v3.oas.annotations.Operation; @@ -170,17 +165,18 @@ public class BomController { @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") }) @PreAuthorize("@ss.hasPermission('wms:bom:import')") - public void importExcel(HttpServletResponse response, - @RequestParam("file") MultipartFile file, - @RequestParam(value = "mode") Integer mode, - @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { + public CommonResult> importExcel(HttpServletResponse response, + @RequestParam("file") MultipartFile file, + @RequestParam(value = "mode") Integer mode, + @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { List list = ExcelUtils.read(file, BomImportExcelVo.class); - List errorList = bomService.importBomList(list, mode, updatePart); + List errorList = bomService.importBomList(list, mode, updatePart); Map returnMap = new HashMap<>(); returnMap.put("errorCount", errorList.size()); if(!errorList.isEmpty()) { String url = ExcelUtils.writeLocalFile("物料清单导入错误数据" + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) + ".xls", "错误列表", errorList); returnMap.put("errorFile", url); } + return success(returnMap); } } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/vo/BomImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/vo/BomImportErrorVO.java new file mode 100644 index 00000000..734ab1db --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/bom/vo/BomImportErrorVO.java @@ -0,0 +1,63 @@ +package com.win.module.wms.controller.bom.vo; + + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.win.framework.excel.core.annotations.DictFormat; +import com.win.framework.excel.core.convert.DictConvert; +import com.win.module.wms.enums.DictTypeConstants; +import lombok.Builder; +import lombok.Data; +import lombok.ToString; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@Builder +@ToString(callSuper = true) +public class BomImportErrorVO { + @ExcelProperty("父物料代码") + private String productItemCode; + + @ExcelProperty("子物料代码") + private String componentItemCode; + + @ExcelProperty(value = "子物料计量单位", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String componentUom; + + @ExcelProperty("子物料数量") + private BigDecimal componentQty; + + @ExcelProperty("工序代码") + private String processCode; + + @ExcelProperty("版本") + private String version; + + @ExcelProperty("层级") + private String layer; + + @ExcelProperty(value = "是否可用", converter = DictConvert.class) + @DictFormat(DictTypeConstants.TRUE_FALSE) + private String available; + + @ExcelProperty("生效时间") + @ColumnWidth(value = 16) + private LocalDateTime activeTime; + + @ExcelProperty("失效时间") + @ColumnWidth(value = 16) + private LocalDateTime expireTime; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty(value = "导入状态", index = 0) + private String importStatus; + + @ExcelProperty(value = "导入说明", index = 1) + private String importRemark; + +} diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/bom/BomConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/bom/BomConvert.java index 4c1e6c17..6898750b 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/bom/BomConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/bom/BomConvert.java @@ -1,11 +1,7 @@ package com.win.module.wms.convert.bom; import com.win.framework.common.pojo.PageResult; -import com.win.module.wms.controller.bom.vo.BomImportExcelVo; -import com.win.module.wms.controller.bom.vo.BomCreateReqVO; -import com.win.module.wms.controller.bom.vo.BomExcelVO; -import com.win.module.wms.controller.bom.vo.BomRespVO; -import com.win.module.wms.controller.bom.vo.BomUpdateReqVO; +import com.win.module.wms.controller.bom.vo.*; import com.win.module.wms.dal.dataobject.bom.BomDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -36,4 +32,6 @@ public interface BomConvert { List convertList02(List list); + BomImportErrorVO convert2( BomImportExcelVo bean); + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java index b636cfd7..6544411e 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomService.java @@ -78,7 +78,7 @@ public interface BomService { */ List getBomList(BomExportReqVO exportReqVO); - List importBomList(List boms, Integer mode, Boolean updatePart); + List importBomList(List boms, Integer mode, Boolean updatePart); /** diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java index 93651e8b..d65d8f3a 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java @@ -9,10 +9,13 @@ import com.win.framework.common.pojo.CustomConditions; import com.win.framework.common.pojo.PageResult; import com.win.framework.datapermission.core.util.DataPermissionUtils; import com.win.module.wms.controller.bom.vo.*; +import com.win.module.wms.controller.purchasereceiptRequest.vo.PurchasereceiptRequestMainImportErrorVO; import com.win.module.wms.convert.bom.BomConvert; +import com.win.module.wms.convert.purchasereceiptRequest.PurchasereceiptRequestMainConvert; import com.win.module.wms.dal.dataobject.bom.BomDO; import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.dal.dataobject.productionlineitem.ProductionlineitemDO; +import com.win.module.wms.dal.dataobject.purchasereceiptRequest.PurchasereceiptRequestMainDO; import com.win.module.wms.dal.mysql.bom.BomMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.interceptor.TransactionAspectSupport; @@ -93,73 +96,76 @@ public class BomServiceImpl implements BomService { return bomMapper.selectList(exportReqVO); } + + private String validateBomImport( BomDO bomDo ){ + StringBuilder message = new StringBuilder(); + try { + validateBomExists(null); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateProductItemCodeExists(null,bomDo.getProductItemCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateComponentUomExists(bomDo.getComponentUom()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateAvailableExists(bomDo.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateComponentItemCodeExists(bomDo.getComponentItemCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateComponentQtyExists(bomDo.getComponentQty()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateProcessCodeExists(bomDo.getProcessCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } + @Override - public List importBomList(List boms, Integer mode, Boolean updatePart) { - if (CollUtil.isEmpty(boms)) { + public List importBomList(List datas, Integer mode, Boolean updatePart) { + if (CollUtil.isEmpty(datas)) { throw exception(BOM_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); - boms.forEach(bom -> { - String massage = ""; - if(mode == 2){ - try { - validateBomExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateProductItemCodeExists(null,bom.getProductItemCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateComponentUomExists(bom.getComponentUom()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateAvailableExists(bom.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateComponentItemCodeExists(bom.getComponentItemCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateComponentQtyExists(bom.getComponentQty()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateProcessCodeExists(bom.getProcessCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - - if(StrUtil.isNotEmpty(massage)){ - massage.substring(0,massage.length()-1); - errorList.add(bom); - } - if(errorList == null){ - // 判断如果不存在,在进行插入 - BomDO existAccountcalendar = bomMapper.selectByProductItemCode(bom.getProductItemCode()); - if (existAccountcalendar == null&& mode != 3) { - bomMapper.insert(BomConvert.INSTANCE.convert(bom)); - } - else if (existAccountcalendar != null && mode != 2) {// 如果存在,判断是否允许更新 - BomDO bomDO = BomConvert.INSTANCE.convert(bom); - bomDO.setId(existAccountcalendar.getId()); - bomMapper.updateById(bomDO); - } - } - } + List errorList = new ArrayList<>(); + datas.forEach(bom -> { + BomDO bomDO = BomConvert.INSTANCE.convert(bom); + String massage = this.validateBomImport(bomDO); + boolean flag = true; + if(!massage.isEmpty()){ + BomImportErrorVO importErrorVO = BomConvert.INSTANCE.convert2(bom); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(massage.substring(0, massage.length() - 1)); + errorList.add(importErrorVO); + flag = false; + } + if(flag) { + // 判断如果不存在,在进行插入 + BomDO existAccountcalendar = bomMapper.selectByProductItemCode(bom.getProductItemCode()); + if (existAccountcalendar == null && mode != 3) { + bomMapper.insert(bomDO); + } else if (existAccountcalendar != null && mode != 2) { // 如果存在,判断是否允许更新 + bomDO.setId(existAccountcalendar.getId()); + bomMapper.updateById(bomDO); + } + } }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } + return errorList; }