提交 | 用户 | 时间
|
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.rest.controller; |
|
17 |
|
|
18 |
import cn.hutool.core.bean.BeanUtil; |
|
19 |
import cn.stylefeng.guns.base.log.BussinessLog; |
|
20 |
import cn.stylefeng.guns.base.pojo.node.ZTreeNode; |
|
21 |
import cn.stylefeng.guns.sys.core.constant.dictmap.DeptDict; |
|
22 |
import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory; |
|
23 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestDept; |
|
24 |
import cn.stylefeng.guns.sys.modular.rest.factory.DeptFactory; |
|
25 |
import cn.stylefeng.guns.sys.modular.rest.model.DeptTreeNode; |
|
26 |
import cn.stylefeng.guns.sys.modular.rest.service.RestDeptService; |
|
27 |
import cn.stylefeng.guns.sys.modular.system.model.DeptDto; |
|
28 |
import cn.stylefeng.guns.sys.modular.system.warpper.DeptWrapper; |
|
29 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
30 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
31 |
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData; |
|
32 |
import org.springframework.beans.factory.annotation.Autowired; |
|
33 |
import org.springframework.web.bind.annotation.*; |
|
34 |
|
|
35 |
import java.util.List; |
|
36 |
import java.util.Map; |
|
37 |
|
|
38 |
/** |
|
39 |
* 部门控制器 |
|
40 |
* |
|
41 |
* @author fengshuonan |
|
42 |
* @Date 2017年2月17日20:27:22 |
|
43 |
*/ |
|
44 |
@RestController |
|
45 |
@RequestMapping("/rest/dept") |
|
46 |
public class RestDeptController extends BaseController { |
|
47 |
|
|
48 |
@Autowired |
|
49 |
private RestDeptService restDeptService; |
|
50 |
|
|
51 |
/** |
|
52 |
* 获取部门的tree列表,ztree格式 |
|
53 |
* |
|
54 |
* @author fengshuonan |
|
55 |
* @Date 2018/12/23 4:56 PM |
|
56 |
*/ |
|
57 |
@RequestMapping(value = "/tree") |
|
58 |
public List<ZTreeNode> tree() { |
|
59 |
List<ZTreeNode> tree = this.restDeptService.tree(); |
|
60 |
tree.add(ZTreeNode.createParent()); |
|
61 |
return tree; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* 新增部门 |
|
66 |
* |
|
67 |
* @author fengshuonan |
|
68 |
* @Date 2018/12/23 4:57 PM |
|
69 |
*/ |
|
70 |
@BussinessLog(value = "添加部门", key = "simpleName", dict = DeptDict.class) |
|
71 |
@RequestMapping(value = "/add") |
|
72 |
public ResponseData add(@RequestBody RestDept restDept) { |
|
73 |
this.restDeptService.addDept(restDept); |
|
74 |
return SUCCESS_TIP; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* 获取所有部门列表 |
|
79 |
* |
|
80 |
* @author fengshuonan |
|
81 |
* @Date 2018/12/23 4:57 PM |
|
82 |
*/ |
|
83 |
@RequestMapping(value = "/list") |
|
84 |
public Object list(@RequestParam(value = "condition", required = false) String condition, |
|
85 |
@RequestParam(value = "deptId", required = false) Long deptId) { |
|
86 |
List<Map<String, Object>> list = this.restDeptService.list(condition, deptId); |
|
87 |
List<Map<String, Object>> wrap = new DeptWrapper(list).wrap(); |
|
88 |
|
|
89 |
//创建部门树 |
|
90 |
List<DeptTreeNode> deptTreeNodes = DeptFactory.buildTreeNodes(wrap); |
|
91 |
|
|
92 |
return new SuccessResponseData(deptTreeNodes); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* 部门详情 |
|
97 |
* |
|
98 |
* @author fengshuonan |
|
99 |
* @Date 2018/12/23 4:57 PM |
|
100 |
*/ |
|
101 |
@RequestMapping(value = "/detail/{deptId}") |
|
102 |
public Object detail(@PathVariable("deptId") Long deptId) { |
|
103 |
RestDept dept = restDeptService.getById(deptId); |
|
104 |
DeptDto deptDto = new DeptDto(); |
|
105 |
BeanUtil.copyProperties(dept, deptDto); |
|
106 |
deptDto.setPName(ConstantFactory.me().getDeptName(deptDto.getPid())); |
|
107 |
return deptDto; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* 修改部门 |
|
112 |
* |
|
113 |
* @author fengshuonan |
|
114 |
* @Date 2018/12/23 4:57 PM |
|
115 |
*/ |
|
116 |
@BussinessLog(value = "修改部门", key = "simpleName", dict = DeptDict.class) |
|
117 |
@RequestMapping(value = "/update") |
|
118 |
public ResponseData update(@RequestBody RestDept restDept) { |
|
119 |
restDeptService.editDept(restDept); |
|
120 |
return SUCCESS_TIP; |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* 删除部门 |
|
125 |
* |
|
126 |
* @author fengshuonan |
|
127 |
* @Date 2018/12/23 4:57 PM |
|
128 |
*/ |
|
129 |
@BussinessLog(value = "删除部门", key = "deptId", dict = DeptDict.class) |
|
130 |
@RequestMapping(value = "/delete") |
|
131 |
public ResponseData delete(@RequestParam("deptId") Long deptId) { |
|
132 |
restDeptService.deleteDept(deptId); |
|
133 |
return SUCCESS_TIP; |
|
134 |
} |
|
135 |
|
|
136 |
} |