Przeglądaj źródła

获取配置接口调整

Long 1 tydzień temu
rodzic
commit
caf745f327

+ 11 - 1
fs-admin/src/main/java/com/fs/web/controller/system/SysConfigController.java

@@ -12,6 +12,7 @@ import com.fs.common.core.redis.RedisCache;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.framework.datasource.TenantDataSourceContextHelper;
 import com.fs.system.domain.SysConfig;
 import com.fs.system.domain.SysConfig;
 import com.fs.system.service.ISysConfigService;
 import com.fs.system.service.ISysConfigService;
 import com.fs.tenant.config.service.TenantSysConfigService;
 import com.fs.tenant.config.service.TenantSysConfigService;
@@ -34,6 +35,8 @@ public class SysConfigController extends BaseController {
     private TenantSysConfigService tenantSysConfigService;
     private TenantSysConfigService tenantSysConfigService;
     @Autowired
     @Autowired
     public RedisCache redisCache;
     public RedisCache redisCache;
+    @Autowired
+    private TenantDataSourceContextHelper tenantContextHelper;
 
 
     /**
     /**
      * 获取参数配置列表
      * 获取参数配置列表
@@ -129,7 +132,14 @@ public class SysConfigController extends BaseController {
     @GetMapping(value = "/getConfigByKey/{configKey:.+}")
     @GetMapping(value = "/getConfigByKey/{configKey:.+}")
     public AjaxResult getConfigByKey(@PathVariable String configKey,
     public AjaxResult getConfigByKey(@PathVariable String configKey,
                                      @RequestParam(value = "tenantId", required = false) Long tenantId) {
                                      @RequestParam(value = "tenantId", required = false) Long tenantId) {
-        return AjaxResult.success(tenantSysConfigService.getConfigByKey(tenantId, configKey));
+        SysConfig configByKey;
+        if (tenantId == null) {
+            configByKey = tenantSysConfigService.getConfigByKey(configKey);
+        } else {
+            configByKey = tenantContextHelper.executeInTenant(tenantId, () -> tenantSysConfigService.getConfigByKey(configKey));
+        }
+
+        return AjaxResult.success(configByKey);
     }
     }
 
 
     /**
     /**

+ 1 - 1
fs-service/src/main/java/com/fs/tenant/config/service/TenantSysConfigService.java

@@ -10,7 +10,7 @@ public interface TenantSysConfigService {
     /**
     /**
      * 按 configKey 查询配置。tenantId 为空查主库,否则查对应租户库。
      * 按 configKey 查询配置。tenantId 为空查主库,否则查对应租户库。
      */
      */
-    SysConfig getConfigByKey(Long tenantId, String configKey);
+    SysConfig getConfigByKey(String configKey);
 
 
     /**
     /**
      * 按 configKey 新增或更新。config.tenantId 为空则操作主库,否则操作对应租户库。
      * 按 configKey 新增或更新。config.tenantId 为空则操作主库,否则操作对应租户库。

+ 5 - 9
fs-service/src/main/java/com/fs/tenant/config/service/impl/TenantSysConfigServiceImpl.java

@@ -30,15 +30,11 @@ public class TenantSysConfigServiceImpl implements TenantSysConfigService {
     private RedisCache redisCache;
     private RedisCache redisCache;
 
 
     @Override
     @Override
-    public SysConfig getConfigByKey(Long tenantId, String configKey) {
-//        if (StringUtils.isEmpty(configKey)) {
-//            throw new ServiceException("参数键名不能为空");
-//        }
-//        if (tenantId == null) {
-//            return contextHelper.executeInMaster(() -> configCacheDelegate.loadFromDb(configKey));
-//        }
-//        return contextHelper.executeInTenant(tenantId, () -> configCacheDelegate.loadFromDb(configKey));
-        throw new CustomException("Not implemented");
+    public SysConfig getConfigByKey(String configKey) {
+        if (StringUtils.isEmpty(configKey)) {
+            throw new ServiceException("参数键名不能为空");
+        }
+        return configCacheDelegate.loadFromDb(configKey);
     }
     }
 
 
     @Override
     @Override