package com.fs.course.mapper;

import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fs.course.domain.FsCourseProductOrder;
import com.fs.course.param.FsCourseProductOrderListParam;
import com.fs.course.param.FsCourseProductOrderListUParam;
import com.fs.course.vo.FsCourseProductOrderListUVO;
import com.fs.course.vo.FsCourseProductOrderVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 拍单商品订单Mapper接口
 * 
 * @author fs
 * @date 2025-07-28
 */
public interface FsCourseProductOrderMapper extends BaseMapper<FsCourseProductOrder>{
    /**
     * 查询拍单商品订单
     * 
     * @param courseOrderId 拍单商品订单主键
     * @return 拍单商品订单
     */
    FsCourseProductOrder selectFsCourseProductOrderByCourseOrderId(Long courseOrderId);

    /**
     * 查询拍单商品订单列表
     * 
     * @param param 拍单商品订单
     * @return 拍单商品订单集合
     */
    List<FsCourseProductOrderVO> selectFsCourseProductOrderList(FsCourseProductOrderListParam param);

    /**
     * 新增拍单商品订单
     * 
     * @param fsCourseProductOrder 拍单商品订单
     * @return 结果
     */
    int insertFsCourseProductOrder(FsCourseProductOrder fsCourseProductOrder);

    /**
     * 修改拍单商品订单
     * 
     * @param fsCourseProductOrder 拍单商品订单
     * @return 结果
     */
    int updateFsCourseProductOrder(FsCourseProductOrder fsCourseProductOrder);

    /**
     * 删除拍单商品订单
     * 
     * @param courseOrderId 拍单商品订单主键
     * @return 结果
     */
    int deleteFsCourseProductOrderByCourseOrderId(Long courseOrderId);

    /**
     * 批量删除拍单商品订单
     * 
     * @param courseOrderIds 需要删除的数据主键集合
     * @return 结果
     */
    int deleteFsCourseProductOrderByCourseOrderIds(Long[] courseOrderIds);

    @Select({"<script>" +
            "SELECT cpo.*,cp.product_name,cp.img_url FROM fs_course_product_order cpo" +
            "LEFT JOIN fs_course_product cp ON cp.id =  cpo.course_product_id" +
            "WHERE 1=1" +
            "<if test='maps.status != null'> AND cpo.status = #{maps.status}</if>" +
            "<if test='maps.userId != null'> AND cpo.user_id = #{maps.userId}</if>" +
            "ORDER BY cpo.course_order_id" +
            "</script>"})
    List<FsCourseProductOrderListUVO> selectFsCourseProductOrderListUVO(@Param("maps") FsCourseProductOrderListUParam param);

    @Select({"SELECT * FROM fs_course_product_order where order_code = #{orderCode}"})
    FsCourseProductOrder selectFsCourseProductOrderByOrderCode(String orderCode);

}
