package com.erp.dataimport.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.erp.dataimport.entity.ImportTemplate;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 导入模板 Mapper
 */
@Mapper
public interface ImportTemplateRepository extends BaseMapper<ImportTemplate> {

    @Select("SELECT * FROM import_template WHERE id = #{id} AND deleted_at IS NULL")
    ImportTemplate selectById(@Param("id") Long id);

    @Select("SELECT * FROM import_template WHERE template_code = #{templateCode} AND biz_type = #{bizType} AND tenant_id = #{tenantId} AND deleted_at IS NULL")
    ImportTemplate selectByCodeAndBizType(@Param("templateCode") String templateCode, @Param("bizType") String bizType, @Param("tenantId") Long tenantId);

    @Select("SELECT * FROM import_template WHERE biz_type = #{bizType} AND is_default = true AND tenant_id = #{tenantId} AND deleted_at IS NULL LIMIT 1")
    ImportTemplate selectDefaultByBizType(@Param("bizType") String bizType, @Param("tenantId") Long tenantId);
}
