实体类SysAudit.java
package com.ratel.boot.platform.system.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author ratelie
*/
@Data
@TableName(value = "sys_audit")
public class SysAudit implements Serializable {
private static final long serialVersionUID = 5816298243864266439L;
/** 日志ID */
@JsonSerialize(using= ToStringSerializer.class)
@TableId(value = "log_id", type = IdType.ASSIGN_ID)
private Long logId;
/** 日志类型 1:登录日志 2:业务日志 */
@TableField(value = "log_type")
private String logType;
/** 链路编号 */
@TableField(value = "log_trace_id")
private String logTraceId;
/** 服务中心(系统中心,订单中心,) */
@TableField(value = "log_center")
private String logCenter;
/** 服务中心(用户管理,) */
@TableField(value = "log_module")
private String logModule;
/** 查询用户信息 */
@TableField(value = "log_title")
private String logTitle;
/** 日志描述,用户中心-用户管理-查询用户列表 */
@TableField(value = "log_desc")
private String logDesc;
/** 访问IP */
@TableField(value = "log_ip")
private String logIp;
/** 访问IP */
@TableField(value = "log_ipaddr")
private String logIpaddr;
/** Finger指纹信息 */
@TableField(value = "log_finger")
private String logFinger;
/** 访问路径 */
@TableField(value = "log_url")
private String logUrl;
/** 访问类型 */
@TableField(value = "log_method")
private String logMethod;
/** 请求数据 */
@TableField(value = "log_request")
private String logRequest;
/** 相应数据 */
@TableField(value = "log_response")
private String logResponse;
/** 异常信息 */
@TableField(value = "log_exception")
private String logException;
/** 排序 */
@TableField(value = "sort_order", fill = FieldFill.INSERT)
private int sortOrder;
/** 创建人ID */
@TableField(value = "version", fill = FieldFill.INSERT)
private int version;
/** 创建人ID */
@JsonSerialize(using= ToStringSerializer.class)
@TableField(value = "create_user_id")
private Long createUserId;
/** 创建人名称 */
@TableField(value = "create_user_name")
private String createUserName;
/** 创建人组织ID */
@JsonSerialize(using= ToStringSerializer.class)
@TableField(value = "create_dept_id")
private Long createDeptId;
/** 创建人组织名称 */
@TableField(value = "create_dept_name")
private String createDeptName;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(value = "create_time" , fill = FieldFill.INSERT)
private Date createTime;
/** 删除标识,(默认为 0未删除,1已删除) */
@TableLogic
@TableField(value = "deleted", fill = FieldFill.INSERT)
private Integer deleted;
/** 租户ID */
@JsonSerialize(using= ToStringSerializer.class)
@TableField(value = "tenant_id", fill = FieldFill.INSERT)
private Long tenantId;
}
mapper.xml
package com.ratel.boot.platform.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ratel.boot.platform.system.entity.SysAudit;
import org.apache.ibatis.annotations.Mapper;
/**
* @author ratelie
* @info 系统管理_审计管理
*/
@Mapper
public interface SysAuditMapper extends BaseMapper<SysAudit> {
}
SysAuditService.java
package com.ratel.boot.platform.system.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ratel.boot.platform.system.entity.SysAudit;
import java.util.List;
/**
* @author ratelie
* @info 系统管理_审计管理
*/
public interface SysAuditService {
/**
* 分页列表
*
* @param page
* @param queryWrapper
* @return
*/
IPage<SysAudit> selectPage(Page<SysAudit> page, Wrapper<SysAudit> queryWrapper);
/**
* 新增
*
* @param entity
* @return
*/
int insert(SysAudit entity);
/**
* 根据主键查询
*
* @param logId
* @return
*/
SysAudit selectById(Long logId);
/**
* 根据主键修改
*
* @param entity
* @return
*/
int updateById(SysAudit entity);
/**
* 根据主键删除
*
* @param logId
* @return
*/
int deleteById(Long logId);
/**
* 查询列表
*
* @param queryWrapper
* @return
*/
List<SysAudit> selectList(Wrapper<SysAudit> queryWrapper);
/**
* 批量清除审计日志
* @param logIds
* @return
*/
int deleteByIds(List<Long> logIds);
}
SysAuditServiceImpl.java
package com.ratel.boot.platform.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ratel.boot.platform.system.entity.SysAudit;
import com.ratel.boot.platform.system.mapper.SysAuditMapper;
import com.ratel.boot.platform.system.service.SysAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author ratelie
* @info 系统管理_审计管理
*/
@Service
public class SysAuditServiceImpl implements SysAuditService {
@Autowired
private SysAuditMapper mapper;
@Override
public IPage<SysAudit> selectPage(Page<SysAudit> page, Wrapper<SysAudit> queryWrapper) {
IPage<SysAudit> result = mapper.selectPage(page, queryWrapper);
return result;
}
@Override
public int insert(SysAudit entity) {
return mapper.insert(entity);
}
@Override
public SysAudit selectById(Long logId) {
return mapper.selectById(logId);
}
@Override
public int updateById(SysAudit entity) {
return mapper.updateById(entity);
}
@Override
public int deleteById(Long logId) {
return mapper.deleteById(logId);
}
@Override
public List<SysAudit> selectList(Wrapper<SysAudit> queryWrapper) {
return mapper.selectList(queryWrapper);
}
@Override
public int deleteByIds(List<Long> logIds) {
return mapper.deleteBatchIds(logIds);
}
}
SysAuditController.java
package com.ratel.boot.platform.system.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ratel.boot.common.base.ResponseData;
import com.ratel.boot.common.utils.RtStringUtils;
import com.ratel.boot.config.aspect.LogAcl;
import com.ratel.boot.platform.system.dto.SysAuditDto;
import com.ratel.boot.platform.system.entity.SysAudit;
import com.ratel.boot.platform.system.mapstruct.SysAuditMapstruct;
import com.ratel.boot.platform.system.service.SysAuditService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author ratelie
*/
@Slf4j
@RestController
@RequestMapping(value = "/system/audit")
public class SysAuditController {
@Autowired
private SysAuditService service;
///BaseInterface//
///BaseInterface//
///BaseInterface//
@LogAcl(logCenter = "系统管理", logModule = "审计管理", logTitle = "插入日志")
@PreAuthorize("hasAuthority('system:audit:insert')")
@PostMapping(value = "/insert")
public ResponseData insert(@RequestBody SysAudit entity) {
int result = service.insert(entity);
return ResponseData.success(result);
}
@LogAcl(logCenter = "系统管理", logModule = "审计管理", logTitle = "插入日志")
@PreAuthorize("hasAuthority('system:audit:update')")
@PutMapping(value = "/updateById")
public ResponseData updateById(@RequestBody SysAuditDto dto) {
SysAudit entity = SysAuditMapstruct.INSTANCE.dtoToEntity(dto);
int result = service.updateById(entity);
return ResponseData.success(result);
}
@LogAcl(logCenter = "系统管理", logModule = "审计管理", logTitle = "查询详情")
@PreAuthorize("hasAuthority('system:audit:select')")
@GetMapping(value = "/selectById/{logId}")
public ResponseData selectById(@PathVariable("logId") Long logId) {
SysAudit result = service.selectById(logId);
return ResponseData.success(result);
}
@LogAcl(logCenter = "系统管理", logModule = "审计管理", logTitle = "删除日志")
@PreAuthorize("hasAuthority('system:audit:delete')")
@DeleteMapping(value = "/deleteById/{logId}")
public ResponseData deleteById(@PathVariable("logId") Long logId) {
int result = service.deleteById(logId);
return ResponseData.success(result);
}
@LogAcl(logCenter = "系统管理", logModule = "用户管理", logTitle = "根据主键删除")
@PreAuthorize("hasAuthority('system:audit:delete')")
@DeleteMapping(value = "/deleteByIds")
public ResponseData deleteByIds(List<Long> logIds) {
int result = service.deleteByIds(logIds);
return ResponseData.success(result);
}
///ExpandInterface//
///ExpandInterface//
///ExpandInterface//
@LogAcl(logCenter = "系统管理", logModule = "用户管理", logTitle = "查询登录日志")
@PreAuthorize("hasAuthority('system:audit:select')")
@GetMapping(value = "/selectPageForSignin")
public ResponseData selectPageForSignin(Page page, SysAuditDto dto) {
LambdaQueryWrapper<SysAudit> queryWrapper = new LambdaQueryWrapper();
if (RtStringUtils.isNotEmpty(dto.getLogId())) {
queryWrapper.like(SysAudit::getLogId, dto.getLogId());
}
if (RtStringUtils.isNotEmpty(dto.getLogTraceId())) {
queryWrapper.like(SysAudit::getLogTraceId, dto.getLogTraceId());
}
if (RtStringUtils.isNotEmpty(dto.getLogType())) {
queryWrapper.like(SysAudit::getLogType, dto.getLogCenter());
}
if (RtStringUtils.isNotEmpty(dto.getLogCenter())) {
queryWrapper.like(SysAudit::getLogCenter, dto.getLogCenter());
}
if (RtStringUtils.isNotEmpty(dto.getLogTitle())) {
queryWrapper.like(SysAudit::getLogTitle, dto.getLogTitle());
}
if (RtStringUtils.isNotEmpty(dto.getLogDesc())) {
queryWrapper.like(SysAudit::getLogDesc, dto.getLogDesc());
}
if (RtStringUtils.isNotEmpty(dto.getLogIp())) {
queryWrapper.like(SysAudit::getLogIp, dto.getLogIp());
}
if (RtStringUtils.isNotEmpty(dto.getLogFinger())) {
queryWrapper.like(SysAudit::getLogFinger, dto.getLogFinger());
}
if (RtStringUtils.isNotEmpty(dto.getBeginTime()) && RtStringUtils.isNotEmpty(dto.getEndTime())) {
queryWrapper.between(SysAudit::getCreateTime, dto.getBeginTime(), dto.getEndTime());
}
queryWrapper.orderByDesc(SysAudit::getCreateTime);
IPage<SysAudit> result = service.selectPage(page, queryWrapper);
return ResponseData.success(result);
}
///ExpandInterface//
///ExpandInterface//
///ExpandInterface//
@LogAcl(logCenter = "系统管理", logModule = "用户管理", logTitle = "查询操作日志")
@PreAuthorize("hasAuthority('system:audit:select')")
@GetMapping(value = "/selectPageForOperate")
public ResponseData selectPageForOperate(Page page, SysAuditDto dto) {
LambdaQueryWrapper<SysAudit> queryWrapper = new LambdaQueryWrapper();
if (RtStringUtils.isNotEmpty(dto.getLogId())) {
queryWrapper.like(SysAudit::getLogId, dto.getLogId());
}
if (RtStringUtils.isNotEmpty(dto.getLogTraceId())) {
queryWrapper.like(SysAudit::getLogTraceId, dto.getLogTraceId());
}
if (RtStringUtils.isNotEmpty(dto.getLogTitle())) {
queryWrapper.like(SysAudit::getLogTitle, dto.getLogTitle());
}
if (RtStringUtils.isNotEmpty(dto.getLogDesc())) {
queryWrapper.like(SysAudit::getLogDesc, dto.getLogDesc());
}
if (RtStringUtils.isNotEmpty(dto.getLogIp())) {
queryWrapper.like(SysAudit::getLogIp, dto.getLogIp());
}
if (RtStringUtils.isNotEmpty(dto.getBeginTime()) && RtStringUtils.isNotEmpty(dto.getEndTime())) {
queryWrapper.between(SysAudit::getCreateTime, dto.getBeginTime(), dto.getEndTime());
}
if (RtStringUtils.isNotEmpty(dto.getLogIp())) {
queryWrapper.like(SysAudit::getLogIp, dto.getLogIp());
}
queryWrapper.orderByDesc(SysAudit::getCreateTime);
IPage<SysAudit> result = service.selectPage(page, queryWrapper);
return ResponseData.success(result);
}
}
分页列表页面