SysPostController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.ruoyi.web.controller.system;
  2. import java.util.List;
  3. import org.apache.shiro.authz.annotation.RequiresPermissions;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.ui.ModelMap;
  7. import org.springframework.validation.annotation.Validated;
  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.RequestMapping;
  12. import org.springframework.web.bind.annotation.ResponseBody;
  13. import com.ruoyi.common.annotation.Log;
  14. import com.ruoyi.common.core.controller.BaseController;
  15. import com.ruoyi.common.core.domain.AjaxResult;
  16. import com.ruoyi.common.core.page.TableDataInfo;
  17. import com.ruoyi.common.enums.BusinessType;
  18. import com.ruoyi.common.utils.poi.ExcelUtil;
  19. import com.ruoyi.system.domain.SysPost;
  20. import com.ruoyi.system.service.ISysPostService;
  21. /**
  22. * 岗位信息操作处理
  23. *
  24. * @author ruoyi
  25. */
  26. @Controller
  27. @RequestMapping("/system/post")
  28. public class SysPostController extends BaseController
  29. {
  30. private String prefix = "system/post";
  31. @Autowired
  32. private ISysPostService postService;
  33. @RequiresPermissions("system:post:view")
  34. @GetMapping()
  35. public String operlog()
  36. {
  37. return prefix + "/post";
  38. }
  39. @RequiresPermissions("system:post:list")
  40. @PostMapping("/list")
  41. @ResponseBody
  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. @ResponseBody
  52. public AjaxResult export(SysPost post)
  53. {
  54. List<SysPost> list = postService.selectPostList(post);
  55. ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
  56. return util.exportExcel(list, "岗位数据");
  57. }
  58. @RequiresPermissions("system:post:remove")
  59. @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  60. @PostMapping("/remove")
  61. @ResponseBody
  62. public AjaxResult remove(String ids)
  63. {
  64. return toAjax(postService.deletePostByIds(ids));
  65. }
  66. /**
  67. * 新增岗位
  68. */
  69. @RequiresPermissions("system:post:add")
  70. @GetMapping("/add")
  71. public String add()
  72. {
  73. return prefix + "/add";
  74. }
  75. /**
  76. * 新增保存岗位
  77. */
  78. @RequiresPermissions("system:post:add")
  79. @Log(title = "岗位管理", businessType = BusinessType.INSERT)
  80. @PostMapping("/add")
  81. @ResponseBody
  82. public AjaxResult addSave(@Validated SysPost post)
  83. {
  84. if (!postService.checkPostNameUnique(post))
  85. {
  86. return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  87. }
  88. else if (!postService.checkPostCodeUnique(post))
  89. {
  90. return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  91. }
  92. post.setCreateBy(getLoginName());
  93. return toAjax(postService.insertPost(post));
  94. }
  95. /**
  96. * 修改岗位
  97. */
  98. @RequiresPermissions("system:post:edit")
  99. @GetMapping("/edit/{postId}")
  100. public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
  101. {
  102. mmap.put("post", postService.selectPostById(postId));
  103. return prefix + "/edit";
  104. }
  105. /**
  106. * 修改保存岗位
  107. */
  108. @RequiresPermissions("system:post:edit")
  109. @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  110. @PostMapping("/edit")
  111. @ResponseBody
  112. public AjaxResult editSave(@Validated SysPost post)
  113. {
  114. if (!postService.checkPostNameUnique(post))
  115. {
  116. return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  117. }
  118. else if (!postService.checkPostCodeUnique(post))
  119. {
  120. return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  121. }
  122. post.setUpdateBy(getLoginName());
  123. return toAjax(postService.updatePost(post));
  124. }
  125. /**
  126. * 校验岗位名称
  127. */
  128. @PostMapping("/checkPostNameUnique")
  129. @ResponseBody
  130. public boolean checkPostNameUnique(SysPost post)
  131. {
  132. return postService.checkPostNameUnique(post);
  133. }
  134. /**
  135. * 校验岗位编码
  136. */
  137. @PostMapping("/checkPostCodeUnique")
  138. @ResponseBody
  139. public boolean checkPostCodeUnique(SysPost post)
  140. {
  141. return postService.checkPostCodeUnique(post);
  142. }
  143. }