mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-17 20:45:06 +08:00
完成部门模块的迁移
This commit is contained in:
@ -2,17 +2,15 @@ package cn.iocoder.dashboard.modules.system.controller.dept;
|
||||
|
||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dept.SysDeptConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
@ -49,4 +47,39 @@ public class SysDeptController {
|
||||
return success(SysDeptConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@ApiOperation("获得部门信息")
|
||||
@ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:query')")
|
||||
@GetMapping("/get")
|
||||
public CommonResult<SysDeptRespVO> getDept(@RequestParam("id") Long id) {
|
||||
return success(SysDeptConvert.INSTANCE.convert(deptService.getDept(id)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增部门")
|
||||
@PostMapping("create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:add')")
|
||||
// @Log(title = "部门管理", businessType = BusinessType.INSERT)
|
||||
public CommonResult<Long> createDept(@Validated @RequestBody SysDeptCreateReqVO reqVO) {
|
||||
Long deptId = deptService.createDept(reqVO);
|
||||
return success(deptId);
|
||||
}
|
||||
|
||||
@ApiOperation("修改部门")
|
||||
@PostMapping("update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:edit')")
|
||||
// @Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateDept(@Validated @RequestBody SysDeptUpdateReqVO reqVO) {
|
||||
deptService.updateDept(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("删除部门")
|
||||
@ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024")
|
||||
@PostMapping("delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:remove')")
|
||||
// @Log(title = "部门管理", businessType = BusinessType.DELETE)
|
||||
public CommonResult<Boolean> deleteDept(@RequestParam("id") Long id) {
|
||||
deptService.deleteDept(id);
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
|
@ -40,4 +40,9 @@ public class SysDeptBaseVO {
|
||||
@Size(max = 50, message = "邮箱长度不能超过50个字符")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 SysCommonStatusEnum 枚举")
|
||||
@NotNull(message = "状态不能为空")
|
||||
// @InEnum(value = SysCommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
@ -3,12 +3,10 @@ package cn.iocoder.dashboard.modules.system.controller.dept.vo.dept;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@ApiModel("部门列表 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysDeptListReqVO extends SysDeptBaseVO {
|
||||
public class SysDeptListReqVO {
|
||||
|
||||
@ApiModelProperty(value = "部门名称", example = "芋道", notes = "模糊匹配")
|
||||
private String name;
|
||||
|
@ -15,9 +15,6 @@ public class SysDeptRespVO extends SysDeptBaseVO {
|
||||
@ApiModelProperty(value = "部门编号", required = true, example = "1024")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "祖级列表", required = true, example = "0,100")
|
||||
private String ancestors;
|
||||
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
|
||||
private Integer status;
|
||||
|
||||
|
@ -14,6 +14,6 @@ public class SysDeptUpdateReqVO extends SysDeptBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "部门编号", required = true, example = "1024")
|
||||
@NotNull(message = "部门编号不能为空")
|
||||
private Integer id;
|
||||
private Long id;
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package cn.iocoder.dashboard.modules.system.convert.dept;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@ -17,4 +19,10 @@ public interface SysDeptConvert {
|
||||
|
||||
List<SysDeptSimpleRespVO> convertList02(List<SysDeptDO> list);
|
||||
|
||||
SysDeptRespVO convert(SysDeptDO bean);
|
||||
|
||||
SysDeptDO convert(SysDeptCreateReqVO bean);
|
||||
|
||||
SysDeptDO convert(SysDeptUpdateReqVO bean);
|
||||
|
||||
}
|
||||
|
@ -21,4 +21,13 @@ public interface SysDeptMapper extends BaseMapper<SysDeptDO> {
|
||||
.eqIfPresent("status", reqVO.getStatus()));
|
||||
}
|
||||
|
||||
default SysDeptDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(new QueryWrapper<SysDeptDO>().eq("parent_id", parentId)
|
||||
.eq("name", name));
|
||||
}
|
||||
|
||||
default Integer selectCountByParentId(Long parentId) {
|
||||
return selectCount(new QueryWrapper<SysDeptDO>().eq("parent_id", parentId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,10 +32,6 @@ public class SysDeptDO extends BaseDO {
|
||||
* 外键 {@link #id}
|
||||
*/
|
||||
private Long parentId;
|
||||
/**
|
||||
* 祖级列表
|
||||
*/
|
||||
private String ancestors;
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
|
@ -43,9 +43,10 @@ public interface SysErrorCodeConstants {
|
||||
ErrorCode DEPT_PARENT_NOT_EXITS = new ErrorCode(1002004002,"父级部门不存在");
|
||||
ErrorCode DEPT_NOT_FOUND = new ErrorCode(1002004003, "当前部门不存在");
|
||||
ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1002004004, "存在子部门,无法删除");
|
||||
ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1002004005, "不能设置自己为父资源");
|
||||
ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1002004005, "不能设置自己为父部门");
|
||||
ErrorCode DEPT_EXISTS_USER = new ErrorCode(1002004006, "部门中存在员工,无法删除");
|
||||
ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1002004007, "部门不处于开启状态,不允许选择");
|
||||
ErrorCode DEPT_PARENT_IS_CHILD = new ErrorCode(1002004008, "不能设置自己的子部门为父部门");
|
||||
|
||||
// ========== 岗位模块 1002005000 ==========
|
||||
ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在");
|
||||
|
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.dashboard.modules.system.enums.dept;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 部门编号枚举
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DeptIdEnum {
|
||||
|
||||
/**
|
||||
* 根节点
|
||||
*/
|
||||
ROOT(0L);
|
||||
|
||||
private final Long id;
|
||||
|
||||
}
|
@ -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