姜永辉 1 anno fa
parent
commit
c2ee9c3001

+ 7 - 0
src/main/java/com/dk/common/infrastructure/aspect/ServiceAspect.java

@@ -10,6 +10,8 @@ import com.dk.common.infrastructure.operationlog.OperationLogService;
 import com.dk.common.model.vo.core.UserVO;
 import com.dk.common.util.oauth.AESSecurityUtil;
 import com.dk.common.util.oauth.JwtUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.plugin.Invocation;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.After;
 import org.aspectj.lang.annotation.Aspect;
@@ -32,6 +34,7 @@ import java.util.*;
  */
 @Aspect
 @Component
+@Slf4j
 public class ServiceAspect implements HandlerInterceptor {
 
     @Value("${aes-key}")
@@ -69,6 +72,10 @@ public class ServiceAspect implements HandlerInterceptor {
     @Before("print()")
     public void before(JoinPoint joinPoint) {
         try {
+            if(httpServletRequest==null){
+                log.info("service切面=>请求头为空");
+                return;
+            }
             String authorization = httpServletRequest.getHeader("Authorization");
             if(authorization == null ){
                 return;

+ 12 - 13
src/main/java/com/dk/common/infrastructure/util/MyMetaObjectHandler.java

@@ -25,24 +25,23 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
     @Override
     @SneakyThrows
     public void insertFill(MetaObject metaObject) {
-        String authorization = httpServletRequest.getHeader("Authorization");
-
-        if(authorization != null){
-
-            String[] tokens = authorization.split(" ");
-            String decrypt = AESSecurityUtil.decrypt(AESKey, tokens[1]);
-            String cpIdString = JwtUtil.getCpId(decrypt);
-            if (cpIdString!=null){
-                //设置企业Id
-                Integer cpId = Integer.valueOf(cpIdString);
-                this.strictInsertFill(metaObject, "cpId", Integer.class, cpId); // 起始版本 3.3.0(推荐使用)
-            }
+        if(httpServletRequest!=null){
+            String authorization = httpServletRequest.getHeader("Authorization");
+            if(authorization != null){
+                String[] tokens = authorization.split(" ");
+                String decrypt = AESSecurityUtil.decrypt(AESKey, tokens[1]);
+                String cpIdString = JwtUtil.getCpId(decrypt);
+                if (cpIdString!=null){
+                    //设置企业Id
+                    Integer cpId = Integer.valueOf(cpIdString);
+                    this.strictInsertFill(metaObject, "cpId", Integer.class, cpId); // 起始版本 3.3.0(推荐使用)
+                }
 //        // 或者
 //        this.strictInsertFill(metaObject, "createTime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
 //        // 或者
 //        this.fillStrategy(metaObject, "createTime", LocalDateTime.now()); // 也可以使用(3.3.0 该方法有bug)
+            }
         }
-
     }
 
     @Override

+ 6 - 0
src/main/java/com/dk/common/infrastructure/util/MybatisSqlIntercept.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
 import com.dk.common.util.oauth.AESSecurityUtil;
 import com.dk.common.util.oauth.JwtUtil;
 import com.google.common.base.CaseFormat;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.builder.StaticSqlSource;
 import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.mapping.MappedStatement;
@@ -39,6 +40,7 @@ import java.util.Map;
  * @description 拦截方法添加国际化参数 (目前有点小问题 url拼参数的无法添加)
  * TODO selectById的非Map类型参数的暂不支持 待修改
  */
+@Slf4j
 @Component
 @Intercepts({
         @Signature(type = Executor.class, method = "query", args = {MappedStatement.class,
@@ -58,6 +60,10 @@ public class MybatisSqlIntercept implements Interceptor {
     public Object intercept(Invocation invocation) throws Throwable {
 
         Integer cpId = 0;
+        if(httpServletRequest==null){
+            log.info("mybatis查询拦截器=>请求头为空");
+            return new Invocation(invocation.getTarget(), invocation.getMethod(), invocation.getArgs()).proceed();
+        }
 
         String authorization = httpServletRequest.getHeader("Authorization");