定时任务

master
lzq 2025-12-19 10:46:07 +08:00
parent 583548c3e6
commit adc9cd6d98
7 changed files with 33 additions and 12 deletions

View File

@ -127,7 +127,10 @@ function addHandler() {
} }
function reset() { function reset() {
searchForm.value = {} searchForm.value = {
current: 1,
size: 20,
}
paging() paging()
} }

View File

@ -18,12 +18,12 @@ import java.util.List;
@Accessors(chain = true) @Accessors(chain = true)
public final class PageParam { public final class PageParam {
/** /**
* 10 * 500
*/ */
private Integer size; private Integer size;
/** /**
* * 1
*/ */
private Integer current; private Integer current;

View File

@ -46,7 +46,11 @@ public final class PageResult<T> {
return new PageResult<>(page.getRecords(), (int) page.getTotal(), (int) page.getPages(), (int) page.getCurrent(), (int) page.getSize()); return new PageResult<>(page.getRecords(), (int) page.getTotal(), (int) page.getPages(), (int) page.getCurrent(), (int) page.getSize());
} }
public static <E> PageResult<E> of(int current, int size, List<E> data) { public static <E> PageResult<E> of(PageParam pageParam, List<E> data) {
Integer current_ = pageParam.getCurrent();
Integer size_ = pageParam.getSize();
int current = current_ == null ? 1 : current_;
int size = size_ == null ? 500 : size_;
if (data == null) data = Collections.emptyList(); if (data == null) data = Collections.emptyList();
int total = data.size(); int total = data.size();
int pages = Math.toIntExact(total % size == 0 ? (total / size) : (total / size + 1)); int pages = Math.toIntExact(total % size == 0 ? (total / size) : (total / size + 1));

View File

@ -28,7 +28,6 @@ public class SearchTaskScheduleRecodeParam {
* *
*/ */
private LocalDateTime endTime; private LocalDateTime endTime;
/** /**
* *
*/ */
@ -37,7 +36,4 @@ public class SearchTaskScheduleRecodeParam {
* *
*/ */
private Boolean manually; private Boolean manually;
private Boolean builtin;
} }

View File

@ -63,13 +63,12 @@ public class MemoryTaskStoreService implements TaskStore {
} }
public PageResult<SearchTaskResult> paging(PageParam pageParam, SearchTaskParam searchTaskParam) { public PageResult<SearchTaskResult> paging(PageParam pageParam, SearchTaskParam searchTaskParam) {
Integer current = pageParam.getCurrent();
Integer size = pageParam.getSize();
String taskName = searchTaskParam.getTaskName(); String taskName = searchTaskParam.getTaskName();
String fn = searchTaskParam.getFn(); String fn = searchTaskParam.getFn();
ScheduleType scheduleType = searchTaskParam.getScheduleType(); ScheduleType scheduleType = searchTaskParam.getScheduleType();
return PageResult.of(current, size, return PageResult.of(pageParam,
TASKS.stream() TASKS.stream()
.filter(it -> { .filter(it -> {
boolean f = true; boolean f = true;

View File

@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njzscloud.common.core.ex.Exceptions; import com.njzscloud.common.core.ex.Exceptions;
import com.njzscloud.common.mp.support.PageParam; import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult; import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.common.sichen.contant.TaskLogLevel;
import com.njzscloud.common.sichen.mapper.TaskExecuteLogMapper; import com.njzscloud.common.sichen.mapper.TaskExecuteLogMapper;
import com.njzscloud.common.sichen.pojo.entity.TaskExecuteLogEntity; import com.njzscloud.common.sichen.pojo.entity.TaskExecuteLogEntity;
import com.njzscloud.common.sichen.pojo.param.SearchTaskExecuteLogParam; import com.njzscloud.common.sichen.pojo.param.SearchTaskExecuteLogParam;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
public class TaskExecuteLogService extends ServiceImpl<TaskExecuteLogMapper, TaskExecuteLogEntity> implements IService<TaskExecuteLogEntity> { public class TaskExecuteLogService extends ServiceImpl<TaskExecuteLogMapper, TaskExecuteLogEntity> implements IService<TaskExecuteLogEntity> {
@ -50,10 +52,15 @@ public class TaskExecuteLogService extends ServiceImpl<TaskExecuteLogMapper, Tas
*/ */
public PageResult<TaskExecuteLogEntity> paging(PageParam pageParam, SearchTaskExecuteLogParam searchTaskExecuteLogParam) { public PageResult<TaskExecuteLogEntity> paging(PageParam pageParam, SearchTaskExecuteLogParam searchTaskExecuteLogParam) {
Long scheduleId = searchTaskExecuteLogParam.getScheduleId(); Long scheduleId = searchTaskExecuteLogParam.getScheduleId();
TaskLogLevel logLevel = searchTaskExecuteLogParam.getLogLevel();
LocalDateTime startLogTime = searchTaskExecuteLogParam.getStartLogTime();
LocalDateTime endLogTime = searchTaskExecuteLogParam.getEndLogTime();
Assert.notNull(scheduleId, () -> Exceptions.clierr("未指调度记录")); Assert.notNull(scheduleId, () -> Exceptions.clierr("未指调度记录"));
return PageResult.of(this.page(pageParam.toPage(), Wrappers.<TaskExecuteLogEntity>lambdaQuery() return PageResult.of(this.page(pageParam.toPage(), Wrappers.<TaskExecuteLogEntity>lambdaQuery()
.eq(TaskExecuteLogEntity::getScheduleId, scheduleId) .eq(TaskExecuteLogEntity::getScheduleId, scheduleId)
.eq(logLevel != null, TaskExecuteLogEntity::getLogLevel, logLevel)
.ge(startLogTime != null, TaskExecuteLogEntity::getLogTime, startLogTime)
.le(endLogTime != null, TaskExecuteLogEntity::getLogTime, endLogTime)
)); ));
} }
} }

View File

@ -15,6 +15,7 @@ import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult; import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.common.sichen.config.TaskProperties; import com.njzscloud.common.sichen.config.TaskProperties;
import com.njzscloud.common.sichen.contant.TaskLogLevel; import com.njzscloud.common.sichen.contant.TaskLogLevel;
import com.njzscloud.common.sichen.contant.TaskStatus;
import com.njzscloud.common.sichen.mapper.TaskScheduleRecodeMapper; import com.njzscloud.common.sichen.mapper.TaskScheduleRecodeMapper;
import com.njzscloud.common.sichen.pojo.entity.TaskExecuteLogEntity; import com.njzscloud.common.sichen.pojo.entity.TaskExecuteLogEntity;
import com.njzscloud.common.sichen.pojo.entity.TaskScheduleRecodeEntity; import com.njzscloud.common.sichen.pojo.entity.TaskScheduleRecodeEntity;
@ -70,9 +71,17 @@ public class TaskScheduleRecodeService extends ServiceImpl<TaskScheduleRecodeMap
*/ */
public PageResult<TaskScheduleRecodeEntity> paging(PageParam pageParam, SearchTaskScheduleRecodeParam searchTaskScheduleRecodeParam) { public PageResult<TaskScheduleRecodeEntity> paging(PageParam pageParam, SearchTaskScheduleRecodeParam searchTaskScheduleRecodeParam) {
Long taskId = searchTaskScheduleRecodeParam.getTaskId(); Long taskId = searchTaskScheduleRecodeParam.getTaskId();
LocalDateTime startTime = searchTaskScheduleRecodeParam.getStartTime();
LocalDateTime endTime = searchTaskScheduleRecodeParam.getEndTime();
TaskStatus taskStatus = searchTaskScheduleRecodeParam.getTaskStatus();
Boolean manually = searchTaskScheduleRecodeParam.getManually();
Assert.notNull(taskId, () -> Exceptions.clierr("未指定任务")); Assert.notNull(taskId, () -> Exceptions.clierr("未指定任务"));
return PageResult.of(this.page(pageParam.toPage(), Wrappers.<TaskScheduleRecodeEntity>lambdaQuery() return PageResult.of(this.page(pageParam.toPage(), Wrappers.<TaskScheduleRecodeEntity>lambdaQuery()
.eq(TaskScheduleRecodeEntity::getTaskId, taskId) .eq(TaskScheduleRecodeEntity::getTaskId, taskId)
.ge(startTime != null, TaskScheduleRecodeEntity::getScheduleTime, startTime)
.le(endTime != null, TaskScheduleRecodeEntity::getScheduleTime, endTime)
.eq(taskStatus != null, TaskScheduleRecodeEntity::getTaskStatus, taskStatus)
.eq(manually != null, TaskScheduleRecodeEntity::getManually, manually)
)); ));
} }
@ -177,10 +186,13 @@ public class TaskScheduleRecodeService extends ServiceImpl<TaskScheduleRecodeMap
@Task(id = 1, name = "日志清理", logLevel = TaskLogLevel.INFO, cron = "1 0 0 * * ?") @Task(id = 1, name = "日志清理", logLevel = TaskLogLevel.INFO, cron = "1 0 0 * * ?")
public void clearLog() { public void clearLog() {
TaskHandle.info("执行日志清理任务");
TaskProperties.Logger logger = taskProperties.getLogger(); TaskProperties.Logger logger = taskProperties.getLogger();
int history = logger.getHistory(); int history = logger.getHistory();
if (history < 1) history = 1; if (history < 1) history = 1;
DateTime historyTime = DateUtil.beginOfDay(DateUtil.offsetDay(new DateTime(), -history)); DateTime historyTime = DateUtil.beginOfDay(DateUtil.offsetDay(new DateTime(), -history));
TaskHandle.info("删除 {} 之前的日志", historyTime);
taskExecuteLogService.remove(Wrappers.lambdaQuery(TaskExecuteLogEntity.class).lt(TaskExecuteLogEntity::getLogTime, historyTime)); taskExecuteLogService.remove(Wrappers.lambdaQuery(TaskExecuteLogEntity.class).lt(TaskExecuteLogEntity::getLogTime, historyTime));
TaskHandle.info("删除日志清理完成");
} }
} }