Browse Source

修改 租户和influx组件模块

guoenzhou 2 years ago
parent
commit
9c879357bb

+ 4 - 4
usky-common/usky-common-core/src/main/java/com/usky/common/influx/config/InfluxDbConfig.java

@@ -1,6 +1,5 @@
 package com.usky.common.influx.config;
 
-import com.usky.common.core.util.StringUtils;
 import com.usky.common.influx.core.InfluxDbUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -36,10 +35,11 @@ public class InfluxDbConfig {
     public InfluxDbUtils influxDbUtils() {
         log.info("influx config info:{},{}",influxDBUrl,database);
         if(influxDBUrl!= null && !influxDBUrl.equals("''") ) {
-            log.warn("influx 组件启动");
+            log.debug("influx 组件启动");
             return new InfluxDbUtils(userName, password, influxDBUrl, database, "");
+        } else {
+            log.warn("influx 配置缺失,未启动");
+            return new InfluxDbUtils();
         }
-        log.warn("influx 配置缺失,未启动");
-        return null;
     }
 }

+ 6 - 5
usky-common/usky-common-core/src/main/java/com/usky/common/influx/core/InfluxDbUtils.java

@@ -1,12 +1,14 @@
 package com.usky.common.influx.core;
 
 import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
 import org.influxdb.InfluxDB;
 import org.influxdb.InfluxDBFactory;
 import org.influxdb.dto.Query;
 import org.influxdb.dto.QueryResult;
 
 @Data
+@Slf4j
 public class InfluxDbUtils {
 
     private String userName;
@@ -16,11 +18,11 @@ public class InfluxDbUtils {
     private String retentionPolicy;
     // InfluxDB实例
     private InfluxDB influxDB;
-
     // 数据保存策略
     public static String policyNamePix = "logRetentionPolicy_";
 
-
+    public InfluxDbUtils() {
+    }
 
     public InfluxDbUtils(String userName, String password, String url, String database,
                          String retentionPolicy) {
@@ -42,11 +44,10 @@ public class InfluxDbUtils {
             influxDB = InfluxDBFactory.connect(url, userName, password);
         }
         try {
-//            createDB(database);
+//          createDB(database);
             influxDB.setDatabase(database);
         } catch (Exception e) {
-            e.printStackTrace();
-//          log.error("create influx db failed, error: {}", e.getMessage());
+          log.error("create influx db failed, error: {}", e.getMessage());
         } finally {
             influxDB.setRetentionPolicy(retentionPolicy);
         }

+ 1 - 2
usky-common/usky-common-tenant/src/main/java/com/usky/common/tenant/config/TenantAutoConfiguration.java

@@ -16,7 +16,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 @Configuration
-@ConditionalOnProperty(prefix = "tenant", value = "enable", matchIfMissing = true) // 允许使用 tenant.enable=treu 禁用多租户
+@ConditionalOnProperty(prefix = "spring.tenant", value = "enable", matchIfMissing = true) // 允许使用 tenant.enable=true 禁用多租户
 @EnableConfigurationProperties(TenantProperties.class)
 public class TenantAutoConfiguration {
 
@@ -41,7 +41,6 @@ public class TenantAutoConfiguration {
         TenantLineInnerInterceptor inner = new TenantLineInnerInterceptor();
         //多租户插件
         inner.setTenantLineHandler(new TenantDatabaseHandler(properties));
-
         // 添加到 interceptor 中
         // 需要加在首个,主要是为了在分页插件前面。这个是 MyBatis Plus 的规定
         List<InnerInterceptor> inners = new ArrayList<>(interceptor.getInterceptors());

+ 1 - 2
usky-common/usky-common-tenant/src/main/java/com/usky/common/tenant/config/TenantProperties.java

@@ -7,10 +7,9 @@ import java.util.Set;
 
 /**
  * 多租户配置
- *
  * @author yq
  */
-@ConfigurationProperties(prefix = "tenant")
+@ConfigurationProperties(prefix = "spring.tenant")
 @Data
 public class TenantProperties {
 

+ 3 - 0
usky-common/usky-common-tenant/src/main/java/com/usky/common/tenant/core/web/TenantContextWebFilter.java

@@ -2,6 +2,7 @@ package com.usky.common.tenant.core.web;
 
 
 import com.usky.common.tenant.core.context.TenantContextHolder;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.filter.OncePerRequestFilter;
 
@@ -18,6 +19,7 @@ import java.io.IOException;
  * 1.放到header的tentant_id有被篡改的风险,考虑到降低组件依赖耦合,该行为应该有其它组件来预防实现,它的主要职责进行横切拼接SQL
  * @author yq
  */
+@Slf4j
 public class TenantContextWebFilter extends OncePerRequestFilter {
 
     /**
@@ -30,6 +32,7 @@ public class TenantContextWebFilter extends OncePerRequestFilter {
             throws ServletException, IOException {
         // 设置
         Integer tenantId = getTenantId(request);
+        log.debug("tenantId value:{}",tenantId);
         if (tenantId != null) {
             TenantContextHolder.setTenantId(tenantId);
         }