package cn.iocoder.yudao.module.system.api.dept; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import java.util.Collection; import java.util.List; import java.util.Map; /** * 部门 API 接口 * * @author 超级管理员 */ public interface DeptApi { /** * 获得部门信息 * * @param id 部门编号 * @return 部门信息 */ DeptRespDTO getDept(Long id); /** * 获得部门信息数组 * * @param ids 部门编号数组 * @return 部门信息数组 */ List getDeptList(Collection ids); /** * 获得全部部门列表 * * @return 部门信息数组 */ List getDeptList(); /** * 校验部门们是否有效。如下情况,视为无效: * 1. 部门编号不存在 * 2. 部门被禁用 * * @param ids 角色编号数组 */ void validateDeptList(Collection ids); /** * 获得指定编号的部门 Map * * @param ids 部门编号数组 * @return 部门 Map */ default Map getDeptMap(Collection ids) { List list = getDeptList(ids); return CollectionUtils.convertMap(list, DeptRespDTO::getId); } /** * 获得指定部门的所有子部门 * * @param id 部门编号 * @return 子部门列表 */ List getChildDeptList(Long id); /** * 按名称获得部门编号,不存在时自动创建(挂在根部门下) * *

用于 Excel 导入等「只有名称没有编号」的场景:员工导入时部门是必填项, * 若客户表格里的部门名在系统中尚未建立,直接报错会导致整批导入失败, * 这里改为自动补建,保证导入可用。 * * @param name 部门名称 * @return 部门编号;名称为空时返回 {@code null} */ Long getOrCreateDeptByName(String name); }