RegularlyPaymentStatus.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.ydtech.modules.ttqf;
  2. import cn.hutool.extra.spring.SpringUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.ipaynow.jiaxin.domain.OrderQueryResultModel;
  6. import com.ipaynow.jiaxin.response.OrderQueryResponse;
  7. import com.ydtech.modules.ttqf.dao.PaymentNoticeMapper;
  8. import com.ydtech.modules.ttqf.entity.PaymentNoticeEntity;
  9. import com.ydtech.utils.StringUtils;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.scheduling.annotation.Async;
  12. import org.springframework.stereotype.Component;
  13. import java.util.*;
  14. @Component
  15. @Slf4j
  16. public class RegularlyPaymentStatus {
  17. @Async
  18. public void updatePaymentStatus(String orderNo){
  19. Timer timer = new Timer();
  20. final int[] executionCount = {1};
  21. TimerTask task = new TimerTask() {
  22. @Override
  23. public void run() {
  24. try {
  25. log.info("打款状态定时任务入参:{}",orderNo);
  26. OrderQueryResponse response = SpringUtil.getBean(RetrieveTTQFApi.class).orderQuery(orderNo);
  27. log.info("打款状态定时返回执行数据:{}", JSONObject.toJSONString(response.getResultModel()));
  28. if (response == null || !StringUtils.equals(response.getBizCode(),"0000")) {
  29. log.info("获取打款状态任务退出{}");
  30. timer.cancel();
  31. }
  32. if (response.isSuccess()) {
  33. if (Arrays.stream(PayConstantStatus.ORDER_ARRAY).anyMatch(i -> Objects.equals(i,response.getResultModel().getStatus()))){
  34. updatePayLog(orderNo,response.getResultModel());
  35. log.info("获取打款状态任务退出");
  36. timer.cancel();
  37. }
  38. }
  39. log.info("当前线程+++++++++++++{}",Thread.currentThread().getId());
  40. // if (executionCount[0] == 20){
  41. // log.info("获取打款状态任务退出{}");
  42. // timer.cancel();
  43. // }
  44. }catch (Exception e){
  45. log.error("定时获取打款状态任务异常:{}",e.getMessage());
  46. timer.cancel();
  47. }
  48. executionCount[0]++;
  49. }
  50. };
  51. timer.schedule(task, 2000, 5000);
  52. }
  53. public void updatePayLog(String orderNo, OrderQueryResultModel resultModel){
  54. QueryWrapper<PaymentNoticeEntity> wrapper = new QueryWrapper<>();
  55. wrapper.eq("order_no",orderNo);
  56. PaymentNoticeEntity notice = SpringUtil.getBean(PaymentNoticeMapper.class).selectOne(wrapper);
  57. if (null == notice){
  58. PaymentNoticeEntity noticeEntity = JSONObject.parseObject(JSONObject.toJSONString(resultModel), PaymentNoticeEntity.class);
  59. if (null == noticeEntity.getPayTime()){
  60. noticeEntity.setPayTime(new Date());
  61. }
  62. noticeEntity.setCreateTime(new Date());
  63. int update = SpringUtil.getBean(PaymentNoticeMapper.class).insert(noticeEntity);
  64. log.info("获取打款状态成功正在保存===========:{}",orderNo ,"+++++", update > 0 ? "保存成功" : "保存失败");
  65. }
  66. }
  67. }