From 177249c76aeea0b4bf8d8816d4994e3b445b45ce Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期四, 02 九月 2021 10:39:34 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/zzj' into zzj

---
 springcloud_k8s_panzhihuazhihuishequ/grid_app/src/main/java/com/panzhihua/grid_app/aop/OperLogAspect.java |  188 ++++++++++++++++++++++++----------------------
 1 files changed, 98 insertions(+), 90 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/grid_app/src/main/java/com/panzhihua/grid_app/aop/OperLogAspect.java b/springcloud_k8s_panzhihuazhihuishequ/grid_app/src/main/java/com/panzhihua/grid_app/aop/OperLogAspect.java
index a4ea519..a260595 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/grid_app/src/main/java/com/panzhihua/grid_app/aop/OperLogAspect.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/grid_app/src/main/java/com/panzhihua/grid_app/aop/OperLogAspect.java
@@ -1,15 +1,16 @@
 package com.panzhihua.grid_app.aop;
 
-import com.alibaba.fastjson.JSONObject;
-import com.panzhihua.common.constants.Constants;
-import com.panzhihua.common.constants.TokenConstant;
-import com.panzhihua.common.interfaces.OperLog;
-import com.panzhihua.common.model.vos.LoginUserInfoVO;
-import com.panzhihua.common.model.vos.user.SysOperLogVO;
-import com.panzhihua.common.service.user.UserService;
-import com.panzhihua.common.utlis.AES;
-import com.panzhihua.common.utlis.IPUtil;
-import lombok.extern.slf4j.Slf4j;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.AfterReturning;
 import org.aspectj.lang.annotation.Aspect;
@@ -20,15 +21,17 @@
 import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
 
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import com.alibaba.fastjson.JSONObject;
+import com.panzhihua.common.constants.Constants;
+import com.panzhihua.common.constants.TokenConstant;
+import com.panzhihua.common.interfaces.OperLog;
+import com.panzhihua.common.model.vos.LoginUserInfoVO;
+import com.panzhihua.common.model.vos.user.SysOperLogVO;
+import com.panzhihua.common.service.user.UserService;
+import com.panzhihua.common.utlis.AES;
+import com.panzhihua.common.utlis.IPUtil;
+
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * 切面处理类,操作日志异常日志记录处理
@@ -48,21 +51,22 @@
      * 设置操作日志切入点 记录操作日志 在注解的位置切入代码
      */
     @Pointcut("@annotation(com.panzhihua.common.interfaces.OperLog)")
-    public void operLogPoinCut() {
-    }
+    public void operLogPoinCut() {}
 
-//    /**
-//     * 设置操作异常切入点记录异常日志 扫描所有controller包下操作
-//     */
-//    @Pointcut("execution(* com.hyd.zcar.cms.controller..*.*(..))")
-//    public void operExceptionLogPoinCut() {
-//    }
+    // /**
+    // * 设置操作异常切入点记录异常日志 扫描所有controller包下操作
+    // */
+    // @Pointcut("execution(* com.hyd.zcar.cms.controller..*.*(..))")
+    // public void operExceptionLogPoinCut() {
+    // }
 
     /**
      * 正常返回通知,拦截用户操作日志,连接点正常执行完成后执行, 如果连接点抛出异常,则不会执行
      *
-     * @param joinPoint 切入点
-     * @param keys      返回结果
+     * @param joinPoint
+     *            切入点
+     * @param keys
+     *            返回结果
      */
     @AfterReturning(value = "operLogPoinCut()", returning = "keys")
     public void saveOperLog(JoinPoint joinPoint, Object keys) {
@@ -70,25 +74,25 @@
         // 获取RequestAttributes
         RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
         // 从获取RequestAttributes中获取HttpServletRequest的信息
-        HttpServletRequest request = (HttpServletRequest) requestAttributes
-                .resolveReference(RequestAttributes.REFERENCE_REQUEST);
-//        登录对象信息
+        HttpServletRequest request =
+            (HttpServletRequest)requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
+        // 登录对象信息
         String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO);
         boolean empty = ObjectUtils.isEmpty(userInfo);
         if (empty) {
-            log.error("操作日志获取登录用户信息失败【{}】",joinPoint);
+            log.error("操作日志获取登录用户信息失败【{}】", joinPoint);
             return;
         }
         byte[] bytes = AES.parseHexStr2Byte(userInfo);
         byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY);
