package com.stylefeng.guns.modular.system.util;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.stylefeng.guns.modular.system.dao.DriverWorkMapper;
|
import com.stylefeng.guns.modular.system.model.Driver;
|
import com.stylefeng.guns.modular.system.model.DriverWork;
|
import com.stylefeng.guns.modular.system.model.TSysFaceDistinguish;
|
import com.stylefeng.guns.modular.system.service.IDriverService;
|
import com.stylefeng.guns.modular.system.service.IOrderService;
|
import com.stylefeng.guns.modular.system.service.ITSysFaceDistinguishService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
|
/**
|
* 定时任务工具类
|
*/
|
@Component
|
public class TaskUtil {
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private IOrderService orderService;
|
|
@Autowired
|
private JGPushUtil jgPushUtil;
|
@Resource
|
private DriverWorkMapper driverWorkMapper;
|
|
@Autowired
|
private ITSysFaceDistinguishService faceDistinguishService;
|
|
@Autowired
|
private PushUtil pushUtil;
|
|
|
|
public Set<Integer> driverIds = new HashSet<>();//存储需要提醒司机预约单的司机id
|
|
|
//每隔一分钟去检测司机人脸
|
@Scheduled(fixedRate = 1000 * 60)
|
public void driverFace(){
|
//拿到后台配置的人脸识别配置
|
TSysFaceDistinguish tSysFaceDistinguish = faceDistinguishService.selectOne(null);
|
//如果是关闭就结束
|
if (tSysFaceDistinguish.getIsOpen()==2){
|
return;
|
}
|
System.err.println("================正在进行人脸识别任务");
|
//获取上线司机的ids
|
List<DriverWork> driverIds = driverWorkMapper.selectList(new EntityWrapper<DriverWork>().eq("state", 1));
|
//判断司机是否有正在进行中的订单,获取闲置司机id
|
List<Integer> drivers = new ArrayList<>();
|
for (DriverWork driverWork : driverIds) {
|
try {
|
List<Map<String, Object>> list = orderService.queryOrderList(1, 1, 10, driverWork.getDriverId());
|
if(list.isEmpty()){
|
drivers.add(driverWork.getDriverId());
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
//从后台获取人脸识别的配置,比对最后一次打卡时间后进行socket推送
|
List<Integer> pullDrivers = new ArrayList<>();
|
|
List<Driver> todrivers = driverService.selectBatchIds(drivers);
|
Date now = new Date();
|
for (Driver todriver : todrivers) {
|
if (todriver.getLastFacialTime()==null){
|
pullDrivers.add(todriver.getId());
|
continue;
|
}
|
Date lastFacialTime = todriver.getLastFacialTime();
|
// 创建一个Calendar实例并设置为给定的日期
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(lastFacialTime);
|
|
// 增加2分钟
|
calendar.add(Calendar.MINUTE, 2);
|
Date updatedDate = calendar.getTime();
|
int compareResult = now.compareTo(updatedDate);
|
if (compareResult >= 0) {
|
pullDrivers.add(todriver.getId());
|
}
|
}
|
|
if (!pullDrivers.isEmpty()){
|
for (Integer pullDriver : pullDrivers) {
|
pushUtil.pushFaceTime(2,pullDriver);
|
}
|
}
|
|
|
}
|
|
|
/**
|
* 每隔一分钟去处理的定时任务
|
*/
|
@Scheduled(fixedRate = 1000 * 60)
|
public void taskMinute(){
|
try {
|
//修改满足活动条件的数据(在线时长,订单量)
|
driverService.taskMinute();
|
//处于预约单
|
orderService.reservationOrder();
|
//处理车载端断电后的自动下班
|
driverService.taskOffWork();
|
//处理结束订单后30分钟解绑小号功能
|
// orderService.taskMidAxbUnBindSend();
|
} 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();
|
}
|
}
|
|
|
//
|
// /**
|
// * 每月第一天的1点执行的任务
|
// */
|
// @Scheduled(cron = "0 0 1 1 * *")
|
// public void taskMonth(){
|
// try {
|
//
|
// }catch (Exception e){
|
// e.printStackTrace();
|
// }
|
// }
|
}
|