智慧保安后台管理-外网项目备份
zhongrj
2023-09-14 6311a8b8af3bb964f3154305f0cb0d6840ebbe88
新增角色树查询接口(查询所有下级)
6 files modified
1 files added
121 ■■■■■ changed files
src/main/java/org/springblade/modules/system/controller/RoleController.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/RoleMapper.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/RoleMapper.xml 22 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/IRoleService.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/RoleServiceImpl.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/vo/RoleParam.java 53 ●●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/controller/RoleController.java
@@ -35,6 +35,7 @@
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.service.IRoleService;
import org.springblade.modules.system.vo.GrantVO;
import org.springblade.modules.system.vo.RoleParam;
import org.springblade.modules.system.vo.RoleVO;
import org.springblade.modules.system.wrapper.RoleWrapper;
import org.springframework.web.bind.annotation.*;
@@ -101,6 +102,17 @@
    }
    /**
     * 自定义列表(只获取当前角色下级角色)
     * @param roleParam
     * @return
     */
    @GetMapping("/getRoleList")
    public R<List<RoleVO>> getRoleList(RoleParam roleParam) {
        List<Role> list = roleService.getRoleList(roleParam);
        return R.data(RoleWrapper.build().listNodeVO(list));
    }
    /**
     * 获取角色树形结构
     */
    @GetMapping("/tree")
src/main/java/org/springblade/modules/system/mapper/RoleMapper.java
@@ -18,8 +18,10 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.vo.DeptVO;
import org.springblade.modules.system.vo.RoleParam;
import org.springblade.modules.system.vo.RoleVO;
import java.util.List;
@@ -65,5 +67,17 @@
     * @return
     */
    List<String> getRoleAliases(Long[] ids);
    /**
     * 角色查询
     * @return
     */
    List selectRole();
    /**
     * 自定义列表(只获取当前角色下级角色)
     * @param roleParam
     * @return
     */
    List<Role> getRoleList(@Param("roleParam") RoleParam roleParam);
}
src/main/java/org/springblade/modules/system/mapper/RoleMapper.xml
@@ -74,6 +74,7 @@
          and is_deleted = 0
    </select>
    <!--角色查询-->
    <select id="selectRole" resultType="java.util.HashMap">
        SELECT id,
               role_name AS title
@@ -89,4 +90,25 @@
    AND id != 1431234799414071297
    </select>
    <!--角色查询-->
    <select id="getRoleList" resultType="org.springblade.modules.system.entity.Role">
        SELECT br.* FROM blade_role br
        inner join (
            SELECT * FROM
            (
                SELECT t1.*,IF( find_in_set( parent_id, @pids ) > 0, @pids := concat( @pids, ',', id ), 0 ) AS ischild FROM
                ( SELECT id, parent_id,role_name FROM blade_role t where is_deleted =0 ORDER BY parent_id, id ) t1,
                ( SELECT @pids := #{roleParam.roleId} ) t2
            ) t3
            WHERE
            ischild != 0
        ) on br.id = t3.id
        <if test="roleParam.isNowLevel==0">
            union all
            (
            SELECT * FROM blade_role where id = #{roleParam.roleId}
            )
        </if>
    </select>
</mapper>
src/main/java/org/springblade/modules/system/service/IRoleService.java
@@ -19,6 +19,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.vo.RoleParam;
import org.springblade.modules.system.vo.RoleVO;
import javax.validation.constraints.NotEmpty;
@@ -102,4 +103,10 @@
    List<RoleVO> search(String roleName, Long parentId);
    List selectRole();
    /**
     * 自定义列表(只获取当前角色下级角色)
     * @param roleParam
     * @return
     */
    List<Role> getRoleList(RoleParam roleParam);
}
src/main/java/org/springblade/modules/system/service/impl/RoleServiceImpl.java
@@ -35,6 +35,7 @@
import org.springblade.modules.system.service.IRoleMenuService;
import org.springblade.modules.system.service.IRoleScopeService;
import org.springblade.modules.system.service.IRoleService;
import org.springblade.modules.system.vo.RoleParam;
import org.springblade.modules.system.vo.RoleVO;
import org.springblade.modules.system.wrapper.RoleWrapper;
import org.springframework.stereotype.Service;
@@ -224,4 +225,14 @@
        return baseMapper.selectRole();
    }
    /**
     * 自定义列表(只获取当前角色下级角色)
     * @param roleParam
     * @return
     */
    @Override
    public List<Role> getRoleList(RoleParam roleParam) {
        roleParam.setRoleId(AuthUtil.getUser().getRoleId());
        return baseMapper.getRoleList(roleParam);
    }
}
src/main/java/org/springblade/modules/system/vo/RoleParam.java
New file
@@ -0,0 +1,53 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tool.node.INode;
import org.springblade.modules.system.entity.Role;
import sun.rmi.runtime.Log;
import java.util.ArrayList;
import java.util.List;
/**
 * 视图实体类
 *
 * @author Chill
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "RoleVO对象", description = "RoleVO对象")
public class RoleParam extends Role{
    private static final long serialVersionUID = 1L;
    /**
     * 是否返回当前层级 0:是  1:否
     */
    private Integer isNowLevel;
    /**
     * 角色id
     */
    private String roleId;
}
src/main/resources/application-test.yml
@@ -5,7 +5,7 @@
    host: 127.0.0.1
    port: 6379
    password:
    database: 1
    database: 8
    ssl: false
    ##redis 集群环境配置
    #cluster: