From 2f4fb959e8e4457b2da51704b54f15e51454140b Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 25 May 2020 16:51:05 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/chonggaoxiao/new_excoin.git

---
 src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java |    7 ++-----
 src/main/java/com/xcong/excoin/common/LoginUserUtils.java                         |   18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/common/LoginUserUtils.java b/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
index dbdd9d2..64c0aa2 100644
--- a/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
+++ b/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
@@ -1,5 +1,6 @@
 package com.xcong.excoin.common;
 
+import com.xcong.excoin.common.exception.GlobalException;
 import com.xcong.excoin.modules.member.entity.MemberEntity;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -17,6 +18,23 @@
 
     public static MemberEntity getAppLoginUser() {
         if (SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals(ANON)) {
+            throw new GlobalException("无法获取登陆信息");
+        } else {
+            return (MemberEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+        }
+    }
+
+    public static String getAppLoginUserToken() {
+        return (String) SecurityContextHolder.getContext().getAuthentication().getCredentials();
+    }
+
+    /**
+     * mybatis 拦截器专用
+     *
+     * @return MemberEntity
+     */
+    public static MemberEntity getUser() {
+        if (SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals(ANON)) {
             return null;
         } else {
             return (MemberEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
diff --git a/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java b/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java
index f7b0c87..5e69b7a 100644
--- a/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java
+++ b/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java
@@ -27,10 +27,7 @@
     @Override
     public Object intercept(Invocation invocation) throws Throwable {
         MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
-        String sqlId = mappedStatement.getId();
-        log.info("----sqlId----" + sqlId);
         SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
-        log.info("-------------->{}", sqlCommandType);
 
         Object parameter = invocation.getArgs()[1];
         if (parameter == null) {
@@ -75,7 +72,7 @@
     }
 
     public void injectForInsert(Object o) {
-        MemberEntity member = LoginUserUtils.getAppLoginUser();
+        MemberEntity member = LoginUserUtils.getUser();
         if (o instanceof BaseEntity) {
             BaseEntity baseEntity = (BaseEntity) o;
             if (member != null) {
@@ -92,7 +89,7 @@
     }
 
     public void injectForUpdate(Object o) {
-        MemberEntity member = LoginUserUtils.getAppLoginUser();
+        MemberEntity member = LoginUserUtils.getUser();
         if (o instanceof BaseEntity) {
             BaseEntity baseEntity = (BaseEntity) o;
             if (member != null) {

--
Gitblit v1.9.1