提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.controller.admin.dept; |
H |
2 |
|
|
3 |
import com.iailab.framework.apilog.core.annotation.ApiAccessLog; |
|
4 |
import com.iailab.framework.common.enums.CommonStatusEnum; |
|
5 |
import com.iailab.framework.common.pojo.CommonResult; |
|
6 |
import com.iailab.framework.common.pojo.PageParam; |
|
7 |
import com.iailab.framework.common.pojo.PageResult; |
|
8 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
9 |
import com.iailab.framework.excel.core.util.ExcelUtils; |
|
10 |
import com.iailab.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
|
11 |
import com.iailab.module.system.controller.admin.dept.vo.post.PostRespVO; |
|
12 |
import com.iailab.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
|
13 |
import com.iailab.module.system.controller.admin.dept.vo.post.PostSimpleRespVO; |
|
14 |
import com.iailab.module.system.dal.dataobject.dept.PostDO; |
|
15 |
import com.iailab.module.system.service.dept.PostService; |
|
16 |
import io.swagger.v3.oas.annotations.Operation; |
|
17 |
import io.swagger.v3.oas.annotations.Parameter; |
|
18 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
19 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
20 |
import org.springframework.validation.annotation.Validated; |
|
21 |
import org.springframework.web.bind.annotation.*; |
|
22 |
|
|
23 |
import javax.annotation.Resource; |
|
24 |
import javax.servlet.http.HttpServletResponse; |
|
25 |
import javax.validation.Valid; |
|
26 |
import java.io.IOException; |
|
27 |
import java.util.Collections; |
|
28 |
import java.util.Comparator; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
|
32 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
33 |
|
|
34 |
@Tag(name = "管理后台 - 岗位") |
|
35 |
@RestController |
|
36 |
@RequestMapping("/system/post") |
|
37 |
@Validated |
|
38 |
public class PostController { |
|
39 |
|
|
40 |
@Resource |
|
41 |
private PostService postService; |
|
42 |
|
|
43 |
@PostMapping("/create") |
|
44 |
@Operation(summary = "创建岗位") |
|
45 |
@PreAuthorize("@ss.hasPermission('system:post:create')") |
|
46 |
public CommonResult<Long> createPost(@Valid @RequestBody PostSaveReqVO createReqVO) { |
|
47 |
Long postId = postService.createPost(createReqVO); |
|
48 |
return success(postId); |
|
49 |
} |
|
50 |
|
|
51 |
@PutMapping("/update") |
|
52 |
@Operation(summary = "修改岗位") |
|
53 |
@PreAuthorize("@ss.hasPermission('system:post:update')") |
|
54 |
public CommonResult<Boolean> updatePost(@Valid @RequestBody PostSaveReqVO updateReqVO) { |
|
55 |
postService.updatePost(updateReqVO); |
|
56 |
return success(true); |
|
57 |
} |
|
58 |
|
|
59 |
@DeleteMapping("/delete") |
|
60 |
@Operation(summary = "删除岗位") |
|
61 |
@PreAuthorize("@ss.hasPermission('system:post:delete')") |
|
62 |
public CommonResult<Boolean> deletePost(@RequestParam("id") Long id) { |
|
63 |
postService.deletePost(id); |
|
64 |
return success(true); |
|
65 |
} |
|
66 |
|
|
67 |
@GetMapping(value = "/get") |
|
68 |
@Operation(summary = "获得岗位信息") |
|
69 |
@Parameter(name = "id", description = "岗位编号", required = true, example = "1024") |
|
70 |
@PreAuthorize("@ss.hasPermission('system:post:query')") |
|
71 |
public CommonResult<PostRespVO> getPost(@RequestParam("id") Long id) { |
|
72 |
PostDO post = postService.getPost(id); |
|
73 |
return success(BeanUtils.toBean(post, PostRespVO.class)); |
|
74 |
} |
|
75 |
|
|
76 |
@GetMapping(value = {"/list-all-simple", "simple-list"}) |
|
77 |
@Operation(summary = "获取岗位全列表", description = "只包含被开启的岗位,主要用于前端的下拉选项") |
|
78 |
public CommonResult<List<PostSimpleRespVO>> getSimplePostList() { |
|
79 |
// 获得岗位列表,只要开启状态的 |
|
80 |
List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); |
|
81 |
// 排序后,返回给前端 |
|
82 |
list.sort(Comparator.comparing(PostDO::getSort)); |
|
83 |
return success(BeanUtils.toBean(list, PostSimpleRespVO.class)); |
|
84 |
} |
|
85 |
|
|
86 |
@GetMapping("/page") |
|
87 |
@Operation(summary = "获得岗位分页列表") |
|
88 |
@PreAuthorize("@ss.hasPermission('system:post:query')") |
|
89 |
public CommonResult<PageResult<PostRespVO>> getPostPage(@Validated PostPageReqVO pageReqVO) { |
|
90 |
PageResult<PostDO> pageResult = postService.getPostPage(pageReqVO); |
|
91 |
return success(BeanUtils.toBean(pageResult, PostRespVO.class)); |
|
92 |
} |
|
93 |
|
|
94 |
@GetMapping("/export") |
|
95 |
@Operation(summary = "岗位管理") |
|
96 |
@PreAuthorize("@ss.hasPermission('system:post:export')") |
|
97 |
@ApiAccessLog(operateType = EXPORT) |
|
98 |
public void export(HttpServletResponse response, @Validated PostPageReqVO reqVO) throws IOException { |
|
99 |
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
|
100 |
List<PostDO> list = postService.getPostPage(reqVO).getList(); |
|
101 |
// 输出 |
|
102 |
ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostRespVO.class, |
|
103 |
BeanUtils.toBean(list, PostRespVO.class)); |
|
104 |
} |
|
105 |
|
|
106 |
} |