Commit 7dad85a9d678fe60d481eb147d81463351e30e73

Authored by YunaiV
1 parent 4ab1cf1c

梳理操作日志表,提交~

ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java
1 1 package com.ruoyi.web.controller.monitor;
2 2  
3 3 import java.util.List;
  4 +
4 5 import org.springframework.beans.factory.annotation.Autowired;
5 6 import org.springframework.security.access.prepost.PreAuthorize;
6 7 import org.springframework.web.bind.annotation.DeleteMapping;
... ... @@ -19,20 +20,19 @@ import com.ruoyi.system.service.ISysOperLogService;
19 20  
20 21 /**
21 22 * 操作日志记录
22   - *
  23 + *
23 24 * @author ruoyi
24 25 */
25 26 @RestController
26 27 @RequestMapping("/monitor/operlog")
27   -public class SysOperlogController extends BaseController
28   -{
  28 +public class SysOperlogController extends BaseController {
  29 +
29 30 @Autowired
30 31 private ISysOperLogService operLogService;
31 32  
32 33 @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
33 34 @GetMapping("/list")
34   - public TableDataInfo list(SysOperLog operLog)
35   - {
  35 + public TableDataInfo list(SysOperLog operLog) {
36 36 startPage();
37 37 List<SysOperLog> list = operLogService.selectOperLogList(operLog);
38 38 return getDataTable(list);
... ... @@ -41,26 +41,10 @@ public class SysOperlogController extends BaseController
41 41 @Log(title = "操作日志", businessType = BusinessType.EXPORT)
42 42 @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
43 43 @GetMapping("/export")
44   - public AjaxResult export(SysOperLog operLog)
45   - {
  44 + public AjaxResult export(SysOperLog operLog) {
46 45 List<SysOperLog> list = operLogService.selectOperLogList(operLog);
47 46 ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
48 47 return util.exportExcel(list, "操作日志");
49 48 }
50 49  
51   - @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
52   - @DeleteMapping("/{operIds}")
53   - public AjaxResult remove(@PathVariable Long[] operIds)
54   - {
55   - return toAjax(operLogService.deleteOperLogByIds(operIds));
56   - }
57   -
58   - @Log(title = "操作日志", businessType = BusinessType.CLEAN)
59   - @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
60   - @DeleteMapping("/clean")
61   - public AjaxResult clean()
62   - {
63   - operLogService.cleanOperLog();
64   - return AjaxResult.success();
65   - }
66 50 }
... ...
ruoyi-common/pom.xml
... ... @@ -17,102 +17,18 @@
17 17  
18 18 <dependencies>
19 19  
20   - <!-- Spring框架基本的核心工具 -->
21   - <dependency>
22   - <groupId>org.springframework</groupId>
23   - <artifactId>spring-context-support</artifactId>
24   - </dependency>
25   -
26   - <!-- SpringWeb模块 -->
27   - <dependency>
28   - <groupId>org.springframework</groupId>
29   - <artifactId>spring-web</artifactId>
30   - </dependency>
31   -
32   -
33   - <!-- pagehelper 分页插件 -->
34   - <dependency>
35   - <groupId>com.github.pagehelper</groupId>
36   - <artifactId>pagehelper-spring-boot-starter</artifactId>
37   - </dependency>
38   -
39   - <!-- 自定义验证注解 -->
40   - <dependency>
41   - <groupId>javax.validation</groupId>
42   - <artifactId>validation-api</artifactId>
43   - </dependency>
44   -
45   - <!--常用工具类 -->
46   - <dependency>
47   - <groupId>org.apache.commons</groupId>
48   - <artifactId>commons-lang3</artifactId>
49   - </dependency>
50   -
51   - <!-- JSON工具类 -->
52   - <dependency>
53   - <groupId>com.fasterxml.jackson.core</groupId>
54   - <artifactId>jackson-databind</artifactId>
55   - </dependency>
56   -
57   - <!-- 阿里JSON解析器 -->
58   - <dependency>
59   - <groupId>com.alibaba</groupId>
60   - <artifactId>fastjson</artifactId>
61   - </dependency>
62   -
63   - <!-- io常用工具类 -->
64   - <dependency>
65   - <groupId>commons-io</groupId>
66   - <artifactId>commons-io</artifactId>
67   - </dependency>
68   -
69   - <!-- 文件上传工具类 -->
70   - <dependency>
71   - <groupId>commons-fileupload</groupId>
72   - <artifactId>commons-fileupload</artifactId>
73   - </dependency>
74   -
75   - <!-- excel工具 -->
76   - <dependency>
77   - <groupId>org.apache.poi</groupId>
78   - <artifactId>poi-ooxml</artifactId>
79   - </dependency>
80   -
81 20 <!-- yml解析器 -->
82 21 <dependency>
83 22 <groupId>org.yaml</groupId>
84 23 <artifactId>snakeyaml</artifactId>
85 24 </dependency>
86 25  
87   - <!--Token生成与解析-->
88   - <dependency>
89   - <groupId>io.jsonwebtoken</groupId>
90   - <artifactId>jjwt</artifactId>
91   - </dependency>
92   -
93   - <!-- redis 缓存操作 -->
94   - <dependency>
95   - <groupId>org.springframework.boot</groupId>
96   - <artifactId>spring-boot-starter-data-redis</artifactId>
97   - </dependency>
98   -
99   - <!-- pool 对象池 -->
100   - <dependency>
101   - <groupId>org.apache.commons</groupId>
102   - <artifactId>commons-pool2</artifactId>
103   - </dependency>
104   -
105 26 <!-- 解析客户端操作系统、浏览器等 -->
106 27 <dependency>
107 28 <groupId>eu.bitwalker</groupId>
108 29 <artifactId>UserAgentUtils</artifactId>
109 30 </dependency>
110 31  
111   - <!-- servlet包 -->
112   - <dependency>
113   - <groupId>javax.servlet</groupId>
114   - <artifactId>javax.servlet-api</artifactId>
115   - </dependency>
116 32  
117 33 </dependencies>
118 34  
... ...
ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessStatus.java deleted
1   -package com.ruoyi.common.enums;
2   -
3   -/**
4   - * 操作状态
5   - *
6   - * @author ruoyi
7   - *
8   - */
9   -public enum BusinessStatus
10   -{
11   - /**
12   - * 成功
13   - */
14   - SUCCESS,
15   -
16   - /**
17   - * 失败
18   - */
19   - FAIL,
20   -}
ruoyi-common/src/main/java/com/ruoyi/common/enums/OperatorType.java deleted
1   -package com.ruoyi.common.enums;
2   -
3   -/**
4   - * 操作人类别
5   - *
6   - * @author ruoyi
7   - */
8   -public enum OperatorType
9   -{
10   - /**
11   - * 其它
12   - */
13   - OTHER,
14   -
15   - /**
16   - * 后台用户
17   - */
18   - MANAGE,
19   -
20   - /**
21   - * 手机端用户
22   - */
23   - MOBILE
24   -}
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java deleted
1   -package com.ruoyi.system.domain;
2   -
3   -import java.util.Date;
4   -import com.fasterxml.jackson.annotation.JsonFormat;
5   -import com.ruoyi.common.annotation.Excel;
6   -import com.ruoyi.common.annotation.Excel.ColumnType;
7   -import com.ruoyi.common.core.domain.BaseEntity;
8   -
9   -/**
10   - * 操作日志记录表 oper_log
11   - *
12   - * @author ruoyi
13   - */
14   -public class SysOperLog extends BaseEntity
15   -{
16   - private static final long serialVersionUID = 1L;
17   -
18   - /** 日志主键 */
19   - @Excel(name = "操作序号", cellType = ColumnType.NUMERIC)
20   - private Long operId;
21   -
22   - /** 操作模块 */
23   - @Excel(name = "操作模块")
24   - private String title;
25   -
26   - /** 业务类型(0其它 1新增 2修改 3删除) */
27   - @Excel(name = "业务类型", readConverterExp = "0=其它,1=新增,2=修改,3=删除,4=授权,5=导出,6=导入,7=强退,8=生成代码,9=清空数据")
28   - private Integer businessType;
29   -
30   - /** 业务类型数组 */
31   - private Integer[] businessTypes;
32   -
33   - /** 请求方法 */
34   - @Excel(name = "请求方法")
35   - private String method;
36   -
37   - /** 请求方式 */
38   - @Excel(name = "请求方式")
39   - private String requestMethod;
40   -
41   - /** 操作类别(0其它 1后台用户 2手机端用户) */
42   - @Excel(name = "操作类别", readConverterExp = "0=其它,1=后台用户,2=手机端用户")
43   - private Integer operatorType;
44   -
45   - /** 操作人员 */
46   - @Excel(name = "操作人员")
47   - private String operName;
48   -
49   - /** 部门名称 */
50   - @Excel(name = "部门名称")
51   - private String deptName;
52   -
53   - /** 请求url */
54   - @Excel(name = "请求地址")
55   - private String operUrl;
56   -
57   - /** 操作地址 */
58   - @Excel(name = "操作地址")
59   - private String operIp;
60   -
61   - /** 操作地点 */
62   - @Excel(name = "操作地点")
63   - private String operLocation;
64   -
65   - /** 请求参数 */
66   - @Excel(name = "请求参数")
67   - private String operParam;
68   -
69   - /** 返回参数 */
70   - @Excel(name = "返回参数")
71   - private String jsonResult;
72   -
73   - /** 操作状态(0正常 1异常) */
74   - @Excel(name = "状态", readConverterExp = "0=正常,1=异常")
75   - private Integer status;
76   -
77   - /** 错误消息 */
78   - @Excel(name = "错误消息")
79   - private String errorMsg;
80   -
81   - /** 操作时间 */
82   - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
83   - @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
84   - private Date operTime;
85   -
86   -}
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOperLogService.java deleted
1   -package com.ruoyi.system.service;
2   -
3   -import java.util.List;
4   -import com.ruoyi.system.domain.SysOperLog;
5   -
6   -/**
7   - * 操作日志 服务层
8   - *
9   - * @author ruoyi
10   - */
11   -public interface ISysOperLogService
12   -{
13   - /**
14   - * 新增操作日志
15   - *
16   - * @param operLog 操作日志对象
17   - */
18   - public void insertOperlog(SysOperLog operLog);
19   -
20   - /**
21   - * 查询系统操作日志集合
22   - *
23   - * @param operLog 操作日志对象
24   - * @return 操作日志集合
25   - */
26   - public List<SysOperLog> selectOperLogList(SysOperLog operLog);
27   -
28   - /**
29   - * 批量删除系统操作日志
30   - *
31   - * @param operIds 需要删除的操作日志ID
32   - * @return 结果
33   - */
34   - public int deleteOperLogByIds(Long[] operIds);
35   -
36   - /**
37   - * 查询操作日志详细
38   - *
39   - * @param operId 操作ID
40   - * @return 操作日志对象
41   - */
42   - public SysOperLog selectOperLogById(Long operId);
43   -
44   - /**
45   - * 清空操作日志
46   - */
47   - public void cleanOperLog();
48   -}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java
... ... @@ -39,16 +39,6 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
39 39 return operLogMapper.selectOperLogList(operLog);
40 40 }
41 41  
42   - /**
43   - * 批量删除系统操作日志
44   - *
45   - * @param operIds 需要删除的操作日志ID
46   - * @return 结果
47   - */
48   - @Override
49   - public int deleteOperLogByIds(Long[] operIds) {
50   - return operLogMapper.deleteOperLogByIds(operIds);
51   - }
52 42  
53 43 /**
54 44 * 查询操作日志详细
... ... @@ -61,11 +51,4 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
61 51 return operLogMapper.selectOperLogById(operId);
62 52 }
63 53  
64   - /**
65   - * 清空操作日志
66   - */
67   - @Override
68   - public void cleanOperLog() {
69   - operLogMapper.cleanOperLog();
70   - }
71 54 }
... ...
ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml
... ... @@ -4,35 +4,6 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
4 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5 5 <mapper namespace="com.ruoyi.system.mapper.SysOperLogMapper">
6 6  
7   - <resultMap type="SysOperLog" id="SysOperLogResult">
8   - <id property="operId" column="oper_id" />
9   - <result property="title" column="title" />
10   - <result property="businessType" column="business_type" />
11   - <result property="method" column="method" />
12   - <result property="requestMethod" column="request_method" />
13   - <result property="operatorType" column="operator_type" />
14   - <result property="operName" column="oper_name" />
15   - <result property="deptName" column="dept_name" />
16   - <result property="operUrl" column="oper_url" />
17   - <result property="operIp" column="oper_ip" />
18   - <result property="operLocation" column="oper_location" />
19   - <result property="operParam" column="oper_param" />
20   - <result property="jsonResult" column="json_result" />
21   - <result property="status" column="status" />
22   - <result property="errorMsg" column="error_msg" />
23   - <result property="operTime" column="oper_time" />
24   - </resultMap>
25   -
26   - <sql id="selectOperLogVo">
27   - 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
28   - from sys_oper_log
29   - </sql>
30   -
31   - <insert id="insertOperlog" parameterType="SysOperLog">
32   - 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)
33   - values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, sysdate())
34   - </insert>
35   -
36 7 <select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">
37 8 <include refid="selectOperLogVo"/>
38 9 <where>
... ... @@ -46,7 +17,7 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
46 17 AND business_type in
47 18 <foreach collection="businessTypes" item="businessType" open="(" separator="," close=")">
48 19 #{businessType}
49   - </foreach>
  20 + </foreach>
