RuoYi
2023-02-16 ee2ecbc0b4fe1900f0c2f71f34fc5dfe8b910d74
操作日志新增消耗时间属性
已修改3个文件
已重命名1个文件
42 ■■■■■ 文件已修改
sql/ry_20230216.sql 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/framework/aspectj/LogAspect.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/project/monitor/domain/SysOperLog.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mybatis/monitor/SysOperLogMapper.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sql/ry_20230216.sql
ÎļþÃû´Ó sql/ry_20220822.sql ÐÞ¸Ä
@@ -432,6 +432,7 @@
  status            int(1)          default 0                  comment '操作状态(0正常 1异常)',
  error_msg         varchar(2000)   default ''                 comment '错误消息',
  oper_time         datetime                                   comment '操作时间',
  cost_time         bigint(20)      default 0                  comment '消耗时间',
  primary key (oper_id)
) engine=innodb auto_increment=100 comment = '操作日志记录';
src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
@@ -8,8 +8,10 @@
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.NamedThreadLocal;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.web.multipart.MultipartFile;
@@ -40,6 +42,18 @@
    /** æŽ’除敏感属性字段 */
    public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
    /** è®¡ç®—操作消耗时间 */
    private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
    /**
     * å¤„理请求前执行
     */
    @Before(value = "@annotation(controllerLog)")
    public void boBefore(JoinPoint joinPoint, Log controllerLog)
    {
        TIME_THREADLOCAL.set(System.currentTimeMillis());
    }
    /**
     * å¤„理完请求后执行
@@ -96,6 +110,8 @@
            operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
            // å¤„理设置注解上的参数
            getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
            // è®¾ç½®æ¶ˆè€—æ—¶é—´
            operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
            // ä¿å­˜æ•°æ®åº“
            AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
        }
@@ -105,6 +121,10 @@
            log.error("异常信息:{}", exp.getMessage());
            exp.printStackTrace();
        }
        finally
        {
            TIME_THREADLOCAL.remove();
        }
    }
    /**
src/main/java/com/ruoyi/project/monitor/domain/SysOperLog.java
@@ -83,6 +83,10 @@
    @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date operTime;
    /** æ¶ˆè€—æ—¶é—´ */
    @Excel(name = "消耗时间", suffix = "毫秒")
    private Long costTime;
    public Long getOperId()
    {
        return operId;
@@ -252,4 +256,14 @@
    {
        this.operTime = operTime;
    }
    public Long getCostTime()
    {
        return costTime;
    }
    public void setCostTime(Long costTime)
    {
        this.costTime = costTime;
    }
}
src/main/resources/mybatis/monitor/SysOperLogMapper.xml
@@ -21,16 +21,17 @@
        <result property="status"         column="status"         />
        <result property="errorMsg"       column="error_msg"      />
        <result property="operTime"       column="oper_time"      />
        <result property="costTime"       column="cost_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
        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, cost_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 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, cost_time, oper_time)
        values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate())
    </insert>
    
    <select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">