|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.entity.AvailableStockBo;
|
|
@@ -375,12 +376,8 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
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<>();
|
|
|
-
|
|
|
//获取待采购物料列表
|
|
|
List<AvailableStockBo> collect = inOutBoMap.values().stream().collect(Collectors.toList());
|
|
|
//操作可用库存计数需要采购量
|
|
@@ -401,11 +398,136 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
subscribeDetailList.add(subscribeDetail);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//保存待采购明细
|
|
|
subscribeDetailService.saveBatch(subscribeDetailList);
|
|
|
}
|
|
|
|
|
|
+ void updateMaterialWaitPurchase(Long newContractId) {
|
|
|
+ Contract newContract = contractService.getById(newContractId);
|
|
|
+ Long oldContractId = newContract.getOldContractId();
|
|
|
+ Long companyId = newContract.getCompanyId();
|
|
|
+ //---------------------------------------------------------------
|
|
|
+ List<ContractProductBomVo> oldProductBomListSum = contractProductBomService.getContractProductBomQuantitySum(oldContractId);
|
|
|
+
|
|
|
+ //获取新合同物料数量Map
|
|
|
+ List<ContractProductBomVo> contractProductBomQuantitySum = contractProductBomService.getContractProductBomQuantitySum(newContractId);
|
|
|
+ Map<Long, BigDecimal> newQuantityMap = contractProductBomQuantitySum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
|
|
|
+
|
|
|
+
|
|
|
+ List<AvailableStockBo> availableStockBoList = new ArrayList<>();
|
|
|
+
|
|
|
+ //获取已采购数量
|
|
|
+ List<EhsdPurchaseProductVo> purchaseQuantitySumByContractId = ehsdPurchaseProductMapper.getPurchaseQuantitySumByContractId(newContractId);
|
|
|
+ Map<Long, BigDecimal> collect = purchaseQuantitySumByContractId.stream().collect(Collectors.toMap(EhsdPurchaseProduct::getProductId, EhsdPurchaseProduct::getQuantity));
|
|
|
+
|
|
|
+ //旧数据处理
|
|
|
+ for (ContractProductBomVo oldContractProductBom : oldProductBomListSum) {
|
|
|
+ Long materialId = oldContractProductBom.getMaterialId();
|
|
|
+
|
|
|
+ //新数量
|
|
|
+ BigDecimal newQuantity = newQuantityMap.get(materialId);
|
|
|
+ //已采购数量
|
|
|
+ BigDecimal purchaseQuantity = collect.getOrDefault(materialId, BigDecimal.ZERO);
|
|
|
+
|
|
|
+ //获取原需采购量
|
|
|
+ SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q
|
|
|
+ .eq(SubscribeDetail::getContractId, newContractId)
|
|
|
+ .eq(SubscribeDetail::getProductId, materialId)
|
|
|
+ );
|
|
|
+ BigDecimal demandPurchaseCount = BigDecimal.ZERO;
|
|
|
+ if (ObjectUtils.isNotEmpty(subscribeDetail)) {
|
|
|
+ demandPurchaseCount = subscribeDetail.getCount();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //生成操作可用库存的实体
|
|
|
+ AvailableStockBo availableStockBo = new AvailableStockBo();
|
|
|
+ availableStockBo.setProductId(materialId);
|
|
|
+ availableStockBo.setQuantity(oldContractProductBom.getQuantity());
|
|
|
+ availableStockBo.setNewQuantity(newQuantity);
|
|
|
+ availableStockBo.setInStockQuantity(purchaseQuantity);
|
|
|
+ availableStockBo.setDemandPurchaseCount(demandPurchaseCount);
|
|
|
+
|
|
|
+ availableStockBoList.add(availableStockBo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //新添加的数据处理
|
|
|
+ Map<Long, BigDecimal> oldQuantityMap = oldProductBomListSum.stream().collect(Collectors.toMap(ContractProductBom::getMaterialId, ContractProductBom::getQuantity));
|
|
|
+ for (ContractProductBomVo newPurchaseProduct : contractProductBomQuantitySum) {
|
|
|
+ Long materialId = newPurchaseProduct.getMaterialId();
|
|
|
+
|
|
|
+ BigDecimal bigDecimal = oldQuantityMap.get(materialId);
|
|
|
+ //忽略掉变更前有的物料
|
|
|
+ if (ObjectUtils.isNotEmpty(bigDecimal)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成操作可用库存的实体
|
|
|
+ AvailableStockBo availableStockBo = new AvailableStockBo();
|
|
|
+ availableStockBo.setProductId(materialId);
|
|
|
+ availableStockBo.setQuantity(BigDecimal.ZERO);
|
|
|
+ availableStockBo.setNewQuantity(newPurchaseProduct.getQuantity());
|
|
|
+ availableStockBo.setInStockQuantity(BigDecimal.ZERO);
|
|
|
+ availableStockBo.setDemandPurchaseCount(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ availableStockBoList.add(availableStockBo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //修改可用库存
|
|
|
+ productInfoService.editAvailableQuantity(availableStockBoList, newContractId, ProductAvailableRecordType.SALE_UPDATE, companyId);
|
|
|
+
|
|
|
+
|
|
|
+ //修该待采购量为需采购量
|
|
|
+ for (AvailableStockBo availableStockBo : availableStockBoList) {
|
|
|
+
|
|
|
+ Long materialId = availableStockBo.getProductId();
|
|
|
+ SubscribeDetail subscribeDetail = subscribeDetailService.getOne(q -> q.eq(SubscribeDetail::getContractId, newContractId)
|
|
|
+ .eq(SubscribeDetail::getProductId, materialId)
|
|
|
+ );
|
|
|
+
|
|
|
+ BigDecimal requiredQuantity = availableStockBo.getNewQuantity();
|
|
|
+
|
|
|
+
|
|
|
+ //需采购量>0
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (ObjectUtils.isEmpty(subscribeDetail)) {
|
|
|
+ //生成待采购
|
|
|
+ subscribeDetail = new SubscribeDetail();
|
|
|
+ subscribeDetail.setProductId(materialId);
|
|
|
+ subscribeDetail.setCount(BigDecimal.ZERO);
|
|
|
+ subscribeDetail.setStatus(15);//待采购
|
|
|
+ subscribeDetail.setContractId(newContractId);
|
|
|
+ subscribeDetail.setDataType(1);
|
|
|
+ subscribeDetail.setCompanyId(companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改待采购量
|
|
|
+ subscribeDetail.setCount(requiredQuantity);
|
|
|
+
|
|
|
+ //计算状态
|
|
|
+ BigDecimal purchaseQuantity = availableStockBo.getInStockQuantity();
|
|
|
+ int status = purchaseQuantity.compareTo(requiredQuantity) >= 0 ? 20 : 30;
|
|
|
+ if (purchaseQuantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ status = 15;
|
|
|
+ }
|
|
|
+ subscribeDetail.setStatus(status);
|
|
|
+
|
|
|
+ subscribeDetailService.saveOrUpdate(subscribeDetail);
|
|
|
+ } else {
|
|
|
+ //需采购==0不显示或删除,<不存在
|
|
|
+ if (ObjectUtils.isNotEmpty(subscribeDetail)) {
|
|
|
+ subscribeDetailService.removeById(subscribeDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //---------------------------------------------------------------
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建生产任务
|
|
|
*/
|
|
@@ -421,19 +543,49 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
List<ProductionOrderDetail> productionOrderDetailList = new ArrayList<>();
|
|
|
List<ContractProduct> contractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, contractId));
|
|
|
|
|
|
+ //将被删除的任务作废
|
|
|
+ List<Long> cpIds = contractProductList.stream().map(ContractProduct::getId).collect(Collectors.toList());
|
|
|
+ produceOrderDetailService.update(q -> q
|
|
|
+ .eq(ProductionOrderDetail::getProduceOrderId, orderDtoId)
|
|
|
+ .eq(ProductionOrderDetail::getContractId, contractId)
|
|
|
+ .notIn(ProductionOrderDetail::getContractDetailId, cpIds)
|
|
|
+ .set(ProductionOrderDetail::getProduceStatus, 99)
|
|
|
+ );
|
|
|
+
|
|
|
for (ContractProduct contractProduct : contractProductList) {
|
|
|
- ProductionOrderDetail productionOrderDetail = new ProductionOrderDetail();
|
|
|
+ ProductionOrderDetail productionOrderDetail = produceOrderDetailService.getOne(q -> q
|
|
|
+ .eq(ProductionOrderDetail::getProduceOrderId, orderDtoId)
|
|
|
+ .eq(ProductionOrderDetail::getContractId, contractId)
|
|
|
+ .eq(ProductionOrderDetail::getContractDetailId, contractProduct.getId())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(productionOrderDetail)) {
|
|
|
+ productionOrderDetail = new ProductionOrderDetail();
|
|
|
+ productionOrderDetail.setFinishQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
productionOrderDetail.setProduceOrderId(orderDtoId);
|
|
|
productionOrderDetail.setContractId(contractId);
|
|
|
productionOrderDetail.setContractDetailId(contractProduct.getId());
|
|
|
productionOrderDetail.setProductId(contractProduct.getProductId());
|
|
|
productionOrderDetail.setQuantity(contractProduct.getQuantity());
|
|
|
- productionOrderDetail.setFinishQuantity(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ //修改状态
|
|
|
+ if (productionOrderDetail.getFinishQuantity().compareTo(productionOrderDetail.getQuantity()) >= 0) {
|
|
|
+ //生产完成
|
|
|
+ productionOrderDetail.setProduceStatus(2);
|
|
|
+ } else {
|
|
|
+ //进行中
|
|
|
+ productionOrderDetail.setProduceStatus(1);
|
|
|
+ }
|
|
|
+ if (productionOrderDetail.getFinishQuantity().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ //未开始
|
|
|
+ productionOrderDetail.setProduceStatus(0);
|
|
|
+ }
|
|
|
+
|
|
|
productionOrderDetail.setProduceStatus(0);
|
|
|
productionOrderDetail.setCompanyId(companyId);
|
|
|
productionOrderDetailList.add(productionOrderDetail);
|
|
|
}
|
|
|
- produceOrderDetailService.saveBatch(productionOrderDetailList);
|
|
|
+ produceOrderDetailService.saveOrUpdateBatch(productionOrderDetailList);
|
|
|
|
|
|
List<Long> productIds = productionOrderDetailList.stream().map(ProductionOrderDetail::getProductId).collect(Collectors.toList());
|
|
|
|
|
@@ -444,21 +596,31 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
for (ProductionOrderDetail productionOrderDetail : productionOrderDetailList) {
|
|
|
List<ProductionProcessesVo> productionProcessesVos = processesMap.getOrDefault(productionOrderDetail.getProductId(), new ArrayList<>());
|
|
|
for (ProductionProcessesVo productionProcessesVo : productionProcessesVos) {
|
|
|
- ProductionTaskProgress prodTaskProgress = new ProductionTaskProgress();
|
|
|
+ ProductionTaskProgress prodTaskProgress = productionTaskProgressService.getOne(q -> q
|
|
|
+ .eq(ProductionTaskProgress::getTaskId, productionOrderDetail.getId())
|
|
|
+ .eq(ProductionTaskProgress::getProcessesId, productionProcessesVo.getId())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(prodTaskProgress)) {
|
|
|
+ prodTaskProgress = new ProductionTaskProgress();
|
|
|
+ prodTaskProgress.setFinishQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
prodTaskProgress.setTaskId(productionOrderDetail.getId());
|
|
|
prodTaskProgress.setProcessesId(productionProcessesVo.getId());
|
|
|
- prodTaskProgress.setFinishQuantity(BigDecimal.ZERO);
|
|
|
|
|
|
//如果是第一道工序,结存数量直接等于任务数量
|
|
|
prodTaskProgress.setBalanceQuantity(BigDecimal.ZERO);
|
|
|
if (ObjectUtil.equals(productionProcessesVo.getSourceProcessesId(), 1L)) {
|
|
|
- prodTaskProgress.setBalanceQuantity(productionOrderDetail.getQuantity());
|
|
|
+ BigDecimal balanceQuantity = prodTaskProgress.getFinishQuantity().subtract(productionOrderDetail.getQuantity());
|
|
|
+ if (balanceQuantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ balanceQuantity = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ prodTaskProgress.setBalanceQuantity(balanceQuantity);
|
|
|
}
|
|
|
|
|
|
productionTaskProgressList.add(prodTaskProgress);
|
|
|
}
|
|
|
}
|
|
|
- productionTaskProgressService.saveBatch(productionTaskProgressList);
|
|
|
+ productionTaskProgressService.saveOrUpdateBatch(productionTaskProgressList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -488,18 +650,29 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
for (ContractProductBom bomDetail : contractProductBomList) {
|
|
|
BigDecimal multiply = bomDetail.getQuantity().multiply(productionOrderDetail.getQuantity());
|
|
|
|
|
|
- MaterialPreparation materialPreparation = new MaterialPreparation();
|
|
|
+ MaterialPreparation materialPreparation = materialPreparationService.getOne(q -> q
|
|
|
+ .eq(MaterialPreparation::getProductionOrderDetailId, productionOrderDetail.getId())
|
|
|
+ .eq(MaterialPreparation::getMaterialId, bomDetail.getMaterialId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(materialPreparation)) {
|
|
|
+ materialPreparation = new MaterialPreparation();
|
|
|
+ materialPreparation.setStatus(0);
|
|
|
+ } else {
|
|
|
+ if (materialPreparation.getQuantity().compareTo(multiply) != 0 && materialPreparation.getStatus() == 1) {
|
|
|
+ materialPreparation.setStatus(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
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);
|
|
|
+ materialPreparationService.saveOrUpdateBatch(materialPreparationList);
|
|
|
}
|
|
|
|
|
|
produceOrderDetailService.updateBatchById(productionOrderDetailList);
|
|
@@ -531,8 +704,13 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
msg.put("business_id", productionOrder.getId());
|
|
|
WebSocketPush.byUser(PushTypeEnum.MESSAGE, productionOrder.getCreateUser(), title, PushBusinessTypeEnum.PRODUCTION_ORDER_REJECT.getType(), msg.toString());
|
|
|
} else {
|
|
|
- //创建待采购
|
|
|
- createMaterialWaitPurchase(productionOrder);
|
|
|
+ if (produceOrderDetailService.count(q -> q.eq(ProductionOrderDetail::getProduceOrderId, dto.getId())) > 0) {
|
|
|
+ //创建待采购
|
|
|
+ createMaterialWaitPurchase(productionOrder);
|
|
|
+ } else {
|
|
|
+ //修改待采购
|
|
|
+ updateMaterialWaitPurchase(productionOrder.getContractId());
|
|
|
+ }
|
|
|
|
|
|
//创建生产任务
|
|
|
createOrderDetails(productionOrder);
|
|
@@ -557,28 +735,47 @@ public class ProduceOrderServiceImpl extends ServiceImpl<ProduceOrderMapper, Pro
|
|
|
|
|
|
private void createStockWait(ProductionOrder productionOrder) {
|
|
|
//生成待出库
|
|
|
- StockWait stockWait = new StockWait();
|
|
|
+ StockWait stockWait = stockWaitService.getOne(q -> q
|
|
|
+ .eq(StockWait::getBusinessId, productionOrder.getId())
|
|
|
+ .eq(StockWait::getBusinessType, JournalType.PROD_OUT.getDetailType())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(stockWait)) {
|
|
|
+ stockWait = new StockWait();
|
|
|
+ stockWait.setStatus(0);//待出库
|
|
|
+ } else {
|
|
|
+ stockWait.setStatus(1);//部分出库
|
|
|
+ }
|
|
|
stockWait.setCompanyId(SecurityUtils.getCompanyId());
|
|
|
stockWait.setBusinessId(productionOrder.getId());
|
|
|
stockWait.setType(2);//出库
|
|
|
- stockWait.setStatus(0);//待出库
|
|
|
+
|
|
|
stockWait.setBusinessType(JournalType.PROD_OUT.getDetailType());//生产任务出库
|
|
|
stockWait.setContractId(productionOrder.getContractId());
|
|
|
stockWait.setBusinessCode(productionOrder.getCode());
|
|
|
- stockWaitService.save(stockWait);
|
|
|
+ stockWaitService.saveOrUpdate(stockWait);
|
|
|
|
|
|
List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
|
|
|
List<ContractProductBomVo> contractProductBomQuantitySum = contractProductBomService.getContractProductBomQuantitySum(productionOrder.getContractId());
|
|
|
for (ContractProductBomVo contractProductBomVo : contractProductBomQuantitySum) {
|
|
|
//创建待出库明细
|
|
|
- StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
- stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
|
+ Long stockWaitId = stockWait.getId();
|
|
|
+ StockWaitDetails stockWaitDetails = stockWaitDetailsService.getOne(q -> q
|
|
|
+ .eq(StockWaitDetails::getStockWaitId, stockWaitId)
|
|
|
+ .eq(StockWaitDetails::getProductId, contractProductBomVo.getMaterialId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(stockWaitDetails)) {
|
|
|
+ stockWaitDetails = new StockWaitDetails();
|
|
|
+ stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ stockWaitDetails.setStockWaitId(stockWaitId);
|
|
|
stockWaitDetails.setProductId(contractProductBomVo.getMaterialId());
|
|
|
stockWaitDetails.setQuantity(contractProductBomVo.getQuantity());
|
|
|
- stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
stockWaitDetailsList.add(stockWaitDetails);
|
|
|
}
|
|
|
- stockWaitDetailsService.saveBatch(stockWaitDetailsList);
|
|
|
+ stockWaitDetailsService.saveOrUpdateBatch(stockWaitDetailsList);
|
|
|
}
|
|
|
|
|
|
@Override
|