diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customer/CustomerController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customer/CustomerController.java index 4d3e2158..8882a810 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customer/CustomerController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customer/CustomerController.java @@ -10,13 +10,8 @@ import com.win.module.system.api.user.AdminUserApi; import com.win.module.system.api.user.dto.AdminUserRespDTO; import com.win.module.wms.controller.customer.vo.CustomerImportExcelVo; import com.win.module.wms.controller.customer.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.customer.CustomerConvert; -import com.win.module.wms.convert.itembasic.ItembasicConvert; -import com.win.module.wms.convert.itempackaging.ItempackagingConvert; import com.win.module.wms.dal.dataobject.customer.CustomerDO; -import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.service.customer.CustomerService; import io.swagger.v3.oas.annotations.Operation; @@ -181,16 +176,22 @@ public class CustomerController { @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") }) @PreAuthorize("@ss.hasPermission('wms:customer: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, CustomerImportExcelVo.class); - List errorList = customerService.importCustomerList(list, mode, updatePart); + List errorList = customerService.importCustomerList(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/customer/vo/CustomerImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customer/vo/CustomerImportErrorVO.java new file mode 100644 index 00000000..8a2fab33 --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customer/vo/CustomerImportErrorVO.java @@ -0,0 +1,90 @@ +package com.win.module.wms.controller.customer.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 lombok.Builder; +import lombok.Data; +import lombok.ToString; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@Builder +@ToString(callSuper = true) +public class CustomerImportErrorVO { + @ExcelProperty("代码") + private String code; + + @ExcelProperty("名称") + private String name; + + @ExcelProperty("简称") + private String shortName; + + @ExcelProperty("地址") + private String address; + + @ExcelProperty("国家") + private String country; + + @ExcelProperty("城市") + private String city; + + @ExcelProperty("电话") + private String phone; + + @ExcelProperty("传真") + private String fax; + + @ExcelProperty("邮编") + private String postId; + + @ExcelProperty("联系人") + private String contacts; + + @ExcelProperty("银行") + private String bank; + + @ExcelProperty(value = "币种", converter = DictConvert.class) + @DictFormat("currency") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private String currency; + + @ExcelProperty("税率") + private BigDecimal taxRate; + + @ExcelProperty(value = "类型", converter = DictConvert.class) + @DictFormat("customer_type") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private String type; + + @ExcelProperty(value = "是否可用", converter = DictConvert.class) + @DictFormat("true_false") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private String available; + + @ExcelProperty("生效时间") + @ColumnWidth(value = 16) + private LocalDateTime activeTime; + + @ExcelProperty("失效时间") + @ColumnWidth(value = 16) + private LocalDateTime expireTime; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("创建时间") + @ColumnWidth(value = 16) + private LocalDateTime createTime; + + @ExcelProperty("创建者ID") + private String creator; + + @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/controller/customerdock/CustomerdockController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/customerdock/CustomerdockController.java index 9f27940f..4f24c812 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,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.customer.vo.CustomerRespVO; import com.win.module.wms.controller.customerdock.vo.*; -import com.win.module.wms.controller.itembasic.vo.ItembasicExcelVO; -import com.win.module.wms.convert.customer.CustomerConvert; import com.win.module.wms.convert.customerdock.CustomerdockConvert; -import com.win.module.wms.convert.itembasic.ItembasicConvert; import com.win.module.wms.dal.dataobject.customerdock.CustomerdockDO; -import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.service.customerdock.CustomerdockService; import io.swagger.v3.oas.annotations.Operation; @@ -161,10 +156,10 @@ public class CustomerdockController { @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") }) @PreAuthorize("@ss.hasPermission('wms:customer: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, CustomerdockImportExcelVo.class); List errorList = customerdockService.importCustomerdockList(list, mode, updatePart); Map returnMap = new HashMap<>(); @@ -172,5 +167,7 @@ public class CustomerdockController { 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/convert/customer/CustomerConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customer/CustomerConvert.java index 34b5178b..47bcdbaf 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customer/CustomerConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/customer/CustomerConvert.java @@ -1,6 +1,8 @@ package com.win.module.wms.convert.customer; 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.customer.vo.*; import com.win.module.wms.dal.dataobject.customer.CustomerDO; import org.mapstruct.Mapper; @@ -32,4 +34,6 @@ public interface CustomerConvert { CustomerDO convert(CustomerImportExcelVo customer); + CustomerImportErrorVO convert2(CustomerDO bean); + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerService.java index 27d1f678..630a686e 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerService.java @@ -77,7 +77,7 @@ public interface CustomerService { */ List getCustomerList(CustomerExportReqVO exportReqVO); - List importCustomerList(List customers, Integer mode, Boolean updatePart); + List importCustomerList(List customers, Integer mode, Boolean updatePart); /** * 校验客户信息有效 * BQ-----QCus diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerServiceImpl.java index b7970ac4..dfa2beae 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/customer/CustomerServiceImpl.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.customer.vo.*; +import com.win.module.wms.convert.bom.BomConvert; import com.win.module.wms.convert.customer.CustomerConvert; +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.customer.CustomerDO; import com.win.module.wms.dal.mysql.customer.CustomerMapper; @@ -88,58 +90,62 @@ public class CustomerServiceImpl implements CustomerService { return customerMapper.selectList(exportReqVO); } + private String validateCustomerImport( CustomerDO customer ){ + StringBuilder message = new StringBuilder(); + try { + validateCustomerExists(null); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateCodeExists(null,customer.getCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateShortNameExists(customer.getShortName()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateAvailableExists(customer.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } + @Override - public List importCustomerList(List customers, Integer mode, Boolean updatePart) { + public List importCustomerList(List customers, Integer mode, Boolean updatePart) { if (CollUtil.isEmpty(customers)) { throw exception(CUSTOMER_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); customers.forEach(customer -> { - String massage = ""; - // 校验,判断是否有不符合的原因 - if(mode != null){ - try { - validateCustomerExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateCodeExists(null,customer.getCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateShortNameExists(customer.getShortName()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateAvailableExists(customer.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - if(StrUtil.isNotEmpty(massage)){ - massage.substring(0,massage.length()-1); - errorList.add(customer); - } - if(errorList == null){ - // 判断如果不存在,在进行插入 - CurrencyexchangeDO existConfigurationSetting = null; - if (existConfigurationSetting == null&& mode != 3) { - customerMapper.insert(CustomerConvert.INSTANCE.convert(customer)); - } - else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新 - CustomerDO customerDO = CustomerConvert.INSTANCE.convert(customer); - customerDO.setId(existConfigurationSetting.getId()); - customerMapper.updateById(customerDO); - } - } + CustomerDO customerDO = CustomerConvert.INSTANCE.convert(customer); + String message = this.validateCustomerImport(customerDO); + boolean flag = true; + if(!message.isEmpty()){ + CustomerImportErrorVO importErrorVO = CustomerConvert.INSTANCE.convert2(customerDO); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); + errorList.add(importErrorVO); + flag = false; + } + if(flag){ + // 判断如果不存在,在进行插入 + CustomerDO existAccountcalendar = customerMapper.selectByCode(customerDO.getCode()); + if(existAccountcalendar == null && mode !=3){ + customerMapper.insert(customerDO); + } else if (existAccountcalendar !=null && mode !=2){ + // 如果存在,判断是否允许更新 + customerDO.setId(existAccountcalendar.getId()); + customerMapper.updateById(customerDO); + } + } + // 校验,判断是否有不符合的原因 }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } return errorList; } 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 c345ce65..f6ea6e55 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 @@ -106,6 +106,7 @@ public class CustomerdockServiceImpl implements CustomerdockService { } List errorList = new ArrayList<>(); customerdocks.forEach(customerdock -> { + String massage = ""; // 校验,判断是否有不符合的原因 if(mode != null){