diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/asset/AssetApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/asset/AssetApplicationService.java index 893b81c..e406559 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/asset/AssetApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/asset/AssetApplicationService.java @@ -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 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();