梳理操作日志表,提交~

pull/2/head
YunaiV 2021-01-16 01:37:46 +08:00
parent 4ab1cf1cd4
commit 7dad85a9d6
11 changed files with 182 additions and 407 deletions

View File

@ -1,6 +1,7 @@
package com.ruoyi.web.controller.monitor; package com.ruoyi.web.controller.monitor;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
@ -24,15 +25,14 @@ import com.ruoyi.system.service.ISysOperLogService;
*/ */
@RestController @RestController
@RequestMapping("/monitor/operlog") @RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController public class SysOperlogController extends BaseController {
{
@Autowired @Autowired
private ISysOperLogService operLogService; private ISysOperLogService operLogService;
@PreAuthorize("@ss.hasPermi('monitor:operlog:list')") @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SysOperLog operLog) public TableDataInfo list(SysOperLog operLog) {
{
startPage(); startPage();
List<SysOperLog> list = operLogService.selectOperLogList(operLog); List<SysOperLog> list = operLogService.selectOperLogList(operLog);
return getDataTable(list); return getDataTable(list);
@ -41,26 +41,10 @@ public class SysOperlogController extends BaseController
@Log(title = "操作日志", businessType = BusinessType.EXPORT) @Log(title = "操作日志", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('monitor:operlog:export')") @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
@GetMapping("/export") @GetMapping("/export")
public AjaxResult export(SysOperLog operLog) public AjaxResult export(SysOperLog operLog) {
{
List<SysOperLog> list = operLogService.selectOperLogList(operLog); List<SysOperLog> list = operLogService.selectOperLogList(operLog);
ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class); ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
return util.exportExcel(list, "操作日志"); return util.exportExcel(list, "操作日志");
} }
@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
@DeleteMapping("/{operIds}")
public AjaxResult remove(@PathVariable Long[] operIds)
{
return toAjax(operLogService.deleteOperLogByIds(operIds));
}
@Log(title = "操作日志", businessType = BusinessType.CLEAN)
@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
@DeleteMapping("/clean")
public AjaxResult clean()
{
operLogService.cleanOperLog();
return AjaxResult.success();
}
} }

View File

@ -17,102 +17,18 @@
<dependencies> <dependencies>
<!-- Spring框架基本的核心工具 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- SpringWeb模块 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- pagehelper 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<!-- 自定义验证注解 -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!--常用工具类 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- JSON工具类 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- 阿里JSON解析器 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<!-- io常用工具类 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!-- 文件上传工具类 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<!-- excel工具 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<!-- yml解析器 --> <!-- yml解析器 -->
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
</dependency> </dependency>
<!--Token生成与解析-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
<!-- redis 缓存操作 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- pool 对象池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- 解析客户端操作系统、浏览器等 --> <!-- 解析客户端操作系统、浏览器等 -->
<dependency> <dependency>
<groupId>eu.bitwalker</groupId> <groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId> <artifactId>UserAgentUtils</artifactId>
</dependency> </dependency>
<!-- servlet包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@ -1,20 +0,0 @@
package com.ruoyi.common.enums;
/**
*
*
* @author ruoyi
*
*/
public enum BusinessStatus
{
/**
*
*/
SUCCESS,
/**
*
*/
FAIL,
}

View File

@ -1,59 +0,0 @@
package com.ruoyi.common.enums;
/**
*
*
* @author ruoyi
*/
public enum BusinessType
{
/**
*
*/
OTHER,
/**
*
*/
INSERT,
/**
*
*/
UPDATE,
/**
*
*/
DELETE,
/**
*
*/
GRANT,
/**
*
*/
EXPORT,
/**
*
*/
IMPORT,
/**
* 退
*/
FORCE,
/**
*
*/
GENCODE,
/**
*
*/
CLEAN,
}

View File

@ -1,24 +0,0 @@
package com.ruoyi.common.enums;
/**
*
*
* @author ruoyi
*/
public enum OperatorType
{
/**
*
*/
OTHER,
/**
*
*/
MANAGE,
/**
*
*/
MOBILE
}

View File

@ -1,86 +0,0 @@
package com.ruoyi.system.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* oper_log
*
* @author ruoyi
*/
public class SysOperLog extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 日志主键 */
@Excel(name = "操作序号", cellType = ColumnType.NUMERIC)
private Long operId;
/** 操作模块 */
@Excel(name = "操作模块")
private String title;
/** 业务类型0其它 1新增 2修改 3删除 */
@Excel(name = "业务类型", readConverterExp = "0=其它,1=新增,2=修改,3=删除,4=授权,5=导出,6=导入,7=强退,8=生成代码,9=清空数据")
private Integer businessType;
/** 业务类型数组 */
private Integer[] businessTypes;
/** 请求方法 */
@Excel(name = "请求方法")
private String method;
/** 请求方式 */
@Excel(name = "请求方式")
private String requestMethod;
/** 操作类别0其它 1后台用户 2手机端用户 */
@Excel(name = "操作类别", readConverterExp = "0=其它,1=后台用户,2=手机端用户")
private Integer operatorType;
/** 操作人员 */
@Excel(name = "操作人员")
private String operName;
/** 部门名称 */
@Excel(name = "部门名称")
private String deptName;
/** 请求url */
@Excel(name = "请求地址")
private String operUrl;
/** 操作地址 */
@Excel(name = "操作地址")
private String operIp;
/** 操作地点 */
@Excel(name = "操作地点")
private String operLocation;
/** 请求参数 */
@Excel(name = "请求参数")
private String operParam;
/** 返回参数 */
@Excel(name = "返回参数")
private String jsonResult;
/** 操作状态0正常 1异常 */
@Excel(name = "状态", readConverterExp = "0=正常,1=异常")
private Integer status;
/** 错误消息 */
@Excel(name = "错误消息")
private String errorMsg;
/** 操作时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date operTime;
}

View File

@ -1,48 +0,0 @@
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.SysOperLog;
/**
*
*
* @author ruoyi
*/
public interface ISysOperLogService
{
/**
*
*
* @param operLog
*/
public void insertOperlog(SysOperLog operLog);
/**
*
*
* @param operLog
* @return
*/
public List<SysOperLog> selectOperLogList(SysOperLog operLog);
/**
*
*
* @param operIds ID
* @return
*/
public int deleteOperLogByIds(Long[] operIds);
/**
*
*
* @param operId ID
* @return
*/
public SysOperLog selectOperLogById(Long operId);
/**
*
*/
public void cleanOperLog();
}

View File

@ -39,16 +39,6 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
return operLogMapper.selectOperLogList(operLog); return operLogMapper.selectOperLogList(operLog);
} }
/**
*
*
* @param operIds ID
* @return
*/
@Override
public int deleteOperLogByIds(Long[] operIds) {
return operLogMapper.deleteOperLogByIds(operIds);
}
/** /**
* *
@ -61,11 +51,4 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
return operLogMapper.selectOperLogById(operId); return operLogMapper.selectOperLogById(operId);
} }
/**
*
*/
@Override
public void cleanOperLog() {
operLogMapper.cleanOperLog();
}
} }

