SysRoleController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package com.boman.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.boman.domain.constant.UserConstants;
  16. import com.boman.common.core.utils.SecurityUtils;
  17. import com.boman.common.core.utils.poi.ExcelUtil;
  18. import com.boman.common.core.web.controller.BaseController;
  19. import com.boman.domain.dto.AjaxResult;
  20. import com.boman.domain.TableDataInfo;
  21. import com.boman.common.log.annotation.Log;
  22. import com.boman.common.log.enums.BusinessType;
  23. import com.boman.common.security.annotation.PreAuthorize;
  24. import com.boman.domain.SysRole;
  25. import com.boman.system.service.ISysRoleService;
  26. /**
  27. * 角色信息
  28. *
  29. * @author ruoyi
  30. */
  31. @RestController
  32. @RequestMapping("/role")
  33. public class SysRoleController extends BaseController
  34. {
  35. @Autowired
  36. private ISysRoleService roleService;
  37. @PreAuthorize(hasPermi = "system:role:list")
  38. @GetMapping("/list")
  39. public TableDataInfo list(SysRole role)
  40. {
  41. startPage();
  42. List<SysRole> list = roleService.selectRoleList(role);
  43. return getDataTable(list);
  44. }
  45. @Log(title = "角色管理", businessType = BusinessType.EXPORT)
  46. @PreAuthorize(hasPermi = "system:role:export")
  47. @PostMapping("/export")
  48. public void export(HttpServletResponse response, SysRole role) throws IOException
  49. {
  50. List<SysRole> list = roleService.selectRoleList(role);
  51. ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
  52. util.exportExcel(response, list, "角色数据");
  53. }
  54. /**
  55. * 根据角色编号获取详细信息
  56. */
  57. @PreAuthorize(hasPermi = "system:role:query")
  58. @GetMapping(value = "/{id}")
  59. public AjaxResult getInfo(@PathVariable Long id)
  60. {
  61. return AjaxResult.success(roleService.selectRoleById(id));
  62. }
  63. /**
  64. * 新增角色
  65. */
  66. @PreAuthorize(hasPermi = "system:role:add")
  67. @Log(title = "角色管理", businessType = BusinessType.INSERT)
  68. @PostMapping
  69. public AjaxResult add(@Validated @RequestBody SysRole role) {
  70. if (null == role.getId()) {
  71. if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {
  72. return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
  73. } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
  74. return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
  75. }
  76. role.setCreateBy(SecurityUtils.getUsername());
  77. return toAjax(roleService.insertRole(role));
  78. }
  79. return edit(role);
  80. }
  81. /**
  82. * 修改保存角色
  83. */
  84. @PreAuthorize(hasPermi = "system:role:edit")
  85. @Log(title = "角色管理", businessType = BusinessType.UPDATE)
  86. @PostMapping("/put")
  87. public AjaxResult edit(@Validated @RequestBody SysRole role)
  88. {
  89. roleService.checkRoleAllowed(role);
  90. if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
  91. {
  92. return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
  93. }
  94. else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
  95. {
  96. return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
  97. }
  98. role.setUpdateBy(SecurityUtils.getUsername());
  99. return toAjax(roleService.updateRole(role));
  100. }
  101. /**
  102. * 修改保存数据权限
  103. */
  104. @PreAuthorize(hasPermi = "system:role:edit")
  105. @Log(title = "角色管理", businessType = BusinessType.UPDATE)
  106. @PostMapping("/dataScope")
  107. public AjaxResult dataScope(@RequestBody SysRole role)
  108. {
  109. roleService.checkRoleAllowed(role);
  110. return toAjax(roleService.authDataScope(role));
  111. }
  112. /**
  113. * 状态修改
  114. */
  115. @PreAuthorize(hasPermi = "system:role:edit")
  116. @Log(title = "角色管理", businessType = BusinessType.UPDATE)
  117. @PostMapping("/changeStatus")
  118. public AjaxResult changeStatus(@RequestBody SysRole role)
  119. {
  120. roleService.checkRoleAllowed(role);
  121. role.setUpdateBy(SecurityUtils.getUsername());
  122. return toAjax(roleService.updateRoleStatus(role));
  123. }
  124. /**
  125. * 删除角色
  126. */
  127. @PreAuthorize(hasPermi = "system:role:remove")
  128. @Log(title = "角色管理", businessType = BusinessType.DELETE)
  129. @GetMapping(value = "/delete/{ids}")
  130. public AjaxResult remove(@PathVariable Long[] ids)
  131. {
  132. return toAjax(roleService.deleteRoleByIds(ids));
  133. }
  134. /**
  135. * 获取角色选择框列表
  136. */
  137. @PreAuthorize(hasPermi = "system:role:query")
  138. @GetMapping("/optionselect")
  139. public AjaxResult optionselect()
  140. {
  141. return AjaxResult.success(roleService.selectRoleAll());
  142. }
  143. }