From 8fe376194216e57040149fc2fc0ef786c5a343bd Mon Sep 17 00:00:00 2001 From: "hongxi.lian" Date: Wed, 29 Nov 2023 17:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=97=A5=E5=8E=86=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemcalendarController.java | 11 ++- .../vo/SystemcalendarImportErrorVO.java | 56 +++++++++++ .../systemcalendar/SystemcalendarConvert.java | 10 +- .../systemcalendar/SystemcalendarMapper.java | 5 + .../InventoryinitRequestMainServiceImpl.java | 2 +- .../systemcalendar/SystemcalendarService.java | 2 +- .../SystemcalendarServiceImpl.java | 94 +++++++++++-------- 7 files changed, 129 insertions(+), 51 deletions(-) create mode 100644 win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/systemcalendar/vo/SystemcalendarImportErrorVO.java diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/systemcalendar/SystemcalendarController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/systemcalendar/SystemcalendarController.java index 01da58b3..e53d4780 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/systemcalendar/SystemcalendarController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/systemcalendar/SystemcalendarController.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.itembasic.vo.ItembasicExcelVO; import com.win.module.wms.controller.process.vo.ProcessRespVO; import com.win.module.wms.controller.systemcalendar.vo.*; @@ -144,7 +145,7 @@ public class SystemcalendarController { } @GetMapping("/get-import-template") - @Operation(summary = "获得导入班组信息模板") + @Operation(summary = "获得导入系统日历信息模板") public void importTemplate(HttpServletResponse response) throws IOException { // 手动创建导出 demo List list = Arrays.asList( @@ -156,12 +157,12 @@ public class SystemcalendarController { // 输出 // 输出 - ExcelUtils.write(response, "班组导入模板.xls", "班组列表", SystemcalendarImportExcelVo.class, list,mapDropDown); + ExcelUtils.write(response, "系统日历导入模板.xls", "系统日历列表", SystemcalendarImportExcelVo.class, list,mapDropDown); } @PostMapping("/import") - @Operation(summary = "导入班组信息") + @Operation(summary = "导入系统日历信息") @Parameters({ @Parameter(name = "file", description = "Excel 文件", required = true), @Parameter(name = "mode", description = "导入模式1更新2追加3覆盖", example = "1"), @@ -173,11 +174,11 @@ public class SystemcalendarController { @RequestParam(value = "mode") Integer mode, @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { List list = ExcelUtils.read(file, SystemcalendarImportExcelVo.class); - List errorList = systemcalendarService.importSystemcalendarList(list, mode, updatePart); + List errorList = systemcalendarService.importSystemcalendarList(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); + 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/systemcalendar/vo/SystemcalendarImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/systemcalendar/vo/SystemcalendarImportErrorVO.java new file mode 100644 index 00000000..319f66b2 --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/systemcalendar/vo/SystemcalendarImportErrorVO.java @@ -0,0 +1,56 @@ +package com.win.module.wms.controller.systemcalendar.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 SystemcalendarImportErrorVO { + @ExcelProperty("模块") + private String module; + + @ExcelProperty("开始时间") + @ColumnWidth(value = 16) + private LocalDateTime startTime; + + @ExcelProperty("结束时间") + @ColumnWidth(value = 16) + private LocalDateTime stopTime; + + @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/convert/systemcalendar/SystemcalendarConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/systemcalendar/SystemcalendarConvert.java index 05e47dcd..00963976 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/systemcalendar/SystemcalendarConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/systemcalendar/SystemcalendarConvert.java @@ -4,11 +4,9 @@ import java.util.*; import com.win.framework.common.pojo.PageResult; -import com.win.module.wms.controller.systemcalendar.vo.SystemcalendarCreateReqVO; -import com.win.module.wms.controller.systemcalendar.vo.SystemcalendarExcelVO; -import com.win.module.wms.controller.systemcalendar.vo.SystemcalendarRespVO; -import com.win.module.wms.controller.systemcalendar.vo.SystemcalendarUpdateReqVO; -import com.win.module.wms.controller.systemcalendar.vo.SystemcalendarImportExcelVo; +import com.win.module.wms.controller.bom.vo.BomImportErrorVO; +import com.win.module.wms.controller.bom.vo.BomImportExcelVo; +import com.win.module.wms.controller.systemcalendar.vo.*; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import com.win.module.wms.dal.dataobject.systemcalendar.SystemcalendarDO; @@ -37,4 +35,6 @@ public interface SystemcalendarConvert { SystemcalendarDO convert(SystemcalendarImportExcelVo bean); + SystemcalendarImportErrorVO convert2(SystemcalendarDO bean); + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/dal/mysql/systemcalendar/SystemcalendarMapper.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/dal/mysql/systemcalendar/SystemcalendarMapper.java index cbc42c17..dbfb7d92 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/dal/mysql/systemcalendar/SystemcalendarMapper.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/dal/mysql/systemcalendar/SystemcalendarMapper.java @@ -7,6 +7,7 @@ import com.win.framework.mybatis.core.query.LambdaQueryWrapperX; import com.win.framework.mybatis.core.util.QueryWrapperUtils; import com.win.module.wms.controller.systemcalendar.vo.SystemcalendarExportReqVO; import com.win.module.wms.controller.systemcalendar.vo.SystemcalendarPageReqVO; +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.systemcalendar.SystemcalendarDO; import org.apache.ibatis.annotations.Mapper; @@ -53,5 +54,9 @@ public interface SystemcalendarMapper extends BaseMapperX { default List selectSeniorList(CustomConditions conditions) { return selectList(QueryWrapperUtils.structure(conditions)); } + default SystemcalendarDO selectByModule(String module){ + return selectOne(SystemcalendarDO::getModule, module); + } + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/inventoryinitRequest/InventoryinitRequestMainServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/inventoryinitRequest/InventoryinitRequestMainServiceImpl.java index 77860c83..63cbdf08 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/inventoryinitRequest/InventoryinitRequestMainServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/inventoryinitRequest/InventoryinitRequestMainServiceImpl.java @@ -380,7 +380,7 @@ public class InventoryinitRequestMainServiceImpl implements InventoryinitRequest } //写入数据 if (flag) { - String number = serialNumberApi.generateCode(RuleCodeEnum.PURCHASE_RECEIPT_REQUEST.getCode()); + String number = serialNumberApi.generateCode(RuleCodeEnum.INVENTORY_INITIAL_REQUEST.getCode()); mainDO.setNumber(number); RequestsettingDO requestsettingDO = requestsettingService.selectRequestsettingExist("TransferDeliverRequest"); RequestStatusState requestStatusState = new RequestStatusState(); diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarService.java index 70eb13e3..07c0b2cb 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarService.java @@ -78,6 +78,6 @@ public interface SystemcalendarService { - List importSystemcalendarList(List importTeam, Integer mode, boolean updatePart); + List importSystemcalendarList(List importTeam, Integer mode, boolean updatePart); } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarServiceImpl.java index d437b4ba..ba8b7224 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/systemcalendar/SystemcalendarServiceImpl.java @@ -7,8 +7,11 @@ import com.win.framework.common.exception.ServiceException; 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.BomImportErrorVO; import com.win.module.wms.controller.systemcalendar.vo.*; +import com.win.module.wms.convert.bom.BomConvert; import com.win.module.wms.convert.systemcalendar.SystemcalendarConvert; +import com.win.module.wms.dal.dataobject.bom.BomDO; import com.win.module.wms.dal.dataobject.systemcalendar.SystemcalendarDO; import com.win.module.wms.dal.mysql.systemcalendar.SystemcalendarMapper; import org.springframework.stereotype.Service; @@ -83,53 +86,57 @@ public class SystemcalendarServiceImpl implements SystemcalendarService { public List getSystemcalendarList(SystemcalendarExportReqVO exportReqVO) { return systemcalendarMapper.selectList(exportReqVO); } - public List importSystemcalendarList(List systemcalendars, Integer mode, boolean updatePart) { + + private String validateSystemcalendarImport( SystemcalendarDO systemcalendar ){ + StringBuilder message = new StringBuilder(); + try { + validateSystemcalendarExists(null); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + + try { + validateMoubleExists(systemcalendar.getModule()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateAvailableExists(systemcalendar.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } + public List importSystemcalendarList(List systemcalendars, Integer mode, boolean updatePart) { if (CollUtil.isEmpty(systemcalendars)) { throw exception(SYSTEMCALENDAR_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); systemcalendars.forEach(systemcalendar -> { + SystemcalendarDO SystemcalendarDO = SystemcalendarConvert.INSTANCE.convert(systemcalendar); // 校验,判断是否有不符合的原因 - String massage = ""; - if (mode != null) { - try { - validateSystemcalendarExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - - try { - validateMoubleExists(systemcalendar.getModule()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateAvailableExists(systemcalendar.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - if (StrUtil.isNotEmpty(massage)) { - massage.substring(0, massage.length() - 1); - errorList.add(systemcalendar); - } - if (errorList == null) { - // 判断如果不存在,在进行插入 - SystemcalendarDO existSystemcalendar = null; - if (existSystemcalendar == null && mode != 3) { - systemcalendarMapper.insert(SystemcalendarConvert.INSTANCE.convert(systemcalendar)); - } else if (existSystemcalendar != null && mode != 2) {// 如果存在,判断是否允许更新 - SystemcalendarDO systemcalendarDO = SystemcalendarConvert.INSTANCE.convert(systemcalendar); - systemcalendarDO.setId(existSystemcalendar.getId()); - systemcalendarMapper.updateById(systemcalendarDO); - } + String message = this.validateSystemcalendarImport(SystemcalendarDO); + boolean flag = true; + if(!message.isEmpty()){ + SystemcalendarImportErrorVO importErrorVO = SystemcalendarConvert.INSTANCE.convert2(SystemcalendarDO); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); + errorList.add(importErrorVO); + flag = false; + } + if(flag){ + SystemcalendarDO existSystemcalendar = systemcalendarMapper.selectByModule(SystemcalendarDO.getModule()); + if (existSystemcalendar == null && mode != 3) { + systemcalendarMapper.insert(SystemcalendarConvert.INSTANCE.convert(systemcalendar)); + } else if (existSystemcalendar != null && mode != 2) { + // 如果存在,判断是否允许更新 + SystemcalendarDO systemcalendarDO = SystemcalendarConvert.INSTANCE.convert(systemcalendar); + systemcalendarDO.setId(existSystemcalendar.getId()); + systemcalendarMapper.updateById(systemcalendarDO); } } - }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } + return errorList; } @@ -158,7 +165,16 @@ public class SystemcalendarServiceImpl implements SystemcalendarService { if (mouble == null) { throw exception(SYSTEMCALENDAR_MOUBLE_NOT_EXISTS); } + else { + SystemcalendarDO systemcalendarDO = systemcalendarMapper.selectByModule(mouble); + if(systemcalendarDO!=null){ + throw exception(SYSTEMCALENDAR_MOUBLE_NOT_EXISTS); + } + } } + + + @VisibleForTesting private void validateAvailableExists(String available) { if (available == null) {