瀏覽代碼

操作日志新增消耗时间属性

RuoYi 3 年之前
父節點
當前提交
8dff14a6cc

+ 14 - 0
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysOperLog.java

@@ -79,6 +79,10 @@ public class SysOperLog extends BaseEntity
79 79
     @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
80 80
     private Date operTime;
81 81
 
82
+    /** 消耗时间 */
83
+    @Excel(name = "消耗时间", suffix = "毫秒")
84
+    private Long costTime;
85
+
82 86
     public Long getOperId()
83 87
     {
84 88
         return operId;
@@ -238,4 +242,14 @@ public class SysOperLog extends BaseEntity
238 242
     {
239 243
         this.operTime = operTime;
240 244
     }
245
+
246
+    public Long getCostTime()
247
+    {
248
+        return costTime;
249
+    }
250
+
251
+    public void setCostTime(Long costTime)
252
+    {
253
+        this.costTime = costTime;
254
+    }
241 255
 }

+ 20 - 0
ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java

@@ -8,9 +8,11 @@ import org.aspectj.lang.JoinPoint;
8 8
 import org.aspectj.lang.annotation.AfterReturning;
9 9
 import org.aspectj.lang.annotation.AfterThrowing;
10 10
 import org.aspectj.lang.annotation.Aspect;
11
+import org.aspectj.lang.annotation.Before;
11 12
 import org.slf4j.Logger;
12 13
 import org.slf4j.LoggerFactory;
13 14
 import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.core.NamedThreadLocal;
14 16
 import org.springframework.http.HttpMethod;
15 17
 import org.springframework.stereotype.Component;
16 18
 import org.springframework.validation.BindingResult;
@@ -40,10 +42,22 @@ public class LogAspect
40 42
     /** 排除敏感属性字段 */
41 43
     public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
42 44
 
45
+    /** 计算操作消耗时间 */
46
+    private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
47
+
43 48
     @Autowired
44 49
     private AsyncLogService asyncLogService;
45 50
 
46 51
     /**
52
+     * 处理请求前执行
53
+     */
54
+    @Before(value = "@annotation(controllerLog)")
55
+    public void boBefore(JoinPoint joinPoint, Log controllerLog)
56
+    {
57
+        TIME_THREADLOCAL.set(System.currentTimeMillis());
58
+    }
59
+
60
+    /**
47 61
      * 处理完请求后执行
48 62
      *
49 63
      * @param joinPoint 切点
@@ -96,6 +110,8 @@ public class LogAspect
96 110
             operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
97 111
             // 处理设置注解上的参数
98 112
             getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
113
+            // 设置消耗时间
114
+            operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
99 115
             // 保存数据库
100 116
             asyncLogService.saveSysLog(operLog);
101 117
         }
@@ -105,6 +121,10 @@ public class LogAspect
105 121
             log.error("异常信息:{}", exp.getMessage());
106 122
             exp.printStackTrace();
107 123
         }
124
+        finally
125
+        {
126
+            TIME_THREADLOCAL.remove();
127
+        }
108 128
     }
109 129
 
110 130
     /**

+ 6 - 1
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/auth/AuthUtil.java

@@ -27,7 +27,7 @@ public class AuthUtil
27 27
     /**
28 28
      * 会话注销,根据指定Token
29 29
      * 
30
-     * @param tokenValue 指定token
30
+     * @param token 指定token
31 31
      */
32 32
     public static void logoutByToken(String token)
33 33
     {
@@ -44,6 +44,9 @@ public class AuthUtil
44 44
 
45 45
     /**
46 46
      * 获取当前登录用户信息
47
+     * 
48
+     * @param token 指定token
49
+     * @return 用户信息
47 50
      */
48 51
     public static LoginUser getLoginUser(String token)
49 52
     {
@@ -52,6 +55,8 @@ public class AuthUtil
52 55
 
53 56
     /**
54 57
      * 验证当前用户有效期
58
+     * 
59
+     * @param loginUser 用户信息
55 60
      */
56 61
     public static void verifyLoginUserExpire(LoginUser loginUser)
57 62
     {

+ 4 - 3
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysOperLogMapper.xml

@@ -20,16 +20,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
20 20
 		<result property="status"         column="status"         />
21 21
 		<result property="errorMsg"       column="error_msg"      />
22 22
 		<result property="operTime"       column="oper_time"      />
23
+		<result property="costTime"       column="cost_time"      />
23 24
 	</resultMap>
24 25
 
25 26
 	<sql id="selectOperLogVo">
26
-        select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_param, json_result, status, error_msg, oper_time
27
+        select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_param, json_result, status, error_msg, oper_time, cost_time
27 28
         from sys_oper_log
28 29
     </sql>
29 30
     
30 31
 	<insert id="insertOperlog" parameterType="SysOperLog">
31
-		insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_param, json_result, status, error_msg, oper_time)
32
-        values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, sysdate())
32
+		insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_param, json_result, status, error_msg, cost_time, oper_time)
33
+        values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate())
33 34
 	</insert>
34 35
 	
35 36
 	<select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">

+ 13 - 5
ruoyi-ui/src/views/system/operlog/index.vue

@@ -102,7 +102,7 @@
102 102
     </el-row>
103 103
 
104 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 106
       <el-table-column label="日志编号" align="center" prop="operId" />
107 107
       <el-table-column label="系统模块" align="center" prop="title" />
108 108
       <el-table-column label="操作类型" align="center" prop="businessType">
@@ -111,18 +111,23 @@
111 111
         </template>
112 112
       </el-table-column>
113 113
       <el-table-column label="请求方式" align="center" prop="requestMethod" />
114
-      <el-table-column label="操作人员" align="center" prop="operName" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']" width="100"/>
114
+      <el-table-column label="操作人员" align="center" prop="operName" width="110" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
115 115
       <el-table-column label="主机" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" />
116 116
       <el-table-column label="操作状态" align="center" prop="status">
117 117
         <template slot-scope="scope">
118 118
           <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/>
119 119
         </template>
120 120
       </el-table-column>
121
-      <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="180" sortable="custom" :sort-orders="['descending', 'ascending']">
122 122
         <template slot-scope="scope">
123 123
           <span>{{ parseTime(scope.row.operTime) }}</span>
124 124
         </template>
125 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>
126 131
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
127 132
         <template slot-scope="scope">
128 133
           <el-button
@@ -167,13 +172,16 @@
167 172
           <el-col :span="24">
168 173
             <el-form-item label="返回参数:">{{ form.jsonResult }}</el-form-item>
169 174
           </el-col>
170
-          <el-col :span="12">
175
+          <el-col :span="6">
171 176
             <el-form-item label="操作状态:">
172 177
               <div v-if="form.status === 0">正常</div>
173 178
               <div v-else-if="form.status === 1">失败</div>
174 179
             </el-form-item>
175 180
           </el-col>
176
-          <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">
177 185
             <el-form-item label="操作时间:">{{ parseTime(form.operTime) }}</el-form-item>
178 186
           </el-col>
179 187
           <el-col :span="24">

File diff suppressed because it is too large
+ 689 - 585
sql/ry_20220814.sql