<?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="com.yida.data.school.secondClass.mapper.EduSecondClassVenueOrderMapper">
  <resultMap id="voMap" type="com.yida.data.school.vo.secondClass.VenueOrderVO">
    <result property="id" column="id"/>
    <result property="createDate" column="create_date"/>
    <result property="date" column="date"/>
    <result property="startTime" column="start_time"/>
    <result property="endTime" column="end_time"/>
    <result property="status" column="status"/>
    <association property="guide" javaType="com.yida.data.school.vo.secondClass.VenueGuideVO">
      <result property="id" column="gId"/>
      <result property="name" column="gName"/>
      <result property="avatar" column="gAvatar"/>
    </association>
    <collection property="memberList" ofType="com.yida.data.school.vo.secondClass.VenueOrdermemberVO">
      <result property="name" column="mName"/>
      <result property="mobile" column="mMobile"/>
      <result property="idCard" column="mIdCard"/>
    </collection>
  </resultMap>

  <select id="listVenueOrder" resultMap="voMap">
    select a.id,
           a.create_date,
           a.date,
           a.start_time,
           a.end_time,
           a.status,
           b.name    mName,
           b.mobile  mMobile,
           b.id_card mIdCard,
           c.name    gName,
           c.avatar  gAvatar,
           c.id      gId
    from edu_second_class_venue_order a
           left join edu_second_class_venue_order_member b on a.id = b.order_id
           left join edu_second_class_venue_guide c on a.guide_id = c.id
    where a.del_flag = 0
    <if test="venueId != null">
      and a.venue_id = #{venueId}
    </if>
    <if test="userId != null and userId != ''">
      and a.user_id=#{userId}
    </if>
    order by a.create_date desc, a.date desc, a.start_time desc
  </select>
</mapper>
