<?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.liquidnet.service.kylin.mapper.KylinTicketsMapper">

    <resultMap id="ticketAgentResult" type="com.liquidnet.service.kylin.dao.TicketAgentDao">
        <result column="tickets_id" property="ticketsId"/>
        <result column="title" property="title"/>
        <result column="is_agent" property="isAgent"/>
    </resultMap>

    <resultMap id="ticketDamaiResult" type="com.liquidnet.service.kylin.dao.TicketDamaiDao">
        <result column="tickets_id" property="ticketsId"/>
        <result column="title" property="title"/>
        <result column="is_agent" property="isAgent"/>
    </resultMap>


    <!-- 票分销情况-->
    <select id="ticketAgent" parameterType="java.lang.String" resultMap="ticketAgentResult">
        SELECT
            tickets_id ,
            concat(title,' - ',use_start)  as 'title',
            ts.is_agent
        FROM
            kylin_ticket_status AS ts
                LEFT JOIN kylin_ticket_relations AS tr ON tr.ticket_id = ts.ticket_id
                LEFT JOIN kylin_ticket_time_relation AS ttr ON tr.times_id = ttr.times_id
                LEFT JOIN kylin_tickets AS t ON t.tickets_id = ts.ticket_id
        where performance_id = ${performanceIds}
    </select>

    <!-- 票大麦情况-->
    <select id="ticketDamai" parameterType="java.lang.String" resultMap="ticketDamaiResult">
        SELECT
            tickets_id ,
            concat(title,' - ',use_start)  as 'title',
            ts.sync_damai
        FROM
            kylin_ticket_status AS ts
                LEFT JOIN kylin_ticket_relations AS tr ON tr.ticket_id = ts.ticket_id
                LEFT JOIN kylin_ticket_time_relation AS ttr ON tr.times_id = ttr.times_id
                LEFT JOIN kylin_tickets AS t ON t.tickets_id = ts.ticket_id
        where performance_id = ${performanceIds}
    </select>
    <select id="getPerformancesTicketList" resultType="com.liquidnet.service.kylin.dao.PerformancesTicketListDao">
        SELECT
            a.tickets_id ,
            a.title,
            e.title as time_title
        FROM
            kylin_tickets AS a
                LEFT JOIN kylin_ticket_status AS b ON b.ticket_id = a.tickets_id
                LEFT JOIN kylin_ticket_relations AS c ON c.ticket_id = a.tickets_id
                LEFT JOIN kylin_ticket_time_relation AS d ON d.times_id = c.times_id
                LEFT JOIN kylin_ticket_times AS e ON e.ticket_times_id = d.times_id
        where d.performance_id = ${performanceId}
        and b.is_express = 1
        and b.status IN (2, 3, 6, 7, 8, 9, 10)
    </select>
</mapper>
