123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package com.fjhx.sale.flow;
- import cn.hutool.extra.spring.SpringUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.dynamic.datasource.annotation.DS;
- import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
- 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.common.utils.Assert;
- import com.fjhx.flow.core.FlowDelegate;
- import com.fjhx.flow.enums.FlowStatusEnum;
- import com.fjhx.sale.entity.quotation.po.QuotationPay;
- import com.fjhx.sale.entity.quotation.po.QuotationProduct;
- import com.fjhx.sale.entity.sale.dto.SaleQuotationDto;
- import com.fjhx.sale.entity.sale.po.SaleQuotation;
- 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;
- /**
- * 报价单流程
- */
- @DS(SourceConstant.SALE)
- @Component
- 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() {
- return "sale_quotation_flow";
- }
- /**
- * 发起流程
- *
- * @param flowId 流程ID
- * @param submitData 采购付款数据
- * @return
- */
- @Override
- public Long start(Long flowId, JSONObject submitData) {
- SaleQuotationDto saleQuotation = submitData.toJavaObject(SaleQuotationDto.class);
- //添加报价编码
- saleQuotation.setCode(codingRuleService.createCode(CodingRuleEnum.SALE_QUOTATION.getKey(), saleQuotation.getBuyCorporationId()));
- saleQuotation = commStart(saleQuotation, 0);
- return saleQuotation.getId();
- }
- /**
- * 结束流程
- *
- * @param flowId 流程ID
- * @param businessId 业务ID
- * @param submitData 数据
- */
- @Override
- public void end(Long flowId, Long businessId, JSONObject submitData) {
- SaleQuotationService saleQuotationService = SpringUtil.getBean(SaleQuotationService.class);
- //通过业务ID查询合同数据
- SaleQuotation contract = saleQuotationService.getById(businessId);
- if (ObjectUtils.isEmpty(contract)) {
- throw new ServiceException("报价单不存在");
- }
- //修改采购状态为审批通过
- contract.setStatus(SaleQuotationEnum.PASS.getKey());
- saleQuotationService.updateById(contract);
- }
- @Override
- public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
- super.relaunch(flowId, businessId, flowStatus, submitData);
- SaleQuotationDto saleQuotation = submitData.toJavaObject(SaleQuotationDto.class);
- Assert.notEmpty(saleQuotation.getId(), "报价单id不能为空");
- commStart(saleQuotation, 1);
- }
- @Override
- public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
- super.reject(flowId, businessId, flowStatus);
- 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.saveOrUpdateBatch(quotationPayList);
- }
- return saleQuotation;
- }
- }
|