Commit e4fd022ce1db21dd784e7c25ced8a14dc4789642

Authored by YunaiV
1 parent 7f171d14

完成部门模块的迁移

Showing 25 changed files with 316 additions and 1245 deletions
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java deleted
1 -package com.ruoyi.web.controller.system;  
2 -  
3 -import java.util.Iterator;  
4 -import java.util.List;  
5 -import org.apache.commons.lang3.ArrayUtils;  
6 -import org.springframework.beans.factory.annotation.Autowired;  
7 -import org.springframework.security.access.prepost.PreAuthorize;  
8 -import org.springframework.validation.annotation.Validated;  
9 -import org.springframework.web.bind.annotation.DeleteMapping;  
10 -import org.springframework.web.bind.annotation.GetMapping;  
11 -import org.springframework.web.bind.annotation.PathVariable;  
12 -import org.springframework.web.bind.annotation.PostMapping;  
13 -import org.springframework.web.bind.annotation.PutMapping;  
14 -import org.springframework.web.bind.annotation.RequestBody;  
15 -import org.springframework.web.bind.annotation.RequestMapping;  
16 -import org.springframework.web.bind.annotation.RestController;  
17 -import com.ruoyi.common.annotation.Log;  
18 -import com.ruoyi.common.constant.UserConstants;  
19 -import com.ruoyi.common.core.controller.BaseController;  
20 -import com.ruoyi.common.core.domain.AjaxResult;  
21 -import com.ruoyi.common.core.domain.entity.SysDept;  
22 -import com.ruoyi.common.enums.BusinessType;  
23 -import com.ruoyi.common.utils.SecurityUtils;  
24 -import com.ruoyi.common.utils.StringUtils;  
25 -import com.ruoyi.system.service.ISysDeptService;  
26 -  
27 -/**  
28 - * 部门信息  
29 - *  
30 - * @author ruoyi  
31 - */  
32 -@RestController  
33 -@RequestMapping("/system/dept")  
34 -public class SysDeptController extends BaseController  
35 -{  
36 - @Autowired  
37 - private ISysDeptService deptService;  
38 -  
39 - /**  
40 - * 获取部门列表  
41 - */  
42 - @PreAuthorize("@ss.hasPermi('system:dept:list')")  
43 - @GetMapping("/list")  
44 - public AjaxResult list(SysDept dept)  
45 - {  
46 - List<SysDept> depts = deptService.selectDeptList(dept);  
47 - return AjaxResult.success(depts);  
48 - }  
49 -  
50 - /**  
51 - * 查询部门列表(排除节点)  
52 - */  
53 - @PreAuthorize("@ss.hasPermi('system:dept:list')")  
54 - @GetMapping("/list/exclude/{deptId}")  
55 - public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)  
56 - {  
57 - List<SysDept> depts = deptService.selectDeptList(new SysDept());  
58 - Iterator<SysDept> it = depts.iterator();  
59 - while (it.hasNext())  
60 - {  
61 - SysDept d = (SysDept) it.next();  
62 - if (d.getDeptId().intValue() == deptId  
63 - || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))  
64 - {  
65 - it.remove();  
66 - }  
67 - }  
68 - return AjaxResult.success(depts);  
69 - }  
70 -  
71 - /**  
72 - * 根据部门编号获取详细信息  
73 - */  
74 - @PreAuthorize("@ss.hasPermi('system:dept:query')")  
75 - @GetMapping(value = "/{deptId}")  
76 - public AjaxResult getInfo(@PathVariable Long deptId)  
77 - {  
78 - return AjaxResult.success(deptService.selectDeptById(deptId));  
79 - }  
80 -  
81 - /**  
82 - * 获取部门下拉树列表  
83 - */  
84 - @GetMapping("/treeselect")  
85 - public AjaxResult treeselect(SysDept dept)  
86 - {  
87 - List<SysDept> depts = deptService.selectDeptList(dept);  
88 - return AjaxResult.success(deptService.buildDeptTreeSelect(depts));  
89 - }  
90 -  
91 - /**  
92 - * 加载对应角色部门列表树  
93 - */  
94 - @GetMapping(value = "/roleDeptTreeselect/{roleId}")  
95 - public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)  
96 - {  
97 - List<SysDept> depts = deptService.selectDeptList(new SysDept());  
98 - AjaxResult ajax = AjaxResult.success();  
99 - ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));  
100 - ajax.put("depts", deptService.buildDeptTreeSelect(depts));  
101 - return ajax;  
102 - }  
103 -  
104 - /**  
105 - * 新增部门  
106 - */  
107 - @PreAuthorize("@ss.hasPermi('system:dept:add')")  
108 - @Log(title = "部门管理", businessType = BusinessType.INSERT)  
109 - @PostMapping  
110 - public AjaxResult add(@Validated @RequestBody SysDept dept)  
111 - {  
112 - if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))  
113 - {  
114 - return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");  
115 - }  
116 - dept.setCreateBy(SecurityUtils.getUsername());  
117 - return toAjax(deptService.insertDept(dept));  
118 - }  
119 -  
120 - /**  
121 - * 修改部门  
122 - */  
123 - @PreAuthorize("@ss.hasPermi('system:dept:edit')")  
124 - @Log(title = "部门管理", businessType = BusinessType.UPDATE)  
125 - @PutMapping  
126 - public AjaxResult edit(@Validated @RequestBody SysDept dept)  
127 - {  
128 - if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))  
129 - {  
130 - return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");  
131 - }  
132 - else if (dept.getParentId().equals(dept.getDeptId()))  
133 - {  
134 - return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");  
135 - }  
136 - else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())  
137 - && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)  
138 - {  
139 - return AjaxResult.error("该部门包含未停用的子部门!");  
140 - }  
141 - dept.setUpdateBy(SecurityUtils.getUsername());  
142 - return toAjax(deptService.updateDept(dept));  
143 - }  
144 -  
145 - /**  
146 - * 删除部门  
147 - */  
148 - @PreAuthorize("@ss.hasPermi('system:dept:remove')")  
149 - @Log(title = "部门管理", businessType = BusinessType.DELETE)  
150 - @DeleteMapping("/{deptId}")  
151 - public AjaxResult remove(@PathVariable Long deptId)  
152 - {  
153 - if (deptService.hasChildByDeptId(deptId))  
154 - {  
155 - return AjaxResult.error("存在下级部门,不允许删除");  
156 - }  
157 - if (deptService.checkDeptExistUser(deptId))  
158 - {  
159 - return AjaxResult.error("部门存在用户,不允许删除");  
160 - }  
161 - return toAjax(deptService.deleteDeptById(deptId));  
162 - }  
163 -}  
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeEntity.java deleted
1 -package com.ruoyi.common.core.domain;  
2 -  
3 -import java.util.ArrayList;  
4 -import java.util.List;  
5 -  
6 -/**  
7 - * Tree基类  
8 - *  
9 - * @author ruoyi  
10 - */  
11 -public class TreeEntity extends BaseEntity  
12 -{  
13 - private static final long serialVersionUID = 1L;  
14 -  
15 - /** 父菜单名称 */  
16 - private String parentName;  
17 -  
18 - /** 父菜单ID */  
19 - private Long parentId;  
20 -  
21 - /** 显示顺序 */  
22 - private Integer orderNum;  
23 -  
24 - /** 祖级列表 */  
25 - private String ancestors;  
26 -  
27 - /** 子部门 */  
28 - private List<?> children = new ArrayList<>();  
29 -  
30 -}  
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java deleted
1 -package com.ruoyi.common.core.domain;  
2 -  
3 -import java.io.Serializable;  
4 -import java.util.List;  
5 -import java.util.stream.Collectors;  
6 -import com.fasterxml.jackson.annotation.JsonInclude;  
7 -import com.ruoyi.common.core.domain.entity.SysDept;  
8 -import com.ruoyi.common.core.domain.entity.SysMenu;  
9 -  
10 -/**  
11 - * Treeselect树结构实体类  
12 - *  
13 - * @author ruoyi  
14 - */  
15 -public class TreeSelect implements Serializable {  
16 - /** 节点ID */  
17 - private Long id;  
18 -  
19 - /** 节点名称 */  
20 - private String label;  
21 -  
22 - /** 子节点 */  
23 - @JsonInclude(JsonInclude.Include.NON_EMPTY)  
24 - private List<TreeSelect> children;  
25 -  
26 -}  
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java deleted
1 -package com.ruoyi.common.core.domain.entity;  
2 -  
3 -import java.util.ArrayList;  
4 -import java.util.List;  
5 -import javax.validation.constraints.Email;  
6 -import javax.validation.constraints.NotBlank;  
7 -import javax.validation.constraints.Size;  
8 -import org.apache.commons.lang3.builder.ToStringBuilder;  
9 -import org.apache.commons.lang3.builder.ToStringStyle;  
10 -import com.ruoyi.common.core.domain.BaseEntity;  
11 -  
12 -/**  
13 - * 部门表 sys_dept  
14 - *  
15 - * @author ruoyi  
16 - */  
17 -public class SysDept extends BaseEntity  
18 -{  
19 - private static final long serialVersionUID = 1L;  
20 -  
21 - /** 部门ID */  
22 - private Long deptId;  
23 -  
24 - /** 父部门ID */  
25 - private Long parentId;  
26 -  
27 - /** 祖级列表 */  
28 - private String ancestors;  
29 -  
30 - /** 部门名称 */  
31 - private String deptName;  
32 -  
33 - /** 显示顺序 */  
34 - private String orderNum;  
35 -  
36 - /** 负责人 */  
37 - private String leader;  
38 -  
39 - /** 联系电话 */  
40 - private String phone;  
41 -  
42 - /** 邮箱 */  
43 - private String email;  
44 -  
45 - /** 部门状态:0正常,1停用 */  
46 - private String status;  
47 -  
48 - /** 删除标志(0代表存在 2代表删除) */  
49 - private String delFlag;  
50 -  
51 - /** 父部门名称 */  
52 - private String parentName;  
53 -  
54 - /** 子部门 */  
55 - private List<SysDept> children = new ArrayList<SysDept>();  
56 -  
57 -  
58 - @NotBlank(message = "部门名称不能为空")  
59 - @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")  
60 - public String getDeptName()  
61 - {  
62 - return deptName;  
63 - }  
64 -  
65 - @NotBlank(message = "显示顺序不能为空")  
66 - public String getOrderNum()  
67 - {  
68 - return orderNum;  
69 - }  
70 -  
71 - @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")  
72 - public String getPhone()  
73 - {  
74 - return phone;  
75 - }  
76 -  
77 - @Email(message = "邮箱格式不正确")  
78 - @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")  
79 - public String getEmail()  
80 - {  
81 - return email;  
82 - }  
83 -  
84 -}  
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java deleted
1 -package com.ruoyi.system.service;  
2 -  
3 -import java.util.List;  
4 -import com.ruoyi.common.core.domain.TreeSelect;  
5 -import com.ruoyi.common.core.domain.entity.SysDept;  
6 -  
7 -/**  
8 - * 部门管理 服务层  
9 - *  
10 - * @author ruoyi  
11 - */  
12 -public interface ISysDeptService  
13 -{  
14 - /**  
15 - * 查询部门管理数据  
16 - *  
17 - * @param dept 部门信息  
18 - * @return 部门信息集合  
19 - */  
20 - public List<SysDept> selectDeptList(SysDept dept);  
21 -  
22 - /**  
23 - * 构建前端所需要树结构  
24 - *  
25 - * @param depts 部门列表  
26 - * @return 树结构列表  
27 - */  
28 - public List<SysDept> buildDeptTree(List<SysDept> depts);  
29 -  
30 - /**  
31 - * 构建前端所需要下拉树结构  
32 - *  
33 - * @param depts 部门列表  
34 - * @return 下拉树结构列表  
35 - */  
36 - public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts);  
37 -  
38 - /**  
39 - * 根据角色ID查询部门树信息  
40 - *  
41 - * @param roleId 角色ID  
42 - * @return 选中部门列表  
43 - */  
44 - public List<Integer> selectDeptListByRoleId(Long roleId);  
45 -  
46 - /**  
47 - * 根据部门ID查询信息  
48 - *  
49 - * @param deptId 部门ID  
50 - * @return 部门信息  
51 - */  
52 - public SysDept selectDeptById(Long deptId);  
53 -  
54 - /**  
55 - * 根据ID查询所有子部门(正常状态)  
56 - *  
57 - * @param deptId 部门ID  
58 - * @return 子部门数  
59 - */  
60 - public int selectNormalChildrenDeptById(Long deptId);  
61 -  
62 - /**  
63 - * 是否存在部门子节点  
64 - *  
65 - * @param deptId 部门ID  
66 - * @return 结果  
67 - */  
68 - public boolean hasChildByDeptId(Long deptId);  
69 -  
70 - /**  
71 - * 查询部门是否存在用户  
72 - *  
73 - * @param deptId 部门ID  
74 - * @return 结果 true 存在 false 不存在  
75 - */  
76 - public boolean checkDeptExistUser(Long deptId);  
77 -  
78 - /**  
79 - * 校验部门名称是否唯一  
80 - *  
81 - * @param dept 部门信息  
82 - * @return 结果  
83 - */  
84 - public String checkDeptNameUnique(SysDept dept);  
85 -  
86 - /**  
87 - * 新增保存部门信息  
88 - *  
89 - * @param dept 部门信息  
90 - * @return 结果  
91 - */  
92 - public int insertDept(SysDept dept);  
93 -  
94 - /**  
95 - * 修改保存部门信息  
96 - *  
97 - * @param dept 部门信息  
98 - * @return 结果  
99 - */  
100 - public int updateDept(SysDept dept);  
101 -  
102 - /**  
103 - * 删除部门管理信息  
104 - *  
105 - * @param deptId 部门ID  
106 - * @return 结果  
107 - */  
108 - public int deleteDeptById(Long deptId);  
109 -}  
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java deleted
1 -package com.ruoyi.system.service.impl;  
2 -  
3 -import java.util.ArrayList;  
4 -import java.util.Iterator;  
5 -import java.util.List;  
6 -import java.util.stream.Collectors;  
7 -import org.springframework.beans.factory.annotation.Autowired;  
8 -import org.springframework.stereotype.Service;  
9 -import com.ruoyi.common.annotation.DataScope;  
10 -import com.ruoyi.common.constant.UserConstants;  
11 -import com.ruoyi.common.core.domain.TreeSelect;  
12 -import com.ruoyi.common.core.domain.entity.SysDept;  
13 -import com.ruoyi.common.core.domain.entity.SysRole;  
14 -import com.ruoyi.common.exception.CustomException;  
15 -import com.ruoyi.common.utils.StringUtils;  
16 -import com.ruoyi.system.mapper.SysDeptMapper;  
17 -import com.ruoyi.system.mapper.SysRoleMapper;  
18 -import com.ruoyi.system.service.ISysDeptService;  
19 -  
20 -/**  
21 - * 部门管理 服务实现  
22 - *  
23 - * @author ruoyi  
24 - */  
25 -@Service  
26 -public class SysDeptServiceImpl implements ISysDeptService  
27 -{  
28 - @Autowired  
29 - private SysDeptMapper deptMapper;  
30 -  
31 - @Autowired  
32 - private SysRoleMapper roleMapper;  
33 -  
34 - /**  
35 - * 查询部门管理数据  
36 - *  
37 - * @param dept 部门信息  
38 - * @return 部门信息集合  
39 - */  
40 - @Override  
41 - @DataScope(deptAlias = "d")  
42 - public List<SysDept> selectDeptList(SysDept dept)  
43 - {  
44 - return deptMapper.selectDeptList(dept);  
45 - }  
46 -  
47 - /**  
48 - * 构建前端所需要树结构  
49 - *  
50 - * @param depts 部门列表  
51 - * @return 树结构列表  
52 - */  
53 - @Override  
54 - public List<SysDept> buildDeptTree(List<SysDept> depts)  
55 - {  
56 - List<SysDept> returnList = new ArrayList<SysDept>();  
57 - List<Long> tempList = new ArrayList<Long>();  
58 - for (SysDept dept : depts)  
59 - {  
60 - tempList.add(dept.getDeptId());  
61 - }  
62 - for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)  
63 - {  
64 - SysDept dept = (SysDept) iterator.next();  
65 - // 如果是顶级节点, 遍历该父节点的所有子节点  
66 - if (!tempList.contains(dept.getParentId()))  
67 - {  
68 - recursionFn(depts, dept);  
69 - returnList.add(dept);  
70 - }  
71 - }  
72 - if (returnList.isEmpty())  
73 - {  
74 - returnList = depts;  
75 - }  
76 - return returnList;  
77 - }  
78 -  
79 - /**  
80 - * 构建前端所需要下拉树结构  
81 - *  
82 - * @param depts 部门列表  
83 - * @return 下拉树结构列表  
84 - */  
85 - @Override  
86 - public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts)  
87 - {  
88 - List<SysDept> deptTrees = buildDeptTree(depts);  
89 - return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());  
90 - }  
91 -  
92 - /**  
93 - * 根据角色ID查询部门树信息  
94 - *  
95 - * @param roleId 角色ID  
96 - * @return 选中部门列表  
97 - */  
98 - @Override  
99 - public List<Integer> selectDeptListByRoleId(Long roleId)  
100 - {  
101 - SysRole role = roleMapper.selectRoleById(roleId);  
102 - return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());  
103 - }  
104 -  
105 - /**  
106 - * 根据部门ID查询信息  
107 - *  
108 - * @param deptId 部门ID  
109 - * @return 部门信息  
110 - */  
111 - @Override  
112 - public SysDept selectDeptById(Long deptId)  
113 - {  
114 - return deptMapper.selectDeptById(deptId);  
115 - }  
116 -  
117 - /**  
118 - * 根据ID查询所有子部门(正常状态)  
119 - *  
120 - * @param deptId 部门ID  
121 - * @return 子部门数  
122 - */  
123 - @Override  
124 - public int selectNormalChildrenDeptById(Long deptId)  
125 - {  
126 - return deptMapper.selectNormalChildrenDeptById(deptId);  
127 - }  
128 -  
129 - /**  
130 - * 是否存在子节点  
131 - *  
132 - * @param deptId 部门ID  
133 - * @return 结果  
134 - */  
135 - @Override  
136 - public boolean hasChildByDeptId(Long deptId)  
137 - {  
138 - int result = deptMapper.hasChildByDeptId(deptId);  
139 - return result > 0 ? true : false;  
140 - }  
141 -  
142 - /**  
143 - * 查询部门是否存在用户  
144 - *  
145 - * @param deptId 部门ID  
146 - * @return 结果 true 存在 false 不存在  
147 - */  
148 - @Override  
149 - public boolean checkDeptExistUser(Long deptId)  
150 - {  
151 - int result = deptMapper.checkDeptExistUser(deptId);  
152 - return result > 0 ? true : false;  
153 - }  
154 -  
155 - /**  
156 - * 校验部门名称是否唯一  
157 - *  
158 - * @param dept 部门信息  
159 - * @return 结果  
160 - */  
161 - @Override  
162 - public String checkDeptNameUnique(SysDept dept)  
163 - {  
164 - Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();  
165 - SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());  
166 - if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())  
167 - {  
168 - return UserConstants.NOT_UNIQUE;  
169 - }  
170 - return UserConstants.UNIQUE;  
171 - }  
172 -  
173 - /**  
174 - * 新增保存部门信息  
175 - *  
176 - * @param dept 部门信息  
177 - * @return 结果  
178 - */  
179 - @Override  
180 - public int insertDept(SysDept dept)  
181 - {  
182 - SysDept info = deptMapper.selectDeptById(dept.getParentId());  
183 - // 如果父节点不为正常状态,则不允许新增子节点  
184 - if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))  
185 - {  
186 - throw new CustomException("部门停用,不允许新增");  
187 - }  
188 - dept.setAncestors(info.getAncestors() + "," + dept.getParentId());  
189 - return deptMapper.insertDept(dept);  
190 - }  
191 -  
192 - /**  
193 - * 修改保存部门信息  
194 - *  
195 - * @param dept 部门信息  
196 - * @return 结果  
197 - */  
198 - @Override  
199 - public int updateDept(SysDept dept)  
200 - {  
201 - SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());  
202 - SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());  
203 - if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))  
204 - {  
205 - String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();  
206 - String oldAncestors = oldDept.getAncestors();  
207 - dept.setAncestors(newAncestors);  
208 - updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);  
209 - }  
210 - int result = deptMapper.updateDept(dept);  
211 - if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))  
212 - {  
213 - // 如果该部门是启用状态,则启用该部门的所有上级部门  
214 - updateParentDeptStatus(dept);  
215 - }  
216 - return result;  
217 - }  
218 -  
219 - /**  
220 - * 修改该部门的父级部门状态  
221 - *  
222 - * @param dept 当前部门  
223 - */  
224 - private void updateParentDeptStatus(SysDept dept)  
225 - {  
226 - String updateBy = dept.getUpdateBy();  
227 - dept = deptMapper.selectDeptById(dept.getDeptId());  
228 - dept.setUpdateBy(updateBy);  
229 - deptMapper.updateDeptStatus(dept);  
230 - }  
231 -  
232 - /**  
233 - * 修改子元素关系  
234 - *  
235 - * @param deptId 被修改的部门ID  
236 - * @param newAncestors 新的父ID集合  
237 - * @param oldAncestors 旧的父ID集合  
238 - */  
239 - public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors)  
240 - {  
241 - List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);  
242 - for (SysDept child : children)  
243 - {  
244 - child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));  
245 - }  
246 - if (children.size() > 0)  
247 - {  
248 - deptMapper.updateDeptChildren(children);  
249 - }  
250 - }  
251 -  
252 - /**  
253 - * 删除部门管理信息  
254 - *  
255 - * @param deptId 部门ID  
256 - * @return 结果  
257 - */  
258 - @Override  
259 - public int deleteDeptById(Long deptId)  
260 - {  
261 - return deptMapper.deleteDeptById(deptId);  
262 - }  
263 -  
264 - /**  
265 - * 递归列表  
266 - */  
267 - private void recursionFn(List<SysDept> list, SysDept t)  
268 - {  
269 - // 得到子节点列表  
270 - List<SysDept> childList = getChildList(list, t);  
271 - t.setChildren(childList);  
272 - for (SysDept tChild : childList)  
273 - {  
274 - if (hasChild(list, tChild))  
275 - {  
276 - recursionFn(list, tChild);  
277 - }  
278 - }  
279 - }  
280 -  
281 - /**  
282 - * 得到子节点列表  
283 - */  
284 - private List<SysDept> getChildList(List<SysDept> list, SysDept t)  
285 - {  
286 - List<SysDept> tlist = new ArrayList<SysDept>();  
287 - Iterator<SysDept> it = list.iterator();  
288 - while (it.hasNext())  
289 - {  
290 - SysDept n = (SysDept) it.next();  
291 - if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())  
292 - {  
293 - tlist.add(n);  
294 - }  
295 - }  
296 - return tlist;  
297 - }  
298 -  
299 - /**  
300 - * 判断是否有子节点  
301 - */  
302 - private boolean hasChild(List<SysDept> list, SysDept t)  
303 - {  
304 - return getChildList(list, t).size() > 0 ? true : false;  
305 - }  
306 -}  
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java deleted
1 -package com.ruoyi.system.service.impl;  
2 -  
3 -import java.util.ArrayList;  
4 -import java.util.Arrays;  
5 -import java.util.HashSet;  
6 -import java.util.List;  
7 -import java.util.Set;  
8 -  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Service;  
11 -import org.springframework.transaction.annotation.Transactional;  
12 -import com.ruoyi.common.annotation.DataScope;  
13 -import com.ruoyi.common.constant.UserConstants;  
14 -import com.ruoyi.common.core.domain.entity.SysRole;  
15 -import com.ruoyi.common.exception.CustomException;  
16 -import com.ruoyi.common.utils.StringUtils;  
17 -import com.ruoyi.common.utils.spring.SpringUtils;  
18 -import com.ruoyi.system.domain.SysRoleDept;  
19 -import com.ruoyi.system.domain.SysRoleMenu;  
20 -import com.ruoyi.system.mapper.SysRoleDeptMapper;  
21 -import com.ruoyi.system.mapper.SysRoleMapper;  
22 -import com.ruoyi.system.mapper.SysRoleMenuMapper;  
23 -import com.ruoyi.system.mapper.SysUserRoleMapper;  
24 -import com.ruoyi.system.service.ISysRoleService;  
25 -  
26 -/**  
27 - * 角色 业务层处理  
28 - *  
29 - * @author ruoyi  
30 - */  
31 -@Service  
32 -public class SysRoleServiceImpl implements ISysRoleService {  
33 -  
34 - /**  
35 - * 根据条件分页查询角色数据  
36 - *  
37 - * @param role 角色信息  
38 - * @return 角色数据集合信息  
39 - */  
40 - @Override  
41 - @DataScope(deptAlias = "d")  
42 - public List<SysRole> selectRoleList(SysRole role) {  
43 - return roleMapper.selectRoleList(role);  
44 - }  
45 -  
46 - /**  
47 - * 修改数据权限信息  
48 - *  
49 - * @param role 角色信息  
50 - * @return 结果  
51 - */  
52 - @Override  
53 - @Transactional  
54 - public int authDataScope(SysRole role) {  
55 - // 修改角色信息  
56 - roleMapper.updateRole(role);  
57 - // 删除角色与部门关联  
58 - roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());  
59 - // 新增角色和部门信息(数据权限)  
60 - return insertRoleDept(role);  
61 - }  
62 -  
63 - /**  
64 - * 批量删除角色信息  
65 - *  
66 - * @param roleIds 需要删除的角色ID  
67 - * @return 结果  
68 - */  
69 - @Override  
70 - @Transactional  
71 - public int deleteRoleByIds(Long[] roleIds) {  
72 - for (Long roleId : roleIds) {  
73 - checkRoleAllowed(new SysRole(roleId));  
74 - SysRole role = selectRoleById(roleId);  
75 - if (countUserRoleByRoleId(roleId) > 0) {  
76 - throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName()));  
77 - }  
78 - }  
79 - // 删除角色与菜单关联  
80 - roleMenuMapper.deleteRoleMenu(roleIds);  
81 - // 删除角色与部门关联  
82 - roleDeptMapper.deleteRoleDept(roleIds);  
83 - return roleMapper.deleteRoleByIds(roleIds);  
84 - }  
85 -}  
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java deleted
1 -package com.ruoyi.system.service.impl;  
2 -  
3 -import java.util.ArrayList;  
4 -import java.util.List;  
5 -  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.stereotype.Service;  
10 -import org.springframework.transaction.annotation.Transactional;  
11 -import com.ruoyi.common.annotation.DataScope;  
12 -import com.ruoyi.common.constant.UserConstants;  
13 -import com.ruoyi.common.core.domain.entity.SysRole;  
14 -import com.ruoyi.common.core.domain.entity.SysUser;  
15 -import com.ruoyi.common.exception.CustomException;  
16 -import com.ruoyi.common.utils.SecurityUtils;  
17 -import com.ruoyi.common.utils.StringUtils;  
18 -import com.ruoyi.system.domain.SysPost;  
19 -import com.ruoyi.system.domain.SysUserPost;  
20 -import com.ruoyi.system.domain.SysUserRole;  
21 -import com.ruoyi.system.mapper.SysPostMapper;  
22 -import com.ruoyi.system.mapper.SysRoleMapper;  
23 -import com.ruoyi.system.mapper.SysUserMapper;  
24 -import com.ruoyi.system.mapper.SysUserPostMapper;  
25 -import com.ruoyi.system.mapper.SysUserRoleMapper;  
26 -import com.ruoyi.system.service.ISysConfigService;  
27 -import com.ruoyi.system.service.ISysUserService;  
28 -  
29 -/**  
30 - * 用户 业务层处理  
31 - *  
32 - * @author ruoyi  
33 - */  
34 -@Service  
35 -public class SysUserServiceImpl implements ISysUserService {  
36 -  
37 - /**  
38 - * 根据条件分页查询用户列表  
39 - *  
40 - * @param user 用户信息  
41 - * @return 用户信息集合信息  
42 - */  
43 - @Override  
44 - @DataScope(deptAlias = "d", userAlias = "u")  
45 - public List<SysUser> selectUserList(SysUser user) {  
46 - return userMapper.selectUserList(user);  
47 - }  
48 -  
49 - /**  
50 - * 查询用户所属角色组  
51 - *  
52 - * @param userName 用户名  
53 - * @return 结果  
54 - */  
55 - @Override  
56 - public String selectUserRoleGroup(String userName) {  
57 - List<SysRole> list = roleMapper.selectRolesByUserName(userName);  
58 - StringBuffer idsStr = new StringBuffer();  
59 - for (SysRole role : list) {  
60 - idsStr.append(role.getRoleName()).append(",");  
61 - }  
62 - if (StringUtils.isNotEmpty(idsStr.toString())) {  
63 - return idsStr.substring(0, idsStr.length() - 1);  
64 - }  
65 - return idsStr.toString();  
66 - }  
67 -  
68 - /**  
69 - * 查询用户所属岗位组  
70 - *  
71 - * @param userName 用户名  
72 - * @return 结果  
73 - */  
74 - @Override  
75 - public String selectUserPostGroup(String userName) {  
76 - List<SysPost> list = postMapper.selectPostsByUserName(userName);  
77 - StringBuffer idsStr = new StringBuffer();  
78 - for (SysPost post : list) {  
79 - idsStr.append(post.getPostName()).append(",");  
80 - }  
81 - if (StringUtils.isNotEmpty(idsStr.toString())) {  
82 - return idsStr.substring(0, idsStr.length() - 1);  
83 - }  
84 - return idsStr.toString();  
85 - }  
86 -  
87 - /**  
88 - * 校验email是否唯一  
89 - *  
90 - * @param user 用户信息  
91 - * @return  
92 - */  
93 - @Override  
94 - public String checkEmailUnique(SysUser user) {  
95 - Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();  
96 - SysUser info = userMapper.checkEmailUnique(user.getEmail());  
97 - if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {  
98 - return UserConstants.NOT_UNIQUE;  
99 - }  
100 - return UserConstants.UNIQUE;  
101 - }  
102 -  
103 - /**  
104 - * 校验用户是否允许操作  
105 - *  
106 - * @param user 用户信息  
107 - */  
108 - @Override  
109 - public void checkUserAllowed(SysUser user) {  
110 - if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) {  
111 - throw new CustomException("不允许操作超级管理员用户");  
112 - }  
113 - }  
114 -  
115 - /**  
116 - * 新增保存用户信息  
117 - *  
118 - * @param user 用户信息  
119 - * @return 结果  
120 - */  
121 - @Override  
122 - @Transactional  
123 - public int insertUser(SysUser user) {  
124 - // 新增用户信息  
125 - int rows = userMapper.insertUser(user);  
126 - // 新增用户岗位关联  
127 - insertUserPost(user);  
128 - // 新增用户与角色管理  
129 - insertUserRole(user);  
130 - return rows;  
131 - }  
132 -  
133 - /**  
134 - * 修改保存用户信息  
135 - *  
136 - * @param user 用户信息  
137 - * @return 结果  
138 - */  
139 - @Override  
140 - @Transactional  
141 - public int updateUser(SysUser user) {  
142 - Long userId = user.getUserId();  
143 - // 删除用户与角色关联  
144 - userRoleMapper.deleteUserRoleByUserId(userId);  
145 - // 新增用户与角色管理  
146 - insertUserRole(user);  
147 - // 删除用户与岗位关联  
148 - userPostMapper.deleteUserPostByUserId(userId);  
149 - // 新增用户与岗位管理  
150 - insertUserPost(user);  
151 - return userMapper.updateUser(user);  
152 - }  
153 -  
154 - /**  
155 - * 修改用户基本信息  
156 - *  
157 - * @param user 用户信息  
158 - * @return 结果  
159 - */  
160 - @Override  
161 - public int updateUserProfile(SysUser user) {  
162 - return userMapper.updateUser(user);  
163 - }  
164 -  
165 - /**  
166 - * 修改用户头像  
167 - *  
168 - * @param userName 用户名  
169 - * @param avatar 头像地址  
170 - * @return 结果  
171 - */  
172 - @Override  
173 - public boolean updateUserAvatar(String userName, String avatar) {  
174 - return userMapper.updateUserAvatar(userName, avatar) > 0;  
175 - }  
176 -  
177 - /**  
178 - * 重置用户密码  
179 - *  
180 - * @param user 用户信息  
181 - * @return 结果  
182 - */  
183 - @Override  
184 - public int resetPwd(SysUser user) {  
185 - return userMapper.updateUser(user);  
186 - }  
187 -  
188 - /**  
189 - * 重置用户密码  
190 - *  
191 - * @param userName 用户名  
192 - * @param password 密码  
193 - * @return 结果  
194 - */  
195 - @Override  
196 - public int resetUserPwd(String userName, String password) {  
197 - return userMapper.resetUserPwd(userName, password);  
198 - }  
199 -  
200 - /**  
201 - * 新增用户角色信息  
202 - *  
203 - * @param user 用户对象  
204 - */  
205 - public void insertUserRole(SysUser user) {  
206 - Long[] roles = user.getRoleIds();  
207 - if (StringUtils.isNotNull(roles)) {  
208 - // 新增用户与角色管理  
209 - List<SysUserRole> list = new ArrayList<SysUserRole>();  
210 - for (Long roleId : roles) {  
211 - SysUserRole ur = new SysUserRole();  
212 - ur.setUserId(user.getUserId());  
213 - ur.setRoleId(roleId);  
214 - list.add(ur);  
215 - }  
216 - if (list.size() > 0) {  
217 - userRoleMapper.batchUserRole(list);  
218 - }  
219 - }  
220 - }  
221 -  
222 - /**  
223 - * 新增用户岗位信息  
224 - *  
225 - * @param user 用户对象  
226 - */  
227 - public void insertUserPost(SysUser user) {  
228 - Long[] posts = user.getPostIds();  
229 - if (StringUtils.isNotNull(posts)) {  
230 - // 新增用户与岗位管理  
231 - List<SysUserPost> list = new ArrayList<SysUserPost>();  
232 - for (Long postId : posts) {  
233 - SysUserPost up = new SysUserPost();  
234 - up.setUserId(user.getUserId());  
235 - up.setPostId(postId);  
236 - list.add(up);  
237 - }  
238 - if (list.size() > 0) {  
239 - userPostMapper.batchUserPost(list);  
240 - }  
241 - }  
242 - }  
243 -  
244 - /**  
245 - * 通过用户ID删除用户  
246 - *  
247 - * @param userId 用户ID  
248 - * @return 结果  
249 - */  
250 - @Override  
251 - @Transactional  
252 - public int deleteUserById(Long userId) {  
253 - // 删除用户与角色关联  
254 - userRoleMapper.deleteUserRoleByUserId(userId);  
255 - // 删除用户与岗位表  
256 - userPostMapper.deleteUserPostByUserId(userId);  
257 - return userMapper.deleteUserById(userId);  
258 - }  
259 -  
260 - /**  
261 - * 批量删除用户信息  
262 - *  
263 - * @param userIds 需要删除的用户ID  
264 - * @return 结果  
265 - */  
266 - @Override  
267 - @Transactional  
268 - public int deleteUserByIds(Long[] userIds) {  
269 - for (Long userId : userIds) {  
270 - checkUserAllowed(new SysUser(userId));  
271 - }  
272 - // 删除用户与角色关联  
273 - userRoleMapper.deleteUserRole(userIds);  
274 - // 删除用户与岗位关联  
275 - userPostMapper.deleteUserPost(userIds);  
276 - return userMapper.deleteUserByIds(userIds);  
277 - }  
278 -  
279 - /**  
280 - * 导入用户数据  
281 - *  
282 - * @param userList 用户数据列表  
283 - * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据  
284 - * @param operName 操作用户  
285 - * @return 结果  
286 - */  
287 - @Override  
288 - public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) {  
289 - if (StringUtils.isNull(userList) || userList.size() == 0) {  
290 - throw new CustomException("导入用户数据不能为空!");  
291 - }  
292 - int successNum = 0;  
293 - int failureNum = 0;  
294 - StringBuilder successMsg = new StringBuilder();  
295 - StringBuilder failureMsg = new StringBuilder();  
296 - String password = configService.selectConfigByKey("sys.user.initPassword");  
297 - for (SysUser user : userList) {  
298 - try {  
299 - // 验证是否存在这个用户  
300 - SysUser u = userMapper.selectUserByUserName(user.getUserName());  
301 - if (StringUtils.isNull(u)) {  
302 - user.setPassword(SecurityUtils.encryptPassword(password));  
303 - user.setCreateBy(operName);  
304 - this.insertUser(user);  
305 - successNum++;  
306 - successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");  
307 - } else if (isUpdateSupport) {  
308 - user.setUpdateBy(operName);  
309 - this.updateUser(user);  
310 - successNum++;  
311 - successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");  
312 - } else {  
313 - failureNum++;  
314 - failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");  
315 - }  
316 - } catch (Exception e) {  
317 - failureNum++;  
318 - String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";  
319 - failureMsg.append(msg + e.getMessage());  
320 - log.error(msg, e);  
321 - }  
322 - }  
323 - if (failureNum > 0) {  
324 - failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");  
325 - throw new CustomException(failureMsg.toString());  
326 - } else {  
327 - successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");  
328 - }  
329 - return successMsg.toString();  
330 - }  
331 -}  
ruoyi-ui/src/api/system/dept.js
@@ -20,7 +20,7 @@ export function listDeptExcludeChild(deptId) { @@ -20,7 +20,7 @@ export function listDeptExcludeChild(deptId) {
20 // 查询部门详细 20 // 查询部门详细
21 export function getDept(deptId) { 21 export function getDept(deptId) {
22 return request({ 22 return request({
23 - url: '/system/dept/' + deptId, 23 + url: '/system/dept/get?id=' + deptId,
24 method: 'get' 24 method: 'get'
25 }) 25 })
26 } 26 }
@@ -36,7 +36,7 @@ export function listSimpleDepts() { @@ -36,7 +36,7 @@ export function listSimpleDepts() {
36 // 新增部门 36 // 新增部门
37 export function addDept(data) { 37 export function addDept(data) {
38 return request({ 38 return request({
39 - url: '/system/dept', 39 + url: '/system/dept/create',
40 method: 'post', 40 method: 'post',
41 data: data 41 data: data
42 }) 42 })
@@ -45,19 +45,16 @@ export function addDept(data) { @@ -45,19 +45,16 @@ export function addDept(data) {
45 // 修改部门 45 // 修改部门
46 export function updateDept(data) { 46 export function updateDept(data) {
47 return request({ 47 return request({
48 - url: '/system/dept',  
49 - method: 'put', 48 + url: '/system/dept/update',
  49 + method: 'post',
50 data: data 50 data: data
51 }) 51 })
52 } 52 }
53 53
54 // 删除部门 54 // 删除部门
55 -export function delDept(deptId) { 55 +export function delDept(id) {
56 return request({ 56 return request({
57 - url: '/system/dept/' + deptId,  
58 - method: 'delete' 57 + url: '/system/dept/delete?id=' + id,
  58 + method: 'post'
59 }) 59 })
60 } 60 }
61 -  
62 -export class treeselect {  
63 -}  
ruoyi-ui/src/views/system/dept/index.vue
1 <template> 1 <template>
2 <div class="app-container"> 2 <div class="app-container">
3 <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"> 3 <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
4 - <el-form-item label="部门名称" prop="deptName"> 4 + <el-form-item label="部门名称" prop="name">
5 <el-input 5 <el-input
6 - v-model="queryParams.deptName" 6 + v-model="queryParams.name"
7 placeholder="请输入部门名称" 7 placeholder="请输入部门名称"
8 clearable 8 clearable
9 size="small" 9 size="small"
@@ -11,12 +11,12 @@ @@ -11,12 +11,12 @@
11 /> 11 />
12 </el-form-item> 12 </el-form-item>
13 <el-form-item label="状态" prop="status"> 13 <el-form-item label="状态" prop="status">
14 - <el-select v-model="queryParams.status" placeholder="部门状态" clearable size="small"> 14 + <el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small">
15 <el-option 15 <el-option
16 - v-for="dict in statusOptions"  
17 - :key="dict.dictValue"  
18 - :label="dict.dictLabel"  
19 - :value="dict.dictValue" 16 + v-for="dict in statusDictDatas"
  17 + :key="parseInt(dict.value)"
  18 + :label="dict.label"
  19 + :value="parseInt(dict.value)"
20 /> 20 />
21 </el-select> 21 </el-select>
22 </el-form-item> 22 </el-form-item>
@@ -42,12 +42,12 @@ @@ -42,12 +42,12 @@
42 <el-table 42 <el-table
43 v-loading="loading" 43 v-loading="loading"
44 :data="deptList" 44 :data="deptList"
45 - row-key="deptId" 45 + row-key="id"
46 default-expand-all 46 default-expand-all
47 :tree-props="{children: 'children', hasChildren: 'hasChildren'}" 47 :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
48 > 48 >
49 - <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>  
50 - <el-table-column prop="orderNum" label="排序" width="200"></el-table-column> 49 + <el-table-column prop="name" label="部门名称" width="260"></el-table-column>
  50 + <el-table-column prop="sort" label="排序" width="200"></el-table-column>
51 <el-table-column prop="status" label="状态" :formatter="statusFormat" width="100"></el-table-column> 51 <el-table-column prop="status" label="状态" :formatter="statusFormat" width="100"></el-table-column>
52 <el-table-column label="创建时间" align="center" prop="createTime" width="200"> 52 <el-table-column label="创建时间" align="center" prop="createTime" width="200">
53 <template slot-scope="scope"> 53 <template slot-scope="scope">
@@ -56,22 +56,22 @@ @@ -56,22 +56,22 @@
56 </el-table-column> 56 </el-table-column>
57 <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> 57 <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
58 <template slot-scope="scope"> 58 <template slot-scope="scope">
59 - <el-button  
60 - size="mini"  
61 - type="text"  
62 - icon="el-icon-edit" 59 + <el-button
  60 + size="mini"
  61 + type="text"
  62 + icon="el-icon-edit"
63 @click="handleUpdate(scope.row)" 63 @click="handleUpdate(scope.row)"
64 v-hasPermi="['system:dept:edit']" 64 v-hasPermi="['system:dept:edit']"
65 >修改</el-button> 65 >修改</el-button>
66 - <el-button  
67 - size="mini"  
68 - type="text"  
69 - icon="el-icon-plus" 66 + <el-button
  67 + size="mini"
  68 + type="text"
  69 + icon="el-icon-plus"
70 @click="handleAdd(scope.row)" 70 @click="handleAdd(scope.row)"
71 v-hasPermi="['system:dept:add']" 71 v-hasPermi="['system:dept:add']"
72 >新增</el-button> 72 >新增</el-button>
73 <el-button 73 <el-button
74 - v-if="scope.row.parentId != 0" 74 + v-if="scope.row.parentId !== 0"
75 size="mini" 75 size="mini"
76 type="text" 76 type="text"
77 icon="el-icon-delete" 77 icon="el-icon-delete"
@@ -92,13 +92,13 @@ @@ -92,13 +92,13 @@
92 </el-form-item> 92 </el-form-item>
93 </el-col> 93 </el-col>
94 <el-col :span="12"> 94 <el-col :span="12">
95 - <el-form-item label="部门名称" prop="deptName">  
96 - <el-input v-model="form.deptName" placeholder="请输入部门名称" /> 95 + <el-form-item label="部门名称" prop="name">
  96 + <el-input v-model="form.name" placeholder="请输入部门名称" />
97 </el-form-item> 97 </el-form-item>
98 </el-col> 98 </el-col>
99 <el-col :span="12"> 99 <el-col :span="12">
100 - <el-form-item label="显示排序" prop="orderNum">  
101 - <el-input-number v-model="form.orderNum" controls-position="right" :min="0" /> 100 + <el-form-item label="显示排序" prop="sort">
  101 + <el-input-number v-model="form.sort" controls-position="right" :min="0" />
102 </el-form-item> 102 </el-form-item>
103 </el-col> 103 </el-col>
104 <el-col :span="12"> 104 <el-col :span="12">
@@ -117,13 +117,13 @@ @@ -117,13 +117,13 @@
117 </el-form-item> 117 </el-form-item>
118 </el-col> 118 </el-col>
119 <el-col :span="12"> 119 <el-col :span="12">
120 - <el-form-item label="部门状态"> 120 + <el-form-item label="部门状态" prop="status">
121 <el-radio-group v-model="form.status"> 121 <el-radio-group v-model="form.status">
122 <el-radio 122 <el-radio
123 - v-for="dict in statusOptions"  
124 - :key="dict.dictValue"  
125 - :label="dict.dictValue"  
126 - >{{dict.dictLabel}}</el-radio> 123 + v-for="dict in statusDictDatas"
  124 + :key="parseInt(dict.value)"
  125 + :label="parseInt(dict.value)"
  126 + >{{dict.label}}</el-radio>
127 </el-radio-group> 127 </el-radio-group>
128 </el-form-item> 128 </el-form-item>
129 </el-col> 129 </el-col>
@@ -138,10 +138,13 @@ @@ -138,10 +138,13 @@
138 </template> 138 </template>
139 139
140 <script> 140 <script>
141 -import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept"; 141 +import { listDept, getDept, delDept, addDept, updateDept } from "@/api/system/dept";
142 import Treeselect from "@riophae/vue-treeselect"; 142 import Treeselect from "@riophae/vue-treeselect";
143 import "@riophae/vue-treeselect/dist/vue-treeselect.css"; 143 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
144 144
  145 +import {SysCommonStatusEnum, SysMenuTypeEnum} from '@/utils/constants'
  146 +import { getDictDataLabel, getDictDatas, DICT_TYPE } from '@/utils/dict'
  147 +
145 export default { 148 export default {
146 name: "Dept", 149 name: "Dept",
147 components: { Treeselect }, 150 components: { Treeselect },
@@ -163,7 +166,7 @@ export default { @@ -163,7 +166,7 @@ export default {
163 statusOptions: [], 166 statusOptions: [],
164 // 查询参数 167 // 查询参数
165 queryParams: { 168 queryParams: {
166 - deptName: undefined, 169 + name: undefined,
167 status: undefined 170 status: undefined
168 }, 171 },
169 // 表单参数 172 // 表单参数
@@ -173,10 +176,10 @@ export default { @@ -173,10 +176,10 @@ export default {
173 parentId: [ 176 parentId: [
174 { required: true, message: "上级部门不能为空", trigger: "blur" } 177 { required: true, message: "上级部门不能为空", trigger: "blur" }
175 ], 178 ],
176 - deptName: [ 179 + name: [
177 { required: true, message: "部门名称不能为空", trigger: "blur" } 180 { required: true, message: "部门名称不能为空", trigger: "blur" }
178 ], 181 ],
179 - orderNum: [ 182 + sort: [
180 { required: true, message: "显示排序不能为空", trigger: "blur" } 183 { required: true, message: "显示排序不能为空", trigger: "blur" }
181 ], 184 ],
182 email: [ 185 email: [
@@ -192,22 +195,27 @@ export default { @@ -192,22 +195,27 @@ export default {
192 message: "请输入正确的手机号码", 195 message: "请输入正确的手机号码",
193 trigger: "blur" 196 trigger: "blur"
194 } 197 }
  198 + ],
  199 + status: [
  200 + { required: true, message: "状态不能为空", trigger: "blur" }
195 ] 201 ]
196 - } 202 + },
  203 +
  204 + // 枚举
  205 + CommonStatusEnum: SysCommonStatusEnum,
  206 + // 数据字典
  207 + statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)
197 }; 208 };
198 }, 209 },
199 created() { 210 created() {
200 this.getList(); 211 this.getList();
201 - this.getDicts("sys_normal_disable").then(response => {  
202 - this.statusOptions = response.data;  
203 - });  
204 }, 212 },
205 methods: { 213 methods: {
206 /** 查询部门列表 */ 214 /** 查询部门列表 */
207 getList() { 215 getList() {
208 this.loading = true; 216 this.loading = true;
209 listDept(this.queryParams).then(response => { 217 listDept(this.queryParams).then(response => {
210 - this.deptList = this.handleTree(response.data, "deptId"); 218 + this.deptList = this.handleTree(response.data, "id");
211 this.loading = false; 219 this.loading = false;
212 }); 220 });
213 }, 221 },
@@ -217,14 +225,14 @@ export default { @@ -217,14 +225,14 @@ export default {
217 delete node.children; 225 delete node.children;
218 } 226 }
219 return { 227 return {
220 - id: node.deptId,  
221 - label: node.deptName, 228 + id: node.id,
  229 + label: node.name,
222 children: node.children 230 children: node.children
223 }; 231 };
224 }, 232 },
225 // 字典状态字典翻译 233 // 字典状态字典翻译
226 statusFormat(row, column) { 234 statusFormat(row, column) {
227 - return this.selectDictLabel(this.statusOptions, row.status); 235 + return getDictDataLabel(DICT_TYPE.SYS_COMMON_STATUS, row.status)
228 }, 236 },
229 // 取消按钮 237 // 取消按钮
230 cancel() { 238 cancel() {
@@ -234,10 +242,10 @@ export default { @@ -234,10 +242,10 @@ export default {
234 // 表单重置 242 // 表单重置
235 reset() { 243 reset() {
236 this.form = { 244 this.form = {
237 - deptId: undefined, 245 + id: undefined,
238 parentId: undefined, 246 parentId: undefined,
239 - deptName: undefined,  
240 - orderNum: undefined, 247 + name: undefined,
  248 + sort: undefined,
241 leader: undefined, 249 leader: undefined,
242 phone: undefined, 250 phone: undefined,
243 email: undefined, 251 email: undefined,
@@ -257,32 +265,32 @@ export default { @@ -257,32 +265,32 @@ export default {
257 /** 新增按钮操作 */ 265 /** 新增按钮操作 */
258 handleAdd(row) { 266 handleAdd(row) {
259 this.reset(); 267 this.reset();
260 - if (row != undefined) {  
261 - this.form.parentId = row.deptId; 268 + if (row !== undefined) {
  269 + this.form.parentId = row.id;
262 } 270 }
263 this.open = true; 271 this.open = true;
264 this.title = "添加部门"; 272 this.title = "添加部门";
265 listDept().then(response => { 273 listDept().then(response => {
266 - this.deptOptions = this.handleTree(response.data, "deptId"); 274 + this.deptOptions = this.handleTree(response.data, "id");
267 }); 275 });
268 }, 276 },
269 /** 修改按钮操作 */ 277 /** 修改按钮操作 */
270 handleUpdate(row) { 278 handleUpdate(row) {
271 this.reset(); 279 this.reset();
272 - getDept(row.deptId).then(response => { 280 + getDept(row.id).then(response => {
273 this.form = response.data; 281 this.form = response.data;
274 this.open = true; 282 this.open = true;
275 this.title = "修改部门"; 283 this.title = "修改部门";
276 }); 284 });
277 - listDeptExcludeChild(row.deptId).then(response => {  
278 - this.deptOptions = this.handleTree(response.data, "deptId"); 285 + listDept(row.id).then(response => {
  286 + this.deptOptions = this.handleTree(response.data, "id");
279 }); 287 });
280 }, 288 },
281 /** 提交按钮 */ 289 /** 提交按钮 */
282 submitForm: function() { 290 submitForm: function() {
283 this.$refs["form"].validate(valid => { 291 this.$refs["form"].validate(valid => {
284 if (valid) { 292 if (valid) {
285 - if (this.form.deptId != undefined) { 293 + if (this.form.id !== undefined) {
286 updateDept(this.form).then(response => { 294 updateDept(this.form).then(response => {
287 this.msgSuccess("修改成功"); 295 this.msgSuccess("修改成功");
288 this.open = false; 296 this.open = false;
@@ -300,12 +308,12 @@ export default { @@ -300,12 +308,12 @@ export default {
300 }, 308 },
301 /** 删除按钮操作 */ 309 /** 删除按钮操作 */
302 handleDelete(row) { 310 handleDelete(row) {
303 - this.$confirm('是否确认删除名称为"' + row.deptName + '"的数据项?', "警告", { 311 + this.$confirm('是否确认删除名称为"' + row.name + '"的数据项?', "警告", {
304 confirmButtonText: "确定", 312 confirmButtonText: "确定",
305 cancelButtonText: "取消", 313 cancelButtonText: "取消",
306 type: "warning" 314 type: "warning"
307 }).then(function() { 315 }).then(function() {
308 - return delDept(row.deptId); 316 + return delDept(row.id);
309 }).then(() => { 317 }).then(() => {
310 this.getList(); 318 this.getList();
311 this.msgSuccess("删除成功"); 319 this.msgSuccess("删除成功");
@@ -313,4 +321,4 @@ export default { @@ -313,4 +321,4 @@ export default {
313 } 321 }
314 } 322 }
315 }; 323 };
316 -</script>  
317 \ No newline at end of file 324 \ No newline at end of file
  325 +</script>
ruoyi-ui/src/views/system/menu/index.vue
@@ -163,9 +163,10 @@ @@ -163,9 +163,10 @@
163 <el-form-item v-if="form.type != '3'" label="菜单状态"> 163 <el-form-item v-if="form.type != '3'" label="菜单状态">
164 <el-radio-group v-model="form.status"> 164 <el-radio-group v-model="form.status">
165 <el-radio 165 <el-radio
166 - v-for="dict in statusDictDatas"  
167 - :key="dict.value"  
168 - :label="parseInt(dict.value)" 166 + v-for="dict in statusDictDatas"
  167 + :key="parseInt(dict.value)"
  168 + :label="dict.label"
  169 + :value="parseInt(dict.value)"
169 >{{dict.label}}</el-radio> 170 >{{dict.label}}</el-radio>
170 </el-radio-group> 171 </el-radio-group>
171 </el-form-item> 172 </el-form-item>
@@ -223,6 +224,9 @@ export default { @@ -223,6 +224,9 @@ export default {
223 ], 224 ],
224 path: [ 225 path: [
225 { required: true, message: "路由地址不能为空", trigger: "blur" } 226 { required: true, message: "路由地址不能为空", trigger: "blur" }
  227 + ],
  228 + status: [
  229 + { required: true, message: "状态不能为空", trigger: "blur" }
226 ] 230 ]
227 }, 231 },
228 232
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java
@@ -2,17 +2,15 @@ package cn.iocoder.dashboard.modules.system.controller.dept; @@ -2,17 +2,15 @@ package cn.iocoder.dashboard.modules.system.controller.dept;
2 2
3 import cn.iocoder.dashboard.common.enums.CommonStatusEnum; 3 import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
4 import cn.iocoder.dashboard.common.pojo.CommonResult; 4 import cn.iocoder.dashboard.common.pojo.CommonResult;
5 -import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO;  
6 -import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptRespVO;  
7 -import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO; 5 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.*;
8 import cn.iocoder.dashboard.modules.system.convert.dept.SysDeptConvert; 6 import cn.iocoder.dashboard.modules.system.convert.dept.SysDeptConvert;
9 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; 7 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
10 import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; 8 import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
11 import io.swagger.annotations.Api; 9 import io.swagger.annotations.Api;
  10 +import io.swagger.annotations.ApiImplicitParam;
12 import io.swagger.annotations.ApiOperation; 11 import io.swagger.annotations.ApiOperation;
13 -import org.springframework.web.bind.annotation.GetMapping;  
14 -import org.springframework.web.bind.annotation.RequestMapping;  
15 -import org.springframework.web.bind.annotation.RestController; 12 +import org.springframework.validation.annotation.Validated;
  13 +import org.springframework.web.bind.annotation.*;
16 14
17 import javax.annotation.Resource; 15 import javax.annotation.Resource;
18 import java.util.Comparator; 16 import java.util.Comparator;
@@ -49,4 +47,39 @@ public class SysDeptController { @@ -49,4 +47,39 @@ public class SysDeptController {
49 return success(SysDeptConvert.INSTANCE.convertList02(list)); 47 return success(SysDeptConvert.INSTANCE.convertList02(list));
50 } 48 }
51 49
  50 + @ApiOperation("获得部门信息")
  51 + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024")
  52 +// @PreAuthorize("@ss.hasPermi('system:dept:query')")
  53 + @GetMapping("/get")
  54 + public CommonResult<SysDeptRespVO> getDept(@RequestParam("id") Long id) {
  55 + return success(SysDeptConvert.INSTANCE.convert(deptService.getDept(id)));
  56 + }
  57 +
  58 + @ApiOperation("新增部门")
  59 + @PostMapping("create")
  60 +// @PreAuthorize("@ss.hasPermi('system:dept:add')")
  61 +// @Log(title = "部门管理", businessType = BusinessType.INSERT)
  62 + public CommonResult<Long> createDept(@Validated @RequestBody SysDeptCreateReqVO reqVO) {
  63 + Long deptId = deptService.createDept(reqVO);
  64 + return success(deptId);
  65 + }
  66 +
  67 + @ApiOperation("修改部门")
  68 + @PostMapping("update")
  69 +// @PreAuthorize("@ss.hasPermi('system:dept:edit')")
  70 +// @Log(title = "部门管理", businessType = BusinessType.UPDATE)
  71 + public CommonResult<Boolean> updateDept(@Validated @RequestBody SysDeptUpdateReqVO reqVO) {
  72 + deptService.updateDept(reqVO);
  73 + return success(true);
  74 + }
  75 +
  76 + @ApiOperation("删除部门")
  77 + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024")
  78 + @PostMapping("delete")
  79 +// @PreAuthorize("@ss.hasPermi('system:dept:remove')")
  80 +// @Log(title = "部门管理", businessType = BusinessType.DELETE)
  81 + public CommonResult<Boolean> deleteDept(@RequestParam("id") Long id) {
  82 + deptService.deleteDept(id);
  83 + return success(true);
  84 + }
52 } 85 }
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/dept/SysDeptBaseVO.java
@@ -40,4 +40,9 @@ public class SysDeptBaseVO { @@ -40,4 +40,9 @@ public class SysDeptBaseVO {
40 @Size(max = 50, message = "邮箱长度不能超过50个字符") 40 @Size(max = 50, message = "邮箱长度不能超过50个字符")
41 private String email; 41 private String email;
42 42
  43 + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 SysCommonStatusEnum 枚举")
  44 + @NotNull(message = "状态不能为空")
  45 +// @InEnum(value = SysCommonStatusEnum.class, message = "修改状态必须是 {value}")
  46 + private Integer status;
  47 +
43 } 48 }
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/dept/SysDeptListReqVO.java
@@ -3,12 +3,10 @@ package cn.iocoder.dashboard.modules.system.controller.dept.vo.dept; @@ -3,12 +3,10 @@ package cn.iocoder.dashboard.modules.system.controller.dept.vo.dept;
3 import io.swagger.annotations.ApiModel; 3 import io.swagger.annotations.ApiModel;
4 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
5 import lombok.Data; 5 import lombok.Data;
6 -import lombok.EqualsAndHashCode;  
7 6
8 @ApiModel("部门列表 Request VO") 7 @ApiModel("部门列表 Request VO")
9 @Data 8 @Data
10 -@EqualsAndHashCode(callSuper = true)  
11 -public class SysDeptListReqVO extends SysDeptBaseVO { 9 +public class SysDeptListReqVO {
12 10
13 @ApiModelProperty(value = "部门名称", example = "芋道", notes = "模糊匹配") 11 @ApiModelProperty(value = "部门名称", example = "芋道", notes = "模糊匹配")
14 private String name; 12 private String name;
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/dept/SysDeptRespVO.java
@@ -15,9 +15,6 @@ public class SysDeptRespVO extends SysDeptBaseVO { @@ -15,9 +15,6 @@ public class SysDeptRespVO extends SysDeptBaseVO {
15 @ApiModelProperty(value = "部门编号", required = true, example = "1024") 15 @ApiModelProperty(value = "部门编号", required = true, example = "1024")
16 private Integer id; 16 private Integer id;
17 17
18 - @ApiModelProperty(value = "祖级列表", required = true, example = "0,100")  
19 - private String ancestors;  
20 -  
21 @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") 18 @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
22 private Integer status; 19 private Integer status;
23 20
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/vo/dept/SysDeptUpdateReqVO.java
@@ -14,6 +14,6 @@ public class SysDeptUpdateReqVO extends SysDeptBaseVO { @@ -14,6 +14,6 @@ public class SysDeptUpdateReqVO extends SysDeptBaseVO {
14 14
15 @ApiModelProperty(value = "部门编号", required = true, example = "1024") 15 @ApiModelProperty(value = "部门编号", required = true, example = "1024")
16 @NotNull(message = "部门编号不能为空") 16 @NotNull(message = "部门编号不能为空")
17 - private Integer id; 17 + private Long id;
18 18
19 } 19 }
src/main/java/cn/iocoder/dashboard/modules/system/convert/dept/SysDeptConvert.java
1 package cn.iocoder.dashboard.modules.system.convert.dept; 1 package cn.iocoder.dashboard.modules.system.convert.dept;
2 2
  3 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO;
3 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptRespVO; 4 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptRespVO;
4 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO; 5 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO;
  6 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptUpdateReqVO;
5 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; 7 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
6 import org.mapstruct.Mapper; 8 import org.mapstruct.Mapper;
7 import org.mapstruct.factory.Mappers; 9 import org.mapstruct.factory.Mappers;
@@ -17,4 +19,10 @@ public interface SysDeptConvert { @@ -17,4 +19,10 @@ public interface SysDeptConvert {
17 19
18 List<SysDeptSimpleRespVO> convertList02(List<SysDeptDO> list); 20 List<SysDeptSimpleRespVO> convertList02(List<SysDeptDO> list);
19 21
  22 + SysDeptRespVO convert(SysDeptDO bean);
  23 +
  24 + SysDeptDO convert(SysDeptCreateReqVO bean);
  25 +
  26 + SysDeptDO convert(SysDeptUpdateReqVO bean);
  27 +
20 } 28 }
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dept/SysDeptMapper.java
@@ -21,4 +21,13 @@ public interface SysDeptMapper extends BaseMapper&lt;SysDeptDO&gt; { @@ -21,4 +21,13 @@ public interface SysDeptMapper extends BaseMapper&lt;SysDeptDO&gt; {
21 .eqIfPresent("status", reqVO.getStatus())); 21 .eqIfPresent("status", reqVO.getStatus()));
22 } 22 }
23 23
  24 + default SysDeptDO selectByParentIdAndName(Long parentId, String name) {
  25 + return selectOne(new QueryWrapper<SysDeptDO>().eq("parent_id", parentId)
  26 + .eq("name", name));
  27 + }
  28 +
  29 + default Integer selectCountByParentId(Long parentId) {
  30 + return selectCount(new QueryWrapper<SysDeptDO>().eq("parent_id", parentId));
  31 + }
  32 +
24 } 33 }
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dept/SysDeptDO.java
@@ -33,10 +33,6 @@ public class SysDeptDO extends BaseDO { @@ -33,10 +33,6 @@ public class SysDeptDO extends BaseDO {
33 */ 33 */
34 private Long parentId; 34 private Long parentId;
35 /** 35 /**
36 - * 祖级列表  
37 - */  
38 - private String ancestors;  
39 - /**  
40 * 显示顺序 36 * 显示顺序
41 */ 37 */
42 private String sort; 38 private String sort;
src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java
@@ -43,9 +43,10 @@ public interface SysErrorCodeConstants { @@ -43,9 +43,10 @@ public interface SysErrorCodeConstants {
43 ErrorCode DEPT_PARENT_NOT_EXITS = new ErrorCode(1002004002,"父级部门不存在"); 43 ErrorCode DEPT_PARENT_NOT_EXITS = new ErrorCode(1002004002,"父级部门不存在");
44 ErrorCode DEPT_NOT_FOUND = new ErrorCode(1002004003, "当前部门不存在"); 44 ErrorCode DEPT_NOT_FOUND = new ErrorCode(1002004003, "当前部门不存在");
45 ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1002004004, "存在子部门,无法删除"); 45 ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1002004004, "存在子部门,无法删除");
46 - ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1002004005, "不能设置自己为父资源"); 46 + ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1002004005, "不能设置自己为父部门");
47 ErrorCode DEPT_EXISTS_USER = new ErrorCode(1002004006, "部门中存在员工,无法删除"); 47 ErrorCode DEPT_EXISTS_USER = new ErrorCode(1002004006, "部门中存在员工,无法删除");
48 ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1002004007, "部门不处于开启状态,不允许选择"); 48 ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1002004007, "部门不处于开启状态,不允许选择");
  49 + ErrorCode DEPT_PARENT_IS_CHILD = new ErrorCode(1002004008, "不能设置自己的子部门为父部门");
49 50
50 // ========== 岗位模块 1002005000 ========== 51 // ========== 岗位模块 1002005000 ==========
51 ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在"); 52 ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在");
src/main/java/cn/iocoder/dashboard/modules/system/enums/dept/DeptIdEnum.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.enums.dept;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Getter;
  5 +
  6 +/**
  7 + * 部门编号枚举
  8 + */
  9 +@Getter
  10 +@AllArgsConstructor
  11 +public enum DeptIdEnum {
  12 +
  13 + /**
  14 + * 根节点
  15 + */
  16 + ROOT(0L);
  17 +
  18 + private final Long id;
  19 +
  20 +}
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptService.java
1 package cn.iocoder.dashboard.modules.system.service.dept; 1 package cn.iocoder.dashboard.modules.system.service.dept;
2 2
  3 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO;
3 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO; 4 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO;
  5 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptUpdateReqVO;
4 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; 6 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
5 7
6 import java.util.Collection; 8 import java.util.Collection;
@@ -58,4 +60,26 @@ public interface SysDeptService { @@ -58,4 +60,26 @@ public interface SysDeptService {
58 */ 60 */
59 SysDeptDO getDept(Long id); 61 SysDeptDO getDept(Long id);
60 62
  63 + /**
  64 + * 创建部门
  65 + *
  66 + * @param reqVO 部门信息
  67 + * @return 部门编号
  68 + */
  69 + Long createDept(SysDeptCreateReqVO reqVO);
  70 +
  71 + /**
  72 + * 更新部门
  73 + *
  74 + * @param reqVO 部门信息
  75 + */
  76 + void updateDept(SysDeptUpdateReqVO reqVO);
  77 +
  78 + /**
  79 + * 删除部门
  80 + *
  81 + * @param id 部门编号
  82 + */
  83 + void deleteDept(Long id);
  84 +
61 } 85 }
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java
1 package cn.iocoder.dashboard.modules.system.service.dept.impl; 1 package cn.iocoder.dashboard.modules.system.service.dept.impl;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
  5 +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
  6 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO;
4 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO; 7 import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptListReqVO;
  8 +import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptUpdateReqVO;
  9 +import cn.iocoder.dashboard.modules.system.convert.dept.SysDeptConvert;
5 import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysDeptMapper; 10 import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysDeptMapper;
6 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; 11 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
  12 +import cn.iocoder.dashboard.modules.system.enums.dept.DeptIdEnum;
7 import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; 13 import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
8 import com.google.common.collect.ImmutableMap; 14 import com.google.common.collect.ImmutableMap;
9 import com.google.common.collect.ImmutableMultimap; 15 import com.google.common.collect.ImmutableMultimap;
@@ -18,6 +24,8 @@ import java.util.Collection; @@ -18,6 +24,8 @@ import java.util.Collection;
18 import java.util.List; 24 import java.util.List;
19 import java.util.Map; 25 import java.util.Map;
20 26
  27 +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
  28 +
21 /** 29 /**
22 * 部门 Service 实现类 30 * 部门 Service 实现类
23 * 31 *
@@ -119,4 +127,105 @@ public class SysDeptServiceImpl implements SysDeptService { @@ -119,4 +127,105 @@ public class SysDeptServiceImpl implements SysDeptService {
119 return deptMapper.selectById(id); 127 return deptMapper.selectById(id);
120 } 128 }
121 129
  130 + @Override
  131 + public Long createDept(SysDeptCreateReqVO reqVO) {
  132 + // 校验正确性
  133 + checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName());
  134 + // 插入部门
  135 + SysDeptDO dept = SysDeptConvert.INSTANCE.convert(reqVO);
  136 + deptMapper.insert(dept);
  137 + return dept.getId();
  138 + }
  139 +
  140 + @Override
  141 + public void updateDept(SysDeptUpdateReqVO reqVO) {
  142 + // 校验正确性
  143 + checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
  144 + // 更新部门
  145 + SysDeptDO updateObj = SysDeptConvert.INSTANCE.convert(reqVO);
  146 + deptMapper.updateById(updateObj);
  147 + }
  148 +
  149 + @Override
  150 + public void deleteDept(Long id) {
  151 + // 校验是否存在
  152 + checkDeptExists(id);
  153 + // 校验是否有子部门
  154 + if (deptMapper.selectCountByParentId(id) > 0) {
  155 + throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN);
  156 + }
  157 + // 删除部门
  158 + deptMapper.deleteById(id);
  159 + }
  160 +
  161 + private void checkCreateOrUpdate(Long id, Long parentId, String name) {
  162 + // 校验自己存在
  163 + checkDeptExists(id);
  164 + // 校验父部门的有效性
  165 + checkParentDeptEnable(id, parentId);
  166 + // 校验部门名的唯一性
  167 + checkDeptNameUnique(id, parentId, name);
  168 + }
  169 +
  170 + private void checkParentDeptEnable(Long id, Long parentId) {
  171 + if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) {
  172 + return;
  173 + }
  174 + // 不能设置自己为父部门
  175 + if (parentId.equals(id)) {
  176 + throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR);
  177 + }
  178 + // 父菜单不存在
  179 + SysDeptDO dept = deptMapper.selectById(parentId);
  180 + if (dept == null) {
  181 + throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS);
  182 + }
  183 + // 父部门被禁用
  184 + if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) {
  185 + throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE);
  186 + }
  187 + // 父部门不能是原来的子部门
  188 + List<SysDeptDO> children = this.listDeptsByParentIdFromCache(id, true);
  189 + if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) {
  190 + throw ServiceExceptionUtil.exception(DEPT_PARENT_IS_CHILD);
  191 + }
  192 + }
  193 +
  194 + private void checkDeptExists(Long id) {
  195 + if (id == null) {
  196 + return;
  197 + }
  198 + SysDeptDO dept = deptMapper.selectById(id);
  199 + if (dept == null) {
  200 + throw ServiceExceptionUtil.exception(DEPT_NOT_FOUND);
  201 + }
  202 + }
  203 +
  204 + private void checkDeptNameUnique(Long id, Long parentId, String name) {
  205 + SysDeptDO menu = deptMapper.selectByParentIdAndName(parentId, name);
  206 + if (menu == null) {
  207 + return;
  208 + }
  209 + // 如果 id 为空,说明不用比较是否为相同 id 的菜单
  210 + if (id == null) {
  211 + throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
  212 + }
  213 + if (!menu.getId().equals(id)) {
  214 + throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
  215 + }
  216 + }
  217 +
  218 +// /**
  219 +// * 查询部门管理数据
  220 +// *
  221 +// * @param dept 部门信息
  222 +// * @return 部门信息集合
  223 +// */
  224 +// @Override
  225 +// @DataScope(deptAlias = "d")
  226 +// public List<SysDept> selectDeptList(SysDept dept)
  227 +// {
  228 +// return deptMapper.selectDeptList(dept);
  229 +// }
  230 +
122 } 231 }
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java
@@ -206,4 +206,16 @@ public class SysRoleServiceImpl implements SysRoleService { @@ -206,4 +206,16 @@ public class SysRoleServiceImpl implements SysRoleService {
206 } 206 }
207 } 207 }
208 208
  209 +
  210 +// /**
  211 +// * 根据条件分页查询角色数据
  212 +// *
  213 +// * @param role 角色信息
  214 +// * @return 角色数据集合信息
  215 +// */
  216 +// @Override
  217 +// @DataScope(deptAlias = "d")
  218 +// public List<SysRole> selectRoleList(SysRole role) {
  219 +// return roleMapper.selectRoleList(role);
  220 +// }
209 } 221 }
src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java
@@ -253,33 +253,6 @@ public class SysUserServiceImpl implements SysUserService { @@ -253,33 +253,6 @@ public class SysUserServiceImpl implements SysUserService {
253 }); 253 });
254 } 254 }
255 255
256 -  
257 -// /**  
258 -// * 新增用户角色信息  
259 -// *  
260 -// * @param user 用户对象  
261 -// */  
262 -// public void insertUserRole(SysUser user)  
263 -// {  
264 -// Long[] roles = user.getRoleIds();  
265 -// if (StringUtils.isNotNull(roles))  
266 -// {  
267 -// // 新增用户与角色管理  
268 -// List<SysUserRole> list = new ArrayList<SysUserRole>();  
269 -// for (Long roleId : roles)  
270 -// {  
271 -// SysUserRole ur = new SysUserRole();  
272 -// ur.setUserId(user.getUserId());  
273 -// ur.setRoleId(roleId);  
274 -// list.add(ur);  
275 -// }  
276 -// if (list.size() > 0)  
277 -// {  
278 -// userRoleMapper.batchUserRole(list);  
279 -// }  
280 -// }  
281 -// }  
282 -  
283 // /** 256 // /**
284 // * 导入用户数据 257 // * 导入用户数据
285 // * 258 // *
@@ -347,4 +320,15 @@ public class SysUserServiceImpl implements SysUserService { @@ -347,4 +320,15 @@ public class SysUserServiceImpl implements SysUserService {
347 // return successMsg.toString(); 320 // return successMsg.toString();
348 // } 321 // }
349 322
  323 +// /**
  324 +// * 根据条件分页查询用户列表
  325 +// *
  326 +// * @param user 用户信息
  327 +// * @return 用户信息集合信息
  328 +// */
  329 +// @Override
  330 +// @DataScope(deptAlias = "d", userAlias = "u")
  331 +// public List<SysUser> selectUserList(SysUser user) {
  332 +// return userMapper.selectUserList(user);
  333 +// }
350 } 334 }