package com.chushang.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chushang.system.entity.dto.ListDeptDTO;
import com.chushang.system.entity.po.SysDept;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 部门用于控制各平台的数据权限 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2022-08-18
 */
public interface SysDeptMapper extends BaseMapper<SysDept> {

    List<SysDept> selectDeptList(ListDeptDTO listDept);

    List<Long> selectDeptListByRoleId(@Param("roleId") Long roleId,
                                         @Param("deptCheckStrictly") boolean deptCheckStrictly);

    void updateDeptChildren(@Param("depts") List<SysDept> depts);

    @Select("SELECT dept_id FROM sys_role_dept WHERE role_id = #{roleId}")
    List<String> listScopeDeptIdByRoleId(@Param("roleId") Long roleId);

    @Select("SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} or find_in_set( #{deptId} , ancestors )")
    List<String> listScopeDeptIdByDeptId(@Param("deptId") Long deptId);
}
