fix(asset): 添加柜格库存检查逻辑以防止库存不足

在资产审批流程中增加对柜格库存的检查,当商品库存或柜格库存不足时抛出异常。这避免了审批通过后实际库存不足的问题。
This commit is contained in:
dzq 2025-06-07 15:00:55 +08:00
parent d451a93a4e
commit 72fdac0083
1 changed files with 11 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package com.agileboot.domain.asset;
import com.agileboot.common.constant.WeixinConstants;
import com.agileboot.domain.asset.command.PostAssetApprovalCommand;
import com.agileboot.domain.asset.command.PostAssetGoodsCommand;
import com.agileboot.domain.cabinet.cell.db.CabinetCellEntity;
import com.agileboot.domain.cabinet.cell.db.CabinetCellService;
import com.agileboot.domain.qywx.accessToken.AccessTokenApplicationService;
import com.agileboot.domain.qywx.accessToken.db.QyAccessTokenEntity;
import com.agileboot.domain.qywx.api.QywxApiUtil;
@ -40,6 +42,7 @@ public class AssetApplicationService {
private final AccessTokenApplicationService accessTokenApplicationService;
private final QyUserService qyUserService;
private final ApprovalGoodsModelFactory approvalGoodsModelFactory;
private final CabinetCellService cabinetCellService;
public void pushExternalGoods(PostAssetGoodsCommand postAssetGoodsCommand) {
if (postAssetGoodsCommand == null || postAssetGoodsCommand.getGoodsInfoList() == null || postAssetGoodsCommand.getGoodsInfoList().isEmpty()) {
@ -134,6 +137,14 @@ public class AssetApplicationService {
throw new IllegalArgumentException("Insufficient stock");
}
List<CabinetCellEntity> cabinetCellEntities = cabinetCellService.selectByGoodsId(shopGoodsEntity.getGoodsId());
if (cabinetCellEntities == null || cabinetCellEntities.isEmpty()) {
throw new IllegalArgumentException("No cabinet cells found for the goods");
}
Integer totalStock = cabinetCellEntities.stream().map(CabinetCellEntity::getStock).reduce(0, Integer::sum);
if (totalStock < command.getApplyQuantity()) {
throw new IllegalArgumentException("Insufficient stock in cabinet cells");
}
AddApprovalGoodsCommand approvalGoodsCommand = new AddApprovalGoodsCommand();
approvalGoodsCommand.initBaseEntity();