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);
|
});
|
}
|
}
|
}
|