mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
完成部门模块的迁移
This commit is contained in:
parent
7f171d14a4
commit
e4fd022ce1
@ -1,163 +0,0 @@
|
||||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
|
||||
/**
|
||||
* 部门信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/dept")
|
||||
public class SysDeptController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISysDeptService deptService;
|
||||
|
||||
/**
|
||||
* 获取部门列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:dept:list')")
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(SysDept dept)
|
||||
{
|
||||
List<SysDept> depts = deptService.selectDeptList(dept);
|
||||
return AjaxResult.success(depts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门列表(排除节点)
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:dept:list')")
|
||||
@GetMapping("/list/exclude/{deptId}")
|
||||
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
|
||||
{
|
||||
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
||||
Iterator<SysDept> it = depts.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
SysDept d = (SysDept) it.next();
|
||||
if (d.getDeptId().intValue() == deptId
|
||||
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return AjaxResult.success(depts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门编号获取详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:dept:query')")
|
||||
@GetMapping(value = "/{deptId}")
|
||||
public AjaxResult getInfo(@PathVariable Long deptId)
|
||||
{
|
||||
return AjaxResult.success(deptService.selectDeptById(deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门下拉树列表
|
||||
*/
|
||||
@GetMapping("/treeselect")
|
||||
public AjaxResult treeselect(SysDept dept)
|
||||
{
|
||||
List<SysDept> depts = deptService.selectDeptList(dept);
|
||||
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载对应角色部门列表树
|
||||
*/
|
||||
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
|
||||
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
|
||||
{
|
||||
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
||||
ajax.put("depts", deptService.buildDeptTreeSelect(depts));
|
||||
return ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增部门
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:dept:add')")
|
||||
@Log(title = "部门管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody SysDept dept)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
||||
{
|
||||
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||
}
|
||||
dept.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(deptService.insertDept(dept));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改部门
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:dept:edit')")
|
||||
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody SysDept dept)
|
||||
{
|
||||
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
||||
{
|
||||
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||
}
|
||||
else if (dept.getParentId().equals(dept.getDeptId()))
|
||||
{
|
||||
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
||||
}
|
||||
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
|
||||
&& deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
|
||||
{
|
||||
return AjaxResult.error("该部门包含未停用的子部门!");
|
||||
}
|
||||
dept.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(deptService.updateDept(dept));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:dept:remove')")
|
||||
@Log(title = "部门管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{deptId}")
|
||||
public AjaxResult remove(@PathVariable Long deptId)
|
||||
{
|
||||
if (deptService.hasChildByDeptId(deptId))
|
||||
{
|
||||
return AjaxResult.error("存在下级部门,不允许删除");
|
||||
}
|
||||
if (deptService.checkDeptExistUser(deptId))
|
||||
{
|
||||
return AjaxResult.error("部门存在用户,不允许删除");
|
||||
}
|
||||
return toAjax(deptService.deleteDeptById(deptId));
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.ruoyi.common.core.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tree基类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class TreeEntity extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 父菜单名称 */
|
||||
private String parentName;
|
||||
|
||||
/** 父菜单ID */
|
||||
private Long parentId;
|
||||
|
||||
/** 显示顺序 */
|
||||
private Integer orderNum;
|
||||
|
||||
/** 祖级列表 */
|
||||
private String ancestors;
|
||||
|
||||
/** 子部门 */
|
||||
private List<?> children = new ArrayList<>();
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.ruoyi.common.core.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysMenu;
|
||||
|
||||
/**
|
||||
* Treeselect树结构实体类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class TreeSelect implements Serializable {
|
||||
/** 节点ID */
|
||||
private Long id;
|
||||
|
||||
/** 节点名称 */
|
||||
private String label;
|
||||
|
||||
/** 子节点 */
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private List<TreeSelect> children;
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.ruoyi.common.core.domain.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 部门表 sys_dept
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SysDept extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 部门ID */
|
||||
private Long deptId;
|
||||
|
||||
/** 父部门ID */
|
||||
private Long parentId;
|
||||
|
||||
/** 祖级列表 */
|
||||
private String ancestors;
|
||||
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
|
||||
/** 显示顺序 */
|
||||
private String orderNum;
|
||||
|
||||
/** 负责人 */
|
||||
private String leader;
|
||||
|
||||
/** 联系电话 */
|
||||
private String phone;
|
||||
|
||||
/** 邮箱 */
|
||||
private String email;
|
||||
|
||||
/** 部门状态:0正常,1停用 */
|
||||
private String status;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
/** 父部门名称 */
|
||||
private String parentName;
|
||||
|
||||
/** 子部门 */
|
||||
private List<SysDept> children = new ArrayList<SysDept>();
|
||||
|
||||
|
||||
@NotBlank(message = "部门名称不能为空")
|
||||
@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
|
||||
public String getDeptName()
|
||||
{
|
||||
return deptName;
|
||||
}
|
||||
|
||||
@NotBlank(message = "显示顺序不能为空")
|
||||
public String getOrderNum()
|
||||
{
|
||||
return orderNum;
|
||||
}
|
||||
|
||||
@Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
|
||||
public String getPhone()
|
||||
{
|
||||
return phone;
|
||||
}
|
||||
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
|
||||
public String getEmail()
|
||||
{
|
||||
return email;
|
||||
}
|
||||
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.core.domain.TreeSelect;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
|
||||
/**
|
||||
* 部门管理 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysDeptService
|
||||
{
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 部门信息集合
|
||||
*/
|
||||
public List<SysDept> selectDeptList(SysDept dept);
|
||||
|
||||
/**
|
||||
* 构建前端所需要树结构
|
||||
*
|
||||
* @param depts 部门列表
|
||||
* @return 树结构列表
|
||||
*/
|
||||
public List<SysDept> buildDeptTree(List<SysDept> depts);
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param depts 部门列表
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中部门列表
|
||||
*/
|
||||
public List<Integer> selectDeptListByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据部门ID查询信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
public SysDept selectDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门(正常状态)
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 子部门数
|
||||
*/
|
||||
public int selectNormalChildrenDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 是否存在部门子节点
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean hasChildByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
public boolean checkDeptExistUser(Long deptId);
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public String checkDeptNameUnique(SysDept dept);
|
||||
|
||||
/**
|
||||
* 新增保存部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDept(SysDept dept);
|
||||
|
||||
/**
|
||||
* 修改保存部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDept(SysDept dept);
|
||||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
}
|
@ -1,306 +0,0 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.TreeSelect;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysDeptServiceImpl implements ISysDeptService
|
||||
{
|
||||
@Autowired
|
||||
private SysDeptMapper deptMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 部门信息集合
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysDept> selectDeptList(SysDept dept)
|
||||
{
|
||||
return deptMapper.selectDeptList(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端所需要树结构
|
||||
*
|
||||
* @param depts 部门列表
|
||||
* @return 树结构列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysDept> buildDeptTree(List<SysDept> depts)
|
||||
{
|
||||
List<SysDept> returnList = new ArrayList<SysDept>();
|
||||
List<Long> tempList = new ArrayList<Long>();
|
||||
for (SysDept dept : depts)
|
||||
{
|
||||
tempList.add(dept.getDeptId());
|
||||
}
|
||||
for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
|
||||
{
|
||||
SysDept dept = (SysDept) iterator.next();
|
||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||
if (!tempList.contains(dept.getParentId()))
|
||||
{
|
||||
recursionFn(depts, dept);
|
||||
returnList.add(dept);
|
||||
}
|
||||
}
|
||||
if (returnList.isEmpty())
|
||||
{
|
||||
returnList = depts;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param depts 部门列表
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
@Override
|
||||
public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts)
|
||||
{
|
||||
List<SysDept> deptTrees = buildDeptTree(depts);
|
||||
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中部门列表
|
||||
*/
|
||||
@Override
|
||||
public List<Integer> selectDeptListByRoleId(Long roleId)
|
||||
{
|
||||
SysRole role = roleMapper.selectRoleById(roleId);
|
||||
return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门ID查询信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
@Override
|
||||
public SysDept selectDeptById(Long deptId)
|
||||
{
|
||||
return deptMapper.selectDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门(正常状态)
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 子部门数
|
||||
*/
|
||||
@Override
|
||||
public int selectNormalChildrenDeptById(Long deptId)
|
||||
{
|
||||
return deptMapper.selectNormalChildrenDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在子节点
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean hasChildByDeptId(Long deptId)
|
||||
{
|
||||
int result = deptMapper.hasChildByDeptId(deptId);
|
||||
return result > 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
@Override
|
||||
public boolean checkDeptExistUser(Long deptId)
|
||||
{
|
||||
int result = deptMapper.checkDeptExistUser(deptId);
|
||||
return result > 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkDeptNameUnique(SysDept dept)
|
||||
{
|
||||
Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
||||
SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
|
||||
if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDept(SysDept dept)
|
||||
{
|
||||
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
||||
// 如果父节点不为正常状态,则不允许新增子节点
|
||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
|
||||
{
|
||||
throw new CustomException("部门停用,不允许新增");
|
||||
}
|
||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||
return deptMapper.insertDept(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDept(SysDept dept)
|
||||
{
|
||||
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
|
||||
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
|
||||
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
|
||||
{
|
||||
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
|
||||
String oldAncestors = oldDept.getAncestors();
|
||||
dept.setAncestors(newAncestors);
|
||||
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
||||
}
|
||||
int result = deptMapper.updateDept(dept);
|
||||
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
|
||||
{
|
||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||
updateParentDeptStatus(dept);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改该部门的父级部门状态
|
||||
*
|
||||
* @param dept 当前部门
|
||||
*/
|
||||
private void updateParentDeptStatus(SysDept dept)
|
||||
{
|
||||
String updateBy = dept.getUpdateBy();
|
||||
dept = deptMapper.selectDeptById(dept.getDeptId());
|
||||
dept.setUpdateBy(updateBy);
|
||||
deptMapper.updateDeptStatus(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改子元素关系
|
||||
*
|
||||
* @param deptId 被修改的部门ID
|
||||
* @param newAncestors 新的父ID集合
|
||||
* @param oldAncestors 旧的父ID集合
|
||||
*/
|
||||
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors)
|
||||
{
|
||||
List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);
|
||||
for (SysDept child : children)
|
||||
{
|
||||
child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
|
||||
}
|
||||
if (children.size() > 0)
|
||||
{
|
||||
deptMapper.updateDeptChildren(children);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeptById(Long deptId)
|
||||
{
|
||||
return deptMapper.deleteDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
private void recursionFn(List<SysDept> list, SysDept t)
|
||||
{
|
||||
// 得到子节点列表
|
||||
List<SysDept> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
for (SysDept tChild : childList)
|
||||
{
|
||||
if (hasChild(list, tChild))
|
||||
{
|
||||
recursionFn(list, tChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到子节点列表
|
||||
*/
|
||||
private List<SysDept> getChildList(List<SysDept> list, SysDept t)
|
||||
{
|
||||
List<SysDept> tlist = new ArrayList<SysDept>();
|
||||
Iterator<SysDept> it = list.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
SysDept n = (SysDept) it.next();
|
||||
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
|
||||
{
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有子节点
|
||||
*/
|
||||
private boolean hasChild(List<SysDept> list, SysDept t)
|
||||
{
|
||||
return getChildList(list, t).size() > 0 ? true : false;
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.domain.SysRoleDept;
|
||||
import com.ruoyi.system.domain.SysRoleMenu;
|
||||
import com.ruoyi.system.mapper.SysRoleDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
|
||||
/**
|
||||
* 角色 业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements ISysRoleService {
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysRole> selectRoleList(SysRole role) {
|
||||
return roleMapper.selectRoleList(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int authDataScope(SysRole role) {
|
||||
// 修改角色信息
|
||||
roleMapper.updateRole(role);
|
||||
// 删除角色与部门关联
|
||||
roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());
|
||||
// 新增角色和部门信息(数据权限)
|
||||
return insertRoleDept(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除角色信息
|
||||
*
|
||||
* @param roleIds 需要删除的角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteRoleByIds(Long[] roleIds) {
|
||||
for (Long roleId : roleIds) {
|
||||
checkRoleAllowed(new SysRole(roleId));
|
||||
SysRole role = selectRoleById(roleId);
|
||||
if (countUserRoleByRoleId(roleId) > 0) {
|
||||
throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName()));
|
||||
}
|
||||
}
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteRoleMenu(roleIds);
|
||||
// 删除角色与部门关联
|
||||
roleDeptMapper.deleteRoleDept(roleIds);
|
||||
return roleMapper.deleteRoleByIds(roleIds);
|
||||
}
|
||||
}
|
@ -1,331 +0,0 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.SysPost;
|
||||
import com.ruoyi.system.domain.SysUserPost;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.mapper.SysPostMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.mapper.SysUserPostMapper;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
|
||||
/**
|
||||
* 用户 业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysUserServiceImpl implements ISysUserService {
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u")
|
||||
public List<SysUser> selectUserList(SysUser user) {
|
||||
return userMapper.selectUserList(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户所属角色组
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户角色信息
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户岗位信息
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
public void insertUserPost(SysUser user) {
|
||||
Long[] posts = user.getPostIds();
|
||||
if (StringUtils.isNotNull(posts)) {
|
||||
// 新增用户与岗位管理
|
||||
List<SysUserPost> list = new ArrayList<SysUserPost>();
|
||||
for (Long postId : posts) {
|
||||
SysUserPost up = new SysUserPost();
|
||||
up.setUserId(user.getUserId());
|
||||
up.setPostId(postId);
|
||||
list.add(up);
|
||||
}
|
||||
if (list.size() > 0) {
|
||||
userPostMapper.batchUserPost(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteUserById(Long userId) {
|
||||
// 删除用户与角色关联
|
||||
userRoleMapper.deleteUserRoleByUserId(userId);
|
||||
// 删除用户与岗位表
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入用户数据
|
||||
*
|
||||
* @param userList 用户数据列表
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
* @param operName 操作用户
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) {
|
||||
if (StringUtils.isNull(userList) || userList.size() == 0) {
|
||||
throw new CustomException("导入用户数据不能为空!");
|
||||
}
|
||||
int successNum = 0;
|
||||
int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
String password = configService.selectConfigByKey("sys.user.initPassword");
|
||||
for (SysUser user : userList) {
|
||||
try {
|
||||
// 验证是否存在这个用户
|
||||
SysUser u = userMapper.selectUserByUserName(user.getUserName());
|
||||
if (StringUtils.isNull(u)) {
|
||||
user.setPassword(SecurityUtils.encryptPassword(password));
|
||||
user.setCreateBy(operName);
|
||||
this.insertUser(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
|
||||
} else if (isUpdateSupport) {
|
||||
user.setUpdateBy(operName);
|
||||
this.updateUser(user);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
|
||||
failureMsg.append(msg + e.getMessage());
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
if (failureNum > 0) {
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new CustomException(failureMsg.toString());
|
||||
} else {
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ export function listDeptExcludeChild(deptId) {
|
||||
// 查询部门详细
|
||||
export function getDept(deptId) {
|
||||
return request({
|
||||
url: '/system/dept/' + deptId,
|
||||
url: '/system/dept/get?id=' + deptId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
@ -36,7 +36,7 @@ export function listSimpleDepts() {
|
||||
// 新增部门
|
||||
export function addDept(data) {
|
||||
return request({
|
||||
url: '/system/dept',
|
||||
url: '/system/dept/create',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
@ -45,19 +45,16 @@ export function addDept(data) {
|
||||
// 修改部门
|
||||
export function updateDept(data) {
|
||||
return request({
|
||||
url: '/system/dept',
|
||||
method: 'put',
|
||||
url: '/system/dept/update',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除部门
|
||||
export function delDept(deptId) {
|
||||
export function delDept(id) {
|
||||
return request({
|
||||
url: '/system/dept/' + deptId,
|
||||
method: 'delete'
|
||||
url: '/system/dept/delete?id=' + id,
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
export class treeselect {
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
|
||||
<el-form-item label="部门名称" prop="deptName">
|
||||
<el-form-item label="部门名称" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.deptName"
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入部门名称"
|
||||
clearable
|
||||
size="small"
|
||||
@ -11,12 +11,12 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="部门状态" clearable size="small">
|
||||
<el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small">
|
||||
<el-option
|
||||
v-for="dict in statusOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictLabel"
|
||||
:value="dict.dictValue"
|
||||
v-for="dict in statusDictDatas"
|
||||
:key="parseInt(dict.value)"
|
||||
:label="dict.label"
|
||||
:value="parseInt(dict.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@ -42,12 +42,12 @@
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="deptList"
|
||||
row-key="deptId"
|
||||
row-key="id"
|
||||
default-expand-all
|
||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||
>
|
||||
<el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
|
||||
<el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
|
||||
<el-table-column prop="name" label="部门名称" width="260"></el-table-column>
|
||||
<el-table-column prop="sort" label="排序" width="200"></el-table-column>
|
||||
<el-table-column prop="status" label="状态" :formatter="statusFormat" width="100"></el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="200">
|
||||
<template slot-scope="scope">
|
||||
@ -56,22 +56,22 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['system:dept:edit']"
|
||||
>修改</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-plus"
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-plus"
|
||||
@click="handleAdd(scope.row)"
|
||||
v-hasPermi="['system:dept:add']"
|
||||
>新增</el-button>
|
||||
<el-button
|
||||
v-if="scope.row.parentId != 0"
|
||||
v-if="scope.row.parentId !== 0"
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@ -92,13 +92,13 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="部门名称" prop="deptName">
|
||||
<el-input v-model="form.deptName" placeholder="请输入部门名称" />
|
||||
<el-form-item label="部门名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入部门名称" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="显示排序" prop="orderNum">
|
||||
<el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
|
||||
<el-form-item label="显示排序" prop="sort">
|
||||
<el-input-number v-model="form.sort" controls-position="right" :min="0" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
@ -117,13 +117,13 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="部门状态">
|
||||
<el-form-item label="部门状态" prop="status">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio
|
||||
v-for="dict in statusOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictValue"
|
||||
>{{dict.dictLabel}}</el-radio>
|
||||
v-for="dict in statusDictDatas"
|
||||
:key="parseInt(dict.value)"
|
||||
:label="parseInt(dict.value)"
|
||||
>{{dict.label}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -138,10 +138,13 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept";
|
||||
import { listDept, getDept, delDept, addDept, updateDept } from "@/api/system/dept";
|
||||
import Treeselect from "@riophae/vue-treeselect";
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
|
||||
import {SysCommonStatusEnum, SysMenuTypeEnum} from '@/utils/constants'
|
||||
import { getDictDataLabel, getDictDatas, DICT_TYPE } from '@/utils/dict'
|
||||
|
||||
export default {
|
||||
name: "Dept",
|
||||
components: { Treeselect },
|
||||
@ -163,7 +166,7 @@ export default {
|
||||
statusOptions: [],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
deptName: undefined,
|
||||
name: undefined,
|
||||
status: undefined
|
||||
},
|
||||
// 表单参数
|
||||
@ -173,10 +176,10 @@ export default {
|
||||
parentId: [
|
||||
{ required: true, message: "上级部门不能为空", trigger: "blur" }
|
||||
],
|
||||
deptName: [
|
||||
name: [
|
||||
{ required: true, message: "部门名称不能为空", trigger: "blur" }
|
||||
],
|
||||
orderNum: [
|
||||
sort: [
|
||||
{ required: true, message: "显示排序不能为空", trigger: "blur" }
|
||||
],
|
||||
email: [
|
||||
@ -192,22 +195,27 @@ export default {
|
||||
message: "请输入正确的手机号码",
|
||||
trigger: "blur"
|
||||
}
|
||||
],
|
||||
status: [
|
||||
{ required: true, message: "状态不能为空", trigger: "blur" }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
// 枚举
|
||||
CommonStatusEnum: SysCommonStatusEnum,
|
||||
// 数据字典
|
||||
statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
this.getDicts("sys_normal_disable").then(response => {
|
||||
this.statusOptions = response.data;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
/** 查询部门列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listDept(this.queryParams).then(response => {
|
||||
this.deptList = this.handleTree(response.data, "deptId");
|
||||
this.deptList = this.handleTree(response.data, "id");
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
@ -217,14 +225,14 @@ export default {
|
||||
delete node.children;
|
||||
}
|
||||
return {
|
||||
id: node.deptId,
|
||||
label: node.deptName,
|
||||
id: node.id,
|
||||
label: node.name,
|
||||
children: node.children
|
||||
};
|
||||
},
|
||||
// 字典状态字典翻译
|
||||
statusFormat(row, column) {
|
||||
return this.selectDictLabel(this.statusOptions, row.status);
|
||||
return getDictDataLabel(DICT_TYPE.SYS_COMMON_STATUS, row.status)
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
@ -234,10 +242,10 @@ export default {
|
||||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
deptId: undefined,
|
||||
id: undefined,
|
||||
parentId: undefined,
|
||||
deptName: undefined,
|
||||
orderNum: undefined,
|
||||
name: undefined,
|
||||
sort: undefined,
|
||||
leader: undefined,
|
||||
phone: undefined,
|
||||
email: undefined,
|
||||
@ -257,32 +265,32 @@ export default {
|
||||
/** 新增按钮操作 */
|
||||
handleAdd(row) {
|
||||
this.reset();
|
||||
if (row != undefined) {
|
||||
this.form.parentId = row.deptId;
|
||||
if (row !== undefined) {
|
||||
this.form.parentId = row.id;
|
||||
}
|
||||
this.open = true;
|
||||
this.title = "添加部门";
|
||||
listDept().then(response => {
|
||||
this.deptOptions = this.handleTree(response.data, "deptId");
|
||||
this.deptOptions = this.handleTree(response.data, "id");
|
||||
});
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
getDept(row.deptId).then(response => {
|
||||
getDept(row.id).then(response => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = "修改部门";
|
||||
});
|
||||
listDeptExcludeChild(row.deptId).then(response => {
|
||||
this.deptOptions = this.handleTree(response.data, "deptId");
|
||||
listDept(row.id).then(response => {
|
||||
this.deptOptions = this.handleTree(response.data, "id");
|
||||
});
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm: function() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.deptId != undefined) {
|
||||
if (this.form.id !== undefined) {
|
||||
updateDept(this.form).then(response => {
|
||||
this.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
@ -300,12 +308,12 @@ export default {
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
this.$confirm('是否确认删除名称为"' + row.deptName + '"的数据项?', "警告", {
|
||||
this.$confirm('是否确认删除名称为"' + row.name + '"的数据项?', "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function() {
|
||||
return delDept(row.deptId);
|
||||
return delDept(row.id);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.msgSuccess("删除成功");
|
||||
@ -313,4 +321,4 @@ export default {
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</script>
|
||||
|
@ -163,9 +163,10 @@
|
||||
<el-form-item v-if="form.type != '3'" label="菜单状态">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio
|
||||
v-for="dict in statusDictDatas"
|
||||
:key="dict.value"
|
||||
:label="parseInt(dict.value)"
|
||||
v-for="dict in statusDictDatas"
|
||||
:key="parseInt(dict.value)"
|
||||
:label="dict.label"
|
||||
:value="parseInt(dict.value)"
|
||||
>{{dict.label}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
@ -223,6 +224,9 @@ export default {
|
||||
],
|
||||
path: [
|
||||
{ required: true, message: "路由地址不能为空", trigger: "blur" }
|
||||
],
|
||||
status: [
|
||||
{ required: true, message: "状态不能为空", trigger: "blur" }
|
||||
]
|
||||
},
|
||||
|
||||
|
@ -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);
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user