操作日志新增消耗时间属性
parent
e26b65ca31
commit
00f2db99d8
|
@ -19,12 +19,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-2 control-label">请求地址:</label>
|
<label class="col-sm-2 control-label">请求地址:</label>
|
||||||
<div class="form-control-static" th:text="${operLog.operUrl}">
|
<div class="form-control-static" th:text="${operLog.requestMethod} + ' - ' + ${operLog.operUrl} + ' ' + '(' + '耗时' + ${operLog.costTime} + '毫秒)'">
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label">请求方式:</label>
|
|
||||||
<div class="form-control-static" th:text="${operLog.requestMethod}">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
@ -136,6 +136,14 @@
|
||||||
title: '操作时间',
|
title: '操作时间',
|
||||||
sortable: true
|
sortable: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: 'costTime',
|
||||||
|
title: '消耗时间',
|
||||||
|
sortable: true,
|
||||||
|
formatter: function(value, row, index) {
|
||||||
|
return $.common.sprintf("%s毫秒", value);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
|
|
|
@ -250,6 +250,7 @@ public class SysUser extends BaseEntity
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
public String getSalt()
|
public String getSalt()
|
||||||
{
|
{
|
||||||
return salt;
|
return salt;
|
||||||
|
|
|
@ -8,9 +8,10 @@ import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.AfterThrowing;
|
import org.aspectj.lang.annotation.AfterThrowing;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.NamedThreadLocal;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -40,10 +41,16 @@ public class LogAspect
|
||||||
/** 排除敏感属性字段 */
|
/** 排除敏感属性字段 */
|
||||||
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
||||||
|
|
||||||
// 配置织入点
|
/** 计算操作消耗时间 */
|
||||||
@Pointcut("@annotation(com.ruoyi.common.annotation.Log)")
|
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
||||||
public void logPointCut()
|
|
||||||
|
/**
|
||||||
|
* 处理请求前执行
|
||||||
|
*/
|
||||||
|
@Before(value = "@annotation(controllerLog)")
|
||||||
|
public void boBefore(JoinPoint joinPoint, Log controllerLog)
|
||||||
{
|
{
|
||||||
|
TIME_THREADLOCAL.set(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,16 +113,21 @@ public class LogAspect
|
||||||
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
||||||
// 处理设置注解上的参数
|
// 处理设置注解上的参数
|
||||||
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
||||||
|
// 设置消耗时间
|
||||||
|
operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
|
||||||
// 保存数据库
|
// 保存数据库
|
||||||
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
||||||
}
|
}
|
||||||
catch (Exception exp)
|
catch (Exception exp)
|
||||||
{
|
{
|
||||||
// 记录本地异常日志
|
// 记录本地异常日志
|
||||||
log.error("==前置通知异常==");
|
|
||||||
log.error("异常信息:{}", exp.getMessage());
|
log.error("异常信息:{}", exp.getMessage());
|
||||||
exp.printStackTrace();
|
exp.printStackTrace();
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
TIME_THREADLOCAL.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -83,6 +83,10 @@ public class SysOperLog extends BaseEntity
|
||||||
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date operTime;
|
private Date operTime;
|
||||||
|
|
||||||
|
/** 消耗时间 */
|
||||||
|
@Excel(name = "消耗时间", suffix = "毫秒")
|
||||||
|
private Long costTime;
|
||||||
|
|
||||||
public Long getOperId()
|
public Long getOperId()
|
||||||
{
|
{
|
||||||
return operId;
|
return operId;
|
||||||
|
@ -253,6 +257,16 @@ public class SysOperLog extends BaseEntity
|
||||||
this.operTime = operTime;
|
this.operTime = operTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getCostTime()
|
||||||
|
{
|
||||||
|
return costTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCostTime(Long costTime)
|
||||||
|
{
|
||||||
|
this.costTime = costTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
@ -272,6 +286,7 @@ public class SysOperLog extends BaseEntity
|
||||||
.append("status", getStatus())
|
.append("status", getStatus())
|
||||||
.append("errorMsg", getErrorMsg())
|
.append("errorMsg", getErrorMsg())
|
||||||
.append("operTime", getOperTime())
|
.append("operTime", getOperTime())
|
||||||
|
.append("costTime", getCostTime())
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,16 +21,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<result property="status" column="status" />
|
<result property="status" column="status" />
|
||||||
<result property="errorMsg" column="error_msg" />
|
<result property="errorMsg" column="error_msg" />
|
||||||
<result property="operTime" column="oper_time" />
|
<result property="operTime" column="oper_time" />
|
||||||
|
<result property="costTime" column="cost_time" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectOperLogVo">
|
<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
|
from sys_oper_log
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<insert id="insertOperlog" parameterType="SysOperLog">
|
<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)
|
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}, sysdate())
|
values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate())
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">
|
<select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">
|
||||||
|
|
|
@ -428,6 +428,7 @@ create table sys_oper_log (
|
||||||
status int(1) default 0 comment '操作状态(0正常 1异常)',
|
status int(1) default 0 comment '操作状态(0正常 1异常)',
|
||||||
error_msg varchar(2000) default '' comment '错误消息',
|
error_msg varchar(2000) default '' comment '错误消息',
|
||||||
oper_time datetime comment '操作时间',
|
oper_time datetime comment '操作时间',
|
||||||
|
cost_time bigint(20) default 0 comment '消耗时间',
|
||||||
primary key (oper_id)
|
primary key (oper_id)
|
||||||
) engine=innodb auto_increment=100 comment = '操作日志记录';
|
) engine=innodb auto_increment=100 comment = '操作日志记录';
|
||||||
|
|
Loading…
Reference in New Issue