RegularlyUpdateStatus.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.quartz.*;
  12. import java.util.Arrays;
  13. import java.util.Date;
  14. import java.util.Objects;
  15. @Slf4j
  16. public class RegularlyUpdateStatus implements Job {
  17. @Override
  18. public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
  19. try {
  20. if ((boolean) QuartzManager.getInstance().getContext().get("flag")){
  21. JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
  22. String orderNo = String.valueOf(mergedJobDataMap.get("orderNo"));
  23. log.info("打款状态定时任务入参:{}",orderNo);
  24. OrderQueryResponse response = SpringUtil.getBean(RetrieveTTQFApi.class).orderQuery(orderNo);
  25. log.info("打款状态定时返回执行数据:{}", JSONObject.toJSONString(response.getResultModel()));
  26. if (response == null || !StringUtils.equals(response.getBizCode(),"0000")) {
  27. log.info("获取打款状态任务退出{}");
  28. QuartzManager.getInstance().removeJob(jobExecutionContext);
  29. }
  30. if (response.isSuccess()) {
  31. if (Arrays.stream(PayConstantStatus.ORDER_ARRAY).anyMatch(i -> Objects.equals(i,response.getResultModel().getStatus()))){
  32. updatePayLog(orderNo,response.getResultModel());
  33. log.info("获取打款状态任务退出");
  34. }
  35. QuartzManager.getInstance().removeJob(jobExecutionContext);
  36. }
  37. log.info("当前线程+++++++++++++{}",Thread.currentThread().getId());
  38. }else {
  39. log.info("获取天天企赋状态退出",jobExecutionContext.getJobDetail().getKey().getName());
  40. QuartzManager.getInstance().removeJob(jobExecutionContext);
  41. }
  42. } catch (SchedulerException e) {
  43. throw new RuntimeException(e);
  44. }
  45. }
  46. public void updatePayLog(String orderNo, OrderQueryResultModel resultModel){
  47. QueryWrapper<PaymentNoticeEntity> wrapper = new QueryWrapper<>();
  48. wrapper.eq("order_no",orderNo);
  49. PaymentNoticeEntity notice = SpringUtil.getBean(PaymentNoticeMapper.class).selectOne(wrapper);
  50. if (null == notice){
  51. PaymentNoticeEntity noticeEntity = JSONObject.parseObject(JSONObject.toJSONString(resultModel), PaymentNoticeEntity.class);
  52. if (null == noticeEntity.getPayTime()){
  53. noticeEntity.setPayTime(new Date());
  54. }
  55. noticeEntity.setCreateTime(new Date());
  56. int update = SpringUtil.getBean(PaymentNoticeMapper.class).insert(noticeEntity);
  57. log.info("获取打款状态成功正在保存===========:{}",orderNo ,"+++++", update > 0 ? "保存成功" : "保存失败");
  58. }
  59. }
  60. }