|
@@ -3,7 +3,7 @@ package com.fjhx.sale.flow;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
-import com.fjhx.common.entity.InOutBo;
|
|
|
+import com.fjhx.common.entity.AvailableStockBo;
|
|
|
import com.fjhx.common.enums.FlowStatusEnum1;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.common.utils.Utils;
|
|
@@ -11,7 +11,7 @@ import com.fjhx.flow.core.FlowDelegate;
|
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
import com.fjhx.item.enums.ProductAvailableRecordType;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
-import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
|
|
|
+import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
|
|
|
import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
|
|
|
import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
|
|
|
import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
|
|
@@ -19,16 +19,20 @@ import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
|
|
|
import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
|
|
|
import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
|
|
|
import com.fjhx.sale.service.purchase.EhsdPurchaseService;
|
|
|
+import com.fjhx.wms.entity.stock.po.StockWaitDetails;
|
|
|
+import com.fjhx.wms.service.stock.StockWaitDetailsService;
|
|
|
+import com.fjhx.wms.service.stock.StockWaitService;
|
|
|
import com.ruoyi.common.core.domain.BasePo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 采购变更流程
|
|
@@ -45,6 +49,10 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
private EhsdPurchaseProjectService ehsdPurchaseProjectService;
|
|
|
@Autowired
|
|
|
private ProductInfoService productInfoService;
|
|
|
+ @Autowired
|
|
|
+ private StockWaitDetailsService stockWaitDetailsService;
|
|
|
+ @Autowired
|
|
|
+ private StockWaitService stockWaitService;
|
|
|
|
|
|
@Override
|
|
|
public String getFlowKey() {
|
|
@@ -57,15 +65,16 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
@Override
|
|
|
public Long start(Long flowId, JSONObject submitData) {
|
|
|
EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
-
|
|
|
- //清理Id防止前端误传
|
|
|
+ Assert.notEmpty(purchase.getId(), "原采购订单id不能为空");
|
|
|
+ //赋值原采购id 并 清空id
|
|
|
+ purchase.setOldPurchaseId(purchase.getId());
|
|
|
purchase.setId(null);
|
|
|
|
|
|
//赋值流程id
|
|
|
purchase.setFlowId(flowId);
|
|
|
|
|
|
+ //获取原采购id
|
|
|
Long oldPurchaseId = purchase.getOldPurchaseId();
|
|
|
- Assert.notEmpty(oldPurchaseId, "原采购订单id不能为空");
|
|
|
|
|
|
//判断合同是否在变更中,防止用户缓存导致重复变更
|
|
|
EhsdPurchase oldPurchase = ehsdPurchaseService.getById(oldPurchaseId);
|
|
@@ -83,8 +92,11 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
//获取明细信息
|
|
|
List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
|
List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
|
- //清空物料,收费项目id 防止前端误传
|
|
|
- purchaseProductList.forEach(item -> item.setId(null));
|
|
|
+ //赋值原id 清除id字段
|
|
|
+ for (EhsdPurchaseProduct ehsdPurchaseProduct : purchaseProductList) {
|
|
|
+ ehsdPurchaseProduct.setOldPurchaseProductId(ehsdPurchaseProduct.getId());
|
|
|
+ ehsdPurchaseProduct.setId(null);
|
|
|
+ }
|
|
|
purchaseProjectList.forEach(item -> item.setId(null));
|
|
|
|
|
|
//调用采购发起公共代码块
|
|
@@ -102,44 +114,98 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
EhsdPurchase purchase = ehsdPurchaseService.getById(businessId);
|
|
|
Assert.notEmpty(purchase, "采购单不存在,或已被删除");
|
|
|
|
|
|
+ //修改采购状态为审批通过
|
|
|
+ purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
|
|
|
+ purchase.setApprovedDate(new Date());
|
|
|
+ ehsdPurchaseService.updateById(purchase);
|
|
|
+
|
|
|
//原合同改为 已变更
|
|
|
EhsdPurchase oldEhsdPurchase = ehsdPurchaseService.getById(purchase.getOldPurchaseId());
|
|
|
oldEhsdPurchase.setStatus(FlowStatusEnum1.UPDATE.getKey());
|
|
|
ehsdPurchaseService.updateById(oldEhsdPurchase);
|
|
|
|
|
|
- //修改可用库存
|
|
|
- //回滚旧合同数据
|
|
|
- List<InOutBo> oldInOutBoList = new ArrayList<>();
|
|
|
+
|
|
|
+ //---------------------------------------------
|
|
|
+ //获取新采购明细数据
|
|
|
+ Map<Long, BigDecimal> newQuantityMap = ehsdPurchaseProductService.mapKV(
|
|
|
+ EhsdPurchaseProduct::getOldPurchaseProductId, EhsdPurchaseProduct::getQuantity,
|
|
|
+ q -> q.eq(EhsdPurchaseProduct::getPurchaseId, businessId)
|
|
|
+ );
|
|
|
+
|
|
|
List<EhsdPurchaseProduct> oldPurchaseProductList = ehsdPurchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, purchase.getOldPurchaseId()));
|
|
|
- for (EhsdPurchaseProduct purchaseProduct : oldPurchaseProductList) {
|
|
|
- //如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 - 采购明细数量)
|
|
|
- if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
|
|
|
- InOutBo inOutBo = new InOutBo();
|
|
|
- inOutBo.setProductId(purchaseProduct.getProductId());
|
|
|
- inOutBo.setQuantity(purchaseProduct.getQuantity());
|
|
|
- oldInOutBoList.add(inOutBo);
|
|
|
+
|
|
|
+ List<AvailableStockBo> availableStockBoList = new ArrayList<>();
|
|
|
+
|
|
|
+ //旧数据处理
|
|
|
+ Long stockWaitId = null;
|
|
|
+ for (EhsdPurchaseProduct oldPurchaseProduct : oldPurchaseProductList) {
|
|
|
+ //新数量
|
|
|
+ BigDecimal newQuantity = newQuantityMap.get(oldPurchaseProduct.getId());
|
|
|
+ //已入库数量
|
|
|
+ StockWaitDetails stockWaitDetails = stockWaitDetailsService.getOne(q -> q.eq(StockWaitDetails::getBusinessDetailsId, oldPurchaseProduct.getId()));
|
|
|
+ stockWaitId = stockWaitDetails.getStockWaitId();
|
|
|
+
|
|
|
+ //生成操作可用库存的实体
|
|
|
+ AvailableStockBo availableStockBo = new AvailableStockBo();
|
|
|
+ availableStockBo.setProductId(oldPurchaseProduct.getProductId());
|
|
|
+ availableStockBo.setQuantity(oldPurchaseProduct.getQuantity());
|
|
|
+ availableStockBo.setNewQuantity(newQuantity);
|
|
|
+ availableStockBo.setInStockQuantity(stockWaitDetails.getReceiptQuantity());
|
|
|
+
|
|
|
+ availableStockBoList.add(availableStockBo);
|
|
|
+
|
|
|
+
|
|
|
+ //操作待入库数据
|
|
|
+ if (ObjectUtils.isEmpty(newQuantity)) {
|
|
|
+ //原数据被删,检查已入库数量,>0禁止变更
|
|
|
+ stockWaitDetailsService.removeById(stockWaitDetails);
|
|
|
+ } else {
|
|
|
+ stockWaitDetails.setQuantity(newQuantity);
|
|
|
+ //计算状态
|
|
|
+ int status = stockWaitDetails.getReceiptQuantity().compareTo(stockWaitDetails.getQuantity()) >= 0 ? 2 : 1;
|
|
|
+ if (stockWaitDetails.getReceiptQuantity().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ status = 0;
|
|
|
+ }
|
|
|
+ stockWaitDetails.setStatus(status);
|
|
|
+ stockWaitDetailsService.updateById(stockWaitDetails);
|
|
|
+
|
|
|
+ stockWaitService.updateStatus(stockWaitDetails.getStockWaitId());
|
|
|
}
|
|
|
}
|
|
|
- productInfoService.editAvailableQuantity(oldInOutBoList, purchase.getOldPurchaseId(), ProductAvailableRecordType.PURCHASE_UPDATE_OUT, purchase.getCompanyId());
|
|
|
-
|
|
|
-
|
|
|
- //将可用库存改为新合同数据
|
|
|
- List<InOutBo> inOutBoList = new ArrayList<>();
|
|
|
- List<EhsdPurchaseProduct> purchaseProductList = ehsdPurchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, businessId));
|
|
|
- for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
|
|
|
- //如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 + 采购明细数量)
|
|
|
- if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
|
|
|
- InOutBo inOutBo = new InOutBo();
|
|
|
- inOutBo.setProductId(purchaseProduct.getProductId());
|
|
|
- inOutBo.setQuantity(purchaseProduct.getQuantity());
|
|
|
- inOutBoList.add(inOutBo);
|
|
|
- }
|
|
|
+
|
|
|
+ //新添加的数据处理
|
|
|
+ List<EhsdPurchaseProduct> newPurchaseProductInfo = ehsdPurchaseProductService.list(q -> q
|
|
|
+ .eq(EhsdPurchaseProduct::getPurchaseId, businessId)
|
|
|
+ .isNull(EhsdPurchaseProduct::getOldPurchaseProductId)
|
|
|
+ );
|
|
|
+ for (EhsdPurchaseProduct newPurchaseProduct : newPurchaseProductInfo) {
|
|
|
+ //生成操作可用库存的实体
|
|
|
+ AvailableStockBo availableStockBo = new AvailableStockBo();
|
|
|
+ availableStockBo.setProductId(newPurchaseProduct.getProductId());
|
|
|
+ availableStockBo.setQuantity(null);
|
|
|
+ availableStockBo.setNewQuantity(newPurchaseProduct.getQuantity());
|
|
|
+ availableStockBo.setInStockQuantity(null);
|
|
|
+ availableStockBoList.add(availableStockBo);
|
|
|
+
|
|
|
+ //生成待入库
|
|
|
+ Assert.notEmpty(stockWaitId, "查询不到待入库信息!");
|
|
|
+ StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
+ stockWaitDetails.setStockWaitId(stockWaitId);
|
|
|
+ stockWaitDetails.setBusinessDetailsId(newPurchaseProduct.getId());
|
|
|
+ stockWaitDetails.setPurchaseDetailId(newPurchaseProduct.getId());
|
|
|
+
|
|
|
+ stockWaitDetails.setProductId(newPurchaseProduct.getProductId());
|
|
|
+ stockWaitDetails.setQuantity(newPurchaseProduct.getQuantity());
|
|
|
+ stockWaitDetails.setStatus(0);
|
|
|
+ stockWaitDetailsService.save(stockWaitDetails);
|
|
|
+
|
|
|
+ stockWaitService.updateStatus(stockWaitDetails.getStockWaitId());
|
|
|
}
|
|
|
- productInfoService.editAvailableQuantity(inOutBoList, businessId, ProductAvailableRecordType.PURCHASE_UPDATE_IN, purchase.getCompanyId());
|
|
|
|
|
|
|
|
|
- //调用采购发起流程的结束方法
|
|
|
- ehsdPurchaseFlow.end(flowId, businessId, submitData);
|
|
|
+ //修改可用库存
|
|
|
+ productInfoService.editAvailableQuantity(availableStockBoList, businessId, ProductAvailableRecordType.PURCHASE_UPDATE, purchase.getCompanyId());
|
|
|
+
|
|
|
|
|
|
Long oldPurchaseId = purchase.getOldPurchaseId();
|
|
|
|