<?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
               e.tickets_id, e.title, f.title as time_title,
               count(*) as order_num, sum(a.number) as tickets_num
        FROM kylin_order_tickets a
                 INNER JOIN kylin_order_ticket_status s ON s.order_id = a.order_tickets_id
                 INNER JOIN kylin_order_ticket_relations c ON a.order_tickets_id = c.order_id
                 INNER JOIN kylin_tickets e ON c.ticket_id = e.tickets_id
                 INNER JOIN kylin_ticket_times AS f ON f.ticket_times_id = c.time_id
        where a.get_ticket_type = 'express'
          and s.status = 1
          AND c.performance_id = ${performanceId}
        GROUP BY e.tickets_id

        /*SELECT
            a.tickets_id,
            a.title,
            e.title as time_title,
            count(*) as order_num, count(*) as tickets_num
        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>
