<?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.tourism.common.mobile.dao.MobileEntryMapper">
    <resultMap id="BaseResultMap" type="com.tourism.common.mobile.model.MobileEntry">
        <id column="entry_id" jdbcType="BIGINT" property="entryId"/>
        <result column="tenant_admin_entry_id" jdbcType="BIGINT" property="tenantAdminEntryId"/>
        <result column="tenant_id" jdbcType="BIGINT" property="tenantId"/>
        <result column="parent_id" jdbcType="BIGINT" property="parentId"/>
        <result column="entry_name" jdbcType="VARCHAR" property="entryName"/>
        <result column="entry_type" jdbcType="INTEGER" property="entryType"/>
        <result column="common_entry" jdbcType="BOOLEAN" property="commonEntry"/>
        <result column="extra_data" jdbcType="LONGVARCHAR" property="extraData"/>
        <result column="image_data" jdbcType="VARCHAR" property="imageData"/>
        <result column="show_order" jdbcType="INTEGER" property="showOrder"/>
        <result column="tenant_available" jdbcType="BOOLEAN" property="tenantAvailable"/>
        <result column="tenant_custom" jdbcType="BOOLEAN" property="tenantCustom"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
    </resultMap>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="filterRef">
        <if test="mobileEntryFilter != null">
            <if test="mobileEntryFilter.tenantId == null">
                AND zz_mobile_entry.tenant_id IS NULL
            </if>
            <if test="mobileEntryFilter.tenantId != null">
                AND zz_mobile_entry.tenant_id = #{mobileEntryFilter.tenantId}
            </if>
            <if test="mobileEntryFilter.entryType != null">
                AND zz_mobile_entry.entry_type = #{mobileEntryFilter.entryType}
            </if>
            <if test="mobileEntryFilter.commonEntry != null">
                AND zz_mobile_entry.common_entry = #{mobileEntryFilter.commonEntry}
            </if>
        </if>
        AND zz_mobile_entry.tenant_available = 1
    </sql>

    <select id="getMobileEntryList" resultMap="BaseResultMap" parameterType="com.tourism.common.mobile.model.MobileEntry">
        SELECT * FROM zz_mobile_entry
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>

    <select id="getMobileEntryListByRoleIds" resultMap="BaseResultMap">
        SELECT
            m.*
        FROM
            zz_mobile_entry_role mr,
            zz_mobile_entry m
        WHERE
            mr.role_id IN
            <foreach collection="roleIds" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
            AND mr.entry_id = m.entry_id
            AND m.tenant_available = 1
    </select>

    <select id="getCommonMobileEntryList" resultMap="BaseResultMap" parameterType="com.tourism.common.mobile.model.MobileEntry">
        SELECT * FROM zz_mobile_entry
        WHERE (common_entry = 1 OR entry_type = 2)
        <if test="tenantId == null">
            AND tenant_id IS NULL
        </if>
        <if test="tenantId != null">
            AND tenant_id = #{tenantId}
        </if>
    </select>
</mapper>
