ソースを参照

[chg] sql性能,日志切面优化.

wcz 5 年 前
コミット
c783cc458c

+ 11 - 14
lift-business-service/src/main/java/cn/com/ty/lift/business/emergency/controller/EmergencyRepairController.java

@@ -97,16 +97,14 @@ public class EmergencyRepairController {
         faultIds.addAll(natureIds);
         faultIds.addAll(handleIds);
         faultIds.addAll(dutyIds);
-        if(IterUtil.isNotEmpty(faultIds)){
-            Collection<LiftFault> liftFaults = liftFaultService.listByIds(faultIds);
-            if(IterUtil.isNotEmpty(liftFaults)){
-                result.setFaultParts(liftFaults.stream().filter(lf -> (partIds.contains(lf.getId()))).collect(Collectors.toList()));
-                result.setFaultReasons(liftFaults.stream().filter(lf -> (reasonIds.contains(lf.getId()))).collect(Collectors.toList()));
-                result.setFaultNatures(liftFaults.stream().filter(lf -> (natureIds.contains(lf.getId()))).collect(Collectors.toList()));
-                result.setFaultHandles(liftFaults.stream().filter(lf -> (handleIds.contains(lf.getId()))).collect(Collectors.toList()));
-                result.setFaultDuties(liftFaults.stream().filter(lf -> (dutyIds.contains(lf.getId()))).collect(Collectors.toList()));
-            }
-        }
+        if(faultIds.isEmpty()) return;
+        Collection<LiftFault> liftFaults = liftFaultService.listByIds(faultIds);
+        if(IterUtil.isEmpty(liftFaults)) return;
+        result.setFaultParts(liftFaults.stream().filter(lf -> (partIds.contains(lf.getId()))).collect(Collectors.toList()));
+        result.setFaultReasons(liftFaults.stream().filter(lf -> (reasonIds.contains(lf.getId()))).collect(Collectors.toList()));
+        result.setFaultNatures(liftFaults.stream().filter(lf -> (natureIds.contains(lf.getId()))).collect(Collectors.toList()));
+        result.setFaultHandles(liftFaults.stream().filter(lf -> (handleIds.contains(lf.getId()))).collect(Collectors.toList()));
+        result.setFaultDuties(liftFaults.stream().filter(lf -> (dutyIds.contains(lf.getId()))).collect(Collectors.toList()));
     }
 
     /**
@@ -116,10 +114,9 @@ public class EmergencyRepairController {
      */
     private List<Long> splitIds(String idStr){
         if(StrUtil.isEmpty(idStr)){
-            return Collections.EMPTY_LIST;
+            return Collections.emptyList();
         }
-        List<Long> ids = Arrays.asList(idStr.split(StrPool.COMMA)).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
-        return ids;
+        return Arrays.stream(idStr.split(StrPool.COMMA)).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
     }
     /**
      * 新增急修
@@ -301,7 +298,7 @@ public class EmergencyRepairController {
         Judge.notNull(repair);
 
         List<ErRecordCost> erRecordCosts = request.getErRecordCosts();
-        BigDecimal costTotal = erRecordCosts.stream().map(ErRecordCost::getCostMoney).reduce(BigDecimal.ZERO,(m1,m2) -> m1.add(m2));
+        BigDecimal costTotal = erRecordCosts.stream().map(ErRecordCost::getCostMoney).reduce(BigDecimal.ZERO, (m1, m2) -> m1.add(m2));
         repair.setCostTotal(costTotal);
 
         boolean result = emergencyRepairService.addCost(repair, erRecordCosts);

+ 1 - 1
lift-business-service/src/main/java/cn/com/ty/lift/business/emergency/service/impl/EmergencyRepairService.java

@@ -117,7 +117,7 @@ public class EmergencyRepairService extends ServiceImpl<EmergencyRepairMapper, E
             return true;
         } else {
             //强制手动事务回滚
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            rollback();
             return false;
         }
     }

+ 87 - 36
lift-business-service/src/main/java/cn/com/ty/lift/business/framework/aspect/ControllerAspect.java

@@ -5,14 +5,14 @@ import cn.com.ty.lift.common.utils.JudgeException;
 import cn.com.ty.lift.common.utils.Judger;
 import cn.com.ty.lift.common.utils.StrPool;
 import cn.com.xwy.boot.web.dto.RestResponse;
-import cn.hutool.json.JSON;
-import cn.hutool.json.JSONUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.Signature;
 import org.aspectj.lang.annotation.*;
 import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -34,6 +34,18 @@ import java.util.Arrays;
 @Component
 public class ControllerAspect {
 
+    @Autowired
+    private ObjectMapper objectMapper;
+    private Instant      begin = Instant.now();
+    private Instant      end   = Instant.now();
+    private String       url;
+    private String       httpMethod;
+    private String       ip;
+    private String       classMethod;
+    private String       args;
+    private String       resp;
+    private long         timing;
+
     @Pointcut("execution(* cn.com.ty.lift.business.*.controller..*(..))")
     public void pointcut() {
     }
@@ -41,16 +53,16 @@ public class ControllerAspect {
     @Before("pointcut()")
     public void doBefore(JoinPoint joinPoint) throws Throwable {
         // Receives the request and get request content
+        begin = Instant.now();
         ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
         HttpServletRequest request = attributes.getRequest();
         Signature signature = joinPoint.getSignature();
 
-        log.info(StrPool.LOG_LINE);
-        log.info(StrPool.LOG_URL + request.getRequestURL().toString());
-        log.info(StrPool.LOG_HTTP_METHOD + request.getMethod());
-        log.info(StrPool.LOG_IP + request.getRemoteAddr());
-        log.info(StrPool.LOG_CLASS_METHOD + signature.getDeclaringTypeName() + StrPool.DOT + signature.getName());
-        log.info(StrPool.LOG_ARGS + Arrays.toString(joinPoint.getArgs()));
+        url = StrPool.LOG_URL + request.getRequestURL().toString();
+        httpMethod = StrPool.LOG_HTTP_METHOD + request.getMethod();
+        ip = StrPool.LOG_IP + request.getRemoteAddr();
+        classMethod = StrPool.LOG_CLASS_METHOD + signature.getDeclaringTypeName() + StrPool.DOT + signature.getName();
+        args = StrPool.LOG_ARGS + Arrays.toString(joinPoint.getArgs()).replace("=null","");
 
         judge(joinPoint);
     }
@@ -58,58 +70,97 @@ public class ControllerAspect {
     @AfterReturning(returning = "response", pointcut = "pointcut()")
     public void doAfterReturning(RestResponse response) throws Throwable {
         // Processes the request and returns the content
-        String res = JSONUtil.toJsonPrettyStr(response);
-        if(null != res){
-            int length = res.length();
-            int sub = length - StrPool.LOG_PRINT_MAX;
-            res = sub < 0 ? res : res.substring(0, StrPool.LOG_PRINT_MAX) + StrPool.NEWLINE + "... " + sub + " characters omitted." + StrPool.NEWLINE + "}";
-            log.info(StrPool.LOG_RESPONSE + StrPool.NEWLINE + res);
+        end = Instant.now();
+        String res = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response);
+        if (null != res && res.length() > 0) {
+            if(!StrPool.LOG_PRINT_ALL){
+                int length = res.length();
+                int sub = length - StrPool.LOG_PRINT_MAX;
+                int head = StrPool.LOG_PRINT_MAX >> 1;
+                int tail = length - head;
+                res = sub < 0 ? res : res.substring(0, head) + StrPool.NEWLINE + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE
+                        + sub + " omit." + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE + StrPool.NEWLINE
+                        + res.substring(tail, length);
+            }
+            timing = Duration.between(begin, end).toMillis();
+            resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + StrPool.NEWLINE + res;
+            if (timing > StrPool.LOG_GOOD_TIME) {
+                warn();
+            } else {
+                info();
+            }
         }
     }
 
     @AfterThrowing(throwing = "ex", pointcut = "pointcut()")
     public void doAfterThrowing(Exception ex) throws Throwable {
         // Processes the exception
-        if(null != ex){
-            Class<? extends Exception> exClass = ex.getClass();
-            if(exClass.equals(JudgeException.class) || exClass.equals(MethodArgumentNotValidException.class)){
-                final String msg = ex.getMessage();
-                log.info(StrPool.LOG_RESPONSE + msg);
+        end = Instant.now();
+        if (null != ex) {
+            Class<? extends Exception> clazz = ex.getClass();
+            if (clazz.equals(JudgeException.class) || clazz.equals(MethodArgumentNotValidException.class)) {
+                String res = ex.getMessage();
+                timing = Duration.between(begin, end).toMillis();
+                resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + res;
+                error();
             }
         }
     }
 
-
     @Around("pointcut()")
     public Object interceptor(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
-        Instant start = Instant.now();
-        Object result = proceedingJoinPoint.proceed();
-        Instant end = Instant.now();
-        long toMillis = Duration.between(start, end).toMillis();
-        if (StrPool.LOG_GOOD_TIME < toMillis) {
-            Signature signature = proceedingJoinPoint.getSignature();
-            String classMethod = signature.getDeclaringTypeName() + "." + signature.getName();
-            log.warn(StrPool.LOG_TIME + "(" + toMillis + " ms) " + classMethod);
-        } else {
-            log.info(StrPool.LOG_TIME + toMillis + " ms");
-        }
-        return result;
+        return proceedingJoinPoint.proceed();
     }
 
     //检查必要参数非空,数值型参数必须 !null && > 0
-    private void judge(JoinPoint joinPoint){
+    private void judge(JoinPoint joinPoint) {
         Object[] args = joinPoint.getArgs();
         MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
         Method method = methodSignature.getMethod();
         Judger judger = method.getDeclaredAnnotation(Judger.class);
-        if(null == judger || args.length == 0){
+        if (null == judger || args.length == 0) {
             return;
         }
         Object object = args[0];
         String[] fields = judger.fields();
-        if(null == object || fields.length == 0){
+        if (null == object || fields.length == 0) {
             return;
         }
-        Judge.judgement(object,fields);
+        Judge.judgement(object, fields);
+    }
+
+    private void info() {
+        log.info(StrPool.LOG_LINE);
+        log.info(url);
+        log.info(httpMethod);
+        log.info(ip);
+        log.info(classMethod);
+        log.info(args);
+        log.info(resp);
+        log.info(StrPool.LOG_LINE);
+    }
+
+    private void warn() {
+        log.warn(StrPool.LOG_LINE);
+        log.warn(url);
+        log.warn(httpMethod);
+        log.warn(ip);
+        log.warn(classMethod);
+        log.warn(args);
+        log.warn(resp);
+        log.warn(StrPool.LOG_LINE);
+    }
+
+    private void error() {
+        log.error(StrPool.LOG_LINE);
+        log.error(url);
+        log.error(httpMethod);
+        log.error(ip);
+        log.error(classMethod);
+        log.error(args);
+        log.error(resp);
+        log.error(StrPool.LOG_LINE);
     }
 }

+ 0 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/framework/conf/SystemConfiguration.java

@@ -99,8 +99,6 @@ public class SystemConfiguration {
         sqlAnalysisInterceptor.setFormat(true);
         //sql写入日志文件
         sqlAnalysisInterceptor.setLogWrite(true);
-        //开发模式,慢sql直接抛出异常
-        sqlAnalysisInterceptor.setDevMode(true);
         return sqlAnalysisInterceptor;
     }
 

+ 13 - 16
lift-common/src/main/java/cn.com.ty.lift.common/sql/SqlAnalysisInterceptor.java

@@ -75,21 +75,13 @@ public class SqlAnalysisInterceptor implements Interceptor {
     private boolean format   = false;
     /**
      * 是否写入日志文件
-     * <p>true 写入日志文件</p>
+     * <p>true 写入日志文件,慢sql->ERROR,其他sql->INFO</p>
+     * <p>默认false 不写入日志文件,慢sql->system.err, 同时抛出异常,其他sql->system.out</p>
      */
     @Setter
     @Getter
     @Accessors(chain = true)
     private boolean logWrite = false;
