lyh
2025-01-17 ea704e018a27c26ef6deeaea4adc8a28b4d0b27e
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package org.jeecg.modules.dnc.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.dnc.request.DepartmentRequest;
import org.jeecg.modules.dnc.response.*;
import org.jeecg.modules.dnc.service.IDepartmentService;
import org.jeecg.modules.dnc.ucenter.Department;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Collections;
import java.util.List;
 
@Slf4j
@Api(tags = "DNC部门管理")
@RestController
@RequestMapping("/ucenter/depart")
public class DepartmentController  {
    @Autowired
    private IDepartmentService departmentService;
 
    @AutoLog(value = "DNC部门管理-添加部门信息")
    @ApiOperation(value = "DNC部门管理-添加部门信息", notes = "DNC部门管理-添加部门信息")
    @PostMapping("/add")
    public ResponseResult addDepartment(@RequestBody Department department) {
        boolean b = departmentService.addDepartment(department);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "DNC部门管理-修改部门")
    @ApiOperation(value = "DNC部门管理-修改部门", notes = "DNC部门管理-修改部门")
    @PutMapping("/edit/{id}")
    public ResponseResult editDepartment(@PathVariable("id") String id,@RequestBody Department department) {
        boolean b = departmentService.editDepartment(id,department);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "DNC部门管理-分页查询")
    @ApiOperation(value = "DNC部门管理-分页查询", notes = "DNC部门管理-分页查询")
    @GetMapping("/find/page/{page}/{size}")
    public QueryPageResponseResult<Department> findPageList(@PathVariable("page") int page, @PathVariable("size") int size, DepartmentRequest departmentRequest) {
        return departmentService.findPageList(page,size,departmentRequest);
    }
 
