package com.fs.course.mapper;

import java.util.List;
import com.fs.course.domain.FsUserCourseOrder;
import com.fs.course.param.FsUserCourseOrderListUParam;
import com.fs.course.param.FsUserCourseOrderParam;
import com.fs.course.vo.FsUserCourseOrderListPVO;
import com.fs.course.vo.FsUserCourseOrderListUVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 课程订单信息Mapper接口
 *
 * @author fs
 * @date 2024-05-21
 */
public interface FsUserCourseOrderMapper
{
    /**
     * 查询课程订单信息
     *
     * @param orderId 课程订单信息主键
     * @return 课程订单信息
     */
    public FsUserCourseOrder selectFsUserCourseOrderByOrderId(Long orderId);

    /**
     * 查询课程订单信息列表
     *
     * @param fsUserCourseOrder 课程订单信息
     * @return 课程订单信息集合
     */
    public List<FsUserCourseOrder> selectFsUserCourseOrderList(FsUserCourseOrder fsUserCourseOrder);

    /**
     * 新增课程订单信息
     *
     * @param fsUserCourseOrder 课程订单信息
     * @return 结果
     */
    public int insertFsUserCourseOrder(FsUserCourseOrder fsUserCourseOrder);

    /**
     * 修改课程订单信息
     *
     * @param fsUserCourseOrder 课程订单信息
     * @return 结果
     */
    public int updateFsUserCourseOrder(FsUserCourseOrder fsUserCourseOrder);

    /**
     * 删除课程订单信息
     *
     * @param orderId 课程订单信息主键
     * @return 结果
     */
    public int deleteFsUserCourseOrderByOrderId(Long orderId);

    /**
     * 批量删除课程订单信息
     *
     * @param orderIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsUserCourseOrderByOrderIds(Long[] orderIds);

    @Select("select * from fs_user_course_order where order_code = #{orderCode}")
    FsUserCourseOrder selectFsUserCourseOrderByOrderCode(String orderCode);

    @Select("select * from fs_user_course_order where user_id = #{userId} and course_video_id = #{videoId} and status = 2 ")
    FsUserCourseOrder selectFsUserCourseOrderByCourseVideo(@Param("userId") Long userId, @Param("videoId") Long videoId);


    @Select("select * from fs_user_course_order where user_id = #{userId} and course_id = #{courseId} and status = 2 and create_type = 1 ")
    FsUserCourseOrder selectFsUserCourseOrderByCourse(@Param("userId") Long userId, @Param("courseId") Long courseId);

    @Select({"<script> " +
            "select o.*,v.title as video_name,u.phone as user_name  from fs_user_course_order o " +
            " left join fs_user_course_video v on v.video_id = o.course_video_id" +
            " left join fs_user u on u.user_id = o.user_id " +
            "where 1=1   " +
            "<if test = ' maps.userId !=null '> " +
            "and o.user_id = #{maps.userId} " +
            "</if>" +
            "<if test = ' maps.orderCode !=null and maps.orderCode!=\"\" '> " +
            "and o.order_code = #{maps.orderCode} " +
            "</if>" +
            "<if test = ' maps.courseName !=null and maps.courseName!=\"\" '> " +
            "and o.course_name = #{maps.courseName} " +
            "</if>" +
            "<if test = ' maps.videoName !=null and maps.videoName!=\"\" '> " +
            "and v.title = #{maps.videoName} " +
            "</if>" +
            "<if test = ' maps.payType !=null '> " +
            "and o.pay_type = #{maps.payType} " +
            "</if>" +
            "<if test = ' maps.createType !=null '> " +
            "and o.create_type = #{maps.createType} " +
            "</if>" +
            "<if test = ' maps.status !=null '> " +
            "and o.status = #{maps.status} " +
            "</if>" +
            " order by o.order_id desc  "+
            "</script>"})
    List<FsUserCourseOrderListPVO> selectFsUserCourseOrderListPVO(@Param("maps") FsUserCourseOrderParam param);

    @Select("select o.*,v.title as video_name,u.phone as user_name  from fs_user_course_order o " +
            " left join fs_user_course_video v on v.video_id = o.course_video_id" +
            " left join fs_user u on u.user_id = o.user_id " +
            "where o.order_id = #{orderId}   " )
    FsUserCourseOrderListPVO selectFsUserCourseOrderVOByOrderId(@Param("orderId") Long orderId);

    @Select({"<script> " +
            "select o.*,v.title as video_name,c.description,c.img_url  from fs_user_course_order o " +
            " left join fs_user_course_video v on v.video_id = o.course_video_id " +
            " left join fs_user_course c on c.course_id = o.course_id " +
            "where 1=1   " +
            "<if test = ' maps.userId !=null '> " +
            "and o.user_id = #{maps.userId} " +
            "</if>" +
            "<if test = ' maps.courseName !=null and maps.courseName!=\"\" '> " +
            "and o.course_name = #{maps.courseName} " +
            "</if>" +
            "<if test = ' maps.status !=null '> " +
            "and o.status = #{maps.status} " +
            "</if>" +
            " order by o.order_id desc  "+
            "</script>"})
    List<FsUserCourseOrderListUVO> selectFsUserCourseOrderListUVO(@Param("maps") FsUserCourseOrderListUParam param);
}
