kongdeqiang
2023-03-02 ee83188936c8ac306144f6c8cd119b6d7574dfc6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.boying.job;
 
import cn.hutool.core.thread.ThreadUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.boying.common.ReturnData;
import com.boying.common.SystemConfigProperties;
import com.boying.controller.phone.PayController;
import com.boying.entity.Barrier;
import com.boying.entity.OutPark;
import com.boying.service.*;
import com.boying.util.HTTPEntityUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class PayResultScheduled {
 
 
    @Autowired
    private OutParkService outParkService;
    @Autowired
    private BarrierService barrierService;
    @Autowired
    private SystemConfigProperties systemConfigProperties;
    @Autowired
    private PayController payController;
 
    Boolean taskFlag = false;
 
    @Scheduled(cron = "0/2 * * * * ?")
    public void execute() throws Exception {
        if(taskFlag == true){
            System.out.println("正在运行,强制退出-------》");
            return;
        }
        taskFlag = true;
        QueryWrapper<Barrier> barrierQueryWrapper = new QueryWrapper<>();
        barrierQueryWrapper.lambda()
                .eq(Barrier::getType,0)
                .isNotNull(Barrier::getCarNo);
        for (Barrier barrier : barrierService.list(barrierQueryWrapper)) {
            //根据道闸查询最后一个出场纪录
            QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(OutPark::getBarrierId,barrier.getId())
                    .eq(OutPark::getStatus,0)
                    .eq(OutPark::getCarNo,barrier.getCarNo())
                    .ne(OutPark::getPrice,0)
                    .isNotNull(OutPark::getPayCode)
                    .orderByDesc(OutPark::getCreateTime);
            List<OutPark> outParks = outParkService.list(wrapper);
            if(outParks.size()>0){
                //查询到最后一个出场没缴费的记录
                OutPark outPark = outParks.get(0);
                log.info("查询到最后的出场信息为:"+outPark);
                //查询缴款码记录更新
                doPay(outPark);
            }
        }
        taskFlag = false;
    }
 
    public void doPay(OutPark outPark){
        ThreadUtil.execute(() -> {
            //查询缴款码记录更新
            Map<String,Object> map1 = new HashMap<>();
            map1.put("eticketnum",outPark.getPayCode());
            String urlRoad = systemConfigProperties.getETICKET();
            String urlIp = systemConfigProperties.getIp4();
            RestTemplate restTemplate = new RestTemplate();
            ResponseEntity<ReturnData> entity = restTemplate.postForEntity(urlIp+urlRoad, HTTPEntityUtil.setEntity(map1), ReturnData.class);
            log.info("查询是否支付成功返回为:"+entity.getBody());
            System.out.println("查询是否支付成功返回为:"+entity.getBody());
            if(entity.getBody().getCode() == 1){
                //更新订单
                payController.updateOrderRecord(outPark.getPayCode(),"03");
            }
 
        });
    }
 
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            String s= i+"";
            ThreadUtil.execute(() -> {
              //  System.out.println(s);
            });
        }
    }
}