|
@@ -187,6 +187,9 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
produceOrderDto.setCode(contract.getCode());
|
|
|
produceOrderDto.setProduceStatus(0);
|
|
|
this.save(produceOrderDto);
|
|
|
+
|
|
|
+ //创建生产任务
|
|
|
+ createOrderDetails(produceOrderDto);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -202,8 +205,8 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
throw new ServiceException("该订单已投产,请勿重复投产!!");
|
|
|
}
|
|
|
|
|
|
- //创建生产任务
|
|
|
- createOrderDetails(productionOrder);
|
|
|
+ //生成待备料
|
|
|
+ createMaterialPreparation(productionOrder);
|
|
|
|
|
|
Date date = new Date();
|
|
|
this.update(q -> q
|
|
@@ -217,7 +220,7 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
/**
|
|
|
* 创建生产任务
|
|
|
*/
|
|
|
- private void createOrderDetails(ProductionOrder produceOrder) {
|
|
|
+ private synchronized void createOrderDetails(ProductionOrder produceOrder) {
|
|
|
Long orderDtoId = produceOrder.getId();
|
|
|
Long contractId = produceOrder.getContractId();
|
|
|
Long companyId = produceOrder.getCompanyId();
|
|
@@ -229,11 +232,6 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
List<ProductionOrderDetail> productionOrderDetailList = new ArrayList<>();
|
|
|
List<ContractProduct> contractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, contractId));
|
|
|
|
|
|
- //获取产品id
|
|
|
- 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>> productBomDetailMap = productBomDetailService.mapKGroup(ProductBomDetail::getProductId, q -> q.in(ProductBomDetail::getProductId, productIds));
|
|
|
-
|
|
|
for (ContractProduct contractProduct : contractProductList) {
|
|
|
ProductionOrderDetail productionOrderDetail = new ProductionOrderDetail();
|
|
|
productionOrderDetail.setProduceOrderId(orderDtoId);
|
|
@@ -245,32 +243,12 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
productionOrderDetail.setProduceStatus(0);
|
|
|
productionOrderDetail.setCompanyId(companyId);
|
|
|
productionOrderDetailList.add(productionOrderDetail);
|
|
|
-
|
|
|
- //创建备料
|
|
|
- Long productId = contractProduct.getProductId();
|
|
|
- ProductInfo productInfo = productInfoMap.get(productId);
|
|
|
- Assert.notEmpty(productInfo, "查询不到产品信息");
|
|
|
-
|
|
|
- List<ProductBomDetail> productBomDetailList = productBomDetailMap.get(productId);
|
|
|
- List<MaterialPreparation> materialPreparationList = new ArrayList<>();
|
|
|
- for (ProductBomDetail bomDetail : productBomDetailList) {
|
|
|
- BigDecimal multiply = bomDetail.getQuantity().multiply(contractProduct.getQuantity());
|
|
|
-
|
|
|
- MaterialPreparation materialPreparation = new MaterialPreparation();
|
|
|
- materialPreparation.setContractId(contractId);
|
|
|
- materialPreparation.setContractDetailId(contractProduct.getId());
|
|
|
- materialPreparation.setProductionOrderId(orderDtoId);
|
|
|
- materialPreparation.setProductionOrderDetailId(productionOrderDetail.getId());
|
|
|
- materialPreparation.setMaterialId(bomDetail.getMaterialId());
|
|
|
- materialPreparation.setQuantity(multiply);
|
|
|
- materialPreparation.setStatus(0);
|
|
|
- materialPreparation.setCompanyId(companyId);
|
|
|
- materialPreparationList.add(materialPreparation);
|
|
|
- }
|
|
|
- materialPreparationService.saveBatch(materialPreparationList);
|
|
|
}
|
|
|
produceOrderDetailService.saveBatch(productionOrderDetailList);
|
|
|
|
|
|
+ List<Long> productIds = productionOrderDetailList.stream().map(ProductionOrderDetail::getProductId).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
//创建生产订单明细
|
|
|
int index = 0;
|
|
|
List<WorkOrder> workOrderList = new ArrayList<>();
|
|
@@ -308,4 +286,49 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
productionTaskProgressService.saveBatch(productionTaskProgressList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建生产备料
|
|
|
+ */
|
|
|
+ private synchronized void createMaterialPreparation(ProductionOrder productionOrder) {
|
|
|
+ Long contractId = productionOrder.getContractId();
|
|
|
+ Long companyId = productionOrder.getCompanyId();
|
|
|
+ //创建生产备料
|
|
|
+ List<ProductionOrderDetail> productionOrderDetailList = produceOrderDetailService.list(q -> q
|
|
|
+ .eq(ProductionOrderDetail::getProduceOrderId, productionOrder.getId())
|
|
|
+ );
|
|
|
+
|
|
|
+ //获取产品id
|
|
|
+ List<Long> productIds = productionOrderDetailList.stream().map(ProductionOrderDetail::getProductId).collect(Collectors.toList());
|
|
|
+ Map<Long, ProductInfo> productInfoMap = productInfoService.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, productIds));
|
|
|
+ Map<Long, List<ProductBomDetail>> productBomDetailMap = productBomDetailService.mapKGroup(ProductBomDetail::getProductId, q -> q.in(ProductBomDetail::getProductId, productIds));
|
|
|
+
|
|
|
+ for (ProductionOrderDetail productionOrderDetail : productionOrderDetailList) {
|
|
|
+ productionOrderDetail.setProduceStatus(1);
|
|
|
+ //创建备料
|
|
|
+ Long productId = productionOrderDetail.getProductId();
|
|
|
+ ProductInfo productInfo = productInfoMap.get(productId);
|
|
|
+ Assert.notEmpty(productInfo, "查询不到产品信息");
|
|
|
+
|
|
|
+ List<ProductBomDetail> productBomDetailList = productBomDetailMap.get(productId);
|
|
|
+ List<MaterialPreparation> materialPreparationList = new ArrayList<>();
|
|
|
+ for (ProductBomDetail bomDetail : productBomDetailList) {
|
|
|
+ BigDecimal multiply = bomDetail.getQuantity().multiply(productionOrderDetail.getQuantity());
|
|
|
+
|
|
|
+ MaterialPreparation materialPreparation = new MaterialPreparation();
|
|
|
+ materialPreparation.setContractId(contractId);
|
|
|
+ materialPreparation.setContractDetailId(productionOrderDetail.getContractDetailId());
|
|
|
+ materialPreparation.setProductionOrderId(productionOrder.getId());
|
|
|
+ materialPreparation.setProductionOrderDetailId(productionOrderDetail.getId());
|
|
|
+ materialPreparation.setMaterialId(bomDetail.getMaterialId());
|
|
|
+ materialPreparation.setQuantity(multiply);
|
|
|
+ materialPreparation.setStatus(0);
|
|
|
+ materialPreparation.setCompanyId(companyId);
|
|
|
+ materialPreparationList.add(materialPreparation);
|
|
|
+ }
|
|
|
+ materialPreparationService.saveBatch(materialPreparationList);
|
|
|
+ }
|
|
|
+
|
|
|
+ produceOrderDetailService.updateBatchById(productionOrderDetailList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|