From e4fd022ce1db21dd784e7c25ced8a14dc4789642 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 11 Jan 2021 21:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=83=A8=E9=97=A8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysDeptController.java | 163 --------- .../ruoyi/common/core/domain/TreeEntity.java | 30 -- .../ruoyi/common/core/domain/TreeSelect.java | 26 -- .../common/core/domain/entity/SysDept.java | 84 ----- .../ruoyi/system/service/ISysDeptService.java | 109 ------ .../service/impl/SysDeptServiceImpl.java | 306 ---------------- .../service/impl/SysRoleServiceImpl.java | 85 ----- .../service/impl/SysUserServiceImpl.java | 331 ------------------ ruoyi-ui/src/api/system/dept.js | 17 +- ruoyi-ui/src/views/system/dept/index.vue | 114 +++--- ruoyi-ui/src/views/system/menu/index.vue | 10 +- .../controller/dept/SysDeptController.java | 45 ++- .../dept/vo/dept/SysDeptBaseVO.java | 5 + .../dept/vo/dept/SysDeptListReqVO.java | 4 +- .../dept/vo/dept/SysDeptRespVO.java | 3 - .../dept/vo/dept/SysDeptUpdateReqVO.java | 2 +- .../system/convert/dept/SysDeptConvert.java | 8 + .../dal/mysql/dao/dept/SysDeptMapper.java | 9 + .../dal/mysql/dataobject/dept/SysDeptDO.java | 4 - .../system/enums/SysErrorCodeConstants.java | 3 +- .../modules/system/enums/dept/DeptIdEnum.java | 20 ++ .../system/service/dept/SysDeptService.java | 24 ++ .../service/dept/impl/SysDeptServiceImpl.java | 109 ++++++ .../permission/impl/SysRoleServiceImpl.java | 12 + .../service/user/SysUserServiceImpl.java | 38 +- 25 files changed, 316 insertions(+), 1245 deletions(-) delete mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeEntity.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/enums/dept/DeptIdEnum.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java deleted file mode 100644 index 60bd1a5b59..0000000000 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java +++ /dev/null @@ -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 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 depts = deptService.selectDeptList(new SysDept()); - Iterator 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 depts = deptService.selectDeptList(dept); - return AjaxResult.success(deptService.buildDeptTreeSelect(depts)); - } - - /** - * 加载对应角色部门列表树 - */ - @GetMapping(value = "/roleDeptTreeselect/{roleId}") - public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) - { - List 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)); - } -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeEntity.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeEntity.java deleted file mode 100644 index 8a26324833..0000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeEntity.java +++ /dev/null @@ -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<>(); - -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java deleted file mode 100644 index 1993939071..0000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java +++ /dev/null @@ -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 children; - -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java deleted file mode 100644 index 8ae2b83dc1..0000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java +++ /dev/null @@ -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 children = new ArrayList(); - - - @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; - } - -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java deleted file mode 100644 index e3850cf222..0000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java +++ /dev/null @@ -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 selectDeptList(SysDept dept); - - /** - * 构建前端所需要树结构 - * - * @param depts 部门列表 - * @return 树结构列表 - */ - public List buildDeptTree(List depts); - - /** - * 构建前端所需要下拉树结构 - * - * @param depts 部门列表 - * @return 下拉树结构列表 - */ - public List buildDeptTreeSelect(List depts); - - /** - * 根据角色ID查询部门树信息 - * - * @param roleId 角色ID - * @return 选中部门列表 - */ - public List 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); -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java deleted file mode 100644 index 35f6276963..0000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ /dev/null @@ -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 selectDeptList(SysDept dept) - { - return deptMapper.selectDeptList(dept); - } - - /** - * 构建前端所需要树结构 - * - * @param depts 部门列表 - * @return 树结构列表 - */ - @Override - public List buildDeptTree(List depts) - { - List returnList = new ArrayList(); - List tempList = new ArrayList(); - for (SysDept dept : depts) - { - tempList.add(dept.getDeptId()); - } - for (Iterator 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 buildDeptTreeSelect(List depts) - { - List deptTrees = buildDeptTree(depts); - return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); - } - - /** - * 根据角色ID查询部门树信息 - * - * @param roleId 角色ID - * @return 选中部门列表 - */ - @Override - public List 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 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 list, SysDept t) - { - // 得到子节点列表 - List childList = getChildList(list, t); - t.setChildren(childList); - for (SysDept tChild : childList) - { - if (hasChild(list, tChild)) - { - recursionFn(list, tChild); - } - } - } - - /** - * 得到子节点列表 - */ - private List getChildList(List list, SysDept t) - { - List tlist = new ArrayList(); - Iterator 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 list, SysDept t) - { - return getChildList(list, t).size() > 0 ? true : false; - } -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java deleted file mode 100644 index 29ff4b0861..0000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ /dev/null @@ -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 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); - } -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java deleted file mode 100644 index d3ff7a22b5..0000000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ /dev/null @@ -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 selectUserList(SysUser user) { - return userMapper.selectUserList(user); - } - - /** - * 查询用户所属角色组 - * - * @param userName 用户名 - * @return 结果 - */ - @Override - public String selectUserRoleGroup(String userName) { - List 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 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 list = new ArrayList(); - 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 list = new ArrayList(); - 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 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("
" + successNum + "、账号 " + user.getUserName() + " 导入成功"); - } else if (isUpdateSupport) { - user.setUpdateBy(operName); - this.updateUser(user); - successNum++; - successMsg.append("
" + successNum + "、账号 " + user.getUserName() + " 更新成功"); - } else { - failureNum++; - failureMsg.append("
" + failureNum + "、账号 " + user.getUserName() + " 已存在"); - } - } catch (Exception e) { - failureNum++; - String msg = "
" + 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(); - } -} diff --git a/ruoyi-ui/src/api/system/dept.js b/ruoyi-ui/src/api/system/dept.js index 1ab09fac75..c22f0f4a8a 100644 --- a/ruoyi-ui/src/api/system/dept.js +++ b/ruoyi-ui/src/api/system/dept.js @@ -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 { -} diff --git a/ruoyi-ui/src/views/system/dept/index.vue b/ruoyi-ui/src/views/system/dept/index.vue index c75b05555a..f0bb4e74e1 100644 --- a/ruoyi-ui/src/views/system/dept/index.vue +++ b/ruoyi-ui/src/views/system/dept/index.vue @@ -1,9 +1,9 @@