<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.train.mapper.ReservationCourseMapper">

    <select id="queryListPage" resultType="cn.iocoder.yudao.module.train.vo.ReservationCourseVO">
        SELECT
        dsrc.*,dsp.train_time,dss.name AS userName,dss.phone AS userMobile,dss.sex AS userSex,dsc.type as courseType,
        CASE dsrc.status
        WHEN 0 THEN '已拒绝'
        WHEN 1 THEN '已审核'
        ELSE '待审核'
        END AS statusStr,
        CASE dsrc.subject
        WHEN 1 THEN '科目一'
        WHEN 2 THEN '科目二'
        WHEN 3 THEN '科目三'
        WHEN 4 THEN '科目四'
        ELSE '未知'
        END AS subjectStr
        FROM
        drive_school_reservation_course dsrc
        LEFT JOIN drive_school_process dsp ON dsrc.user_id = dsp.user_id
        AND dsrc.course_id = dsp.course_id
        AND dsrc.coach_id = dsp.coach_id
        AND dsrc.`subject` = dsp.`subject`
        AND dsp.`status`='1'
        LEFT JOIN drive_school_student dss ON dsrc.user_id = dss.user_id
        LEFT JOIN drive_school_course dsc ON dsrc.course_id = dsc.id
        where
            dsrc.deleted = 0
            <if test="entity.userId != null and entity.userId != ''">
                and dsrc.user_id =#{entity.userId}
            </if>
            <if test="entity.userName != null and entity.userName != ''">
                and dsrc.user_name LIKE (CONCAT('%',#{entity.userName},'%'))
            </if>
            <if test="entity.coachId != null and entity.coachId != ''">
                and dsrc.coach_id =#{entity.coachId}
            </if>
            <if test="entity.coachName != null and entity.coachName != ''">
                and dsrc.coach_name LIKE (CONCAT('%',#{entity.coachName},'%'))
            </if>
            <if test="entity.courseId != null and entity.courseId != ''">
                and dsrc.course_id =#{entity.courseId}
            </if>
            <if test="entity.reservDay != null and entity.reservDay != ''">
                and dsrc.reserv_day =#{entity.reservDay}
            </if>
            <if test="entity.subject != null and entity.subject != ''">
                and dsrc.subject =#{entity.subject}
            </if>
            <if test="entity.ifCancel != null">
                and dsrc.if_cancel =#{entity.ifCancel}
            </if>
        order by dsrc.create_time desc,dsp.create_time desc
    </select>
</mapper>
