ソースを参照

管理后台操作日志

lyhzzz 3 年 前
コミット
962bb15ac0

+ 14 - 5
src/main/java/com/fdkankan/gateway/filter/CommonLogService.java

@@ -63,10 +63,17 @@ public class CommonLogService {
         // 请求路径
         String uri = request.getPath().pathWithinApplication().value();
         String requestPath;
+
+        Long userId = null;
+        String userName = null;
+        String nickName = null;
         if(uri.equals("/service/auth/manage/login")){
             requestPath = "登录";
         }else {
             requestPath = getRequestPath(uri);
+            userId =Long.valueOf( StpUtil.getExtra("userId").toString());
+            userName = StpUtil.getExtra("userName").toString();
+            nickName = StpUtil.getExtra("nickName").toString();
         }
         String operationType;
         if(uri.contains("manage")){
@@ -86,11 +93,7 @@ public class CommonLogService {
         operLog.setRequestPath(requestPath);
         operLog.setOperationType(operationType);
 
-        String userId = StpUtil.getExtra("userId").toString();
-        String userName = StpUtil.getExtra("userName").toString();
-        String nickName = StpUtil.getExtra("nickName").toString();
-
-        operLog.setUserId(Long.valueOf(userId));
+        operLog.setUserId(userId);
         operLog.setUserName(userName);
         operLog.setNickName(nickName);
 
@@ -287,6 +290,12 @@ public class CommonLogService {
                             ResultData resultData = JSON.parseObject(responseResult, ResultData.class);
                             if(resultData.getCode() == 0){
                                 operLog.setResult("操作成功");
+                                JSONObject jsonObject = (JSONObject) resultData.getData();
+                                if(operLog.getUserId() == null){
+                                    operLog.setUserId( Long.valueOf(jsonObject.getString("id")));
+                                    operLog.setUserName(jsonObject.getString("userName"));
+                                    operLog.setNickName(jsonObject.getString("nickName"));
+                                }
                             }else {
                                 operLog.setResult("操作失败");
                             }