|
@@ -17,7 +17,6 @@ import com.fjhx.common.utils.Assert;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
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.ProductInfo;
|
|
import com.fjhx.item.entity.product.po.ProductStockInfo;
|
|
import com.fjhx.item.entity.product.po.ProductStockInfo;
|
|
import com.fjhx.item.enums.ProductAvailableRecordType;
|
|
import com.fjhx.item.enums.ProductAvailableRecordType;
|
|
@@ -260,87 +259,88 @@ public class ContractFlow extends FlowDelegate {
|
|
* 创建合同产品 物料待采购信息
|
|
* 创建合同产品 物料待采购信息
|
|
*/
|
|
*/
|
|
private void createMaterialWaitPurchase(Contract contract) {
|
|
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<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<>();
|
|
List<SubscribeDetail> subscribeDetailList = new ArrayList<>();
|
|
|
|
|
|
for (ContractProduct contractProduct : contractProductList) {
|
|
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);
|
|
|
|
- //计数需要采购的数量(需采购量 = 安全库存 - (可用库存 - 合同量)若 需采购量<0,则按0算不采购)
|
|
|
|
- BigDecimal subtract = availableQuantity.subtract(multiply);
|
|
|
|
- BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
|
|
|
|
-
|
|
|
|
- //计算可用库存
|
|
|
|
- if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
- //需要采购的数量<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 {
|
|
|
|
- //需要采购的数量>=0 可用库存 = 安全库存
|
|
|
|
- InOutBo inOutBo = new InOutBo();
|
|
|
|
- inOutBo.setProductId(materialId);
|
|
|
|
- inOutBo.setQuantity(stockThreshold);
|
|
|
|
- productInfoService.editAvailableQuantity(Arrays.asList(inOutBo), InOutType.EQ, contractProduct.getId(), ProductAvailableRecordType.SALE_PASS, contract.getCompanyId());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //需要采购的数量大于0生成待采购数据
|
|
|
|
- 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);
|
|
|
|
+ //计数需要采购的数量(需采购量 = 安全库存 - (可用库存 - 合同量)若 需采购量<0,则按0算不采购)
|
|
|
|
+ BigDecimal subtract = availableQuantity.subtract(multiply);
|
|
|
|
+ BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
|
|
|
|
+
|
|
|
|
+ //计算可用库存
|
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
+ //需要采购的数量<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 {
|
|
|
|
+ //需要采购的数量>=0 可用库存 = 安全库存
|
|
|
|
+ InOutBo inOutBo = new InOutBo();
|
|
|
|
+ inOutBo.setProductId(materialId);
|
|
|
|
+ inOutBo.setQuantity(stockThreshold);
|
|
|
|
+ productInfoService.editAvailableQuantity(Arrays.asList(inOutBo), InOutType.EQ, contractProduct.getId(), ProductAvailableRecordType.SALE_PASS, companyId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //需要采购的数量大于0生成待采购数据
|
|
|
|
+ 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);
|
|
subscribeDetailService.saveBatch(subscribeDetailList);
|