|
@@ -1,5 +1,6 @@
|
|
|
package com.fdkankan.manage.interceptor;
|
|
package com.fdkankan.manage.interceptor;
|
|
|
|
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import cn.hutool.http.ContentType;
|
|
import cn.hutool.http.ContentType;
|
|
@@ -7,21 +8,12 @@ import cn.hutool.http.useragent.UserAgent;
|
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.fdkankan.common.util.JwtUtil;
|
|
|
|
|
import com.fdkankan.manage.bean.MenuBean;
|
|
import com.fdkankan.manage.bean.MenuBean;
|
|
|
import com.fdkankan.manage.entity.OperLog;
|
|
import com.fdkankan.manage.entity.OperLog;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
-import io.jsonwebtoken.Claims;
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.Calendar;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.LinkedList;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Around;
|
|
@@ -36,6 +28,9 @@ import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
@Component
|
|
@Component
|
|
|
@Aspect
|
|
@Aspect
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -85,6 +80,7 @@ public class VisitLogInterceptor {
|
|
|
Object result = pjp.proceed();
|
|
Object result = pjp.proceed();
|
|
|
|
|
|
|
|
//获取用户信息 如果已登录,从token中获取用户信息,如果是登录接口,查询数据库获取用户信息
|
|
//获取用户信息 如果已登录,从token中获取用户信息,如果是登录接口,查询数据库获取用户信息
|
|
|
|
|
+
|
|
|
Map<String, Object> userInfo = this.getUserInfo(request, uri, result);
|
|
Map<String, Object> userInfo = this.getUserInfo(request, uri, result);
|
|
|
Long userId = (Long)userInfo.get("userId");
|
|
Long userId = (Long)userInfo.get("userId");
|
|
|
String userName = (String)userInfo.get("userName");
|
|
String userName = (String)userInfo.get("userName");
|
|
@@ -109,15 +105,16 @@ public class VisitLogInterceptor {
|
|
|
|
|
|
|
|
private String getRequestPath(String uri){
|
|
private String getRequestPath(String uri){
|
|
|
String hget = redisUtil.hget(RedisKey.MANAGE_MENU, uri);
|
|
String hget = redisUtil.hget(RedisKey.MANAGE_MENU, uri);
|
|
|
|
|
+ assert StringUtils.isNotBlank(hget);
|
|
|
MenuBean menuBean = JSON.parseObject(hget, MenuBean.class);
|
|
MenuBean menuBean = JSON.parseObject(hget, MenuBean.class);
|
|
|
LinkedList<String> menuList = new LinkedList<>();
|
|
LinkedList<String> menuList = new LinkedList<>();
|
|
|
this.getRequestPathHandler(menuList, menuBean);
|
|
this.getRequestPathHandler(menuList, menuBean);
|
|
|
StringBuilder sb = new StringBuilder();
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- menuList.stream().forEach(str->sb.append("->").append(str));
|
|
|
|
|
|
|
+ menuList.forEach(str->sb.append("->").append(str));
|
|
|
return sb.substring(2);
|
|
return sb.substring(2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void getRequestPathHandler(LinkedList list, MenuBean menuBean){
|
|
|
|
|
|
|
+ private void getRequestPathHandler(LinkedList<String> list, MenuBean menuBean){
|
|
|
list.addFirst("[" + menuBean.getName() + "]");
|
|
list.addFirst("[" + menuBean.getName() + "]");
|
|
|
if(Objects.isNull(menuBean.getParent())){
|
|
if(Objects.isNull(menuBean.getParent())){
|
|
|
return;
|
|
return;
|
|
@@ -136,10 +133,10 @@ public class VisitLogInterceptor {
|
|
|
}else{
|
|
}else{
|
|
|
token = request.getHeader("token");
|
|
token = request.getHeader("token");
|
|
|
}
|
|
}
|
|
|
- Claims claims = JwtUtil.parseJWT(token);
|
|
|
|
|
- Integer userId = (Integer) claims.get("userId");
|
|
|
|
|
- String userName = (String)claims.get("userName");
|
|
|
|
|
- String nickName = (String)claims.get("nickName");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Integer userId = (Integer)StpUtil.getExtra("userId");
|
|
|
|
|
+ String userName = (String)StpUtil.getExtra("userName");
|
|
|
|
|
+ String nickName = (String)StpUtil.getExtra("nickName");
|
|
|
Map<String, Object> userInfo = new HashMap<>();
|
|
Map<String, Object> userInfo = new HashMap<>();
|
|
|
userInfo.put("userId", Long.valueOf(userId));
|
|
userInfo.put("userId", Long.valueOf(userId));
|
|
|
userInfo.put("userName", userName);
|
|
userInfo.put("userName", userName);
|