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


    <resultMap id="childPerformanceDaoResult" type="com.liquidnet.service.kylin.dao.ChildPerformanceDao">
        <result column="performances_id" property="performancesId"/>
        <result column="title" property="title"/>
        <result column="time_start" property="timeStart"/>
        <result column="time_end" property="timeEnd"/>
        <result column="can_down_time" property="canDownTime"/>
    </resultMap>

    <!-- 第三方 验票员已配置 演出 -->
    <select id="childPerformanceList" parameterType="java.util.Map" resultMap="childPerformanceDaoResult">
        SELECT
        p.performances_id ,
        p.title ,
        p.time_start ,
        p.time_end,
        cup.can_down_time
        FROM
        kylin_performances AS p
        LEFT JOIN kylin_check_user_performances AS cup ON cup.performance_id = p.performances_id
        LEFT JOIN kylin_performance_relations AS pr ON pr.performance_id = p.performances_id
        <where>
            pr.merchant_id = #{merchantId} AND cup.check_user_id = #{checkUserId}
            <if test="name!=''">
                AND title LIKE concat('%', #{name}, '%')
            </if>
        </where>
    </select>

    <!-- 第三方 验票员未配置 演出 -->
    <select id="unChildPerformanceList" parameterType="java.util.Map" resultMap="childPerformanceDaoResult">
        SELECT p.performances_id,
               p.title,
               p.time_start,
               p.time_end
        FROM kylin_performances AS p
                 LEFT JOIN kylin_performance_relations AS pr ON pr.performance_id = p.performances_id
        WHERE p.performances_id NOT IN (
            SELECT performance_id
            FROM kylin_check_user_performances
            WHERE check_user_id = #{checkUserId}
        )
          AND pr.merchant_id = #{merchantId}
        <if test="name!=''">
            AND title LIKE concat('%', #{name}, '%')
        </if>
    </select>
</mapper>
