SysPostController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package com.ruoyi.web.controller.system;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import com.ruoyi.common.annotation.Log;
  4. import com.ruoyi.common.constant.UserConstants;
  5. import com.ruoyi.common.core.controller.BaseController;
  6. import com.ruoyi.common.core.domain.PageQuery;
  7. import com.ruoyi.common.core.domain.R;
  8. import com.ruoyi.common.core.page.TableDataInfo;
  9. import com.ruoyi.common.enums.BusinessType;
  10. import com.ruoyi.common.utils.poi.ExcelUtil;
  11. import com.ruoyi.system.domain.SysPost;
  12. import com.ruoyi.system.service.ISysPostService;
  13. import io.swagger.v3.oas.annotations.Parameter;
  14. import io.swagger.v3.oas.annotations.tags.Tag;
  15. import lombok.RequiredArgsConstructor;
  16. import org.springframework.validation.annotation.Validated;
  17. import org.springframework.web.bind.annotation.*;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.util.List;
  20. /**
  21. * 岗位信息操作处理
  22. *
  23. * @author Lion Li
  24. */
  25. @Validated
  26. @Tag(name ="岗位信息控制器", description = "岗位信息管理")
  27. @RequiredArgsConstructor
  28. @RestController
  29. @RequestMapping("/system/post")
  30. public class SysPostController extends BaseController {
  31. private final ISysPostService postService;
  32. /**
  33. * 获取岗位列表
  34. */
  35. @SaCheckPermission("system:post:list")
  36. @GetMapping("/list")
  37. public TableDataInfo<SysPost> list(SysPost post, PageQuery pageQuery) {
  38. return postService.selectPagePostList(post, pageQuery);
  39. }
  40. @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
  41. @SaCheckPermission("system:post:export")
  42. @PostMapping("/export")
  43. public void export(SysPost post, HttpServletResponse response) {
  44. List<SysPost> list = postService.selectPostList(post);
  45. ExcelUtil.exportExcel(list, "岗位数据", SysPost.class, response);
  46. }
  47. /**
  48. * 根据岗位编号获取详细信息
  49. */
  50. @SaCheckPermission("system:post:query")
  51. @GetMapping(value = "/{postId}")
  52. public R<SysPost> getInfo(@Parameter(name = "岗位ID") @PathVariable Long postId) {
  53. return R.ok(postService.selectPostById(postId));
  54. }
  55. /**
  56. * 新增岗位
  57. */
  58. @SaCheckPermission("system:post:add")
  59. @Log(title = "岗位管理", businessType = BusinessType.INSERT)
  60. @PostMapping
  61. public R<Void> add(@Validated @RequestBody SysPost post) {
  62. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  63. return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  64. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  65. return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  66. }
  67. return toAjax(postService.insertPost(post));
  68. }
  69. /**
  70. * 修改岗位
  71. */
  72. @SaCheckPermission("system:post:edit")
  73. @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  74. @PutMapping
  75. public R<Void> edit(@Validated @RequestBody SysPost post) {
  76. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  77. return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  78. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  79. return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  80. }
  81. return toAjax(postService.updatePost(post));
  82. }
  83. /**
  84. * 删除岗位
  85. */
  86. @SaCheckPermission("system:post:remove")
  87. @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  88. @DeleteMapping("/{postIds}")
  89. public R<Void> remove(@Parameter(name = "岗位ID串") @PathVariable Long[] postIds) {
  90. return toAjax(postService.deletePostByIds(postIds));
  91. }
  92. /**
  93. * 获取岗位选择框列表
  94. */
  95. @GetMapping("/optionselect")
  96. public R<List<SysPost>> optionselect() {
  97. List<SysPost> posts = postService.selectPostAll();
  98. return R.ok(posts);
  99. }
  100. }