<?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="org.jeecg.modules.system.app.mapper.AppSitePlaceMapper">
    <resultMap id="ConcertsVOResult" type="org.jeecg.modules.app.vo.stadium.ConcertsVO">
        <result property="sitePlaceId" column="site_place_id"/>
        <result property="sitePlaceName" column="site_place_name"/>
        <collection property="concertsDetailsVOList" ofType="org.jeecg.modules.app.vo.stadium.ConcertsDetailsVO" javaType="java.util.List">
            <result property="id" column="id" />
            <result property="startTime" column="start_time" />
            <result property="endTime" column="end_time"/>
            <result property="concertStatus" column="concertStatus" />
            <result property="price" column="selling_price" javaType="java.math.BigDecimal"/>
        </collection>
    </resultMap>

    <select id="getPlaceInfoNoFixation" resultType="org.jeecg.modules.app.vo.PlaceInfoVO$PlaceInfoGymMsgVO">
        SELECT
            a.id,
            a.name,
            a.advance_time,
            MIN(b.original_price) AS original_price,
            MAX(b.selling_price) AS selling_price,
            a.cover,
            a.reminder,
            a.refund_type
        FROM
            nm_site_place a
                LEFT JOIN nm_site_price_rules b ON a.id = b.site_place_id
        WHERE
            a.site_id = #{id}
          AND a.type = 2
        GROUP BY
            a.id,
            a.name,
            a.advance_time
        ORDER BY
            selling_price ASC;
    </select>
    <select id="findByConcerts" resultMap="ConcertsVOResult" >
     <![CDATA[   select b.site_place_id,a.name as site_place_name,
        b.id,b.start_time,b.end_time ,b.selling_price,
        CASE
        WHEN c.order_status <=1 THEN 1
        ELSE 0
        END AS concertStatus
        from nm_site_place a
        left join  nm_site_price_rules b on a.id = b.site_place_id
        LEFT JOIN nm_order_pro_info c on c.product_id =b.id
        where a.site_id = #{siteId} and b.category_id =#{categoryId} and b.day_of_week =#{weekDay}
        ]]>
    </select>
    <select id="findBySidAndCid" resultType="org.jeecg.modules.app.vo.stadium.StadiumConcertsResponseVO">
        select early_refund_time,buy_limit from nm_site_place where site_id = #{siteId} and category_id =#{categoryId} limit 1
    </select>
    <select id="previewOrderPlaceGymnasiumNoFixation" resultType="org.jeecg.modules.app.vo.OrderVO$PreviewOrderPlaceGymnasiumNoFixation">
        SELECT
            a.id AS placeId,
            a.NAME AS name,
            g.original_price,
            g.selling_price,
            a.reminder,
            a.indate,
            g.start_time,
            g.end_time,
            a.advance_time,
            a.usable_count,
            a.refund_type
        FROM
            nm_site_place a
                LEFT JOIN nm_site_price_rules g ON a.id = g.site_place_id
                AND g.day_of_week = ( WEEKDAY( NOW()) + 1 )
        WHERE
            a.id = #{placeId}
    </select>
    <select id="findByConcertsAndTime" resultMap="ConcertsVOResult">
        <![CDATA[  select b.site_place_id,a.name as site_place_name,
               b.id,b.start_time,b.end_time ,b.selling_price,
        CASE
        WHEN c.order_status <=1 THEN 1
        WHEN CURRENT_TIME() < TIME(b.end_time) THEN 0
        ELSE 1
        END AS concertStatus
        from nm_site_place a
        left join  nm_site_price_rules b on a.id = b.site_place_id
        LEFT JOIN nm_order_pro_info c on c.product_id =b.id
        where a.site_id = #{siteId} and b.category_id =#{categoryId} and b.day_of_week =#{weekDay}
        ]]>
    </select>
</mapper>