Browse Source

报价单 重新发起 驳回实现

yzc 1 year ago
parent
commit
1bf3220f68
1 changed files with 66 additions and 26 deletions
  1. 66 26
      hx-sale/src/main/java/com/fjhx/sale/flow/SaleQuotationFlow.java

+ 66 - 26
hx-sale/src/main/java/com/fjhx/sale/flow/SaleQuotationFlow.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fjhx.area.utils.CustomizeAreaUtil;
 import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.common.enums.CodingRuleEnum;
+import com.fjhx.common.enums.FlowStatusEnum1;
 import com.fjhx.common.service.coding.CodingRuleService;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.enums.FlowStatusEnum;
@@ -19,10 +20,13 @@ import com.fjhx.sale.enums.SaleQuotationEnum;
 import com.fjhx.sale.service.quotation.QuotationPayService;
 import com.fjhx.sale.service.quotation.QuotationProductService;
 import com.fjhx.sale.service.sale.SaleQuotationService;
+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.util.Date;
 import java.util.List;
 
 /**
@@ -33,6 +37,12 @@ import java.util.List;
 public class SaleQuotationFlow extends FlowDelegate {
     @Autowired
     private CodingRuleService codingRuleService;
+    @Autowired
+    private SaleQuotationService saleQuotationService;
+    @Autowired
+    private QuotationPayService quotationPayService;
+    @Autowired
+    private QuotationProductService quotationProductService;
 
     @Override
     public String getFlowKey() {
@@ -41,45 +51,25 @@ public class SaleQuotationFlow extends FlowDelegate {
 
     /**
      * 发起流程
-     * @param flowId 流程ID
+     *
+     * @param flowId     流程ID
      * @param submitData 采购付款数据
      * @return
      */
     @Override
     public Long start(Long flowId, JSONObject submitData) {
-        SaleQuotationService saleQuotationService = SpringUtil.getBean(SaleQuotationService.class);
-        QuotationPayService quotationPayService = SpringUtil.getBean(QuotationPayService.class);
-        QuotationProductService quotationProductService = SpringUtil.getBean(QuotationProductService.class);
         SaleQuotationDto saleQuotation = submitData.toJavaObject(SaleQuotationDto.class);
-        //赋值城市省份信息
-        CustomizeAreaUtil.setAreaId(saleQuotation);
-        saleQuotation.setBuyCityId(saleQuotation.getCityId());
-        saleQuotation.setBuyCountryId(saleQuotation.getCountryId());
-        saleQuotation.setBuyProvinceId(saleQuotation.getProvinceId());
         //添加报价编码
-        saleQuotation.setCode(codingRuleService.createCode(CodingRuleEnum.SALE_QUOTATION.getKey(),saleQuotation.getBuyCorporationId()));
-//        saleQuotation.setCode(CodeEnum.SALE_QUOTATION.getCode());
-        //添加报价状态
-        saleQuotation.setStatus(SaleQuotationEnum.UNDER_REVIEW.getKey());
-        //添加报价单信息
-        saleQuotationService.save(saleQuotation);
-        List<QuotationProduct> quotationProductList = saleQuotation.getQuotationProductList();
-        if(CollectionUtils.isNotEmpty(quotationProductList)){//保存报价产品信息
-            quotationProductList.forEach(quotationProduct -> quotationProduct.setSaleQuotationId(saleQuotation.getId()));
-            quotationProductService.saveBatch(quotationProductList);
-        }
-        List<QuotationPay> quotationPayList = saleQuotation.getQuotationPayList();
-        if(CollectionUtils.isNotEmpty(quotationPayList)){//保存报价项目信息
-           quotationPayList.forEach(quotationPay -> quotationPay.setSaleQuotationId(saleQuotation.getId()));
-            quotationPayService.saveBatch(quotationPayList);
-        }
+        saleQuotation.setCode(codingRuleService.createCode(CodingRuleEnum.SALE_QUOTATION.getKey(), saleQuotation.getBuyCorporationId()));
+        saleQuotation = commStart(saleQuotation, 0);
 
         return saleQuotation.getId();
     }
 
     /**
      * 结束流程
-     * @param flowId 流程ID
+     *
+     * @param flowId     流程ID
      * @param businessId 业务ID
      * @param submitData 数据
      */
@@ -98,6 +88,56 @@ public class SaleQuotationFlow extends FlowDelegate {
 
     @Override
     public void defaultMethod(Long flowId, Long businessId, FlowStatusEnum flowStatusEnum, JSONObject submitData) {
+        //重新发起
+        if (FlowStatusEnum.READY_START.equals(flowStatusEnum)) {
+            SaleQuotationDto saleQuotation = submitData.toJavaObject(SaleQuotationDto.class);
+            commStart(saleQuotation, 1);
+        }
+        //驳回
+        if (FlowStatusEnum.REJECT.equals(flowStatusEnum)) {
+            saleQuotationService.update(q -> q
+                    .eq(SaleQuotation::getId, businessId)
+                    .set(SaleQuotation::getStatus, FlowStatusEnum1.REJECT.getKey())
+                    .set(BasePo::getUpdateTime, new Date())
+                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+            );
+        }
+    }
+
+    /**
+     * 开始公共代码抽取
+     *
+     * @param opType 操作类型 0直接发起 1重新发起
+     */
+    private SaleQuotationDto commStart(SaleQuotationDto saleQuotation, Integer opType) {
+        //赋值城市省份信息
+        CustomizeAreaUtil.setAreaId(saleQuotation);
+        saleQuotation.setBuyCityId(saleQuotation.getCityId());
+        saleQuotation.setBuyCountryId(saleQuotation.getCountryId());
+        saleQuotation.setBuyProvinceId(saleQuotation.getProvinceId());
 
+        //添加报价状态
+        saleQuotation.setStatus(SaleQuotationEnum.UNDER_REVIEW.getKey());
+        //添加报价单信息
+        saleQuotationService.saveOrUpdate(saleQuotation);
+        List<QuotationProduct> quotationProductList = saleQuotation.getQuotationProductList();
+        if (CollectionUtils.isNotEmpty(quotationProductList)) {//保存报价产品信息
+            if (opType == 1) {
+                //先删除被删除的产品
+                quotationProductService.editLinked(quotationProductList, QuotationProduct::getSaleQuotationId, saleQuotation.getId());
+            }
+            quotationProductList.forEach(quotationProduct -> quotationProduct.setSaleQuotationId(saleQuotation.getId()));
+            quotationProductService.saveOrUpdateBatch(quotationProductList);
+        }
+        List<QuotationPay> quotationPayList = saleQuotation.getQuotationPayList();
+        if (CollectionUtils.isNotEmpty(quotationPayList)) {//保存报价项目信息
+            if (opType == 1) {
+                //先删除被删除的产品
+                quotationPayService.editLinked(quotationPayList, QuotationPay::getSaleQuotationId, saleQuotation.getId());
+            }
+            quotationPayList.forEach(quotationPay -> quotationPay.setSaleQuotationId(saleQuotation.getId()));
+            quotationPayService.saveBatch(quotationPayList);
+        }
+        return saleQuotation;
     }
 }