RefundFlow.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.fjhx.purchase.flow;
  2. import cn.hutool.extra.spring.SpringUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.dynamic.datasource.annotation.DS;
  5. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  6. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  7. import com.fjhx.common.constant.SourceConstant;
  8. import com.fjhx.common.enums.FlowStatusEnum1;
  9. import com.fjhx.common.utils.Assert;
  10. import com.fjhx.flow.core.FlowDelegate;
  11. import com.fjhx.flow.enums.FlowStatusEnum;
  12. import com.fjhx.purchase.entity.pay.enums.PayStatusEnum;
  13. import com.fjhx.purchase.entity.refund.po.Refund;
  14. import com.fjhx.purchase.entity.refund.po.RefundDetail;
  15. import com.fjhx.purchase.service.refund.RefundDetailService;
  16. import com.fjhx.purchase.service.refund.RefundService;
  17. import com.ruoyi.common.core.domain.BasePo;
  18. import com.ruoyi.common.exception.ServiceException;
  19. import com.ruoyi.common.utils.SecurityUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Component;
  22. import java.util.Date;
  23. import java.util.List;
  24. /**
  25. * 退货流程
  26. *
  27. * @Author:caozj
  28. * @DATE:2023/4/3 17:38
  29. */
  30. @DS(SourceConstant.PURCHASE)
  31. @Component
  32. public class RefundFlow extends FlowDelegate {
  33. @Autowired
  34. private RefundService refundService;
  35. @Autowired
  36. private RefundDetailService refundDetailService;
  37. @Override
  38. public String getFlowKey() {
  39. return "refund_flow";
  40. }
  41. /**
  42. * 发起流程
  43. *
  44. * @param flowId 流程ID
  45. * @param submitData 数据
  46. * @return
  47. */
  48. @Override
  49. public Long start(Long flowId, JSONObject submitData) {
  50. Refund refund = submitData.toJavaObject(Refund.class);
  51. refund = commStart(refund, 0);
  52. return refund.getId();
  53. }
  54. /**
  55. * 开始公共代码抽取
  56. *
  57. * @param opType 操作类型 0直接发起 1重新发起
  58. */
  59. private Refund commStart(Refund refund, Integer opType) {
  60. if (opType == 1) {
  61. Assert.notEmpty(refund.getId(), "退款id不能为空");
  62. }
  63. refund.setStatus(PayStatusEnum.UNDER_REVIEW.getKey());
  64. refundService.saveOrUpdate(refund);
  65. List<RefundDetail> refundDetailList = refund.getRefundDetailList();
  66. if (CollectionUtils.isNotEmpty(refundDetailList)) {
  67. if (opType == 1) {
  68. //先删除被删除的产品
  69. refundDetailService.editLinked(refundDetailList, RefundDetail::getRefundId, refund.getId());
  70. }
  71. for (RefundDetail s : refundDetailList) {
  72. s.setRefundId(refund.getId());
  73. }
  74. refundDetailService.saveOrUpdateBatch(refundDetailList);
  75. }
  76. return refund;
  77. }
  78. /**
  79. * 结束流程
  80. *
  81. * @param flowId 流程ID
  82. * @param businessId 业务ID
  83. * @param submitData 数据
  84. */
  85. @Override
  86. public void end(Long flowId, Long businessId, JSONObject submitData) {
  87. RefundService refundService = SpringUtil.getBean(RefundService.class);
  88. //通过业务ID查询申购数据
  89. Refund refund = refundService.getById(businessId);
  90. if (ObjectUtils.isEmpty(refund)) {
  91. throw new ServiceException("退款单不存在");
  92. }
  93. //修改采购状态为审批通过
  94. refund.setStatus(PayStatusEnum.PASS.getKey());
  95. refund.setApprovedDate(new Date());
  96. refundService.updateById(refund);
  97. }
  98. @Override
  99. public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
  100. super.relaunch(flowId, businessId, flowStatus, submitData);
  101. Refund refund = submitData.toJavaObject(Refund.class);
  102. commStart(refund, 1);
  103. }
  104. @Override
  105. public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
  106. super.reject(flowId, businessId, flowStatus);
  107. refundService.update(q -> q
  108. .eq(Refund::getId, businessId)
  109. .set(Refund::getStatus, FlowStatusEnum1.REJECT.getKey())
  110. .set(BasePo::getUpdateTime, new Date())
  111. .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
  112. );
  113. }
  114. }