SaleQuotationFlow.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.fjhx.sale.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.area.utils.CustomizeAreaUtil;
  8. import com.fjhx.common.constant.SourceConstant;
  9. import com.fjhx.common.enums.CodingRuleEnum;
  10. import com.fjhx.common.enums.FlowStatusEnum1;
  11. import com.fjhx.common.service.coding.CodingRuleService;
  12. import com.fjhx.common.utils.Assert;
  13. import com.fjhx.flow.core.FlowDelegate;
  14. import com.fjhx.flow.enums.FlowStatusEnum;
  15. import com.fjhx.sale.entity.quotation.po.QuotationPay;
  16. import com.fjhx.sale.entity.quotation.po.QuotationProduct;
  17. import com.fjhx.sale.entity.sale.dto.SaleQuotationDto;
  18. import com.fjhx.sale.entity.sale.po.SaleQuotation;
  19. import com.fjhx.sale.enums.SaleQuotationEnum;
  20. import com.fjhx.sale.service.quotation.QuotationPayService;
  21. import com.fjhx.sale.service.quotation.QuotationProductService;
  22. import com.fjhx.sale.service.sale.SaleQuotationService;
  23. import com.ruoyi.common.core.domain.BasePo;
  24. import com.ruoyi.common.exception.ServiceException;
  25. import com.ruoyi.common.utils.SecurityUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Component;
  28. import java.util.Date;
  29. import java.util.List;
  30. /**
  31. * 报价单流程
  32. */
  33. @DS(SourceConstant.SALE)
  34. @Component
  35. public class SaleQuotationFlow extends FlowDelegate {
  36. @Autowired
  37. private CodingRuleService codingRuleService;
  38. @Autowired
  39. private SaleQuotationService saleQuotationService;
  40. @Autowired
  41. private QuotationPayService quotationPayService;
  42. @Autowired
  43. private QuotationProductService quotationProductService;
  44. @Override
  45. public String getFlowKey() {
  46. return "sale_quotation_flow";
  47. }
  48. /**
  49. * 发起流程
  50. *
  51. * @param flowId 流程ID
  52. * @param submitData 采购付款数据
  53. * @return
  54. */
  55. @Override
  56. public Long start(Long flowId, JSONObject submitData) {
  57. SaleQuotationDto saleQuotation = submitData.toJavaObject(SaleQuotationDto.class);
  58. //添加报价编码
  59. saleQuotation.setCode(codingRuleService.createCode(CodingRuleEnum.SALE_QUOTATION.getKey(), saleQuotation.getBuyCorporationId()));
  60. saleQuotation = commStart(saleQuotation, 0);
  61. return saleQuotation.getId();
  62. }
  63. /**
  64. * 结束流程
  65. *
  66. * @param flowId 流程ID
  67. * @param businessId 业务ID
  68. * @param submitData 数据
  69. */
  70. @Override
  71. public void end(Long flowId, Long businessId, JSONObject submitData) {
  72. SaleQuotationService saleQuotationService = SpringUtil.getBean(SaleQuotationService.class);
  73. //通过业务ID查询合同数据
  74. SaleQuotation contract = saleQuotationService.getById(businessId);
  75. if (ObjectUtils.isEmpty(contract)) {
  76. throw new ServiceException("报价单不存在");
  77. }
  78. //修改采购状态为审批通过
  79. contract.setStatus(SaleQuotationEnum.PASS.getKey());
  80. saleQuotationService.updateById(contract);
  81. }
  82. @Override
  83. public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
  84. super.relaunch(flowId, businessId, flowStatus, submitData);
  85. SaleQuotationDto saleQuotation = submitData.toJavaObject(SaleQuotationDto.class);
  86. Assert.notEmpty(saleQuotation.getId(), "报价单id不能为空");
  87. commStart(saleQuotation, 1);
  88. }
  89. @Override
  90. public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
  91. super.reject(flowId, businessId, flowStatus);
  92. saleQuotationService.update(q -> q
  93. .eq(SaleQuotation::getId, businessId)
  94. .set(SaleQuotation::getStatus, FlowStatusEnum1.REJECT.getKey())
  95. .set(BasePo::getUpdateTime, new Date())
  96. .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
  97. );
  98. }
  99. /**
  100. * 开始公共代码抽取
  101. *
  102. * @param opType 操作类型 0直接发起 1重新发起
  103. */
  104. private SaleQuotationDto commStart(SaleQuotationDto saleQuotation, Integer opType) {
  105. //赋值城市省份信息
  106. CustomizeAreaUtil.setAreaId(saleQuotation);
  107. saleQuotation.setBuyCityId(saleQuotation.getCityId());
  108. saleQuotation.setBuyCountryId(saleQuotation.getCountryId());
  109. saleQuotation.setBuyProvinceId(saleQuotation.getProvinceId());
  110. //添加报价状态
  111. saleQuotation.setStatus(SaleQuotationEnum.UNDER_REVIEW.getKey());
  112. //添加报价单信息
  113. saleQuotationService.saveOrUpdate(saleQuotation);
  114. List<QuotationProduct> quotationProductList = saleQuotation.getQuotationProductList();
  115. if (CollectionUtils.isNotEmpty(quotationProductList)) {//保存报价产品信息
  116. if (opType == 1) {
  117. //先删除被删除的产品
  118. quotationProductService.editLinked(quotationProductList, QuotationProduct::getSaleQuotationId, saleQuotation.getId());
  119. }
  120. quotationProductList.forEach(quotationProduct -> quotationProduct.setSaleQuotationId(saleQuotation.getId()));
  121. quotationProductService.saveOrUpdateBatch(quotationProductList);
  122. }
  123. List<QuotationPay> quotationPayList = saleQuotation.getQuotationPayList();
  124. if (CollectionUtils.isNotEmpty(quotationPayList)) {//保存报价项目信息
  125. if (opType == 1) {
  126. //先删除被删除的产品
  127. quotationPayService.editLinked(quotationPayList, QuotationPay::getSaleQuotationId, saleQuotation.getId());
  128. }
  129. quotationPayList.forEach(quotationPay -> quotationPay.setSaleQuotationId(saleQuotation.getId()));
  130. quotationPayService.saveOrUpdateBatch(quotationPayList);
  131. }
  132. return saleQuotation;
  133. }
  134. }