From 1c0fe3f0a7bd8978b39b6f9363e6db6b71cb1cfb Mon Sep 17 00:00:00 2001 From: "hongxi.lian" Date: Thu, 30 Nov 2023 15:38:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8F=AD=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wms/controller/shift/ShiftController.java | 3 +- .../shift/vo/ShiftImportErrorVO.java | 63 ++++++++++ .../shift/vo/ShiftImportExcelVo.java | 2 +- .../wms/convert/shift/ShiftConvert.java | 4 + .../wms/service/shift/ShiftService.java | 2 +- .../wms/service/shift/ShiftServiceImpl.java | 114 +++++++++--------- 6 files changed, 130 insertions(+), 58 deletions(-) create mode 100644 win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/vo/ShiftImportErrorVO.java diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/ShiftController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/ShiftController.java index 03f178cb..411a26c9 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/ShiftController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/ShiftController.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.carrier.vo.CarrierRespVO; import com.win.module.wms.controller.itembasic.vo.ItembasicExcelVO; import com.win.module.wms.controller.shift.vo.*; @@ -177,7 +178,7 @@ public class ShiftController { @RequestParam(value = "mode") Integer mode, @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { List list = ExcelUtils.read(file, ShiftImportExcelVo.class); - List errorList = shiftService.importShiftList(list, mode, updatePart); + List errorList = shiftService.importShiftList(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/shift/vo/ShiftImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/vo/ShiftImportErrorVO.java new file mode 100644 index 00000000..0fb68bd7 --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/vo/ShiftImportErrorVO.java @@ -0,0 +1,63 @@ +package com.win.module.wms.controller.shift.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 ShiftImportErrorVO { + + @ExcelProperty("代码") + private String code; + + @ExcelProperty("名称") + private String name; + + @ExcelProperty("描述") + private String description; + + @ExcelProperty(value = "开始时间") + @ColumnWidth(value = 16) + private LocalDateTime beginTime; + + @ExcelProperty(value = "结束时间") + @ColumnWidth(value = 16) + private LocalDateTime entTime; + + @ExcelProperty(value = "生效时间") + @ColumnWidth(value = 16) + private LocalDateTime activeTime; + + @ExcelProperty(value = "失效时间") + @ColumnWidth(value = 16) + private LocalDateTime expireTime; + + @ExcelProperty(value = "备注") + private String remark; + + @ExcelProperty(value = "是否跨天", converter = DictConvert.class) + @DictFormat(DictTypeConstants.TRUE_FALSE) + private String endAtNextDay; + + @ExcelProperty(value = "是否可用", converter = DictConvert.class) + @DictFormat(DictTypeConstants.TRUE_FALSE) + private String available; + + @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/shift/vo/ShiftImportExcelVo.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/vo/ShiftImportExcelVo.java index 782c058e..7b9a67d6 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/vo/ShiftImportExcelVo.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/shift/vo/ShiftImportExcelVo.java @@ -53,7 +53,7 @@ public class ShiftImportExcelVo { @ColumnWidth(value = 16) private LocalDateTime expireTime; - @ExcelProperty(value = "备注") + @ExcelProperty("备注") private String remark; @ExcelProperty(value = "是否跨天", converter = DictConvert.class) diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/shift/ShiftConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/shift/ShiftConvert.java index db78ae04..566f263d 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/shift/ShiftConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/shift/ShiftConvert.java @@ -4,6 +4,8 @@ import java.util.*; 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.shift.vo.ShiftCreateReqVO; import com.win.module.wms.controller.shift.vo.ShiftExcelVO; import com.win.module.wms.controller.shift.vo.ShiftRespVO; @@ -36,4 +38,6 @@ public interface ShiftConvert { ShiftDO convert(ShiftImportExcelVo bean); + ShiftImportErrorVO convert2(ShiftDO bean); + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftService.java index d6eb2bdc..f2ba4f95 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftService.java @@ -84,6 +84,6 @@ public interface ShiftService { */ List getShiftList(ShiftExportReqVO exportReqVO); - List importShiftList(List importTeam, Integer mode, boolean updatePart); + List importShiftList(List importTeam, Integer mode, boolean updatePart); } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftServiceImpl.java index 2bdc4540..ef7af82a 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/shift/ShiftServiceImpl.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.shift.vo.*; +import com.win.module.wms.convert.bom.BomConvert; import com.win.module.wms.convert.shift.ShiftConvert; +import com.win.module.wms.dal.dataobject.bom.BomDO; import com.win.module.wms.dal.dataobject.shift.ShiftDO; import com.win.module.wms.dal.mysql.shift.ShiftMapper; import org.springframework.stereotype.Service; @@ -102,68 +104,70 @@ public class ShiftServiceImpl implements ShiftService { return shiftMapper.selectSenior(conditions); } + private String validateShiftImport( ShiftDO shift ){ + StringBuilder message = new StringBuilder(); + try { + validateShiftExists(null); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateCodeExists(null, shift.getCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateBeginTimeExists(shift.getBeginTime()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateEndTimeExists(shift.getEntTime()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateEndatnextDayExists(shift.getEndAtNextDay()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateAvailableExists(shift.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } - public List importShiftList(List shifts, Integer mode, boolean updatePart) { + + public List importShiftList(List shifts, Integer mode, boolean updatePart) { if (CollUtil.isEmpty(shifts)) { throw exception(SHIFT_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); shifts.forEach(shift -> { - // 校验,判断是否有不符合的原因 - String massage = ""; - if(mode != null) { - try { - validateShiftExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateCodeExists(null, shift.getCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateBeginTimeExists(shift.getBeginTime()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateEndTimeExists(shift.getEntTime()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateEndatnextDayExists(shift.getEndAtNextDay()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateAvailableExists(shift.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - if (StrUtil.isNotEmpty(massage)) { - massage.substring(0, massage.length() - 1); - errorList.add(shift); - } - if (errorList == null) { - - // 判断如果不存在,在进行插入 - ShiftDO existShift = shiftMapper.selectByCode(shift.getCode()); - if (existShift == null && mode != 3) { - shiftMapper.insert(ShiftConvert.INSTANCE.convert(shift)); - } else if (existShift != null && mode != 2) {// 如果存在,判断是否允许更新 - ShiftDO shiftDO = ShiftConvert.INSTANCE.convert(shift); - shiftDO.setId(existShift.getId()); - shiftMapper.updateById(shiftDO); - } - } + ShiftDO shiftDO = ShiftConvert.INSTANCE.convert(shift); + String message = this.validateShiftImport(shiftDO); + boolean flag = true; + if(!message.isEmpty()){ + ShiftImportErrorVO importErrorVO = ShiftConvert.INSTANCE.convert2(shiftDO); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); + errorList.add(importErrorVO); + flag = false; + } + if(flag){ + // 判断如果不存在,在进行插入 + ShiftDO existShift = shiftMapper.selectByCode(shift.getCode()); + if (existShift == null && mode != 3) { + shiftMapper.insert(ShiftConvert.INSTANCE.convert(shift)); + } else if (existShift != null && mode != 2) { + // 如果存在,判断是否允许更新 + shiftDO.setId(existShift.getId()); + shiftMapper.updateById(shiftDO); } + } }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } return errorList; }