From cab76283721fec435bd2495efdb4bc45075f3831 Mon Sep 17 00:00:00 2001 From: shusir <497819738@qq.com> Date: Mon, 9 Mar 2026 11:18:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4=E6=89=B9=E6=AC=A1?= =?UTF-8?q?=E3=80=81=E5=B7=A5=E6=AE=B5=E6=80=BB=E6=95=B0=E9=87=8F=E3=80=81?= =?UTF-8?q?=E9=94=81=E5=AE=9A=E6=95=B0=E9=87=8F=E3=80=81=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MaterialInventoryInboundController.java | 4 +- .../controller/vo/MaterialBatchRespVO.java | 8 +-- .../dal/dataobject/MaterialBatchDO.java | 15 +++-- .../service/MaterialBatchService.java | 10 +++- .../service/MaterialBatchServiceImpl.java | 58 ++++++++++++++----- .../MaterialInventoryInboundServiceImpl.java | 45 +++++--------- .../service/MaterialLifecycleServiceImpl.java | 40 +++++++------ 7 files changed, 104 insertions(+), 76 deletions(-) diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryInboundController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryInboundController.java index de7c1b8d..7073abc7 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryInboundController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialInventoryInboundController.java @@ -48,7 +48,7 @@ public class MaterialInventoryInboundController implements BusinessControllerMar return success(materialInventoryInboundService.createMaterialInventoryInbound(createReqVO)); } - @DeleteMapping("/delete") +// @DeleteMapping("/delete") @Operation(summary = "删除入库") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('qms:material-inventory-inbound:delete')") @@ -57,7 +57,7 @@ public class MaterialInventoryInboundController implements BusinessControllerMar return success(true); } - @DeleteMapping("/delete-list") +// @DeleteMapping("/delete-list") @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除入库") @PreAuthorize("@ss.hasPermission('qms:material-inventory-inbound:delete')") diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java index ee0acb8e..be7005fd 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialBatchRespVO.java @@ -53,14 +53,14 @@ public class MaterialBatchRespVO { @ExcelProperty("批次编号") private String batchNo; - @Schema(description = "初始总数量") - @ExcelProperty("初始总数量") - private BigDecimal initialQuantity; - @Schema(description = "总数量") @ExcelProperty("总数量") private BigDecimal inboundQuantity; + @Schema(description = "可用数量") + @ExcelProperty("可用数量") + private BigDecimal remaineQuantity; + @Schema(description = "退货数量") @ExcelProperty("退货数量") private BigDecimal returnQuantity; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java index 51229bff..c16fba52 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialBatchDO.java @@ -48,16 +48,16 @@ public class MaterialBatchDO extends BusinessBaseDO { */ @TableField("BAT_NO") private String batchNo; - /** - * 初始总数量 - */ - @TableField("INIT_QTY") - private BigDecimal initialQuantity; /** * 总数量 */ @TableField("INB_QTY") private BigDecimal inboundQuantity; + /** + * 可用数量 + */ + @TableField("RMNE_QTY") + private BigDecimal remaineQuantity; /** * 退货数量 */ @@ -73,6 +73,11 @@ public class MaterialBatchDO extends BusinessBaseDO { */ @TableField("INB_END_QTY") private BigDecimal inboundEndQuantity; + /** + * 检定/校准数量 + */ + @TableField("VRFN_QTY") + private BigDecimal verificationQuantity; /** * 锁定数量 */ diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java index d3f2aa76..cfec36c6 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java @@ -101,7 +101,7 @@ public interface MaterialBatchService { * * @param gongDO 批次工段信息 */ - void updateMaterialBatchInbEndQty(MaterialBatchDO gongDO); + void updateById(MaterialBatchDO gongDO); /** * 更新批次工段验收状态 @@ -174,4 +174,12 @@ public interface MaterialBatchService { * @param lockType 锁定类型 */ void lockBatchVerifyCalibrateCount(List batches, LockType lockType); + + /** + * 更新批次检定数量 + * + * @param batches 批次信息 + * @param adjustType 调整类型 + */ + void updateBatchVerifyCalibrateCount(List batches, AdjustType adjustType); } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java index e3c84e83..4e3c0eee 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java @@ -67,7 +67,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { mtrlBat.setBatchNo(sequenceUtil.genCode(MaterialConstants.SEQUENCE_BATCH_KEY)); mtrlBat.setParentId(0L); - mtrlBat.setInitialQuantity(mtrlBat.getInboundQuantity()); + mtrlBat.setRemaineQuantity(mtrlBat.getInboundQuantity()); materialBatchMapper.insert(mtrlBat); // 返回 @@ -85,6 +85,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { // 更新 MaterialBatchDO updateObj = BeanUtils.toBean(updateReqVO, MaterialBatchDO.class); + updateObj.setRemaineQuantity(updateObj.getInboundQuantity()); materialBatchMapper.updateById(updateObj); } @@ -95,11 +96,17 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { if (batchDO == null) throw exception(MATERIAL_BATCH_NOT_EXISTS); if (batchDO.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "批次已经提交,不可删除"); - + // 删除拆分数据 + deleteAssignByBatIds(Collections.singletonList(id)); // 删除 materialBatchMapper.deleteById(id); } + private void deleteAssignByBatIds(List ids) { + materialBatchMapper.delete(Wrappers.lambdaQuery(MaterialBatchDO.class) + .in(MaterialBatchDO::getParentId, ids)); + } + @Transactional @Override public void deleteMaterialBatchListByIds(List ids) { @@ -113,6 +120,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { if (batch.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "存在已经提交的批次,不可删除"); } + deleteAssignByBatIds(ids); // 删除 materialBatchMapper.deleteByIds(ids); } @@ -169,15 +177,14 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { .eq(MaterialBatchDO::getParentId, batId)); if (exists) { // 删除之前的拆分数据 - materialBatchMapper.delete(Wrappers.lambdaQuery(MaterialBatchDO.class) - .eq(MaterialBatchDO::getParentId, batId)); + deleteAssignByBatIds(Collections.singletonList(batId)); } // 3. 保存工段 List gongEts = createReqVOs.stream().map(batAsn -> { MaterialBatchDO bean = BeanUtils.toBean(batAsn, MaterialBatchDO.class); bean.setProductId(mtrlBat.getProductId()).setBatchNo(mtrlBat.getBatchNo()) - .setInitialQuantity(bean.getInboundQuantity()) + .setRemaineQuantity(bean.getInboundQuantity()) .setAcceptanceStatus(MaterialAcceptStatus.not_accepted.name()); return bean; }).toList(); @@ -233,7 +240,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { } @Override - public void updateMaterialBatchInbEndQty(MaterialBatchDO gongDO) { + public void updateById(MaterialBatchDO gongDO) { materialBatchMapper.updateById(gongDO); } @@ -395,7 +402,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { switch (lockType) { case lock -> { BigDecimal lockQuantity = batchDO.getLockQuantity().add(influenceCount); - if (lockQuantity.compareTo(batchDO.getInboundQuantity()) > 0) + if (lockQuantity.compareTo(batchDO.getRemaineQuantity()) > 0) throw new ServiceException(1_032_160_000, "检定数量大于可用数量"); batchDO.setLockQuantity(lockQuantity); } @@ -405,6 +412,28 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { materialBatchMapper.updateBatch(batchDOS); } + @Override + public void updateBatchVerifyCalibrateCount(List batches, AdjustType adjustType) { + List batIds = batches.stream().map(MaterialLifecycleDetailDO::getBatchId).toList(); + List batchDOS = getBatchListByBatchIds(batIds); + Map lifecycleDetailDOMapByBatchId = batches.stream().collect(Collectors.toMap(MaterialLifecycleDetailDO::getBatchId, Function.identity())); + for (MaterialBatchDO batchDO : batchDOS) { + MaterialLifecycleDetailDO detailDO = lifecycleDetailDOMapByBatchId.get(batchDO.getId()); + BigDecimal influenceCount = detailDO.getInfluenceCount(); + switch (adjustType) { + case add -> { + batchDO.setVerificationQuantity(batchDO.getVerificationQuantity().add(influenceCount)); + batchDO.setRemaineQuantity(batchDO.getRemaineQuantity().subtract(influenceCount)); + } + case subtract -> { + batchDO.setVerificationQuantity(batchDO.getVerificationQuantity().subtract(influenceCount)); + batchDO.setRemaineQuantity(batchDO.getRemaineQuantity().add(influenceCount)); + } + } + } + materialBatchMapper.updateBatch(batchDOS); + } + private void lockBatchOrGongReturnExchangeCount(LockType lockType, List batchOrGongDOS, Map lifecycleDetailDOMapByBatOrGongId) { for (MaterialBatchDO batOrGong : batchOrGongDOS) { MaterialLifecycleDetailDO detailDO = lifecycleDetailDOMapByBatOrGongId.get(batOrGong.getId()); @@ -412,7 +441,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { switch (lockType) { case lock -> { BigDecimal lockQuantity = batOrGong.getLockQuantity().add(influenceCount); - if (lockQuantity.compareTo(batOrGong.getInboundQuantity()) > 0) + if (lockQuantity.compareTo(batOrGong.getRemaineQuantity()) > 0) throw new ServiceException(1_032_160_000, "退换货数量大于可用数量"); batOrGong.setLockQuantity(lockQuantity); } @@ -434,16 +463,15 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { BigDecimal replaceQuantity = adjustType == AdjustType.add ? batOrGong.getReplaceQuantity().add(influenceCount) : batOrGong.getReplaceQuantity().subtract(influenceCount); batOrGong.setReplaceQuantity(replaceQuantity); - batOrGong.setInboundQuantity(batOrGong.getInboundQuantity().subtract(replaceQuantity)); } - BigDecimal inboundQuantity = adjustType == AdjustType.add ? batOrGong.getInboundQuantity().subtract(influenceCount) - : batOrGong.getInboundQuantity().add(influenceCount); - if (inboundQuantity.compareTo(BigDecimal.ZERO) < 0) + BigDecimal remaineQuantity = adjustType == AdjustType.add ? batOrGong.getRemaineQuantity().subtract(influenceCount) + : batOrGong.getRemaineQuantity().add(influenceCount); + if (remaineQuantity.compareTo(BigDecimal.ZERO) < 0) throw new ServiceException(1_032_160_000, " 退换货数量大于可用数量"); - if (inboundQuantity.compareTo(batOrGong.getInitialQuantity()) > 0) - throw new ServiceException(1_032_160_000, "批次数量不能大于初始数量"); + if (remaineQuantity.compareTo(batOrGong.getInboundQuantity()) > 0) + throw new ServiceException(1_032_160_000, "批次数量不能大于初始总数量"); - batOrGong.setInboundQuantity(inboundQuantity); + batOrGong.setRemaineQuantity(remaineQuantity); } } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java index 1fefa803..d64b0d6d 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialInventoryInboundServiceImpl.java @@ -1,8 +1,6 @@ package com.zt.plat.module.qms.resource.material.service; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.NumberUtil; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zt.plat.framework.common.exception.ServiceException; import com.zt.plat.framework.common.pojo.CommonResult; import com.zt.plat.framework.common.pojo.PageResult; @@ -11,7 +9,6 @@ import com.zt.plat.framework.security.core.LoginUser; import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; import com.zt.plat.module.qms.common.dic.controller.vo.DictionaryBusinessRespVO; import com.zt.plat.module.qms.common.dic.service.DictionaryBusinessService; -import com.zt.plat.module.qms.core.code.SequenceUtil; import com.zt.plat.module.qms.core.constant.CommonConstant; import com.zt.plat.module.qms.core.constant.DataTypeConstant; import com.zt.plat.module.qms.resource.material.constant.MaterialConstants; @@ -22,9 +19,7 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialInventoryI import com.zt.plat.module.qms.resource.material.dal.dataobject.*; import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialInventoryInboundMapper; import com.zt.plat.module.qms.resource.material.enums.MaterialAcceptStatus; -import com.zt.plat.module.qms.resource.material.enums.MaterialInfomationOrigin; import jakarta.annotation.Resource; -import org.jspecify.annotations.NonNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,7 +27,6 @@ import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -89,29 +83,14 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb if (!MaterialAcceptStatus.accepted.name().equals(gongDO.getAcceptanceStatus())) throw new ServiceException(1_032_160_000, "工段未验收,不能入库"); - // 2. 计算已入库总量并校验 - List inboundDOS = materialInventoryInboundMapper.selectList(Wrappers.lambdaQuery(MaterialInventoryInboundDO.class) - .eq(MaterialInventoryInboundDO::getGongduanId, gongduanId)); - BigDecimal existingQuantity = inboundDOS.stream() - .map(MaterialInventoryInboundDO::getQuantity) - .reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal totalQuantity = existingQuantity.add(reqQuantity); - - // 校验入库数量不超过工段未入库数量 - if (totalQuantity.compareTo(gongDO.getInboundQuantity()) > 0) { - throw new ServiceException(1_032_160_000, "入库数量不能大于批次工段未入库数量"); - } - - // 校验入库数量不超过工段可用数量(考虑锁定数量) - if (gongDO.getLockQuantity().compareTo(BigDecimal.ZERO) > 0) { - BigDecimal availableQuantity = gongDO.getInboundQuantity().subtract(gongDO.getLockQuantity()); - if (totalQuantity.compareTo(availableQuantity) > 0) { - throw new ServiceException(1_032_160_000, "入库数量不能大于批次工段可用数量"); - } - } + // 2. 校验入库数量不超过工段可用数量(考虑锁定数量) + BigDecimal availableQuantity = gongDO.getRemaineQuantity().subtract(gongDO.getLockQuantity()); + if (reqQuantity.compareTo(availableQuantity) > 0) + throw new ServiceException(1_032_160_000, "入库数量不能大于批次工段可用数量"); // 3.保存入库记录 - MaterialInventoryInboundDO inbound = saveInbound(createReqVO, gongDO); + MaterialInventoryInboundDO inbound = getInbound(createReqVO, gongDO); + materialInventoryInboundMapper.insert(inbound); // 4.生成物料实例 Long productId = gongDO.getProductId(); MaterialProductDO product = materialProductService.getMaterialProduct(productId); @@ -124,9 +103,14 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb List infomationDOS = materialInfomationService.saveMaterialInfomationsByBatInb(locationId, reqQuantity, gongduanId, product, batch); // 5.保存入库明细 materialInventoryInboundDetailService.saveInboundDetails(infomationDOS, inbound, batchId, gongduanId); - // 更新工段已入库数量 + // 更新工段已入库数量和可用数量 gongDO.setInboundEndQuantity(gongDO.getInboundEndQuantity().add(reqQuantity)); - materialBatchService.updateMaterialBatchInbEndQty(gongDO); + gongDO.setRemaineQuantity(gongDO.getRemaineQuantity().subtract(reqQuantity)); + materialBatchService.updateById(gongDO); + // 更新批次已入库数量和可用数量 + batch.setInboundEndQuantity(batch.getInboundEndQuantity().add(reqQuantity)); + batch.setRemaineQuantity(batch.getRemaineQuantity().subtract(reqQuantity)); + materialBatchService.updateById(batch); // 更新物料大类预警级别 materialProductService.updateMaterialProductAlarmLevel(Collections.singletonList(productId)); // 返回 @@ -137,7 +121,7 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb return respVO; } - private MaterialInventoryInboundDO saveInbound(MaterialInventoryInboundSaveReqVO createReqVO, MaterialBatchDO gongDO) { + private MaterialInventoryInboundDO getInbound(MaterialInventoryInboundSaveReqVO createReqVO, MaterialBatchDO gongDO) { MaterialInventoryInboundDO inbound = BeanUtils.toBean(createReqVO, MaterialInventoryInboundDO.class); LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); if (loginUser == null) throw exception(USER_NOT_EXISTS); @@ -146,7 +130,6 @@ public class MaterialInventoryInboundServiceImpl implements MaterialInventoryInb .setApplyDepartment(loginUser.getVisitDeptName()).setApplyDepartmentId(loginUser.getVisitDeptId()) .setApplyTime(LocalDateTime.now()) .setRemark(gongDO.getRemark()); - materialInventoryInboundMapper.insert(inbound); return inbound; } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java index 79cb9055..37003af8 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialLifecycleServiceImpl.java @@ -219,12 +219,12 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , // 删除原来的明细 materialLifecycleDetailService.deleteLifecycleDetailListByLfcId(reqId); List oriDetailList = materialLifecycleDetailService.getDetailListByLfcId(reqId); - // 退换货 + // 释放原来退换货资源 boolean isReturnExchangeMaterial = MaterialFlowType.return_material.getName().equals(mtrlLfc.getBusinessType()) || MaterialFlowType.exchange_material.getName().equals(mtrlLfc.getBusinessType()); if (isReturnExchangeMaterial) lockReturnExchangeResources(oriDetailList, LockType.unlock); - // 物料检定 + // 释放原理啊物料检定资源 boolean isVerifyCalibrate = MaterialFlowType.verify_calibrate.getName().equals(mtrlLfc.getBusinessType()); if (isVerifyCalibrate) lockVerifyCalibrateResources(oriDetailList, LockType.unlock); List detailDOS = getLifecycleDetailDOSByBusinessType(detailList, mtrlLfc); @@ -311,9 +311,9 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , for (MaterialLifecycleDetailSaveReqVO reqDetail : reqDetails) { MaterialBatchDO batchDO = batchDOMapById.get(reqDetail.getBatchId()); // 可用数量 - BigDecimal availableQuantity = batchDO.getInboundQuantity().subtract(batchDO.getLockQuantity()); - if (reqDetail.getInfluenceCount().compareTo(availableQuantity) > 0) - throw new ServiceException(1_032_160_000, String.format("检定数量超过了批次【%s】可用数量【%s】", batchDO.getBatchNo(), availableQuantity)); + BigDecimal remaineQuantity = batchDO.getRemaineQuantity(); + if (reqDetail.getInfluenceCount().compareTo(remaineQuantity) > 0) + throw new ServiceException(1_032_160_000, String.format("检定数量超过了批次【%s】可用数量【%s】", batchDO.getBatchNo(), remaineQuantity)); } return reqDetails.stream().map(detail -> { @@ -364,14 +364,9 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , Map gongsMapById = gongs.stream().collect(Collectors.toMap(MaterialBatchDO::getId, Function.identity())); for (MaterialLifecycleDetailSaveReqVO reqGong : reqGongs) { MaterialBatchDO gong = gongsMapById.get(reqGong.getBatchGongduanId()); - BigDecimal inboundQuantity = gong.getInboundQuantity(); - BigDecimal returnQuantity = gong.getReturnQuantity(); - BigDecimal replaceQuantity = gong.getReplaceQuantity(); - BigDecimal inboundEndQuantity = gong.getInboundEndQuantity(); - BigDecimal remaine = inboundQuantity.subtract(returnQuantity).subtract(replaceQuantity).subtract(inboundEndQuantity); - + BigDecimal remaine = gong.getRemaineQuantity(); if (reqGong.getInfluenceCount().compareTo(remaine) > 0) - throw new ServiceException(1_032_160_000, String.format("退换货数量超过了批次工段【%s-%s】剩余量", + throw new ServiceException(1_032_160_000, String.format("退换货数量超过了批次工段【%s-%s】可用数量", gongsMapById.get(reqGong.getBatchGongduanId()).getBatchNo(), gongsMapById.get(reqGong.getBatchGongduanId()).getAssignDepartmentName())); } @@ -393,9 +388,9 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , } Map batchesMapById = batches.stream().collect(Collectors.toMap(MaterialBatchDO::getId, Function.identity())); for (MaterialLifecycleDetailSaveReqVO reqBatch : reqBatches) { - BigDecimal inboundQuantity = batchesMapById.get(reqBatch.getBatchId()).getInboundQuantity(); - if (reqBatch.getInfluenceCount().compareTo(inboundQuantity) > 0) - throw new ServiceException(1_032_160_000, String.format("退换货数量超过了批次【%s】数量", batchesMapById.get(reqBatch.getBatchId()).getBatchNo())); + BigDecimal remaineQuantity = batchesMapById.get(reqBatch.getBatchId()).getRemaineQuantity(); + if (reqBatch.getInfluenceCount().compareTo(remaineQuantity) > 0) + throw new ServiceException(1_032_160_000, String.format("退换货数量超过了批次【%s】可用数量【%s】", batchesMapById.get(reqBatch.getBatchId()).getBatchNo(), remaineQuantity)); } } @@ -538,11 +533,11 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , case verify_calibrate -> { // 检定需要发起检定流程 this.createProcessInstance(lifecycleDO); - // TODO 释放锁定的资源 + // 释放锁定的资源 List detailList = materialLifecycleDetailService.getDetailListByLfcId(id); this.lockVerifyCalibrateResources(detailList, LockType.unlock); - // TODO 更新批次数量 - // this.updateVerifyCalibrateResources(detailList, AdjustType.add); + // 更新批次相关数量 + this.updateVerifyCalibrateResources(detailList, AdjustType.add); } } @@ -551,6 +546,15 @@ public class MaterialLifecycleServiceImpl implements MaterialLifecycleService , return true; } + private void updateVerifyCalibrateResources(List detailList, AdjustType adjustType) { + // 批次 + List batches = detailList.stream().filter(detail -> detail.getBatchId() != null).toList(); + + if (CollUtil.isNotEmpty(batches)) { + materialBatchService.updateBatchVerifyCalibrateCount(batches, adjustType); + } + } + @Override public PageResult getMaterialLifecycleRespVOPage(MaterialLifecyclePageReqVO pageReqVO) { PageResult lifecyclePage = getMaterialLifecyclePage(pageReqVO);