|
@@ -57,6 +57,7 @@ import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -293,89 +294,83 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
Long companyId = productionOrderDto.getCompanyId();
|
|
|
Long contractId = productionOrderDto.getContractId();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
List<ContractProduct> contractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, contractId));
|
|
|
+ Map<Long, ContractProduct> productMap = contractProductList.stream().collect(Collectors.toMap(ContractProduct::getId, Function.identity()));
|
|
|
|
|
|
|
|
|
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));
|
|
|
-
|
|
|
-
|
|
|
- Map<Long, SubscribeDetail> subscribeDetailMap = new ConcurrentHashMap<>();
|
|
|
-
|
|
|
- for (ContractProduct contractProduct : contractProductList) {
|
|
|
-
|
|
|
- List<ContractProductBom> contractProductBomList = cpBMap.get(contractProduct.getId());
|
|
|
-
|
|
|
- if (ObjectUtil.isEmpty(contractProductBomList)) {
|
|
|
- continue;
|
|
|
+ List<ContractProductBom> cpBList = contractProductBomService.list(q -> q.in(ContractProductBom::getContractProductId, cpIds));
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, InOutBo> inOutBoMap = new ConcurrentHashMap<>();
|
|
|
+ for (ContractProductBom bom : cpBList) {
|
|
|
+ Long materialId = bom.getMaterialId();
|
|
|
+ ContractProduct contractProduct = productMap.get(bom.getContractProductId());
|
|
|
+ BigDecimal multiply = bom.getQuantity().multiply(contractProduct.getQuantity());
|
|
|
+
|
|
|
+
|
|
|
+ InOutBo inOutBo = inOutBoMap.get(materialId);
|
|
|
+ if (ObjectUtil.isEmpty(inOutBo)) {
|
|
|
+ inOutBo.setProductId(materialId);
|
|
|
+ inOutBo.setQuantity(BigDecimal.ZERO);
|
|
|
}
|
|
|
- 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 = subscribeDetailMap.get(materialId);
|
|
|
- if (ObjectUtil.isEmpty(subscribeDetail)) {
|
|
|
- subscribeDetail = new SubscribeDetail();
|
|
|
- subscribeDetail.setProductId(materialId);
|
|
|
- subscribeDetail.setCount(BigDecimal.ZERO);
|
|
|
- subscribeDetail.setStatus(15);
|
|
|
- subscribeDetail.setContractId(contractId);
|
|
|
- subscribeDetail.setDataType(1);
|
|
|
- subscribeDetail.setCompanyId(companyId);
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal count = subscribeDetail.getCount();
|
|
|
- subscribeDetail.setCount(count.add(requiredQuantity));
|
|
|
-
|
|
|
-
|
|
|
- subscribeDetailMap.put(materialId, subscribeDetail);
|
|
|
- }
|
|
|
+ inOutBo.setQuantity(inOutBo.getQuantity().add(multiply));
|
|
|
+ inOutBoMap.put(materialId, inOutBo);
|
|
|
+ }
|
|
|
|
|
|
+ List<Long> materialIds = cpBList.stream().map(ContractProductBom::getMaterialId).collect(Collectors.toList());
|
|
|
+ Map<Long, ProductInfo> materialMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, materialIds));
|
|
|
+
|
|
|
+
|
|
|
+ List<SubscribeDetail> subscribeDetailList = new ArrayList<>();
|
|
|
+ for (InOutBo value : inOutBoMap.values()) {
|
|
|
+ Long materialId = value.getProductId();
|
|
|
+ BigDecimal multiply = value.getQuantity();
|
|
|
+
|
|
|
+ ProductInfo materialInfo = materialMap.get(materialId);
|
|
|
+
|
|
|
+ BigDecimal stockThreshold = materialInfo.getStockThreshold();
|
|
|
+
|
|
|
+ BigDecimal availableQuantity = BigDecimal.ZERO;
|
|
|
+ ProductStockInfo productStockInfo = productStockInfoService.getOne(q -> q.eq(ProductStockInfo::getProductId, materialId).eq(ProductStockInfo::getCompanyId, companyId));
|
|
|
+ if (ObjectUtil.isNotEmpty(productStockInfo)) {
|
|
|
+ availableQuantity = productStockInfo.getAvailableQuantity();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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, contractId, ProductAvailableRecordType.SALE_PASS, companyId);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ InOutBo inOutBo = new InOutBo();
|
|
|
+ inOutBo.setProductId(materialId);
|
|
|
+ inOutBo.setQuantity(stockThreshold);
|
|
|
+ productInfoService.editAvailableQuantity(Arrays.asList(inOutBo), InOutType.EQ, contractId, 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(contractId);
|
|
|
+ subscribeDetail.setDataType(1);
|
|
|
+ subscribeDetail.setCompanyId(companyId);
|
|
|
+ subscribeDetailList.add(subscribeDetail);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- subscribeDetailService.saveBatch(subscribeDetailMap.values());
|
|
|
|
|
|
+
|
|
|
+ subscribeDetailService.saveBatch(subscribeDetailList);
|
|
|
}
|
|
|
|
|
|
|