潘志宝
2024-12-25 8a6b19bf5c50ebb54e965645a9366f6cfea02351
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.system.controller.admin.dept;
H 2
3 import com.iailab.framework.common.enums.CommonStatusEnum;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.util.object.BeanUtils;
6 import com.iailab.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
7 import com.iailab.module.system.controller.admin.dept.vo.dept.DeptRespVO;
8 import com.iailab.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
9 import com.iailab.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
10 import com.iailab.module.system.dal.dataobject.dept.DeptDO;
11 import com.iailab.module.system.service.dept.DeptService;
12 import io.swagger.v3.oas.annotations.Operation;
13 import io.swagger.v3.oas.annotations.Parameter;
14 import io.swagger.v3.oas.annotations.tags.Tag;
15 import org.springframework.security.access.prepost.PreAuthorize;
16 import org.springframework.validation.annotation.Validated;
17 import org.springframework.web.bind.annotation.*;
18
19 import javax.annotation.Resource;
20 import javax.validation.Valid;
21 import java.util.List;
22
23 import static com.iailab.framework.common.pojo.CommonResult.success;
24
25 @Tag(name = "管理后台 - 部门")
26 @RestController
27 @RequestMapping("/system/dept")
28 @Validated
29 public class DeptController {
30
31     @Resource
32     private DeptService deptService;
33
34     @PostMapping("create")
35     @Operation(summary = "创建部门")
36     @PreAuthorize("@ss.hasPermission('system:dept:create')")
37     public CommonResult<Long> createDept(@Valid @RequestBody DeptSaveReqVO createReqVO) {
38         Long deptId = deptService.createDept(createReqVO);
39         return success(deptId);
40     }
41
42     @PutMapping("update")
43     @Operation(summary = "更新部门")
44     @PreAuthorize("@ss.hasPermission('system:dept:update')")
45     public CommonResult<Boolean> updateDept(@Valid @RequestBody DeptSaveReqVO updateReqVO) {
46         deptService.updateDept(updateReqVO);
47         return success(true);
48     }
49
50     @DeleteMapping("delete")
51     @Operation(summary = "删除部门")
52     @Parameter(name = "id", description = "编号", required = true, example = "1024")
53     @PreAuthorize("@ss.hasPermission('system:dept:delete')")
54     public CommonResult<Boolean> deleteDept(@RequestParam("id") Long id) {
55         deptService.deleteDept(id);
56         return success(true);
57     }
58
59     @GetMapping("/list")
60     @Operation(summary = "获取部门列表")
61     @PreAuthorize("@ss.hasPermission('system:dept:query')")
62     public CommonResult<List<DeptRespVO>> getDeptList(DeptListReqVO reqVO) {
63         List<DeptDO> list = deptService.getDeptList(reqVO);
64         return success(BeanUtils.toBean(list, DeptRespVO.class));
65     }
66
67     @GetMapping(value = {"/list-all-simple", "/simple-list"})
68     @Operation(summary = "获取部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项")
69     public CommonResult<List<DeptSimpleRespVO>> getSimpleDeptList() {
70         List<DeptDO> list = deptService.getDeptList(
71                 new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
72         return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
73     }
74
75     @GetMapping("/get")
76     @Operation(summary = "获得部门信息")
77     @Parameter(name = "id", description = "编号", required = true, example = "1024")
78     @PreAuthorize("@ss.hasPermission('system:dept:query')")
79     public CommonResult<DeptRespVO> getDept(@RequestParam("id") Long id) {
80         DeptDO dept = deptService.getDept(id);
81         return success(BeanUtils.toBean(dept, DeptRespVO.class));
82     }
83
84 }