Ver Fonte

1、调整修改租户配置信息

yys há 1 mês atrás
pai
commit
373db3ec3b

+ 47 - 0
fs-admin/src/main/java/com/fs/tenant/TenantInfoController.java

@@ -16,8 +16,11 @@ import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.company.domain.CompanyMenu;
 import com.fs.framework.datasource.DynamicDataSourceContextHolder;
 import com.fs.framework.datasource.TenantDataSourceManager;
+import com.fs.system.domain.SysConfig;
+import com.fs.system.service.ISysConfigService;
 import com.fs.tenant.domain.TenantInfo;
 import com.fs.tenant.dto.MenuDto;
+import com.fs.tenant.dto.SysConfigDto;
 import com.fs.tenant.mapper.TenantInfoMapper;
 import com.fs.tenant.service.TenantInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +46,9 @@ public class TenantInfoController extends BaseController
     @Autowired
     private TenantInfoService tenantInfoService;
 
+    @Autowired
+    private ISysConfigService configService;
+
     @Autowired
     private TenantInfoMapper tenantInfoMapper;
 
@@ -179,6 +185,47 @@ public class TenantInfoController extends BaseController
         return tenantInfoService.menuEdit(selected, unSelected, menuDto.getFlag(),null,addCompanyMenu);
     }
 
+
+    /**
+     * 租户配置修改
+     */
+    @PreAuthorize("@ss.hasPermi('tenant:config:edit')")
+    @PostMapping("/config/edit")
+    public R configEdit(@Validated @RequestBody SysConfigDto config)
+    {
+        TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(config.getId());
+        if (tenantInfo.getStatus() == 2) {
+            throw new CustomException("租户初始化中");
+        }
+
+        tenantDataSourceManager.switchTenant(tenantInfo);
+        //修复只能更新的BUG
+        if (null != config.getConfigId()) {
+            return R.ok().put("data", configService.updateConfig(config));
+        } else {
+           return R.ok().put("data", configService.insertConfig(config));
+        }
+    }
+
+    /**
+     * 根据租户id获取指定配置文件
+     *
+     * @param configKey
+     * @param id
+     * @return
+     */
+    @GetMapping(value = "/getConfigByKey/{configKey}")
+    public AjaxResult getConfigByKey(@PathVariable String configKey,String id) {
+        TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(id);
+        if (tenantInfo.getStatus() == 2) {
+            throw new CustomException("租户初始化中");
+        }
+
+        tenantDataSourceManager.switchTenant(tenantInfo);
+        SysConfig config = configService.selectConfigByConfigKey(configKey);
+        return AjaxResult.success(config);
+    }
+
     /**
      * 获取需要更新的后台菜单
      */

+ 2 - 2
fs-qw-api-msg/src/main/resources/application.yml

@@ -3,8 +3,8 @@ server:
 # Spring配置
 spring:
   profiles:
-#    active: dev
+    active: dev
 #    active: druid-jzzx
 #    active: druid-hdt
 #    active: druid-sxjz
-    active: druid-hzyy-test
+#    active: druid-hzyy-test

+ 12 - 0
fs-service/src/main/java/com/fs/tenant/dto/SysConfigDto.java

@@ -0,0 +1,12 @@
+package com.fs.tenant.dto;
+
+import com.fs.system.domain.SysConfig;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SysConfigDto extends SysConfig {
+    private String id; // 租户ID
+
+}

+ 1 - 1
fs-service/src/main/resources/application-dev.yml

@@ -76,4 +76,4 @@ spring:
                         merge-sql: true
                     wall:
                         config:
-                            multi-statement-allow: true
+                            multi-statement-allow: true