From d68c61517a3a6d4ec4d47844c21bdc143f99cbab Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期三, 17 四月 2024 22:58:05 +0800
Subject: [PATCH] 大屏接口

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java |  153 +++++++++++++++++++++++++-------------------------
 1 files changed, 77 insertions(+), 76 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
index fa44b77..1205627 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
@@ -1,49 +1,60 @@
 package com.ruoyi.web.controller.system;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
 
-import com.ruoyi.common.basic.PageInfo;
-import com.ruoyi.common.core.domain.entity.SysMenu;
-import com.ruoyi.system.dto.SysRoleDTO;
-import com.ruoyi.system.query.SysRoleQuery;
-import com.ruoyi.system.service.ISysMenuService;
-import com.ruoyi.system.vo.RoleInfoVO;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.basic.PageDTO;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.core.domain.entity.SysMenu;
 import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.BeanUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.web.service.SysPermissionService;
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.domain.SysUserRole;
+import com.ruoyi.system.dto.SysRoleDTO;
+import com.ruoyi.system.query.SysRoleQuery;
 import com.ruoyi.system.service.ISysDeptService;
+import com.ruoyi.system.service.ISysMenuService;
 import com.ruoyi.system.service.ISysRoleService;
 import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.system.vo.RoleInfoVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+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.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * 角色信息
- * 
+ *
  * @author ruoyi
  */
 @Api(tags = "角色信息")
 @RestController
 @RequestMapping("/system/role")
