选装售后
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AflSupplementaryPayOrderServiceImpl.java 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.qtzl.alterSales.manager.service;
  2. import cn.com.taiji.common.manager.net.http.ServiceHandleException;
  3. import com.qtzl.alterSales.dao.entity.primary.AflSupplementaryPayOrder;
  4. import com.qtzl.alterSales.dao.entity.primary.FssPaccountPay;
  5. import com.qtzl.alterSales.dao.repo.jpa.primary.AflSupplementaryPayOrderRepo;
  6. import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountPayRepo;
  7. import com.qtzl.alterSales.manager.enums.*;
  8. import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
  9. import com.qtzl.alterSales.manager.model.protocol.sales.AflSupplementaryNotifyRequest;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.util.CollectionUtils;
  15. import javax.annotation.Resource;
  16. import java.time.LocalDateTime;
  17. import java.time.format.DateTimeFormatter;
  18. import java.util.List;
  19. /***
  20. * <p>
  21. * 补缴单 service
  22. * </p>
  23. * @author hou yi
  24. * {@code @date} 2023/11/16 9:47
  25. **/
  26. @Service
  27. public class AflSupplementaryPayOrderServiceImpl implements AflSupplementaryPayOrderService {
  28. private static final Logger log = LoggerFactory.getLogger(AflSupplementaryPayOrderServiceImpl.class);
  29. @Resource
  30. private AflSupplementaryPayOrderRepo supplementaryPayOrderRepo;
  31. @Resource
  32. private FssPaccountPayRepo accountPayRepo;
  33. @Resource
  34. private AflBlackInfoManager aflBlackInfoManager;
  35. @Resource
  36. AflPaccountRefundCountService aflPaccountRefundCountService;
  37. @Override
  38. public void notifyHandler(AflSupplementaryNotifyRequest request) throws ServiceHandleException {
  39. //
  40. final AflSupplementaryPayOrder supplementaryPayOrder = notifyHandlerVerify(request);
  41. if (SupplementartPayOrderStateEnum.SUCCESS.equals(supplementaryPayOrder.getState())) {
  42. log.warn("补缴状态为SUCCESS的补交单,不进行补缴通知的相关处理,响应渠道方时为成功... payId:{}", request.getPayId());
  43. return;
  44. }
  45. DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  46. final LocalDateTime successTime;
  47. try {
  48. successTime = LocalDateTime.parse(request.getSuccessTime(), df);
  49. } catch (Exception e) {
  50. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("补缴成功时间格式错误");
  51. }
  52. // 流水处理
  53. final FssPaccountPay fssPaccountPay = accountPayRepo.findByPayId(request.getPayId());
  54. if (null == fssPaccountPay) {
  55. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("路网交易流水号对应流水不存在,payId:" + request.getPayId());
  56. }
  57. if (null != fssPaccountPay.getStatus() && fssPaccountPay.getStatus().equals(1)) {
  58. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("路网交易流水号对应流水状态为扣款成功,请核实,payId:" + request.getPayId());
  59. }
  60. supplementaryPayOrder.setSupplementaryNo(request.getOutTradeNo());
  61. supplementaryPayOrder.setSupplementaryTime(successTime);
  62. supplementaryPayOrder.setSupplementaryNotifyTime(LocalDateTime.now());
  63. supplementaryPayOrder.setState(SupplementartPayOrderStateEnum.SUCCESS);
  64. fssPaccountPay.setStatus(1);
  65. fssPaccountPay.setMsg("请款成功");
  66. fssPaccountPay.setWxPayStatus(1);
  67. fssPaccountPay.setWxPayTime(supplementaryPayOrder.getSupplementaryTime());
  68. fssPaccountPay.setWxOrderId(request.getOutTradeNo());
  69. // 进行是否需要进行返白操作
  70. userStateHandler(fssPaccountPay, request.getPayId());
  71. //
  72. //进行统计累加已收款金额
  73. aflPaccountRefundCountService.saveFind(request.getPayId());
  74. supplementaryPayOrderRepo.save(supplementaryPayOrder);
  75. accountPayRepo.save(fssPaccountPay);
  76. }
  77. @Override
  78. public void paySuccessNotify(String payId, LocalDateTime supplementaryTime, String supplementaryNo) {
  79. // 补缴成功后通知渠道
  80. AflSupplementaryPayOrder supplementaryPayOrder = supplementaryPayOrderRepo.findByPayId(payId);
  81. if (null == supplementaryPayOrder) {
  82. // 未生成补缴单的流水补扣成功后不推送
  83. return;
  84. }
  85. supplementaryPayOrder.setSupplementaryTime(supplementaryTime);
  86. supplementaryPayOrder.setSupplementaryNo(supplementaryNo);
  87. supplementaryPayOrder.setState(SupplementartPayOrderStateEnum.SUCCESS);
  88. supplementaryPayOrder.setSupplementaryNotifyTime(LocalDateTime.now());
  89. supplementaryPayOrder.setQtState(QtStateEnum.FAIL);
  90. supplementaryPayOrderRepo.save(supplementaryPayOrder);
  91. }
  92. private void userStateHandler(FssPaccountPay fssPaccountPay, String payId) {
  93. // 用户是否返白处理
  94. final List<FssPaccountPay> accountPays = accountPayRepo.findByAgreementNum(fssPaccountPay.getAgreementNum());
  95. final List<FssPaccountPay> payStream = accountPays.stream().filter(vo -> !vo.getPayId().equals(payId)).toList();
  96. if (CollectionUtils.isEmpty(payStream)) {
  97. // 不存在其他待扣款流水,进行返白
  98. aflBlackInfoManager.execute(fssPaccountPay.getAgreementNum(),
  99. BlacklistOpType.OUT, "渠道方通知补缴成功,查询无其他待补缴流水,进行返白", fssPaccountPay.getOrderId(), payId,
  100. null, null, null);
  101. }
  102. }
  103. private AflSupplementaryPayOrder notifyHandlerVerify(AflSupplementaryNotifyRequest request) throws ServiceHandleException {
  104. //
  105. if (StringUtils.isEmpty(request.getPayId())) {
  106. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("路网交易流水号不能为空");
  107. }
  108. if (null == request.getStatus()) {
  109. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("补缴状态不能为空");
  110. }
  111. if (null == request.getTotalFee()) {
  112. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("补缴金额不能为空");
  113. }
  114. if (!SupplementaryNotifyStatusEnum.SUPPLEMENTARY_SUCCESS.getCode().equals(request.getStatus())) {
  115. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("非补缴成功的补缴单,请在补缴成功后再进行通知");
  116. }
  117. if (StringUtils.isEmpty(request.getOutTradeNo())) {
  118. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("补缴单号不能为空");
  119. }
  120. if (StringUtils.isEmpty(request.getSuccessTime())) {
  121. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("补缴成功时间不能为空");
  122. }
  123. final AflSupplementaryPayOrder supplementaryPayOrder = supplementaryPayOrderRepo.findByPayId(request.getPayId());
  124. if (null == supplementaryPayOrder) {
  125. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("路网交易流水号对应补缴单不存在,请核实");
  126. }
  127. if (!request.getTotalFee().equals(supplementaryPayOrder.getReceiptAmt())) {
  128. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("补缴金额与补缴单金额不一致,请核实");
  129. }
  130. return supplementaryPayOrder;
  131. }
  132. }