    @AutoLog(value = "DNC部门管理-获取所有列表,按层级")
    @ApiOperation(value = "DNC部门管理-获取所有列表,按层级", notes = "DNC部门管理-获取所有列表,按层级")
    @GetMapping("/load/tree")
    public QueryListResponseResult<CommonJsonTree> loadTree() {
        List<CommonJsonTree> tree = departmentService.loadTree();
        if(tree == null)
            tree = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, tree);
    }
 
    @AutoLog(value = "DNC部门管理-删除 部门")
    @ApiOperation(value = "DNC部门管理-删除 部门", notes = "DNC部门管理-删除 部门")
    @DeleteMapping("/delete")
    public ResponseResult deleteDepartment(@RequestParam("id") String id) {
        boolean b = departmentService.deleteDepartmentById(id);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "DNC部门管理-获取用户未分配的部门列表")
    @ApiOperation(value = "DNC部门管理-获取用户未分配的部门列表", notes = "DNC部门管理-获取用户未分配的部门列表")
    @GetMapping("/perm/select/non/{userId}")
    public QueryListResponseResult<Department> getUserNonPermDepart(@PathVariable("userId") String userId) {
        List<Department> list = departmentService.getUserNonPermDepart(userId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "DNC部门管理-获取用户已分配的部门列表")
    @ApiOperation(value = "DNC部门管理-获取用户已分配的部门列表", notes = "DNC部门管理-获取用户已分配的部门列表")
    @GetMapping("/perm/select/{userId}")
    public QueryListResponseResult<Department> getUserPermDepart(@PathVariable("userId") String userId) {
        List<Department> list = departmentService.getUserPermDepart(userId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "DNC部门管理-获取部门未指定的审批人")
    @ApiOperation(value = "DNC部门管理-获取部门未指定的审批人", notes = "DNC部门管理-获取部门未指定的审批人")
    @GetMapping("/approve/select/non/{departId}")
    public QueryListResponseResult<SysUser> getUserNonApproveDepart(@PathVariable("departId") String departId) {
        List<SysUser> list = departmentService.getUserNonApproveDepart(departId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "DNC部门管理-获取部门已指定的审批人")
    @ApiOperation(value = "DNC部门管理-获取部门已指定的审批人", notes = "DNC部门管理-获取部门已指定的审批人")
    @GetMapping("/approve/select/{departId}")
    public QueryListResponseResult<SysUser> getUserApproveDepart(@PathVariable("departId") String departId) {
        List<SysUser> list = departmentService.getUserApproveDepart(departId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "DNC部门管理-增加部门审批人")
    @ApiOperation(value = "DNC部门管理-增加部门审批人", notes = "DNC部门管理-增加部门审批人")
    @PostMapping("/assign/add/approve/user/{departId}/{relativeFlag}")
    public ResponseResult assignAddApproveUser(@PathVariable("departId") String departId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
        boolean b = departmentService.assignAddApproveUser(departId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "DNC部门管理-移除部门审批人")
    @ApiOperation(value = "DNC部门管理-移除部门审批人", notes = "DNC部门管理-移除部门审批人")
    @PostMapping("/assign/remove/approve/user/{departId}/{relativeFlag}")
    public ResponseResult assignRemoveApproveUser(@PathVariable("departId") String departId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
        boolean b = departmentService.assignRemoveApproveUser(departId, relativeFlag, userIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "DNC部门管理-获取部门List")
    @ApiOperation(value = "DNC部门管理-获取部门List", notes = "DNC部门管理-获取部门List")
    @GetMapping("/list/all")
    public QueryListResponseResult<Department> getDepartList() {
        List<Department> list = departmentService.list();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
 
    @AutoLog(value = "DNC部门管理-获取树结构")
    @ApiOperation(value = "DNC部门管理-获取树结构", notes = "DNC部门管理-获取树结构")
    @GetMapping("/load/queryTreeList")
    public QueryListResponseResult<CommonJsonTree> queryTreeList() {
        List<CommonJsonTree> tree = departmentService.loadTree();
        if(tree == null)
            tree = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, tree);
    }
 
    /**
     * 查询数据 查出所有部门,并以树结构数据格式响应给前端
     *
     * @return
     */
    @GetMapping(value = "/queryTreeList")
    public Result<List<DepartmentTreeModel>> queryTreeList(@RequestParam(name = "ids", required = false) String ids) {
        Result<List<DepartmentTreeModel>> result = new Result<>();
        try {
            // 从内存中读取
//            List<SysDepartTreeModel> list =FindsDepartsChildrenUtil.getSysDepartTreeList();
//            if (CollectionUtils.isEmpty(list)) {
//                list = sysDepartService.queryTreeList();
//            }
            if(oConvertUtils.isNotEmpty(ids)){
                List<DepartmentTreeModel> departList = departmentService.queryTreeList(ids);
                result.setResult(departList);
            }else{
                List<DepartmentTreeModel> list = departmentService.queryTreeList();
                result.setResult(list);
            }
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return result;
    }
 
    /**
     * <p>
     * 部门搜索功能方法,根据关键字模糊搜索相关部门
     * </p>
     *
     * @param keyWord
     * @return
     */
    @RequestMapping(value = "/searchBy", method = RequestMethod.GET)
    public Result<List<DepartmentTreeModel>> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord,@RequestParam(name = "myDeptSearch", required = false) String myDeptSearch) {
        Result<List<DepartmentTreeModel>> result = new Result<List<DepartmentTreeModel>>();
        //部门查询,myDeptSearch为1时为我的部门查询,登录用户为上级时查只查负责部门下数据
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String departIds = null;
        if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals( CommonConstant.USER_IDENTITY_2 )){
            departIds = user.getDepartIds();
        }
        List<DepartmentTreeModel> treeList = this.departmentService.searchByKeyWord(keyWord,myDeptSearch,departIds);
        if (treeList == null || treeList.size() == 0) {
            result.setSuccess(false);
            result.setMessage("未查询匹配数据!");
            return result;
        }
        result.setResult(treeList);
        return result;
    }
}