package org.jeecg.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysRole;

import java.util.List;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @Author scott
 * @since 2018-12-19
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * @Author scott
     * @Date 2019/12/13 16:12
     * @Description: 删除角色与用户关系
     */
    @Delete("delete from sys_user_role where role_id = #{roleId}")
    void deleteRoleUserRelation(@Param("roleId") String roleId);


    /**
     * @Author scott
     * @Date 2019/12/13 16:12
     * @Description: 删除角色与权限关系
     */
    @Delete("delete from sys_role_permission where role_id = #{roleId}")
    void deleteRolePermissionRelation(@Param("roleId") String roleId);

    @Select("select DISTINCT a.* from (SELECT  c.* FROM `sys_role` a " +
            "            left join sys_user_role b  on a.id = b.role_id " +
            "            left join sys_role c on FIND_IN_SET(c.id,a.permissions) " +
            "            where b.user_id = #{id} and c.del_flag = 0 " +
            "" +
            "UNION " +
            "SELECT a.* FROM `sys_role` a " +
            "            left join sys_user_role b  on a.id = b.role_id " +
            "where b.user_id = #{id})a ")
    List<SysRole> getRoleRoleRermissions(@Param("id") String id);

    List<String> getRoleIdList(@Param("str") String[] str1);

    List<String> getRoleIdList1(@Param("id") String id);

    List<SysRole> getByUserId(@Param("id") String id);
}
