package com.lesingle.creation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lesingle.creation.entity.Department;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 部门 Mapper 接口
 */
@Mapper
public interface DepartmentMapper extends BaseMapper<Department> {

    /**
     * 根据租户 ID 和部门编码查询部门
     *
     * @param tenantId 租户 ID
     * @param code 部门编码
     * @return 部门实体
     */
    @Select("SELECT * FROM t_biz_department WHERE tenant_id = #{tenantId} AND code = #{code} AND deleted = 0")
    Department selectByCode(@Param("tenantId") Long tenantId, @Param("code") String code);

    /**
     * 根据租户 ID 查询部门列表
     *
     * @param tenantId 租户 ID
     * @return 部门列表
     */
    @Select("SELECT * FROM t_biz_department WHERE tenant_id = #{tenantId} AND deleted = 0 ORDER BY sort ASC")
    List<Department> selectByTenantId(@Param("tenantId") Long tenantId);
}
