SysPostController.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package com.ruoyi.web.controller.system;
  2. import com.ruoyi.common.annotation.Log;
  3. import com.ruoyi.common.constant.UserConstants;
  4. import com.ruoyi.common.core.controller.BaseController;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.common.core.page.TableDataInfo;
  7. import com.ruoyi.common.enums.BusinessType;
  8. import com.ruoyi.common.utils.poi.ExcelUtil;
  9. import com.ruoyi.system.domain.SysPost;
  10. import com.ruoyi.system.service.ISysPostService;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import lombok.RequiredArgsConstructor;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.security.access.prepost.PreAuthorize;
  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. @Api(value = "岗位信息控制器", tags = {"岗位信息管理"})
  27. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  28. @RestController
  29. @RequestMapping("/system/post")
  30. public class SysPostController extends BaseController {
  31. private final ISysPostService postService;
  32. /**
  33. * 获取岗位列表
  34. */
  35. @ApiOperation("获取岗位列表")
  36. @PreAuthorize("@ss.hasPermi('system:post:list')")
  37. @GetMapping("/list")
  38. public TableDataInfo<SysPost> list(SysPost post) {
  39. return postService.selectPagePostList(post);
  40. }
  41. @ApiOperation("导出岗位列表")
  42. @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
  43. @PreAuthorize("@ss.hasPermi('system:post:export')")
  44. @GetMapping("/export")
  45. public void export(SysPost post, HttpServletResponse response) {
  46. List<SysPost> list = postService.selectPostList(post);
  47. ExcelUtil.exportExcel(list, "岗位数据", SysPost.class, response);
  48. }
  49. /**
  50. * 根据岗位编号获取详细信息
  51. */
  52. @ApiOperation("根据岗位编号获取详细信息")
  53. @PreAuthorize("@ss.hasPermi('system:post:query')")
  54. @GetMapping(value = "/{postId}")
  55. public AjaxResult<SysPost> getInfo(@PathVariable Long postId) {
  56. return AjaxResult.success(postService.selectPostById(postId));
  57. }
  58. /**
  59. * 新增岗位
  60. */
  61. @ApiOperation("新增岗位")
  62. @PreAuthorize("@ss.hasPermi('system:post:add')")
  63. @Log(title = "岗位管理", businessType = BusinessType.INSERT)
  64. @PostMapping
  65. public AjaxResult<Void> add(@Validated @RequestBody SysPost post) {
  66. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  67. return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  68. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  69. return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  70. }
  71. return toAjax(postService.insertPost(post));
  72. }
  73. /**
  74. * 修改岗位
  75. */
  76. @ApiOperation("修改岗位")
  77. @PreAuthorize("@ss.hasPermi('system:post:edit')")
  78. @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  79. @PutMapping
  80. public AjaxResult<Void> edit(@Validated @RequestBody SysPost post) {
  81. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  82. return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  83. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  84. return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  85. }
  86. return toAjax(postService.updatePost(post));
  87. }
  88. /**
  89. * 删除岗位
  90. */
  91. @ApiOperation("删除岗位")
  92. @PreAuthorize("@ss.hasPermi('system:post:remove')")
  93. @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  94. @DeleteMapping("/{postIds}")
  95. public AjaxResult<Void> remove(@PathVariable Long[] postIds) {
  96. return toAjax(postService.deletePostByIds(postIds));
  97. }
  98. /**
  99. * 获取岗位选择框列表
  100. */
  101. @ApiOperation("获取岗位选择框列表")
  102. @GetMapping("/optionselect")
  103. public AjaxResult<List<SysPost>> optionselect() {
  104. List<SysPost> posts = postService.selectPostAll();
  105. return AjaxResult.success(posts);
  106. }
  107. }