SysPostController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 lombok.RequiredArgsConstructor;
  14. import org.springframework.validation.annotation.Validated;
  15. import org.springframework.web.bind.annotation.*;
  16. import jakarta.servlet.http.HttpServletResponse;
  17. import java.util.List;
  18. /**
  19. * 岗位信息操作处理
  20. *
  21. * @author Lion Li
  22. */
  23. @Validated
  24. @RequiredArgsConstructor
  25. @RestController
  26. @RequestMapping("/system/post")
  27. public class SysPostController extends BaseController {
  28. private final ISysPostService postService;
  29. /**
  30. * 获取岗位列表
  31. */
  32. @SaCheckPermission("system:post:list")
  33. @GetMapping("/list")
  34. public TableDataInfo<SysPost> list(SysPost post, PageQuery pageQuery) {
  35. return postService.selectPagePostList(post, pageQuery);
  36. }
  37. /**
  38. * 导出岗位列表
  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. * @param postId 岗位ID
  51. */
  52. @SaCheckPermission("system:post:query")
  53. @GetMapping(value = "/{postId}")
  54. public R<SysPost> getInfo(@PathVariable Long postId) {
  55. return R.ok(postService.selectPostById(postId));
  56. }
  57. /**
  58. * 新增岗位
  59. */
  60. @SaCheckPermission("system:post:add")
  61. @Log(title = "岗位管理", businessType = BusinessType.INSERT)
  62. @PostMapping
  63. public R<Void> add(@Validated @RequestBody SysPost post) {
  64. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  65. return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  66. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  67. return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  68. }
  69. return toAjax(postService.insertPost(post));
  70. }
  71. /**
  72. * 修改岗位
  73. */
  74. @SaCheckPermission("system:post:edit")
  75. @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  76. @PutMapping
  77. public R<Void> edit(@Validated @RequestBody SysPost post) {
  78. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  79. return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  80. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  81. return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  82. }
  83. return toAjax(postService.updatePost(post));
  84. }
  85. /**
  86. * 删除岗位
  87. *
  88. * @param postIds 岗位ID串
  89. */
  90. @SaCheckPermission("system:post:remove")
  91. @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  92. @DeleteMapping("/{postIds}")
  93. public R<Void> remove(@PathVariable Long[] postIds) {
  94. return toAjax(postService.deletePostByIds(postIds));
  95. }
  96. /**
  97. * 获取岗位选择框列表
  98. */
  99. @GetMapping("/optionselect")
  100. public R<List<SysPost>> optionselect() {
  101. List<SysPost> posts = postService.selectPostAll();
  102. return R.ok(posts);
  103. }
  104. }