Переглянути джерело

[chg] 批量上传uploads如果有失败的删除之前已经上传的文件,verification优化

wcz 5 роки тому
батько
коміт
6ab27509b9

+ 24 - 8
lift-business-service/src/main/java/cn/com/ty/lift/business/common/CommonController.java

@@ -3,7 +3,6 @@ package cn.com.ty.lift.business.common;
 import cn.com.ty.lift.business.framework.conf.SystemConfiguration;
 import cn.com.ty.lift.business.framework.util.MessageUtils;
 import cn.com.ty.lift.business.library.dao.entity.LiftBrand;
-import cn.com.ty.lift.common.aliservice.aliyunoss.AliyunOSS;
 import cn.com.ty.lift.common.constants.RedisConstants;
 import cn.com.ty.lift.common.model.AreaCode;
 import cn.com.ty.lift.common.utils.StrPool;
@@ -23,7 +22,9 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author bieao
@@ -81,17 +82,33 @@ public class CommonController {
     public RestResponse uploads(@RequestParam("files") MultipartFile[] files){
         Verify.notTrue(null == files || files.length == 0,Verify.Upload.fileDataMissing);
         try {
-            List<String> urls = new ArrayList<>();
+            Map<String, MultipartFile> fileMap = new HashMap<>();
+            //1 先解析文件格式
             for (MultipartFile file : files) {
                 String fileName = handleFile(file);
                 if(StrUtil.isEmpty(fileName)){
                     return RestResponse.fail(Verify.Upload.fileFormatNotSupport);
                 }
-                AliyunOSS aliyunOSS = systemConfiguration.build();
-                String url = aliyunOSS.putObject(fileName, file.getBytes());
+                fileMap.put(fileName, file);
+            }
+            //2 批量上传
+            List<String> urls = new ArrayList<>();
+            List<String> success = new ArrayList<>();
+            for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()){
+                String url = systemConfiguration.build().putObject(entry.getKey(), entry.getValue().getBytes());
                 log.info("上传文件,文件URL: {}",url);
-                Verify.notNull(url);
-                urls.add(url);
+                if(null == url){
+                    // 删除已经成功上传的文件
+                    if(!success.isEmpty()){
+                        for (String filename : success) {
+                            systemConfiguration.build().deleteObject(filename);
+                        }
+                    }
+                    return RestResponse.fail(Verify.Upload.fileUploadFail);
+                }else{
+                    success.add(entry.getKey());
+                    urls.add(url);
+                }
             }
             return RestResponse.success(urls);
         }catch (Exception e){
@@ -114,8 +131,7 @@ public class CommonController {
             if(StrUtil.isEmpty(fileName)){
                 return RestResponse.fail(Verify.Upload.fileFormatNotSupport);
             }
-            AliyunOSS aliyunOSS = systemConfiguration.build();
-            String url = aliyunOSS.putObject(fileName, file.getBytes());
+            String url = systemConfiguration.build().putObject(fileName, file.getBytes());
             log.info("上传文件,文件URL: {}",url);
             return RestResponse.success(url);
         }catch (Exception e){

+ 0 - 50
lift-business-service/src/main/java/cn/com/ty/lift/business/framework/aspect/VerifyMethodInterceptor.java

@@ -1,50 +0,0 @@
-package cn.com.ty.lift.business.framework.aspect;
-
-import cn.com.ty.lift.common.verify.Ver;
-import cn.com.ty.lift.common.verify.Verification;
-import cn.com.ty.lift.common.verify.Verifier;
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-
-/**
- * the {@link MethodInterceptor} to verify the parameters
- *
- * @author wcz
- * @since 2020/2/25
- */
-public class VerifyMethodInterceptor implements MethodInterceptor {
-    @Override
-    public Object invoke(MethodInvocation invocation) throws Throwable {
-        //get the method
-        Method method = invocation.getMethod();
-        //check whether the method is present with verifier annotation.
-        if (!method.isAnnotationPresent(Verifier.class)) {
-            return invocation.proceed();
-        }
-
-        Object[] arguments = invocation.getArguments();
-        //just return if there is not any argument.
-        if (arguments.length == 0) {
-            return invocation.proceed();
-        }
-        Object object = null;
-        //by default, verify the first arg present with Ver,
-        Parameter[] parameters = method.getParameters();
-        for (int i = 0; i < parameters.length; i++) {
-            if(parameters[i].isAnnotationPresent(Ver.class)){
-                object = arguments[i];
-                break;
-            }
-        }
-        if (null == object) {
-            return invocation.proceed();
-        }
-        //get the verifier
-        Verifier verifier = method.getDeclaredAnnotation(Verifier.class);
-        Verification.getInstance().action(object, verifier.fields());
-        return invocation.proceed();
-    }
-}

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

@@ -1,10 +1,10 @@
 package cn.com.ty.lift.business.framework.conf;
 
-import cn.com.ty.lift.business.framework.aspect.VerifyMethodInterceptor;
 import cn.com.ty.lift.common.aliservice.aliyunoss.AliyunOSS;
 import cn.com.ty.lift.common.export.ExportUtils;
 import cn.com.ty.lift.common.sql.SqlAnalysisInterceptor;
 import cn.com.ty.lift.common.sql.SqlIllegalInterceptor;
+import cn.com.ty.lift.common.verify.Verification;
 import cn.com.ty.lift.common.verify.Verifier;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.util.StrUtil;
@@ -26,6 +26,8 @@ import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import net.sf.jsqlparser.expression.Expression;
 import net.sf.jsqlparser.expression.LongValue;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.springframework.aop.support.DefaultPointcutAdvisor;
 import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
@@ -144,7 +146,13 @@ public class SystemConfiguration {
     public DefaultPointcutAdvisor defaultPointcutAdvisor(){
         DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
         advisor.setPointcut(new AnnotationMatchingPointcut(RestController.class, Verifier.class));
-        advisor.setAdvice(new VerifyMethodInterceptor());
+        advisor.setAdvice(new MethodInterceptor() {
+            @Override
+            public Object invoke(MethodInvocation invocation) throws Throwable {
+                Verification.getInstance().action(invocation.getMethod(), invocation.getArguments());
+                return invocation.proceed();
+            }
+        });
         advisor.setOrder(2);
         return advisor;
     }

+ 0 - 6
lift-common/pom.xml

@@ -103,12 +103,6 @@
             <!--<artifactId>hibernate-validator</artifactId>-->
             <!--<version>6.0.16.Final</version>-->
         <!--</dependency>-->
-        <!-- https://mvnrepository.com/artifact/com.innowhere/relproxy -->
-        <!--<dependency>-->
-            <!--<groupId>com.innowhere</groupId>-->
-            <!--<artifactId>relproxy</artifactId>-->
-            <!--<version>0.8.6</version>-->
-        <!--</dependency>-->
 
     </dependencies>
 

+ 5 - 1
lift-common/src/main/java/cn.com.ty.lift.common/aliservice/aliyunoss/AliyunOSS.java

@@ -33,6 +33,10 @@ public class AliyunOSS {
     //OSSClient实例
     private OSS ossClient;
 
+    private static class Builder{
+        private static OSSClientBuilder ossClientBuilder = new OSSClientBuilder();
+    }
+
     /**
      * 无参构造,初始化oss
      */
@@ -66,7 +70,7 @@ public class AliyunOSS {
      */
     private void init() {
         if (null == ossClient) {
-            ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+            ossClient = Builder.ossClientBuilder.build(endpoint, accessKeyId, accessKeySecret);
         }
     }
 

+ 54 - 46
lift-common/src/main/java/cn.com.ty.lift.common/sql/SqlIllegalInterceptor.java

@@ -70,18 +70,21 @@ public class SqlIllegalInterceptor implements Interceptor {
     /**
      * cache the legal sql result.
      */
-    private final Set<String>                   legalSqlCacheSet  = new HashSet<>();
+    private final Set<String> legalSqlCacheSet  = new HashSet<>();
     /**
      * cache the index info exist on the column.
      */
-    private final Set<String>                   indexInfoCacheSet = new CopyOnWriteArraySet<>();
+    private final Set<String> indexInfoCacheSet = new CopyOnWriteArraySet<>();
     /**
      * cache the table had load index info from the connection.
      */
-    private final Set<String>                   tableCacheSet     = new HashSet<>();
+    private final Set<String> tableCacheSet     = new HashSet<>();
     @Getter
     @Setter
-    private       boolean                       devMode           = true;
+    private       boolean     devMode           = true;
+    @Getter
+    @Setter
+    private       boolean     sqlWrite          = false;
     @Override
     public Object intercept(Invocation invocation) throws Throwable {
         StatementHandler statementHandler = SqlUtils.realTarget(invocation.getTarget());
@@ -93,7 +96,7 @@ public class SqlIllegalInterceptor implements Interceptor {
         }
         String originalSql = statementHandler.getBoundSql().getSql();
         log.info("Verifying SQL ID: {}", mappedStatement.getId());
-        if (!devMode) {
+        if (sqlWrite) {
             log.info("Verifying SQL:");
             log.info(originalSql);
         }
@@ -142,9 +145,13 @@ public class SqlIllegalInterceptor implements Interceptor {
     @Override
     public void setProperties(Properties prop) {
         String devMode = prop.getProperty("devMode");
+        String sqlWrite = prop.getProperty("sqlWrite");
         if (SqlUtils.isBoolean(devMode)) {
             this.devMode = Boolean.valueOf(devMode);
         }
+        if (SqlUtils.isBoolean(devMode)) {
+            this.sqlWrite = Boolean.valueOf(sqlWrite);
+        }
     }
 
     /**
@@ -294,51 +301,52 @@ public class SqlIllegalInterceptor implements Interceptor {
          * @param indexInfo include catalog & schema & tableName & columnName to Specify a unique index.
          */
         private int columnNoUseIndex(IndexInfo indexInfo) {
-            String indexCache = indexInfo.fullyQualifiedColumn();
+            String fullyQualifiedColumn = indexInfo.fullyQualifiedColumn();
             //if the column has set. and the cache contains the column.
-            if (indexInfo.fullyColumn() && indexInfoCacheSet.contains(indexCache)) {
+            if (indexInfo.fullyColumn() && indexInfoCacheSet.contains(fullyQualifiedColumn)) {
                 return 1;
             }
             //if the table has set. and the cache do not contains the table.
-            String tableCache = indexInfo.fullyQualifiedTable();
+            String fullyQualifiedTable = indexInfo.fullyQualifiedTable();
             // if new create index on the column. must to reload index,
-            if (indexInfo.fullyTable() && !tableCacheSet.contains(tableCache)) {
-                //get index info from the connection.
-                try (ResultSet resultSet = databaseMetaData.getIndexInfo(indexInfo.catalog, indexInfo.schema, indexInfo.tableName, false, true)){
-                    int indexCount = 0;
-                    while (resultSet.next()) {
-                        //索引中的列序列号等于1,才有效, index: 8, label: ORDINAL_POSITION
-                        if (resultSet.getShort("ORDINAL_POSITION") == 1) {
-                            //在索引中的列名列 index:9, label: COLUMN_NAME
-                            IndexInfo index = IndexInfo.newInstance();
-                            //TABLE_CAT
-                            index.setCatalog(indexInfo.catalog);
-                            //TABLE_SCHEM
-                            index.setSchema(indexInfo.schema);
-                            //TABLE_NAME
-                            index.setTableName(indexInfo.tableName);
-                            //COLUMN_NAME
-                            index.setColumnName(resultSet.getString("COLUMN_NAME"));
-                            indexInfoCacheSet.add(index.fullyQualifiedColumn());
-                            indexCount++;
-                            //cache table, no reload index every time.
-                            tableCacheSet.add(index.fullyQualifiedTable());
-                        }
-                    }
-                    if (indexCount > 6) {
-                        addMessage("Too many indexes (%s > 6) use on table (%s).", indexCount, tableCache);
+            if (indexInfo.fullyTable() && tableCacheSet.contains(fullyQualifiedTable)) {
+                addMessage("Index not use on %s. Example sql: CREATE [UNIQUE|CLUSTERED] INDEX idx_%s ON %s(%s)", fullyQualifiedColumn, indexInfo.columnName, indexInfo.tableName, indexInfo.columnName);
+                return 0;
+            }
+            //get index info from the connection.
+            try (ResultSet resultSet = databaseMetaData.getIndexInfo(indexInfo.catalog, indexInfo.schema, indexInfo.tableName, false, true)) {
+                int indexCount = 0;
+                while (resultSet.next()) {
+                    //索引中的列序列号等于1,才有效, index: 8, label: ORDINAL_POSITION
+                    if (resultSet.getShort("ORDINAL_POSITION") == 1) {
+                        //在索引中的列名列 index:9, label: COLUMN_NAME
+                        IndexInfo index = IndexInfo.newInstance();
+                        //TABLE_CAT
+                        index.setCatalog(indexInfo.catalog);
+                        //TABLE_SCHEM
+                        index.setSchema(indexInfo.schema);
+                        //TABLE_NAME
+                        index.setTableName(indexInfo.tableName);
+                        //COLUMN_NAME
+                        index.setColumnName(resultSet.getString("COLUMN_NAME"));
+                        indexInfoCacheSet.add(index.fullyQualifiedColumn());
+                        indexCount++;
+                        //cache table, no reload index every time.
+                        tableCacheSet.add(index.fullyQualifiedTable());
                     }
-                    log.info("Cache index: {}, table: {}", indexInfoCacheSet.size(), tableCacheSet.size());
-                } catch (SQLException e) {
-                    log.error("get index info from DatabaseMetaData fail.");
                 }
+                if (indexCount > 6) {
+                    addMessage("Too many indexes (%s > 6) use on table (%s).", indexCount, fullyQualifiedTable);
+                }
+                log.info("Cache index: {}, table: {}", indexInfoCacheSet.size(), tableCacheSet.size());
+            } catch (SQLException e) {
+                log.error("get index info from DatabaseMetaData fail.");
             }
-            boolean useIndex = indexInfoCacheSet.contains(indexCache);
-            if (!useIndex) {
-                addMessage("Index not use on %s. Example sql: CREATE [UNIQUE|CLUSTERED] INDEX idx_%s ON %s(%s)", indexCache, indexInfo.columnName, indexInfo.tableName, indexInfo.columnName);
-                return 0;
+            if (indexInfo.fullyColumn() && indexInfoCacheSet.contains(fullyQualifiedColumn)) {
+                return 1;
             }
-            return 1;
+            addMessage("Index not use on %s. Example sql: CREATE [UNIQUE|CLUSTERED] INDEX idx_%s ON %s(%s)", fullyQualifiedColumn, indexInfo.columnName, indexInfo.tableName, indexInfo.columnName);
+            return 0;
         }
 
         /**
@@ -736,23 +744,23 @@ public class SqlIllegalInterceptor implements Interceptor {
         private String tableName;
         private String columnName;
 
-        public static IndexInfo newInstance(){
+        private static IndexInfo newInstance() {
             return new IndexInfo();
         }
 
-        public boolean fullyColumn() {
+        private boolean fullyColumn() {
             return SqlUtils.notNull(getTableName(), getColumnName());
         }
 
-        public boolean fullyTable() {
+        private boolean fullyTable() {
             return SqlUtils.notNull(getTableName());
         }
 
-        public String fullyQualifiedColumn() {
+        private String fullyQualifiedColumn() {
             return fullyColumn() ? String.format("%s.%s.%s.%s", fixCatalog(), fixSchema(), getTableName(), getColumnName()) : null;
         }
 
-        public String fullyQualifiedTable() {
+        private String fullyQualifiedTable() {
             return fullyTable() ? String.format("%s.%s.%s", fixCatalog(), fixSchema(), getTableName()) : null;
         }
 

Різницю між файлами не показано, бо вона завелика
+ 124 - 114
lift-common/src/main/java/cn.com.ty.lift.common/verify/Verification.java


+ 0 - 50
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/common/VerifyMethodInterceptor.java

@@ -1,50 +0,0 @@
-package cn.com.ty.lift.enterprise.common;
-
-import cn.com.ty.lift.common.verify.Ver;
-import cn.com.ty.lift.common.verify.Verification;
-import cn.com.ty.lift.common.verify.Verifier;
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-
-/**
- * the {@link MethodInterceptor} to verify the parameters
- *
- * @author wcz
- * @since 2020/2/25
- */
-public class VerifyMethodInterceptor implements MethodInterceptor {
-    @Override
-    public Object invoke(MethodInvocation invocation) throws Throwable {
-        //get the method
-        Method method = invocation.getMethod();
-        //check whether the method is present with verifier annotation.
-        if (!method.isAnnotationPresent(Verifier.class)) {
-            return invocation.proceed();
-        }
-
-        Object[] arguments = invocation.getArguments();
-        //just return if there is not any argument.
-        if (arguments.length == 0) {
-            return invocation.proceed();
-        }
-        Object object = null;
-        //by default, verify the first arg present with Ver,
-        Parameter[] parameters = method.getParameters();
-        for (int i = 0; i < parameters.length; i++) {
-            if(parameters[i].isAnnotationPresent(Ver.class)){
-                object = arguments[i];
-                break;
-            }
-        }
-        if (null == object) {
-            return invocation.proceed();
-        }
-        //get the verifier
-        Verifier verifier = method.getDeclaredAnnotation(Verifier.class);
-        Verification.getInstance().action(object, verifier.fields());
-        return invocation.proceed();
-    }
-}

+ 10 - 2
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/config/SystemConfiguration.java

@@ -3,8 +3,8 @@ package cn.com.ty.lift.enterprise.config;
 import cn.com.ty.lift.common.aliservice.aliyunoss.AliyunOSS;
 import cn.com.ty.lift.common.export.ExportUtils;
 import cn.com.ty.lift.common.sql.SqlAnalysisInterceptor;
+import cn.com.ty.lift.common.verify.Verification;
 import cn.com.ty.lift.common.verify.Verifier;
-import cn.com.ty.lift.enterprise.common.VerifyMethodInterceptor;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
@@ -17,6 +17,8 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
 import org.springframework.aop.support.DefaultPointcutAdvisor;
 import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -121,7 +123,13 @@ public class SystemConfiguration {
     public DefaultPointcutAdvisor defaultPointcutAdvisor(){
         DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
         advisor.setPointcut(new AnnotationMatchingPointcut(RestController.class, Verifier.class));
-        advisor.setAdvice(new VerifyMethodInterceptor());
+        advisor.setAdvice(new MethodInterceptor() {
+            @Override
+            public Object invoke(MethodInvocation invocation) throws Throwable {
+                Verification.getInstance().action(invocation.getMethod(), invocation.getArguments());
+                return invocation.proceed();
+            }
+        });
         advisor.setOrder(2);
         return advisor;
     }

+ 10 - 1
lift-quan-service/src/main/java/cn/com/ty/lift/quan/config/SystemConfiguration.java

@@ -2,6 +2,7 @@ package cn.com.ty.lift.quan.config;
 
 import cn.com.ty.lift.common.aliservice.aliyunoss.AliyunOSS;
 import cn.com.ty.lift.common.sql.SqlAnalysisInterceptor;
+import cn.com.ty.lift.common.verify.Verification;
 import cn.com.ty.lift.common.verify.Verifier;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.util.StrUtil;
@@ -14,6 +15,8 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
 import lombok.Data;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
 import org.springframework.aop.support.DefaultPointcutAdvisor;
 import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -100,7 +103,13 @@ public class SystemConfiguration {
     public DefaultPointcutAdvisor defaultPointcutAdvisor(){
         DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
         advisor.setPointcut(new AnnotationMatchingPointcut(RestController.class, Verifier.class));
-        advisor.setAdvice(new VerifyMethodInterceptor());
+        advisor.setAdvice(new MethodInterceptor() {
+            @Override
+            public Object invoke(MethodInvocation invocation) throws Throwable {
+                Verification.getInstance().action(invocation.getMethod(), invocation.getArguments());
+                return invocation.proceed();
+            }
+        });
         advisor.setOrder(2);
         return advisor;
     }

+ 0 - 50
lift-quan-service/src/main/java/cn/com/ty/lift/quan/config/VerifyMethodInterceptor.java

@@ -1,50 +0,0 @@
-package cn.com.ty.lift.quan.config;
-
-import cn.com.ty.lift.common.verify.Ver;
-import cn.com.ty.lift.common.verify.Verification;
-import cn.com.ty.lift.common.verify.Verifier;
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-
-/**
- * the {@link MethodInterceptor} to verify the parameters
- *
- * @author wcz
- * @since 2020/2/25
- */
-public class VerifyMethodInterceptor implements MethodInterceptor {
-    @Override
-    public Object invoke(MethodInvocation invocation) throws Throwable {
-        //get the method
-        Method method = invocation.getMethod();
-        //check whether the method is present with verifier annotation.
-        if (!method.isAnnotationPresent(Verifier.class)) {
-            return invocation.proceed();
-        }
-
-        Object[] arguments = invocation.getArguments();
-        //just return if there is not any argument.
-        if (arguments.length == 0) {
-            return invocation.proceed();
-        }
-        Object object = null;
-        //by default, verify the first arg present with Ver
-        Parameter[] parameters = method.getParameters();
-        for (int i = 0; i < parameters.length; i++) {
-            if(parameters[i].isAnnotationPresent(Ver.class)){
-                object = arguments[i];
-                break;
-            }
-        }
-        if (null == object) {
-            return invocation.proceed();
-        }
-        //get the verifier
-        Verifier verifier = method.getDeclaredAnnotation(Verifier.class);
-        Verification.getInstance().action(object, verifier.fields());
-        return invocation.proceed();
-    }
-}

+ 10 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/config/SystemConfiguration.java

@@ -2,6 +2,7 @@ package cn.com.ty.lift.system.config;
 
 import cn.com.ty.lift.common.aliservice.aliyunoss.AliyunOSS;
 import cn.com.ty.lift.common.sql.SqlAnalysisInterceptor;
+import cn.com.ty.lift.common.verify.Verification;
 import cn.com.ty.lift.common.verify.Verifier;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.util.StrUtil;
@@ -14,6 +15,8 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
 import lombok.Data;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
 import org.springframework.aop.support.DefaultPointcutAdvisor;
 import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -101,7 +104,13 @@ public class SystemConfiguration {
     public DefaultPointcutAdvisor defaultPointcutAdvisor(){
         DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
         advisor.setPointcut(new AnnotationMatchingPointcut(RestController.class, Verifier.class));
-        advisor.setAdvice(new VerifyMethodInterceptor());
+        advisor.setAdvice(new MethodInterceptor() {
+            @Override
+            public Object invoke(MethodInvocation invocation) throws Throwable {
+                Verification.getInstance().action(invocation.getMethod(), invocation.getArguments());
+                return invocation.proceed();
+            }
+        });
         advisor.setOrder(2);
         return advisor;
     }

+ 0 - 50
lift-system-service/src/main/java/cn/com/ty/lift/system/config/VerifyMethodInterceptor.java

@@ -1,50 +0,0 @@
-package cn.com.ty.lift.system.config;
-
-import cn.com.ty.lift.common.verify.Ver;
-import cn.com.ty.lift.common.verify.Verification;
-import cn.com.ty.lift.common.verify.Verifier;
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-
-/**
- * the {@link MethodInterceptor} to verify the parameters
- *
- * @author wcz
- * @since 2020/2/25
- */
-public class VerifyMethodInterceptor implements MethodInterceptor {
-    @Override
-    public Object invoke(MethodInvocation invocation) throws Throwable {
-        //get the method
-        Method method = invocation.getMethod();
-        //check whether the method is present with verifier annotation.
-        if (!method.isAnnotationPresent(Verifier.class)) {
-            return invocation.proceed();
-        }
-
-        Object[] arguments = invocation.getArguments();
-        //just return if there is not any argument.
-        if (arguments.length == 0) {
-            return invocation.proceed();
-        }
-        Object object = null;
-        //by default, verify the first arg present with Ver
-        Parameter[] parameters = method.getParameters();
-        for (int i = 0; i < parameters.length; i++) {
-            if(parameters[i].isAnnotationPresent(Ver.class)){
-                object = arguments[i];
-                break;
-            }
-        }
-        if (null == object) {
-            return invocation.proceed();
-        }
-        //get the verifier
-        Verifier verifier = method.getDeclaredAnnotation(Verifier.class);
-        Verification.getInstance().action(object, verifier.fields());
-        return invocation.proceed();
-    }
-}