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
package com.ycl.controller.depart;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.annotation.LogSave;
import com.ycl.api.BasePageDTO;
import com.ycl.api.BasePageVO;
import com.ycl.api.CommonResult;
import com.ycl.controller.BaseController;
import com.ycl.entity.depart.UmsDepart;
import com.ycl.service.depart.UmsDepartService;
import com.ycl.service.user.UmsDepartManageService;
import com.ycl.utils.auth.UserAuthUtil;
import com.ycl.vo.depart.DepartVO;
import com.ycl.vo.depart.UmsDepartVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author lyq
 * @since 2022-09-07
 */
@RestController
@Api(tags = "部门管理模块")
@RequestMapping("/depart")
public class DepartController extends BaseController {
 
    @Autowired
    private UmsDepartService departService;
    @Resource
    private UmsDepartManageService umsAdminDepartService;
    @Resource
    private UserAuthUtil userAuthUtil;
 
    @ApiOperation("添加部门")
    @PostMapping(value = "/create")
    @LogSave(operationType = "部门管理", contain = "添加部门")
    public CommonResult<Void> create(@Validated @RequestBody DepartVO.AddDepartVO addDepartVO) {
        departService.create(addDepartVO);
        return CommonResult.success(null);
    }
 
    @ApiOperation("编辑部门")
    @PostMapping(value = "/update")
    @LogSave(operationType = "部门管理", contain = "编辑部门")
    public CommonResult<Void> create(@Validated @RequestBody DepartVO.UpdateDepartVO params) {
        departService.update(params);
        return CommonResult.success(null);
    }
 
    @ApiOperation("删除")
    @PostMapping(value = "/delete")
    @LogSave(operationType = "部门管理", contain = "删除部门")
    public CommonResult<Void> delete(@Validated @RequestBody DepartVO.IdDepartVO params) {
        departService.delete(params.getId());
        return CommonResult.success(null);
    }
 
    /**
     * @return com.ycl.api.CommonResult<java.lang.Void>
     * @Description batch deletion departments
     * @Param [ids]
     **/
    @ApiOperation("批处理-删除")
    @PostMapping(value = "/batch_deletion")
    @LogSave(operationType = "部门管理", contain = "批量删除部门")
    public CommonResult delete(@RequestParam List<Long> ids) {
        if (ids.isEmpty()) {
            return CommonResult.failed("bad request parameter");
        }
        return CommonResult.success(departService.removeBatchByIds(ids));
    }
 
    @ApiOperation("批处理-开启或者禁用部门")
    @PutMapping(value = "/batch_status")
    @LogSave(operationType = "部门管理", contain = "批量开启或者禁用部门")
    public CommonResult updateBatch(@RequestParam List<UmsDepart> umsDepartList) {
        if (umsDepartList.isEmpty()) {
            return CommonResult.failed("bad request parameter");
        }
        return CommonResult.success(departService.updateBatchById(umsDepartList));
    }
 
    @ApiOperation("详情")
    @PostMapping(value = "/detail")
    @LogSave(operationType = "部门管理", contain = "查看部门")
    public CommonResult<UmsDepart> detail(@Validated @RequestBody DepartVO.IdDepartVO params) {
        UmsDepart sccgDepart = departService.loadDepartById(params.getId());
        return CommonResult.success(sccgDepart);
    }
 
    @ApiOperation("树结构")
    @GetMapping(value = "/tree")
    public CommonResult<List<UmsDepart>> tree() {
        List<UmsDepart> tree = departService.tree();
        return CommonResult.success(tree);
    }
 
    @ApiOperation("修改部门状态")
    @PostMapping(value = "/status")
    public CommonResult<Void> status(@Validated @RequestBody DepartVO.StatusDepartVO params) {
        departService.updateStatus(params);
        return CommonResult.success(null);
    }
 
    @ApiOperation("查询全部部门")
    @GetMapping(value = "/page")
    public CommonResult<IPage<UmsDepartVO>> page(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize,
                                                 @RequestParam(value = "departName", required = false) String departName) {
        IPage<UmsDepartVO> page = new Page<>(currentPage, pageSize);
        departService.pageDepart(departName, page);
        return CommonResult.success(page);
    }
 
    @ApiOperation("查询我的部门")
    @GetMapping(value = "/belongDepart")
    public CommonResult<BasePageDTO> belongDepart(BasePageVO params) {
        BasePageDTO basePageDTO = umsAdminDepartService.belongDepart(fetchOperator(request).getOperatorId(), params.getCurrent(), params.getPageSize());
        return CommonResult.success(basePageDTO);
    }
 
    @ApiOperation("用户修改角色")
    @PutMapping(value = "/user_update_Role")
    public CommonResult userUpdateRole(@RequestParam Long id,
                                       @RequestParam List<Long> roles) {
        umsAdminDepartService.userUpdateRoles(id, roles);
        return CommonResult.success("update success");
    }
 
    @ApiOperation("用户修改部门")
    @PutMapping(value = "/user_update_depart")
    public CommonResult userUpdateDepart(@RequestParam Long userId,
                                         @RequestParam Long departId) {
        umsAdminDepartService.userUpdateDepart(userId, departId);
        return CommonResult.success("update success");
    }
 
    @ApiOperation("查询不在部门的剩余人员")
    @GetMapping("/query_surplus_user")
    public CommonResult searchSurplusUser() {
        return CommonResult.success(departService.selectSurplusUser());
    }
 
    @ApiOperation("查询不在部门的剩余人员和已在部门的人")
    @GetMapping("/query_surplus_exist_user")
    public CommonResult searchSurplusUser(@RequestParam Long id) {
        return CommonResult.success(departService.selectSurplusUserAndExistUser(id));
    }
 
    @ApiOperation("查询顶级部门")
    @GetMapping(value = "/query_father")
    public CommonResult search() {
        Integer fatherId = 0;
        return CommonResult.success(departService
                .list(new LambdaQueryWrapper<UmsDepart>()
                        .eq(UmsDepart::getParentId, fatherId)));
    }
 
    @ApiOperation("查询部门二级")
    @GetMapping(value = "/query_father_children")
    public CommonResult search(@RequestParam Integer fatherId) {
        return CommonResult.success(departService
                .list(new LambdaQueryWrapper<UmsDepart>()
                        .eq(UmsDepart::getParentId, fatherId)));
    }
}