package com.fs.live.mapper;

import java.util.List;
import java.util.Map;

import com.fs.live.domain.LiveOrderItem;
import com.fs.live.vo.LiveOrderItemListUVO;
import com.fs.live.vo.LiveOrderItemVo;
import org.apache.ibatis.annotations.*;

/**
 * 订单详情Mapper接口
 *
 * @author fs
 * @date 2025-07-08
 */
public interface LiveOrderItemMapper {
    /**
     * 查询订单详情
     *
     * @param itemId 订单详情主键
     * @return 订单详情
     */
    LiveOrderItem selectLiveOrderItemByItemId(String itemId);

    /**
     * 查询订单详情列表
     *
     * @param liveOrderItem 订单详情
     * @return 订单详情集合
     */
    List<LiveOrderItem> selectLiveOrderItemList(LiveOrderItem liveOrderItem);

    /**
     * 新增订单详情
     *
     * @param liveOrderItem 订单详情
     * @return 结果
     */
    int insertLiveOrderItem(LiveOrderItem liveOrderItem);

    /**
     * 修改订单详情
     *
     * @param liveOrderItem 订单详情
     * @return 结果
     */
    int updateLiveOrderItem(LiveOrderItem liveOrderItem);

    /**
     * 删除订单详情
     *
     * @param itemId 订单详情主键
     * @return 结果
     */
    int deleteLiveOrderItemByItemId(String itemId);

    /**
     * 批量删除订单详情
     *
     * @param itemIds 需要删除的数据主键集合
     * @return 结果
     */
    int deleteLiveOrderItemByItemIds(String[] itemIds);

    @Select("select loi.*,fsp.bar_code from live_order_item loi left join fs_store_product fsp on loi.product_id =fsp.product_id   where loi.order_id = #{orderId}")
    List<LiveOrderItem> selectLiveOrderItemByOrderId(Long orderId);

    @MapKey("orderId")
    @Select("<script>" +
            "select a.item_id, a.order_id as orderId, a.order_code, a.cart_id, a.goods_id, a.product_id, a.product_attr_value_id, a.json_info, a.num, a.is_after_sales, a.is_prescribe, a.store_id, a.is_gift\n" +
            ", b.product_name, b.image as img_url, b.price, b.ot_price, b.sales, b.product_info as product_introduce\n" +
            "from live_order_item a\n" +
            "left join fs_store_product b on a.product_id = b.product_id\n" +
            "where order_id in\n" +
            "<foreach item='id' collection='orderIds' open='(' separator=',' close=')'> " +
            " #{id} " +
            "</foreach>" +
            "</script>")
    @ResultMap("liveOrderItemVoMap")
    List<LiveOrderItemVo> selectLiveOrderItemByOrderIds(@Param("orderIds") List<Long> orderIds);

    int insertBatchList(@Param("liveOrderItemList") List<LiveOrderItem> liveOrderItemList);


    List<LiveOrderItemVo> selectCheckedByUserId(@Param("userId") String userId);

    @Select("select product_id,json_info,order_code,item_id,num from live_order_item where order_id=#{orderId}")
    List<LiveOrderItemListUVO> selectLiveOrderItemListUVOByOrderId(Long orderId);

    @Update("update live_order_item set order_code=#{orderCode} where order_id=#{orderId} ")
    int updateFsStoreOrderCode(@Param("orderId")Long orderId,@Param("orderCode") String orderSn);

    @Select("select * from live_order_item where order_id= #{orderId}")
    List<LiveOrderItem> selectCheckedByOrderId(@Param("orderId") Long orderId);
}
