| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package com.ydtech.modules.ttqf;
- import cn.hutool.extra.spring.SpringUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.ipaynow.jiaxin.domain.OrderQueryResultModel;
- import com.ipaynow.jiaxin.response.OrderQueryResponse;
- import com.ydtech.modules.ttqf.dao.PaymentNoticeMapper;
- import com.ydtech.modules.ttqf.entity.PaymentNoticeEntity;
- import com.ydtech.utils.StringUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Component;
- import java.util.*;
- @Component
- @Slf4j
- public class RegularlyPaymentStatus {
- @Async
- public void updatePaymentStatus(String orderNo){
- Timer timer = new Timer();
- final int[] executionCount = {1};
- TimerTask task = new TimerTask() {
- @Override
- public void run() {
- try {
- log.info("打款状态定时任务入参:{}",orderNo);
- OrderQueryResponse response = SpringUtil.getBean(RetrieveTTQFApi.class).orderQuery(orderNo);
- log.info("打款状态定时返回执行数据:{}", JSONObject.toJSONString(response.getResultModel()));
- if (response == null || !StringUtils.equals(response.getBizCode(),"0000")) {
- log.info("获取打款状态任务退出{}");
- timer.cancel();
- }
- if (response.isSuccess()) {
- if (Arrays.stream(PayConstantStatus.ORDER_ARRAY).anyMatch(i -> Objects.equals(i,response.getResultModel().getStatus()))){
- updatePayLog(orderNo,response.getResultModel());
- log.info("获取打款状态任务退出");
- timer.cancel();
- }
- }
- log.info("当前线程+++++++++++++{}",Thread.currentThread().getId());
- // if (executionCount[0] == 20){
- // log.info("获取打款状态任务退出{}");
- // timer.cancel();
- // }
- }catch (Exception e){
- log.error("定时获取打款状态任务异常:{}",e.getMessage());
- timer.cancel();
- }
- executionCount[0]++;
- }
- };
- timer.schedule(task, 2000, 5000);
- }
- public void updatePayLog(String orderNo, OrderQueryResultModel resultModel){
- QueryWrapper<PaymentNoticeEntity> wrapper = new QueryWrapper<>();
- wrapper.eq("order_no",orderNo);
- PaymentNoticeEntity notice = SpringUtil.getBean(PaymentNoticeMapper.class).selectOne(wrapper);
- if (null == notice){
- PaymentNoticeEntity noticeEntity = JSONObject.parseObject(JSONObject.toJSONString(resultModel), PaymentNoticeEntity.class);
- if (null == noticeEntity.getPayTime()){
- noticeEntity.setPayTime(new Date());
- }
- noticeEntity.setCreateTime(new Date());
- int update = SpringUtil.getBean(PaymentNoticeMapper.class).insert(noticeEntity);
- log.info("获取打款状态成功正在保存===========:{}",orderNo ,"+++++", update > 0 ? "保存成功" : "保存失败");
- }
- }
- }
|