审计日志
This commit is contained in:
@@ -24,14 +24,14 @@ public class AuditParam {
|
|||||||
@Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误")
|
@Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误")
|
||||||
private String searchEndTime;
|
private String searchEndTime;
|
||||||
|
|
||||||
@ApiModelProperty("用户名")
|
@ApiModelProperty("登录名")
|
||||||
private String userName;
|
private String loginName;
|
||||||
|
|
||||||
@ApiModelProperty("事件类型")
|
@ApiModelProperty("事件类型(0.业务事件 1.系统事件)")
|
||||||
private String type;
|
private Integer type;
|
||||||
|
|
||||||
@ApiModelProperty("操作类型")
|
@ApiModelProperty("操作类型")
|
||||||
private String operate;
|
private String operateType;
|
||||||
|
|
||||||
@ApiModelProperty("页码")
|
@ApiModelProperty("页码")
|
||||||
@NotNull(message = "页码不可为空")
|
@NotNull(message = "页码不可为空")
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ public class AuditLogCusVO implements Serializable {
|
|||||||
* 操作人员
|
* 操作人员
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty("操作人员")
|
@ApiModelProperty("操作人员")
|
||||||
private String userName;
|
private String LoginName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作类型
|
* 操作类型
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty("操作类型")
|
@ApiModelProperty("操作类型")
|
||||||
private String operate;
|
private String operateType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件总数
|
* 事件总数
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class AuditLogVO {
|
|||||||
* 事件类型
|
* 事件类型
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty("事件类型")
|
@ApiModelProperty("事件类型")
|
||||||
private String operateType;
|
private String type;
|
||||||
/**
|
/**
|
||||||
* 操作结果
|
* 操作结果
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.njcn.system.pojo.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author: chenchao
|
||||||
|
* @date: 2022/07/19 19:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LogParamVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("登录名")
|
||||||
|
private List<String> loginName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作类型
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("操作类型")
|
||||||
|
private List<String> operateType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,7 +7,9 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.HttpResultUtil;
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
import com.njcn.system.pojo.param.AuditParam;
|
import com.njcn.system.pojo.param.AuditParam;
|
||||||
|
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
||||||
import com.njcn.system.pojo.vo.AuditLogVO;
|
import com.njcn.system.pojo.vo.AuditLogVO;
|
||||||
|
import com.njcn.system.pojo.vo.LogParamVO;
|
||||||
import com.njcn.system.service.AuditService;
|
import com.njcn.system.service.AuditService;
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -64,15 +66,24 @@ public class AuditController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,res,methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,res,methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
// @PostMapping("/censusAuditLog")
|
@PostMapping("/censusAuditLog")
|
||||||
// @ApiOperation("审计日志统计")
|
@ApiOperation("审计日志统计")
|
||||||
// @ApiImplicitParam(name = "auditParam", value = "审计日志参数", required = true)
|
@ApiImplicitParam(name = "auditParam", value = "审计日志参数", required = true)
|
||||||
// public HttpResult<Page<AuditLogCusVO>> censusAuditLog(@RequestBody @Validated AuditParam auditParam){
|
public HttpResult<Page<AuditLogCusVO>> censusAuditLog(@RequestBody @Validated AuditParam auditParam){
|
||||||
// String methodDescribe = getMethodDescribe("censusAuditLog");
|
String methodDescribe = getMethodDescribe("censusAuditLog");
|
||||||
// Page<AuditLogCusVO> result = auditService.censusAuditLog(auditParam);
|
Page<AuditLogCusVO> result = auditService.censusAuditLog(auditParam);
|
||||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,result,methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,result,methodDescribe);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@PostMapping("/saveLogParam")
|
||||||
|
@ApiOperation("筛选下拉列表参数")
|
||||||
|
public HttpResult<LogParamVO> saveLogParam() {
|
||||||
|
String methodDescribe = getMethodDescribe("saveLogParam");
|
||||||
|
LogParamVO result = auditService.saveLogParam();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.njcn.system.pojo.dto.excel.UserLogExcel;
|
import com.njcn.system.pojo.dto.excel.UserLogExcel;
|
||||||
import com.njcn.system.pojo.param.AuditParam;
|
import com.njcn.system.pojo.param.AuditParam;
|
||||||
import com.njcn.system.pojo.po.UserLog;
|
import com.njcn.system.pojo.po.UserLog;
|
||||||
|
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,5 +25,16 @@ public interface AuditMapper {
|
|||||||
* 查询需要备份的审计日志
|
* 查询需要备份的审计日志
|
||||||
*/
|
*/
|
||||||
List<UserLogExcel> queryExportUser(@Param("ew") QueryWrapper<UserLogExcel> queryWrapper);
|
List<UserLogExcel> queryExportUser(@Param("ew") QueryWrapper<UserLogExcel> queryWrapper);
|
||||||
|
/**
|
||||||
|
* 获取审计日志统计列表
|
||||||
|
*/
|
||||||
|
List<AuditLogCusVO> selectCensusAuditLog(@Param("auditParam") AuditParam auditParam);
|
||||||
|
/**
|
||||||
|
* 查询所有登录名
|
||||||
|
*/
|
||||||
|
List<String> selectLoginName();
|
||||||
|
/**
|
||||||
|
* 查询所有操作类型
|
||||||
|
*/
|
||||||
|
List<String> selectOperateType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
FROM sys_user_log
|
FROM sys_user_log
|
||||||
WHERE update_time >= #{auditParam.searchBeginTime}
|
WHERE update_time >= #{auditParam.searchBeginTime}
|
||||||
AND #{auditParam.searchEndTime} >= update_time
|
AND #{auditParam.searchEndTime} >= update_time
|
||||||
|
<if test="auditParam.loginName!=null">
|
||||||
|
and login_name = #{auditParam.loginName}
|
||||||
|
</if>
|
||||||
|
<if test="auditParam.type!=null">
|
||||||
|
and type = #{auditParam.type}
|
||||||
|
</if>
|
||||||
|
<if test="auditParam.operateType!=null">
|
||||||
|
and operate_type = #{auditParam.operateType}
|
||||||
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectAuditLog" resultType="UserLog">
|
<select id="selectAuditLog" resultType="UserLog">
|
||||||
@@ -32,14 +41,14 @@
|
|||||||
sys_user_log
|
sys_user_log
|
||||||
WHERE update_time >= #{auditParam.searchBeginTime}
|
WHERE update_time >= #{auditParam.searchBeginTime}
|
||||||
AND #{auditParam.searchEndTime} >= update_time
|
AND #{auditParam.searchEndTime} >= update_time
|
||||||
<if test="auditParam.userName!=null">
|
<if test="auditParam.loginName!=null">
|
||||||
and user_name = #{auditParam.userName}
|
and login_name = #{auditParam.loginName}
|
||||||
</if>
|
</if>
|
||||||
<if test="auditParam.type!=null">
|
<if test="auditParam.type!=null">
|
||||||
and type = #{auditParam.type}
|
and type = #{auditParam.type}
|
||||||
</if>
|
</if>
|
||||||
<if test="auditParam.operate!=null">
|
<if test="auditParam.operateType!=null">
|
||||||
and operate = #{auditParam.operate}
|
and operate_type = #{auditParam.operateType}
|
||||||
</if>
|
</if>
|
||||||
AND id >= (select id from sys_user_log order by id limit #{auditParam.pageNum}, 1) limit #{auditParam.pageSize}
|
AND id >= (select id from sys_user_log order by id limit #{auditParam.pageNum}, 1) limit #{auditParam.pageSize}
|
||||||
</select>
|
</select>
|
||||||
@@ -66,5 +75,43 @@
|
|||||||
Where ${ew.sqlSegment}
|
Where ${ew.sqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectCensusAuditLog" resultType="AuditLogCusVO">
|
||||||
|
SELECT
|
||||||
|
login_name LoginName,
|
||||||
|
operate_type operateType,
|
||||||
|
count(id) AS count
|
||||||
|
FROM sys_user_log
|
||||||
|
WHERE user_name !=""
|
||||||
|
AND user_name !="unknown user"
|
||||||
|
AND operate != "unknown operate"
|
||||||
|
AND update_time >= #{auditParam.searchBeginTime}
|
||||||
|
AND #{auditParam.searchEndTime} >= update_time
|
||||||
|
<if test="auditParam.loginName!=null">
|
||||||
|
and login_name = #{auditParam.loginName}
|
||||||
|
</if>
|
||||||
|
<if test="auditParam.type!=null">
|
||||||
|
and type = #{auditParam.type}
|
||||||
|
</if>
|
||||||
|
<if test="auditParam.operateType!=null">
|
||||||
|
and operate_type = #{auditParam.operateType}
|
||||||
|
</if>
|
||||||
|
GROUP BY login_name, operate_type
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectLoginName" resultType="String">
|
||||||
|
SELECT
|
||||||
|
login_name
|
||||||
|
FROM sys_user_log
|
||||||
|
WHERE login_name !=""
|
||||||
|
AND login_name !="unknown user"
|
||||||
|
GROUP BY login_name
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectOperateType" resultType="String">
|
||||||
|
SELECT
|
||||||
|
operate_type
|
||||||
|
FROM sys_user_log
|
||||||
|
GROUP BY operate_type
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -6,6 +6,7 @@ import com.njcn.system.pojo.param.AuditParam;
|
|||||||
import com.njcn.system.pojo.po.UserLog;
|
import com.njcn.system.pojo.po.UserLog;
|
||||||
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
||||||
import com.njcn.system.pojo.vo.AuditLogVO;
|
import com.njcn.system.pojo.vo.AuditLogVO;
|
||||||
|
import com.njcn.system.pojo.vo.LogParamVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
@@ -35,4 +36,8 @@ public interface AuditService extends IService<UserLog> {
|
|||||||
*/
|
*/
|
||||||
Page<AuditLogCusVO> censusAuditLog(AuditParam auditParam);
|
Page<AuditLogCusVO> censusAuditLog(AuditParam auditParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取筛选下拉列表参数
|
||||||
|
*/
|
||||||
|
LogParamVO saveLogParam();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|||||||
import cn.afterturn.easypoi.excel.imports.ExcelImportService;
|
import cn.afterturn.easypoi.excel.imports.ExcelImportService;
|
||||||
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
|
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -18,6 +19,7 @@ import com.njcn.system.pojo.param.AuditParam;
|
|||||||
import com.njcn.system.pojo.po.UserLog;
|
import com.njcn.system.pojo.po.UserLog;
|
||||||
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
||||||
import com.njcn.system.pojo.vo.AuditLogVO;
|
import com.njcn.system.pojo.vo.AuditLogVO;
|
||||||
|
import com.njcn.system.pojo.vo.LogParamVO;
|
||||||
import com.njcn.system.service.AuditService;
|
import com.njcn.system.service.AuditService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.apache.commons.compress.utils.IOUtils;
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
@@ -76,7 +78,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
AuditLogVO auditLogVO = new AuditLogVO();
|
AuditLogVO auditLogVO = new AuditLogVO();
|
||||||
String updateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(userLog.getUpdateTime());
|
String updateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(userLog.getUpdateTime());
|
||||||
auditLogVO.setTime(updateTime);
|
auditLogVO.setTime(updateTime);
|
||||||
if (userLog.getUserName().isEmpty()) {
|
if (userLog.getUserName()==null || userLog.getUserName().equals("")) {
|
||||||
auditLogVO.setUserName(userLog.getLoginName());
|
auditLogVO.setUserName(userLog.getLoginName());
|
||||||
} else {
|
} else {
|
||||||
auditLogVO.setUserName(userLog.getUserName());
|
auditLogVO.setUserName(userLog.getUserName());
|
||||||
@@ -91,7 +93,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
describe.append("失败").append(",失败原因为").append(userLog.getFailReason());
|
describe.append("失败").append(",失败原因为").append(userLog.getFailReason());
|
||||||
}
|
}
|
||||||
auditLogVO.setDescribe(describe.toString());
|
auditLogVO.setDescribe(describe.toString());
|
||||||
auditLogVO.setOperateType(userLog.getType() == 0 ? "业务事件" : "系统事件");
|
auditLogVO.setType(userLog.getType() == 0 ? "业务事件" : "系统事件");
|
||||||
auditLogVO.setResult(userLog.getResult() == 0 ? "失败" : "成功");
|
auditLogVO.setResult(userLog.getResult() == 0 ? "失败" : "成功");
|
||||||
auditLogVO.setIp(userLog.getIp());
|
auditLogVO.setIp(userLog.getIp());
|
||||||
if (userLog.getLevel()==0) {
|
if (userLog.getLevel()==0) {
|
||||||
@@ -126,6 +128,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
File file = new File(filePath.getPath() + File.separator + nowDate +" sys_user_log.xlsx");
|
File file = new File(filePath.getPath() + File.separator + nowDate +" sys_user_log.xlsx");
|
||||||
ExcelUtil.exportExcelWithTargetFile(file, UserLogExcel.class, excelList);
|
ExcelUtil.exportExcelWithTargetFile(file, UserLogExcel.class, excelList);
|
||||||
|
|
||||||
|
//备份为txt
|
||||||
// QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
|
// QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
|
||||||
// queryWrapper.ge("sys_user_log.update_time",date);
|
// queryWrapper.ge("sys_user_log.update_time",date);
|
||||||
// List<UserLog> userLogs = userLogMapper.selectList(queryWrapper);
|
// List<UserLog> userLogs = userLogMapper.selectList(queryWrapper);
|
||||||
@@ -163,7 +166,6 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
throw new BusinessException(AuditLogEnum.NOT_FIND_FILE);
|
throw new BusinessException(AuditLogEnum.NOT_FIND_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportParams params = new ImportParams();
|
ImportParams params = new ImportParams();
|
||||||
params.setHeadRows(1);//表头
|
params.setHeadRows(1);//表头
|
||||||
params.setTitleRows(0);//标题行数
|
params.setTitleRows(0);//标题行数
|
||||||
@@ -173,7 +175,6 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
params.setSheetNum(1);
|
params.setSheetNum(1);
|
||||||
|
|
||||||
FileInputStream in = null;
|
FileInputStream in = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
in = new FileInputStream(file);
|
in = new FileInputStream(file);
|
||||||
List<UserLogExcel> excelList = new ExcelImportService().importExcelByIs(in, UserLogExcel.class, params, false).getList();
|
List<UserLogExcel> excelList = new ExcelImportService().importExcelByIs(in, UserLogExcel.class, params, false).getList();
|
||||||
@@ -192,7 +193,6 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
IOUtils.closeQuietly(in);
|
IOUtils.closeQuietly(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
// // FileInputStream in = new FileInputStream(file);
|
// // FileInputStream in = new FileInputStream(file);
|
||||||
// MultipartFile multipartFile = getMultipartFile(file);
|
// MultipartFile multipartFile = getMultipartFile(file);
|
||||||
@@ -217,19 +217,28 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
page.setSize(auditParam.getPageSize());
|
page.setSize(auditParam.getPageSize());
|
||||||
page.setCurrent(auditParam.getPageNum());
|
page.setCurrent(auditParam.getPageNum());
|
||||||
//待分页数据总量
|
//待分页数据总量
|
||||||
int count = auditMapper.getCount(auditParam);
|
List<AuditLogCusVO> auditLogCusVOS = auditMapper.selectCensusAuditLog(auditParam);
|
||||||
page.setTotal(count);
|
page.setTotal(auditLogCusVOS.size());
|
||||||
//分页总页数
|
//分页总页数
|
||||||
int pages = (int)Math.ceil(count*1.0/auditParam.getPageSize());
|
int pages = (int)Math.ceil(page.getTotal()*1.0/auditParam.getPageSize());
|
||||||
page.setPages(pages);
|
page.setPages(pages);
|
||||||
|
|
||||||
auditParam.setPageNum(auditParam.getPageSize()*(auditParam.getPageNum()-1));
|
if (!CollectionUtils.isEmpty(auditLogCusVOS)) {
|
||||||
List<UserLog> userLogs = auditMapper.selectAuditLog(auditParam);
|
List<List<AuditLogCusVO>> pageList = Lists.partition(auditLogCusVOS, auditParam.getPageSize());
|
||||||
|
auditLogVOS = pageList.get(auditParam.getPageNum() - 1);
|
||||||
|
}
|
||||||
|
page.setRecords(auditLogVOS);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LogParamVO saveLogParam() {
|
||||||
|
LogParamVO logParamVO = new LogParamVO();
|
||||||
|
logParamVO.setLoginName(auditMapper.selectLoginName());
|
||||||
|
logParamVO.setOperateType(auditMapper.selectOperateType());
|
||||||
|
return logParamVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user