feat(user): 添加根据手机号查询用户的跨租户功能
- 在 UserMapper 中新增 selectByPhone 方法,支持忽略租户隔离查询 - 更新 UserMapper.xml 中的 selectByPhone 查询语句,实现跨库查询逻辑 - 修改 UserServiceImpl 中的 getByPhone 方法,使用自定义 SQL 避免租户拦截器影响 - 实现跨租户查询,直接访问 gxwebsoft_core.sys_user 表获取用户信息
This commit is contained in:
@@ -62,6 +62,14 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
User selectByIdIgnoreTenant(@Param("userId") Integer userId);
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户(忽略租户隔离,跨库查 gxwebsoft_core.sys_user)
|
||||
* @param phone 手机号
|
||||
* @return User
|
||||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
User selectByPhone(@Param("phone") String phone);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<User> pageAdminByPhone(@Param("param") UserParam param);
|
||||
|
||||
|
||||
@@ -182,20 +182,13 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 根据手机号码查询 -->
|
||||
<!-- 根据手机号码查询(跨租户,忽略租户隔离) -->
|
||||
<select id="selectByPhone" resultType="com.gxwebsoft.common.system.entity.User">
|
||||
SELECT a.*
|
||||
FROM gxwebsoft_core.sys_user a
|
||||
<where>
|
||||
AND a.deleted = 0
|
||||
WHERE a.deleted = 0
|
||||
AND a.phone = #{phone}
|
||||
<if test="tenantId != null">
|
||||
AND a.tenant_id = #{tenantId}
|
||||
</if>
|
||||
<if test="tenantId == null">
|
||||
AND a.tenant_id = 1
|
||||
</if>
|
||||
</where>
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 获取所有的邮政协会/管局工作人员 -->
|
||||
|
||||
@@ -180,7 +180,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
|
||||
@Override
|
||||
public User getByPhone(String phone) {
|
||||
return query().eq("phone", phone).one();
|
||||
// 使用自定义 SQL(@InterceptorIgnore),避免 TenantLineInterceptor 把表定位到当前库的 sys_user
|
||||
return baseMapper.selectByPhone(phone);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user