SysPostController.java 4.4 KB

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