diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customeritem/CustomeritemController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customeritem/CustomeritemController.java index c0fff056..157b1232 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customeritem/CustomeritemController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customeritem/CustomeritemController.java @@ -8,14 +8,9 @@ import com.win.framework.excel.core.util.ExcelUtils; 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.customerdock.vo.CustomerdockRespVO; import com.win.module.wms.controller.customeritem.vo.*; -import com.win.module.wms.controller.itembasic.vo.ItembasicExcelVO; -import com.win.module.wms.convert.customerdock.CustomerdockConvert; import com.win.module.wms.convert.customeritem.CustomeritemConvert; -import com.win.module.wms.convert.itembasic.ItembasicConvert; import com.win.module.wms.dal.dataobject.customeritem.CustomeritemDO; -import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.service.customeritem.CustomeritemService; import io.swagger.v3.oas.annotations.Operation; @@ -176,16 +171,18 @@ public class CustomeritemController { @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") }) @PreAuthorize("@ss.hasPermission('wms:customeritem: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, CustomeritemImportExcelVO.class); - List errorList = customeritemService.CustomeritemimportCustomeritemList(list, mode, updatePart); + List errorList = customeritemService.CustomeritemimportCustomeritemList(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/customeritem/vo/CustomeritemImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customeritem/vo/CustomeritemImportErrorVO.java new file mode 100644 index 00000000..eaf25750 --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customeritem/vo/CustomeritemImportErrorVO.java @@ -0,0 +1,75 @@ +package com.win.module.wms.controller.customeritem.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 CustomeritemImportErrorVO { + + @ExcelProperty("客户代码") + private String customerCode; + + @ExcelProperty("物料代码") + private String itemCode; + + @ExcelProperty("客户物料代码") + private String customerItemCode; + + @ExcelProperty(value = "客户计量单位", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String cusotmerUom; + + @ExcelProperty("转换率") + private String convertRate; + + @ExcelProperty(value = "客户包装单位", converter = DictConvert.class) + @DictFormat(DictTypeConstants.PACK_UNIT) + private String packUnit; + + @ExcelProperty("客户包装量") + private BigDecimal packQty; + + @ExcelProperty(value = "客户替代包装单位", converter = DictConvert.class) + @DictFormat(DictTypeConstants.PACK_UNIT) + private String altPackUnit; + + @ExcelProperty("客户替代包装量") + private String altPackQty; + + @ExcelProperty("每器具包装数") + private Integer packQtyOfContainer; + + @ExcelProperty(value = "是否可用", converter = DictConvert.class) + @DictFormat(DictTypeConstants.TRUE_FALSE) + private String available; + + @ExcelProperty(value = "生效时间") + @ColumnWidth(value = 16) + private LocalDateTime activeTime; + + @ExcelProperty(value = "失效时间") + @ColumnWidth(value = 16) + private LocalDateTime expireTime; + + @ExcelProperty(value = "备注") + 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/customeritem/CustomeritemConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customeritem/CustomeritemConvert.java index b26429bc..634af310 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customeritem/CustomeritemConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customeritem/CustomeritemConvert.java @@ -1,6 +1,8 @@ package com.win.module.wms.convert.customeritem; import com.win.framework.common.pojo.PageResult; +import com.win.module.wms.controller.bom.vo.BomImportErrorVO; +import com.win.module.wms.controller.bom.vo.BomImportExcelVo; import com.win.module.wms.controller.customeritem.vo.*; import com.win.module.wms.dal.dataobject.customeritem.CustomeritemDO; import org.mapstruct.Mapper; @@ -32,4 +34,6 @@ public interface CustomeritemConvert { List convertList02(List list); + CustomeritemImportErrorVO convert2(CustomeritemDO bean); + } 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 6d2d1ae5..676a728a 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 @@ -137,6 +137,8 @@ public class BomServiceImpl implements BomService { return message.toString(); } + + @Override public List importBomList(List datas, Integer mode, Boolean updatePart) { if (CollUtil.isEmpty(datas)) { diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemService.java index 465d7cab..fe4cb9fd 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemService.java @@ -77,7 +77,7 @@ public interface CustomeritemService { */ List getCustomeritemList(CustomeritemExportReqVO exportReqVO); - List CustomeritemimportCustomeritemList(List customeritems, Integer mode, Boolean updatePart); + List CustomeritemimportCustomeritemList(List customeritems, Integer mode, Boolean updatePart); /** * 查询客户物品是否存在 diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemServiceImpl.java index 347a6846..b319530b 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customeritem/CustomeritemServiceImpl.java @@ -9,7 +9,9 @@ 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.customeritem.vo.*; +import com.win.module.wms.convert.bom.BomConvert; import com.win.module.wms.convert.customeritem.CustomeritemConvert; +import com.win.module.wms.dal.dataobject.bom.BomDO; import com.win.module.wms.dal.dataobject.customeritem.CustomeritemDO; import com.win.module.wms.dal.mysql.customeritem.CustomeritemMapper; import org.springframework.stereotype.Service; @@ -93,74 +95,81 @@ public class CustomeritemServiceImpl implements CustomeritemService { public List getCustomeritemList(CustomeritemExportReqVO exportReqVO) { return customeritemMapper.selectList(exportReqVO); } + private String validateCustomeritemImport( CustomeritemDO customeritem ){ + StringBuilder message = new StringBuilder(); + try { + validateItemCodeExists(null,customeritem.getCustomerItemCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateCustomerCodeExists(customeritem.getCustomerCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validatePackUnitExists(customeritem.getPackUnit()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validatePackQtyExists(customeritem.getPackQty()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validatePackQtyOfContainerExists(customeritem.getPackQtyOfContainer()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateAvailableExists(customeritem.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } + + + + public CustomeritemDO existcustomeritem( CustomeritemDO customeritem){ + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("customer_code",customeritem.getCustomerCode()); + queryWrapper.eq("item_code",customeritem.getItemCode()); + CustomeritemDO customeritemDO = customeritemMapper.selectOne(queryWrapper); + return customeritemDO; + } + @Override - public List CustomeritemimportCustomeritemList(List customeritems, Integer mode, Boolean updatePart) { + public List CustomeritemimportCustomeritemList(List customeritems, Integer mode, Boolean updatePart) { if (CollUtil.isEmpty(customeritems)) { throw exception(CUSTOMERITEM_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); customeritems.forEach(customeritem -> { - String massage = ""; - // 校验,判断是否有不符合的原因 - if(mode != null){ - try { - validateCustomerExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateItemCodeExists(null,customeritem.getCustomerItemCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateCustomerCodeExists(customeritem.getCustomerCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validatePackUnitExists(customeritem.getPackUnit()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validatePackQtyExists(customeritem.getPackQty()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validatePackQtyOfContainerExists(customeritem.getPackQtyOfContainer()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateAvailableExists(customeritem.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - } - if(StrUtil.isNotEmpty(massage)){ - massage.substring(0,massage.length()-1); - errorList.add(customeritem); + CustomeritemDO customeritemDO = CustomeritemConvert.INSTANCE.convert(customeritem); + String message = this.validateCustomeritemImport(customeritemDO); + boolean flag = true; + if(!message.isEmpty()){ + CustomeritemImportErrorVO importErrorVO = CustomeritemConvert.INSTANCE.convert2(customeritemDO); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); + errorList.add(importErrorVO); + flag = false; } - if(errorList == null){ + if(flag) { // 判断如果不存在,在进行插入 - CustomeritemDO existConfigurationSetting = null; - if (existConfigurationSetting == null&& mode != 3) { + CustomeritemDO existConfigurationSetting = existcustomeritem(customeritemDO); + if (existConfigurationSetting == null && mode != 3) { customeritemMapper.insert(CustomeritemConvert.INSTANCE.convert(customeritem)); - } - else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新 - CustomeritemDO customeritemDO = CustomeritemConvert.INSTANCE.convert(customeritem); + } else if (existConfigurationSetting != null && mode != 2) { + // 如果存在,判断是否允许更新 customeritemDO.setId(existConfigurationSetting.getId()); customeritemMapper.updateById(customeritemDO); } } }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } return errorList; }