50 21 </if>
51 22 <if test="status != null">
52 23 AND status = #{status}
... ... @@ -63,21 +34,6 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
63 34 </where>
64 35 order by oper_id desc
65 36 </select>
66   -
67   - <delete id="deleteOperLogByIds" parameterType="Long">
68   - delete from sys_oper_log where oper_id in
69   - <foreach collection="array" item="operId" open="(" separator="," close=")">
70   - #{operId}
71   - </foreach>
72   - </delete>
73   -
74   - <select id="selectOperLogById" parameterType="Long" resultMap="SysOperLogResult">
75   - <include refid="selectOperLogVo"/>
76   - where oper_id = #{operId}
77   - </select>
78   -
79   - <update id="cleanOperLog">
80   - truncate table sys_oper_log
81   - </update>
82 37  
83   -</mapper>
84 38 \ No newline at end of file
  39 +
  40 +</mapper>
... ...
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger;
  2 +
  3 +import cn.iocoder.dashboard.common.pojo.CommonResult;
  4 +import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
  5 +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
  6 +import cn.iocoder.dashboard.modules.system.enums.logger.SysOperateLogTypeEnum;
  7 +import com.baomidou.mybatisplus.annotation.TableField;
  8 +import com.baomidou.mybatisplus.annotation.TableId;
  9 +import com.baomidou.mybatisplus.annotation.TableName;
  10 +import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
  11 +import lombok.Data;
  12 +import lombok.EqualsAndHashCode;
  13 +
  14 +import java.util.Date;
  15 +import java.util.Map;
  16 +
  17 +/**
  18 + * 操作日志表
  19 + *
  20 + * @author 芋道源码
  21 + */
  22 +@TableName("sys_operate_log")
  23 +@Data
  24 +@EqualsAndHashCode(callSuper = true)
  25 +public class SysOperateLogDO extends BaseDO {
  26 +
  27 + /**
  28 + * 日志主键
  29 + */
  30 + @TableId
  31 + private Long id;
  32 + /**
  33 + * 链路追踪编号
  34 + *
  35 + * 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。
  36 + */
  37 + private String traceId;
  38 + /**
  39 + * 操作人
  40 + *
  41 + * {@link SysUserDO#getId()}
  42 + */
  43 + private Long userId;
  44 + /**
  45 + * 操作模块
  46 + */
  47 + private String module;
  48 + /**
  49 + * 操作名
  50 + */
  51 + private String name;
  52 + /**
  53 + * 操作分类
  54 + *
  55 + * 枚举 {@link SysOperateLogTypeEnum}
  56 + */
  57 + private Integer type;
  58 + /**
  59 + * 操作内容,记录整个操作的明细
  60 + * 例如说,修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。
  61 + *
  62 + * TODO 预留字段
  63 + */
  64 + private String content;
  65 + /**
  66 + * 拓展字段,有些复杂的业务,需要记录一些字段
  67 + * 例如说,记录订单编号,则可以添加 key 为 "orderId",value 为订单编号
  68 + *
  69 + * TODO 预留字段
  70 + */
  71 + @TableField(typeHandler = FastjsonTypeHandler.class)
  72 + private Map<String, Object> ext;
  73 +
  74 + /**
  75 + * 请求方法名
  76 + */
  77 + private String requestMethod;
  78 + /**
  79 + * 请求地址
  80 + */
  81 + private String requestUrl;
  82 + /**
  83 + * 请求参数
  84 + */
  85 + @TableField(typeHandler = FastjsonTypeHandler.class)
  86 + private Map<String, Object> requestParams;
  87 + /**
  88 + * 用户 IP
  89 + */
  90 + private String userIp;
  91 + /**
  92 + * 浏览器 UA
  93 + */
  94 + private String userAgent;
  95 +
  96 + /**
  97 + * Java 方法名
  98 + */
  99 + private String javaMethod;
  100 + /**
  101 + * 开始时间
  102 + */
  103 + private Date startTime;
  104 + /**
  105 + * 执行时长,单位:毫秒
  106 + */
  107 + private Integer duration;
  108 + /**
  109 + * 结果码
  110 + *
  111 + * 目前使用的 {@link CommonResult#getCode()} 属性
  112 + */
  113 + private Integer resultCode;
  114 + /**
  115 + * 结果提示
  116 + *
  117 + * 目前使用的 {@link CommonResult#getMsg()} 属性
  118 + */
  119 + private String resultMsg;
  120 + /**
  121 + * 结果数据
  122 + */
  123 + @TableField(typeHandler = FastjsonTypeHandler.class)
  124 + private Map<String, Object> resultData;
  125 +
  126 +}
