diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockInController.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockInController.java index 2327a71ac..1fab1d893 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockInController.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockInController.java @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO; import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService; +import cn.iocoder.yudao.module.erp.service.mold.MoldService; import cn.iocoder.yudao.module.erp.service.product.ErpProductService; import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService; import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService; @@ -47,6 +48,7 @@ import java.util.concurrent.TimeUnit; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @@ -67,6 +69,8 @@ public class ErpStockInController { @Resource private MoldBrandService moldBrandService; + @Resource + private MoldService moldService; @Resource private AdminUserApi adminUserApi; @@ -118,14 +122,25 @@ public class ErpStockInController { List stockInItemList = stockInService.getStockInItemListByInId(id); if (Objects.equals(stockIn.getInType(), "模具入库")) { Map moldMap = moldBrandService.getMoldVOMap( - convertSet(stockInItemList, ErpStockInItemDO::getProductId)); - return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO -> - stockInVO.setItems(BeanUtils.toBean(stockInItemList, ErpStockInRespVO.Item.class, item -> { - ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId()); - item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); - MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName()) - .setProductBarCode(mold.getCode())); - })))); + convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId)); + Map> moldListMap = moldService.getMoldListMapByBrandIds( + convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId)); + return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO -> { + stockInVO.setItems(convertList(stockInItemList, source -> { + ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class); + item.setMoldSetId(source.getMoldSetId()); + item.setMoldSetName(source.getMoldSetName()); + ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId()); + item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); + item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>())); + MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName()) + .setProductName(mold.getName()) + .setProductBarCode(mold.getCode())); + return item; + })); + stockInVO.setMoldSetNames(CollUtil.join(stockInVO.getItems(), ",", ErpStockInRespVO.Item::getMoldSetName)); + stockInVO.setProductNames(stockInVO.getMoldSetNames()); + })); } else { Map productMap = productService.getProductVOMap( convertSet(stockInItemList, ErpStockInItemDO::getProductId)); @@ -172,35 +187,40 @@ public class ErpStockInController { if (CollUtil.isEmpty(pageResult.getList())) { return PageResult.empty(pageResult.getTotal()); } - // 1.1 入库项 List stockInItemList = stockInService.getStockInItemListByInIds( convertSet(pageResult.getList(), ErpStockInDO::getId)); Map> stockInItemMap = convertMultiMap(stockInItemList, ErpStockInItemDO::getInId); - // 1.2 产品信息 Map productMap = productService.getProductVOMap( convertSet(stockInItemList, ErpStockInItemDO::getProductId)); - // 1.3 供应商信息 Map supplierMap = supplierService.getSupplierMap( convertSet(pageResult.getList(), ErpStockInDO::getSupplierId)); - // 1.4 管理员信息 Map userMap = adminUserApi.getUserMap( convertSet(pageResult.getList(), stockIn -> Long.parseLong(stockIn.getCreator()))); - // 1.7 模具信息 Map moldMap = moldBrandService.getMoldVOMap( - convertSet(stockInItemList, ErpStockInItemDO::getProductId)); + convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId)); + Map> moldListMap = moldService.getMoldListMapByBrandIds( + convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId)); - // 2. 开始拼接 return BeanUtils.toBean(pageResult, ErpStockInRespVO.class, stockIn -> { if (Objects.equals(stockIn.getInType(), "模具入库")) { - stockIn.setItems(BeanUtils.toBean(stockInItemMap.get(stockIn.getId()), ErpStockInRespVO.Item.class, - item -> MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName()) - .setProductBarCode(mold.getCode())))); - stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName)); + List itemDOS = stockInItemMap.get(stockIn.getId()); + stockIn.setItems(convertList(itemDOS, source -> { + ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class); + item.setMoldSetId(source.getMoldSetId()); + item.setMoldSetName(source.getMoldSetName()); + item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>())); + MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName()) + .setProductName(mold.getName()) + .setProductBarCode(mold.getCode())); + return item; + })); + stockIn.setMoldSetNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getMoldSetName)); + stockIn.setProductNames(stockIn.getMoldSetNames()); } else { stockIn.setItems(BeanUtils.toBean(stockInItemMap.get(stockIn.getId()), ErpStockInRespVO.Item.class, item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())))); - stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName)); + stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName)); } MapUtils.findAndThen(supplierMap, stockIn.getSupplierId(), supplier -> stockIn.setSupplierName(supplier.getName())); @@ -232,4 +252,14 @@ public class ErpStockInController { return success(buildStockInVOPageResult(pageResult)); } + + @PutMapping("/update-mold-status") + @Operation(summary = "更新模具入库单的状态") + @PreAuthorize("@ss.hasPermission('erp:stock-out:update-status')") + @RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS) + public CommonResult updateMoldStatus(@RequestParam("id") Long id, + @RequestParam("status") Integer status) { + stockInService.updateMoldStatus(id, status); + return success(true); + } } diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java index 3e1400fb0..6bd76683d 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java @@ -9,7 +9,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.ratelimiter.core.annotation.RateLimiter; -import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldRespVO; +import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO; import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutRespVO; @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; +import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService; import cn.iocoder.yudao.module.erp.service.mold.MoldService; import cn.iocoder.yudao.module.erp.service.product.ErpProductService; import cn.iocoder.yudao.module.erp.service.sale.ErpCustomerService; @@ -48,6 +49,7 @@ import java.util.concurrent.TimeUnit; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @@ -66,6 +68,8 @@ public class ErpStockOutController { @Resource private ErpCustomerService customerService; + @Resource + private MoldBrandService moldBrandService; @Resource private MoldService moldService; @@ -98,6 +102,17 @@ public class ErpStockOutController { return success(true); } + + @PutMapping("/update-mold-status") + @Operation(summary = "更新模具出库单的状态") + @PreAuthorize("@ss.hasPermission('erp:stock-out:update-status')") + @RateLimiter(count = 1, timeUnit = TimeUnit.SECONDS) + public CommonResult updateMoldStatus(@RequestParam("id") Long id, + @RequestParam("status") Integer status) { + stockOutService.updateMoldStatus(id, status); + return success(true); + } + @DeleteMapping("/delete") @Operation(summary = "删除其它出库单") @Parameter(name = "ids", description = "编号数组", required = true) @@ -118,15 +133,26 @@ public class ErpStockOutController { } List stockOutItemList = stockOutService.getStockOutItemListByOutId(id); if (Objects.equals(stockOut.getOutType(), "模具出库")) { - Map moldMap = moldService.getMoldVOMap( - convertSet(stockOutItemList, ErpStockOutItemDO::getProductId)); - return success(BeanUtils.toBean(stockOut, ErpStockOutRespVO.class, stockOutVO -> - stockOutVO.setItems(BeanUtils.toBean(stockOutItemList, ErpStockOutRespVO.Item.class, item -> { - ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId()); - item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); - MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName()) - .setProductBarCode(mold.getCode()).setProductUnitName(mold.getUnitName())); - })))); + Map moldMap = moldBrandService.getMoldVOMap( + convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId)); + Map> moldListMap = moldService.getMoldListMapByBrandIds( + convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId)); + return success(BeanUtils.toBean(stockOut, ErpStockOutRespVO.class, stockOutVO -> { + stockOutVO.setItems(convertList(stockOutItemList, source -> { + ErpStockOutRespVO.Item item = BeanUtils.toBean(source, ErpStockOutRespVO.Item.class); + item.setMoldSetId(source.getMoldSetId()); + item.setMoldSetName(source.getMoldSetName()); + ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId()); + item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); + item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>())); + MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName()) + .setProductName(mold.getName()) + .setProductBarCode(mold.getCode())); + return item; + })); + stockOutVO.setMoldSetNames(CollUtil.join(stockOutVO.getItems(), "?", ErpStockOutRespVO.Item::getMoldSetName)); + stockOutVO.setProductNames(stockOutVO.getMoldSetNames()); + })); } else { Map productMap = productService.getProductVOMap( convertSet(stockOutItemList, ErpStockOutItemDO::getProductId)); @@ -172,40 +198,44 @@ public class ErpStockOutController { if (CollUtil.isEmpty(pageResult.getList())) { return PageResult.empty(pageResult.getTotal()); } - // 1.1 出库项 List stockOutItemList = stockOutService.getStockOutItemListByOutIds( convertSet(pageResult.getList(), ErpStockOutDO::getId)); Map> stockOutItemMap = convertMultiMap(stockOutItemList, ErpStockOutItemDO::getOutId); - // 1.2 产品信息 Map productMap = productService.getProductVOMap( convertSet(stockOutItemList, ErpStockOutItemDO::getProductId)); - // 1.3 客户信息 Map customerMap = customerService.getCustomerMap( convertSet(pageResult.getList(), ErpStockOutDO::getCustomerId)); - // 1.5 管理员信息 Map userMap = adminUserApi.getUserMap( convertSet(pageResult.getList(), stockOut -> Long.parseLong(stockOut.getCreator()))); - // 1.6 领料员信息 Map responserMap = adminUserApi.getUserMap( convertSet(pageResult.getList(), ErpStockOutDO::getResponserId)); - // 1.7 模具信息 - Map moldMap = moldService.getMoldVOMap( - convertSet(stockOutItemList, ErpStockOutItemDO::getProductId)); + Map moldMap = moldBrandService.getMoldVOMap( + convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId)); + Map> moldListMap = moldService.getMoldListMapByBrandIds( + convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId)); - // 2. 开始拼接 return BeanUtils.toBean(pageResult, ErpStockOutRespVO.class, stockOut -> { if (Objects.equals(stockOut.getOutType(), "模具出库")) { - stockOut.setItems(BeanUtils.toBean(stockOutItemMap.get(stockOut.getId()), ErpStockOutRespVO.Item.class, - item -> MapUtils.findAndThen(moldMap, item.getProductId(), mold -> item.setProductName(mold.getName()) - .setProductBarCode(mold.getCode()).setProductUnitName(mold.getUnitName())))); - stockOut.setProductNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getProductName)); + List itemDOS = stockOutItemMap.get(stockOut.getId()); + stockOut.setItems(convertList(itemDOS, source -> { + ErpStockOutRespVO.Item item = BeanUtils.toBean(source, ErpStockOutRespVO.Item.class); + item.setMoldSetId(source.getMoldSetId()); + item.setMoldSetName(source.getMoldSetName()); + item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>())); + MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName()) + .setProductName(mold.getName()) + .setProductBarCode(mold.getCode())); + return item; + })); + stockOut.setMoldSetNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getMoldSetName)); + stockOut.setProductNames(stockOut.getMoldSetNames()); } else { stockOut.setItems(BeanUtils.toBean(stockOutItemMap.get(stockOut.getId()), ErpStockOutRespVO.Item.class, item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())))); - stockOut.setProductNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getProductName)); + stockOut.setProductNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getProductName)); } - MapUtils.findAndThen(customerMap, stockOut.getCustomerId(), supplier -> stockOut.setCustomerName(supplier.getName())); + MapUtils.findAndThen(customerMap, stockOut.getCustomerId(), customer -> stockOut.setCustomerName(customer.getName())); MapUtils.findAndThen(userMap, Long.parseLong(stockOut.getCreator()), user -> stockOut.setCreatorName(user.getNickname())); MapUtils.findAndThen(responserMap, stockOut.getResponserId(), user -> stockOut.setResponserName(user.getNickname())); }); diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInRespVO.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInRespVO.java index 21f2773d5..d929b9342 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInRespVO.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInRespVO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; @@ -76,6 +77,9 @@ public class ErpStockInRespVO { @ExcelProperty("产品信息") private String productNames; + @Schema(description = "模具组名称") + private String moldSetNames; + @Data public static class Item { @@ -113,7 +117,10 @@ public class ErpStockInRespVO { private String productUnitName; @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") - private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用 + private BigDecimal stockCount; + + @Schema(description = "子模具详情") + private List moldList; } diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInSaveReqVO.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInSaveReqVO.java index 8d39b99ba..684e14966 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInSaveReqVO.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInSaveReqVO.java @@ -47,10 +47,10 @@ public class ErpStockInSaveReqVO { @Data public static class Item { - @Schema(description = "入库项编号", example = "11756") + @Schema(description = "????????????????", example = "11756") private Long id; - @Schema(description = "模具组 ID(模具入库时传入,兼容旧前端仍可使用 id 传值)", example = "1") + @Schema(description = "??? ID?????????", example = "101") private Long moldSetId; @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") @@ -58,7 +58,6 @@ public class ErpStockInSaveReqVO { private Long warehouseId; @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") - @NotNull(message = "产品编号不能为空") private Long productId; @Schema(description = "产品单价", example = "100.00") diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java index 5a4e00aee..fddfd8ed1 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutRespVO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; @@ -78,6 +79,9 @@ public class ErpStockOutRespVO { @ExcelProperty("产品信息") private String productNames; + @Schema(description = "模具组名字") + private String moldSetNames; + @Schema(description = "计划单Code", example = "随便") private String planCode; @@ -88,6 +92,12 @@ public class ErpStockOutRespVO { @Schema(description = "出库项编号", example = "11756") private Long id; + @Schema(description = "??? ID", example = "1") + private Long moldSetId; + + @Schema(description = "?????", example = "A?") + private String moldSetName; + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") private Long warehouseId; @@ -103,9 +113,7 @@ public class ErpStockOutRespVO { @Schema(description = "备注", example = "随便") private String remark; - // ========== 关联字段 ========== - - @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力") + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "???") private String productName; @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985") private String productBarCode; @@ -113,7 +121,10 @@ public class ErpStockOutRespVO { private String productUnitName; @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") - private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用 + private BigDecimal stockCount; + + @Schema(description = "子模具列表") + private List moldList; } diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutSaveReqVO.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutSaveReqVO.java index b2acb9da6..e2b817b02 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutSaveReqVO.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/out/ErpStockOutSaveReqVO.java @@ -49,22 +49,23 @@ public class ErpStockOutSaveReqVO { @Schema(description = "出库项编号", example = "11756") private Long id; + @Schema(description = "模具组id", example = "101") + private Long moldSetId; + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") -// @NotNull(message = "仓库编号不能为空") private Long warehouseId; - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") - @NotNull(message = "产品编号不能为空") + @Schema(description = "产品id", example = "3113") private Long productId; @Schema(description = "产品单价", example = "100.00") private BigDecimal productPrice; @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") - @NotNull(message = "产品数量不能为空") +// @NotNull(message = "产品数量不能为空") private BigDecimal count; - @Schema(description = "备注", example = "随便") + @Schema(description = "备注", example = "??") private String remark; } diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockOutItemDO.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockOutItemDO.java index baa2d44f3..094d2b33d 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockOutItemDO.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockOutItemDO.java @@ -29,6 +29,8 @@ public class ErpStockOutItemDO extends BaseDO { */ @TableId private Long id; + private Long moldSetId; + private String moldSetName; /** * 出库编号 * diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldService.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldService.java index 0e3598627..890696d59 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldService.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldService.java @@ -105,5 +105,7 @@ public interface MoldService { List getMoldListByIds(Collection ids); + Map> getMoldListMapByBrandIds(Collection brandIds); + } \ No newline at end of file diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldServiceImpl.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldServiceImpl.java index d8363e364..bf8676aed 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldServiceImpl.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/mold/MoldServiceImpl.java @@ -17,6 +17,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.stream.Collectors; import cn.iocoder.yudao.module.common.controller.admin.mold.vo.*; import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -142,5 +143,17 @@ public class MoldServiceImpl implements MoldService { if (ids == null || ids.isEmpty()) { return Collections.emptyList(); } - return moldMapper.selectBatchIds(ids); } + return moldMapper.selectBatchIds(ids); + } + + @Override + public Map> getMoldListMapByBrandIds(Collection brandIds) { + if (CollUtil.isEmpty(brandIds)) { + return Collections.emptyMap(); + } + List moldList = moldMapper.selectList(new LambdaQueryWrapperX() + .inIfPresent(MoldDO::getBrandId, brandIds) + .orderByDesc(MoldDO::getId)); + return moldList.stream().collect(Collectors.groupingBy(MoldDO::getBrandId)); + } } \ No newline at end of file diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInService.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInService.java index da1711fc7..cd41b5b91 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInService.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInService.java @@ -81,4 +81,5 @@ public interface ErpStockInService { */ List getStockInItemListByInIds(Collection inIds); + void updateMoldStatus(Long id, Integer status); } \ No newline at end of file diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java index 0fd9ec689..4696526bd 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO; +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper; @@ -59,6 +60,7 @@ public class ErpStockInServiceImpl implements ErpStockInService { @Resource private ErpProductService productService; + @Resource private ErpWarehouseService warehouseService; @Resource private ErpSupplierService supplierService; @@ -128,111 +130,96 @@ public class ErpStockInServiceImpl implements ErpStockInService { @Transactional(rollbackFor = Exception.class) public void updateStockInStatus(Long id, Integer status,Integer bizType) { boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); - // 1.1 校验存在 ErpStockInDO stockIn = validateStockInExists(id); - // 1.2 校验状态 if (stockIn.getStatus().equals(status)) { throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL); } - // 2. 更新状态 int updateCount = stockInMapper.updateByIdAndStatus(id, stockIn.getStatus(), new ErpStockInDO().setStatus(status)); if (updateCount == 0) { throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL); } - // 3. 变更库存 List stockInItems = stockInItemMapper.selectListByInId(id); - - -// Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_IN.getType() -// : ErpStockRecordBizTypeEnum.OTHER_IN_CANCEL.getType(); - - stockInItems.forEach(stockInItem -> { BigDecimal count = approve ? stockInItem.getCount() : stockInItem.getCount().negate(); if (Objects.equals(stockIn.getInType(), "模具入库")) { - MoldBrandDO moldDO = moldBrandService.getMoldBrand(stockInItem.getProductId()); + MoldBrandDO moldDO = moldBrandService.getMoldBrand(stockInItem.getMoldSetId()); stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( stockInItem.getProductId(), moldDO.getId(), stockInItem.getWarehouseId(), count, ErpStockRecordBizTypeEnum.OTHER_IN.getType(), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime())); } else { ErpProductDO productDO = productService.getProduct(stockInItem.getProductId()); stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( - stockInItem.getProductId(),productDO.getCategoryId(), stockInItem.getWarehouseId(), count, - ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(),status), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime())); - - //更新库存 -// erpStockMapper.updateStockCount(productDO.getId(), stockInItem.getWarehouseId(), stockInItem.getCount()); -// ErpStockDO stock = erpStockMapper.selectByProductIdAndWarehouseId(productDO.getId(), stockInItem.getWarehouseId()); -// stock.setCount(stock.getCount() + 1); -// erpStockMapper.updateById(stock); + stockInItem.getProductId(), productDO.getCategoryId(), stockInItem.getWarehouseId(), count, + ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(), status), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime())); } }); - // 更改状态 if (Objects.equals(stockIn.getInType(), "模具入库")) { for (ErpStockInItemDO item : stockInItems) { - if (item.getProductId() != null) { - MoldBrandDO moldDO = moldBrandService.getMoldBrand(item.getProductId()); - - // 已经在库 + if (item.getMoldSetId() != null) { + MoldBrandDO moldDO = moldBrandService.getMoldBrand(item.getMoldSetId()); if (Objects.equals(moldDO.getStatus(), 1)) { - throw exception(STOCK_ALERADY_IN,moldDO.getCode() + "-" + moldDO.getName()); + throw exception(STOCK_ALERADY_IN, moldDO.getCode() + "-" + moldDO.getName()); } - - moldDO.setStatus(1); // 在库 + moldDO.setStatus(1); moldBrandService.updateMoldBrand(BeanUtils.toBean(moldDO, MoldBrandSaveReqVO.class)); } - } } } private List validateStockInItems(List list,String outType) { if (Objects.equals(outType, "模具入库")) { - // 1.1 校验模具存在 -// List moldList = moldService.validMoldList( -// convertSet(list, ErpStockInSaveReqVO.Item::getProductId)); -// Map moldMap = convertMap(moldList, MoldDO::getId); List moldList = moldBrandService.validMoldList( - convertSet(list, ErpStockInSaveReqVO.Item::getId)); + convertSet(list, ErpStockInSaveReqVO.Item::getMoldSetId)); Map moldMap = convertMap(moldList, MoldBrandDO::getId); - List productList = productService.validProductList( - convertSet(moldList, MoldBrandDO::getProductId)); - Map productMap = convertMap(productList, ErpProductDO::getId); - // 1.2 校验仓库存在 -// warehouseService.validWarehouseList(convertSet( -// list, ErpStockInSaveReqVO.Item::getWarehouseId)); - // 2. 转化为 ErpStockInItemDO 列表 - return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item - .setProductUnitId(productMap.get(item.getProductId()).getUnitId()) - .setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())))); - + return convertList(list, o -> { + MoldBrandDO moldBrand = moldMap.get(o.getMoldSetId()); + return ErpStockInItemDO.builder() + .id(null) + .moldSetId(moldBrand.getId()) + .moldSetName(moldBrand.getName()) + .warehouseId(o.getWarehouseId()) + .productId(moldBrand.getId()) + .productUnitId(null) + .productPrice(o.getProductPrice()) + .count(o.getCount()) + .totalPrice(MoneyUtils.priceMultiply(o.getProductPrice(), o.getCount())) + .remark(o.getRemark()) + .deviceId(o.getDeviceId()) + .build(); + }); } else { - // 1.1 校验产品存在 List productList = productService.validProductList( convertSet(list, ErpStockInSaveReqVO.Item::getProductId)); Map productMap = convertMap(productList, ErpProductDO::getId); - // 1.2 校验仓库存在 warehouseService.validWarehouseList(convertSet( list, ErpStockInSaveReqVO.Item::getWarehouseId)); - // 2. 转化为 ErpStockInItemDO 列表 return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item .setProductUnitId(productMap.get(item.getProductId()).getUnitId()) .setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())))); } - } private void updateStockInItemList(Long id, List newList) { - // 第一步,对比新老数据,获得添加、修改、删除的列表 + boolean moldStockIn = CollUtil.isNotEmpty(newList) + && newList.stream().anyMatch(item -> item.getMoldSetId() != null); + if (moldStockIn) { + stockInItemMapper.deleteByInId(id); + newList.forEach(o -> { + o.setId(null); + o.setInId(id); + }); + stockInItemMapper.insertBatch(newList); + return; + } + List oldList = stockInItemMapper.selectListByInId(id); - List> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 + List> diffList = diffList(oldList, newList, (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); - - // 第二步,批量添加、修改、删除 if (CollUtil.isNotEmpty(diffList.get(0))) { diffList.get(0).forEach(o -> o.setInId(id)); stockInItemMapper.insertBatch(diffList.get(0)); @@ -301,4 +288,11 @@ public class ErpStockInServiceImpl implements ErpStockInService { return stockInItemMapper.selectListByInIds(inIds); } + @Override + public void updateMoldStatus(Long id, Integer status) { + ErpStockInDO stockIn = validateStockInExists(id); + stockIn.setStatus(status); + stockInMapper.updateById(stockIn); + } + } diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutService.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutService.java index f33bb02d5..7c8ff0420 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutService.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutService.java @@ -82,4 +82,5 @@ public interface ErpStockOutService { List getStockOutItemListByOutIds(Collection outIds); List selectByOutType(List outTypes); + void updateMoldStatus(Long id, Integer status); } \ No newline at end of file diff --git a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java index a48904f89..199ff3823 100644 --- a/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java +++ b/yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java @@ -4,15 +4,12 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldSaveReqVO; +import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldBrandSaveReqVO; import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO; -import cn.iocoder.yudao.module.common.dal.mysql.mold.MoldBrandMapper; import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO; -import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO; import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; -import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper; @@ -128,55 +125,42 @@ public class ErpStockOutServiceImpl implements ErpStockOutService { @Transactional(rollbackFor = Exception.class) public void updateStockOutStatus(Long id, Integer status, Integer bizType) { boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); - // 1.1 校验存在 ErpStockOutDO stockOut = validateStockOutExists(id); - // 1.2 校验状态 if (stockOut.getStatus().equals(status)) { throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL); } - // 2. 更新状态 int updateCount = stockOutMapper.updateByIdAndStatus(id, stockOut.getStatus(), new ErpStockOutDO().setStatus(status)); if (updateCount == 0) { throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL); } - // 3. 变更库存 List stockOutItems = stockOutItemMapper.selectListByOutId(id); - -// Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_OUT.getType() -// : ErpStockRecordBizTypeEnum.OTHER_OUT_CANCEL.getType(); stockOutItems.forEach(stockOutItem -> { BigDecimal count = approve ? stockOutItem.getCount().negate() : stockOutItem.getCount(); if (Objects.equals(stockOut.getOutType(), "模具出库")) { - MoldDO moldDO = moldService.getMold(stockOutItem.getProductId()); + MoldBrandDO moldDO = moldBrandService.getMoldBrand(stockOutItem.getMoldSetId()); stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( - stockOutItem.getProductId(),moldDO.getBrandId(), stockOutItem.getWarehouseId(), count, - ErpStockRecordBizTypeEnum.OTHER_OUT.getType(), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(),stockOut.getOutTime())); - + stockOutItem.getProductId(), moldDO.getId(), stockOutItem.getWarehouseId(), count, + ErpStockRecordBizTypeEnum.OTHER_OUT.getType(), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(), stockOut.getOutTime())); } else { ErpProductRespVO product = productService.getProduct(stockOutItem.getProductId()); stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( - stockOutItem.getProductId(),product.getCategoryId(), stockOutItem.getWarehouseId(), count, - ErpStockRecordBizTypeEnum.getTypeByName(stockOut.getOutType(),status), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(),stockOut.getOutTime())); - + stockOutItem.getProductId(), product.getCategoryId(), stockOutItem.getWarehouseId(), count, + ErpStockRecordBizTypeEnum.getTypeByName(stockOut.getOutType(), status), stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(), stockOut.getOutTime())); } }); - - // 更改状态 if (Objects.equals(stockOut.getOutType(), "模具出库")) { for (ErpStockOutItemDO item : stockOutItems) { - if (item.getProductId() != null) { - MoldDO moldDO = moldService.getMold(item.getProductId()); - // 已经出库 + if (item.getMoldSetId() != null) { + MoldBrandDO moldDO = moldBrandService.getMoldBrand(item.getMoldSetId()); if (Objects.equals(moldDO.getStatus(), 3)) { - throw exception(STOCK_ALERADY_OUT,moldDO.getCode() + "-" + moldDO.getName()); + throw exception(STOCK_ALERADY_OUT, moldDO.getCode() + "-" + moldDO.getName()); } - - moldDO.setStatus(3); // 在途 - moldService.updateMold(BeanUtils.toBean(moldDO, MoldSaveReqVO.class)); + moldDO.setStatus(3); + moldBrandService.updateMoldBrand(BeanUtils.toBean(moldDO, MoldBrandSaveReqVO.class)); } } } @@ -184,24 +168,28 @@ public class ErpStockOutServiceImpl implements ErpStockOutService { private List validateStockOutItems(List list,String outType) { if (Objects.equals(outType, "模具出库")) { - // 1.1 校验模具存在 List moldList = moldBrandService.validMoldList( - convertSet(list, ErpStockOutSaveReqVO.Item::getProductId)); + convertSet(list, ErpStockOutSaveReqVO.Item::getMoldSetId)); Map moldMap = convertMap(moldList, MoldBrandDO::getId); - // 1.2 校验仓库存在 -// warehouseService.validWarehouseList(convertSet(list, ErpStockOutSaveReqVO.Item::getWarehouseId)); - // 2. 转化为 ErpStockOutItemDO 列表 - return convertList(list, o -> BeanUtils.toBean(o, ErpStockOutItemDO.class, item -> item -// .setProductUnitId(moldMap.get(item.getProductId()).getUnitId()) - .setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())))); + return convertList(list, o -> { + MoldBrandDO moldBrand = moldMap.get(o.getMoldSetId()); + return ErpStockOutItemDO.builder() + .id(null) + .moldSetId(moldBrand.getId()) + .moldSetName(moldBrand.getName()) + .warehouseId(o.getWarehouseId()) + .productId(moldBrand.getId()) + .productUnitId(null) + .productPrice(o.getProductPrice()) + .count(o.getCount()) + .totalPrice(MoneyUtils.priceMultiply(o.getProductPrice(), o.getCount())) + .remark(o.getRemark()) + .build(); + }); } else { - // 1.1 校验产品存在 List productList = productService.validProductList( convertSet(list, ErpStockOutSaveReqVO.Item::getProductId)); Map productMap = convertMap(productList, ErpProductDO::getId); - // 1.2 校验仓库存在 -// warehouseService.validWarehouseList(convertSet(list, ErpStockOutSaveReqVO.Item::getWarehouseId)); - // 2. 转化为 ErpStockOutItemDO 列表 return convertList(list, o -> BeanUtils.toBean(o, ErpStockOutItemDO.class, item -> item .setProductUnitId(productMap.get(item.getProductId()).getUnitId()) .setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())))); @@ -209,12 +197,21 @@ public class ErpStockOutServiceImpl implements ErpStockOutService { } private void updateStockOutItemList(Long id, List newList) { - // 第一步,对比新老数据,获得添加、修改、删除的列表 + boolean moldStockOut = CollUtil.isNotEmpty(newList) + && newList.stream().anyMatch(item -> item.getMoldSetId() != null); + if (moldStockOut) { + stockOutItemMapper.deleteByOutId(id); + newList.forEach(o -> { + o.setId(null); + o.setOutId(id); + }); + stockOutItemMapper.insertBatch(newList); + return; + } + List oldList = stockOutItemMapper.selectListByOutId(id); - List> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 + List> diffList = diffList(oldList, newList, (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); - - // 第二步,批量添加、修改、删除 if (CollUtil.isNotEmpty(diffList.get(0))) { diffList.get(0).forEach(o -> o.setOutId(id)); stockOutItemMapper.insertBatch(diffList.get(0)); @@ -288,5 +285,12 @@ public class ErpStockOutServiceImpl implements ErpStockOutService { return stockOutMapper.selectByOutType(outTypes); } + @Override + public void updateMoldStatus(Long id, Integer status) { + ErpStockOutDO stockOut = validateStockOutExists(id); + stockOut.setStatus(status); + stockOutMapper.updateById(stockOut); + } + } \ No newline at end of file