|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import javax.validation.Validator;
|
|
|
|
import javax.validation.Validator;
|
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@ -36,8 +37,7 @@ import com.ruoyi.system.service.ISysUserService;
|
|
|
|
* @author ruoyi
|
|
|
|
* @author ruoyi
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class SysUserServiceImpl implements ISysUserService
|
|
|
|
public class SysUserServiceImpl implements ISysUserService {
|
|
|
|
{
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
@ -69,8 +69,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@DataScope(deptAlias = "d", userAlias = "u", tenantAlias = "u")
|
|
|
|
@DataScope(deptAlias = "d", userAlias = "u", tenantAlias = "u")
|
|
|
|
public List<SysUser> selectUserList(SysUser user)
|
|
|
|
public List<SysUser> selectUserList(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.selectUserList(user);
|
|
|
|
return userMapper.selectUserList(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -82,8 +81,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@DataScope(deptAlias = "d", userAlias = "u")
|
|
|
|
@DataScope(deptAlias = "d", userAlias = "u")
|
|
|
|
public List<SysUser> selectAllocatedList(SysUser user)
|
|
|
|
public List<SysUser> selectAllocatedList(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.selectAllocatedList(user);
|
|
|
|
return userMapper.selectAllocatedList(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -95,8 +93,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@DataScope(deptAlias = "d", userAlias = "u")
|
|
|
|
@DataScope(deptAlias = "d", userAlias = "u")
|
|
|
|
public List<SysUser> selectUnallocatedList(SysUser user)
|
|
|
|
public List<SysUser> selectUnallocatedList(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.selectUnallocatedList(user);
|
|
|
|
return userMapper.selectUnallocatedList(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -107,8 +104,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 用户对象信息
|
|
|
|
* @return 用户对象信息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public SysUser selectUserByUserName(String userName)
|
|
|
|
public SysUser selectUserByUserName(String userName) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.selectUserByUserName(userName);
|
|
|
|
return userMapper.selectUserByUserName(userName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -119,8 +115,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 用户对象信息
|
|
|
|
* @return 用户对象信息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public SysUser selectUserById(Long userId)
|
|
|
|
public SysUser selectUserById(Long userId) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.selectUserById(userId);
|
|
|
|
return userMapper.selectUserById(userId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -131,11 +126,9 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String selectUserRoleGroup(String userName)
|
|
|
|
public String selectUserRoleGroup(String userName) {
|
|
|
|
{
|
|
|
|
|
|
|
|
List<SysRole> list = roleMapper.selectRolesByUserName(userName);
|
|
|
|
List<SysRole> list = roleMapper.selectRolesByUserName(userName);
|
|
|
|
if (CollectionUtils.isEmpty(list))
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(","));
|
|
|
|
return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(","));
|
|
|
@ -148,11 +141,9 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String selectUserPostGroup(String userName)
|
|
|
|
public String selectUserPostGroup(String userName) {
|
|
|
|
{
|
|
|
|
|
|
|
|
List<SysPost> list = postMapper.selectPostsByUserName(userName);
|
|
|
|
List<SysPost> list = postMapper.selectPostsByUserName(userName);
|
|
|
|
if (CollectionUtils.isEmpty(list))
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list.stream().map(SysPost::getPostName).collect(Collectors.joining(","));
|
|
|
|
return list.stream().map(SysPost::getPostName).collect(Collectors.joining(","));
|
|
|
@ -165,12 +156,10 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkUserNameUnique(SysUser user)
|
|
|
|
public boolean checkUserNameUnique(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
|
|
|
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
|
|
|
SysUser info = userMapper.checkUserNameUnique(user.getUserName());
|
|
|
|
SysUser info = userMapper.checkUserNameUnique(user.getUserName());
|
|
|
|
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
|
|
|
|
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
@ -183,12 +172,10 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkPhoneUnique(SysUser user)
|
|
|
|
public boolean checkPhoneUnique(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
|
|
|
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
|
|
|
SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
|
|
|
|
SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
|
|
|
|
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
|
|
|
|
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
@ -201,12 +188,10 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkEmailUnique(SysUser user)
|
|
|
|
public boolean checkEmailUnique(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
|
|
|
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
|
|
|
SysUser info = userMapper.checkEmailUnique(user.getEmail());
|
|
|
|
SysUser info = userMapper.checkEmailUnique(user.getEmail());
|
|
|
|
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
|
|
|
|
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
@ -218,10 +203,8 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @param user 用户信息
|
|
|
|
* @param user 用户信息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void checkUserAllowed(SysUser user)
|
|
|
|
public void checkUserAllowed(SysUser user) {
|
|
|
|
{
|
|
|
|
if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) {
|
|
|
|
if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ServiceException("不允许操作超级管理员用户");
|
|
|
|
throw new ServiceException("不允许操作超级管理员用户");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -232,15 +215,12 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @param userId 用户id
|
|
|
|
* @param userId 用户id
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void checkUserDataScope(Long userId)
|
|
|
|
public void checkUserDataScope(Long userId) {
|
|
|
|
{
|
|
|
|
if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
|
|
|
|
if (!SysUser.isAdmin(SecurityUtils.getUserId()))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SysUser user = new SysUser();
|
|
|
|
SysUser user = new SysUser();
|
|
|
|
user.setUserId(userId);
|
|
|
|
user.setUserId(userId);
|
|
|
|
List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user);
|
|
|
|
List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user);
|
|
|
|
if (StringUtils.isEmpty(users))
|
|
|
|
if (StringUtils.isEmpty(users)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ServiceException("没有权限访问用户数据!");
|
|
|
|
throw new ServiceException("没有权限访问用户数据!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -254,8 +234,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public int insertUser(SysUser user)
|
|
|
|
public int insertUser(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
// 新增用户信息
|
|
|
|
// 新增用户信息
|
|
|
|
int rows = userMapper.insertUser(user);
|
|
|
|
int rows = userMapper.insertUser(user);
|
|
|
|
// 新增用户岗位关联
|
|
|
|
// 新增用户岗位关联
|
|
|
@ -272,8 +251,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean registerUser(SysUser user)
|
|
|
|
public boolean registerUser(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.insertUser(user) > 0;
|
|
|
|
return userMapper.insertUser(user) > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -285,8 +263,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public int updateUser(SysUser user)
|
|
|
|
public int updateUser(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
Long userId = user.getUserId();
|
|
|
|
Long userId = user.getUserId();
|
|
|
|
// 删除用户与角色关联
|
|
|
|
// 删除用户与角色关联
|
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId);
|
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId);
|
|
|
@ -307,8 +284,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void insertUserAuth(Long userId, Long[] roleIds)
|
|
|
|
public void insertUserAuth(Long userId, Long[] roleIds) {
|
|
|
|
{
|
|
|
|
|
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId);
|
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId);
|
|
|
|
insertUserRole(userId, roleIds);
|
|
|
|
insertUserRole(userId, roleIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -320,8 +296,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int updateUserStatus(SysUser user)
|
|
|
|
public int updateUserStatus(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.updateUser(user);
|
|
|
|
return userMapper.updateUser(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -332,8 +307,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int updateUserProfile(SysUser user)
|
|
|
|
public int updateUserProfile(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.updateUser(user);
|
|
|
|
return userMapper.updateUser(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -345,8 +319,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateUserAvatar(String userName, String avatar)
|
|
|
|
public boolean updateUserAvatar(String userName, String avatar) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.updateUserAvatar(userName, avatar) > 0;
|
|
|
|
return userMapper.updateUserAvatar(userName, avatar) > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -357,8 +330,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int resetPwd(SysUser user)
|
|
|
|
public int resetPwd(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.updateUser(user);
|
|
|
|
return userMapper.updateUser(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -370,8 +342,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int resetUserPwd(String userName, String password)
|
|
|
|
public int resetUserPwd(String userName, String password) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return userMapper.resetUserPwd(userName, password);
|
|
|
|
return userMapper.resetUserPwd(userName, password);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -380,8 +351,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param user 用户对象
|
|
|
|
* @param user 用户对象
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void insertUserRole(SysUser user)
|
|
|
|
public void insertUserRole(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
this.insertUserRole(user.getUserId(), user.getRoleIds());
|
|
|
|
this.insertUserRole(user.getUserId(), user.getRoleIds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -390,15 +360,12 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param user 用户对象
|
|
|
|
* @param user 用户对象
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void insertUserPost(SysUser user)
|
|
|
|
public void insertUserPost(SysUser user) {
|
|
|
|
{
|
|
|
|
|
|
|
|
Long[] posts = user.getPostIds();
|
|
|
|
Long[] posts = user.getPostIds();
|
|
|
|
if (StringUtils.isNotEmpty(posts))
|
|
|
|
if (StringUtils.isNotEmpty(posts)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
// 新增用户与岗位管理
|
|
|
|
// 新增用户与岗位管理
|
|
|
|
List<SysUserPost> list = new ArrayList<SysUserPost>();
|
|
|
|
List<SysUserPost> list = new ArrayList<SysUserPost>();
|
|
|
|
for (Long postId : posts)
|
|
|
|
for (Long postId : posts) {
|
|
|
|
{
|
|
|
|
|
|
|
|
SysUserPost up = new SysUserPost();
|
|
|
|
SysUserPost up = new SysUserPost();
|
|
|
|
up.setUserId(user.getUserId());
|
|
|
|
up.setUserId(user.getUserId());
|
|
|
|
up.setPostId(postId);
|
|
|
|
up.setPostId(postId);
|
|
|
@ -414,14 +381,11 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @param userId 用户ID
|
|
|
|
* @param userId 用户ID
|
|
|
|
* @param roleIds 角色组
|
|
|
|
* @param roleIds 角色组
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void insertUserRole(Long userId, Long[] roleIds)
|
|
|
|
public void insertUserRole(Long userId, Long[] roleIds) {
|
|
|
|
{
|
|
|
|
if (StringUtils.isNotEmpty(roleIds)) {
|
|
|
|
if (StringUtils.isNotEmpty(roleIds))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 新增用户与角色管理
|
|
|
|
// 新增用户与角色管理
|
|
|
|
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
|
|
|
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
|
|
|
for (Long roleId : roleIds)
|
|
|
|
for (Long roleId : roleIds) {
|
|
|
|
{
|
|
|
|
|
|
|
|
SysUserRole ur = new SysUserRole();
|
|
|
|
SysUserRole ur = new SysUserRole();
|
|
|
|
ur.setUserId(userId);
|
|
|
|
ur.setUserId(userId);
|
|
|
|
ur.setRoleId(roleId);
|
|
|
|
ur.setRoleId(roleId);
|
|
|
@ -439,8 +403,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public int deleteUserById(Long userId)
|
|
|
|
public int deleteUserById(Long userId) {
|
|
|
|
{
|
|
|
|
|
|
|
|
// 删除用户与角色关联
|
|
|
|
// 删除用户与角色关联
|
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId);
|
|
|
|
userRoleMapper.deleteUserRoleByUserId(userId);
|
|
|
|
// 删除用户与岗位表
|
|
|
|
// 删除用户与岗位表
|
|
|
@ -456,10 +419,8 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public int deleteUserByIds(Long[] userIds)
|
|
|
|
public int deleteUserByIds(Long[] userIds) {
|
|
|
|
{
|
|
|
|
for (Long userId : userIds) {
|
|
|
|
for (Long userId : userIds)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
checkUserAllowed(new SysUser(userId));
|
|
|
|
checkUserAllowed(new SysUser(userId));
|
|
|
|
checkUserDataScope(userId);
|
|
|
|
checkUserDataScope(userId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -479,10 +440,8 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName)
|
|
|
|
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) {
|
|
|
|
{
|
|
|
|
if (StringUtils.isNull(userList) || userList.size() == 0) {
|
|
|
|
if (StringUtils.isNull(userList) || userList.size() == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ServiceException("导入用户数据不能为空!");
|
|
|
|
throw new ServiceException("导入用户数据不能为空!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int successNum = 0;
|
|
|
|
int successNum = 0;
|
|
|
@ -490,23 +449,18 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
StringBuilder successMsg = new StringBuilder();
|
|
|
|
StringBuilder successMsg = new StringBuilder();
|
|
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
|
|
String password = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
|
String password = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
|
for (SysUser user : userList)
|
|
|
|
for (SysUser user : userList) {
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 验证是否存在这个用户
|
|
|
|
// 验证是否存在这个用户
|
|
|
|
SysUser u = userMapper.selectUserByUserName(user.getUserName());
|
|
|
|
SysUser u = userMapper.selectUserByUserName(user.getUserName());
|
|
|
|
if (StringUtils.isNull(u))
|
|
|
|
if (StringUtils.isNull(u)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
BeanValidators.validateWithException(validator, user);
|
|
|
|
BeanValidators.validateWithException(validator, user);
|
|
|
|
user.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
|
user.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
|
user.setCreateBy(operName);
|
|
|
|
user.setCreateBy(operName);
|
|
|
|
userMapper.insertUser(user);
|
|
|
|
userMapper.insertUser(user);
|
|
|
|
successNum++;
|
|
|
|
successNum++;
|
|
|
|
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
|
|
|
|
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
|
|
|
|
}
|
|
|
|
} else if (isUpdateSupport) {
|
|
|
|
else if (isUpdateSupport)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BeanValidators.validateWithException(validator, user);
|
|
|
|
BeanValidators.validateWithException(validator, user);
|
|
|
|
checkUserAllowed(u);
|
|
|
|
checkUserAllowed(u);
|
|
|
|
checkUserDataScope(u.getUserId());
|
|
|
|
checkUserDataScope(u.getUserId());
|
|
|
@ -515,31 +469,43 @@ public class SysUserServiceImpl implements ISysUserService
|
|
|
|
userMapper.updateUser(user);
|
|
|
|
userMapper.updateUser(user);
|
|
|
|
successNum++;
|
|
|
|
successNum++;
|
|
|
|
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
|
|
|
|
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
failureNum++;
|
|
|
|
failureNum++;
|
|
|
|
failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
|
|
|
|
failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
failureNum++;
|
|
|
|
failureNum++;
|
|
|
|
String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
|
|
|
|
String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
|
|
|
|
failureMsg.append(msg + e.getMessage());
|
|
|
|
failureMsg.append(msg + e.getMessage());
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (failureNum > 0)
|
|
|
|
if (failureNum > 0) {
|
|
|
|
{
|
|
|
|
|
|
|
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
|
throw new ServiceException(failureMsg.toString());
|
|
|
|
throw new ServiceException(failureMsg.toString());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return successMsg.toString();
|
|
|
|
return successMsg.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param: tenantId
|
|
|
|
|
|
|
|
* @description 根据租户ID获取用户ID数组
|
|
|
|
|
|
|
|
* @author xins
|
|
|
|
|
|
|
|
* @date 2023-09-27 10:08
|
|
|
|
|
|
|
|
* @return Long[]
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Long[] getUserIdsByTenantId(Long tenantId) {
|
|
|
|
|
|
|
|
SysUser queryUser = new SysUser();
|
|
|
|
|
|
|
|
queryUser.setTenantId(tenantId);
|
|
|
|
|
|
|
|
List<SysUser> users = userMapper.selectUserList(queryUser);
|
|
|
|
|
|
|
|
if (users != null && !users.isEmpty()) {
|
|
|
|
|
|
|
|
return users.stream().
|
|
|
|
|
|
|
|
map(SysUser::getUserId).toArray(Long[]::new);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Long[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|