无关风月
2024-07-11 eb6b6dbb35a9f029e0b7d269773685c19fd40976
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/RoleController.java
@@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * 角色控制器
@@ -110,6 +111,14 @@
    @ResponseBody
    public Object list(@RequestParam(required = false) String roleName) {
        List<Map<String, Object>> roles = this.roleService.selectRoles(super.getPara("roleName"));
        //运营商
        if (UserExt.getUser().getObjectType()==2){
            List<Map<String, Object>> filteredRoles = roles.stream()
                    .filter(role -> role.containsKey("version") && role.get("version").equals(UserExt.getUser().getId()))
                    .collect(Collectors.toList());
            return super.warpObject(new RoleWarpper(filteredRoles));
        }
        return super.warpObject(new RoleWarpper(roles));
    }
@@ -125,6 +134,9 @@
            throw new GunsException(BizExceptionEnum.REQUEST_NULL);
        }
        role.setId(null);
        role.setObjType(UserExt.getUser().getObjectType());
        role.setObjId(UserExt.getUser().getObjectId());
        role.setVersion(UserExt.getUser().getId());
        this.roleService.save(role);
@@ -216,7 +228,7 @@
    @RequestMapping(value = "/roleTreeList")
    @ResponseBody
    public List<ZTreeNode> roleTreeList() {
        List<ZTreeNode> roleTreeList = this.roleService.roleTreeList();
        List<ZTreeNode> roleTreeList = this.roleService.roleTreeList(UserExt.getUser().getObjectType(),UserExt.getUser().getObjectId());
        roleTreeList.add(ZTreeNode.createParent());
        return roleTreeList;
    }
@@ -229,12 +241,14 @@
    public List<ZTreeNode> roleTreeListByUserId(@PathVariable Integer userId) {
        User theUser = this.userService.getById(userId);
        String roleid = theUser.getRoleid();
        Integer objectType = UserExt.getUser().getObjectType();
        Integer objectId = UserExt.getUser().getObjectId();
        if (Objects.isNull(roleid)) {
            List<ZTreeNode> roleTreeList = this.roleService.roleTreeList();
            List<ZTreeNode> roleTreeList = this.roleService.roleTreeList(objectType,objectId);
            return roleTreeList;
        } else {
            String[] strArray = Convert.toStrArray(",", roleid);
            List<ZTreeNode> roleTreeListByUserId = this.roleService.roleTreeListByRoleId(strArray);
            List<ZTreeNode> roleTreeListByUserId = this.roleService.roleTreeListByRoleId(strArray,objectType,objectId);
            return roleTreeListByUserId;
        }
    }