doum
2025-09-25 c5675caab8392bfafd217d06529c2547edaa6aa8
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.cloud;
 
import com.doumee.api.BaseController;
import com.doumee.biz.system.SystemDepartmentBiz;
import com.doumee.config.annotation.CloudRequiredPermission;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.annotation.trace.Trace;
import com.doumee.core.constants.OperaType;
import com.doumee.service.business.third.model.ApiResponse;
import com.doumee.service.business.third.model.PageData;
import com.doumee.service.business.third.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.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(Constants.CLOUD_SERVICE_URL_INDEX+"/system/department")
public class SystemDepartmentCloudController extends BaseController {
 
    @Autowired
    private SystemDepartmentBiz systemDepartmentBiz;
 
    @Autowired
    private SystemUserService systemUserService;
 
    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @CloudRequiredPermission("system:department:create")
    public ApiResponse create(@RequestHeader(Constants.HEADER_USER_TOKEN) String token,@Validated(OperaType.Create.class) @RequestBody SystemDepartment systemDepartment) {
        systemDepartment.setCreateUser(getLoginUser(token).getId());
        systemDepartment.setUpdateUser(getLoginUser(token).getId());
        return ApiResponse.success(systemDepartmentBiz.create(systemDepartment));
    }
 
    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    @CloudRequiredPermission("system:department:delete")
    public ApiResponse deleteById(@RequestHeader(Constants.HEADER_USER_TOKEN) String token,@PathVariable Integer id) {
        systemDepartmentBiz.deleteById(id);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @PreventRepeat
    @CloudRequiredPermission("system:department:delete")
    public ApiResponse deleteByIdInBatch(@RequestHeader(Constants.HEADER_USER_TOKEN) String token,@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")
    @CloudRequiredPermission("system:department:update")
    public ApiResponse updateById(@RequestHeader(Constants.HEADER_USER_TOKEN) String token,@Validated(OperaType.Update.class) @RequestBody SystemDepartment systemDepartment) {
        systemDepartment.setCreateUser(getLoginUser(token).getId());
        systemDepartment.setUpdateUser(getLoginUser(token).getId());
        systemDepartmentBiz.updateById(systemDepartment);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("查询部门列表")
    @PostMapping("/tree")
    @CloudRequiredPermission("system:department:query")
    public ApiResponse<List<SystemDepartmentListVO>> findTree (@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        return ApiResponse.success(systemDepartmentBiz.findTree());
    }
 
    @ApiOperation("查询部门列表及部门下的人员")
    @GetMapping("/findTreeUser")
    @CloudRequiredPermission("system:department:query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "parentId", paramType = "query", dataType = "Integer"),
    })
    public ApiResponse<SystemDepartmentListVO> findTreeUser(@RequestHeader(Constants.HEADER_USER_TOKEN) String token,Integer parentId) {
        return ApiResponse.success(systemDepartmentBiz.findTreeUser(parentId));
    }
 
    @Trace(exclude = true)
    @ApiOperation("查询部门人员")
    @PostMapping("/users")
    @CloudRequiredPermission("system:department:queryUsers")
    public ApiResponse<PageData<SystemUserListVO>> findPage (@RequestHeader(Constants.HEADER_USER_TOKEN) String token,@RequestBody PageWrap<QuerySystemUserDTO> pageWrap) {
        return ApiResponse.success(systemUserService.findPage(pageWrap));
    }
}