定时任务
parent
583548c3e6
commit
adc9cd6d98
|
|
@ -127,7 +127,10 @@ function addHandler() {
|
|||
}
|
||||
|
||||
function reset() {
|
||||
searchForm.value = {}
|
||||
searchForm.value = {
|
||||
current: 1,
|
||||
size: 20,
|
||||
}
|
||||
paging()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ import java.util.List;
|
|||
@Accessors(chain = true)
|
||||
public final class PageParam {
|
||||
/**
|
||||
* 每页显示条数,默认 10
|
||||
* 每页显示条数,默认 500
|
||||
*/
|
||||
private Integer size;
|
||||
|
||||
/**
|
||||
* 当前页
|
||||
* 当前页,默认 1
|
||||
*/
|
||||
private Integer current;
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
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();
|
||||
int total = data.size();
|
||||
int pages = Math.toIntExact(total % size == 0 ? (total / size) : (total / size + 1));
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ public class SearchTaskScheduleRecodeParam {
|
|||
* 任务结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 任务状态
|
||||
*/
|
||||
|
|
@ -37,7 +36,4 @@ public class SearchTaskScheduleRecodeParam {
|
|||
* 本次调度是否为手动触发
|
||||
*/
|
||||
private Boolean manually;
|
||||
|
||||
private Boolean builtin;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,13 +63,12 @@ public class MemoryTaskStoreService implements TaskStore {
|
|||
}
|
||||
|
||||
public PageResult<SearchTaskResult> paging(PageParam pageParam, SearchTaskParam searchTaskParam) {
|
||||
Integer current = pageParam.getCurrent();
|
||||
Integer size = pageParam.getSize();
|
||||
|
||||
String taskName = searchTaskParam.getTaskName();
|
||||
String fn = searchTaskParam.getFn();
|
||||
ScheduleType scheduleType = searchTaskParam.getScheduleType();
|
||||
|
||||
return PageResult.of(current, size,
|
||||
return PageResult.of(pageParam,
|
||||
TASKS.stream()
|
||||
.filter(it -> {
|
||||
boolean f = true;
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.njzscloud.common.core.ex.Exceptions;
|
||||
import com.njzscloud.common.mp.support.PageParam;
|
||||
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.pojo.entity.TaskExecuteLogEntity;
|
||||
import com.njzscloud.common.sichen.pojo.param.SearchTaskExecuteLogParam;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
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) {
|
||||
Long scheduleId = searchTaskExecuteLogParam.getScheduleId();
|
||||
TaskLogLevel logLevel = searchTaskExecuteLogParam.getLogLevel();
|
||||
LocalDateTime startLogTime = searchTaskExecuteLogParam.getStartLogTime();
|
||||
LocalDateTime endLogTime = searchTaskExecuteLogParam.getEndLogTime();
|
||||
Assert.notNull(scheduleId, () -> Exceptions.clierr("未指调度记录"));
|
||||
return PageResult.of(this.page(pageParam.toPage(), Wrappers.<TaskExecuteLogEntity>lambdaQuery()
|
||||
.eq(TaskExecuteLogEntity::getScheduleId, scheduleId)
|
||||
|
||||
.eq(logLevel != null, TaskExecuteLogEntity::getLogLevel, logLevel)
|
||||
.ge(startLogTime != null, TaskExecuteLogEntity::getLogTime, startLogTime)
|
||||
.le(endLogTime != null, TaskExecuteLogEntity::getLogTime, endLogTime)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.njzscloud.common.mp.support.PageParam;
|
|||
import com.njzscloud.common.mp.support.PageResult;
|
||||
import com.njzscloud.common.sichen.config.TaskProperties;
|
||||
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.pojo.entity.TaskExecuteLogEntity;
|
||||
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) {
|
||||
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("未指定任务"));
|
||||
return PageResult.of(this.page(pageParam.toPage(), Wrappers.<TaskScheduleRecodeEntity>lambdaQuery()
|
||||
.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 * * ?")
|
||||
public void clearLog() {
|
||||
TaskHandle.info("执行日志清理任务");
|
||||
TaskProperties.Logger logger = taskProperties.getLogger();
|
||||
int history = logger.getHistory();
|
||||
if (history < 1) history = 1;
|
||||
DateTime historyTime = DateUtil.beginOfDay(DateUtil.offsetDay(new DateTime(), -history));
|
||||
TaskHandle.info("删除 {} 之前的日志", historyTime);
|
||||
taskExecuteLogService.remove(Wrappers.lambdaQuery(TaskExecuteLogEntity.class).lt(TaskExecuteLogEntity::getLogTime, historyTime));
|
||||
TaskHandle.info("删除日志清理完成");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue