From 00816b42a9861c3cc2f5a0cb1c31338e282028f0 Mon Sep 17 00:00:00 2001 From: "hongxi.lian" Date: Fri, 24 Nov 2023 15:20:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE=20?= =?UTF-8?q?=E7=89=A9=E5=93=81=E5=8C=85=E8=A3=85=E4=BF=A1=E6=81=AF=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ItempackagingController.java | 30 +++-- .../itempackaging/vo/ItempackagingBaseVO.java | 2 + .../vo/ItempackagingImportErrorVO.java | 88 ++++++++++++++ .../vo/ItempackagingImportExcelVO.java | 24 ++-- .../vo/PurchasePlanDetailBaseVO.java | 1 - .../itempackaging/ItempackagingConvert.java | 10 ++ .../itempackaging/ItempackagingService.java | 2 +- .../ItempackagingServiceImpl.java | 113 +++++++++--------- .../PurchasePlanDetailServiceImpl.java | 2 + 9 files changed, 183 insertions(+), 89 deletions(-) create mode 100644 win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingImportErrorVO.java diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/ItempackagingController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/ItempackagingController.java index 5c96af81..ade0b819 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/ItempackagingController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/ItempackagingController.java @@ -8,12 +8,8 @@ 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.itembasic.vo.ItembasicExcelVO; -import com.win.module.wms.controller.itembasic.vo.ItembasicRespVO; import com.win.module.wms.controller.itempackaging.vo.*; -import com.win.module.wms.convert.itembasic.ItembasicConvert; import com.win.module.wms.convert.itempackaging.ItempackagingConvert; -import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.dal.dataobject.itempackaging.ItempackagingDO; import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.service.itempackaging.ItempackagingService; @@ -173,17 +169,17 @@ public class ItempackagingController { String[] uom = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.UOM); mapDropDown.put(1, uom); String[] description = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.UOM); - mapDropDown.put(2, description);; + mapDropDown.put(2, description); String[] altPackUnit1 = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.UOM); - mapDropDown.put(5, altPackUnit1);; + mapDropDown.put(4, altPackUnit1); String[] altPackUnit2 = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.UOM); - mapDropDown.put(7, altPackUnit2);; + mapDropDown.put(6, altPackUnit2); String[] altPackUnit3 = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.UOM); - mapDropDown.put(9, altPackUnit3);; + mapDropDown.put(8, altPackUnit3); String[] altPackUnit4 = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.UOM); - mapDropDown.put(11, altPackUnit4);; + mapDropDown.put(10, altPackUnit4); String[] available = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.TRUE_FALSE); - mapDropDown.put(13, available);; + mapDropDown.put(12, available); // 输出 ExcelUtils.write(response, "物品包装信息导入模板.xls", "物品包装信息列表", ItempackagingImportExcelVO.class, list,mapDropDown); } @@ -196,16 +192,18 @@ public class ItempackagingController { @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") }) @PreAuthorize("@ss.hasPermission('wms:itempackaging: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, ItempackagingImportExcelVO.class); - List errorList = itempackagingService.itempackagingimportDocumentList(list, mode, updatePart); + List errorList = itempackagingService.itempackagingimportDocumentList(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/itempackaging/vo/ItempackagingBaseVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingBaseVO.java index f9a2699f..3281dfdb 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingBaseVO.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingBaseVO.java @@ -1,5 +1,6 @@ package com.win.module.wms.controller.itempackaging.vo; +import com.win.framework.excel.core.annotations.OnlyOne; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -18,6 +19,7 @@ import static com.win.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY public class ItempackagingBaseVO { @Schema(description = "id", example = "id") + @OnlyOne private Long id; @Schema(description = "物品代码", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingImportErrorVO.java new file mode 100644 index 00000000..5c7a2928 --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingImportErrorVO.java @@ -0,0 +1,88 @@ +package com.win.module.wms.controller.itempackaging.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; + + +/** + * 采购索赔申请子 Excel VO + * + * @author 超级管理员 + */ +@Data +@Builder +@ToString(callSuper = true) +public class ItempackagingImportErrorVO { + + + @ExcelProperty("物品代码") + private String itemCode; + + @ExcelProperty(value = "计量单位", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String uom; + + @ExcelProperty(value = "包装单位", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String stdPackUnit; + + @ExcelProperty("包装数量") + private BigDecimal stdPackQty; + + @ExcelProperty(value = "替代包装单位1", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String altPackUnit1; + + @ExcelProperty("替代包装量1") + private BigDecimal altPackQty1; + + @ExcelProperty(value = "替代包装单位2", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String altPackUnit2; + + @ExcelProperty("替代包装量2") + private BigDecimal altPackQty2; + + @ExcelProperty(value = "替代包装单位3", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String altPackUnit3; + + @ExcelProperty("替代包装量3") + private BigDecimal altPackQty3; + + @ExcelProperty(value = "替代包装单位4", converter = DictConvert.class) + @DictFormat(DictTypeConstants.UOM) + private String altPackUnit4; + + @ExcelProperty("替代包装量4") + private BigDecimal altPackQty4; + + @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/controller/itempackaging/vo/ItempackagingImportExcelVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingImportExcelVO.java index 3f2f4c3f..7b4fbc9d 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingImportExcelVO.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/itempackaging/vo/ItempackagingImportExcelVO.java @@ -35,33 +35,33 @@ public class ItempackagingImportExcelVO { @ExcelProperty("包装数量") private BigDecimal stdPackQty; - @ExcelProperty(value = "替代包装单位", converter = DictConvert.class) + @ExcelProperty(value = "替代包装单位1", converter = DictConvert.class) @DictFormat(DictTypeConstants.UOM) private String altPackUnit1; - @ExcelProperty("替代包装量") - private String altPackQty1; + @ExcelProperty("替代包装量1") + private BigDecimal altPackQty1; - @ExcelProperty(value = "替代包装单位", converter = DictConvert.class) + @ExcelProperty(value = "替代包装单位2", converter = DictConvert.class) @DictFormat(DictTypeConstants.UOM) private String altPackUnit2; - @ExcelProperty("替代包装量") - private String altPackQty2; + @ExcelProperty("替代包装量2") + private BigDecimal altPackQty2; - @ExcelProperty(value = "替代包装单位", converter = DictConvert.class) + @ExcelProperty(value = "替代包装单位3", converter = DictConvert.class) @DictFormat(DictTypeConstants.UOM) private String altPackUnit3; - @ExcelProperty("替代包装量") - private String altPackQty3; + @ExcelProperty("替代包装量3") + private BigDecimal altPackQty3; - @ExcelProperty(value = "替代包装单位", converter = DictConvert.class) + @ExcelProperty(value = "替代包装单位4", converter = DictConvert.class) @DictFormat(DictTypeConstants.UOM) private String altPackUnit4; - @ExcelProperty("替代包装量") - private String altPackQty4; + @ExcelProperty("替代包装量4") + private BigDecimal altPackQty4; @ExcelProperty(value = "是否可用", converter = DictConvert.class) @DictFormat(DictTypeConstants.TRUE_FALSE) diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/purchasePlan/vo/PurchasePlanDetailBaseVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/purchasePlan/vo/PurchasePlanDetailBaseVO.java index bc9feb0e..3bfee81b 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/purchasePlan/vo/PurchasePlanDetailBaseVO.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/purchasePlan/vo/PurchasePlanDetailBaseVO.java @@ -40,7 +40,6 @@ public class PurchasePlanDetailBaseVO { private String remark; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "创建时间不能为空") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime createTime; diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/itempackaging/ItempackagingConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/itempackaging/ItempackagingConvert.java index 743879fe..37b47ab1 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/itempackaging/ItempackagingConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/itempackaging/ItempackagingConvert.java @@ -2,8 +2,15 @@ package com.win.module.wms.convert.itempackaging; import com.win.framework.common.pojo.PageResult; import com.win.module.wms.controller.itempackaging.vo.*; +import com.win.module.wms.controller.purchasereceiptRequest.vo.PurchasereceiptRequestMainCreateReqVO; +import com.win.module.wms.controller.purchasereceiptRequest.vo.PurchasereceiptRequestMainExcelVO; +import com.win.module.wms.controller.purchasereceiptRequest.vo.PurchasereceiptRequestMainImportErrorVO; import com.win.module.wms.dal.dataobject.itempackaging.ItempackagingDO; +import com.win.module.wms.dal.dataobject.purchasereceiptRequest.PurchasereceiptRequestDetailDO; +import com.win.module.wms.dal.dataobject.purchasereceiptRequest.PurchasereceiptRequestMainDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import java.util.List; @@ -31,4 +38,7 @@ public interface ItempackagingConvert { List convertList02(List list); ItempackagingDO convert(ItempackagingImportExcelVO itempackaging); + + ItempackagingImportErrorVO convert2(ItempackagingImportExcelVO bean); + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingService.java index 9b69898a..36d799bd 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingService.java @@ -78,7 +78,7 @@ public interface ItempackagingService { */ List getItempackagingList(ItempackagingExportReqVO exportReqVO); - List itempackagingimportDocumentList(List itempackagings, Integer mode, Boolean updatePart); + List itempackagingimportDocumentList(List list , Integer mode, Boolean updatePart); /** * BQ----QIP diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingServiceImpl.java index d0a0f438..6ee8b7c9 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/itempackaging/ItempackagingServiceImpl.java @@ -13,13 +13,11 @@ import com.win.module.wms.convert.itempackaging.ItempackagingConvert; import com.win.module.wms.dal.dataobject.itempackaging.ItempackagingDO; import com.win.module.wms.dal.mysql.itempackaging.ItempackagingMapper; import org.springframework.stereotype.Service; -import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -88,69 +86,65 @@ public class ItempackagingServiceImpl implements ItempackagingService { public PageResult getItempackagingSenior(CustomConditions conditions) { return itempackagingMapper.selectSenior(conditions); } + + private String validateItempackagingImport(ItempackagingDO itempackagingDO) { + StringBuilder message = new StringBuilder(); + try { + validateItempackagingExists(null); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateItemCodeExists(null,itempackagingDO.getItemCode()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateUomExists(itempackagingDO.getUom()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateStdPackUnitExists(itempackagingDO.getStdPackUnit()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateStdPackQtyExists(itempackagingDO.getStdPackQty()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateAvailableExists(itempackagingDO.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } @Override - public List itempackagingimportDocumentList(List itempackagings, Integer mode, Boolean updatePart) { - if (CollUtil.isEmpty(itempackagings)) { + public List itempackagingimportDocumentList(List datas, Integer mode, Boolean updatePart) { + if (CollUtil.isEmpty(datas)) { throw exception(ITEMPACKAGING_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); - itempackagings.forEach(itempackaging -> { - String massage = ""; - // 校验,判断是否有不符合的原因 - if(mode != null){ - try { - validateItempackagingExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateItemCodeExists(null,itempackaging.getItemCode()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateUomExists(itempackaging.getUom()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateStdPackUnitExists(itempackaging.getStdPackUnit()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateStdPackQtyExists(itempackaging.getStdPackQty()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateAvailableExists(itempackaging.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - } - if(StrUtil.isNotEmpty(massage)){ - massage.substring(0,massage.length()-1); - errorList.add(itempackaging); + List errorList = new ArrayList<>(); + datas.forEach(createReqVO -> { + ItempackagingDO itempackagingDO = ItempackagingConvert.INSTANCE.convert(createReqVO); + String message = this.validateItempackagingImport(itempackagingDO); + // 是否有错误数据 + boolean flag = true; + if(!message.isEmpty()){ + ItempackagingImportErrorVO importErrorVO = ItempackagingConvert.INSTANCE.convert2(createReqVO); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); + errorList.add(importErrorVO); + flag = false; } - if(errorList == null){ - // 判断如果不存在,在进行插入 - ItempackagingDO existConfigurationSetting = null; - if (existConfigurationSetting == null&& mode != 3) { - itempackagingMapper.insert(ItempackagingConvert.INSTANCE.convert(itempackaging)); - } - else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新 - ItempackagingDO itempackagingMapperDO = ItempackagingConvert.INSTANCE.convert(itempackaging); - itempackagingMapperDO.setId(existConfigurationSetting.getId()); - itempackagingMapper.updateById(itempackagingMapperDO); - } + //写入数据 + if(flag) { + itempackagingMapper.insert(itempackagingDO); } }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } - return errorList; + return errorList; } private void validateItempackagingForCreateOrUpdate(Long id, String itemCode, String uom, String stdPackUnit, BigDecimal stdPackQty, String available) { @@ -220,6 +214,7 @@ public class ItempackagingServiceImpl implements ItempackagingService { throw exception(ITEMPACKAGING_AVAILABLE_NOT_EXISTS); } } + @Override public ItempackagingDO selectItemPackagingExist(String pitemCode){ QueryWrapper queryWrapper = new QueryWrapper(); diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/purchasePlan/PurchasePlanDetailServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/purchasePlan/PurchasePlanDetailServiceImpl.java index 95420fcf..189bcfdf 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/purchasePlan/PurchasePlanDetailServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/purchasePlan/PurchasePlanDetailServiceImpl.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; +import java.time.LocalDateTime; import java.util.*; import com.win.module.wms.dal.dataobject.purchasePlan.PurchasePlanDetailDO; @@ -36,6 +37,7 @@ public class PurchasePlanDetailServiceImpl implements PurchasePlanDetailService public Long createPurchasePlanDetail(PurchasePlanDetailCreateReqVO createReqVO) { // 插入 PurchasePlanDetailDO purchasePlanDetail = PurchasePlanDetailConvert.INSTANCE.convert(createReqVO); + purchasePlanDetail.setCreateTime(LocalDateTime.now()); purchasePlanDetailMapper.insert(purchasePlanDetail); // 返回 return purchasePlanDetail.getId();