|
@@ -17,7 +17,6 @@ import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
-import com.fjhx.item.entity.product.po.ProductBomDetail;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.entity.product.po.ProductStockInfo;
|
|
|
import com.fjhx.item.enums.ProductAvailableRecordType;
|
|
@@ -260,87 +259,88 @@ public class ContractFlow extends FlowDelegate {
|
|
|
* 创建合同产品 物料待采购信息
|
|
|
*/
|
|
|
private void createMaterialWaitPurchase(Contract contract) {
|
|
|
+
|
|
|
+ Long companyId = contract.getCompanyId();
|
|
|
+ SysDept company = deptService.getById(companyId);
|
|
|
+ if (ObjectUtil.isEmpty(company)) {
|
|
|
+ throw new ServiceException("归属公司不存在");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
List<ContractProduct> contractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, contract.getId()));
|
|
|
- List<Long> productIds = contractProductList.stream().map(ContractProduct::getProductId).collect(Collectors.toList());
|
|
|
-
|
|
|
- Map<Long, ProductInfo> productInfoMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, productIds));
|
|
|
-
|
|
|
- Map<Long, List<ProductBomDetail>> productBomMap = productBomDetailService.mapKGroup(ProductBomDetail::getProductId, q -> q.in(ProductBomDetail::getProductId, productIds));
|
|
|
+
|
|
|
+
|
|
|
+ List<Long> cpIds = contractProductList.stream().map(ContractProduct::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<ContractProductBom>> cpBMap = contractProductBomService.mapKGroup(ContractProductBom::getContractProductId,
|
|
|
+ q -> q.in(ContractProductBom::getContractProductId, cpIds)
|
|
|
+ );
|
|
|
|
|
|
|
|
|
List<SubscribeDetail> subscribeDetailList = new ArrayList<>();
|
|
|
|
|
|
for (ContractProduct contractProduct : contractProductList) {
|
|
|
- Long productId = contractProduct.getProductId();
|
|
|
- ProductInfo productInfo = productInfoMap.get(productId);
|
|
|
-
|
|
|
|
|
|
- List<ProductBomDetail> productBomDetails = productBomMap.get(productId);
|
|
|
-
|
|
|
- if (ObjectUtil.isNotEmpty(productBomDetails)) {
|
|
|
- List<Long> materialIds = productBomDetails.stream().map(ProductBomDetail::getMaterialId).collect(Collectors.toList());
|
|
|
- Map<Long, ProductInfo> materialMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, materialIds));
|
|
|
-
|
|
|
-
|
|
|
- Map<Long, BigDecimal> availableQuantityMap = productStockInfoService.mapKV(ProductStockInfo::getId, ProductStockInfo::getAvailableQuantity, q -> q
|
|
|
- .in(ProductStockInfo::getProductId, materialIds)
|
|
|
- .eq(ProductStockInfo::getCompanyId, contract.getCompanyId())
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- for (ProductBomDetail productBomDetail : productBomDetails) {
|
|
|
- Long materialId = productBomDetail.getMaterialId();
|
|
|
- ProductInfo materialInfo = materialMap.get(materialId);
|
|
|
-
|
|
|
- BigDecimal multiply = productBomDetail.getQuantity().multiply(contractProduct.getQuantity());
|
|
|
-
|
|
|
-
|
|
|
- BigDecimal stockThreshold = materialInfo.getStockThreshold();
|
|
|
-
|
|
|
- BigDecimal availableQuantity = availableQuantityMap.getOrDefault(materialId, BigDecimal.ZERO);
|
|
|
-
|
|
|
- BigDecimal subtract = availableQuantity.subtract(multiply);
|
|
|
- BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
|
|
|
-
|
|
|
-
|
|
|
- if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
-
|
|
|
- InOutBo inOutBo = new InOutBo();
|
|
|
- inOutBo.setProductId(materialId);
|
|
|
- inOutBo.setQuantity(multiply);
|
|
|
- productInfoService.editAvailableQuantity(Arrays.asList(inOutBo), InOutType.OUT, contractProduct.getId(), ProductAvailableRecordType.SALE_PASS, contract.getCompanyId());
|
|
|
- } else {
|
|
|
-
|
|
|
- InOutBo inOutBo = new InOutBo();
|
|
|
- inOutBo.setProductId(materialId);
|
|
|
- inOutBo.setQuantity(stockThreshold);
|
|
|
- productInfoService.editAvailableQuantity(Arrays.asList(inOutBo), InOutType.EQ, contractProduct.getId(), ProductAvailableRecordType.SALE_PASS, contract.getCompanyId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- SubscribeDetail subscribeDetail = new SubscribeDetail();
|
|
|
- subscribeDetail.setProductId(materialId);
|
|
|
- subscribeDetail.setCount(requiredQuantity);
|
|
|
- subscribeDetail.setStatus(15);
|
|
|
- subscribeDetail.setContractId(contract.getId());
|
|
|
- subscribeDetail.setContractDetailId(contractProduct.getId());
|
|
|
- subscribeDetail.setDataType(1);
|
|
|
-
|
|
|
- subscribeDetailList.add(subscribeDetail);
|
|
|
- }
|
|
|
+ List<ContractProductBom> contractProductBomList = cpBMap.get(contractProduct.getId());
|
|
|
|
|
|
+ if (ObjectUtil.isEmpty(contractProductBomList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<Long> materialIds = contractProductBomList.stream().map(ContractProductBom::getMaterialId).collect(Collectors.toList());
|
|
|
+ Map<Long, ProductInfo> materialMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, materialIds));
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> availableQuantityMap = productStockInfoService.mapKV(ProductStockInfo::getId, ProductStockInfo::getAvailableQuantity, q -> q
|
|
|
+ .in(ProductStockInfo::getProductId, materialIds)
|
|
|
+ .eq(ProductStockInfo::getCompanyId, companyId)
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (ContractProductBom productBomDetail : contractProductBomList) {
|
|
|
+ Long materialId = productBomDetail.getMaterialId();
|
|
|
+ ProductInfo materialInfo = materialMap.get(materialId);
|
|
|
+
|
|
|
+ BigDecimal multiply = productBomDetail.getQuantity().multiply(contractProduct.getQuantity());
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal stockThreshold = materialInfo.getStockThreshold();
|
|
|
+
|
|
|
+ BigDecimal availableQuantity = availableQuantityMap.getOrDefault(materialId, BigDecimal.ZERO);
|
|
|
+
|
|
|
+ BigDecimal subtract = availableQuantity.subtract(multiply);
|
|
|
+ BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
|
|
|
+
|
|
|
+
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+
|
|
|
+ InOutBo inOutBo = new InOutBo();
|
|
|
+ inOutBo.setProductId(materialId);
|
|
|
+ inOutBo.setQuantity(multiply);
|
|
|
+ productInfoService.editAvailableQuantity(Arrays.asList(inOutBo), InOutType.OUT, contractProduct.getId(), ProductAvailableRecordType.SALE_PASS, companyId);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ InOutBo inOutBo = new InOutBo();
|
|
|
+ inOutBo.setProductId(materialId);
|
|
|
+ inOutBo.setQuantity(stockThreshold);
|
|
|
+ productInfoService.editAvailableQuantity(Arrays.asList(inOutBo), InOutType.EQ, contractProduct.getId(), ProductAvailableRecordType.SALE_PASS, companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ SubscribeDetail subscribeDetail = new SubscribeDetail();
|
|
|
+ subscribeDetail.setProductId(materialId);
|
|
|
+ subscribeDetail.setCount(requiredQuantity);
|
|
|
+ subscribeDetail.setStatus(15);
|
|
|
+ subscribeDetail.setContractId(contract.getId());
|
|
|
+ subscribeDetail.setContractDetailId(contractProduct.getId());
|
|
|
+ subscribeDetail.setDataType(1);
|
|
|
+ subscribeDetail.setCompanyId(companyId);
|
|
|
+
|
|
|
+ subscribeDetailList.add(subscribeDetail);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- Long companyId = contract.getCompanyId();
|
|
|
- SysDept company = deptService.getById(companyId);
|
|
|
- if (ObjectUtil.isEmpty(companyId)) {
|
|
|
- throw new ServiceException("归属公司不存在");
|
|
|
}
|
|
|
|
|
|
subscribeDetailService.saveBatch(subscribeDetailList);
|