SysPostController.java 4.7 KB

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