清除火箭重置定时任务
This commit is contained in:
parent
b1e66d134c
commit
3cbcb484cc
@ -1,61 +0,0 @@
|
||||
package com.red.circle.other.app.scheduler;
|
||||
|
||||
import com.red.circle.other.domain.gateway.RocketStatusGateway;
|
||||
import com.red.circle.other.domain.rocket.RocketStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 火箭每日重置定时任务
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-01-15
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RocketDailyResetTask {
|
||||
|
||||
private final RocketStatusGateway rocketStatusGateway;
|
||||
|
||||
/**
|
||||
* 每天00:00执行重置
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void resetDaily() {
|
||||
log.info("开始执行火箭每日重置任务");
|
||||
|
||||
try {
|
||||
String today = LocalDate.now().toString();
|
||||
|
||||
// 查询所有处于充能状态的火箭
|
||||
List<RocketStatus> chargingRockets = rocketStatusGateway.findAllCharging(today);
|
||||
|
||||
log.info("找到需要重置的火箭数量: {}", chargingRockets.size());
|
||||
|
||||
// 重置每个火箭
|
||||
for (RocketStatus rocketStatus : chargingRockets) {
|
||||
try {
|
||||
// TODO: 保存昨日历史记录
|
||||
|
||||
// 重置状态
|
||||
rocketStatus.reset();
|
||||
rocketStatusGateway.save(rocketStatus);
|
||||
|
||||
log.info("火箭重置成功, roomId={}", rocketStatus.getRoomId());
|
||||
} catch (Exception e) {
|
||||
log.error("火箭重置失败, roomId={}", rocketStatus.getRoomId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("火箭每日重置任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("火箭每日重置任务执行失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user