审计日志细节修改

This commit is contained in:
陈超
2022-07-21 21:00:36 +08:00
parent 9d326c84eb
commit 0d7a82c264
4 changed files with 68 additions and 34 deletions

View File

@@ -17,12 +17,12 @@ public class LogParamVO {
* 登录名
*/
@ApiModelProperty("登录名")
private List<String> loginName;
private List<ValuePO> loginName;
/**
* 操作类型
*/
@ApiModelProperty("操作类型")
private List<String> operateType;
private List<ValuePO> operateType;
}

View File

@@ -0,0 +1,16 @@
package com.njcn.system.pojo.vo;
import lombok.Data;
/**
* @version 1.0.0
* @author: chenchao
* @date: 2022/07/21 12:36
*/
@Data
public class ValuePO {
private String name;
private String value;
}

View File

@@ -1,22 +0,0 @@
package com.njcn.system.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @version 1.0.0
* @author: chenchao
* @date: 2022/07/15 14:31
*/
@Data
@Component
public class SystemBaseConfig {
@Value("${business.wavePath}")
private String wavePath;
@Value("${business.tempPath}")
private String tempPath;
}

View File

@@ -9,9 +9,9 @@ import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.poi.excel.ExcelUtil;
import com.njcn.system.config.SystemBaseConfig;
import com.njcn.system.enums.AuditLogEnum;
import com.njcn.system.mapper.AuditMapper;
import com.njcn.system.mapper.UserLogMapper;
@@ -21,6 +21,7 @@ import com.njcn.system.pojo.po.UserLog;
import com.njcn.system.pojo.vo.AuditLogCusVO;
import com.njcn.system.pojo.vo.AuditLogVO;
import com.njcn.system.pojo.vo.LogParamVO;
import com.njcn.system.pojo.vo.ValuePO;
import com.njcn.system.service.AuditService;
import lombok.AllArgsConstructor;
import org.apache.commons.compress.utils.IOUtils;
@@ -41,6 +42,7 @@ import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @version 1.0.0
@@ -55,7 +57,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
private final UserLogMapper userLogMapper;
private final SystemBaseConfig SystemBaseConfig;
private final GeneralInfo generalInfo;
@Override
public Page<AuditLogVO> getAuditLog(AuditParam auditParam) {
@@ -126,7 +128,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
queryWrapper.ge("sys_user_log.update_time",date);
List<UserLogExcel> excelList = auditMapper.queryExportUser(queryWrapper);
File filePath = new File(SystemBaseConfig.getTempPath());
File filePath = new File(generalInfo.getBusinessTempPath());
filePath.mkdirs();
File file = new File(filePath.getPath() + File.separator + nowDate +" sys_user_log.xlsx");
ExcelUtil.exportExcelWithTargetFile(file, UserLogExcel.class, excelList);
@@ -165,7 +167,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
@Override
public boolean recoverLogFile() {
LocalDate nowDate = LocalDate.now();
File file = new File(SystemBaseConfig.getTempPath()+ File.separator + nowDate +" sys_user_log.xlsx");
File file = new File(generalInfo.getBusinessTempPath() + File.separator + nowDate +" sys_user_log.xlsx");
if (!file.exists()) {
throw new BusinessException(AuditLogEnum.NOT_FIND_FILE);
}
@@ -184,11 +186,32 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
if (excelList.get(0).getId().isEmpty()) {
throw new BusinessException(AuditLogEnum.LOG_EXCEPTION);
}
for (UserLogExcel excel: excelList) {
UserLog userLog = new UserLog();
BeanUtil.copyProperties(excel,userLog);
this.saveOrUpdate(userLog);
List<String> oldIds = excelList.stream().map(UserLogExcel::getId).collect(Collectors.toList());
//查找该备份文件是否已存在
List<UserLog> logList = userLogMapper.selectBatchIds(oldIds);
if (CollectionUtils.isEmpty(logList)) {
List<UserLog> userLogs = new ArrayList<>();
for (UserLogExcel excel: excelList) {
UserLog userLog = new UserLog();
BeanUtil.copyProperties(excel,userLog);
userLogs.add(userLog);
}
this.saveBatch(userLogs);
} else {
List<String> isIds = logList.stream().map(UserLog::getId).collect(Collectors.toList());
List<UserLogExcel> needSaveUserLogData = excelList.stream().filter(userLogExcelTemp -> !isIds.contains(userLogExcelTemp.getId())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(needSaveUserLogData)) {
List<UserLog> userLogs = new ArrayList<>();
for (UserLogExcel needSave: needSaveUserLogData) {
UserLog userLog = new UserLog();
BeanUtil.copyProperties(needSave,userLog);
userLogs.add(userLog);
}
this.saveBatch(userLogs);
// this.saveOrUpdateBatch(userLogs);
}
}
} catch (Exception e) {
e.printStackTrace();
throw new ExcelImportException(e.getMessage(), e);
@@ -238,10 +261,27 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
@Override
public LogParamVO saveLogParam() {
LogParamVO logParamVO = new LogParamVO();
logParamVO.setLoginName(auditMapper.selectLoginName());
logParamVO.setOperateType(auditMapper.selectOperateType());
List<String> loginName = auditMapper.selectLoginName();
List<String> operateType = auditMapper.selectOperateType();
List<ValuePO> loginNameList = new ArrayList<>();
List<ValuePO> operateTypeList = new ArrayList<>();
for (int i = 0; i<loginName.size(); i++) {
ValuePO valuePO = new ValuePO();
valuePO.setName("选项"+(i+1));
valuePO.setValue(loginName.get(i));
loginNameList.add(valuePO);
}
for (int i = 0; i<operateType.size(); i++) {
ValuePO valuePO = new ValuePO();
valuePO.setName("选项"+(i+1));
valuePO.setValue(operateType.get(i));
operateTypeList.add(valuePO);
}
logParamVO.setLoginName(loginNameList);
logParamVO.setOperateType(operateTypeList);
return logParamVO;
}
}