|
@@ -1,4 +1,4 @@
|
|
|
-package com.fjhx.sale.flow;
|
|
|
+package com.fjhx.purchase.flow;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson2.JSONWriter;
|
|
@@ -16,20 +16,16 @@ import com.fjhx.flow.core.FlowDelegate;
|
|
|
import com.fjhx.flow.core.FlowThreadLocalUtil;
|
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
import com.fjhx.purchase.entity.purchase.dto.PurchaseDto;
|
|
|
-import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
|
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseDetailStatusEnum;
|
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
|
|
|
import com.fjhx.purchase.entity.purchase.po.Purchase;
|
|
|
import com.fjhx.purchase.entity.purchase.po.PurchaseDetail;
|
|
|
-import com.fjhx.purchase.entity.subscribe.enums.SubscribeDetailStatusEnum;
|
|
|
import com.fjhx.purchase.entity.subscribe.po.Subscribe;
|
|
|
import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
|
|
|
import com.fjhx.purchase.service.purchase.PurchaseDetailService;
|
|
|
import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
|
import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
|
|
|
import com.fjhx.purchase.service.subscribe.SubscribeService;
|
|
|
-import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
-import com.fjhx.sale.service.contract.ContractProductService;
|
|
|
import com.ruoyi.common.core.domain.BasePo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
@@ -38,10 +34,8 @@ 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.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 采购流程
|
|
@@ -62,8 +56,6 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
@Autowired
|
|
|
private SubscribeDetailService subscribeDetailService;
|
|
|
@Autowired
|
|
|
- private ContractProductService contractProductService;
|
|
|
- @Autowired
|
|
|
private CodingRuleService codingRuleService;
|
|
|
|
|
|
@Override
|
|
@@ -113,8 +105,10 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
throw new ServiceException("采购数量不能小于或等于0");
|
|
|
}
|
|
|
//计算采购数量是否大于申购数量
|
|
|
- List<PurchaseDetail> purchaseDetailList1 = purchaseDetailService.list(q -> q.eq(PurchaseDetail::getSubscribeDetailId,
|
|
|
- s.getSubscribeDetailId()));
|
|
|
+ List<PurchaseDetail> purchaseDetailList1 = purchaseDetailService.list(q -> q
|
|
|
+ .eq(PurchaseDetail::getSubscribeDetailId, s.getSubscribeDetailId())
|
|
|
+ .in(PurchaseDetail::getStatus, 10, 30, 99)
|
|
|
+ );
|
|
|
//求和
|
|
|
BigDecimal purchaseCount = purchaseDetailList1.stream()
|
|
|
.map(PurchaseDetail::getCount)
|
|
@@ -170,30 +164,30 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
//修改申购明细状态
|
|
|
List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
|
|
|
- updateSubscribeStatus(businessId);
|
|
|
+ purchaseService.updateSubscribeStatus(businessId);
|
|
|
|
|
|
//通过业务ID查询采购数据
|
|
|
Purchase purchase = purchaseService.getById(businessId);
|
|
|
if (ObjectUtils.isEmpty(purchase)) {
|
|
|
throw new ServiceException("采购单不存在");
|
|
|
}
|
|
|
- //查询采购产品
|
|
|
- List<ContractProduct> upContractProduct = new ArrayList<>();
|
|
|
- for (PurchaseDetail p : purchaseDetailList) {
|
|
|
- if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
|
|
|
- p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
|
|
|
- ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
|
|
|
- BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getCount());
|
|
|
- if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
|
|
|
- throw new ServiceException("采购数量不得大于外销合同数量");
|
|
|
- }
|
|
|
- contractProduct.setExpendQuantity(expendQuantity);
|
|
|
- upContractProduct.add(contractProduct);
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
|
|
|
- contractProductService.updateBatchById(upContractProduct);
|
|
|
- }
|
|
|
+// //查询采购产品
|
|
|
+// List<ContractProduct> upContractProduct = new ArrayList<>();
|
|
|
+// for (PurchaseDetail p : purchaseDetailList) {
|
|
|
+// if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
|
|
|
+// p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
|
|
|
+// ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
|
|
|
+// BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getCount());
|
|
|
+// if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
|
|
|
+// throw new ServiceException("采购数量不得大于外销合同数量");
|
|
|
+// }
|
|
|
+// contractProduct.setExpendQuantity(expendQuantity);
|
|
|
+// upContractProduct.add(contractProduct);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
|
|
|
+// contractProductService.updateBatchById(upContractProduct);
|
|
|
+// }
|
|
|
//修改采购状态为审批通过
|
|
|
purchase.setPurchaseStatus(PurchaseStatusEnum.PASS.getKey());
|
|
|
purchase.setApprovedDate(new Date());
|
|
@@ -232,7 +226,7 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
.set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
);
|
|
|
//修改申购明细状态
|
|
|
- updateSubscribeStatus(businessId);
|
|
|
+ purchaseService.updateSubscribeStatus(businessId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -303,30 +297,4 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新申购明细的待采购状态
|
|
|
- */
|
|
|
- private void updateSubscribeStatus(Long businessId) {
|
|
|
- //修改申购明细状态
|
|
|
- List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
|
|
|
- List<Long> subscribeDetailIds = purchaseDetailList.stream().map(PurchaseDetail::getSubscribeDetailId).collect(Collectors.toList());
|
|
|
- List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
|
|
|
- for (SubscribeDetail subscribeDetail : subscribeDetails) {
|
|
|
- //获取申购明细下的所有采购记录 计算已采购数
|
|
|
- List<PurchaseDetail> purchaseDetails = purchaseDetailService.list(q -> q.eq(PurchaseDetail::getSubscribeDetailId,
|
|
|
- subscribeDetail.getId()).eq(PurchaseDetail::getBussinessId, subscribeDetail.getBussinessId()));
|
|
|
- BigDecimal count = purchaseDetails.stream()
|
|
|
- .map(PurchaseDetail::getCount)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- if (count.compareTo(subscribeDetail.getCount()) >= 0) {
|
|
|
- //修改为已采购
|
|
|
- subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
|
|
|
- } else {
|
|
|
- //修改为部分采购
|
|
|
- subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
|
|
|
- }
|
|
|
- }
|
|
|
- subscribeDetailService.updateBatchById(subscribeDetails);
|
|
|
- }
|
|
|
-
|
|
|
}
|