提交 8a12de3b authored 作者: Matrix's avatar Matrix

[核查模块] 核查周期保存功能-bug修复

上级 a65f5ced
......@@ -16,15 +16,15 @@ public enum TaskPeriod {
/**
* 月度
*/
monthly("0 0 0 1 * ? *"),
monthly("0 0 0 1 * *"),
/**
* 季度
*/
quarterly("0 0 0 1 3/3 ? *"),
quarterly("0 0 0 1 3/3 *"),
/**
* 年度
*/
yearly("0 0 0 1 3/3 ? *");
yearly("0 0 0 1 1 *");
private final String cron;
......
......@@ -35,6 +35,7 @@ import com.tykj.dev.misc.base.StatusEnum;
import com.tykj.dev.misc.utils.JacksonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -131,8 +132,9 @@ public class DeviceCheckController {
* @return
*/
@ApiOperation(value = "更新自动核查周期", notes = "更新自动核查周期")
@PutMapping("/task/{period}")
public ResponseEntity updateTaskPeriod(@PathVariable Integer periodId) {
@PutMapping("/task/{periodId}")
public ResponseEntity updateTaskPeriod(
@PathVariable @ApiParam(value = "核查周期,1-月度 2-季度 3-年度",example = "1") Integer periodId) {
if (periodId < 1 || periodId > 3) {
return ResponseEntity.status(400).body(new ResultObj<>("提供了错误的周期参数!应该是 1/2/3 , 您提供的是" + periodId));
}
......@@ -146,7 +148,7 @@ public class DeviceCheckController {
if (startSuccess) {
String nextTime = ccService.getNextTaskDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
return ResponseEntity.ok(new ResultObj<>(String.format("更新自动核查周期成功,下一次任务的执行时间为%s %n", nextTime)));
return ResponseEntity.ok(new ResultObj<>(String.format("更新自动核查周期成功,下一次任务的执行时间为%s", nextTime)));
} else {
return ResponseEntity.status(400).body("自动核查更新周期失败了!");
}
......
......@@ -331,7 +331,13 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine
@Override
public LocalDate getNextTaskDate() {
// 获得当前的period
TaskPeriod period = periodDao.findTopByOrderByIdDesc().getCronExpression();
DeviceCheckPeriod dcp = periodDao.findTopByOrderByIdDesc();
TaskPeriod period;
if (dcp == null) {
period = TaskPeriod.yearly;
} else {
period = dcp.getCronExpression();
}
LocalDate now = LocalDate.now();
switch (period) {
case yearly:
......@@ -356,7 +362,13 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine
public boolean startAutoCheckCron() {
boolean flag = false;
//从数据库动态获取执行周期
TaskPeriod period = getCurrentTaskPeriod().getCronExpression();
TaskPeriod period;
// 如果数据库里没有设置,那么就使用默认的年
if (getCurrentTaskPeriod() == null) {
period = TaskPeriod.yearly;
} else {
period = getCurrentTaskPeriod().getCronExpression();
}
String cron = period.getCron();
future = threadPoolTaskScheduler.schedule(this::autoCheck, new CronTrigger(cron));
if (future != null) {
......@@ -418,5 +430,7 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine
public void run(String... args) throws Exception {
//开启计划任务
startAutoCheckCron();
log.info("[核查模块] 初始化开启任务成功");
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论