Quellcode durchsuchen

优化新增参数配置、修改参数配置、删除参数配置和刷新参数缓存四个接口,增加租户Id的处理逻辑

james vor 16 Stunden
Ursprung
Commit
87a28c9d58

+ 1 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/SysConfigController.java

@@ -69,6 +69,7 @@ public class SysConfigController extends BaseController
             return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
         }
         config.setCreateBy(SecurityUtils.getUsername());
+        config.setTenantId(SecurityUtils.getTenantId());
         return toAjax(configService.insertConfig(config));
     }
 

+ 15 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/domain/SysConfig.java

@@ -43,6 +43,21 @@ public class SysConfig extends BaseEntity
         this.configId = configId;
     }
 
+    /**
+     * 租户ID
+     */
+    private Integer tenantId;
+
+    public Integer getTenantId()
+    {
+        return tenantId;
+    }
+
+    public void setTenantId(Integer tenantId)
+    {
+        this.tenantId = tenantId;
+    }
+
     @NotBlank(message = "参数名称不能为空")
     @Size(min = 0, max = 100, message = "参数名称不能超过100个字符")
     public String getConfigName()

+ 14 - 7
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysConfigServiceImpl.java

@@ -7,6 +7,7 @@ import com.usky.common.core.util.Convert;
 import com.usky.common.core.util.StringUtils;
 import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.common.redis.core.RedisHelper;
+import com.usky.common.security.utils.SecurityUtils;
 import com.usky.system.domain.SysConfig;
 import com.usky.system.domain.constants.UserConstants;
 import com.usky.system.mapper.SysConfigMapper;
@@ -65,17 +66,20 @@ public class SysConfigServiceImpl extends AbstractCrudService<SysConfigMapper, S
     @Override
     public String selectConfigByKey(String configKey)
     {
-        String configValue = Convert.toStr(redisHelper.get(getCacheKey(configKey)));
+        Integer tenantId = SecurityUtils.getTenantId();
+        String configKey1 = configKey+tenantId;
+        String configValue = Convert.toStr(redisHelper.get(getCacheKey(configKey1)));
         if (StringUtils.isNotEmpty(configValue))
         {
             return configValue;
         }
         SysConfig config = new SysConfig();
         config.setConfigKey(configKey);
+        config.setTenantId(tenantId);
         SysConfig retConfig = configMapper.selectConfig(config);
         if (Objects.nonNull(retConfig))
         {
-            redisHelper.set(getCacheKey(configKey), retConfig.getConfigValue());
+            redisHelper.set(getCacheKey(configKey1), retConfig.getConfigValue());
             return retConfig.getConfigValue();
         }
         return StringUtils.EMPTY;
@@ -106,6 +110,7 @@ public class SysConfigServiceImpl extends AbstractCrudService<SysConfigMapper, S
     @Override
     public List<SysConfig> selectConfigList(SysConfig config)
     {
+        config.setTenantId(SecurityUtils.getTenantId());
         return configMapper.selectConfigList(config);
     }
 
@@ -121,7 +126,7 @@ public class SysConfigServiceImpl extends AbstractCrudService<SysConfigMapper, S
         int row = configMapper.insertConfig(config);
         if (row > 0)
         {
-            redisHelper.set(getCacheKey(config.getConfigKey()), config.getConfigValue());
+            redisHelper.set(getCacheKey(config.getConfigKey()+SecurityUtils.getTenantId()), config.getConfigValue());
         }
         return row;
     }
@@ -138,7 +143,7 @@ public class SysConfigServiceImpl extends AbstractCrudService<SysConfigMapper, S
         int row = configMapper.updateConfig(config);
         if (row > 0)
         {
-            redisHelper.set(getCacheKey(config.getConfigKey()), config.getConfigValue());
+            redisHelper.set(getCacheKey(config.getConfigKey()+SecurityUtils.getTenantId()), config.getConfigValue());
         }
         return row;
     }
@@ -160,7 +165,7 @@ public class SysConfigServiceImpl extends AbstractCrudService<SysConfigMapper, S
                 throw new BusinessException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
             }
             configMapper.deleteConfigById(configId);
-            redisHelper.delete(getCacheKey(config.getConfigKey()));
+            redisHelper.delete(getCacheKey(config.getConfigKey()+SecurityUtils.getTenantId()));
         }
     }
 
@@ -170,10 +175,12 @@ public class SysConfigServiceImpl extends AbstractCrudService<SysConfigMapper, S
     @Override
     public void loadingConfigCache()
     {
-        List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
+        SysConfig config1 = new SysConfig();
+        config1.setTenantId(SecurityUtils.getTenantId());
+        List<SysConfig> configsList = configMapper.selectConfigList(config1);
         for (SysConfig config : configsList)
         {
-            redisHelper.set(getCacheKey(config.getConfigKey()), config.getConfigValue());
+            redisHelper.set(getCacheKey(config.getConfigKey()+SecurityUtils.getTenantId()), config.getConfigValue());
         }
     }
 

+ 5 - 0
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysConfigMapper.xml

@@ -56,6 +56,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
 				and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
 			</if>
+            <if test="tenantId != null and tenantId != '' and tenantId != 0">
+                AND tenant_id = #{tenantId}
+            </if>
 		</where>
     </select>
     
@@ -72,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="configType != null and configType != '' ">config_type,</if>
 			<if test="createBy != null and createBy != ''">create_by,</if>
 			<if test="remark != null and remark != ''">remark,</if>
+            <if test="tenantId != null and tenantId != '' and tenantId != 0">tenant_id,</if>
  			create_time
         )values(
 			<if test="configName != null and configName != ''">#{configName},</if>
@@ -80,6 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="configType != null and configType != ''">#{configType},</if>
 			<if test="createBy != null and createBy != ''">#{createBy},</if>
 			<if test="remark != null and remark != ''">#{remark},</if>
+            <if test="tenantId != null and tenantId != '' and tenantId != 0">#{tenantId},</if>
  			sysdate()
 		)
     </insert>