RoleController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package com.ruoyi.project.system.role.controller;
  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.transaction.annotation.Transactional;
  7. import org.springframework.ui.ModelMap;
  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.utils.poi.ExcelUtil;
  14. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  15. import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
  16. import com.ruoyi.framework.web.controller.BaseController;
  17. import com.ruoyi.framework.web.domain.AjaxResult;
  18. import com.ruoyi.framework.web.page.TableDataInfo;
  19. import com.ruoyi.project.system.role.domain.Role;
  20. import com.ruoyi.project.system.role.service.IRoleService;
  21. /**
  22. * 角色信息
  23. *
  24. * @author ruoyi
  25. */
  26. @Controller
  27. @RequestMapping("/system/role")
  28. public class RoleController extends BaseController
  29. {
  30. private String prefix = "system/role";
  31. @Autowired
  32. private IRoleService roleService;
  33. @RequiresPermissions("system:role:view")
  34. @GetMapping()
  35. public String role()
  36. {
  37. return prefix + "/role";
  38. }
  39. @RequiresPermissions("system:role:list")
  40. @PostMapping("/list")
  41. @ResponseBody
  42. public TableDataInfo list(Role role)
  43. {
  44. startPage();
  45. List<Role> list = roleService.selectRoleList(role);
  46. return getDataTable(list);
  47. }
  48. @Log(title = "角色管理", action = BusinessType.EXPORT)
  49. @RequiresPermissions("system:role:export")
  50. @PostMapping("/export")
  51. @ResponseBody
  52. public AjaxResult export(Role role) throws Exception
  53. {
  54. try
  55. {
  56. List<Role> list = roleService.selectRoleList(role);
  57. ExcelUtil<Role> util = new ExcelUtil<Role>(Role.class);
  58. return util.exportExcel(list, "role");
  59. }
  60. catch (Exception e)
  61. {
  62. return error("导出Excel失败,请联系网站管理员!");
  63. }
  64. }
  65. /**
  66. * 新增角色
  67. */
  68. @GetMapping("/add")
  69. public String add()
  70. {
  71. return prefix + "/add";
  72. }
  73. /**
  74. * 新增保存角色
  75. */
  76. @RequiresPermissions("system:role:add")
  77. @Log(title = "角色管理", action = BusinessType.INSERT)
  78. @PostMapping("/add")
  79. @Transactional(rollbackFor = Exception.class)
  80. @ResponseBody
  81. public AjaxResult addSave(Role role)
  82. {
  83. return toAjax(roleService.insertRole(role));
  84. }
  85. /**
  86. * 修改角色
  87. */
  88. @GetMapping("/edit/{roleId}")
  89. public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap)
  90. {
  91. mmap.put("role", roleService.selectRoleById(roleId));
  92. return prefix + "/edit";
  93. }
  94. /**
  95. * 修改保存角色
  96. */
  97. @RequiresPermissions("system:role:edit")
  98. @Log(title = "角色管理", action = BusinessType.UPDATE)
  99. @PostMapping("/edit")
  100. @Transactional(rollbackFor = Exception.class)
  101. @ResponseBody
  102. public AjaxResult editSave(Role role)
  103. {
  104. return toAjax(roleService.updateRole(role));
  105. }
  106. @RequiresPermissions("system:role:remove")
  107. @Log(title = "角色管理", action = BusinessType.DELETE)
  108. @PostMapping("/remove")
  109. @ResponseBody
  110. public AjaxResult remove(String ids)
  111. {
  112. try
  113. {
  114. return toAjax(roleService.deleteRoleByIds(ids));
  115. }
  116. catch (Exception e)
  117. {
  118. return error(e.getMessage());
  119. }
  120. }
  121. /**
  122. * 校验角色名称
  123. */
  124. @PostMapping("/checkRoleNameUnique")
  125. @ResponseBody
  126. public String checkRoleNameUnique(Role role)
  127. {
  128. String uniqueFlag = "0";
  129. if (role != null)
  130. {
  131. uniqueFlag = roleService.checkRoleNameUnique(role);
  132. }
  133. return uniqueFlag;
  134. }
  135. /**
  136. * 校验角色权限
  137. */
  138. @PostMapping("/checkRoleKeyUnique")
  139. @ResponseBody
  140. public String checkRoleKeyUnique(Role role)
  141. {
  142. String uniqueFlag = "0";
  143. if (role != null)
  144. {
  145. uniqueFlag = roleService.checkRoleKeyUnique(role);
  146. }
  147. return uniqueFlag;
  148. }
  149. /**
  150. * 选择菜单树
  151. */
  152. @GetMapping("/selectMenuTree")
  153. public String selectMenuTree()
  154. {
  155. return prefix + "/tree";
  156. }
  157. }