-public class SysRoleController extends BaseController
-{
+public class SysRoleController extends BaseController {
+
     @Autowired
     private ISysRoleService roleService;
 
@@ -64,32 +75,30 @@
     // @PreAuthorize("@ss.hasPermi('system:role:list')")
     @ApiOperation(value = "角色列表")
     @PostMapping("/list")
-    public AjaxResult list(@RequestBody SysRoleQuery query)
-    {
-        PageInfo<SysRole> list = roleService.selectList(query);
-        return AjaxResult.success(list);
+    public R<PageDTO<RoleInfoVO>> list(@RequestBody SysRoleQuery query) {
+        PageDTO<RoleInfoVO> sysRolePageDTO = roleService.selectList(query);
+        return R.ok(sysRolePageDTO);
     }
 
     @ApiOperation(value = "角色列表不分页")
     @PostMapping("/listNotPage")
-    public AjaxResult list()
-    {
+    public R<List<RoleInfoVO>> list() {
         List<SysRole> list = roleService.selectRoleList(new SysRole());
-        return AjaxResult.success(list);
+        List<RoleInfoVO> vos = BeanUtils.copyList(list, RoleInfoVO.class);
+        return R.ok(vos);
     }
 
-    @ApiOperation(value = "角色数量统计")
+    //    @ApiOperation(value = "角色数量统计")
     @PostMapping("/roleCount")
-    public AjaxResult roleCount()
-    {
+    public AjaxResult roleCount() {
         int all = roleService.selectCount(null);
         int normal = roleService.selectCount(0);
         int stop = roleService.selectCount(1);
 
-        Map<String,Integer> map = new HashMap<>();
-        map.put("all",all);
-        map.put("normal",normal);
-        map.put("stop",stop);
+        Map<String, Integer> map = new HashMap<>();
+        map.put("all", all);
+        map.put("normal", normal);
+        map.put("stop", stop);
         return AjaxResult.success(map);
     }
 
@@ -108,8 +117,7 @@
      */
     // @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping(value = "/{roleId}")
-    public AjaxResult getInfo(@PathVariable Long roleId)
-    {
+    public AjaxResult getInfo(@PathVariable Long roleId) {
         roleService.checkRoleDataScope(roleId);
         return AjaxResult.success(roleService.selectRoleById(roleId));
     }
@@ -117,17 +125,19 @@
 
     @ApiOperation("角色详情")
     @GetMapping("/roleInfo")
-    public AjaxResult roleInfo(@RequestParam Long roleId)
-    {
+    public R<RoleInfoVO> roleInfo(@RequestParam Long roleId) {
         SysRole role = roleService.selectRoleById(roleId);
+        if (Objects.isNull(role)) {
+            return R.ok(new RoleInfoVO());
+        }
         RoleInfoVO roleInfoVo = new RoleInfoVO();
         roleInfoVo.setRoleId(role.getRoleId());
         roleInfoVo.setRoleName(role.getRoleName());
 
         // 获取当前角色的菜单列表
         List<SysMenu> menus = menuService.selectListByRoleId(roleId);
-        if(menus.size()==0){
-            return AjaxResult.success(new ArrayList<>());
+        if (menus.size() == 0) {
+            return R.ok(roleInfoVo);
         }
         List<Long> menusId = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
 
@@ -135,17 +145,21 @@
         List<SysMenu> levelMenus = roleService.getMenuLevelList(menusId);
 
         roleInfoVo.setMenus(menusId);
-        return AjaxResult.success(roleInfoVo);
+        return R.ok(roleInfoVo);
     }
 
 
     @ApiOperation("用户获取权限菜单")
     @GetMapping("/roleInfoFromUserId")
-    public AjaxResult roleInfoFromUserId(@RequestParam Long userId)
-    {
+    public AjaxResult roleInfoFromUserId(@RequestParam Long userId) {
         return AjaxResult.success(roleService.roleInfoFromUserId(userId));
     }
 
+    @ApiOperation("角色获取权限菜单")
+    @GetMapping("/getMenuByRoleId")
+    public AjaxResult getMenuByRoleId(@RequestParam Long roleId) {
+        return AjaxResult.success(roleService.getMenuByRoleId(roleId));
+    }
 
     /**
      * 新增角色
@@ -154,10 +168,9 @@
     @ApiOperation(value = "新增角色")
     @Log(title = "角色信息-新增角色", businessType = BusinessType.INSERT)
     @PostMapping("/add")
-    public AjaxResult add(@Validated @RequestBody SysRoleDTO dto)
-    {
-        Boolean flag= roleService.isExit(dto.getRoleId(),dto.getRoleName());
-        if(flag){
+    public AjaxResult add(@Validated @RequestBody SysRoleDTO dto) {
+        Boolean flag = roleService.isExit(dto.getRoleId(), dto.getRoleName());
+        if (flag) {
             return error("新增角色'" + dto.getRoleName() + "'失败,角色名称已存在");
         }
         roleService.saveRole(dto);
@@ -172,20 +185,18 @@
     @ApiOperation(value = "编辑角色")
     @Log(title = "角色信息-编辑角色", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@Validated @RequestBody SysRoleDTO dto)
-    {
-        Boolean flag= roleService.isExit(dto.getRoleId(),dto.getRoleName());
-        if (flag){
+    public AjaxResult edit(@Validated @RequestBody SysRoleDTO dto) {
+        Boolean flag = roleService.isExit(dto.getRoleId(), dto.getRoleName());
+        if (flag) {
             return error("修改角色'" + dto.getRoleName() + "'失败,角色名称已存在");
         }
-        if (roleService.editRole(dto) > 0)
-        {
+        if (roleService.editRole(dto) > 0) {
             // 更新缓存用户权限
             LoginUser loginUser = getLoginUser();
-            if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
-            {
+            if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) {
                 loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
-                loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
+                loginUser.setUser(
+                        userService.selectUserByUserName(loginUser.getUser().getUserName()));
                 tokenService.setLoginUser(loginUser);
             }
             return AjaxResult.success();
@@ -199,8 +210,7 @@
     // @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.UPDATE)
     @PutMapping("/dataScope")
-    public AjaxResult dataScope(@RequestBody SysRole role)
-    {
+    public AjaxResult dataScope(@RequestBody SysRole role) {
         roleService.checkRoleAllowed(role);
         roleService.checkRoleDataScope(role.getRoleId());
         return AjaxResult.success(roleService.authDataScope(role));
@@ -210,11 +220,10 @@
      * 状态修改
      */
     // @PreAuthorize("@ss.hasPermi('system:role:edit')")
-    @ApiOperation(value = "状态修改")
+//    @ApiOperation(value = "状态修改")
     @Log(title = "角色信息-角色状态修改", businessType = BusinessType.UPDATE)
     @PutMapping("/changeStatus")
-    public AjaxResult changeStatus(@RequestBody SysRole role)
-    {
+    public AjaxResult changeStatus(@RequestBody SysRole role) {
         role.setUpdateBy(getUsername());
         roleService.updateStatus(role);
         return AjaxResult.success();
@@ -227,8 +236,7 @@
     @ApiOperation(value = "删除角色")
     @Log(title = "角色信息-角色删除角色", businessType = BusinessType.DELETE)
     @DeleteMapping("/deleteById/{ids}")
-    public AjaxResult remove(@PathVariable String ids)
-    {
+    public AjaxResult remove(@PathVariable String ids) {
         String[] split = ids.split(",");
         List<Long> id = new ArrayList<>();
         for (String s : split) {
@@ -242,8 +250,7 @@
      */
     // @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping("/optionselect")
-    public AjaxResult optionselect()
-    {
+    public AjaxResult optionselect() {
         return AjaxResult.success(roleService.selectRoleAll());
     }
 
@@ -252,8 +259,7 @@
      */
     // @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/authUser/allocatedList")
-    public TableDataInfo allocatedList(SysUser user)
-    {
+    public TableDataInfo allocatedList(SysUser user) {
 //        startPage();
         List<SysUser> list = userService.selectAllocatedList(user);
         return getDataTable(list);
@@ -264,8 +270,7 @@
      */
     // @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/authUser/unallocatedList")
-    public TableDataInfo unallocatedList(SysUser user)
-    {
+    public TableDataInfo unallocatedList(SysUser user) {
 //        startPage();
         List<SysUser> list = userService.selectUnallocatedList(user);
         return getDataTable(list);
@@ -277,8 +282,7 @@
     // @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/cancel")
-    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
-    {
+    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) {
         return AjaxResult.success(roleService.deleteAuthUser(userRole));
     }
 
@@ -288,8 +292,7 @@
     // @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/cancelAll")
-    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
-    {
+    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) {
         return AjaxResult.success(roleService.deleteAuthUsers(roleId, userIds));
     }
 
@@ -299,8 +302,7 @@
     // @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/selectAll")
-    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
-    {
+    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) {
         roleService.checkRoleDataScope(roleId);
         return AjaxResult.success(roleService.insertAuthUsers(roleId, userIds));
     }
@@ -310,8 +312,7 @@
      */
     // @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping(value = "/deptTree/{roleId}")
-    public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
-    {
+    public AjaxResult deptTree(@PathVariable("roleId") Long roleId) {
         AjaxResult ajax = AjaxResult.success();
         ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
         ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));

--
Gitblit v1.7.1