-        userInfo=new String(decrypt);
-        LoginUserInfoVO loginUserInfoVO= JSONObject.parseObject(userInfo,LoginUserInfoVO.class);
+        userInfo = new String(decrypt);
+        LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(userInfo, LoginUserInfoVO.class);
 
         SysOperLogVO operlog = new SysOperLogVO();
         try {
 
             // 从切面织入点处通过反射机制获取织入点处的方法
-            MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+            MethodSignature signature = (MethodSignature)joinPoint.getSignature();
             // 获取切入点所在的方法
             Method method = signature.getMethod();
             // 获取操作
@@ -126,66 +130,67 @@
             operlog.setOperTime(new Date()); // 创建时间
             operlog.setAccount(loginUserInfoVO.getAccount());
             Long communityId = loginUserInfoVO.getCommunityId();
-            operlog.setCommunityId(null==communityId?0:communityId);
+            operlog.setCommunityId(null == communityId ? 0 : communityId);
             userService.addOperLog(operlog);
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
-//    /**
-//     * 异常返回通知,用于拦截异常日志信息 连接点抛出异常后执行
-//     *
-//     * @param joinPoint 切入点
-//     * @param e         异常信息
-//     */
-//    @AfterThrowing(pointcut = "operExceptionLogPoinCut()", throwing = "e")
-//    public void saveExceptionLog(JoinPoint joinPoint, Throwable e) {
-//        // 获取RequestAttributes
-//        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
-//        // 从获取RequestAttributes中获取HttpServletRequest的信息
-//        HttpServletRequest request = (HttpServletRequest) requestAttributes
-//                .resolveReference(RequestAttributes.REFERENCE_REQUEST);
-//
-//        ExceptionLog excepLog = new ExceptionLog();
-//        try {
-//            // 从切面织入点处通过反射机制获取织入点处的方法
-//            MethodSignature signature = (MethodSignature) joinPoint.getSignature();
-//            // 获取切入点所在的方法
-//            Method method = signature.getMethod();
-//            excepLog.setExcId(UuidUtil.get32UUID());
-//            // 获取请求的类名
-//            String className = joinPoint.getTarget().getClass().getName();
-//            // 获取请求的方法名
-//            String methodName = method.getName();
-//            methodName = className + "." + methodName;
-//            // 请求的参数
-//            Map<String, String> rtnMap = converMap(request.getParameterMap());
-//            // 将参数所在的数组转换成json
-//            String params = JSON.toJSONString(rtnMap);
-//            excepLog.setExcRequParam(params); // 请求参数
-//            excepLog.setOperMethod(methodName); // 请求方法名
-//            excepLog.setExcName(e.getClass().getName()); // 异常名称
-//            excepLog.setExcMessage(stackTraceToString(e.getClass().getName(), e.getMessage(), e.getStackTrace())); // 异常信息
-//            excepLog.setOperUserId(UserShiroUtil.getCurrentUserLoginName()); // 操作员ID
-//            excepLog.setOperUserName(UserShiroUtil.getCurrentUserName()); // 操作员名称
-//            excepLog.setOperUri(request.getRequestURI()); // 操作URI
-//            excepLog.setOperIp(IPUtil.getRemortIP(request)); // 操作员IP
-//            excepLog.setOperVer(operVer); // 操作版本号
-//            excepLog.setOperCreateTime(new Date()); // 发生异常时间
-//
-//            exceptionLogService.insert(excepLog);
-//
-//        } catch (Exception e2) {
-//            e2.printStackTrace();
-//        }
-//
-//    }
+    // /**
+    // * 异常返回通知,用于拦截异常日志信息 连接点抛出异常后执行
+    // *
+    // * @param joinPoint 切入点
+    // * @param e 异常信息
+    // */
+    // @AfterThrowing(pointcut = "operExceptionLogPoinCut()", throwing = "e")
+    // public void saveExceptionLog(JoinPoint joinPoint, Throwable e) {
+    // // 获取RequestAttributes
+    // RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
+    // // 从获取RequestAttributes中获取HttpServletRequest的信息
+    // HttpServletRequest request = (HttpServletRequest) requestAttributes
+    // .resolveReference(RequestAttributes.REFERENCE_REQUEST);
+    //
+    // ExceptionLog excepLog = new ExceptionLog();
+    // try {
+    // // 从切面织入点处通过反射机制获取织入点处的方法
+    // MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+    // // 获取切入点所在的方法
+    // Method method = signature.getMethod();
+    // excepLog.setExcId(UuidUtil.get32UUID());
+    // // 获取请求的类名
+    // String className = joinPoint.getTarget().getClass().getName();
+    // // 获取请求的方法名
+    // String methodName = method.getName();
+    // methodName = className + "." + methodName;
+    // // 请求的参数
+    // Map<String, String> rtnMap = converMap(request.getParameterMap());
+    // // 将参数所在的数组转换成json
+    // String params = JSON.toJSONString(rtnMap);
+    // excepLog.setExcRequParam(params); // 请求参数
+    // excepLog.setOperMethod(methodName); // 请求方法名
+    // excepLog.setExcName(e.getClass().getName()); // 异常名称
+    // excepLog.setExcMessage(stackTraceToString(e.getClass().getName(), e.getMessage(), e.getStackTrace())); // 异常信息
+    // excepLog.setOperUserId(UserShiroUtil.getCurrentUserLoginName()); // 操作员ID
+    // excepLog.setOperUserName(UserShiroUtil.getCurrentUserName()); // 操作员名称
+    // excepLog.setOperUri(request.getRequestURI()); // 操作URI
+    // excepLog.setOperIp(IPUtil.getRemortIP(request)); // 操作员IP
+    // excepLog.setOperVer(operVer); // 操作版本号
+    // excepLog.setOperCreateTime(new Date()); // 发生异常时间
+    //
+    // exceptionLogService.insert(excepLog);
+    //
+    // } catch (Exception e2) {
+    // e2.printStackTrace();
+    // }
+    //
+    // }
 
     /**
      * 转换request 请求参数
      *
-     * @param paramMap request获取的参数数组
+     * @param paramMap
+     *            request获取的参数数组
      */
     public Map<String, String> converMap(Map<String, String[]> paramMap) {
         Map<String, String> rtnMap = new HashMap<String, String>();
@@ -195,7 +200,7 @@
         return rtnMap;
     }
 
-    private  String getPostData(HttpServletRequest request) {
+    private String getPostData(HttpServletRequest request) {
         StringBuffer data = new StringBuffer();
         String line = null;
         BufferedReader reader = null;
@@ -212,9 +217,12 @@
     /**
      * 转换异常信息为字符串
      *
-     * @param exceptionName    异常名称
-     * @param exceptionMessage 异常信息
-     * @param elements         堆栈信息
+     * @param exceptionName
+     *            异常名称
+     * @param exceptionMessage
+     *            异常信息
+     * @param elements
+     *            堆栈信息
      */
     public String stackTraceToString(String exceptionName, String exceptionMessage, StackTraceElement[] elements) {
         StringBuffer strbuff = new StringBuffer();

--
Gitblit v1.7.1