<?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.TrainMapper">

    <select id="queryListPage" resultType="cn.iocoder.yudao.module.train.vo.TrainVO">
        SELECT
        dsrc.*
        FROM
        drive_school_reservation_course dsrc
        where
            dsrc.deleted = 0
            <if test="entity.userId != null and entity.userId != ''">
                and dsrc.user_id =#{entity.userId}
            </if>
            <if test="entity.coachId != null and entity.coachId != ''">
                and dsrc.coach_id =#{entity.coachId}
            </if>
            <if test="entity.courseId != null and entity.courseId != ''">
                and dsrc.course_id =#{entity.courseId}
            </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>
            <if test="entity.reservDay != null and entity.reservDay != ''">
                and dsrc.reserv_day LIKE CONCAT(#{entity.reservDay},'%')
            </if>
        order by dsrc.create_time desc
    </select>
    <select id="selectTrainByCondition" resultType="cn.iocoder.yudao.module.train.vo.TrainVO">
        SELECT
            dst.*,
            dsc.car_id
        FROM
            drive_school_train dst
                LEFT JOIN drive_school_coach dsc ON dst.coach_id = dsc.user_id
        WHERE
            dst.deleted = 0
            <if test="coachId != null and coachId != ''">
              AND dst.coach_id = #{coachId}
            </if>
            <if test="startTime!=null and startTime!=''">
                AND dst.create_time &gt;= #{startTime}
            </if>
            <if test="endTime!=null and endTime!=''">
                AND dst.create_time &lt;= #{endTime}
            </if>
    </select>
    <select id="queryTrainListPage" resultType="cn.iocoder.yudao.module.train.vo.TrainVO">
        SELECT
        dst.*, dsc.type as courseType
        FROM
        drive_school_train dst
        LEFT JOIN drive_school_course dsc ON dst.course_id = dsc.id
        where
        dst.deleted = 0
        <if test="entity.userId != null and entity.userId != ''">
            and dst.user_id =#{entity.userId}
        </if>
        <if test="entity.coachId != null and entity.coachId != ''">
            and dst.coach_id =#{entity.coachId}
        </if>
        <if test="entity.courseId != null and entity.courseId != ''">
            and dst.course_id =#{entity.courseId}
        </if>
        <if test="entity.isEnd != null and entity.isEnd != ''">
            and dst.end_time IS NOT NULL
        </if>
        order by dst.create_time desc
    </select>
    <select id="listJoinBatchByIds" resultType="cn.iocoder.yudao.module.train.vo.TrainVO">
        SELECT
        dst.*, dsc.type as courseType
        FROM
        drive_school_train dst
        LEFT JOIN drive_school_course dsc ON dst.course_id = dsc.id
        where
            dst.deleted = 0
            and dst.id in
            <foreach collection="trainIds" item="trainId" open="(" separator="," close=")">
                #{trainId}
            </foreach>
    </select>
</mapper>
