|
@@ -0,0 +1,148 @@
|
|
|
+package com.fjhx.sale.flow;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fjhx.account.entity.account.dto.AccountPaymentDto;
|
|
|
+import com.fjhx.account.entity.account.enums.PaymentStatusEnum;
|
|
|
+import com.fjhx.account.service.account.AccountPaymentService;
|
|
|
+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.entity.flow.dto.InitiateDto;
|
|
|
+import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
+import com.fjhx.flow.service.flow.FlowProcessService;
|
|
|
+import com.fjhx.sale.entity.after.dto.AfterSalesDto;
|
|
|
+import com.fjhx.sale.entity.after.po.AfterSales;
|
|
|
+import com.fjhx.sale.entity.after.po.AfterSalesDetail;
|
|
|
+import com.fjhx.sale.entity.contract.dto.ContractDto;
|
|
|
+import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
+import com.fjhx.sale.service.after.AfterSalesDetailService;
|
|
|
+import com.fjhx.sale.service.after.AfterSalesService;
|
|
|
+import com.fjhx.sale.service.contract.ContractService;
|
|
|
+import com.fjhx.tenant.utils.DictUtils;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class AfterSalesFlow extends FlowDelegate {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AfterSalesService afterSalesService;
|
|
|
+ @Autowired
|
|
|
+ private AfterSalesDetailService afterSalesDetailService;
|
|
|
+ @Autowired
|
|
|
+ private CodingRuleService codingRuleService;
|
|
|
+ @Autowired
|
|
|
+ private AccountPaymentService accountPaymentService;
|
|
|
+ @Autowired
|
|
|
+ private ContractService contractService;
|
|
|
+ @Autowired
|
|
|
+ private FlowProcessService flowProcessService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "after_sales_flow";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
+ AfterSalesDto afterSalesDto = submitData.toJavaObject(AfterSalesDto.class);
|
|
|
+
|
|
|
+ afterSalesDto.setFlowId(flowId);
|
|
|
+ afterSalesDto.setStatus(FlowStatusEnum1.UNDER_REVIEW.getKey());
|
|
|
+ afterSalesDto.setCode(codingRuleService.createCode(CodingRuleEnum.AFTER_SALES.getKey(), null));
|
|
|
+ afterSalesService.addOrEdit(afterSalesDto);
|
|
|
+
|
|
|
+ return afterSalesDto.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
+ afterSalesService.update(q -> q
|
|
|
+ .eq(AfterSales::getId, businessId)
|
|
|
+ .set(AfterSales::getStatus, FlowStatusEnum1.PASS.getKey())
|
|
|
+ .set(AfterSales::getUpdateTime, new Date())
|
|
|
+ .set(AfterSales::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ AfterSales afterSales = afterSalesService.getById(businessId);
|
|
|
+ Map<String, String> dictMap = DictUtils.getDictMap("after_sales_type");
|
|
|
+ String type = afterSales.getType();
|
|
|
+ type += dictMap.getOrDefault(type, "");
|
|
|
+ //(1)如果审批通过,且售后类型=退货退款:后续跟进补充运单号,自动生成财务打款数据
|
|
|
+ //(2)如果审批通过,且售后类型=仅退款:自动生成财务打款数据
|
|
|
+ if (type.contains("退货退款") || type.contains("仅退款")) {
|
|
|
+ AccountPaymentDto accountPayment = new AccountPaymentDto();
|
|
|
+// accountPayment.setDepartmentId(accountRequestFunds.getDepartmentId());
|
|
|
+// accountPayment.setCorporationId(accountRequestFunds.getCorporationId());
|
|
|
+ accountPayment.setBusinessId(afterSales.getId());
|
|
|
+ accountPayment.setPaymentTime(new Date());
|
|
|
+ accountPayment.setCurrency("CNY");
|
|
|
+ accountPayment.setStatus(PaymentStatusEnum.UNDER_REVIEW.getKey());
|
|
|
+ accountPayment.setType("40");//售后
|
|
|
+// accountPayment.setPaymentRemark();
|
|
|
+ accountPayment.setPaymentMethod("bank");
|
|
|
+ accountPayment.setIncomeAmount(afterSales.getAmount());
|
|
|
+ accountPayment.setName(afterSales.getAccountName());
|
|
|
+// accountPayment.setBusinessManagementId(accountRequestFunds.getAccountManagementId());
|
|
|
+ accountPayment.setOpeningBank(afterSales.getAccountBank());
|
|
|
+ accountPayment.setAccountOpening(afterSales.getAccountNumber());
|
|
|
+// accountPayment.setInterbankNumber(accountRequestFunds.getInterbankNumber());
|
|
|
+ accountPayment.setDataUser(afterSales.getCreateUser());
|
|
|
+ accountPayment.setAmount(BigDecimal.ZERO);
|
|
|
+ accountPaymentService.save(accountPayment);
|
|
|
+ }
|
|
|
+ //(3)如果审批通过,且售后类型=补发/换货:自动生成订单,单价=0
|
|
|
+ if (type.contains("补发") || type.contains("换货")) {
|
|
|
+ ContractDto contractDto = BeanUtil.copyProperties(contractService.getById(afterSales.getContractId()), ContractDto.class);
|
|
|
+ contractDto.setId(null);
|
|
|
+ contractDto.setAmount(BigDecimal.ZERO);
|
|
|
+ List<AfterSalesDetail> afterSalesDetailList = afterSalesDetailService.list(q -> q.eq(AfterSalesDetail::getAfterSalesId, afterSales.getId()));
|
|
|
+ List<ContractProduct> contractProductList = new ArrayList<>();
|
|
|
+ for (AfterSalesDetail afterSalesDetail : afterSalesDetailList) {
|
|
|
+ ContractProduct contractProduct = new ContractProduct();
|
|
|
+ contractProduct.setProductId(afterSalesDetail.getProductId());
|
|
|
+ contractProduct.setPrice(BigDecimal.ZERO);
|
|
|
+ contractProduct.setAmount(BigDecimal.ZERO);
|
|
|
+ contractProduct.setQuantity(afterSalesDetail.getQuantity());
|
|
|
+ contractProductList.add(contractProduct);
|
|
|
+ }
|
|
|
+ contractDto.setContractProductList(contractProductList);
|
|
|
+
|
|
|
+ //生成合同审批数据
|
|
|
+ InitiateDto initiateDto = new InitiateDto();
|
|
|
+ initiateDto.setFlowKey("contract_flow");
|
|
|
+ initiateDto.setData(JSONObject.parseObject(JSONObject.toJSONString(contractDto)));
|
|
|
+ flowProcessService.initiate(initiateDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
|
|
|
+ AfterSalesDto afterSalesDto = submitData.toJavaObject(AfterSalesDto.class);
|
|
|
+ afterSalesService.addOrEdit(afterSalesDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ afterSalesService.update(q -> q
|
|
|
+ .eq(AfterSales::getId, businessId)
|
|
|
+ .set(AfterSales::getStatus, FlowStatusEnum1.REJECT.getKey())
|
|
|
+ .set(AfterSales::getUpdateTime, new Date())
|
|
|
+ .set(AfterSales::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ afterSalesService.cancellation(businessId);
|
|
|
+ }
|
|
|
+}
|