提交 | 用户 | 时间
|
1ac2bc
|
1 |
/** |
懒 |
2 |
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng) |
|
3 |
* <p> |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* <p> |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* <p> |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
package cn.stylefeng.guns.sys.modular.system.controller; |
|
17 |
|
|
18 |
import cn.hutool.core.bean.BeanUtil; |
|
19 |
import cn.stylefeng.guns.base.auth.annotion.Permission; |
|
20 |
import cn.stylefeng.guns.base.log.BussinessLog; |
|
21 |
import cn.stylefeng.guns.base.pojo.node.LayuiTreeNode; |
|
22 |
import cn.stylefeng.guns.base.pojo.node.TreeviewNode; |
|
23 |
import cn.stylefeng.guns.base.pojo.node.ZTreeNode; |
|
24 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; |
|
25 |
import cn.stylefeng.guns.sys.core.constant.dictmap.DeptDict; |
|
26 |
import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory; |
|
27 |
import cn.stylefeng.guns.sys.core.log.LogObjectHolder; |
|
28 |
import cn.stylefeng.guns.sys.modular.system.entity.Dept; |
|
29 |
import cn.stylefeng.guns.sys.modular.system.factory.LayuiTreeFactory; |
|
30 |
import cn.stylefeng.guns.sys.modular.system.model.DeptDto; |
|
31 |
import cn.stylefeng.guns.sys.modular.system.service.DeptService; |
|
32 |
import cn.stylefeng.guns.sys.modular.system.warpper.DeptTreeWrapper; |
|
33 |
import cn.stylefeng.guns.sys.modular.system.warpper.DeptWrapper; |
|
34 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
35 |
import cn.stylefeng.roses.core.treebuild.DefaultTreeBuildFactory; |
|
36 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
37 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
38 |
import org.springframework.beans.factory.annotation.Autowired; |
|
39 |
import org.springframework.stereotype.Controller; |
|
40 |
import org.springframework.web.bind.annotation.PathVariable; |
|
41 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
42 |
import org.springframework.web.bind.annotation.RequestParam; |
|
43 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
44 |
|
|
45 |
import javax.validation.Valid; |
|
46 |
import java.util.List; |
|
47 |
import java.util.Map; |
|
48 |
|
|
49 |
/** |
|
50 |
* 部门控制器 |
|
51 |
* |
|
52 |
* @author fengshuonan |
|
53 |
* @Date 2017年2月17日20:27:22 |
|
54 |
*/ |
|
55 |
@Controller |
|
56 |
@RequestMapping("/dept") |
|
57 |
public class DeptController extends BaseController { |
|
58 |
|
|
59 |
private String PREFIX = "/modular/system/dept/"; |
|
60 |
|
|
61 |
@Autowired |
|
62 |
private DeptService deptService; |
|
63 |
|
|
64 |
/** |
|
65 |
* 跳转到部门管理首页 |
|
66 |
* |
|
67 |
* @author fengshuonan |
|
68 |
* @Date 2018/12/23 4:56 PM |
|
69 |
*/ |
|
70 |
@RequestMapping("") |
|
71 |
public String index() { |
|
72 |
return PREFIX + "dept.html"; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* 跳转到添加部门 |
|
77 |
* |
|
78 |
* @author fengshuonan |
|
79 |
* @Date 2018/12/23 4:56 PM |
|
80 |
*/ |
|
81 |
@RequestMapping("/dept_add") |
|
82 |
public String deptAdd() { |
|
83 |
return PREFIX + "dept_add.html"; |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* 跳转到修改部门 |
|
88 |
* |
|
89 |
* @author fengshuonan |
|
90 |
* @Date 2018/12/23 4:56 PM |
|
91 |
*/ |
|
92 |
@Permission |
|
93 |
@RequestMapping("/dept_update") |
|
94 |
public String deptUpdate(@RequestParam("deptId") Long deptId) { |
|
95 |
Dept dept = deptService.getById(deptId); |
|
96 |
LogObjectHolder.me().set(dept); |
|
97 |
|
|
98 |
return PREFIX + "dept_edit.html"; |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* 获取部门的tree列表,layuiTree格式 |
|
103 |
* |
|
104 |
* @author fengshuonan |
|
105 |
* @Date 2018/12/23 4:56 PM |
|
106 |
*/ |
|
107 |
@RequestMapping(value = "/layuiTree") |
|
108 |
@ResponseBody |
|
109 |
public List<LayuiTreeNode> layuiTree() { |
|
110 |
|
|
111 |
List<LayuiTreeNode> list = this.deptService.layuiTree(); |
|
112 |
list.add(LayuiTreeFactory.createRoot()); |
|
113 |
|
|
114 |
DefaultTreeBuildFactory<LayuiTreeNode> treeBuildFactory = new DefaultTreeBuildFactory<>(); |
|
115 |
treeBuildFactory.setRootParentId("-1"); |
|
116 |
return treeBuildFactory.doTreeBuild(list); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* 获取部门的tree列表,ztree格式 |
|
121 |
* |
|
122 |
* @author fengshuonan |
|
123 |
* @Date 2019-8-27 15:24 |
|
124 |
*/ |
|
125 |
@RequestMapping(value = "/tree") |
|
126 |
@ResponseBody |
|
127 |
public List<ZTreeNode> tree() { |
|
128 |
List<ZTreeNode> tree = this.deptService.tree(); |
|
129 |
tree.add(ZTreeNode.createParent()); |
|
130 |
return tree; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* 获取部门的tree列表,treeview格式 |
|
135 |
* |
|
136 |
* @author fengshuonan |
|
137 |
* @Date 2018/12/23 4:57 PM |
|
138 |
*/ |
|
139 |
@RequestMapping(value = "/treeview") |
|
140 |
@ResponseBody |
|
141 |
public List<TreeviewNode> treeview() { |
|
142 |
List<TreeviewNode> treeviewNodes = this.deptService.treeviewNodes(); |
|
143 |
|
|
144 |
//构建树 |
|
145 |
DefaultTreeBuildFactory<TreeviewNode> factory = new DefaultTreeBuildFactory<>(); |
|
146 |
factory.setRootParentId("0"); |
|
147 |
List<TreeviewNode> results = factory.doTreeBuild(treeviewNodes); |
|
148 |
|
|
149 |
//把子节点为空的设为null |
|
150 |
DeptTreeWrapper.clearNull(results); |
|
151 |
|
|
152 |
return results; |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* 新增部门 |
|
157 |
* |
|
158 |
* @author fengshuonan |
|
159 |
* @Date 2018/12/23 4:57 PM |
|
160 |
*/ |
|
161 |
@BussinessLog(value = "添加部门", key = "simpleName", dict = DeptDict.class) |
|
162 |
@RequestMapping(value = "/add") |
|
163 |
@Permission |
|
164 |
@ResponseBody |
|
165 |
public ResponseData add(@Valid Dept dept) { |
|
166 |
this.deptService.addDept(dept); |
|
167 |
return SUCCESS_TIP; |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* 获取所有部门列表 |
|
172 |
* |
|
173 |
* @author fengshuonan |
|
174 |
* @Date 2018/12/23 4:57 PM |
|
175 |
*/ |
|
176 |
@RequestMapping(value = "/list") |
|
177 |
@Permission |
|
178 |
@ResponseBody |
|
179 |
public Object list(@RequestParam(value = "condition", required = false) String condition, |
|
180 |
@RequestParam(value = "deptId", required = false) Long deptId) { |
|
181 |
Page<Map<String, Object>> list = this.deptService.list(condition, deptId); |
|
182 |
Page<Map<String, Object>> wrap = new DeptWrapper(list).wrap(); |
|
183 |
return LayuiPageFactory.createPageInfo(wrap); |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* 部门详情 |
|
188 |
* |
|
189 |
* @author fengshuonan |
|
190 |
* @Date 2018/12/23 4:57 PM |
|
191 |
*/ |
|
192 |
@RequestMapping(value = "/detail/{deptId}") |
|
193 |
@Permission |
|
194 |
@ResponseBody |
|
195 |
public Object detail(@PathVariable("deptId") Long deptId) { |
|
196 |
Dept dept = deptService.getById(deptId); |
|
197 |
DeptDto deptDto = new DeptDto(); |
|
198 |
BeanUtil.copyProperties(dept, deptDto); |
|
199 |
deptDto.setPName(ConstantFactory.me().getDeptName(deptDto.getPid())); |
|
200 |
return deptDto; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* 修改部门 |
|
205 |
* |
|
206 |
* @author fengshuonan |
|
207 |
* @Date 2018/12/23 4:57 PM |
|
208 |
*/ |
|
209 |
@BussinessLog(value = "修改部门", key = "simpleName", dict = DeptDict.class) |
|
210 |
@RequestMapping(value = "/update") |
|
211 |
@Permission |
|
212 |
@ResponseBody |
|
213 |
public ResponseData update(@Valid Dept dept) { |
|
214 |
deptService.editDept(dept); |
|
215 |
return SUCCESS_TIP; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* 删除部门 |
|
220 |
* |
|
221 |
* @author fengshuonan |
|
222 |
* @Date 2018/12/23 4:57 PM |
|
223 |
*/ |
|
224 |
@BussinessLog(value = "删除部门", key = "deptId", dict = DeptDict.class) |
|
225 |
@RequestMapping(value = "/delete") |
|
226 |
@Permission |
|
227 |
@ResponseBody |
|
228 |
public ResponseData delete(@RequestParam("deptId") Long deptId) { |
|
229 |
|
|
230 |
//缓存被删除的部门名称 |
|
231 |
LogObjectHolder.me().set(ConstantFactory.me().getDeptName(deptId)); |
|
232 |
|
|
233 |
deptService.deleteDept(deptId); |
|
234 |
|
|
235 |
return SUCCESS_TIP; |
|
236 |
} |
|
237 |
|
|
238 |
} |