-    /**
-     * 是否开发模式
-     * <p>true,如果同时设置了maxTime > 0,慢sql会system.err打印</p>
-     * <p>超过设定的最大执行时长直接抛出异常!</p>
-     */
-    @Setter
-    @Getter
-    @Accessors(chain = true)
-    private boolean devMode  = false;
     private Method  oracleGetOriginalSqlMethod;
     private Method  druidGetSQLMethod;
 
@@ -113,7 +105,7 @@ public class SqlAnalysisInterceptor implements Interceptor {
             try {
                 statement = (Statement) stmtMetaObj.getValue(delegate);
             } catch (Exception ignored) {
-
+                // do nothing
             }
         }
 
@@ -161,6 +153,8 @@ public class SqlAnalysisInterceptor implements Interceptor {
         if (originalSql == null) {
             originalSql = statement.toString();
         }
+        //\s用于匹配空白字符, \\s用于匹配字符串中的\和s,两个字符
+        //去掉原始sql中的格式,换行,全部格式化为一行sql
         originalSql = originalSql.replaceAll("[\\s]+", SPACE);
         int index = indexOfSqlStart(originalSql);
         if (index > 0) {
@@ -189,10 +183,9 @@ public class SqlAnalysisInterceptor implements Interceptor {
             if (slowSql) {
                 log.error(sql);
             } else {
-                log.debug(sql);
+                log.info(sql);
             }
-        }
-        if(this.isDevMode()) {
+        }else{
             if(slowSql){
                 System.err.println(sql);
                 throw new SqlAnalysisException("The SQL execution time is too large, please optimize ! ");
@@ -215,12 +208,16 @@ public class SqlAnalysisInterceptor implements Interceptor {
     public void setProperties(Properties prop) {
         String maxTime = prop.getProperty("maxTime");
         String format = prop.getProperty("format");
-        if (SqlUtils.isNotEmpty(maxTime)) {
+        String logWrite = prop.getProperty("logWrite");
+        if (SqlUtils.isNumeric(maxTime)) {
             this.maxTime = Long.parseLong(maxTime);
         }
-        if (SqlUtils.isNotEmpty(format)) {
+        if (SqlUtils.isBoolean(format)) {
             this.format = Boolean.valueOf(format);
         }
+        if(SqlUtils.isBoolean(logWrite)){
+            this.logWrite = Boolean.valueOf(logWrite);
+        }
     }
 
     /**

+ 29 - 0
lift-common/src/main/java/cn.com.ty.lift.common/sql/SqlUtils.java

@@ -20,6 +20,8 @@ import org.apache.ibatis.reflection.SystemMetaObject;
 
 import java.lang.reflect.Proxy;
 import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * SqlUtils工具类
@@ -88,6 +90,33 @@ public class SqlUtils {
         return (coll == null || coll.isEmpty());
     }
 
+    /**
+     * 判断是不是数字
+     * @param cs 输入
+     * @return boolean
+     */
+    public static boolean isNumeric(final CharSequence cs){
+        if(isEmpty(cs)){
+            return false;
+        }
+        Pattern pattern = Pattern.compile("[0-9]+");
+        Matcher isNum = pattern.matcher(cs);
+        return isNum.matches();
+    }
+
+    /**
+     * 判断是否为boolean类型的字符串
+     * @param cs 输入
+     * @return boolean
+     */
+    public static boolean isBoolean(final CharSequence cs){
+        if(isEmpty(cs)){
+            return false;
+        }
+        String input = cs.toString().toLowerCase();
+        return "true".equals(input) || "false".equals(input);
+    }
+
     /**
      * 获得真正的处理对象,可能多层代理.
      */

+ 62 - 46
lift-common/src/main/java/cn.com.ty.lift.common/utils/Judge.java

@@ -25,6 +25,22 @@ public interface Judge {
     String PARAMETER_VERIFY_FAIL    = "参数校验失败";
     String PARAMETER_FILED_MISSING  = "缺少参数属性值域";
 
+    static JudgeException judgeException(){
+        return new JudgeException(DATA_MISSING_INCORRECT);
+    }
+
+    static JudgeException judgeException(String message){
+        if(null == message || message.length() == 0){
+            return judgeException();
+        }
+        return new JudgeException(message);
+    }
+    static JudgeException judgeException(String message,Throwable cause){
+        if(null == message || message.length() == 0 || null == cause){
+            return new JudgeException(DATA_MISSING_INCORRECT, new IllegalArgumentException());
+        }
+        return new JudgeException(message, cause);
+    }
     /**
      * id == null || id <= 0 throw new JudgeException(message)
      * @param id id值
@@ -32,8 +48,8 @@ public interface Judge {
      */
     static void id(Long id, String message) {
         notNull(id, message);
-        if (id.longValue() <= 0) {
-            throw new JudgeException(message);
+        if (id <= 0) {
+            throw judgeException(message);
         }
     }
 
@@ -45,8 +61,8 @@ public interface Judge {
     static void id(Long... ids) {
         notNull(ids, IDENTIFIER_INVALID);
         for (Long id : ids) {
-            if (null == id || id.longValue() <= 0) {
-                throw new JudgeException(IDENTIFIER_INVALID);
+            if (null == id || id <= 0) {
+                throw judgeException(IDENTIFIER_INVALID);
             }
         }
     }
@@ -59,19 +75,19 @@ public interface Judge {
      */
     static void gt0(Number value, String message) {
         if (null == value) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Long && value.longValue() <= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Integer && value.intValue() <= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Float && value.floatValue() <= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Double && value.doubleValue() <= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
@@ -95,26 +111,26 @@ public interface Judge {
      */
     static void lt0(Number value, String message) {
         if (null == value) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Long && value.longValue() >= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Integer && value.intValue() >= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Float && value.floatValue() >= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Double && value.doubleValue() >= 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
     /**
      * value == null || value >= 0 throw new JudgeException(message);
      *
-     * @param values 不定个的数值
+     * @param values 一个或多个的数值
      */
     static void lt0(Number... values) {
         notNull(values, MUST_LT0);
@@ -131,25 +147,25 @@ public interface Judge {
      */
     static void eq0(Number value, String message) {
         if (null == value) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Long && value.longValue() != 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Integer && value.intValue() != 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Float && value.floatValue() != 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Double && value.doubleValue() != 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
     /**
      * value == null || value != 0 throw new JudgeException(message);
-     * @param values 不定个数的数值
+     * @param values 一个或多个数的数值
      */
     static void eq0(Number... values) {
         notNull(values, MUST_EQ0);
@@ -166,26 +182,26 @@ public interface Judge {
      */
     static void ngt0(Number value, String message) {
         if (null == value) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Long && value.longValue() < 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Integer && value.intValue() < 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Float && value.floatValue() < 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Double && value.doubleValue() < 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
     /**
      * value == null || value < 0 throw new JudgeException(message);
      *
-     * @param values 不定个数的数值型的值
+     * @param values 一个或多个数的数值型的值
      */
     static void ngt0(Number... values) {
         notNull(values, MUST_NGT0);
@@ -202,26 +218,26 @@ public interface Judge {
      */
     static void nlt0(Number value, String message) {
         if (null == value) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Long && value.longValue() > 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Integer && value.intValue() > 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Float && value.floatValue() > 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Double && value.doubleValue() > 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
     /**
      * value == null || value > 0 throw new JudgeException(message);
      *
-     * @param values 不定个数的数值
+     * @param values 一个或多个数的数值
      */
     static void nlt0(Number... values) {
         notNull(values, MUST_NLT0);
@@ -238,26 +254,26 @@ public interface Judge {
      */
     static void neq0(Number value, String message) {
         if (null == value) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Long && value.longValue() == 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Integer && value.intValue() == 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Float && value.floatValue() == 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
         if (value instanceof Double && value.doubleValue() == 0) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
     /**
      * value == null || value != 0 throw new JudgeException(message);
      *
-     * @param values 不定个数的数值
+     * @param values 一个或多个数的数值
      */
     static void neq0(Number... values) {
         notNull(values, MUST_NEQ0);
@@ -274,7 +290,7 @@ public interface Judge {
      */
     static void isNull(Object object, String message) {
         if (ObjectUtil.isNotEmpty(object)) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
@@ -295,7 +311,7 @@ public interface Judge {
      */
     static void notNull(Object object, String message) {
         if (ObjectUtil.isEmpty(object)) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
@@ -316,7 +332,7 @@ public interface Judge {
      */
     static void isTrue(boolean expression, String message) {
         if (!expression) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
@@ -337,7 +353,7 @@ public interface Judge {
      */
     static void notTrue(boolean expression, String message) {
         if (expression) {
-            throw new JudgeException(message);
+            throw judgeException(message);
         }
     }
 
@@ -376,11 +392,11 @@ public interface Judge {
                 }
             }
         } catch (JudgeException e) {
-            throw new JudgeException(e.getMessage());
+            throw judgeException(e.getMessage());
         } catch (NoSuchFieldException e) {
-            throw new JudgeException(PARAMETER_FILED_MISSING);
+            throw judgeException(PARAMETER_FILED_MISSING);
         } catch (Exception e) {
-            throw new JudgeException(PARAMETER_VERIFY_FAIL);
+            throw judgeException(PARAMETER_VERIFY_FAIL);
         }
     }
 

+ 17 - 15
lift-common/src/main/java/cn.com.ty.lift.common/utils/StrPool.java

@@ -85,22 +85,24 @@ public interface StrPool {
 
     // ----------------------------------------------------------------log
 
-    String LOG_PREFIX                = "###| ";
-    String LOG_LINE                  = "============================================================";
-    String LOG_GLOBAL_EXCEPTION_LINE = "====================== GlobalDefaultException ======================";
-    String LOG_URL                   = StrPool.LOG_PREFIX + "URL          : ";
-    String LOG_HTTP_METHOD           = StrPool.LOG_PREFIX + "HTTP_METHOD  : ";
-    String LOG_IP                    = StrPool.LOG_PREFIX + "IP           : ";
-    String LOG_CLASS_METHOD          = StrPool.LOG_PREFIX + "CLASS_METHOD : ";
-    String LOG_ARGS                  = StrPool.LOG_PREFIX + "ARGS         : ";
-    String LOG_RESPONSE              = StrPool.LOG_PREFIX + "RESPONSE     : ";
-    String LOG_TIME                  = StrPool.LOG_PREFIX + "TIME         : ";
-    String LOG_STATUS                = StrPool.LOG_PREFIX + "STATUS       : ";
-    String LOG_EXCEPTION             = StrPool.LOG_PREFIX + "EXCEPTION    : ";
-    // 结果字符串 > LOG_PRINT_MAX 省略超过部分,并且格式化打印
-    int    LOG_PRINT_MAX             = 1000;
+    String  LOG_PREFIX                = "###| ";
+    String  LOG_LINE                  = "============================================================";
+    String  LOG_GLOBAL_EXCEPTION_LINE = "====================== GlobalDefaultException ======================";
+    String  LOG_URL                   = StrPool.LOG_PREFIX + "URL          : ";
+    String  LOG_HTTP_METHOD           = StrPool.LOG_PREFIX + "HTTP_METHOD  : ";
+    String  LOG_IP                    = StrPool.LOG_PREFIX + "IP           : ";
+    String  LOG_CLASS_METHOD          = StrPool.LOG_PREFIX + "CLASS_METHOD : ";
+    String  LOG_ARGS                  = StrPool.LOG_PREFIX + "ARGS         : ";
+    String  LOG_RESPONSE              = StrPool.LOG_PREFIX + "RESPONSE     : ";
+    String  LOG_TIME                  = StrPool.LOG_PREFIX + "TIME         : ";
+    String  LOG_STATUS                = StrPool.LOG_PREFIX + "STATUS       : ";
+    String  LOG_EXCEPTION             = StrPool.LOG_PREFIX + "EXCEPTION    : ";
+    //是否打印全部的结果
+    boolean LOG_PRINT_ALL             = false;
+    // 结果字符串 > LOG_PRINT_MAX ,格式化打印首尾(LOG_PRINT_MAX / 2)部分,中间省略
+    int     LOG_PRINT_MAX             = 1000;
     // 方法处理耗时 > LOG_GOOD_TIME,日志到warn中
-    long   LOG_GOOD_TIME             = 10 * 1000;
+    long    LOG_GOOD_TIME             = 10 * 1000;
 
     // ---------------------------------------------------------------- array
 

+ 87 - 35
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/common/ControllerAspect.java

@@ -5,13 +5,14 @@ import cn.com.ty.lift.common.utils.JudgeException;
 import cn.com.ty.lift.common.utils.Judger;
 import cn.com.ty.lift.common.utils.StrPool;
 import cn.com.xwy.boot.web.dto.RestResponse;
-import cn.hutool.json.JSONUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.Signature;
 import org.aspectj.lang.annotation.*;
 import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -33,6 +34,18 @@ import java.util.Arrays;
 @Component
 public class ControllerAspect {
 
+    @Autowired
+    private ObjectMapper objectMapper;
+    private Instant      begin = Instant.now();
+    private Instant      end   = Instant.now();
+    private String       url;
+    private String       httpMethod;
+    private String       ip;
+    private String       classMethod;
+    private String       args;
+    private String       resp;
+    private long         timing;
+
     @Pointcut("execution(* cn.com.ty.lift.enterprise.*.controller..*(..))")
     public void pointcut() {
     }
@@ -40,16 +53,16 @@ public class ControllerAspect {
     @Before("pointcut()")
     public void doBefore(JoinPoint joinPoint) throws Throwable {
         // Receives the request and get request content
+        begin = Instant.now();
         ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
         HttpServletRequest request = attributes.getRequest();
         Signature signature = joinPoint.getSignature();
 
-        log.info(StrPool.LOG_LINE);
-        log.info(StrPool.LOG_URL + request.getRequestURL().toString());
-        log.info(StrPool.LOG_HTTP_METHOD + request.getMethod());
-        log.info(StrPool.LOG_IP + request.getRemoteAddr());
-        log.info(StrPool.LOG_CLASS_METHOD + signature.getDeclaringTypeName() + StrPool.DOT + signature.getName());
-        log.info(StrPool.LOG_ARGS + Arrays.toString(joinPoint.getArgs()));
+        url = StrPool.LOG_URL + request.getRequestURL().toString();
+        httpMethod = StrPool.LOG_HTTP_METHOD + request.getMethod();
+        ip = StrPool.LOG_IP + request.getRemoteAddr();
+        classMethod = StrPool.LOG_CLASS_METHOD + signature.getDeclaringTypeName() + StrPool.DOT + signature.getName();
+        args = StrPool.LOG_ARGS + Arrays.toString(joinPoint.getArgs()).replace("=null","");
 
         judge(joinPoint);
     }
@@ -57,58 +70,97 @@ public class ControllerAspect {
     @AfterReturning(returning = "response", pointcut = "pointcut()")
     public void doAfterReturning(RestResponse response) throws Throwable {
         // Processes the request and returns the content
-        String res = JSONUtil.toJsonPrettyStr(response);
-        if(null != res){
-            int length = res.length();
-            int sub = length - StrPool.LOG_PRINT_MAX;
-            res = sub < 0 ? res : res.substring(0, StrPool.LOG_PRINT_MAX) + StrPool.NEWLINE + "... " + sub + " characters omitted." + StrPool.NEWLINE + "}";
-            log.info(StrPool.LOG_RESPONSE + StrPool.NEWLINE + res);
+        end = Instant.now();
+        String res = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response);
+        if (null != res && res.length() > 0) {
+            if(!StrPool.LOG_PRINT_ALL){
+                int length = res.length();
+                int sub = length - StrPool.LOG_PRINT_MAX;
+                int head = StrPool.LOG_PRINT_MAX >> 1;
+                int tail = length - head;
+                res = sub < 0 ? res : res.substring(0, head) + StrPool.NEWLINE + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE
+                        + sub + " omit." + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE + StrPool.NEWLINE
+                        + res.substring(tail, length);
+            }
+            timing = Duration.between(begin, end).toMillis();
+            resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + StrPool.NEWLINE + res;
+            if (timing > StrPool.LOG_GOOD_TIME) {
+                warn();
+            } else {
+                info();
+            }
         }
     }
 
     @AfterThrowing(throwing = "ex", pointcut = "pointcut()")
     public void doAfterThrowing(Exception ex) throws Throwable {
         // Processes the exception
-        if(null != ex){
-            Class<? extends Exception> exClass = ex.getClass();
-            if(exClass.equals(JudgeException.class) || exClass.equals(MethodArgumentNotValidException.class)){
-                final String msg = ex.getMessage();
-                log.info(StrPool.LOG_RESPONSE + msg);
+        end = Instant.now();
+        if (null != ex) {
+            Class<? extends Exception> clazz = ex.getClass();
+            if (clazz.equals(JudgeException.class) || clazz.equals(MethodArgumentNotValidException.class)) {
+                String res = ex.getMessage();
+                timing = Duration.between(begin, end).toMillis();
+                resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + res;
+                error();
             }
         }
     }
 
-
     @Around("pointcut()")
     public Object interceptor(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
-        Instant start = Instant.now();
-        Object result = proceedingJoinPoint.proceed();
-        Instant end = Instant.now();
-        long toMillis = Duration.between(start, end).toMillis();
-        if (StrPool.LOG_GOOD_TIME < toMillis) {
-            Signature signature = proceedingJoinPoint.getSignature();
-            String classMethod = signature.getDeclaringTypeName() + "." + signature.getName();
-            log.warn(StrPool.LOG_TIME + "(" + toMillis + " ms) " + classMethod);
-        } else {
-            log.info(StrPool.LOG_TIME + toMillis + " ms");
-        }
-        return result;
+        return proceedingJoinPoint.proceed();
     }
 
     //检查必要参数非空,数值型参数必须 !null && > 0
-    private void judge(JoinPoint joinPoint){
+    private void judge(JoinPoint joinPoint) {
         Object[] args = joinPoint.getArgs();
         MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
         Method method = methodSignature.getMethod();
         Judger judger = method.getDeclaredAnnotation(Judger.class);
-        if(null == judger || args.length == 0){
+        if (null == judger || args.length == 0) {
             return;
         }
         Object object = args[0];
         String[] fields = judger.fields();
-        if(null == object || fields.length == 0){
+        if (null == object || fields.length == 0) {
             return;
         }
-        Judge.judgement(object,fields);
+        Judge.judgement(object, fields);
+    }
+
+    private void info() {
+        log.info(StrPool.LOG_LINE);
+        log.info(url);
+        log.info(httpMethod);
+        log.info(ip);
+        log.info(classMethod);
+        log.info(args);
+        log.info(resp);
+        log.info(StrPool.LOG_LINE);
+    }
+
+    private void warn() {
+        log.warn(StrPool.LOG_LINE);
+        log.warn(url);
+        log.warn(httpMethod);
+        log.warn(ip);
+        log.warn(classMethod);
+        log.warn(args);
+        log.warn(resp);
+        log.warn(StrPool.LOG_LINE);
+    }
+
+    private void error() {
+        log.error(StrPool.LOG_LINE);
+        log.error(url);
+        log.error(httpMethod);
+        log.error(ip);
+        log.error(classMethod);
+        log.error(args);
+        log.error(resp);
+        log.error(StrPool.LOG_LINE);
     }
 }

+ 105 - 43
lift-quan-service/src/main/java/cn/com/ty/lift/quan/config/ControllerAspect.java

@@ -1,19 +1,25 @@
 package cn.com.ty.lift.quan.config;
 
+import cn.com.ty.lift.common.utils.Judge;
 import cn.com.ty.lift.common.utils.JudgeException;
+import cn.com.ty.lift.common.utils.Judger;
+import cn.com.ty.lift.common.utils.StrPool;
 import cn.com.xwy.boot.web.dto.RestResponse;
-import cn.hutool.json.JSONUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.Signature;
 import org.aspectj.lang.annotation.*;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
 import java.time.Duration;
 import java.time.Instant;
 import java.util.Arrays;
@@ -28,18 +34,17 @@ import java.util.Arrays;
 @Component
 public class ControllerAspect {
 
-    private static final String  line        = "============================================================";
-    private static final String  head        = "#####| ";
-    private static final String  url         = head + "URL          : ";
-    private static final String  httpMethod  = head + "HTTP_METHOD  : ";
-    private static final String  ip          = head + "IP           : ";
-    private static final String  classMethod = head + "CLASS_METHOD : ";
-    private static final String  args        = head + "ARGS         : ";
-    private static final String  resp        = head + "RESPONSE     : ";
-    private static final String  proceed     = head + "TIME         : ";
-    private static final boolean printAll    = false;
-    private static final int     printLength = 1000;
-    private static final long    goodtime    = 10 * 1000;
+    @Autowired
+    private ObjectMapper objectMapper;
+    private Instant      begin = Instant.now();
+    private Instant      end   = Instant.now();
+    private String       url;
+    private String       httpMethod;
+    private String       ip;
+    private String       classMethod;
+    private String       args;
+    private String       resp;
+    private long         timing;
 
     @Pointcut("execution(* cn.com.ty.lift.quan.*.controller..*(..))")
     public void pointcut() {
@@ -48,57 +53,114 @@ public class ControllerAspect {
     @Before("pointcut()")
     public void doBefore(JoinPoint joinPoint) throws Throwable {
         // Receives the request and get request content
+        begin = Instant.now();
         ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
         HttpServletRequest request = attributes.getRequest();
+        Signature signature = joinPoint.getSignature();
 
-        log.info(url + request.getRequestURL().toString());
-        log.info(httpMethod + request.getMethod());
-        log.info(ip + request.getRemoteAddr());
-        log.info(classMethod + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
-        log.info(args + Arrays.toString(joinPoint.getArgs()));
+        url = StrPool.LOG_URL + request.getRequestURL().toString();
+        httpMethod = StrPool.LOG_HTTP_METHOD + request.getMethod();
+        ip = StrPool.LOG_IP + request.getRemoteAddr();
+        classMethod = StrPool.LOG_CLASS_METHOD + signature.getDeclaringTypeName() + StrPool.DOT + signature.getName();
+        args = StrPool.LOG_ARGS + Arrays.toString(joinPoint.getArgs()).replace("=null","");
 
+        judge(joinPoint);
     }
 
     @AfterReturning(returning = "response", pointcut = "pointcut()")
     public void doAfterReturning(RestResponse response) throws Throwable {
         // Processes the request and returns the content
-        String res = JSONUtil.toJsonPrettyStr(response);
-        if(!printAll && null != res){
-            int length = res.length();
-            res = length > printLength ? res.substring(0, printLength) + "\n... "+ (length - printLength) +" characters omitted." : res;
+        end = Instant.now();
+        String res = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response);
+        if (null != res && res.length() > 0) {
+            if(!StrPool.LOG_PRINT_ALL){
+                int length = res.length();
+                int sub = length - StrPool.LOG_PRINT_MAX;
+                int head = StrPool.LOG_PRINT_MAX >> 1;
+                int tail = length - head;
+                res = sub < 0 ? res : res.substring(0, head) + StrPool.NEWLINE + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE
+                        + sub + " omit." + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE + StrPool.NEWLINE
+                        + res.substring(tail, length);
+            }
+            timing = Duration.between(begin, end).toMillis();
+            resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + StrPool.NEWLINE + res;
+            if (timing > StrPool.LOG_GOOD_TIME) {
+                warn();
+            } else {
+                info();
+            }
         }
-        log.info(resp + "\n" + res);
-        log.info(line);
     }
 
     @AfterThrowing(throwing = "ex", pointcut = "pointcut()")
-    public void doAfterThrowing(QuanBasicException ex) throws Throwable {
+    public void doAfterThrowing(Exception ex) throws Throwable {
         // Processes the exception
-        if(null != ex){
-            Class<? extends Exception> exClass = ex.getClass();
-            if(exClass.equals(JudgeException.class) || exClass.equals(MethodArgumentNotValidException.class)){
-                final String msg = ex.getMessage();
-                log.info(resp + msg);
-                log.info(line);
+        end = Instant.now();
+        if (null != ex) {
+            Class<? extends Exception> clazz = ex.getClass();
+            if (clazz.equals(JudgeException.class) || clazz.equals(MethodArgumentNotValidException.class)) {
+                String res = ex.getMessage();
+                timing = Duration.between(begin, end).toMillis();
+                resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + res;
+                error();
             }
         }
     }
 
-
     @Around("pointcut()")
     public Object interceptor(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
-        Instant start = Instant.now();
-        Object result = proceedingJoinPoint.proceed();
-        Instant end = Instant.now();
-        long toMillis = Duration.between(start, end).toMillis();
-        if (goodtime < toMillis) {
-            Signature signature = proceedingJoinPoint.getSignature();
-            String classMethod = signature.getDeclaringTypeName() + "." + signature.getName();
-            log.warn(proceed + " (" + toMillis + " ms)" + classMethod);
-        } else {
-            log.info(proceed + toMillis + " ms");
+        return proceedingJoinPoint.proceed();
+    }
+
+    //检查必要参数非空,数值型参数必须 !null && > 0
+    private void judge(JoinPoint joinPoint) {
+        Object[] args = joinPoint.getArgs();
+        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
+        Method method = methodSignature.getMethod();
+        Judger judger = method.getDeclaredAnnotation(Judger.class);
+        if (null == judger || args.length == 0) {
+            return;
+        }
+        Object object = args[0];
+        String[] fields = judger.fields();
+        if (null == object || fields.length == 0) {
+            return;
         }
-        return result;
+        Judge.judgement(object, fields);
     }
 
+    private void info() {
+        log.info(StrPool.LOG_LINE);
+        log.info(url);
+        log.info(httpMethod);
+        log.info(ip);
+        log.info(classMethod);
+        log.info(args);
+        log.info(resp);
+        log.info(StrPool.LOG_LINE);
+    }
+
+    private void warn() {
+        log.warn(StrPool.LOG_LINE);
+        log.warn(url);
+        log.warn(httpMethod);
+        log.warn(ip);
+        log.warn(classMethod);
+        log.warn(args);
+        log.warn(resp);
+        log.warn(StrPool.LOG_LINE);
+    }
+
+    private void error() {
+        log.error(StrPool.LOG_LINE);
+        log.error(url);
+        log.error(httpMethod);
+        log.error(ip);
+        log.error(classMethod);
+        log.error(args);
+        log.error(resp);
+        log.error(StrPool.LOG_LINE);
+    }
 }

+ 6 - 11
lift-quan-service/src/main/java/cn/com/ty/lift/quan/config/GlobalDefaultExceptionHandler.java

@@ -1,6 +1,7 @@
 package cn.com.ty.lift.quan.config;
 
 import cn.com.ty.lift.common.utils.JudgeException;
+import cn.com.ty.lift.common.utils.StrPool;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.util.StrUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -28,12 +29,6 @@ import java.util.stream.Stream;
 public class GlobalDefaultExceptionHandler {
 
     private static final String classPrefix = "cn.com.ty.lift.quan";
-    private static final String nameSuffix  = ".java";
-    private static final String line        = "========================= GlobalDefaultException =========================";
-    private static final String head        = "#####| ";
-    private static final String url         = head + "URL          : {}";
-    private static final String status      = head + "STATUS       : {}";
-    private static final String exception   = head + "EXCEPTION    : ";
 
     //处理judge抛出的异常
     @ExceptionHandler(value = JudgeException.class)
@@ -65,7 +60,7 @@ public class GlobalDefaultExceptionHandler {
 
         // 过滤错误信息
         final List<StackTraceElement> elements = Stream.of(stackTrace)
-                .filter(st -> (st.getClassName().contains(classPrefix) && st.getFileName().contains(nameSuffix)))
+                .filter(st -> (st.getClassName().contains(classPrefix) && st.getFileName().contains(StrPool.DOT_JAVA)))
                 .collect(Collectors.toCollection(LinkedList::new));
 
         final StackTraceElement[] dwStackTrace = new StackTraceElement[elements.size()];
@@ -73,10 +68,10 @@ public class GlobalDefaultExceptionHandler {
 
         // 填充StackTrace
         error.setStackTrace(dwStackTrace);
-        log.error(line);
-        log.error(url, req.getRequestURI());
-        log.error(status, resp.getStatus());
-        log.error(exception, error);
+        log.error(StrPool.LOG_GLOBAL_EXCEPTION_LINE);
+        log.error(StrPool.LOG_URL + req.getRequestURI());
+        log.error(StrPool.LOG_STATUS + resp.getStatus());
+        log.error(StrPool.LOG_EXCEPTION, error);
 
         if (error instanceof QuanBasicException) {
             final QuanBasicException businessBasicException = (QuanBasicException) error;

+ 103 - 30
lift-system-service/src/main/java/cn/com/ty/lift/system/config/ControllerAspect.java

@@ -1,20 +1,25 @@
 package cn.com.ty.lift.system.config;
 
+import cn.com.ty.lift.common.utils.Judge;
 import cn.com.ty.lift.common.utils.JudgeException;
+import cn.com.ty.lift.common.utils.Judger;
 import cn.com.ty.lift.common.utils.StrPool;
 import cn.com.xwy.boot.web.dto.RestResponse;
-import cn.hutool.json.JSONUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.Signature;
 import org.aspectj.lang.annotation.*;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
 import java.time.Duration;
 import java.time.Instant;
 import java.util.Arrays;
@@ -29,6 +34,18 @@ import java.util.Arrays;
 @Component
 public class ControllerAspect {
 
+    @Autowired
+    private ObjectMapper objectMapper;
+    private Instant      begin = Instant.now();
+    private Instant      end   = Instant.now();
+    private String       url;
+    private String       httpMethod;
+    private String       ip;
+    private String       classMethod;
+    private String       args;
+    private String       resp;
+    private long         timing;
+
     @Pointcut("execution(* cn.com.ty.lift.system.*.controller..*(..))")
     public void pointcut() {
     }
@@ -36,58 +53,114 @@ public class ControllerAspect {
     @Before("pointcut()")
     public void doBefore(JoinPoint joinPoint) throws Throwable {
         // Receives the request and get request content
+        begin = Instant.now();
         ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
         HttpServletRequest request = attributes.getRequest();
         Signature signature = joinPoint.getSignature();
 
-        log.info(StrPool.LOG_LINE);
-        log.info(StrPool.LOG_URL + request.getRequestURL().toString());
-        log.info(StrPool.LOG_HTTP_METHOD + request.getMethod());
-        log.info(StrPool.LOG_IP + request.getRemoteAddr());
-        log.info(StrPool.LOG_CLASS_METHOD + signature.getDeclaringTypeName() + StrPool.DOT + signature.getName());
-        log.info(StrPool.LOG_ARGS + Arrays.toString(joinPoint.getArgs()));
+        url = StrPool.LOG_URL + request.getRequestURL().toString();
+        httpMethod = StrPool.LOG_HTTP_METHOD + request.getMethod();
+        ip = StrPool.LOG_IP + request.getRemoteAddr();
+        classMethod = StrPool.LOG_CLASS_METHOD + signature.getDeclaringTypeName() + StrPool.DOT + signature.getName();
+        args = StrPool.LOG_ARGS + Arrays.toString(joinPoint.getArgs()).replace("=null","");
 
+        judge(joinPoint);
     }
 
     @AfterReturning(returning = "response", pointcut = "pointcut()")
     public void doAfterReturning(RestResponse response) throws Throwable {
         // Processes the request and returns the content
-        String res = JSONUtil.toJsonPrettyStr(response);
-        if(null != res){
-            int length = res.length();
-            int sub = length - StrPool.LOG_PRINT_MAX;
-            res = sub < 0 ? res : res.substring(0, StrPool.LOG_PRINT_MAX) + StrPool.NEWLINE + "... " + sub + " characters omitted." + StrPool.NEWLINE + "}";
-            log.info(StrPool.LOG_RESPONSE + StrPool.NEWLINE + res);
+        end = Instant.now();
+        String res = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response);
+        if (null != res && res.length() > 0) {
+            if(!StrPool.LOG_PRINT_ALL){
+                int length = res.length();
+                int sub = length - StrPool.LOG_PRINT_MAX;
+                int head = StrPool.LOG_PRINT_MAX >> 1;
+                int tail = length - head;
+                res = sub < 0 ? res : res.substring(0, head) + StrPool.NEWLINE + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE
+                        + sub + " omit." + StrPool.NEWLINE
+                        + "..." + StrPool.NEWLINE + StrPool.NEWLINE
+                        + res.substring(tail, length);
+            }
+            timing = Duration.between(begin, end).toMillis();
+            resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + StrPool.NEWLINE + res;
+            if (timing > StrPool.LOG_GOOD_TIME) {
+                warn();
+            } else {
+                info();
+            }
         }
     }
 
     @AfterThrowing(throwing = "ex", pointcut = "pointcut()")
     public void doAfterThrowing(Exception ex) throws Throwable {
         // Processes the exception
-        if(null != ex){
-            Class<? extends Exception> exClass = ex.getClass();
-            if(exClass.equals(JudgeException.class) || exClass.equals(MethodArgumentNotValidException.class)){
-                final String msg = ex.getMessage();
-                log.info(StrPool.LOG_RESPONSE + msg);
+        end = Instant.now();
+        if (null != ex) {
+            Class<? extends Exception> clazz = ex.getClass();
+            if (clazz.equals(JudgeException.class) || clazz.equals(MethodArgumentNotValidException.class)) {
+                String res = ex.getMessage();
+                timing = Duration.between(begin, end).toMillis();
+                resp = StrPool.LOG_RESPONSE + "(" + timing + " ms)" + res;
+                error();
             }
         }
     }
 
-
     @Around("pointcut()")
     public Object interceptor(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
-        Instant start = Instant.now();
-        Object result = proceedingJoinPoint.proceed();
-        Instant end = Instant.now();
-        long toMillis = Duration.between(start, end).toMillis();
-        if (StrPool.LOG_GOOD_TIME < toMillis) {
-            Signature signature = proceedingJoinPoint.getSignature();
-            String classMethod = signature.getDeclaringTypeName() + "." + signature.getName();
-            log.warn(StrPool.LOG_TIME + "(" + toMillis + " ms) " + classMethod);
-        } else {
-            log.info(StrPool.LOG_TIME + toMillis + " ms");
+        return proceedingJoinPoint.proceed();
+    }
+
+    //检查必要参数非空,数值型参数必须 !null && > 0
+    private void judge(JoinPoint joinPoint) {
+        Object[] args = joinPoint.getArgs();
+        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
+        Method method = methodSignature.getMethod();
+        Judger judger = method.getDeclaredAnnotation(Judger.class);
+        if (null == judger || args.length == 0) {
+            return;
+        }
+        Object object = args[0];
+        String[] fields = judger.fields();
+        if (null == object || fields.length == 0) {
+            return;
         }
-        return result;
+        Judge.judgement(object, fields);
     }
 
+    private void info() {
+        log.info(StrPool.LOG_LINE);
+        log.info(url);
+        log.info(httpMethod);
+        log.info(ip);
+        log.info(classMethod);
+        log.info(args);
+        log.info(resp);
+        log.info(StrPool.LOG_LINE);
+    }
+
+    private void warn() {
+        log.warn(StrPool.LOG_LINE);
+        log.warn(url);
+        log.warn(httpMethod);
+        log.warn(ip);
+        log.warn(classMethod);
+        log.warn(args);
+        log.warn(resp);
+        log.warn(StrPool.LOG_LINE);
+    }
+
+    private void error() {
+        log.error(StrPool.LOG_LINE);
+        log.error(url);
+        log.error(httpMethod);
+        log.error(ip);
+        log.error(classMethod);
+        log.error(args);
+        log.error(resp);
+        log.error(StrPool.LOG_LINE);
+    }
 }