mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 17:38:48 +08:00
远程服务
Signed-off-by: 2000 <171332584@qq.com>
This commit is contained in:
parent
2f3e873980
commit
5e2fd3a535
@ -6,6 +6,8 @@ import org.dromara.system.api.domain.bo.RemoteUserBo;
|
|||||||
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.system.api.model.LoginUser;
|
||||||
import org.dromara.system.api.model.XcxLoginUser;
|
import org.dromara.system.api.model.XcxLoginUser;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -14,6 +16,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@FeignClient(name = "user-service", url = "http://localhost:8081")
|
||||||
public interface RemoteUserService {
|
public interface RemoteUserService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +26,8 @@ public interface RemoteUserService {
|
|||||||
* @param tenantId 租户id
|
* @param tenantId 租户id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
LoginUser getUserInfo(String username, String tenantId) throws UserException;
|
@PostMapping("/getUserInfoByUsernameTenantId")
|
||||||
|
LoginUser getUserInfoByUsernameTenantId(@RequestParam("username") String username, @RequestParam("tenantId") String tenantId) throws UserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户id查询用户信息
|
* 通过用户id查询用户信息
|
||||||
@ -32,7 +36,8 @@ public interface RemoteUserService {
|
|||||||
* @param tenantId 租户id
|
* @param tenantId 租户id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
LoginUser getUserInfo(Long userId, String tenantId) throws UserException;
|
@PostMapping("/getUserInfo")
|
||||||
|
LoginUser getUserInfo(@RequestParam("userId") Long userId, @RequestParam("tenantId") String tenantId) throws UserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过手机号查询用户信息
|
* 通过手机号查询用户信息
|
||||||
@ -41,7 +46,8 @@ public interface RemoteUserService {
|
|||||||
* @param tenantId 租户id
|
* @param tenantId 租户id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
LoginUser getUserInfoByPhonenumber(String phonenumber, String tenantId) throws UserException;
|
@PostMapping("/getUserInfoByPhonenumber")
|
||||||
|
LoginUser getUserInfoByPhonenumber(@RequestParam("phonenumber") String phonenumber, @RequestParam("tenantId") String tenantId) throws UserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过邮箱查询用户信息
|
* 通过邮箱查询用户信息
|
||||||
@ -50,7 +56,8 @@ public interface RemoteUserService {
|
|||||||
* @param tenantId 租户id
|
* @param tenantId 租户id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
LoginUser getUserInfoByEmail(String email, String tenantId) throws UserException;
|
@PostMapping("/getUserInfoByEmail")
|
||||||
|
LoginUser getUserInfoByEmail(@RequestParam("email") String email, @RequestParam("tenantId") String tenantId) throws UserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过openid查询用户信息
|
* 通过openid查询用户信息
|
||||||
@ -58,7 +65,8 @@ public interface RemoteUserService {
|
|||||||
* @param openid openid
|
* @param openid openid
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
XcxLoginUser getUserInfoByOpenid(String openid) throws UserException;
|
@PostMapping("/getUserInfoByOpenid")
|
||||||
|
XcxLoginUser getUserInfoByOpenid(@RequestParam("openid") String openid) throws UserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册用户信息
|
* 注册用户信息
|
||||||
@ -66,7 +74,8 @@ public interface RemoteUserService {
|
|||||||
* @param remoteUserBo 用户信息
|
* @param remoteUserBo 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
Boolean registerUserInfo(RemoteUserBo remoteUserBo) throws UserException, ServiceException;
|
@PostMapping("/registerUserInfo")
|
||||||
|
Boolean registerUserInfo(@RequestBody RemoteUserBo remoteUserBo) throws UserException, ServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过userId查询用户账户
|
* 通过userId查询用户账户
|
||||||
@ -74,7 +83,8 @@ public interface RemoteUserService {
|
|||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
String selectUserNameById(Long userId);
|
@GetMapping("/selectUserNameById")
|
||||||
|
String selectUserNameById(@RequestParam("userId") Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户昵称
|
* 通过用户ID查询用户昵称
|
||||||
@ -82,7 +92,8 @@ public interface RemoteUserService {
|
|||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
String selectNicknameById(Long userId);
|
@GetMapping("/selectNicknameById")
|
||||||
|
String selectNicknameById(@RequestParam("userId") Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户账户
|
* 通过用户ID查询用户账户
|
||||||
@ -90,7 +101,8 @@ public interface RemoteUserService {
|
|||||||
* @param userIds 用户ID 多个用逗号隔开
|
* @param userIds 用户ID 多个用逗号隔开
|
||||||
* @return 用户名称
|
* @return 用户名称
|
||||||
*/
|
*/
|
||||||
String selectNicknameByIds(String userIds);
|
@GetMapping("/selectNicknameByIds")
|
||||||
|
String selectNicknameByIds(@RequestParam("userIds") String userIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户手机号
|
* 通过用户ID查询用户手机号
|
||||||
@ -98,7 +110,8 @@ public interface RemoteUserService {
|
|||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @return 用户手机号
|
* @return 用户手机号
|
||||||
*/
|
*/
|
||||||
String selectPhonenumberById(Long userId);
|
@GetMapping("/selectPhonenumberById")
|
||||||
|
String selectPhonenumberById(@RequestParam("userId") Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户邮箱
|
* 通过用户ID查询用户邮箱
|
||||||
@ -106,7 +119,8 @@ public interface RemoteUserService {
|
|||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @return 用户邮箱
|
* @return 用户邮箱
|
||||||
*/
|
*/
|
||||||
String selectEmailById(Long userId);
|
@GetMapping("/selectEmailById")
|
||||||
|
String selectEmailById(@RequestParam("userId") Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户信息
|
* 更新用户信息
|
||||||
@ -114,7 +128,8 @@ public interface RemoteUserService {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param ip IP地址
|
* @param ip IP地址
|
||||||
*/
|
*/
|
||||||
void recordLoginInfo(Long userId, String ip);
|
@PostMapping("/recordLoginInfo")
|
||||||
|
void recordLoginInfo(@RequestParam("userId") Long userId, @RequestParam("ip") String ip);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户列表
|
* 通过用户ID查询用户列表
|
||||||
@ -122,7 +137,8 @@ public interface RemoteUserService {
|
|||||||
* @param userIds 用户ids
|
* @param userIds 用户ids
|
||||||
* @return 用户列表
|
* @return 用户列表
|
||||||
*/
|
*/
|
||||||
List<RemoteUserVo> selectListByIds(List<Long> userIds);
|
@PostMapping("/selectListByIds")
|
||||||
|
List<RemoteUserVo> selectListByIds(@RequestBody List<Long> userIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过角色ID查询用户ID
|
* 通过角色ID查询用户ID
|
||||||
@ -130,5 +146,6 @@ public interface RemoteUserService {
|
|||||||
* @param roleIds 角色ids
|
* @param roleIds 角色ids
|
||||||
* @return 用户ids
|
* @return 用户ids
|
||||||
*/
|
*/
|
||||||
List<Long> selectUserIdsByRoleIds(List<Long> roleIds);
|
@PostMapping("/selectUserIdsByRoleIds")
|
||||||
|
List<Long> selectUserIdsByRoleIds(@RequestBody List<Long> roleIds);
|
||||||
}
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ClientInfoUtil {
|
||||||
|
|
||||||
|
public String getCurrentSystemIp() {
|
||||||
|
try {
|
||||||
|
return InetAddress.getLocalHost().getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientType(HttpServletRequest request) {
|
||||||
|
return request.getHeader("Client-Type");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
import feign.RequestInterceptor;
|
||||||
|
import feign.RequestTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class FeignConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ClientInfoUtil clientInfoUtil;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RequestInterceptor requestInterceptor() {
|
||||||
|
return new RequestInterceptor() {
|
||||||
|
@Override
|
||||||
|
public void apply(RequestTemplate template) {
|
||||||
|
// 获取客户端类型
|
||||||
|
String clientType = clientInfoUtil.getClientType(request);
|
||||||
|
|
||||||
|
// 获取当前系统的IP
|
||||||
|
String currentSystemIp = clientInfoUtil.getCurrentSystemIp();
|
||||||
|
|
||||||
|
// 将客户端信息添加到请求头
|
||||||
|
template.header("X-Client-IP", currentSystemIp);
|
||||||
|
template.header("X-Client-Type", clientType);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,311 @@
|
|||||||
|
package org.dromara.system.saas.remote;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.lang.Opt;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
import org.dromara.common.core.enums.UserStatus;
|
||||||
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
|
import org.dromara.common.core.exception.user.UserException;
|
||||||
|
import org.dromara.common.core.utils.DateUtils;
|
||||||
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.dromara.common.mybatis.helper.DataPermissionHelper;
|
||||||
|
import org.dromara.common.tenant.helper.TenantHelper;
|
||||||
|
import org.dromara.system.api.RemoteUserService;
|
||||||
|
import org.dromara.system.api.domain.bo.RemoteUserBo;
|
||||||
|
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
||||||
|
import org.dromara.system.api.model.LoginUser;
|
||||||
|
import org.dromara.system.api.model.RoleDTO;
|
||||||
|
import org.dromara.system.api.model.XcxLoginUser;
|
||||||
|
import org.dromara.system.domain.SysUser;
|
||||||
|
import org.dromara.system.domain.bo.SysUserBo;
|
||||||
|
import org.dromara.system.domain.vo.SysDeptVo;
|
||||||
|
import org.dromara.system.domain.vo.SysRoleVo;
|
||||||
|
import org.dromara.system.domain.vo.SysUserVo;
|
||||||
|
import org.dromara.system.mapper.SysUserMapper;
|
||||||
|
import org.dromara.system.service.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户服务 fegin实现
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
@DubboService
|
||||||
|
public class RemoteUserServiceImpl implements RemoteUserService {
|
||||||
|
|
||||||
|
private final ISysUserService userService;
|
||||||
|
private final ISysPermissionService permissionService;
|
||||||
|
private final ISysConfigService configService;
|
||||||
|
private final ISysRoleService roleService;
|
||||||
|
private final ISysDeptService deptService;
|
||||||
|
private final SysUserMapper userMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户名查询用户信息
|
||||||
|
*
|
||||||
|
* @param username 用户名
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LoginUser getUserInfo(String username, String tenantId) throws UserException {
|
||||||
|
return TenantHelper.dynamic(tenantId, () -> {
|
||||||
|
SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
|
||||||
|
if (ObjectUtil.isNull(sysUser)) {
|
||||||
|
throw new UserException("user.not.exists", username);
|
||||||
|
}
|
||||||
|
if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) {
|
||||||
|
throw new UserException("user.blocked", username);
|
||||||
|
}
|
||||||
|
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||||
|
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||||
|
return buildLoginUser(sysUser);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户id查询用户信息
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LoginUser getUserInfo(Long userId, String tenantId) throws UserException {
|
||||||
|
return TenantHelper.dynamic(tenantId, () -> {
|
||||||
|
SysUserVo sysUser = userMapper.selectVoById(userId);
|
||||||
|
if (ObjectUtil.isNull(sysUser)) {
|
||||||
|
throw new UserException("user.not.exists", "");
|
||||||
|
}
|
||||||
|
if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) {
|
||||||
|
throw new UserException("user.blocked", sysUser.getUserName());
|
||||||
|
}
|
||||||
|
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||||
|
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||||
|
return buildLoginUser(sysUser);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过手机号查询用户信息
|
||||||
|
*
|
||||||
|
* @param phonenumber 手机号
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LoginUser getUserInfoByPhonenumber(String phonenumber, String tenantId) throws UserException {
|
||||||
|
return TenantHelper.dynamic(tenantId, () -> {
|
||||||
|
SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhonenumber, phonenumber));
|
||||||
|
if (ObjectUtil.isNull(sysUser)) {
|
||||||
|
throw new UserException("user.not.exists", phonenumber);
|
||||||
|
}
|
||||||
|
if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) {
|
||||||
|
throw new UserException("user.blocked", phonenumber);
|
||||||
|
}
|
||||||
|
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||||
|
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||||
|
return buildLoginUser(sysUser);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过邮箱查询用户信息
|
||||||
|
*
|
||||||
|
* @param email 邮箱
|
||||||
|
* @param tenantId 租户id
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LoginUser getUserInfoByEmail(String email, String tenantId) throws UserException {
|
||||||
|
return TenantHelper.dynamic(tenantId, () -> {
|
||||||
|
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getEmail, email));
|
||||||
|
if (ObjectUtil.isNull(user)) {
|
||||||
|
throw new UserException("user.not.exists", email);
|
||||||
|
}
|
||||||
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||||
|
throw new UserException("user.blocked", email);
|
||||||
|
}
|
||||||
|
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||||
|
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||||
|
return buildLoginUser(user);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过openid查询用户信息
|
||||||
|
*
|
||||||
|
* @param openid openid
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public XcxLoginUser getUserInfoByOpenid(String openid) throws UserException {
|
||||||
|
// todo 自行实现 userService.selectUserByOpenid(openid);
|
||||||
|
SysUser sysUser = new SysUser();
|
||||||
|
if (ObjectUtil.isNull(sysUser)) {
|
||||||
|
// todo 用户不存在 业务逻辑自行实现
|
||||||
|
}
|
||||||
|
if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) {
|
||||||
|
// todo 用户已被停用 业务逻辑自行实现
|
||||||
|
}
|
||||||
|
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||||
|
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||||
|
XcxLoginUser loginUser = new XcxLoginUser();
|
||||||
|
loginUser.setUserId(sysUser.getUserId());
|
||||||
|
loginUser.setUsername(sysUser.getUserName());
|
||||||
|
loginUser.setNickname(sysUser.getNickName());
|
||||||
|
loginUser.setUserType(sysUser.getUserType());
|
||||||
|
loginUser.setOpenid(openid);
|
||||||
|
return loginUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册用户信息
|
||||||
|
*
|
||||||
|
* @param remoteUserBo 用户信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean registerUserInfo(RemoteUserBo remoteUserBo) throws UserException, ServiceException {
|
||||||
|
SysUserBo sysUserBo = MapstructUtils.convert(remoteUserBo, SysUserBo.class);
|
||||||
|
String username = sysUserBo.getUserName();
|
||||||
|
boolean exist = TenantHelper.dynamic(remoteUserBo.getTenantId(), () -> {
|
||||||
|
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
|
||||||
|
throw new ServiceException("当前系统没有开启注册功能");
|
||||||
|
}
|
||||||
|
return userMapper.exists(new LambdaQueryWrapper<SysUser>()
|
||||||
|
.eq(SysUser::getUserName, sysUserBo.getUserName()));
|
||||||
|
});
|
||||||
|
if (exist) {
|
||||||
|
throw new UserException("user.register.save.error", username);
|
||||||
|
}
|
||||||
|
return userService.registerUser(sysUserBo, remoteUserBo.getTenantId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户账户
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 用户账户
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String selectUserNameById(Long userId) {
|
||||||
|
return userService.selectUserNameById(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户昵称
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 用户昵称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String selectNicknameById(Long userId) {
|
||||||
|
return userService.selectNicknameById(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户账户
|
||||||
|
*
|
||||||
|
* @param userIds 用户ID 多个用逗号隔开
|
||||||
|
* @return 用户账户
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String selectNicknameByIds(String userIds) {
|
||||||
|
return userService.selectNicknameByIds(userIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户手机号
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 用户手机号
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String selectPhonenumberById(Long userId) {
|
||||||
|
return userService.selectPhonenumberById(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户邮箱
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 用户邮箱
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String selectEmailById(Long userId) {
|
||||||
|
return userService.selectEmailById(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建登录用户
|
||||||
|
*/
|
||||||
|
private LoginUser buildLoginUser(SysUserVo userVo) {
|
||||||
|
LoginUser loginUser = new LoginUser();
|
||||||
|
loginUser.setTenantId(userVo.getTenantId());
|
||||||
|
loginUser.setUserId(userVo.getUserId());
|
||||||
|
loginUser.setDeptId(userVo.getDeptId());
|
||||||
|
loginUser.setUsername(userVo.getUserName());
|
||||||
|
loginUser.setNickname(userVo.getNickName());
|
||||||
|
loginUser.setPassword(userVo.getPassword());
|
||||||
|
loginUser.setUserType(userVo.getUserType());
|
||||||
|
loginUser.setMenuPermission(permissionService.getMenuPermission(userVo.getUserId()));
|
||||||
|
loginUser.setRolePermission(permissionService.getRolePermission(userVo.getUserId()));
|
||||||
|
if (ObjectUtil.isNotNull(userVo.getDeptId())) {
|
||||||
|
Opt<SysDeptVo> deptOpt = Opt.of(userVo.getDeptId()).map(deptService::selectDeptById);
|
||||||
|
loginUser.setDeptName(deptOpt.map(SysDeptVo::getDeptName).orElse(StringUtils.EMPTY));
|
||||||
|
loginUser.setDeptCategory(deptOpt.map(SysDeptVo::getDeptCategory).orElse(StringUtils.EMPTY));
|
||||||
|
}
|
||||||
|
List<SysRoleVo> roles = roleService.selectRolesByUserId(userVo.getUserId());
|
||||||
|
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
||||||
|
return loginUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户信息
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param ip IP地址
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void recordLoginInfo(Long userId, String ip) {
|
||||||
|
SysUser sysUser = new SysUser();
|
||||||
|
sysUser.setUserId(userId);
|
||||||
|
sysUser.setLoginIp(ip);
|
||||||
|
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||||
|
sysUser.setUpdateBy(userId);
|
||||||
|
DataPermissionHelper.ignore(() -> userMapper.updateById(sysUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户列表
|
||||||
|
*
|
||||||
|
* @param userIds 用户ids
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<RemoteUserVo> selectListByIds(List<Long> userIds) {
|
||||||
|
List<SysUserVo> sysUserVos = userService.selectUserByIds(userIds, null);
|
||||||
|
return MapstructUtils.convert(sysUserVos, RemoteUserVo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过角色ID查询用户ID
|
||||||
|
*
|
||||||
|
* @param roleIds 角色ids
|
||||||
|
* @return 用户ids
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Long> selectUserIdsByRoleIds(List<Long> roleIds) {
|
||||||
|
return userService.selectUserIdsByRoleIds(roleIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user