package com.stylefeng.guns.modular.system.util;
|
|
import com.stylefeng.guns.modular.account.service.UserWithdrawalService;
|
import com.stylefeng.guns.modular.system.service.IDriverService;
|
import com.stylefeng.guns.modular.system.service.IOrderService;
|
import com.stylefeng.guns.modular.system.service.IUserMerchantCouponService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
import org.springframework.boot.web.server.WebServer;
|
import org.springframework.context.ApplicationListener;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashSet;
|
import java.util.Set;
|
|
|
/**
|
* 定时任务工具类
|
*/
|
@Component
|
public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private IOrderService orderService;
|
|
@Autowired
|
private JGPushUtil jgPushUtil;
|
|
@Autowired
|
private IUserMerchantCouponService userMerchantCouponService;
|
@Autowired
|
private UserWithdrawalService userWithdrawalService;
|
|
public Set<Integer> driverIds = new HashSet<>();//存储需要提醒司机预约单的司机id
|
|
|
|
|
/**
|
* 每隔一分钟去处理的定时任务
|
*/
|
@Scheduled(fixedRate = 1000 * 60)
|
public void taskMinute(){
|
try {
|
//修改满足活动条件的数据(在线时长,订单量)
|
driverService.taskMinute();
|
//处于预约单
|
orderService.reservationOrder();
|
//处理车载端断电后的自动下班
|
driverService.taskOffWork();
|
//处理结束订单后30分钟解绑小号功能
|
orderService.taskMidAxbUnBindSend();
|
//修改过期的商家券
|
userMerchantCouponService.updateExpired();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
|
|
/**
|
* 每隔五分钟去处理的定时任务
|
*/
|
@Scheduled(fixedRate = 1000 * 60 * 5)
|
public void taskFiveMinute(){
|
try {
|
for (Integer id: driverIds){
|
jgPushUtil.push(1, "您的预约订单出行时间就要到了,请尽快前往预约地点接乘客", "DRIVER" + id);
|
}
|
this.driverIds.clear();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 每天的凌晨执行的任务
|
*/
|
@Scheduled(cron = "0 0 0 * * *")
|
public void taskDay() {
|
try {
|
//生成当天的司机活动
|
driverService.addTodayActivity();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
@Override
|
public void onApplicationEvent(WebServerInitializedEvent event) {
|
// 获取环境对象
|
WebServer webServer = event.getWebServer();
|
// 获取端口号
|
int port = webServer.getPort();
|
// 打印端口号
|
System.out.println("Spring Boot应用已启动,访问端口:" + port);
|
}
|
}
|