Blame view

ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java 5.41 KB
cee572f2   RuoYi   若依 3.0
1
  package com.ruoyi.web.controller.system;

46444bd0   RuoYi   RuoYi-Vue 1.0
2
3
4
5
  

  import java.util.List;

  import org.springframework.beans.factory.annotation.Autowired;

  import org.springframework.security.access.prepost.PreAuthorize;

bcee37b8   RuoYi   若依 1.1
6
  import org.springframework.validation.annotation.Validated;

46444bd0   RuoYi   RuoYi-Vue 1.0
7
8
9
10
11
12
13
14
  import org.springframework.web.bind.annotation.DeleteMapping;

  import org.springframework.web.bind.annotation.GetMapping;

  import org.springframework.web.bind.annotation.PathVariable;

  import org.springframework.web.bind.annotation.PostMapping;

  import org.springframework.web.bind.annotation.PutMapping;

  import org.springframework.web.bind.annotation.RequestBody;

  import org.springframework.web.bind.annotation.RequestMapping;

  import org.springframework.web.bind.annotation.RestController;

cee572f2   RuoYi   若依 3.0
15
  import com.ruoyi.common.annotation.Log;

46444bd0   RuoYi   RuoYi-Vue 1.0
16
  import com.ruoyi.common.constant.UserConstants;

cee572f2   RuoYi   若依 3.0
17
18
19
20
21
  import com.ruoyi.common.core.controller.BaseController;

  import com.ruoyi.common.core.domain.AjaxResult;

  import com.ruoyi.common.core.domain.entity.SysRole;

  import com.ruoyi.common.core.page.TableDataInfo;

  import com.ruoyi.common.enums.BusinessType;

46444bd0   RuoYi   RuoYi-Vue 1.0
22
  import com.ruoyi.common.utils.SecurityUtils;

bcee37b8   RuoYi   若依 1.1
23
  import com.ruoyi.common.utils.poi.ExcelUtil;

cee572f2   RuoYi   若依 3.0
24
  import com.ruoyi.system.service.ISysRoleService;

46444bd0   RuoYi   RuoYi-Vue 1.0
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  

  /**

   * 角色信息

   * 

   * @author ruoyi

   */

  @RestController

  @RequestMapping("/system/role")

  public class SysRoleController extends BaseController

  {

      @Autowired

      private ISysRoleService roleService;

  

      @PreAuthorize("@ss.hasPermi('system:role:list')")

      @GetMapping("/list")

      public TableDataInfo list(SysRole role)

      {

          startPage();

          List<SysRole> list = roleService.selectRoleList(role);

          return getDataTable(list);

      }

  

bcee37b8   RuoYi   若依 1.1
47
48
49
50
51
52
53
54
55
56
      @Log(title = "角色管理", businessType = BusinessType.EXPORT)

      @PreAuthorize("@ss.hasPermi('system:role:export')")

      @GetMapping("/export")

      public AjaxResult export(SysRole role)

      {

          List<SysRole> list = roleService.selectRoleList(role);

          ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);

          return util.exportExcel(list, "角色数据");

      }

  

46444bd0   RuoYi   RuoYi-Vue 1.0
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
      /**

       * 根据角色编号获取详细信息

       */

      @PreAuthorize("@ss.hasPermi('system:role:query')")

      @GetMapping(value = "/{roleId}")

      public AjaxResult getInfo(@PathVariable Long roleId)

      {

          return AjaxResult.success(roleService.selectRoleById(roleId));

      }

  

      /**

       * 新增角色

       */

      @PreAuthorize("@ss.hasPermi('system:role:add')")

      @Log(title = "角色管理", businessType = BusinessType.INSERT)

      @PostMapping

bcee37b8   RuoYi   若依 1.1
73
      public AjaxResult add(@Validated @RequestBody SysRole role)

46444bd0   RuoYi   RuoYi-Vue 1.0
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
      {

          if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))

          {

              return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");

          }

          else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))

          {

              return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");

          }

          role.setCreateBy(SecurityUtils.getUsername());

          return toAjax(roleService.insertRole(role));

  

      }

  

      /**

       * 修改保存角色

       */

      @PreAuthorize("@ss.hasPermi('system:role:edit')")

      @Log(title = "角色管理", businessType = BusinessType.UPDATE)

      @PutMapping

bcee37b8   RuoYi   若依 1.1
94
      public AjaxResult edit(@Validated @RequestBody SysRole role)

46444bd0   RuoYi   RuoYi-Vue 1.0
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
      {

          roleService.checkRoleAllowed(role);

          if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))

          {

              return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");

          }

          else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))

          {

              return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");

          }

          role.setUpdateBy(SecurityUtils.getUsername());

          return toAjax(roleService.updateRole(role));

      }

  

      /**

       * 修改保存数据权限

       */

      @PreAuthorize("@ss.hasPermi('system:role:edit')")

      @Log(title = "角色管理", businessType = BusinessType.UPDATE)

      @PutMapping("/dataScope")

      public AjaxResult dataScope(@RequestBody SysRole role)

      {

          roleService.checkRoleAllowed(role);

          return toAjax(roleService.authDataScope(role));

      }

  

      /**

       * 状态修改

       */

      @PreAuthorize("@ss.hasPermi('system:role:edit')")

      @Log(title = "角色管理", businessType = BusinessType.UPDATE)

      @PutMapping("/changeStatus")

      public AjaxResult changeStatus(@RequestBody SysRole role)

      {

          roleService.checkRoleAllowed(role);

          role.setUpdateBy(SecurityUtils.getUsername());

          return toAjax(roleService.updateRoleStatus(role));

      }

  

      /**

bcee37b8   RuoYi   若依 1.1
135
       * 删除角色

46444bd0   RuoYi   RuoYi-Vue 1.0
136
137
138
       */

      @PreAuthorize("@ss.hasPermi('system:role:remove')")

      @Log(title = "角色管理", businessType = BusinessType.DELETE)

bcee37b8   RuoYi   若依 1.1
139
140
      @DeleteMapping("/{roleIds}")

      public AjaxResult remove(@PathVariable Long[] roleIds)

46444bd0   RuoYi   RuoYi-Vue 1.0
141
      {

bcee37b8   RuoYi   若依 1.1
142
          return toAjax(roleService.deleteRoleByIds(roleIds));

46444bd0   RuoYi   RuoYi-Vue 1.0
143
144
145
146
147
148
149
150
151
152
153
      }

  

      /**

       * 获取角色选择框列表

       */

      @PreAuthorize("@ss.hasPermi('system:role:query')")

      @GetMapping("/optionselect")

      public AjaxResult optionselect()

      {

          return AjaxResult.success(roleService.selectRoleAll());

      }

cee572f2   RuoYi   若依 3.0
154
  }