woody 3 mēneši atpakaļ
vecāks
revīzija
da03c1c562

+ 8 - 2
framework-database/src/main/java/com/chelvc/framework/database/interceptor/DynamicInvokeInterceptor.java

@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
 import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.chelvc.framework.common.util.ObjectUtils;
+import com.chelvc.framework.database.config.DatabaseProperties;
 import com.chelvc.framework.database.context.DatabaseContextHolder;
 import com.chelvc.framework.database.context.TableFieldContext;
 import com.chelvc.framework.database.entity.Creatable;
@@ -20,6 +21,7 @@ import com.chelvc.framework.database.entity.Deletable;
 import com.chelvc.framework.database.entity.Environmental;
 import com.chelvc.framework.database.entity.Updatable;
 import com.google.common.collect.Lists;
+import lombok.RequiredArgsConstructor;
 import net.sf.jsqlparser.JSQLParserException;
 import net.sf.jsqlparser.Model;
 import net.sf.jsqlparser.expression.Alias;
@@ -74,6 +76,7 @@ import org.apache.ibatis.plugin.Signature;
 import org.apache.ibatis.reflection.MetaObject;
 import org.apache.ibatis.reflection.SystemMetaObject;
 import org.apache.ibatis.type.TypeHandler;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 /**
@@ -83,8 +86,11 @@ import org.springframework.stereotype.Component;
  * @date 2024/1/30
  */
 @Component
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
 @Intercepts(@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}))
 public class DynamicInvokeInterceptor implements Interceptor {
+    private final DatabaseProperties properties;
+
     /**
      * 判断字段别名与指定别名是否相同
      *
@@ -829,7 +835,7 @@ public class DynamicInvokeInterceptor implements Interceptor {
     private boolean initializeSensitiveParameter(BoundSql bound, Table table, Column column, JdbcParameter parameter,
                                                  Expression condition, Consumer<Expression> changing) {
         // 针对敏感字段数据混合模式下参数精确匹配场景,将自动添加混合查询条件
-        if (!DatabaseContextHolder.getDatabaseCipherHandler().isMixed() || !(condition instanceof EqualsTo
+        if (!this.properties.getCrypto().isMixed() || !(condition instanceof EqualsTo
                 || condition instanceof NotEqualsTo || condition instanceof InExpression)) {
             return false;
         }
@@ -844,7 +850,7 @@ public class DynamicInvokeInterceptor implements Interceptor {
         Object value = context.handleWriteValue(this.getParameterValue(bound, parameter));
         if (!(value instanceof String)) {
             return false;
-        } else if (!DatabaseContextHolder.getDatabaseCipherHandler().isWritable()) {
+        } else if (!this.properties.getCrypto().isWritable()) {
             // 如果未开启加密写入功能,则添加密文查询条件
             value = DatabaseContextHolder.getDatabaseCipherHandler().encrypt((String) value, true);
         }