Просмотр исходного кода

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

RuoYi лет назад: 3
Родитель
Сommit
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
     @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
79
     @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
80
     private Date operTime;
80
     private Date operTime;
81
 
81
 
82
+    /** 消耗时间 */
83
+    @Excel(name = "消耗时间", suffix = "毫秒")
84
+    private Long costTime;
85
+
82
     public Long getOperId()
86
     public Long getOperId()
83
     {
87
     {
84
         return operId;
88
         return operId;
@@ -238,4 +242,14 @@ public class SysOperLog extends BaseEntity
238
     {
242
     {
239
         this.operTime = operTime;
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
 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;
13
 import org.springframework.beans.factory.annotation.Autowired;
14
 import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.core.NamedThreadLocal;
14
 import org.springframework.http.HttpMethod;
16
 import org.springframework.http.HttpMethod;
15
 import org.springframework.stereotype.Component;
17
 import org.springframework.stereotype.Component;
16
 import org.springframework.validation.BindingResult;
18
 import org.springframework.validation.BindingResult;
@@ -40,10 +42,22 @@ public class LogAspect
40
     /** 排除敏感属性字段 */
42
     /** 排除敏感属性字段 */
41
     public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
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
     @Autowired
48
     @Autowired
44
     private AsyncLogService asyncLogService;
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
      * @param joinPoint 切点
63
      * @param joinPoint 切点
@@ -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
             asyncLogService.saveSysLog(operLog);
116
             asyncLogService.saveSysLog(operLog);
101
         }
117
         }
@@ -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
     /**

+ 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
      * 会话注销,根据指定Token
28
      * 会话注销,根据指定Token
29
      * 
29
      * 
30
-     * @param tokenValue 指定token
30
+     * @param token 指定token
31
      */
31
      */
32
     public static void logoutByToken(String token)
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
     public static LoginUser getLoginUser(String token)
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
     public static void verifyLoginUserExpire(LoginUser loginUser)
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
 		<result property="status"         column="status"         />
20
 		<result property="status"         column="status"         />
21
 		<result property="errorMsg"       column="error_msg"      />
21
 		<result property="errorMsg"       column="error_msg"      />
22
 		<result property="operTime"       column="oper_time"      />
22
 		<result property="operTime"       column="oper_time"      />
23
+		<result property="costTime"       column="cost_time"      />
23
 	</resultMap>
24
 	</resultMap>
24
 
25
 
25
 	<sql id="selectOperLogVo">
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
         from sys_oper_log
28
         from sys_oper_log
28
     </sql>
29
     </sql>
29
     
30
     
30
 	<insert id="insertOperlog" parameterType="SysOperLog">
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
 	</insert>
34
 	</insert>
34
 	
35
 	
35
 	<select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">
36
 	<select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">

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

@@ -102,7 +102,7 @@
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" />
108
       <el-table-column label="操作类型" align="center" prop="businessType">
108
       <el-table-column label="操作类型" align="center" prop="businessType">
@@ -111,18 +111,23 @@
111
         </template>
111
         </template>
112
       </el-table-column>
112
       </el-table-column>
113
       <el-table-column label="请求方式" align="center" prop="requestMethod" />
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
       <el-table-column label="主机" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" />
115
       <el-table-column label="主机" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" />
116
       <el-table-column label="操作状态" align="center" prop="status">
116
       <el-table-column label="操作状态" align="center" prop="status">
117
         <template slot-scope="scope">
117
         <template slot-scope="scope">
118
           <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"/>
119
         </template>
119
         </template>
120
       </el-table-column>
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
         <template slot-scope="scope">
122
         <template slot-scope="scope">
123
           <span>{{ parseTime(scope.row.operTime) }}</span>
123
           <span>{{ parseTime(scope.row.operTime) }}</span>
124
         </template>
124
         </template>
125
       </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>
126
       <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">
127
         <template slot-scope="scope">
132
         <template slot-scope="scope">
128
           <el-button
133
           <el-button
@@ -167,13 +172,16 @@
167
           <el-col :span="24">
172
           <el-col :span="24">
168
             <el-form-item label="返回参数:">{{ form.jsonResult }}</el-form-item>
173
             <el-form-item label="返回参数:">{{ form.jsonResult }}</el-form-item>
169
           </el-col>
174
           </el-col>
170
-          <el-col :span="12">
175
+          <el-col :span="6">
171
             <el-form-item label="操作状态:">
176
             <el-form-item label="操作状态:">
172
               <div v-if="form.status === 0">正常</div>
177
               <div v-if="form.status === 0">正常</div>
173
               <div v-else-if="form.status === 1">失败</div>
178
               <div v-else-if="form.status === 1">失败</div>
174
             </el-form-item>
179
             </el-form-item>
175
           </el-col>
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
             <el-form-item label="操作时间:">{{ parseTime(form.operTime) }}</el-form-item>
185
             <el-form-item label="操作时间:">{{ parseTime(form.operTime) }}</el-form-item>
178
           </el-col>
186
           </el-col>
179
           <el-col :span="24">
187
           <el-col :span="24">

Разница между файлами не показана из-за своего большого размера
+ 689 - 585
sql/ry_20220814.sql