|
|
|
@ -1,18 +1,24 @@
|
|
|
|
|
package cn.estsh.i3plus.core.apiservice.schedulejob;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISysLogService;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.serviceimpl.base.SysLogElasticSearchService;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.serviceimpl.base.SysLogMongoService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.plugin.elasticsearch.ElasticSearchTool;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.platbean.SysLogException;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.platbean.SysLogOperate;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.platbean.SysLogSystem;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.platbean.SysLogTaskTime;
|
|
|
|
|
import cn.estsh.impp.framework.base.schedule.BaseImppScheduleJob;
|
|
|
|
|
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.RedisUtilTool;
|
|
|
|
|
import org.quartz.DisallowConcurrentExecution;
|
|
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -22,6 +28,7 @@ import java.util.Date;
|
|
|
|
|
* @CreateDate : 2019-07-04 19:13
|
|
|
|
|
* @Modify:
|
|
|
|
|
**/
|
|
|
|
|
@Component
|
|
|
|
|
@DisallowConcurrentExecution
|
|
|
|
|
public class CoreLogClearJob extends BaseImppScheduleJob {
|
|
|
|
|
|
|
|
|
@ -32,67 +39,49 @@ public class CoreLogClearJob extends BaseImppScheduleJob {
|
|
|
|
|
super(CoreLogClearJob.class, "日志清除");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Value("${impp.logService.retention-time:-1}")
|
|
|
|
|
private Integer retentionTime;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysLogService logService;
|
|
|
|
|
private SysLogElasticSearchService elasticSearchService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysLogMongoService mongoService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void executeImppJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
|
|
|
|
|
// // 判断日志保留时间 -1 永久
|
|
|
|
|
// if (getJobParam() == null) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// JSONObject clearParam = JSONObject.parseObject(getJobParam());
|
|
|
|
|
//
|
|
|
|
|
// // 计算保留日期
|
|
|
|
|
// String dateTime = TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, -retentionTime,"yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
// long count;
|
|
|
|
|
// // 系统日志
|
|
|
|
|
// if (clearParam.containsKey("logSystem") && clearParam.getInteger("logSystem") != -1) {
|
|
|
|
|
// dateTime = TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, -clearParam.getInteger("logSystem"),"yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
// count = logService.deleteSysLogSystemByDateTimeAfter(dateTime);
|
|
|
|
|
// LOGGER.info("【日志清理】 清理系统日志 {} 条", count);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 异常日志
|
|
|
|
|
// if (clearParam.containsKey("logException") && clearParam.getInteger("logException") != -1) {
|
|
|
|
|
// dateTime = TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, -clearParam.getInteger("logException"),"yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
// count = logService.deleteSysLogExceptionByDateTimeAfter(dateTime);
|
|
|
|
|
// LOGGER.info("【日志清理】 清理异常日志 {} 条", count);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 操作日志
|
|
|
|
|
// if (clearParam.containsKey("logOperate") && clearParam.getInteger("logOperate") != -1) {
|
|
|
|
|
// dateTime = TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, -clearParam.getInteger("logException"),"yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
// count = logService.deleteSysLogOperateByDateTimeAfter(dateTime);
|
|
|
|
|
// LOGGER.info("【日志清理】 清理操作日志 {} 条", count);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 任务日志
|
|
|
|
|
// if (clearParam.containsKey("logTask") && clearParam.getInteger("logTask") != -1) {
|
|
|
|
|
// dateTime = TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, -clearParam.getInteger("logException"),"yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
// count = logService.deleteSysLogTaskTimeByDateTimeAfter(dateTime);
|
|
|
|
|
// LOGGER.info("【日志清理】 清理定时任务日志 {} 条", count);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
int to = RedisUtilTool.getSysConfigIntVal(CommonConstWords.LOG_STORAGE_DAYS, CommonConstWords.LOG_STORAGE_DAYS_DEFAULT);
|
|
|
|
|
Date thisTime = new Date();
|
|
|
|
|
String startTime = TimeTool.getToday(TimeTool.getDateBefore(thisTime, to)) + " 00:00:00";
|
|
|
|
|
String endTime = TimeTool.getToday(TimeTool.getDateBefore(thisTime, to)) + " 23:59:59";
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
JSONObject clearParam = new JSONObject();
|
|
|
|
|
clearParam.put("logSystem",30);
|
|
|
|
|
clearParam.put("logException",30);
|
|
|
|
|
clearParam.put("logOperate",30);
|
|
|
|
|
clearParam.put("logTask",30);
|
|
|
|
|
System.out.println(clearParam.toJSONString());
|
|
|
|
|
SysLogOperate operate = new SysLogOperate();
|
|
|
|
|
operate.setCreateDatetime(startTime);
|
|
|
|
|
operate.setCreateDateTimeStart(startTime);
|
|
|
|
|
operate.setCreateDateTimeEnd(endTime);
|
|
|
|
|
|
|
|
|
|
SysLogSystem system = new SysLogSystem();
|
|
|
|
|
system.setCreateDatetime(startTime);
|
|
|
|
|
system.setCreateDateTimeStart(startTime);
|
|
|
|
|
system.setCreateDateTimeEnd(endTime);
|
|
|
|
|
|
|
|
|
|
clearParam = JSONObject.parseObject("{\"logOperate\":10,\"logException\":10,\"logSystem\":10,\"logTask\":10}");
|
|
|
|
|
SysLogException exception = new SysLogException();
|
|
|
|
|
exception.setCreateDatetime(startTime);
|
|
|
|
|
exception.setCreateDateTimeStart(startTime);
|
|
|
|
|
exception.setCreateDateTimeEnd(endTime);
|
|
|
|
|
|
|
|
|
|
// 计算保留日期
|
|
|
|
|
String dateTime = TimeTool.pareDateToString("yyyy-MM-dd HH:mm:ss",
|
|
|
|
|
TimeTool.timeCalc(new Date(), Calendar.DAY_OF_MONTH, 1)
|
|
|
|
|
);
|
|
|
|
|
SysLogTaskTime taskTime = new SysLogTaskTime();
|
|
|
|
|
taskTime.setCreateDatetime(startTime);
|
|
|
|
|
taskTime.setCreateDateTimeStart(startTime);
|
|
|
|
|
taskTime.setCreateDateTimeEnd(endTime);
|
|
|
|
|
|
|
|
|
|
ElasticSearchTool.reload();
|
|
|
|
|
elasticSearchService.deleteLogOperate(operate);
|
|
|
|
|
elasticSearchService.deleteLogSystem(system);
|
|
|
|
|
elasticSearchService.deleteLogException(exception);
|
|
|
|
|
elasticSearchService.deleteLogTaskTime(taskTime);
|
|
|
|
|
|
|
|
|
|
mongoService.deleteLogOperate(operate);
|
|
|
|
|
mongoService.deleteLogSystem(system);
|
|
|
|
|
mongoService.deleteLogException(exception);
|
|
|
|
|
mongoService.deleteLogTaskTime(taskTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|