update 优化 使用动态租户重构业务对租户的逻辑

This commit is contained in:
疯狂的狮子Li
2023-11-21 14:57:00 +08:00
parent 1e1616ceb0
commit ac6fe634dc
9 changed files with 64 additions and 120 deletions

View File

@ -1,15 +1,14 @@
package org.dromara.system.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.annotation.DataPermission;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.system.domain.SysUser;
import org.dromara.system.domain.vo.SysUserVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -86,37 +85,6 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
*/
SysUserVo selectUserByEmail(String email);
/**
* 通过用户名查询用户(不走租户插件)
*
* @param userName 用户名
* @param tenantId 租户id
* @return 用户对象信息
*/
@InterceptorIgnore(tenantLine = "true")
SysUserVo selectTenantUserByUserName(@Param("userName") String userName, @Param("tenantId") String tenantId);
/**
* 通过手机号查询用户(不走租户插件)
*
* @param phonenumber 手机号
* @param tenantId 租户id
* @return 用户对象信息
*/
@InterceptorIgnore(tenantLine = "true")
SysUserVo selectTenantUserByPhonenumber(@Param("phonenumber") String phonenumber, @Param("tenantId") String tenantId);
/**
* 通过邮箱查询用户(不走租户插件)
*
* @param email 邮箱
* @param tenantId 租户id
* @return 用户对象信息
*/
@InterceptorIgnore(tenantLine = "true")
SysUserVo selectTenantUserByEmail(@Param("email") String email, @Param("tenantId") String tenantId);
/**
* 通过用户ID查询用户
*

View File

@ -85,9 +85,10 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
*/
@Override
public boolean selectRegisterEnabled(String tenantId) {
SysConfig retConfig = baseMapper.selectOne(new LambdaQueryWrapper<SysConfig>()
.eq(SysConfig::getConfigKey, "sys.account.registerUser")
.eq(TenantHelper.isEnable(),SysConfig::getTenantId, tenantId));
SysConfig retConfig = TenantHelper.dynamic(tenantId, () -> {
return baseMapper.selectOne(new LambdaQueryWrapper<SysConfig>()
.eq(SysConfig::getConfigKey, "sys.account.registerUser"));
});
if (ObjectUtil.isNull(retConfig)) {
return false;
}

View File

@ -57,9 +57,8 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
new LambdaQueryWrapper<SysOssConfig>().orderByAsc(TenantEntity::getTenantId))
);
Map<String, List<SysOssConfig>> map = StreamUtils.groupByKey(list, SysOssConfig::getTenantId);
try {
for (String tenantId : map.keySet()) {
TenantHelper.setDynamic(tenantId);
for (String tenantId : map.keySet()) {
TenantHelper.dynamic(tenantId, () -> {
// 加载OSS初始化配置
for (SysOssConfig config : map.get(tenantId)) {
String configKey = config.getConfigKey();
@ -68,9 +67,7 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
}
CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config));
}
}
} finally {
TenantHelper.clearDynamic();
});
}
}

View File

@ -118,21 +118,6 @@
where u.del_flag = '0' and u.email = #{email}
</select>
<select id="selectTenantUserByUserName" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.del_flag = '0' and u.user_name = #{userName} and u.tenant_id = #{tenantId}
</select>
<select id="selectTenantUserByPhonenumber" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.del_flag = '0' and u.phonenumber = #{phonenumber} and u.tenant_id = #{tenantId}
</select>
<select id="selectTenantUserByEmail" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.del_flag = '0' and u.email = #{email} and u.tenant_id = #{tenantId}
</select>
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.del_flag = '0' and u.user_id = #{userId}