package com.erp.warehouse.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.erp.warehouse.entity.InboundOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 入库单Mapper
 */
@Mapper
public interface InboundOrderMapper extends BaseMapper<InboundOrder> {

    @Select("SELECT io.*, w.name as warehouse_name " +
            "FROM inbound_order io " +
            "LEFT JOIN warehouse w ON io.warehouse_id = w.id " +
            "WHERE (#{inboundType} IS NULL OR io.inbound_type = #{inboundType}) " +
            "AND (#{warehouseId} IS NULL OR io.warehouse_id = #{warehouseId}) " +
            "AND (#{status} IS NULL OR io.status = #{status}) " +
            "ORDER BY io.create_time DESC")
    IPage<InboundOrder> selectPageList(Page<InboundOrder> page,
                                        @Param("inboundType") String inboundType,
                                        @Param("warehouseId") Long warehouseId,
                                        @Param("status") String status);

    @Select("SELECT * FROM inbound_order WHERE inbound_no = #{inboundNo} LIMIT 1")
    InboundOrder findByInboundNo(@Param("inboundNo") String inboundNo);
}
