数据清理job逻辑调整,增加用户登录记录清理、客户端连接记录清理

This commit is contained in:
aoshiguchen
2022-11-23 11:33:25 +08:00
parent 44909e20b5
commit 09424a7f07
5 changed files with 90 additions and 4 deletions
@@ -0,0 +1,14 @@
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.aop.Intercept;
/**
* @author: aoshiguchen
* @date: 2022/11/23
*/
@Intercept(ignoreGlobal = true)
@Component
public class ClientConnectRecordMapper {
}
@@ -37,4 +37,9 @@ public interface DataCleanMapper extends SqlMapper {
@Delete("delete from `job_log` where create_time < ?")
void cleanJobLog(long date);
@Delete("delete from `user_login_record` where create_time < ?")
void cleanUserLoginRecord(long date);
@Delete("delete from `client_connect_record` where create_time < ?")
void cleanClientConnectRecord(long date);
}
@@ -0,0 +1,38 @@
package fun.asgc.neutrino.proxy.server.dal.entity;
import fun.asgc.neutrino.core.db.annotation.Id;
import fun.asgc.neutrino.core.db.annotation.Table;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author: aoshiguchen
* @date: 2022/11/23
*/
@ToString
@Accessors(chain = true)
@Data
@Table("client_connect_record")
public class ClientConnectRecordDO {
@Id
private Integer id;
private Integer userId;
private String ip;
private Integer licenseId;
private String licenseKey;
private Integer type;
private String msg;
/**
* 1、成功
* 2、失败
*/
private Integer code;
private String err;
/**
* 创建时间
*/
private Date createTime;
}
@@ -55,14 +55,36 @@ public class DataCleanJob implements IJobHandler {
* Job日志保存天数
*/
private static final Integer JOB_LOG_KEEP_DAYS = 7;
/**
* 用户登录日志保留天数
*/
private static final Integer USER_LOGIN_RECORD_KEEP_DAYS = 30;
/**
* 客户端连接记录保留天数
*/
private static final Integer CLIENT_CONNECT_RECORD_KEEP_DAYS = 30;
@Override
public void execute(String s) throws Exception {
JobParams jobParams = getParams(s);
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getJobLogKeepDays());
log.info("清理调度管理日志 date:{}", sdf.format(date));
dataCleanMapper.cleanJobLog(date.getTime());
{
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getJobLogKeepDays());
log.info("清理调度管理日志 date:{}", sdf.format(date));
dataCleanMapper.cleanJobLog(date.getTime());
}
{
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getUserLoginRecordKeepDays());
log.info("清理用户登录日志 date:{}", sdf.format(date));
dataCleanMapper.cleanUserLoginRecord(date.getTime());
}
{
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getClientConnectRecordKeepDays());
log.info("清理客户端连接日志 date:{}", sdf.format(date));
dataCleanMapper.cleanClientConnectRecord(date.getTime());
}
}
public static JobParams getParams(String s) {
@@ -74,12 +96,16 @@ public class DataCleanJob implements IJobHandler {
// ignore
}
return new JobParams()
.setJobLogKeepDays(JOB_LOG_KEEP_DAYS);
.setJobLogKeepDays(JOB_LOG_KEEP_DAYS)
.setUserLoginRecordKeepDays(USER_LOGIN_RECORD_KEEP_DAYS)
.setClientConnectRecordKeepDays(CLIENT_CONNECT_RECORD_KEEP_DAYS);
}
@Accessors(chain = true)
@Data
public static class JobParams {
private Integer jobLogKeepDays;
private Integer userLoginRecordKeepDays;
private Integer clientConnectRecordKeepDays;
}
}
@@ -80,6 +80,9 @@ CREATE TABLE IF NOT EXISTS `client_connect_record` (
`license_id` INTEGER(20) NOT NULL,
`license_key` VARCHAR(100) NOT NULL,
`type` INTEGER(2) NOT NULL,
`msg` VARCHAR(512) DEFAULT NULL,
`code` INTEGER(2) NOT NULL,
`err` VARCHAR(512) DEFAULT NULL,
`create_time` INTEGER(20) NOT NULL
);
##########################################################