package com.aiotagro.cattletrade.business.mapper;

import com.aiotagro.cattletrade.business.entity.SlaughterHouse;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 屠宰场管理 Mapper
 *
 * @author System
 * @date 2025-12-09
 */
@Mapper
public interface SlaughterHouseMapper extends BaseMapper<SlaughterHouse> {

    /**
     * 根据编码查询
     */
    @Select("SELECT * FROM slaughter_house WHERE slaughter_code = #{slaughterCode} AND is_delete = 0")
    SlaughterHouse selectByCode(@Param("slaughterCode") String slaughterCode);

    /**
     * 查询指定前缀下的最新编码
     */
    @Select("SELECT * FROM slaughter_house WHERE slaughter_code LIKE #{prefixPattern} AND is_delete = 0 ORDER BY slaughter_code DESC LIMIT 1")
    SlaughterHouse selectLastCode(@Param("prefixPattern") String prefixPattern);

    /**
     * 查询所有启用的屠宰场
     */
    @Select("SELECT id, house_name, slaughter_code FROM slaughter_house WHERE status = 1 AND is_delete = 0 ORDER BY create_time DESC")
    List<SlaughterHouse> selectAllEnabled();
}

