From 7dad85a9d678fe60d481eb147d81463351e30e73 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 16 Jan 2021 01:37:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A2=B3=E7=90=86=E6=93=8D=E4=BD=9C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=A1=A8=EF=BC=8C=E6=8F=90=E4=BA=A4~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitor/SysOperlogController.java | 28 +--- ruoyi-common/pom.xml | 84 ------------ .../ruoyi/common/enums/BusinessStatus.java | 20 --- .../com/ruoyi/common/enums/BusinessType.java | 59 -------- .../com/ruoyi/common/enums/OperatorType.java | 24 ---- .../com/ruoyi/system/domain/SysOperLog.java | 86 ------------ .../system/service/ISysOperLogService.java | 48 ------- .../service/impl/SysOperLogServiceImpl.java | 17 --- .../mapper/system/SysOperLogMapper.xml | 50 +------ .../dataobject/logger/SysOperateLogDO.java | 126 ++++++++++++++++++ .../enums/logger/SysOperateLogTypeEnum.java | 47 +++++++ 11 files changed, 182 insertions(+), 407 deletions(-) delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessStatus.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessType.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/OperatorType.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOperLogService.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysOperateLogTypeEnum.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java index 194285613..276442289 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java @@ -1,6 +1,7 @@ package com.ruoyi.web.controller.monitor; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.DeleteMapping; @@ -19,20 +20,19 @@ import com.ruoyi.system.service.ISysOperLogService; /** * 操作日志记录 - * + * * @author ruoyi */ @RestController @RequestMapping("/monitor/operlog") -public class SysOperlogController extends BaseController -{ +public class SysOperlogController extends BaseController { + @Autowired private ISysOperLogService operLogService; @PreAuthorize("@ss.hasPermi('monitor:operlog:list')") @GetMapping("/list") - public TableDataInfo list(SysOperLog operLog) - { + public TableDataInfo list(SysOperLog operLog) { startPage(); List list = operLogService.selectOperLogList(operLog); return getDataTable(list); @@ -41,26 +41,10 @@ public class SysOperlogController extends BaseController @Log(title = "操作日志", businessType = BusinessType.EXPORT) @PreAuthorize("@ss.hasPermi('monitor:operlog:export')") @GetMapping("/export") - public AjaxResult export(SysOperLog operLog) - { + public AjaxResult export(SysOperLog operLog) { List list = operLogService.selectOperLogList(operLog); ExcelUtil util = new ExcelUtil(SysOperLog.class); 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(); - } } diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 0a477eab0..ab7f11b1b 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -17,102 +17,18 @@ - - - org.springframework - spring-context-support - - - - - org.springframework - spring-web - - - - - - com.github.pagehelper - pagehelper-spring-boot-starter - - - - - javax.validation - validation-api - - - - - org.apache.commons - commons-lang3 - - - - - com.fasterxml.jackson.core - jackson-databind - - - - - com.alibaba - fastjson - - - - - commons-io - commons-io - - - - - commons-fileupload - commons-fileupload - - - - - org.apache.poi - poi-ooxml - - org.yaml snakeyaml - - - io.jsonwebtoken - jjwt - - - - - org.springframework.boot - spring-boot-starter-data-redis - - - - - org.apache.commons - commons-pool2 - - eu.bitwalker UserAgentUtils - - - javax.servlet - javax.servlet-api - diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessStatus.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessStatus.java deleted file mode 100644 index 78188fc16..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessStatus.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ruoyi.common.enums; - -/** - * 操作状态 - * - * @author ruoyi - * - */ -public enum BusinessStatus -{ - /** - * 成功 - */ - SUCCESS, - - /** - * 失败 - */ - FAIL, -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessType.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessType.java deleted file mode 100644 index 2bbeaf7d3..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/enums/BusinessType.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.ruoyi.common.enums; - -/** - * 业务操作类型 - * - * @author ruoyi - */ -public enum BusinessType -{ - /** - * 其它 - */ - OTHER, - - /** - * 新增 - */ - INSERT, - - /** - * 修改 - */ - UPDATE, - - /** - * 删除 - */ - DELETE, - - /** - * 授权 - */ - GRANT, - - /** - * 导出 - */ - EXPORT, - - /** - * 导入 - */ - IMPORT, - - /** - * 强退 - */ - FORCE, - - /** - * 生成代码 - */ - GENCODE, - - /** - * 清空数据 - */ - CLEAN, -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/OperatorType.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/OperatorType.java deleted file mode 100644 index 06532af8f..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/enums/OperatorType.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.ruoyi.common.enums; - -/** - * 操作人类别 - * - * @author ruoyi - */ -public enum OperatorType -{ - /** - * 其它 - */ - OTHER, - - /** - * 后台用户 - */ - MANAGE, - - /** - * 手机端用户 - */ - MOBILE -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java deleted file mode 100644 index c1876d8f5..000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysOperLog.java +++ /dev/null @@ -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; - -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOperLogService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOperLogService.java deleted file mode 100644 index 241f121ae..000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOperLogService.java +++ /dev/null @@ -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 selectOperLogList(SysOperLog operLog); - - /** - * 批量删除系统操作日志 - * - * @param operIds 需要删除的操作日志ID - * @return 结果 - */ - public int deleteOperLogByIds(Long[] operIds); - - /** - * 查询操作日志详细 - * - * @param operId 操作ID - * @return 操作日志对象 - */ - public SysOperLog selectOperLogById(Long operId); - - /** - * 清空操作日志 - */ - public void cleanOperLog(); -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java index bfedc6af5..939e8d9ef 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java @@ -39,16 +39,6 @@ public class SysOperLogServiceImpl implements ISysOperLogService { 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); } - /** - * 清空操作日志 - */ - @Override - public void cleanOperLog() { - operLogMapper.cleanOperLog(); - } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml index 2359a49b8..1d9e492d2 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml @@ -4,35 +4,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - - - - 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 - - - - 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()) - - - - - delete from sys_oper_log where oper_id in - - #{operId} - - - - - - - truncate table sys_oper_log - - \ No newline at end of file + + diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java new file mode 100644 index 000000000..f3af32faf --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/logger/SysOperateLogDO.java @@ -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 ext; + + /** + * 请求方法名 + */ + private String requestMethod; + /** + * 请求地址 + */ + private String requestUrl; + /** + * 请求参数 + */ + @TableField(typeHandler = FastjsonTypeHandler.class) + private Map 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 resultData; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysOperateLogTypeEnum.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysOperateLogTypeEnum.java new file mode 100644 index 000000000..a60d14d18 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysOperateLogTypeEnum.java @@ -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; + +}