package com.zy.acs.manager.core.scheduler;
|
|
import com.zy.acs.common.constant.RedisConstant;
|
import com.zy.acs.common.enums.AgvStatusType;
|
import com.zy.acs.common.utils.RedisSupport;
|
import com.zy.acs.manager.manager.entity.*;
|
import com.zy.acs.manager.manager.enums.TaskStsType;
|
import com.zy.acs.manager.manager.service.*;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.List;
|
|
@Slf4j
|
@Component
|
public class StatisticsScheduler {
|
|
private final RedisSupport redis = RedisSupport.defaultRedisSupport;
|
|
@Autowired
|
private AgvService agvService;
|
|
@Autowired
|
private AgvDetailService agvDetailService;
|
|
@Autowired
|
private TaskService taskService;
|
|
@Autowired
|
private AgvDurationService agvDurationService;
|
|
@Autowired
|
private OfflineLogService offlineLogService;
|
|
/**
|
* 定时检查AGV是否掉线,并且保存记录
|
*/
|
@Scheduled(cron = "0/5 * * * * ? ")
|
public void execute() {
|
List<Agv> list = agvService.list();
|
Object object = null;
|
OfflineLog offlineLog;
|
for (Agv agv : list) {
|
if (agv.getStatus() == 1) {
|
object = redis.getObject(RedisConstant.AGV_ONLINE_FLAG, agv.getUuid());
|
if (object == null) {
|
offlineLog = offlineLogService.getTopOfflineLog(agv.getId());
|
if (offlineLog == null) {
|
offlineLog = new OfflineLog();
|
offlineLog.setAgvId(agv.getId());
|
offlineLog.setHappenTime(new Date());
|
offlineLogService.save(offlineLog);
|
}
|
} else {
|
offlineLog = offlineLogService.getTopOfflineLog(agv.getId());
|
if (offlineLog != null) {
|
offlineLog.setResetTime(new Date());
|
offlineLog.setDuration(offlineLog.getResetTime().getTime() - offlineLog.getHappenTime().getTime());
|
offlineLogService.updateById(offlineLog);
|
}
|
}
|
}
|
}
|
}
|
|
@Scheduled(cron = "0/5 * * * * ? ")
|
public void execute2() {
|
List<AgvDuration> agvDurations = agvDurationService.listUnFinish();
|
for (AgvDuration agvDuration : agvDurations) {
|
Task task = taskService.getById(agvDuration.getTaskNo());
|
if (task.getTaskSts() == TaskStsType.COMPLETE.val()) {
|
AgvDetail agvDetail = agvDetailService.selectByAgvId(agvDuration.getAgvId());
|
if (agvDetail.getAgvStatus() != AgvStatusType.CHARGE) {
|
agvDuration.setResetTime(new Date());
|
agvDuration.setDuration(agvDuration.getResetTime().getTime() - agvDuration.getHappenTime().getTime());
|
agvDurationService.updateById(agvDuration);
|
}
|
} else if (task.getTaskSts() == TaskStsType.CANCEL.val()) {
|
agvDurationService.removeById(agvDuration.getId());
|
} else {
|
|
}
|
}
|
}
|
}
|