新增清空历史数据
This commit is contained in:
@@ -62,8 +62,8 @@ public class AuditController extends BaseController {
|
||||
@ApiOperation("日志文件恢复")
|
||||
public HttpResult recoverLogFile() {
|
||||
String methodDescribe = getMethodDescribe("recoverLogFile");
|
||||
boolean res = auditService.recoverLogFile();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,res,methodDescribe);
|
||||
auditService.recoverLogFile();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,null,methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@@ -76,6 +76,15 @@ public class AuditController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,result,methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/clearHistoryLog")
|
||||
@ApiOperation("清空历史日志")
|
||||
public HttpResult clearHistoryLog() {
|
||||
String methodDescribe = getMethodDescribe("clearHistoryLog");
|
||||
auditService.clearHistoryLog();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/saveLogParam")
|
||||
@ApiOperation("筛选下拉列表参数")
|
||||
|
||||
@@ -29,6 +29,10 @@ public interface AuditMapper {
|
||||
* 获取审计日志统计列表
|
||||
*/
|
||||
List<AuditLogCusVO> selectCensusAuditLog(@Param("auditParam") AuditParam auditParam);
|
||||
/**
|
||||
* 根据时间删除日志
|
||||
*/
|
||||
void deleteByTime(@Param("ew") QueryWrapper<UserLog> queryWrapper);
|
||||
/**
|
||||
* 查询所有登录名
|
||||
*/
|
||||
@@ -37,4 +41,5 @@ public interface AuditMapper {
|
||||
* 查询所有操作类型
|
||||
*/
|
||||
List<String> selectOperateType();
|
||||
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@
|
||||
Where ${ew.sqlSegment}
|
||||
</select>
|
||||
|
||||
<delete id="deleteByTime">
|
||||
DELETE FROM sys_user_log
|
||||
WHERE ${ew.sqlSegment}
|
||||
</delete>
|
||||
|
||||
<select id="selectCensusAuditLog" resultType="AuditLogCusVO">
|
||||
SELECT
|
||||
login_name LoginName,
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface AuditService extends IService<UserLog> {
|
||||
/**
|
||||
* 日志文件数据恢复
|
||||
*/
|
||||
boolean recoverLogFile();
|
||||
void recoverLogFile();
|
||||
|
||||
/**
|
||||
* 分页获取审计日志统计列表
|
||||
@@ -40,4 +40,9 @@ public interface AuditService extends IService<UserLog> {
|
||||
* 获取筛选下拉列表参数
|
||||
*/
|
||||
LogParamVO saveLogParam();
|
||||
|
||||
/**
|
||||
* 清空6个月前的历史日志
|
||||
*/
|
||||
void clearHistoryLog();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.imports.ExcelImportService;
|
||||
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -40,8 +41,7 @@ import java.io.OutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -165,12 +165,12 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recoverLogFile() {
|
||||
LocalDate nowDate = LocalDate.now();
|
||||
File file = new File(generalInfo.getBusinessTempPath() + File.separator + nowDate +" sys_user_log.xlsx");
|
||||
if (!file.exists()) {
|
||||
public void recoverLogFile() {
|
||||
File newFile = getLastFile();
|
||||
if (!newFile.exists()) {
|
||||
throw new BusinessException(AuditLogEnum.NOT_FIND_FILE);
|
||||
}
|
||||
|
||||
ImportParams params = new ImportParams();
|
||||
params.setHeadRows(1);//表头
|
||||
params.setTitleRows(0);//标题行数
|
||||
@@ -181,7 +181,8 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(file);
|
||||
in = new FileInputStream(newFile);
|
||||
//将Excel文件转成对象集合
|
||||
List<UserLogExcel> excelList = new ExcelImportService().importExcelByIs(in, UserLogExcel.class, params, false).getList();
|
||||
if (excelList.get(0).getId().isEmpty()) {
|
||||
throw new BusinessException(AuditLogEnum.LOG_EXCEPTION);
|
||||
@@ -231,7 +232,6 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
// } catch (Exception e) {
|
||||
// throw new BusinessException(AuditLogEnum.LOG_EXCEPTION);
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -258,6 +258,17 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHistoryLog() {
|
||||
LocalDate nowDate = LocalDate.now();
|
||||
LocalDate agoDate = nowDate.minusMonths(6).with(TemporalAdjusters.firstDayOfMonth());
|
||||
String date = agoDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
|
||||
QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lt("sys_user_log.update_time",date);
|
||||
auditMapper.deleteByTime(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogParamVO saveLogParam() {
|
||||
LogParamVO logParamVO = new LogParamVO();
|
||||
@@ -282,6 +293,28 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
return logParamVO;
|
||||
}
|
||||
|
||||
/**返回一个最新修改日期的文件*/
|
||||
public File getLastFile() {
|
||||
File parentFile = new File(generalInfo.getBusinessTempPath());
|
||||
Date date = FileUtil.lastModifiedTime(parentFile);
|
||||
System.out.println(">>>>>>>>>>当前文件夹最后修改时间>>>>>>>>>"+date);
|
||||
|
||||
//文件夹下的所有子文件数组
|
||||
File[] files = parentFile.listFiles();
|
||||
List<Date> list = Arrays.stream(files).map(tempFile -> FileUtil.lastModifiedTime(tempFile)).collect(Collectors.toList());
|
||||
//Date集合排序
|
||||
Collections.sort(list, new Comparator<Date>() {
|
||||
@Override
|
||||
public int compare(Date o1, Date o2) {
|
||||
return o2.compareTo(o1);//倒序排序
|
||||
// return o1.compareTo(o2);//正序排序
|
||||
}
|
||||
});
|
||||
File newFile = Arrays.stream(files).filter(tempFile -> FileUtil.lastModifiedTime(tempFile).equals(list.get(0))).collect(Collectors.toList()).get(0);
|
||||
|
||||
return newFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user