|
@@ -6,11 +6,13 @@ import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import cn.hutool.http.ContentType;
|
|
import cn.hutool.http.ContentType;
|
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
-import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.fdkankan.common.constant.ServerCode;
|
|
|
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.manage.entity.SysUser;
|
|
|
|
|
+import com.fdkankan.manage.service.ISysUserService;
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -43,6 +45,9 @@ public class VisitLogInterceptor {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ISysUserService userService;
|
|
|
|
|
+
|
|
|
@Value("${server.servlet.context-path:null}")
|
|
@Value("${server.servlet.context-path:null}")
|
|
|
private String contextPath;
|
|
private String contextPath;
|
|
|
|
|
|
|
@@ -79,14 +84,30 @@ public class VisitLogInterceptor {
|
|
|
|
|
|
|
|
//放行
|
|
//放行
|
|
|
Object result = pjp.proceed();
|
|
Object result = pjp.proceed();
|
|
|
-
|
|
|
|
|
|
|
+ String resultStr = JSON.toJSONString(result);
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(resultStr);
|
|
|
|
|
+ String msg = "操作失败";
|
|
|
|
|
+ if(jsonObject.getInteger("code")== null || jsonObject.getInteger("code").equals(ServerCode.SUCCESS.code())){
|
|
|
|
|
+ msg = "操作成功";
|
|
|
|
|
+ }
|
|
|
//获取用户信息 如果已登录,从token中获取用户信息,如果是登录接口,查询数据库获取用户信息
|
|
//获取用户信息 如果已登录,从token中获取用户信息,如果是登录接口,查询数据库获取用户信息
|
|
|
-
|
|
|
|
|
- Map<String, Object> userInfo = this.getUserInfo(request, uri, result);
|
|
|
|
|
- Long userId = (Long)userInfo.get("userId");
|
|
|
|
|
- String userName = (String)userInfo.get("userName");
|
|
|
|
|
- String nickName = (String)userInfo.get("nickName");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ Long userId =null;
|
|
|
|
|
+ String userName =null;
|
|
|
|
|
+ String nickName =null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ userId = (Long)StpUtil.getExtra("userId");
|
|
|
|
|
+ userName = (String)StpUtil.getExtra("userName");
|
|
|
|
|
+ nickName = (String)StpUtil.getExtra("nickName");
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ JSONObject paramObj = JSONObject.parseObject(params);
|
|
|
|
|
+ userName = paramObj.getString("userName");
|
|
|
|
|
+ SysUser sysUser = userService.getByUserName(userName);
|
|
|
|
|
+ if(sysUser != null){
|
|
|
|
|
+ userId = sysUser.getId();
|
|
|
|
|
+ nickName = sysUser.getNickName();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
//写入mongodb
|
|
//写入mongodb
|
|
|
OperLog operLog = new OperLog();
|
|
OperLog operLog = new OperLog();
|
|
|
operLog.setUserId(userId);
|
|
operLog.setUserId(userId);
|
|
@@ -99,6 +120,7 @@ public class VisitLogInterceptor {
|
|
|
operLog.setIp(clientIP);
|
|
operLog.setIp(clientIP);
|
|
|
operLog.setBrowser(browser);
|
|
operLog.setBrowser(browser);
|
|
|
operLog.setCreateTime(Calendar.getInstance().getTime());
|
|
operLog.setCreateTime(Calendar.getInstance().getTime());
|
|
|
|
|
+ operLog.setResult(msg);
|
|
|
mongoTemplate.insert(operLog);
|
|
mongoTemplate.insert(operLog);
|
|
|
|
|
|
|
|
return result;
|
|
return result;
|
|
@@ -126,27 +148,6 @@ public class VisitLogInterceptor {
|
|
|
this.getRequestPathHandler(list, menuBean.getParent());
|
|
this.getRequestPathHandler(list, menuBean.getParent());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Map<String, Object> getUserInfo(HttpServletRequest request, String uri, Object result){
|
|
|
|
|
- String token = null;
|
|
|
|
|
- boolean isLogin = uri.endsWith("login");
|
|
|
|
|
- if(isLogin){
|
|
|
|
|
- String resultStr = JSON.toJSONString(result);
|
|
|
|
|
- JSONObject jsonObject = JSON.parseObject(resultStr);
|
|
|
|
|
- JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
- token = data.getString("token");
|
|
|
|
|
- }else{
|
|
|
|
|
- token = request.getHeader("token");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Integer userId = (Integer)StpUtil.getExtra("userId");
|
|
|
|
|
- String userName = (String)StpUtil.getExtra("userName");
|
|
|
|
|
- String nickName = (String)StpUtil.getExtra("nickName");
|
|
|
|
|
- Map<String, Object> userInfo = new HashMap<>();
|
|
|
|
|
- userInfo.put("userId", Long.valueOf(userId));
|
|
|
|
|
- userInfo.put("userName", userName);
|
|
|
|
|
- userInfo.put("nickName", nickName);
|
|
|
|
|
- return userInfo;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
private String getParams(JoinPoint pjp, HttpServletRequest request){
|
|
private String getParams(JoinPoint pjp, HttpServletRequest request){
|
|
|
|
|
|