jiangping
2024-05-10 dab5db84055a7f6a8fea3b61099d85d34ea7a706
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
package com.doumee.api.system;
 
import com.doumee.api.BaseController;
import com.doumee.biz.system.SystemDepartmentBiz;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.annotation.trace.Trace;
import com.doumee.core.constants.OperaType;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.dao.system.dto.QuerySystemUserDTO;
import com.doumee.dao.system.model.SystemDepartment;
import com.doumee.dao.system.vo.SystemDepartmentListVO;
import com.doumee.dao.system.vo.SystemUserListVO;
import com.doumee.service.system.SystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author Eva.Caesar Liu
 * @date 2023/03/21 14:49
 */
@Api(tags = "部门")
@RestController
@RequestMapping("/system/department")
public class SystemDepartmentController extends BaseController {
 
    @Autowired
    private SystemDepartmentBiz systemDepartmentBiz;
 
    @Autowired
    private SystemUserService systemUserService;
 
    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @RequiresPermissions("system:department:create")
    public ApiResponse create(@Validated(OperaType.Create.class) @RequestBody SystemDepartment systemDepartment, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        systemDepartment.setCreateUser(this.getLoginUser(token).getId());
        systemDepartment.setUpdateUser(this.getLoginUser(token).getId());
        return ApiResponse.success(systemDepartmentBiz.create(systemDepartment));
    }
 
    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    @RequiresPermissions("system:department:delete")
    public ApiResponse deleteById(@PathVariable Integer id) {
        systemDepartmentBiz.deleteById(id);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @PreventRepeat
    @RequiresPermissions("system:department:delete")
    public ApiResponse deleteByIdInBatch(@RequestParam String ids) {
        String [] idArray = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String id : idArray) {
            idList.add(Integer.valueOf(id));
        }
        systemDepartmentBiz.deleteByIdInBatch(idList);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("修改")
    @PostMapping("/updateById")
    @RequiresPermissions("system:department:update")
    public ApiResponse updateById(@Validated(OperaType.Update.class) @RequestBody SystemDepartment systemDepartment, @RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        systemDepartment.setCreateUser(this.getLoginUser(token).getId());
        systemDepartment.setUpdateUser(this.getLoginUser(token).getId());
        systemDepartmentBiz.updateById(systemDepartment);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("查询部门列表")
    @PostMapping("/tree")
    @RequiresPermissions("system:department:query")
    public ApiResponse<List<SystemDepartmentListVO>> findTree () {
        return ApiResponse.success(systemDepartmentBiz.findTree());
    }
 
    @ApiOperation("查询部门列表及部门下的人员")
    @GetMapping("/findTreeUser")
    @RequiresPermissions("system:department:query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "parentId", paramType = "query", dataType = "Integer"),
    })
    public ApiResponse<SystemDepartmentListVO> findTreeUser(Integer parentId) {
        return ApiResponse.success(systemDepartmentBiz.findTreeUser(parentId));
    }
 
    @Trace(exclude = true)
    @ApiOperation("查询部门人员")
    @PostMapping("/users")
    @RequiresPermissions("system:department:queryUsers")
    public ApiResponse<PageData<SystemUserListVO>> findPage (@RequestBody PageWrap<QuerySystemUserDTO> pageWrap) {
        return ApiResponse.success(systemUserService.findPage(pageWrap));
    }
}