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

    <select id="selectEntitiesList" resultType="com.liquidnet.service.kylin.dao.KylinOrderRefundsEntitiesDao">
        SELECT a.enter_name, a.is_payment, b.title, b.use_start, b.price
        FROM kylin_order_ticket_entities AS a
        JOIN kylin_tickets AS b ON a.ticket_id = b.tickets_id
        <where>
            a.order_ticket_entities_id IN
            <foreach collection="orderTicketEntitiesIdS" item="id" index="index" open="(" close=")" separator=",">
                ${id}
            </foreach>
        </where>
    </select>
    <select id="getRefundEntitiesList" resultType="com.liquidnet.service.kylin.dao.KylinOrderTicketEntitiesDao">
        SELECT a.order_ticket_entities_id, a.enter_name, a.status AS is_out, a.is_payment,
        b.title, b.price, b.use_start, b.use_end,
        c.get_ticket_type
        FROM kylin_order_ticket_entities AS a
        JOIN kylin_tickets AS b ON a.ticket_id = b.tickets_id
        JOIN kylin_order_tickets AS c ON c.order_tickets_id = a.order_id
        <where>
            a.order_id = #{orderTicketsId}
            AND a.is_payment != 0
            AND a.is_payment != 3
        </where>
    </select>
    <select id="getRefundEntitiesPrice" resultType="java.math.BigDecimal">
        SELECT SUM(b.refund_price)
        FROM kylin_order_refunds AS a
        JOIN kylin_order_refund_entities AS b ON a.order_refunds_id = b.order_refunds_id
        <where>
            AND a.order_tickets_id = #{orderTicketsId}
            AND a.status != ${orderRefundStatusCancel}
            AND b.order_ticket_entities_id = #{orderTicketEntitiesId}
        </where>
    </select>
    <select id="getRefundOverEntitiesPrice" resultType="java.math.BigDecimal">
        SELECT SUM(b.refund_price)
        FROM kylin_order_refunds AS a
        JOIN kylin_order_refund_entities AS b ON a.order_refunds_id = b.order_refunds_id
        <where>
            AND a.order_tickets_id = #{orderTicketsId}
            AND a.status = ${orderRefundStatus}
            AND b.order_ticket_entities_id = #{entitiesId}
        </where>
    </select>
    <select id="getOvertimeRefundEntitiesList"
            resultType="com.liquidnet.service.kylin.dao.KylinOrderTicketEntitiesDao">
        SELECT a.order_ticket_entities_id, a.enter_name, a.status AS is_out, a.is_payment,
        b.title, b.price, b.use_start, b.use_end,
        c.get_ticket_type
        FROM kylin_order_ticket_entities AS a
        JOIN kylin_tickets AS b ON a.ticket_id = b.tickets_id
        JOIN kylin_order_tickets AS c ON c.order_tickets_id = a.order_id
        <where>
            a.order_id = #{orderTicketsId}
        </where>
    </select>
</mapper>
