日志清除
This commit is contained in:
@@ -36,8 +36,4 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
|
||||
@Modifying
|
||||
@Query(value = "delete from sys_log where log_type = ?1", nativeQuery = true)
|
||||
void deleteByLogType(String logType);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "delete from sys_log where log_type = ?1 and DATEDIFF(NOW(),create_time) >= 15", nativeQuery = true)
|
||||
void delAfterDay(String logType);
|
||||
}
|
||||
|
||||
@@ -79,14 +79,4 @@ public interface LogService {
|
||||
* 删除所有INFO日志
|
||||
*/
|
||||
void delAllByInfo();
|
||||
|
||||
/**
|
||||
* 删除15天之前的错误日志
|
||||
*/
|
||||
void delAfterDay15ByError();
|
||||
|
||||
/**
|
||||
* 删除15天之前的INFO日志
|
||||
*/
|
||||
void delAfterDay15ByInfo();
|
||||
}
|
||||
|
||||
@@ -155,16 +155,4 @@ public class LogServiceImpl implements LogService {
|
||||
public void delAllByInfo() {
|
||||
logRepository.deleteByLogType("INFO");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAfterDay15ByError() {
|
||||
logRepository.delAfterDay("ERROR");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAfterDay15ByInfo() {
|
||||
logRepository.delAfterDay("INFO");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package org.nl.wms.autotask;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.logging.service.LogService;
|
||||
import org.nl.modules.system.service.ParamService;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -12,14 +13,14 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CleanLog {
|
||||
private final LogService logService;
|
||||
private final ParamService paramService;
|
||||
|
||||
public void run(){
|
||||
// 删除所有异常日志
|
||||
logService.delAfterDay15ByError();
|
||||
// 删除所有操作日志
|
||||
logService.delAfterDay15ByInfo();
|
||||
log.info("删除所有异常/操作日志 执行成功");
|
||||
//delete from sys_log where DATE(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL 30 day)) limit 10;
|
||||
WQLObject logTab = WQLObject.getWQLObject("sys_log");
|
||||
int days = Integer.parseInt(paramService.findByCode("log_day").getValue());
|
||||
logTab.delete("DATE(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL " + days + " day))");
|
||||
log.info("自动清理日志执行成功...!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user