SysPostController.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.constant.UserConstants;
  15. import com.ruoyi.common.core.controller.BaseController;
  16. import com.ruoyi.common.core.domain.AjaxResult;
  17. import com.ruoyi.common.core.page.TableDataInfo;
  18. import com.ruoyi.common.enums.BusinessType;
  19. import com.ruoyi.common.utils.ShiroUtils;
  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. @Controller
  29. @RequestMapping("/system/post")
  30. public class SysPostController extends BaseController
  31. {
  32. private String prefix = "system/post";
  33. @Autowired
  34. private ISysPostService postService;
  35. @RequiresPermissions("system:post:view")
  36. @GetMapping()
  37. public String operlog()
  38. {
  39. return prefix + "/post";
  40. }
  41. @RequiresPermissions("system:post:list")
  42. @PostMapping("/list")
  43. @ResponseBody
  44. public TableDataInfo list(SysPost post)
  45. {
  46. startPage();
  47. List<SysPost> list = postService.selectPostList(post);
  48. return getDataTable(list);
  49. }
  50. @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
  51. @RequiresPermissions("system:post:export")
  52. @PostMapping("/export")
  53. @ResponseBody
  54. public AjaxResult export(SysPost post)
  55. {
  56. List<SysPost> list = postService.selectPostList(post);
  57. ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
  58. return util.exportExcel(list, "岗位数据");
  59. }
  60. @RequiresPermissions("system:post:remove")
  61. @Log(title = "岗位管理", businessType = BusinessType.DELETE)
  62. @PostMapping("/remove")
  63. @ResponseBody
  64. public AjaxResult remove(String ids)
  65. {
  66. try
  67. {
  68. return toAjax(postService.deletePostByIds(ids));
  69. }
  70. catch (Exception e)
  71. {
  72. return error(e.getMessage());
  73. }
  74. }
  75. /**
  76. * 新增岗位
  77. */
  78. @GetMapping("/add")
  79. public String add()
  80. {
  81. return prefix + "/add";
  82. }
  83. /**
  84. * 新增保存岗位
  85. */
  86. @RequiresPermissions("system:post:add")
  87. @Log(title = "岗位管理", businessType = BusinessType.INSERT)
  88. @PostMapping("/add")
  89. @ResponseBody
  90. public AjaxResult addSave(@Validated SysPost post)
  91. {
  92. if (UserConstants.POST_NAME_NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
  93. {
  94. return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  95. }
  96. else if (UserConstants.POST_CODE_NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
  97. {
  98. return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  99. }
  100. post.setCreateBy(ShiroUtils.getLoginName());
  101. return toAjax(postService.insertPost(post));
  102. }
  103. /**
  104. * 修改岗位
  105. */
  106. @GetMapping("/edit/{postId}")
  107. public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
  108. {
  109. mmap.put("post", postService.selectPostById(postId));
  110. return prefix + "/edit";
  111. }
  112. /**
  113. * 修改保存岗位
  114. */
  115. @RequiresPermissions("system:post:edit")
  116. @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
  117. @PostMapping("/edit")
  118. @ResponseBody
  119. public AjaxResult editSave(@Validated SysPost post)
  120. {
  121. if (UserConstants.POST_NAME_NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
  122. {
  123. return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
  124. }
  125. else if (UserConstants.POST_CODE_NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
  126. {
  127. return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
  128. }
  129. post.setUpdateBy(ShiroUtils.getLoginName());
  130. return toAjax(postService.updatePost(post));
  131. }
  132. /**
  133. * 校验岗位名称
  134. */
  135. @PostMapping("/checkPostNameUnique")
  136. @ResponseBody
  137. public String checkPostNameUnique(SysPost post)
  138. {
  139. return postService.checkPostNameUnique(post);
  140. }
  141. /**
  142. * 校验岗位编码
  143. */
  144. @PostMapping("/checkPostCodeUnique")
  145. @ResponseBody
  146. public String checkPostCodeUnique(SysPost post)
  147. {
  148. return postService.checkPostCodeUnique(post);
  149. }
  150. }