SysDeptController.java
3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.gxb.modules.sys.controller;
import com.gxb.common.utils.Constant;
import com.gxb.modules.sys.service.SysDeptService;
import com.gxb.common.utils.R;
import com.gxb.modules.sys.entity.SysDeptEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 部门管理
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2017-06-20 15:23:47
*/
@RestController
@RequestMapping("/sys/dept")
public class SysDeptController extends AbstractController {
@Autowired
private SysDeptService sysDeptService;
/**
* 列表
*/
@RequestMapping("/list")
@RequiresPermissions("sys:dept:list")
public List<SysDeptEntity> list(){
Map<String, Object> map = new HashMap<>();
//如果不是超级管理员,则只能查询本部门及子部门数据
if(getUserId() != Constant.SUPER_ADMIN){
map.put("deptFilter", sysDeptService.getSubDeptIdList(getDeptId()));
}
List<SysDeptEntity> deptList = sysDeptService.queryList(map);
return deptList;
}
/**
* 选择部门(添加、修改菜单)
*/
@RequestMapping("/select")
@RequiresPermissions("sys:dept:select")
public R select(){
Map<String, Object> map = new HashMap<>();
//如果不是超级管理员,则只能查询本部门及子部门数据
if(getUserId() != Constant.SUPER_ADMIN){
map.put("deptFilter", sysDeptService.getSubDeptIdList(getDeptId()));
}
List<SysDeptEntity> deptList = sysDeptService.queryList(map);
//添加一级部门
if(getUserId() == Constant.SUPER_ADMIN){
SysDeptEntity root = new SysDeptEntity();
root.setDeptId(0L);
root.setName("一级部门");
root.setParentId(-1L);
root.setOpen(true);
deptList.add(root);
}
return R.ok().put("deptList", deptList);
}
/**
* 上级部门Id(管理员则为0)
*/
@RequestMapping("/info")
@RequiresPermissions("sys:dept:list")
public R info(){
long deptId = 0;
if(getUserId() != Constant.SUPER_ADMIN){
SysDeptEntity dept = sysDeptService.queryObject(getDeptId());
deptId = dept.getParentId();
}
return R.ok().put("deptId", deptId);
}
/**
* 信息
*/
@RequestMapping("/info/{deptId}")
@RequiresPermissions("sys:dept:info")
public R info(@PathVariable("deptId") Long deptId){
SysDeptEntity dept = sysDeptService.queryObject(deptId);
return R.ok().put("dept", dept);
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("sys:dept:save")
public R save(@RequestBody SysDeptEntity dept){
sysDeptService.save(dept);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("sys:dept:update")
public R update(@RequestBody SysDeptEntity dept){
sysDeptService.update(dept);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("sys:dept:delete")
public R delete(long deptId){
//判断是否有子部门
List<Long> deptList = sysDeptService.queryDetpIdList(deptId);
if(deptList.size() > 0){
return R.error("请先删除子部门");
}
sysDeptService.delete(deptId);
return R.ok();
}
}