package com.aiotagro.cattletrade.business.mapper;

import com.aiotagro.cattletrade.business.entity.Warehouse;
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-01-20
 */
@Mapper
public interface WarehouseMapper extends BaseMapper<Warehouse> {

    /**
     * 根据中转仓编码查询中转仓（唯一性校验）
     * @param warehouseCode 中转仓编码
     * @return 中转仓信息
     */
    @Select("SELECT * FROM warehouse WHERE warehouse_code = #{warehouseCode} AND is_delete = 0")
    Warehouse selectByWarehouseCode(@Param("warehouseCode") String warehouseCode);

    /**
     * 获取所有启用的中转仓（下拉选择用）
     * @return 中转仓列表
     */
    @Select("SELECT id, warehouse_name, warehouse_code FROM warehouse WHERE status = 1 AND is_delete = 0 ORDER BY create_time DESC")
    List<Warehouse> selectAllEnabled();
}

