提交 | 用户 | 时间
|
e57a89
|
1 |
package com.jcdm.web.controller.system; |
懒 |
2 |
|
|
3 |
import java.util.List; |
|
4 |
import org.apache.commons.lang3.ArrayUtils; |
|
5 |
import org.springframework.beans.factory.annotation.Autowired; |
|
6 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
7 |
import org.springframework.validation.annotation.Validated; |
|
8 |
import org.springframework.web.bind.annotation.DeleteMapping; |
|
9 |
import org.springframework.web.bind.annotation.GetMapping; |
|
10 |
import org.springframework.web.bind.annotation.PathVariable; |
|
11 |
import org.springframework.web.bind.annotation.PostMapping; |
|
12 |
import org.springframework.web.bind.annotation.PutMapping; |
|
13 |
import org.springframework.web.bind.annotation.RequestBody; |
|
14 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
15 |
import org.springframework.web.bind.annotation.RestController; |
|
16 |
import com.jcdm.common.annotation.Log; |
|
17 |
import com.jcdm.common.constant.UserConstants; |
|
18 |
import com.jcdm.common.core.controller.BaseController; |
|
19 |
import com.jcdm.common.core.domain.AjaxResult; |
|
20 |
import com.jcdm.common.core.domain.entity.SysDept; |
|
21 |
import com.jcdm.common.enums.BusinessType; |
|
22 |
import com.jcdm.common.utils.StringUtils; |
|
23 |
import com.jcdm.system.service.ISysDeptService; |
|
24 |
|
|
25 |
/** |
|
26 |
* 部门信息 |
|
27 |
* |
|
28 |
* @author jc |
|
29 |
*/ |
|
30 |
@RestController |
|
31 |
@RequestMapping("/system/dept") |
|
32 |
public class SysDeptController extends BaseController |
|
33 |
{ |
|
34 |
@Autowired |
|
35 |
private ISysDeptService deptService; |
|
36 |
|
|
37 |
/** |
|
38 |
* 获取部门列表 |
|
39 |
*/ |
|
40 |
@PreAuthorize("@ss.hasPermi('system:dept:list')") |
|
41 |
@GetMapping("/list") |
|
42 |
public AjaxResult list(SysDept dept) |
|
43 |
{ |
|
44 |
List<SysDept> depts = deptService.selectDeptList(dept); |
|
45 |
return success(depts); |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* 查询部门列表(排除节点) |
|
50 |
*/ |
|
51 |
@PreAuthorize("@ss.hasPermi('system:dept:list')") |
|
52 |
@GetMapping("/list/exclude/{deptId}") |
|
53 |
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) |
|
54 |
{ |
|
55 |
List<SysDept> depts = deptService.selectDeptList(new SysDept()); |
|
56 |
depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); |
|
57 |
return success(depts); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* 根据部门编号获取详细信息 |
|
62 |
*/ |
|
63 |
@PreAuthorize("@ss.hasPermi('system:dept:query')") |
|
64 |
@GetMapping(value = "/{deptId}") |
|
65 |
public AjaxResult getInfo(@PathVariable Long deptId) |
|
66 |
{ |
|
67 |
deptService.checkDeptDataScope(deptId); |
|
68 |
return success(deptService.selectDeptById(deptId)); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* 新增部门 |
|
73 |
*/ |
|
74 |
@PreAuthorize("@ss.hasPermi('system:dept:add')") |
|
75 |
@Log(title = "部门管理", businessType = BusinessType.INSERT) |
|
76 |
@PostMapping |
|
77 |
public AjaxResult add(@Validated @RequestBody SysDept dept) |
|
78 |
{ |
|
79 |
if (!deptService.checkDeptNameUnique(dept)) |
|
80 |
{ |
|
81 |
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); |
|
82 |
} |
|
83 |
dept.setCreateBy(getUsername()); |
|
84 |
return toAjax(deptService.insertDept(dept)); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* 修改部门 |
|
89 |
*/ |
|
90 |
@PreAuthorize("@ss.hasPermi('system:dept:edit')") |
|
91 |
@Log(title = "部门管理", businessType = BusinessType.UPDATE) |
|
92 |
@PutMapping |
|
93 |
public AjaxResult edit(@Validated @RequestBody SysDept dept) |
|
94 |
{ |
|
95 |
Long deptId = dept.getDeptId(); |
|
96 |
deptService.checkDeptDataScope(deptId); |
|
97 |
if (!deptService.checkDeptNameUnique(dept)) |
|
98 |
{ |
|
99 |
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); |
|
100 |
} |
|
101 |
else if (dept.getParentId().equals(deptId)) |
|
102 |
{ |
|
103 |
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); |
|
104 |
} |
|
105 |
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) |
|
106 |
{ |
|
107 |
return error("该部门包含未停用的子部门!"); |
|
108 |
} |
|
109 |
dept.setUpdateBy(getUsername()); |
|
110 |
return toAjax(deptService.updateDept(dept)); |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* 删除部门 |
|
115 |
*/ |
|
116 |
@PreAuthorize("@ss.hasPermi('system:dept:remove')") |
|
117 |
@Log(title = "部门管理", businessType = BusinessType.DELETE) |
|
118 |
@DeleteMapping("/{deptId}") |
|
119 |
public AjaxResult remove(@PathVariable Long deptId) |
|
120 |
{ |
|
121 |
if (deptService.hasChildByDeptId(deptId)) |
|
122 |
{ |
|
123 |
return warn("存在下级部门,不允许删除"); |
|
124 |
} |
|
125 |
if (deptService.checkDeptExistUser(deptId)) |
|
126 |
{ |
|
127 |
return warn("部门存在用户,不允许删除"); |
|
128 |
} |
|
129 |
deptService.checkDeptDataScope(deptId); |
|
130 |
return toAjax(deptService.deleteDeptById(deptId)); |
|
131 |
} |
|
132 |
} |