SysPostController.java 4.6 KB

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