View File

@ -4,35 +4,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.SysOperLogMapper"> <mapper namespace="com.ruoyi.system.mapper.SysOperLogMapper">
<resultMap type="SysOperLog" id="SysOperLogResult">
<id property="operId" column="oper_id" />
<result property="title" column="title" />
<result property="businessType" column="business_type" />
<result property="method" column="method" />
<result property="requestMethod" column="request_method" />
<result property="operatorType" column="operator_type" />
<result property="operName" column="oper_name" />
<result property="deptName" column="dept_name" />
<result property="operUrl" column="oper_url" />
<result property="operIp" column="oper_ip" />
<result property="operLocation" column="oper_location" />
<result property="operParam" column="oper_param" />
<result property="jsonResult" column="json_result" />
<result property="status" column="status" />
<result property="errorMsg" column="error_msg" />
<result property="operTime" column="oper_time" />
</resultMap>
<sql id="selectOperLogVo">
select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time
from sys_oper_log
</sql>
<insert id="insertOperlog" parameterType="SysOperLog">
insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time)
values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, sysdate())
</insert>
<select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult"> <select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">
<include refid="selectOperLogVo"/> <include refid="selectOperLogVo"/>
<where> <where>
@ -64,20 +35,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by oper_id desc order by oper_id desc
</select> </select>
<delete id="deleteOperLogByIds" parameterType="Long">
delete from sys_oper_log where oper_id in
<foreach collection="array" item="operId" open="(" separator="," close=")">
#{operId}
</foreach>
</delete>
<select id="selectOperLogById" parameterType="Long" resultMap="SysOperLogResult">
<include refid="selectOperLogVo"/>
where oper_id = #{operId}
</select>
<update id="cleanOperLog">
truncate table sys_oper_log
</update>
</mapper> </mapper>

View File

@ -0,0 +1,126 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger;
import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
import cn.iocoder.dashboard.modules.system.enums.logger.SysOperateLogTypeEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import java.util.Map;
/**
*
*
* @author
*/
@TableName("sys_operate_log")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysOperateLogDO extends BaseDO {
/**
*
*/
@TableId
private Long id;
/**
*
*
* 访logger
*/
private String traceId;
/**
*
*
* {@link SysUserDO#getId()}
*/
private Long userId;
/**
*
*/
private String module;
/**
*
*/
private String name;
/**
*
*
* {@link SysOperateLogTypeEnum}
*/
private Integer type;
/**
*
* 1
*
* TODO
*/
private String content;
/**
*
* key "orderId"value
*
* TODO
*/
@TableField(typeHandler = FastjsonTypeHandler.class)
private Map<String, Object> ext;
/**
*
*/
private String requestMethod;
/**
*
*/
private String requestUrl;
/**
*
*/
@TableField(typeHandler = FastjsonTypeHandler.class)
private Map<String, Object> requestParams;
/**
* IP
*/
private String userIp;
/**
* UA
*/
private String userAgent;
/**
* Java
*/
private String javaMethod;
/**
*
*/
private Date startTime;
/**
*
*/
private Integer duration;
/**
*
*
* 使 {@link CommonResult#getCode()}
*/
private Integer resultCode;
/**
*
*
* 使 {@link CommonResult#getMsg()}
*/
private String resultMsg;
/**
*
*/
@TableField(typeHandler = FastjsonTypeHandler.class)
private Map<String, Object> resultData;
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.dashboard.modules.system.enums.logger;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
*
* @author ruoyi
*/
@Getter
@AllArgsConstructor
public enum SysOperateLogTypeEnum {
/**
*
*/
CREATE(1),
/**
*
*/
UPDATE(2),
/**
*
*/
DELETE(3),
/**
*
*/
EXPORT(4),
/**
*
*/
IMPORT(5),
/**
*
*
* 使
*/
OTHER(0);
/**
*
*/
private final Integer type;
}