正在显示
5 个修改的文件
包含
53 行增加
和
10 行删除
| @@ -8,8 +8,10 @@ import org.aspectj.lang.JoinPoint; | @@ -8,8 +8,10 @@ import org.aspectj.lang.JoinPoint; | ||
| 8 | import org.aspectj.lang.annotation.AfterReturning; | 8 | import org.aspectj.lang.annotation.AfterReturning; |
| 9 | import org.aspectj.lang.annotation.AfterThrowing; | 9 | import org.aspectj.lang.annotation.AfterThrowing; |
| 10 | import org.aspectj.lang.annotation.Aspect; | 10 | import org.aspectj.lang.annotation.Aspect; |
| 11 | +import org.aspectj.lang.annotation.Before; | ||
| 11 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
| 14 | +import org.springframework.core.NamedThreadLocal; | ||
| 13 | import org.springframework.stereotype.Component; | 15 | import org.springframework.stereotype.Component; |
| 14 | import org.springframework.validation.BindingResult; | 16 | import org.springframework.validation.BindingResult; |
| 15 | import org.springframework.web.multipart.MultipartFile; | 17 | import org.springframework.web.multipart.MultipartFile; |
| @@ -41,6 +43,18 @@ public class LogAspect | @@ -41,6 +43,18 @@ public class LogAspect | ||
| 41 | /** 排除敏感属性字段 */ | 43 | /** 排除敏感属性字段 */ |
| 42 | public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" }; | 44 | public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" }; |
| 43 | 45 | ||
| 46 | + /** 计算操作消耗时间 */ | ||
| 47 | + private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time"); | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 处理请求前执行 | ||
| 51 | + */ | ||
| 52 | + @Before(value = "@annotation(controllerLog)") | ||
| 53 | + public void boBefore(JoinPoint joinPoint, Log controllerLog) | ||
| 54 | + { | ||
| 55 | + TIME_THREADLOCAL.set(System.currentTimeMillis()); | ||
| 56 | + } | ||
| 57 | + | ||
| 44 | /** | 58 | /** |
| 45 | * 处理完请求后执行 | 59 | * 处理完请求后执行 |
| 46 | * | 60 | * |
| @@ -96,6 +110,8 @@ public class LogAspect | @@ -96,6 +110,8 @@ public class LogAspect | ||
| 96 | operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); | 110 | operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); |
| 97 | // 处理设置注解上的参数 | 111 | // 处理设置注解上的参数 |
| 98 | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); | 112 | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); |
| 113 | + // 设置消耗时间 | ||
| 114 | + operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get()); | ||
| 99 | // 保存数据库 | 115 | // 保存数据库 |
| 100 | AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); | 116 | AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); |
| 101 | } | 117 | } |
| @@ -105,6 +121,10 @@ public class LogAspect | @@ -105,6 +121,10 @@ public class LogAspect | ||
| 105 | log.error("异常信息:{}", exp.getMessage()); | 121 | log.error("异常信息:{}", exp.getMessage()); |
| 106 | exp.printStackTrace(); | 122 | exp.printStackTrace(); |
| 107 | } | 123 | } |
| 124 | + finally | ||
| 125 | + { | ||
| 126 | + TIME_THREADLOCAL.remove(); | ||
| 127 | + } | ||
| 108 | } | 128 | } |
| 109 | 129 | ||
| 110 | /** | 130 | /** |
| @@ -83,6 +83,10 @@ public class SysOperLog extends BaseEntity | @@ -83,6 +83,10 @@ public class SysOperLog extends BaseEntity | ||
| 83 | @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") | 83 | @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") |
| 84 | private Date operTime; | 84 | private Date operTime; |
| 85 | 85 | ||
| 86 | + /** 消耗时间 */ | ||
| 87 | + @Excel(name = "消耗时间", suffix = "毫秒") | ||
| 88 | + private Long costTime; | ||
| 89 | + | ||
| 86 | public Long getOperId() | 90 | public Long getOperId() |
| 87 | { | 91 | { |
| 88 | return operId; | 92 | return operId; |
| @@ -252,4 +256,14 @@ public class SysOperLog extends BaseEntity | @@ -252,4 +256,14 @@ public class SysOperLog extends BaseEntity | ||
| 252 | { | 256 | { |
| 253 | this.operTime = operTime; | 257 | this.operTime = operTime; |
| 254 | } | 258 | } |
| 259 | + | ||
| 260 | + public Long getCostTime() | ||
| 261 | + { | ||
| 262 | + return costTime; | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + public void setCostTime(Long costTime) | ||
| 266 | + { | ||
| 267 | + this.costTime = costTime; | ||
| 268 | + } | ||
| 255 | } | 269 | } |
| @@ -21,16 +21,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -21,16 +21,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 21 | <result property="status" column="status" /> | 21 | <result property="status" column="status" /> |
| 22 | <result property="errorMsg" column="error_msg" /> | 22 | <result property="errorMsg" column="error_msg" /> |
| 23 | <result property="operTime" column="oper_time" /> | 23 | <result property="operTime" column="oper_time" /> |
| 24 | + <result property="costTime" column="cost_time" /> | ||
| 24 | </resultMap> | 25 | </resultMap> |
| 25 | 26 | ||
| 26 | <sql id="selectOperLogVo"> | 27 | <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 | + 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 |
| 28 | from sys_oper_log | 29 | from sys_oper_log |
| 29 | </sql> | 30 | </sql> |
| 30 | 31 | ||
| 31 | <insert id="insertOperlog" parameterType="SysOperLog"> | 32 | <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()) | 33 | + 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) |
| 34 | + values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate()) | ||
| 34 | </insert> | 35 | </insert> |
| 35 | 36 | ||
| 36 | <select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult"> | 37 | <select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult"> |
| @@ -102,16 +102,15 @@ | @@ -102,16 +102,15 @@ | ||
| 102 | </el-row> | 102 | </el-row> |
| 103 | 103 | ||
| 104 | <el-table ref="tables" v-loading="loading" :data="list" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange"> | 104 | <el-table ref="tables" v-loading="loading" :data="list" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange"> |
| 105 | - <el-table-column type="selection" width="55" align="center" /> | 105 | + <el-table-column type="selection" width="50" align="center" /> |
| 106 | <el-table-column label="日志编号" align="center" prop="operId" /> | 106 | <el-table-column label="日志编号" align="center" prop="operId" /> |
| 107 | - <el-table-column label="系统模块" align="center" prop="title" /> | 107 | + <el-table-column label="系统模块" align="center" prop="title" :show-overflow-tooltip="true" /> |
| 108 | <el-table-column label="操作类型" align="center" prop="businessType"> | 108 | <el-table-column label="操作类型" align="center" prop="businessType"> |
| 109 | <template slot-scope="scope"> | 109 | <template slot-scope="scope"> |
| 110 | <dict-tag :options="dict.type.sys_oper_type" :value="scope.row.businessType"/> | 110 | <dict-tag :options="dict.type.sys_oper_type" :value="scope.row.businessType"/> |
| 111 | </template> | 111 | </template> |
| 112 | </el-table-column> | 112 | </el-table-column> |
| 113 | - <el-table-column label="请求方式" align="center" prop="requestMethod" /> | ||
| 114 | - <el-table-column label="操作人员" align="center" prop="operName" width="100" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']" /> | 113 | + <el-table-column label="操作人员" align="center" prop="operName" width="110" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']" /> |
| 115 | <el-table-column label="操作地址" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" /> | 114 | <el-table-column label="操作地址" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" /> |
| 116 | <el-table-column label="操作地点" align="center" prop="operLocation" :show-overflow-tooltip="true" /> | 115 | <el-table-column label="操作地点" align="center" prop="operLocation" :show-overflow-tooltip="true" /> |
| 117 | <el-table-column label="操作状态" align="center" prop="status"> | 116 | <el-table-column label="操作状态" align="center" prop="status"> |
| @@ -119,11 +118,16 @@ | @@ -119,11 +118,16 @@ | ||
| 119 | <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/> | 118 | <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/> |
| 120 | </template> | 119 | </template> |
| 121 | </el-table-column> | 120 | </el-table-column> |
| 122 | - <el-table-column label="操作日期" align="center" prop="operTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="180"> | 121 | + <el-table-column label="操作日期" align="center" prop="operTime" width="160" sortable="custom" :sort-orders="['descending', 'ascending']"> |
| 123 | <template slot-scope="scope"> | 122 | <template slot-scope="scope"> |
| 124 | <span>{{ parseTime(scope.row.operTime) }}</span> | 123 | <span>{{ parseTime(scope.row.operTime) }}</span> |
| 125 | </template> | 124 | </template> |
| 126 | </el-table-column> | 125 | </el-table-column> |
| 126 | + <el-table-column label="消耗时间" align="center" prop="costTime" width="110" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"> | ||
| 127 | + <template slot-scope="scope"> | ||
| 128 | + <span>{{ scope.row.costTime }}毫秒</span> | ||
| 129 | + </template> | ||
| 130 | + </el-table-column> | ||
| 127 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | 131 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| 128 | <template slot-scope="scope"> | 132 | <template slot-scope="scope"> |
| 129 | <el-button | 133 | <el-button |
| @@ -168,13 +172,16 @@ | @@ -168,13 +172,16 @@ | ||
| 168 | <el-col :span="24"> | 172 | <el-col :span="24"> |
| 169 | <el-form-item label="返回参数:">{{ form.jsonResult }}</el-form-item> | 173 | <el-form-item label="返回参数:">{{ form.jsonResult }}</el-form-item> |
| 170 | </el-col> | 174 | </el-col> |
| 171 | - <el-col :span="12"> | 175 | + <el-col :span="6"> |
| 172 | <el-form-item label="操作状态:"> | 176 | <el-form-item label="操作状态:"> |
| 173 | <div v-if="form.status === 0">正常</div> | 177 | <div v-if="form.status === 0">正常</div> |
| 174 | <div v-else-if="form.status === 1">失败</div> | 178 | <div v-else-if="form.status === 1">失败</div> |
| 175 | </el-form-item> | 179 | </el-form-item> |
| 176 | </el-col> | 180 | </el-col> |
| 177 | - <el-col :span="12"> | 181 | + <el-col :span="8"> |
| 182 | + <el-form-item label="消耗时间:">{{ form.costTime }}毫秒</el-form-item> | ||
| 183 | + </el-col> | ||
| 184 | + <el-col :span="10"> | ||
| 178 | <el-form-item label="操作时间:">{{ parseTime(form.operTime) }}</el-form-item> | 185 | <el-form-item label="操作时间:">{{ parseTime(form.operTime) }}</el-form-item> |
| 179 | </el-col> | 186 | </el-col> |
| 180 | <el-col :span="24"> | 187 | <el-col :span="24"> |
| @@ -432,6 +432,7 @@ create table sys_oper_log ( | @@ -432,6 +432,7 @@ create table sys_oper_log ( | ||
| 432 | status int(1) default 0 comment '操作状态(0正常 1异常)', | 432 | status int(1) default 0 comment '操作状态(0正常 1异常)', |
| 433 | error_msg varchar(2000) default '' comment '错误消息', | 433 | error_msg varchar(2000) default '' comment '错误消息', |
| 434 | oper_time datetime comment '操作时间', | 434 | oper_time datetime comment '操作时间', |
| 435 | + cost_time bigint(20) default 0 comment '消耗时间', | ||
| 435 | primary key (oper_id) | 436 | primary key (oper_id) |
| 436 | ) engine=innodb auto_increment=100 comment = '操作日志记录'; | 437 | ) engine=innodb auto_increment=100 comment = '操作日志记录'; |
| 437 | 438 |
-
请 注册 或 登录 后发表评论