package com.aiotagro.cattletrade.business.mapper;

import com.aiotagro.cattletrade.business.entity.SlaughterRecord;
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;

/**
 * 屠宰记录 Mapper
 *
 * @author System
 * @date 2025-12-10
 */
@Mapper
public interface SlaughterRecordMapper extends BaseMapper<SlaughterRecord> {

    /**
     * 根据编码前缀查询最后一个编码（用于生成新编码）
     *
     * @param prefixPattern 编码前缀模式，如 "SL20251210%"
     * @return 最后一个屠宰记录
     */
    @Select("SELECT * FROM slaughter_record WHERE record_code LIKE #{prefixPattern} AND is_delete = 0 ORDER BY record_code DESC LIMIT 1")
    SlaughterRecord selectLastCode(@Param("prefixPattern") String prefixPattern);
}


