<?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.AppSiteMapper">
    <select id="getPlaceList" resultType="org.jeecg.modules.app.vo.PlaceVO">
        SELECT
        b.id,
        b.name AS name,
        b.good_rate AS goodRate,
        b.address,
        b.category_id,
        b.latitude,
        b.longitude,
        b.cover,
        b.type
        FROM
        nm_site b
        LEFT JOIN sys_depart c ON b.org_code = c.org_code
        WHERE 1 = 1 AND b.del_flag = 0
        <if test="venueType != null and venueType == '0-1'">
            ORDER BY b.good_rate DESC
        </if>
        <if test="venueType != null and venueType == '1-1'">
            AND c.org_category = 20
        </if>
        <if test="venueType != null and venueType == '1-2'">
            AND c.org_category = 20 ORDER BY  b.good_rate DESC
        </if>
        <if test="venueType != null and venueType == '2-1'">
            AND c.org_category = 21
        </if>
        <if test="venueType != null and venueType == '2-2'">
            AND c.org_category = 21 ORDER BY  b.good_rate DESC
        </if>
    </select>

    <select id="convertSearchPlaceVOPage" resultType="org.jeecg.modules.app.vo.SearchVO$SearchPlaceVO" parameterType="org.jeecg.modules.app.dto.SearchDTO">
        SELECT
        a.id,
        a.name,
        a.good_rate AS goodRate,
        a.address,
        a.cover,
        a.category_id,
        a.type,
        CASE
        WHEN EXISTS (
        SELECT 1
        FROM nm_site_price_rules e
        WHERE e.org_code = a.org_code AND e.inventory > 0
        ) THEN 1
        ELSE 0
        END AS ticketWhether
        FROM nm_site a
        LEFT JOIN sys_depart b ON a.tenant_id = b.id
        WHERE EXISTS (
        SELECT 1
        FROM nm_site_price_rules e
        WHERE e.org_code = a.org_code
        ) AND 1=1
        <if test="searchDTO.keyword != null and searchDTO.keyword != ''">
            AND (a.name LIKE CONCAT('%',#{searchDTO.keyword},'%') OR a.address LIKE CONCAT('%',#{searchDTO.keyword},'%'))
        </if>
        <if test="searchDTO.venueType != null and searchDTO.venueType == '0-2'">
            ORDER BY  a.good_rate DESC
        </if>
    </select>
    <select id="getPlaceInfo" resultType="org.jeecg.modules.app.vo.PlaceInfoVO">
        SELECT
            a.id,
            a.name AS name,
            a.good_rate,
            a.cover,
            a.address,
            a.type,
            a.facility,
            a.run_status AS runStatus,
            a.teaching_day,
            a.no_teaching_day,
            b.mobile AS phone,
            a.video,
            a.longitude,
            a.latitude,
            a.vr
        FROM
            nm_site a
                LEFT JOIN sys_depart b ON a.tenant_id = b.id
        WHERE a.del_flag = 0 AND a.status = 0 AND a.id = #{id}
    </select>
</mapper>