适配多租户
This commit is contained in:
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
import com.rj.entity.sys.User;
|
import com.rj.entity.sys.User;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -18,7 +19,7 @@ import org.apache.ibatis.annotations.Select;
|
|||||||
* - 其他通过 MyBatis-Plus 内置 CRUD 产生的 SQL 仍然会自动带上 tenant_id 条件。
|
* - 其他通过 MyBatis-Plus 内置 CRUD 产生的 SQL 仍然会自动带上 tenant_id 条件。
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author 系统生成
|
* @author
|
||||||
* @since 2025-08-07
|
* @since 2025-08-07
|
||||||
*/
|
*/
|
||||||
public interface UserMapper extends BaseMapper<User> {
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
@@ -36,5 +37,13 @@ public interface UserMapper extends BaseMapper<User> {
|
|||||||
@InterceptorIgnore(tenantLine = "true")
|
@InterceptorIgnore(tenantLine = "true")
|
||||||
@Select("SELECT * FROM user WHERE token = #{token} LIMIT 1")
|
@Select("SELECT * FROM user WHERE token = #{token} LIMIT 1")
|
||||||
User selectByTokenIgnoreTenant(@Param("token") String token);
|
User selectByTokenIgnoreTenant(@Param("token") String token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID更新用户信息(登录时更新token用),不走多租户拦截器。
|
||||||
|
* 此方法用于登录场景,需要跨租户更新用户token,因此不添加 tenant_id 条件。
|
||||||
|
*/
|
||||||
|
@InterceptorIgnore(tenantLine = "true")
|
||||||
|
@Update("UPDATE user SET token = #{user.token} WHERE user_id = #{user.userId}")
|
||||||
|
int updateByIdIgnoreTenant(@Param("user") User user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|||||||
// 生成token
|
// 生成token
|
||||||
String token = UUID.randomUUID().toString().replace("-", "");
|
String token = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
|
||||||
// 更新用户的token
|
// 更新用户的token(登录时不走多租户拦截器,避免添加 tenant_id = null 的限制)
|
||||||
user.setToken(token);
|
user.setToken(token);
|
||||||
this.updateById(user);
|
this.baseMapper.updateByIdIgnoreTenant(user);
|
||||||
|
|
||||||
// 构建登录响应
|
// 构建登录响应
|
||||||
LoginResponse loginResponse = new LoginResponse();
|
LoginResponse loginResponse = new LoginResponse();
|
||||||
|
|||||||
@@ -17,5 +17,10 @@
|
|||||||
user_id, user_name, email, password, token, avatar
|
user_id, user_name, email, password, token, avatar
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<!-- 根据 token 查询用户(token 验证、获取当前用户信息),不走多租户拦截器,不添加 tenant_id 条件 -->
|
||||||
|
<select id="selectByTokenIgnoreTenant" resultMap="BaseResultMap">
|
||||||
|
SELECT * FROM user WHERE token = #{token} LIMIT 1
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ UPDATE `sales_management` SET `tenant_id` = 'DEFAULT_TENANT_ID' WHERE
|
|||||||
-- 门店与项目类
|
-- 门店与项目类
|
||||||
UPDATE `dealership` SET `tenant_id` = 'DEFAULT_TENANT_ID' WHERE `tenant_id` IS NULL;
|
UPDATE `dealership` SET `tenant_id` = 'DEFAULT_TENANT_ID' WHERE `tenant_id` IS NULL;
|
||||||
UPDATE `project_management` SET `tenant_id` = 'DEFAULT_TENANT_ID' WHERE `tenant_id` IS NULL;
|
UPDATE `project_management` SET `tenant_id` = 'DEFAULT_TENANT_ID' WHERE `tenant_id` IS NULL;
|
||||||
|
UPDATE `device_management` SET `tenant_id` = 'DEFAULT_cst_20251216' WHERE `tenant_id` IS NULL;
|
||||||
|
|
||||||
-- 日志与其他
|
-- 日志与其他
|
||||||
UPDATE `yhy_audio_upload_log` SET `tenant_id` = 'DEFAULT_TENANT_ID' WHERE `tenant_id` IS NULL;
|
UPDATE `yhy_audio_upload_log` SET `tenant_id` = 'DEFAULT_TENANT_ID' WHERE `tenant_id` IS NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user