完成部门模块的迁移
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.dept;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -58,4 +60,26 @@ public interface SysDeptService {
|
||||
*/
|
||||
SysDeptDO getDept(Long id);
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*
|
||||
* @param reqVO 部门信息
|
||||
* @return 部门编号
|
||||
*/
|
||||
Long createDept(SysDeptCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*
|
||||
* @param reqVO 部门信息
|
||||
*/
|
||||
void updateDept(SysDeptUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*
|
||||
* @param id 部门编号
|
||||
*/
|
||||
void deleteDept(Long id);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.dept.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dept.SysDeptConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysDeptMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.dashboard.modules.system.enums.dept.DeptIdEnum;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
@@ -18,6 +24,8 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 部门 Service 实现类
|
||||
*
|
||||
@@ -119,4 +127,105 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
return deptMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createDept(SysDeptCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName());
|
||||
// 插入部门
|
||||
SysDeptDO dept = SysDeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.insert(dept);
|
||||
return dept.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDept(SysDeptUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
|
||||
// 更新部门
|
||||
SysDeptDO updateObj = SysDeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDept(Long id) {
|
||||
// 校验是否存在
|
||||
checkDeptExists(id);
|
||||
// 校验是否有子部门
|
||||
if (deptMapper.selectCountByParentId(id) > 0) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除部门
|
||||
deptMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, Long parentId, String name) {
|
||||
// 校验自己存在
|
||||
checkDeptExists(id);
|
||||
// 校验父部门的有效性
|
||||
checkParentDeptEnable(id, parentId);
|
||||
// 校验部门名的唯一性
|
||||
checkDeptNameUnique(id, parentId, name);
|
||||
}
|
||||
|
||||
private void checkParentDeptEnable(Long id, Long parentId) {
|
||||
if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) {
|
||||
return;
|
||||
}
|
||||
// 不能设置自己为父部门
|
||||
if (parentId.equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR);
|
||||
}
|
||||
// 父菜单不存在
|
||||
SysDeptDO dept = deptMapper.selectById(parentId);
|
||||
if (dept == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS);
|
||||
}
|
||||
// 父部门被禁用
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE);
|
||||
}
|
||||
// 父部门不能是原来的子部门
|
||||
List<SysDeptDO> children = this.listDeptsByParentIdFromCache(id, true);
|
||||
if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_IS_CHILD);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeptExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
SysDeptDO dept = deptMapper.selectById(id);
|
||||
if (dept == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeptNameUnique(Long id, Long parentId, String name) {
|
||||
SysDeptDO menu = deptMapper.selectByParentIdAndName(parentId, name);
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的菜单
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
|
||||
}
|
||||
if (!menu.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 查询部门管理数据
|
||||
// *
|
||||
// * @param dept 部门信息
|
||||
// * @return 部门信息集合
|
||||
// */
|
||||
// @Override
|
||||
// @DataScope(deptAlias = "d")
|
||||
// public List<SysDept> selectDeptList(SysDept dept)
|
||||
// {
|
||||
// return deptMapper.selectDeptList(dept);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -206,4 +206,16 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 根据条件分页查询角色数据
|
||||
// *
|
||||
// * @param role 角色信息
|
||||
// * @return 角色数据集合信息
|
||||
// */
|
||||
// @Override
|
||||
// @DataScope(deptAlias = "d")
|
||||
// public List<SysRole> selectRoleList(SysRole role) {
|
||||
// return roleMapper.selectRoleList(role);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -253,33 +253,6 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 新增用户角色信息
|
||||
// *
|
||||
// * @param user 用户对象
|
||||
// */
|
||||
// public void insertUserRole(SysUser user)
|
||||
// {
|
||||
// Long[] roles = user.getRoleIds();
|
||||
// if (StringUtils.isNotNull(roles))
|
||||
// {
|
||||
// // 新增用户与角色管理
|
||||
// List<SysUserRole> list = new ArrayList<SysUserRole>();
|
||||
// for (Long roleId : roles)
|
||||
// {
|
||||
// SysUserRole ur = new SysUserRole();
|
||||
// ur.setUserId(user.getUserId());
|
||||
// ur.setRoleId(roleId);
|
||||
// list.add(ur);
|
||||
// }
|
||||
// if (list.size() > 0)
|
||||
// {
|
||||
// userRoleMapper.batchUserRole(list);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 导入用户数据
|
||||
// *
|
||||
@@ -347,4 +320,15 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
// return successMsg.toString();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 根据条件分页查询用户列表
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 用户信息集合信息
|
||||
// */
|
||||
// @Override
|
||||
// @DataScope(deptAlias = "d", userAlias = "u")
|
||||
// public List<SysUser> selectUserList(SysUser user) {
|
||||
// return userMapper.selectUserList(user);
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user