完成用户的添加和修改的逻辑
This commit is contained in:
@@ -50,4 +50,12 @@ public interface SysDeptService {
|
||||
*/
|
||||
List<SysDeptDO> listDeptsByParentIdFromCache(Long parentId, boolean recursive);
|
||||
|
||||
/**
|
||||
* 获得部门信息
|
||||
*
|
||||
* @param id 部门编号
|
||||
* @return 部门信息
|
||||
*/
|
||||
SysDeptDO getDept(Long id);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.dept;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 岗位 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SysPostService {
|
||||
|
||||
/**
|
||||
* 获得所有岗位列表
|
||||
*
|
||||
* @param ids 岗位编号数组。如果为空,不进行筛选
|
||||
* @param statuses 状态数组。如果为空,不进行筛选
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysPostDO> listPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
|
||||
|
||||
}
|
||||
@@ -114,4 +114,9 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
recursiveCount - 1, parentDeptMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDeptDO getDept(Long id) {
|
||||
return deptMapper.selectById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.dept.impl;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysPostMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 岗位 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class SysPostServiceImpl implements SysPostService {
|
||||
|
||||
@Resource
|
||||
private SysPostMapper postMapper;
|
||||
|
||||
@Override
|
||||
public List<SysPostDO> listPosts(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
return postMapper.selectList(ids, statuses);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -170,55 +170,6 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||
return menuMapper.selectById(id);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获得菜单列表
|
||||
// *
|
||||
// * @param menuIds 菜单编号列表
|
||||
// * @return 菜单列表
|
||||
// */
|
||||
// public List<ResourceBO> listResources(List<Integer> menuIds) {
|
||||
// List<ResourceDO> menuDOs = menuMapper.selectBatchIds(menuIds);
|
||||
// return ResourceConvert.INSTANCE.convertList(menuDOs);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获得菜单全列表
|
||||
// *
|
||||
// * @return 菜单全列表
|
||||
// */
|
||||
// public List<ResourceBO> listResources() {
|
||||
// List<ResourceDO> menuDOs = menuMapper.selectList(null);
|
||||
// return ResourceConvert.INSTANCE.convertList(menuDOs);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获得指定类型的菜单列表
|
||||
// *
|
||||
// * @param type 菜单类型,允许空
|
||||
// * @return 菜单列表
|
||||
// */
|
||||
// public List<ResourceBO> listResourcesByType(Integer type) {
|
||||
// List<ResourceDO> menuDOs = menuMapper.selectListByType(type);
|
||||
// return ResourceConvert.INSTANCE.convertList(menuDOs);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获得角色拥有的菜单列表
|
||||
// *
|
||||
// * @param roleIds 角色编号
|
||||
// * @param type 菜单类型,允许空
|
||||
// * @return 菜单列表
|
||||
// */
|
||||
// public List<ResourceBO> listRoleResourcesByType(Collection<Integer> roleIds, Integer type) {
|
||||
// List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds);
|
||||
// if (CollectionUtils.isEmpty(roleResourceDOs)) {
|
||||
// return Collections.emptyList();
|
||||
// }
|
||||
// List<ResourceDO> menuDOs = menuMapper.selectListByIdsAndType(
|
||||
// CollectionUtils.convertSet(roleResourceDOs, RoleResourceDO::getResourceId), type);
|
||||
// return ResourceConvert.INSTANCE.convertList(menuDOs);
|
||||
// }
|
||||
//
|
||||
/**
|
||||
* 校验父菜单是否合法
|
||||
*
|
||||
@@ -263,7 +214,7 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 menuId 为空,说明不用比较是否为相同 menuId 的菜单
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的菜单
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.user;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
|
||||
|
||||
/**
|
||||
@@ -29,10 +31,10 @@ public interface SysUserService {
|
||||
/**
|
||||
* 通过用户 ID 查询用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param id 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserDO getUser(Long userId);
|
||||
SysUserDO getUser(Long id);
|
||||
|
||||
/**
|
||||
* 获得用户分页列表
|
||||
@@ -42,6 +44,21 @@ public interface SysUserService {
|
||||
*/
|
||||
PageResult<SysUserDO> pageUsers(SysUserPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*
|
||||
* @param reqVO 用户信息
|
||||
* @return 用户编号
|
||||
*/
|
||||
Long createUser(SysUserCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*
|
||||
* @param reqVO 用户信息
|
||||
*/
|
||||
void updateUser(SysUserUpdateReqVO reqVO);
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 根据用户ID查询用户所属角色组
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.user.SysUserMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
|
||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,16 +43,12 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
|
||||
@Resource
|
||||
private SysDeptService deptService;
|
||||
@Resource
|
||||
private SysPostService postService;
|
||||
|
||||
@Resource
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
// @Autowired
|
||||
// private SysUserMapper userMapper;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysRoleMapper roleMapper;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysPostMapper postMapper;
|
||||
//
|
||||
// @Autowired
|
||||
// private SysUserRoleMapper userRoleMapper;
|
||||
//
|
||||
@@ -68,8 +77,8 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserDO getUser(Long userId) {
|
||||
return userMapper.selectById(userId);
|
||||
public SysUserDO getUser(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,240 +86,148 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
// 处理部门查询条件
|
||||
List<Long> deptIds = Collections.emptyList();
|
||||
if (reqVO.getDeptId() != null) {
|
||||
deptIds = CollectionUtils.convertList(deptService.listDeptsByParentIdFromCache(reqVO.getDeptId(), true),
|
||||
SysDeptDO::getId);
|
||||
deptIds = CollectionUtils.convertList(deptService.listDeptsByParentIdFromCache(
|
||||
reqVO.getDeptId(), true), SysDeptDO::getId);
|
||||
deptIds.add(reqVO.getDeptId());
|
||||
}
|
||||
// 执行查询
|
||||
return SysUserConvert.INSTANCE.convertPage(userMapper.selectList(reqVO, deptIds));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 通过用户ID查询用户
|
||||
// *
|
||||
// * @param userId 用户ID
|
||||
// * @return 用户对象信息
|
||||
// */
|
||||
// @Override
|
||||
// public SysUser selectUserById(Long userId)
|
||||
// {
|
||||
// return userMapper.selectUserById(userId);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 查询用户所属角色组
|
||||
// *
|
||||
// * @param userName 用户名
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public String selectUserRoleGroup(String userName)
|
||||
// {
|
||||
// List<SysRole> list = roleMapper.selectRolesByUserName(userName);
|
||||
// StringBuffer idsStr = new StringBuffer();
|
||||
// for (SysRole role : list)
|
||||
// {
|
||||
// idsStr.append(role.getRoleName()).append(",");
|
||||
// }
|
||||
// if (StringUtils.isNotEmpty(idsStr.toString()))
|
||||
// {
|
||||
// return idsStr.substring(0, idsStr.length() - 1);
|
||||
// }
|
||||
// return idsStr.toString();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 查询用户所属岗位组
|
||||
// *
|
||||
// * @param userName 用户名
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public String selectUserPostGroup(String userName)
|
||||
// {
|
||||
// List<SysPost> list = postMapper.selectPostsByUserName(userName);
|
||||
// StringBuffer idsStr = new StringBuffer();
|
||||
// for (SysPost post : list)
|
||||
// {
|
||||
// idsStr.append(post.getPostName()).append(",");
|
||||
// }
|
||||
// if (StringUtils.isNotEmpty(idsStr.toString()))
|
||||
// {
|
||||
// return idsStr.substring(0, idsStr.length() - 1);
|
||||
// }
|
||||
// return idsStr.toString();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 校验用户名称是否唯一
|
||||
// *
|
||||
// * @param userName 用户名称
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public String checkUserNameUnique(String userName)
|
||||
// {
|
||||
// int count = userMapper.checkUserNameUnique(userName);
|
||||
// if (count > 0)
|
||||
// {
|
||||
// return UserConstants.NOT_UNIQUE;
|
||||
// }
|
||||
// return UserConstants.UNIQUE;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 校验用户名称是否唯一
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public String checkPhoneUnique(SysUser user)
|
||||
// {
|
||||
// Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
||||
// SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
|
||||
// if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
|
||||
// {
|
||||
// return UserConstants.NOT_UNIQUE;
|
||||
// }
|
||||
// return UserConstants.UNIQUE;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 校验email是否唯一
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public String checkEmailUnique(SysUser user)
|
||||
// {
|
||||
// Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
||||
// SysUser info = userMapper.checkEmailUnique(user.getEmail());
|
||||
// if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
|
||||
// {
|
||||
// return UserConstants.NOT_UNIQUE;
|
||||
// }
|
||||
// return UserConstants.UNIQUE;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 校验用户是否允许操作
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// */
|
||||
// @Override
|
||||
// public void checkUserAllowed(SysUser user)
|
||||
// {
|
||||
// if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin())
|
||||
// {
|
||||
// throw new CustomException("不允许操作超级管理员用户");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 新增保存用户信息
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional
|
||||
// public int insertUser(SysUser user)
|
||||
// {
|
||||
// // 新增用户信息
|
||||
// int rows = userMapper.insertUser(user);
|
||||
// // 新增用户岗位关联
|
||||
// insertUserPost(user);
|
||||
// // 新增用户与角色管理
|
||||
// insertUserRole(user);
|
||||
// return rows;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改保存用户信息
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional
|
||||
// public int updateUser(SysUser user)
|
||||
// {
|
||||
// Long userId = user.getUserId();
|
||||
// // 删除用户与角色关联
|
||||
// userRoleMapper.deleteUserRoleByUserId(userId);
|
||||
// // 新增用户与角色管理
|
||||
// insertUserRole(user);
|
||||
// // 删除用户与岗位关联
|
||||
// userPostMapper.deleteUserPostByUserId(userId);
|
||||
// // 新增用户与岗位管理
|
||||
// insertUserPost(user);
|
||||
// return userMapper.updateUser(user);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改用户状态
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int updateUserStatus(SysUser user)
|
||||
// {
|
||||
// return userMapper.updateUser(user);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改用户基本信息
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int updateUserProfile(SysUser user)
|
||||
// {
|
||||
// return userMapper.updateUser(user);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改用户头像
|
||||
// *
|
||||
// * @param userName 用户名
|
||||
// * @param avatar 头像地址
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public boolean updateUserAvatar(String userName, String avatar)
|
||||
// {
|
||||
// return userMapper.updateUserAvatar(userName, avatar) > 0;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 重置用户密码
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int resetPwd(SysUser user)
|
||||
// {
|
||||
// return userMapper.updateUser(user);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 重置用户密码
|
||||
// *
|
||||
// * @param userName 用户名
|
||||
// * @param password 密码
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// public int resetUserPwd(String userName, String password)
|
||||
// {
|
||||
// return userMapper.resetUserPwd(userName, password);
|
||||
// }
|
||||
//
|
||||
@Override
|
||||
public Long createUser(SysUserCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
// 插入用户
|
||||
SysUserDO user = SysUserConvert.INSTANCE.convert(reqVO);
|
||||
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
|
||||
user.setPassword(passwordEncoder.encode(reqVO.getPassword())); // 加密密码
|
||||
userMapper.insert(user);
|
||||
return user.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(SysUserUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
// 更新用户
|
||||
SysUserDO updateObj = SysUserConvert.INSTANCE.convert(reqVO);
|
||||
userMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String username, String mobile, String email,
|
||||
Long deptId, Set<Long> postIds) {
|
||||
// 校验用户存在
|
||||
this.checkUserExists(id);
|
||||
// 校验用户名唯一
|
||||
this.checkUsernameUnique(id, username);
|
||||
// 校验手机号唯一
|
||||
this.checkMobileUnique(id, mobile);
|
||||
// 校验邮箱唯一
|
||||
this.checkEmailUnique(id, email);
|
||||
// 校验部门处于开启状态
|
||||
this.checkDeptEnable(deptId);
|
||||
// 校验岗位处于开启状态
|
||||
this.checkPostEnable(postIds);
|
||||
}
|
||||
|
||||
private void checkUserExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
SysUserDO user = userMapper.selectById(id);
|
||||
if (user == null) {
|
||||
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUsernameUnique(Long id, String username) {
|
||||
if (StrUtil.isNotBlank(username)) {
|
||||
return;
|
||||
}
|
||||
SysUserDO user = userMapper.selectByUsername(username);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(USER_USERNAME_EXISTS);
|
||||
}
|
||||
if (!user.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(USER_USERNAME_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEmailUnique(Long id, String email) {
|
||||
if (StrUtil.isNotBlank(email)) {
|
||||
return;
|
||||
}
|
||||
SysUserDO user = userMapper.selectByEmail(email);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(USER_EMAIL_EXISTS);
|
||||
}
|
||||
if (!user.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(USER_EMAIL_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMobileUnique(Long id, String email) {
|
||||
if (StrUtil.isNotBlank(email)) {
|
||||
return;
|
||||
}
|
||||
SysUserDO user = userMapper.selectByMobile(email);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(USER_MOBILE_EXISTS);
|
||||
}
|
||||
if (!user.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(USER_MOBILE_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeptEnable(Long deptId) {
|
||||
if (deptId == null) { // 允许不选择
|
||||
return;
|
||||
}
|
||||
SysDeptDO dept = deptService.getDept(deptId);
|
||||
if (dept == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NOT_FOUND);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPostEnable(Set<Long> postIds) {
|
||||
if (CollUtil.isEmpty(postIds)) { // 允许不选择
|
||||
return;
|
||||
}
|
||||
List<SysPostDO> posts = postService.listPosts(postIds, null);
|
||||
if (CollUtil.isEmpty(posts)) {
|
||||
throw ServiceExceptionUtil.exception(POST_NOT_FOUND);
|
||||
}
|
||||
Map<Long, SysPostDO> postMap = CollectionUtils.convertMap(posts, SysPostDO::getId);
|
||||
postIds.forEach(postId -> {
|
||||
SysPostDO post = postMap.get(postId);
|
||||
if (post == null) {
|
||||
throw ServiceExceptionUtil.exception(POST_NOT_FOUND);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(post.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(POST_NOT_ENABLE, post.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 新增用户角色信息
|
||||
// *
|
||||
@@ -379,28 +296,8 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
// userPostMapper.deleteUserPostByUserId(userId);
|
||||
// return userMapper.deleteUserById(userId);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 批量删除用户信息
|
||||
// *
|
||||
// * @param userIds 需要删除的用户ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional
|
||||
// public int deleteUserByIds(Long[] userIds)
|
||||
// {
|
||||
// for (Long userId : userIds)
|
||||
// {
|
||||
// checkUserAllowed(new SysUser(userId));
|
||||
// }
|
||||
// // 删除用户与角色关联
|
||||
// userRoleMapper.deleteUserRole(userIds);
|
||||
// // 删除用户与岗位关联
|
||||
// userPostMapper.deleteUserPost(userIds);
|
||||
// return userMapper.deleteUserByIds(userIds);
|
||||
// }
|
||||
//
|
||||
|
||||
|
||||
// /**
|
||||
// * 导入用户数据
|
||||
// *
|
||||
|
||||
Reference in New Issue
Block a user