SysPostController.java 4.4 KB

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