package com.haha.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.haha.entity.ReplenishmentOrderItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 补货单明细Mapper
 */
@Mapper
public interface ReplenishmentOrderItemMapper extends BaseMapper<ReplenishmentOrderItem> {

    /**
     * 根据补货单ID查询明细列表
     */
    @Select("SELECT * FROM t_replenishment_order_item WHERE order_id = #{orderId}")
    List<ReplenishmentOrderItem> selectByOrderId(@Param("orderId") Long orderId);

    /**
     * 根据补货单ID删除明细
     */
    @Select("DELETE FROM t_replenishment_order_item WHERE order_id = #{orderId}")
    void deleteByOrderId(@Param("orderId") Long orderId);

    /**
     * 批量插入明细
     */
    @Insert("<script>" +
            "INSERT INTO t_replenishment_order_item (order_id, device_id, product_id, product_code, product_name, " +
            "planned_quantity, unit_price, total_price, shelf_num, position, create_time) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.orderId}, #{item.deviceId}, #{item.productId}, #{item.productCode}, #{item.productName}, " +
            "#{item.plannedQuantity}, #{item.unitPrice}, #{item.totalPrice}, #{item.shelfNum}, #{item.position}, #{item.createTime})" +
            "</foreach>" +
            "</script>")
    int insertBatch(@Param("list") List<ReplenishmentOrderItem> items);
}
