From 90eeb93586cc5b151d7b7120ce921cb922c286fb Mon Sep 17 00:00:00 2001 From: "hongxi.lian" Date: Tue, 28 Nov 2023 11:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E6=9C=88=E5=8F=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customerdock/CustomerdockController.java | 3 +- .../vo/CustomerdockImportErrorVO.java | 68 +++++++++++ .../customerdock/CustomerdockConvert.java | 4 + .../customerdock/CustomerdockService.java | 2 +- .../customerdock/CustomerdockServiceImpl.java | 106 ++++++++++-------- 5 files changed, 133 insertions(+), 50 deletions(-) create mode 100644 win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/vo/CustomerdockImportErrorVO.java diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/CustomerdockController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/CustomerdockController.java index 4f24c812..2bca5e6d 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/CustomerdockController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/CustomerdockController.java @@ -8,6 +8,7 @@ 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.bom.vo.BomImportErrorVO; import com.win.module.wms.controller.customerdock.vo.*; import com.win.module.wms.convert.customerdock.CustomerdockConvert; import com.win.module.wms.dal.dataobject.customerdock.CustomerdockDO; @@ -161,7 +162,7 @@ public class CustomerdockController { @RequestParam(value = "mode") Integer mode, @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { List list = ExcelUtils.read(file, CustomerdockImportExcelVo.class); - List errorList = customerdockService.importCustomerdockList(list, mode, updatePart); + List errorList = customerdockService.importCustomerdockList(list, mode, updatePart); Map returnMap = new HashMap<>(); returnMap.put("errorCount", errorList.size()); if(!errorList.isEmpty()) { diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/vo/CustomerdockImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/vo/CustomerdockImportErrorVO.java new file mode 100644 index 00000000..f6ba82f6 --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/vo/CustomerdockImportErrorVO.java @@ -0,0 +1,68 @@ +package com.win.module.wms.controller.customerdock.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 CustomerdockImportErrorVO { + @ExcelProperty("代码") + private String code; + + @ExcelProperty("名称") + private String name; + + @ExcelProperty("描述") + private String description; + + @ExcelProperty("城市") + private String city; + + @ExcelProperty("地址") + private String address; + + @ExcelProperty("联系人姓名") + private String contactPerson; + + @ExcelProperty("联系人电话") + private String contactPhone; + + @ExcelProperty("客户代码") + private String customerCode; + + @ExcelProperty("仓库") + private String warehouseCode; + + @ExcelProperty("默认库位") + private String defaultLocationCode; + + @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/customerdock/CustomerdockConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customerdock/CustomerdockConvert.java index 7352ff0f..5ab3afa4 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customerdock/CustomerdockConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customerdock/CustomerdockConvert.java @@ -1,6 +1,8 @@ package com.win.module.wms.convert.customerdock; 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.customerdock.vo.*; import com.win.module.wms.dal.dataobject.customerdock.CustomerdockDO; import org.mapstruct.Mapper; @@ -31,4 +33,6 @@ public interface CustomerdockConvert { List convertList02(List list); CustomerdockDO convert(CustomerdockImportExcelVo customerdock); + + CustomerdockImportErrorVO convert2(CustomerdockDO bean); } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockService.java index 999acb3e..6c8e2823 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockService.java @@ -85,7 +85,7 @@ public interface CustomerdockService { */ List getCustomerdockList(CustomerdockExportReqVO exportReqVO); - List importCustomerdockList(List customerdocks, Integer mode, Boolean updatePart); + List importCustomerdockList(List customerdocks, Integer mode, Boolean updatePart); /** * 客户地点(月台)有效,状态正确 diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockServiceImpl.java index f6ea6e55..4e23e6ab 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customerdock/CustomerdockServiceImpl.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.customerdock.vo.*; +import com.win.module.wms.convert.bom.BomConvert; import com.win.module.wms.convert.customerdock.CustomerdockConvert; +import com.win.module.wms.dal.dataobject.bom.BomDO; import com.win.module.wms.dal.dataobject.currencyexchange.CurrencyexchangeDO; import com.win.module.wms.dal.dataobject.customerdock.CustomerdockDO; import com.win.module.wms.dal.mysql.customerdock.CustomerdockMapper; @@ -99,61 +101,69 @@ public class CustomerdockServiceImpl implements CustomerdockService { return customerdockMapper.selectList(exportReqVO); } + private String validateCustomerdockImport( CustomerdockDO customerdock ){ + StringBuilder message = new StringBuilder(); + try { + validateCustomerExists(null); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateCodeExists(null,customerdock.getCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } try { + validateCustomerCodeExists(customerdock.getCustomerCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateDefaultLocationCodeExists(customerdock.getDefaultLocationCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } try { + validateAvailableExists(customerdock.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } + + public CustomerdockDO existCustomerdockDO( CustomerdockDO customerdockDO){ + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("code",customerdockDO.getCode()); + queryWrapper.eq("customer_code",customerdockDO.getCustomerCode()); + CustomerdockDO customerdock = customerdockMapper.selectOne(queryWrapper); + return customerdock; + } + @Override - public List importCustomerdockList(List customerdocks, Integer mode, Boolean updatePart) { + public List importCustomerdockList(List customerdocks, Integer mode, Boolean updatePart) { if (CollUtil.isEmpty(customerdocks)) { throw exception(CUSTOMERDOCK_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); customerdocks.forEach(customerdock -> { - - String massage = ""; - // 校验,判断是否有不符合的原因 - if(mode != null){ - try { - validateCustomerExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateCodeExists(null,customerdock.getCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } try { - validateCustomerCodeExists(customerdock.getCustomerCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateDefaultLocationCodeExists(customerdock.getDefaultLocationCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } try { - validateAvailableExists(customerdock.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - } if(StrUtil.isNotEmpty(massage)){ - massage.substring(0,massage.length()-1); - errorList.add(customerdock); - } - if(errorList == null){ - // 判断如果不存在,在进行插入 - CurrencyexchangeDO existConfigurationSetting = null; - if (existConfigurationSetting == null&& mode != 3) { - customerdockMapper.insert(CustomerdockConvert.INSTANCE.convert(customerdock)); - } - else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新 - CustomerdockDO customerdockDO = CustomerdockConvert.INSTANCE.convert(customerdock); - customerdockDO.setId(existConfigurationSetting.getId()); - customerdockMapper.updateById(customerdockDO); - } + CustomerdockDO customerdockDO = CustomerdockConvert.INSTANCE.convert(customerdock); + String message =validateCustomerdockImport(customerdockDO); + boolean flag = true; + if(!message.isEmpty()){ + CustomerdockImportErrorVO importErrorVO = CustomerdockConvert.INSTANCE.convert2(customerdockDO); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); + errorList.add(importErrorVO); + flag = false; } + if(flag){ + CustomerdockDO existcustomerdockDO = existCustomerdockDO(customerdockDO); + if(existcustomerdockDO==null&& mode !=3){ + customerdockMapper.insert(customerdockDO); + } else if(existcustomerdockDO != null&& mode !=2){ + customerdockDO.setId(existcustomerdockDO.getId()); + customerdockMapper.updateById(customerdockDO); + } + } }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } return errorList; }