... ...
ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessType.java renamed to src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysOperateLogTypeEnum.java
1   -package com.ruoyi.common.enums;
2   -
3   -/**
4   - * 业务操作类型
5   - *
6   - * @author ruoyi
7   - */
8   -public enum BusinessType
9   -{
10   - /**
11   - * 其它
12   - */
13   - OTHER,
14   -
15   - /**
16   - * 新增
17   - */
18   - INSERT,
19   -
20   - /**
21   - * 修改
22   - */
23   - UPDATE,
24   -
25   - /**
26   - * 删除
27   - */
28   - DELETE,
29   -
30   - /**
31   - * 授权
32   - */
33   - GRANT,
34   -
35   - /**
36   - * 导出
37   - */
38   - EXPORT,
39   -
40   - /**
41   - * 导入
42   - */
43   - IMPORT,
44   -
45   - /**
46   - * 强退
47   - */
48   - FORCE,
49   -
50   - /**
51   - * 生成代码
52   - */
53   - GENCODE,
54   -
55   - /**
56   - * 清空数据
57   - */
58   - CLEAN,
59   -}
  1 +package cn.iocoder.dashboard.modules.system.enums.logger;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Getter;
  5 +
  6 +/**
  7 + * 操作日志的操作类型
  8 + *
  9 + * @author ruoyi
  10 + */
  11 +@Getter
  12 +@AllArgsConstructor
  13 +public enum SysOperateLogTypeEnum {
  14 +
  15 + /**
  16 + * 新增
  17 + */
  18 + CREATE(1),
  19 + /**
  20 + * 修改
  21 + */
  22 + UPDATE(2),
  23 + /**
  24 + * 删除
  25 + */
  26 + DELETE(3),
  27 + /**
  28 + * 导出
  29 + */
  30 + EXPORT(4),
  31 + /**
  32 + * 导入
  33 + */
  34 + IMPORT(5),
  35 + /**
  36 + * 其它
  37 + *
  38 + * 在无法归类时,可以选择使用其它。因为还有操作名可以进一步标识
  39 + */
  40 + OTHER(0);
  41 +
  42 + /**
  43 + * 类型
  44 + */
  45 + private final Integer type;
  46 +
  47 +}
... ...