package com.supersavedriving.driver.modular.system.util;
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.supersavedriving.driver.modular.system.model.Order;
|
import com.supersavedriving.driver.modular.system.service.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.StringUtils;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 定时任务工具类
|
*/
|
@Component
|
public class TaskUtil {
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private IAccountChangeDetailService accountChangeDetailService;
|
|
@Autowired
|
private IOrderService orderService;
|
|
@Autowired
|
private IYouTuiDriverService youTuiDriverService;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private IDriverWorkService driverWorkService;
|
|
// 每秒执行一次的定时任务 接单大厅取消订单
|
@Scheduled(fixedRate = 1000)
|
public void taskSecond(){
|
// 查询所有待接单订单
|
List<Order> list = new ArrayList<>();
|
List<Order> orders = orderService.selectList(new EntityWrapper<Order>()
|
.eq("hallOrder", 1)
|
.eq("state",101)
|
.isNotNull("endTime"));
|
for (Order order : orders) {
|
if (order.getEndTime().before(new Date())){
|
// 已取消
|
order.setState(301);
|
list.add(order);
|
}
|
}
|
// 批量取消订单
|
System.err.println("取消数量:"+list.size());
|
System.err.println("取消订单ids:"+list.stream().map(Order::getId).collect(Collectors.toList()));
|
if (!list.isEmpty()){
|
orderService.updateBatchById(list);
|
}
|
}
|
/**
|
* 5秒推送
|
*/
|
@Scheduled(fixedRate = 1000 * 5)
|
public void task5Seconds(){
|
try {
|
Set<String> orderServices = redisUtil.getSetAllValue("orderService");
|
for (String s : orderServices) {
|
orderService.pushOrderInfo(Long.valueOf(s));//开始推送订单数据
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
public void task5SecondsCheck(){
|
try {
|
Set<String> orderServices = redisUtil.getSetAllValue("orderService_check");
|
for (String s : orderServices) {
|
orderService.pushCheckOrderInfo(Long.valueOf(s));//开始推送订单数据
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
|
/**
|
* 每隔一分钟去处理的定时任务
|
*/
|
@Scheduled(fixedRate = 1000 * 60)
|
public void taskMinute(){
|
try {
|
driverWorkService.taskDriverOffWork();
|
youTuiDriverService.editState();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 每天的凌晨执行的任务
|
*/
|
@Scheduled(cron = "0 0 0 * * *")
|
public void taskDay(){
|
try {
|
orderService.completeCollection();
|
// accountChangeDetailService.deductionInsurance();
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
|
|
/**
|
* 每月1日凌晨执行的任务
|
*/
|
@Scheduled(cron = "0 0 0 1 * *")
|
public void taskMonth1(){
|
try {
|
driverService.emptyIntegral();
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 每月16日凌晨执行的任务
|
*/
|
@Scheduled(cron = "0 0 0 16 * *")
|
public void taskMonth16(){
|
try {
|
driverService.emptyIntegral();
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
}
|