Browse Source

退款流程 重新发起 驳回

yzc 1 year ago
parent
commit
809b2ec6c7
1 changed files with 51 additions and 10 deletions
  1. 51 10
      hx-purchase/src/main/java/com/fjhx/purchase/flow/RefundFlow.java

+ 51 - 10
hx-purchase/src/main/java/com/fjhx/purchase/flow/RefundFlow.java

@@ -6,6 +6,8 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fjhx.common.constant.SourceConstant;
+import com.fjhx.common.enums.FlowStatusEnum1;
+import com.fjhx.common.utils.Assert;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.enums.FlowStatusEnum;
 import com.fjhx.purchase.entity.pay.enums.PayStatusEnum;
@@ -13,7 +15,10 @@ import com.fjhx.purchase.entity.refund.po.Refund;
 import com.fjhx.purchase.entity.refund.po.RefundDetail;
 import com.fjhx.purchase.service.refund.RefundDetailService;
 import com.fjhx.purchase.service.refund.RefundService;
+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;
@@ -21,6 +26,7 @@ import java.util.List;
 
 /**
  * 退货流程
+ *
  * @Author:caozj
  * @DATE:2023/4/3 17:38
  */
@@ -28,6 +34,11 @@ import java.util.List;
 @Component
 public class RefundFlow extends FlowDelegate {
 
+    @Autowired
+    private RefundService refundService;
+    @Autowired
+    private RefundDetailService refundDetailService;
+
     @Override
     public String getFlowKey() {
         return "refund_flow";
@@ -36,30 +47,47 @@ public class RefundFlow extends FlowDelegate {
 
     /**
      * 发起流程
-     * @param flowId 流程ID
+     *
+     * @param flowId     流程ID
      * @param submitData 数据
      * @return
      */
     @Override
     public Long start(Long flowId, JSONObject submitData) {
-        RefundService refundService = SpringUtil.getBean(RefundService.class);
-        RefundDetailService refundDetailService = SpringUtil.getBean(RefundDetailService.class);
         Refund refund = submitData.toJavaObject(Refund.class);
+        refund = commStart(refund, 0);
+        return refund.getId();
+    }
+
+    /**
+     * 开始公共代码抽取
+     *
+     * @param opType 操作类型 0直接发起 1重新发起
+     */
+    private Refund commStart(Refund refund, Integer opType) {
+        if (opType == 1) {
+            Assert.notEmpty(refund.getId(), "采购付款id不能为空");
+        }
         refund.setStatus(PayStatusEnum.UNDER_REVIEW.getKey());
-        refundService.save(refund);
+        refundService.saveOrUpdate(refund);
         List<RefundDetail> refundDetailList = refund.getRefundDetailList();
-        if(CollectionUtils.isNotEmpty(refundDetailList)){
-            for(RefundDetail s : refundDetailList){
+        if (CollectionUtils.isNotEmpty(refundDetailList)) {
+            if (opType == 1) {
+                //先删除被删除的产品
+                refundDetailService.editLinked(refundDetailList, RefundDetail::getRefundId, refund.getId());
+            }
+            for (RefundDetail s : refundDetailList) {
                 s.setRefundId(refund.getId());
             }
-            refundDetailService.saveBatch(refundDetailList);
+            refundDetailService.saveOrUpdateBatch(refundDetailList);
         }
-        return refund.getId();
+        return refund;
     }
 
     /**
      * 结束流程
-     * @param flowId 流程ID
+     *
+     * @param flowId     流程ID
      * @param businessId 业务ID
      * @param submitData 数据
      */
@@ -79,6 +107,19 @@ public class RefundFlow extends FlowDelegate {
 
     @Override
     public void defaultMethod(Long flowId, Long businessId, FlowStatusEnum flowStatusEnum, JSONObject submitData) {
-
+        //重新发起
+        if (FlowStatusEnum.READY_START.equals(flowStatusEnum)) {
+            Refund refund = submitData.toJavaObject(Refund.class);
+            commStart(refund, 1);
+        }
+        //驳回
+        if (FlowStatusEnum.REJECT.equals(flowStatusEnum)) {
+            refundService.update(q -> q
+                    .eq(Refund::getId, businessId)
+                    .set(Refund::getStatus, FlowStatusEnum1.REJECT.getKey())
+                    .set(BasePo::getUpdateTime, new Date())
+                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+            );
+        }
     }
 }