cee572f2
RuoYi
若依 3.0
|
1
|
package com.ruoyi.web.controller.system;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
2
|
|
9f4918cc
RuoYi
修改上级部门(选择项排除本身和下级)
|
3
|
import java.util.Iterator;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
4
|
import java.util.List;
|
9f4918cc
RuoYi
修改上级部门(选择项排除本身和下级)
|
5
|
import org.apache.commons.lang3.ArrayUtils;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
6
7
|
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
|
bcee37b8
RuoYi
若依 1.1
|
8
|
import org.springframework.validation.annotation.Validated;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
9
10
11
12
13
14
15
|
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;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
16
|
import org.springframework.web.bind.annotation.RestController;
|
cee572f2
RuoYi
若依 3.0
|
17
|
import com.ruoyi.common.annotation.Log;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
18
|
import com.ruoyi.common.constant.UserConstants;
|
cee572f2
RuoYi
若依 3.0
|
19
20
21
22
|
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;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
23
|
import com.ruoyi.common.utils.SecurityUtils;
|
4b773784
RuoYi
添加校验部门包含未停用的子部门
|
24
|
import com.ruoyi.common.utils.StringUtils;
|
cee572f2
RuoYi
若依 3.0
|
25
|
import com.ruoyi.system.service.ISysDeptService;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/**
* 部门信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/dept")
public class SysDeptController extends BaseController
{
@Autowired
private ISysDeptService deptService;
/**
* 获取部门列表
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list")
public AjaxResult list(SysDept dept)
{
List<SysDept> depts = deptService.selectDeptList(dept);
|
cb0a4b78
RuoYi
若依 2.1
|
47
|
return AjaxResult.success(depts);
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
48
49
50
|
}
/**
|
9f4918cc
RuoYi
修改上级部门(选择项排除本身和下级)
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
* 查询部门列表(排除节点)
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list/exclude/{deptId}")
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
{
List<SysDept> depts = deptService.selectDeptList(new SysDept());
Iterator<SysDept> it = depts.iterator();
while (it.hasNext())
{
SysDept d = (SysDept) it.next();
if (d.getDeptId().intValue() == deptId
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
{
it.remove();
}
}
return AjaxResult.success(depts);
}
/**
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
72
73
74
75
76
77
78
79
80
81
82
83
|
* 根据部门编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:dept:query')")
@GetMapping(value = "/{deptId}")
public AjaxResult getInfo(@PathVariable Long deptId)
{
return AjaxResult.success(deptService.selectDeptById(deptId));
}
/**
* 获取部门下拉树列表
*/
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
84
85
86
87
88
89
90
91
92
93
|
@GetMapping("/treeselect")
public AjaxResult treeselect(SysDept dept)
{
List<SysDept> depts = deptService.selectDeptList(dept);
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
}
/**
* 加载对应角色部门列表树
*/
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
94
|
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
95
96
|
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
{
|
554beaf6
RuoYi
修改在角色管理页修改菜单权限偶尔未...
|
97
98
99
100
101
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
ajax.put("depts", deptService.buildDeptTreeSelect(depts));
return ajax;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
102
103
104
105
106
107
108
109
|
}
/**
* 新增部门
*/
@PreAuthorize("@ss.hasPermi('system:dept:add')")
@Log(title = "部门管理", businessType = BusinessType.INSERT)
@PostMapping
|
bcee37b8
RuoYi
若依 1.1
|
110
|
public AjaxResult add(@Validated @RequestBody SysDept dept)
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
{
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
|
bcee37b8
RuoYi
若依 1.1
|
126
|
public AjaxResult edit(@Validated @RequestBody SysDept dept)
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
127
128
129
130
131
132
133
134
135
|
{
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() + "'失败,上级部门不能是自己");
}
|
4b773784
RuoYi
添加校验部门包含未停用的子部门
|
136
137
138
139
140
|
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
&& deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
{
return AjaxResult.error("该部门包含未停用的子部门!");
}
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
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));
}
}
|