SysPostController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.fjhx.base.system;
  2. import com.baomidou.dynamic.datasource.annotation.DS;
  3. import com.ruoyi.common.annotation.Log;
  4. import com.ruoyi.common.constant.BaseSourceConstant;
  5. import com.ruoyi.common.core.controller.BaseController;
  6. import com.ruoyi.common.core.domain.AjaxResult;
  7. import com.ruoyi.common.core.page.TableDataInfo;
  8. import com.ruoyi.common.enums.BusinessType;
  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. @DS(BaseSourceConstant.BASE)
  24. @RestController
  25. @RequestMapping("/system/post")
  26. public class SysPostController extends BaseController {
  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. startPage();
  36. List<SysPost> list = postService.selectPostList(post);
  37. return getDataTable(list);
  38. }
  39. @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
  40. @PreAuthorize("@ss.hasPermi('system:post:export')")
  41. @PostMapping("/export")
  42. public void export(HttpServletResponse response, SysPost post) {
  43. List<SysPost> list = postService.selectPostList(post);
  44. ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
  45. util.exportExcel(response, list, "岗位数据");
  46. }
  47. /**
  48. * 根据岗位编号获取详细信息
  49. */
  50. @PreAuthorize("@ss.hasPermi('system:post:query')")
  51. @GetMapping(value = "/{postId}")
  52. public AjaxResult getInfo(@PathVariable Long postId) {
  53. return 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. if (!postService.checkPostNameUnique(post)) {
  63. return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  64. } else if (!postService.checkPostCodeUnique(post)) {
  65. return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  66. }
  67. post.setCreateBy(getUsername());
  68. return toAjax(postService.insertPost(post));
  69. }
  70. /**
  71. * 修改岗位
  72. */
  73. @PreAuthorize("@ss.hasPermi('system:post:edit')")
  74. @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  75. @PutMapping
  76. public AjaxResult edit(@Validated @RequestBody SysPost post) {
  77. if (!postService.checkPostNameUnique(post)) {
  78. return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  79. } else if (!postService.checkPostCodeUnique(post)) {
  80. return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  81. }
  82. post.setUpdateBy(getUsername());
  83. return toAjax(postService.updatePost(post));
  84. }
  85. /**
  86. * 删除岗位
  87. */
  88. @PreAuthorize("@ss.hasPermi('system:post:remove')")
  89. @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  90. @DeleteMapping("/{postIds}")
  91. public AjaxResult remove(@PathVariable Long[] postIds) {
  92. return toAjax(postService.deletePostByIds(postIds));
  93. }
  94. /**
  95. * 获取岗位选择框列表
  96. */
  97. @GetMapping("/optionselect")
  98. public AjaxResult optionselect() {
  99. List<SysPost> posts = postService.selectPostAll();
  100. return success(posts);
  101. }
  102. }