SysPostController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.SecurityUtils;
  9. import com.ruoyi.common.utils.poi.ExcelUtil;
  10. import com.ruoyi.system.domain.SysPost;
  11. import com.ruoyi.system.service.ISysPostService;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.security.access.prepost.PreAuthorize;
  14. import org.springframework.validation.annotation.Validated;
  15. import org.springframework.web.bind.annotation.*;
  16. import javax.servlet.http.HttpServletResponse;
  17. import java.util.List;
  18. /**
  19. * 岗位信息操作处理
  20. *
  21. * @author ruoyi
  22. */
  23. @RestController
  24. @RequestMapping("/system/post")
  25. public class SysPostController extends BaseController
  26. {
  27. @Autowired
  28. private ISysPostService postService;
  29. /**
  30. * 获取岗位列表
  31. */
  32. @PreAuthorize("@ss.hasPermi('system:post:list')")
  33. @GetMapping("/list")
  34. public TableDataInfo list(SysPost post)
  35. {
  36. return postService.selectPagePostList(post);
  37. }
  38. @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
  39. @PreAuthorize("@ss.hasPermi('system:post:export')")
  40. @GetMapping("/export")
  41. public void export(SysPost post, HttpServletResponse response)
  42. {
  43. List<SysPost> list = postService.selectPostList(post);
  44. ExcelUtil.exportExcel(list, "岗位数据", SysPost.class, response);
  45. }
  46. /**
  47. * 根据岗位编号获取详细信息
  48. */
  49. @PreAuthorize("@ss.hasPermi('system:post:query')")
  50. @GetMapping(value = "/{postId}")
  51. public AjaxResult getInfo(@PathVariable Long postId)
  52. {
  53. return AjaxResult.success(postService.selectPostById(postId));
  54. }
  55. /**
  56. * 新增岗位
  57. */
  58. @PreAuthorize("@ss.hasPermi('system:post:add')")
  59. @Log(title = "岗位管理", businessType = BusinessType.INSERT)
  60. @PostMapping
  61. public AjaxResult add(@Validated @RequestBody SysPost post)
  62. {
  63. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
  64. {
  65. return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  66. }
  67. else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
  68. {
  69. return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  70. }
  71. post.setCreateBy(SecurityUtils.getUsername());
  72. return toAjax(postService.insertPost(post));
  73. }
  74. /**
  75. * 修改岗位
  76. */
  77. @PreAuthorize("@ss.hasPermi('system:post:edit')")
  78. @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  79. @PutMapping
  80. public AjaxResult edit(@Validated @RequestBody SysPost post)
  81. {
  82. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
  83. {
  84. return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  85. }
  86. else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
  87. {
  88. return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  89. }
  90. post.setUpdateBy(SecurityUtils.getUsername());
  91. return toAjax(postService.updatePost(post));
  92. }
  93. /**
  94. * 删除岗位
  95. */
  96. @PreAuthorize("@ss.hasPermi('system:post:remove')")
  97. @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  98. @DeleteMapping("/{postIds}")
  99. public AjaxResult remove(@PathVariable Long[] postIds)
  100. {
  101. return toAjax(postService.deletePostByIds(postIds));
  102. }
  103. /**
  104. * 获取岗位选择框列表
  105. */
  106. @GetMapping("/optionselect")
  107. public AjaxResult optionselect()
  108. {
  109. List<SysPost> posts = postService.selectPostAll();
  110. return AjaxResult.success(posts);
  111. }
  112. }