mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
[新增][定时任务]重新申请 ApiAccessLog、ApiErrorLog、JobLog 3个日志的定时清理
This commit is contained in:
@ -1,12 +1,9 @@
|
||||
package cn.iocoder.yudao.framework.quartz.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.quartz.core.job.JobLogJobHandler;
|
||||
import cn.iocoder.yudao.framework.quartz.core.job.LogJobProperties;
|
||||
import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.Scheduler;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@ -18,7 +15,6 @@ import java.util.Optional;
|
||||
@AutoConfiguration
|
||||
@EnableScheduling // 开启 Spring 自带的定时任务
|
||||
@Slf4j
|
||||
@EnableConfigurationProperties(LogJobProperties.class)
|
||||
public class YudaoQuartzAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ -30,10 +26,4 @@ public class YudaoQuartzAutoConfiguration {
|
||||
return new SchedulerManager(scheduler.get());
|
||||
}
|
||||
|
||||
// TODO @j-sentinel:这个 job,先拿到 infra biz 里面实现哈;
|
||||
@Bean
|
||||
public JobLogJobHandler jobLogJobHandler(LogJobProperties logJobProperties){
|
||||
return new JobLogJobHandler(logJobProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.quartz.core.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.quartz.core.service.JobLogFrameworkService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
// TODO @j-sentinel:名字和项目里其它保持统一,可以叫 JobLogCleanJob,不用带 handler 哈
|
||||
/**
|
||||
* // TODO @j-sentinel:要写下类注释噢,就是这个类要干啥;然后下面两个应该是 @author 和 @since
|
||||
* @Author: j-sentinel
|
||||
* @Date: 2023/9/30 20:40
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class JobLogJobHandler implements JobHandler {
|
||||
|
||||
private LogJobProperties logJobProperties;
|
||||
|
||||
public JobLogJobHandler(LogJobProperties logJobProperties) {
|
||||
this.logJobProperties = logJobProperties;
|
||||
}
|
||||
|
||||
@Resource
|
||||
private JobLogFrameworkService jobLogFrameworkService;
|
||||
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
Integer integer = jobLogFrameworkService.timingJobCleanLog(logJobProperties.getJobCleanRetainDay());
|
||||
log.info("定时执行清理定时任务日志数量({})个",integer);
|
||||
return String.format("定时执行清理定时任务日志数量 %s 个", integer);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.quartz.core.job;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
// TODO @j-sentinel:这个配置类,先暂时不做,每个 Job 里面定一个静态类。其实不是所有的变量,都需要配置化,因为它本身基本也不会改动。
|
||||
/**
|
||||
* @Author: j-sentinel
|
||||
* @Date: 2023/9/30 16:17
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "yudao.clean-job")
|
||||
public class LogJobProperties {
|
||||
|
||||
private int accessRetainDay = 7;
|
||||
|
||||
private int errorRetainDay = 8;
|
||||
|
||||
private int jobCleanRetainDay = 7;
|
||||
|
||||
}
|
@ -40,11 +40,4 @@ public interface JobLogFrameworkService {
|
||||
@NotNull(message = "结束时间不能为空") LocalDateTime endTime,
|
||||
@NotNull(message = "运行时长不能为空") Integer duration,
|
||||
boolean success, String result);
|
||||
|
||||
/**
|
||||
* 清理 @param jobCleanRetainDay 天的访问日志
|
||||
*
|
||||
* @param jobCleanRetainDay 超过多少天就进行清理
|
||||
*/
|
||||
Integer timingJobCleanLog(Integer jobCleanRetainDay);
|
||||
}
|
||||
|
@ -61,12 +61,6 @@
|
||||
<artifactId>jsoup</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Job 定时任务相关 -->
|
||||
<!-- TODO @j-sentinel:去掉这个依赖哈; -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-job</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -1,14 +1,11 @@
|
||||
package cn.iocoder.yudao.framework.apilog.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.filter.ApiAccessLogFilter;
|
||||
import cn.iocoder.yudao.framework.apilog.core.job.ApiAccessLogJobHandler;
|
||||
import cn.iocoder.yudao.framework.apilog.core.job.ApiErrorLogJobHandler;
|
||||
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
|
||||
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkServiceImpl;
|
||||
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
|
||||
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkServiceImpl;
|
||||
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
|
||||
import cn.iocoder.yudao.framework.quartz.core.job.LogJobProperties;
|
||||
import cn.iocoder.yudao.framework.web.config.WebProperties;
|
||||
import cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration;
|
||||
import cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi;
|
||||
@ -34,16 +31,6 @@ public class YudaoApiLogAutoConfiguration {
|
||||
return new ApiErrorLogFrameworkServiceImpl(apiErrorLogApi);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApiAccessLogJobHandler apiAccessLogJobHandler(LogJobProperties logJobProperties) {
|
||||
return new ApiAccessLogJobHandler(logJobProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApiErrorLogJobHandler apiErrorLogJobHandler(LogJobProperties logJobProperties) {
|
||||
return new ApiErrorLogJobHandler(logJobProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 ApiAccessLogFilter Bean,记录 API 请求日志
|
||||
*/
|
||||
|
@ -1,35 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.apilog.core.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.quartz.core.job.LogJobProperties;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
// TODO @j-sentinel:同 JobLogJobHandler
|
||||
/**
|
||||
* @Author: j-sentinel
|
||||
* @Date: 2023/9/30 16:13
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ApiAccessLogJobHandler implements JobHandler {
|
||||
|
||||
private LogJobProperties logJobProperties;
|
||||
|
||||
public ApiAccessLogJobHandler(LogJobProperties logJobProperties) {
|
||||
this.logJobProperties = logJobProperties;
|
||||
}
|
||||
|
||||
@Resource
|
||||
private ApiAccessLogFrameworkService apiAccessLogFrameworkService;
|
||||
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
apiAccessLogFrameworkService.jobCleanAccessLog(logJobProperties.getAccessRetainDay());
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.apilog.core.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.quartz.core.job.LogJobProperties;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
// TODO @j-sentinel:同 JobLogJobHandler
|
||||
/**
|
||||
* @Author: j-sentinel
|
||||
* @Date: 2023/9/30 16:13
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ApiErrorLogJobHandler implements JobHandler {
|
||||
|
||||
private LogJobProperties logJobProperties;
|
||||
|
||||
public ApiErrorLogJobHandler(LogJobProperties logJobProperties) {
|
||||
this.logJobProperties = logJobProperties;
|
||||
}
|
||||
|
||||
@Resource
|
||||
private ApiErrorLogFrameworkService apiErrorLogFrameworkService;
|
||||
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
apiErrorLogFrameworkService.jobCleanErrorLog(logJobProperties.getErrorRetainDay());
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
@ -13,11 +13,4 @@ public interface ApiAccessLogFrameworkService {
|
||||
* @param apiAccessLog API 访问日志
|
||||
*/
|
||||
void createApiAccessLog(ApiAccessLog apiAccessLog);
|
||||
|
||||
/**
|
||||
* 清理 @param accessLogJobDay 天的访问日志
|
||||
*
|
||||
* @param accessLogJobDay 超过多少天就进行清理
|
||||
*/
|
||||
void jobCleanAccessLog(Integer accessLogJobDay);
|
||||
}
|
||||
|
@ -25,9 +25,4 @@ public class ApiAccessLogFrameworkServiceImpl implements ApiAccessLogFrameworkSe
|
||||
apiAccessLogApi.createApiAccessLog(reqDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobCleanAccessLog(Integer accessLogJobDay) {
|
||||
apiAccessLogApi.jobCleanAccessLog(accessLogJobDay);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,11 +13,4 @@ public interface ApiErrorLogFrameworkService {
|
||||
* @param apiErrorLog API 错误日志
|
||||
*/
|
||||
void createApiErrorLog(ApiErrorLog apiErrorLog);
|
||||
|
||||
/**
|
||||
* 清理 @param errorLogJobDay 天的访问日志
|
||||
*
|
||||
* @param errorLogJobDay 超过多少天就进行清理
|
||||
*/
|
||||
void jobCleanErrorLog(Integer errorLogJobDay);
|
||||
}
|
||||
|
@ -25,9 +25,4 @@ public class ApiErrorLogFrameworkServiceImpl implements ApiErrorLogFrameworkServ
|
||||
apiErrorLogApi.createApiErrorLog(reqDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobCleanErrorLog(Integer errorLogJobDay) {
|
||||
apiErrorLogApi.jobCleanErrorLog(errorLogJobDay);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user