package com.lesingle.creation.mapper;

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

/**
 * 字典 Mapper 接口
 */
@Mapper
public interface DictMapper extends BaseMapper<Dict> {

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

    /**
     * 根据租户 ID 和字典编码查询字典（排除指定 ID）
     *
     * @param tenantId 租户 ID
     * @param code 字典编码
     * @param excludeId 排除的 ID
     * @return 字典实体
     */
    @Select("SELECT * FROM t_sys_dict WHERE tenant_id = #{tenantId} AND code = #{code} AND id != #{excludeId} AND deleted = 0")
    Dict selectByCodeExclude(@Param("tenantId") Long tenantId, @Param("code") String code, @Param("excludeId") Long excludeId);
}
