<?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.webadmin.back.dao.RestaurantInfoMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.RestaurantInfo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="tag" jdbcType="VARCHAR" property="tag"/>
        <result column="type_id" jdbcType="VARCHAR" property="typeId"/>
        <result column="announcement" jdbcType="VARCHAR" property="announcement"/>
        <result column="work_time" jdbcType="VARCHAR" property="workTime"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="enable" jdbcType="TINYINT" property="enable"/>
        <result column="url" jdbcType="VARCHAR" property="url"/>
        <result column="environment_image" jdbcType="VARCHAR" property="environmentImage"/>
        <result column="contact_information" jdbcType="VARCHAR" property="contactInformation"/>
        <result column="longitude" jdbcType="DECIMAL" property="longitude"/>
        <result column="latitude" jdbcType="DECIMAL" property="latitude"/>
        <result column="total_sales" jdbcType="BIGINT" property="totalSales"/>
        <result column="contry" jdbcType="VARCHAR" property="contry"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="city" jdbcType="VARCHAR" property="city"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <result column="dept_id" jdbcType="BIGINT" property="deptId"/>
        <result column="delivery_charge" jdbcType="DECIMAL" property="deliveryCharge"/>
        <result column="min_charge" jdbcType="DECIMAL" property="minCharge"/>
        <result column="is_select_shop" jdbcType="TINYINT" property="isSelectShop"/>
        <result column="is_recommended_shop" jdbcType="TINYINT" property="isRecommendedShop"/>
        <result column="is_delicious_shop" jdbcType="TINYINT" property="isDeliciousShop"/>
        <result column="is_best_new_shop" jdbcType="TINYINT" property="isBestNewShop"/>
        <result column="restaurant_banner" jdbcType="VARCHAR" property="restaurantBanner"/>
        <result column="recommendation_rate" jdbcType="BIGINT" property="recommendationRate"/>
        <result column="delivery_time" jdbcType="INTEGER" property="deliveryTime"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_restaurant_info
            (id,
            name,
            tag,
            type_id,
            announcement,
            work_time,
            address,
            enable,
            url,
            environment_image,
            contact_information,
            longitude,
            latitude,
            total_sales,
            contry,
            create_user_id,
            city,
            create_time,
            update_user_id,
            update_time,
            data_state,
            dept_id,
            delivery_charge,
            min_charge,
            is_select_shop,
            is_recommended_shop,
            is_delicious_shop,
            is_best_new_shop,
        restaurant_banner,
        recommendation_rate,
        delivery_time)

        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.name},
            #{item.tag},
            #{item.typeId},
            #{item.announcement},
            #{item.workTime},
            #{item.address},
            #{item.enable},
            #{item.url},
            #{item.environmentImage},
            #{item.contactInformation},
            #{item.longitude},
            #{item.latitude},
            #{item.totalSales},
            #{item.contry},
            #{item.createUserId},
            #{item.city},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState},
            #{item.deptId},
            #{item.deliveryCharge},
            #{item.minCharge},
            #{item.isSelectShop},
            #{item.isRecommendedShop},
            #{item.isDeliciousShop},
            #{item.isBestNewShop},
            #{item.restaurantBanner},
            #{item.recommendationRate},
            #{item.deliveryTime})

        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.RestaurantInfoMapper.inputFilterRef"/>
        AND tour_restaurant_info.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="restaurantInfoFilter != null">
            <if test="restaurantInfoFilter.name != null and restaurantInfoFilter.name != ''">
                <bind name = "safeRestaurantInfoName" value = "'%' + restaurantInfoFilter.name + '%'" />
                AND tour_restaurant_info.name LIKE #{safeRestaurantInfoName}
            </if>
            <if test="restaurantInfoFilter.id != null">
                AND tour_restaurant_info.id = #{restaurantInfoFilter.id}
            </if>
            <if test="restaurantInfoFilter.enable != null">
                AND tour_restaurant_info.enable = #{restaurantInfoFilter.enable}
            </if>
            <if test="restaurantInfoFilter.contactInformation != null and restaurantInfoFilter.contactInformation != ''">
                <bind name = "safeRestaurantInfoContactInformation" value = "'%' + restaurantInfoFilter.contactInformation + '%'" />
                AND tour_restaurant_info.contact_information LIKE #{safeRestaurantInfoContactInformation}
            </if>
            <if test="restaurantInfoFilter.contry != null and restaurantInfoFilter.contry != ''">
                AND tour_restaurant_info.contry = #{restaurantInfoFilter.contry}
            </if>
            <if test="restaurantInfoFilter.city != null and restaurantInfoFilter.city != ''">
                AND tour_restaurant_info.city = #{restaurantInfoFilter.city}
            </if>
            <if test="restaurantInfoFilter.searchString != null and restaurantInfoFilter.searchString != ''">
                <bind name = "safeRestaurantInfoSearchString" value = "'%' + restaurantInfoFilter.searchString + '%'" />
                AND IFNULL(tour_restaurant_info.name,'') LIKE #{safeRestaurantInfoSearchString}
            </if>
            <if test="restaurantInfoFilter.typeId != null and restaurantInfoFilter.typeId != ''">
                AND FIND_IN_SET(#{restaurantInfoFilter.typeId},tour_restaurant_info.type_id) > 0
            </if>
            <if test="restaurantInfoFilter.isSelectShop != null">
                AND tour_restaurant_info.is_select_shop = #{restaurantInfoFilter.isSelectShop}
            </if>
            <if test="restaurantInfoFilter.isRecommendedShop != null">
                AND tour_restaurant_info.is_recommended_shop = #{restaurantInfoFilter.isRecommendedShop}
            </if>
            <if test="restaurantInfoFilter.isDeliciousShop != null">
                AND tour_restaurant_info.is_delicious_shop = #{restaurantInfoFilter.isDeliciousShop}
            </if>
            <if test="restaurantInfoFilter.isBestNewShop != null">
                AND tour_restaurant_info.is_best_new_shop = #{restaurantInfoFilter.isBestNewShop}
            </if>
            <if test="restaurantInfoFilter.restaurantIdList != null and restaurantInfoFilter.restaurantIdList.size() > 0">
                AND tour_restaurant_info.restaurant_id IN
                <foreach item="id" index="index" collection="restaurantInfoFilter.restaurantIdList" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </if>
    </sql>
    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRefWhere">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.RestaurantInfoMapper.inputFilterRef"/>
        AND tri.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRefWhere">
        <if test="restaurantInfoFilter != null">
            <if test="restaurantInfoFilter.name != null and restaurantInfoFilter.name != ''">
                <bind name = "safeRestaurantInfoName" value = "'%' + restaurantInfoFilter.name + '%'" />
               and trfi.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
                and (trfi.name like concat('%',#{restaurantInfoFilter.foodName},'%')    or tri.name LIKE #{safeRestaurantInfoName})
            </if>
            <if test="restaurantInfoFilter.id != null">
                AND tri.id = #{restaurantInfoFilter.id}
            </if>
            <if test="restaurantInfoFilter.enable != null">
                AND tri.enable = #{restaurantInfoFilter.enable}
            </if>
            <if test="restaurantInfoFilter.contactInformation != null and restaurantInfoFilter.contactInformation != ''">
                <bind name = "safeRestaurantInfoContactInformation" value = "'%' + restaurantInfoFilter.contactInformation + '%'" />
                AND tri.contact_information LIKE #{safeRestaurantInfoContactInformation}
            </if>
            <if test="restaurantInfoFilter.contry != null and restaurantInfoFilter.contry != ''">
                AND tri.contry = #{restaurantInfoFilter.contry}
            </if>
            <if test="restaurantInfoFilter.city != null and restaurantInfoFilter.city != ''">
                AND tri.city = #{restaurantInfoFilter.city}
            </if>
            <if test="restaurantInfoFilter.searchString != null and restaurantInfoFilter.searchString != ''">
                <bind name = "safeRestaurantInfoSearchString" value = "'%' + restaurantInfoFilter.searchString + '%'" />
                AND IFNULL(tri.name,'') LIKE #{safeRestaurantInfoSearchString}
            </if>
            <if test="restaurantInfoFilter.typeId != null and restaurantInfoFilter.typeId != ''">
                AND FIND_IN_SET(#{restaurantInfoFilter.typeId},tri.type_id) > 0
            </if>
            <if test="restaurantInfoFilter.isSelectShop != null">
                AND tri.is_select_shop = #{restaurantInfoFilter.isSelectShop}
            </if>
            <if test="restaurantInfoFilter.isRecommendedShop != null">
                AND tri.is_recommended_shop = #{restaurantInfoFilter.isRecommendedShop}
            </if>
            <if test="restaurantInfoFilter.isDeliciousShop != null">
                AND tri.is_delicious_shop = #{restaurantInfoFilter.isDeliciousShop}
            </if>
            <if test="restaurantInfoFilter.isBestNewShop != null">
                AND tri.is_best_new_shop = #{restaurantInfoFilter.isBestNewShop}
            </if>
            <if test="restaurantInfoFilter.restaurantIdList != null and restaurantInfoFilter.restaurantIdList.size() > 0">
                AND tri.restaurant_id IN
                <foreach item="id" index="index" collection="restaurantInfoFilter.restaurantIdList" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </if>
    </sql>
    <select id="getRestaurantInfoList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.RestaurantInfo">
        SELECT * FROM tour_restaurant_info
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
    <select id="getRestaurantInfoListByShopName" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.RestaurantInfo">
        SELECT tri.* FROM tour_restaurant_info tri join tour_restaurant_food_info trfi on tri.id = trfi.restaurant_id
        <where>
            1 = 1
            AND tri.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
            <if test="restaurantInfoFilter != null">
                <if test="restaurantInfoFilter.name != null and restaurantInfoFilter.name != ''">
                    <bind name = "safeRestaurantInfoName" value = "'%' + restaurantInfoFilter.name + '%'" />
                    and trfi.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
                   and  (tri.name LIKE #{safeRestaurantInfoName}
                    <if test="restaurantInfoFilter.foodName == null and restaurantInfoFilter.foodName == ''">
                        )
                    </if>


                    <if test="restaurantInfoFilter.foodName != null and restaurantInfoFilter.foodName != ''">
                        or trfi.name like concat('%',#{restaurantInfoFilter.foodName},'%')   )
                    </if>

                </if>
                <if test="restaurantInfoFilter.id != null">
                    AND tri.id = #{restaurantInfoFilter.id}
                </if>
                <if test="restaurantInfoFilter.enable != null">
                    AND tri.enable = #{restaurantInfoFilter.enable}
                </if>
                <if test="restaurantInfoFilter.contactInformation != null and restaurantInfoFilter.contactInformation != ''">
                    <bind name = "safeRestaurantInfoContactInformation" value = "'%' + restaurantInfoFilter.contactInformation + '%'" />
                    AND tri.contact_information LIKE #{safeRestaurantInfoContactInformation}
                </if>
                <if test="restaurantInfoFilter.contry != null and restaurantInfoFilter.contry != ''">
                    AND tri.contry = #{restaurantInfoFilter.contry}
                </if>
                <if test="restaurantInfoFilter.city != null and restaurantInfoFilter.city != ''">
                    AND tri.city = #{restaurantInfoFilter.city}
                </if>
                <if test="restaurantInfoFilter.searchString != null and restaurantInfoFilter.searchString != ''">
                    <bind name = "safeRestaurantInfoSearchString" value = "'%' + restaurantInfoFilter.searchString + '%'" />
                    AND IFNULL(tri.name,'') LIKE #{safeRestaurantInfoSearchString}
                </if>
                <if test="restaurantInfoFilter.typeId != null and restaurantInfoFilter.typeId != ''">
                    AND FIND_IN_SET(#{restaurantInfoFilter.typeId},tri.type_id) > 0
                </if>
                <if test="restaurantInfoFilter.isSelectShop != null">
                    AND tri.is_select_shop = #{restaurantInfoFilter.isSelectShop}
                </if>
                <if test="restaurantInfoFilter.isRecommendedShop != null">
                    AND tri.is_recommended_shop = #{restaurantInfoFilter.isRecommendedShop}
                </if>
                <if test="restaurantInfoFilter.isDeliciousShop != null">
                    AND tri.is_delicious_shop = #{restaurantInfoFilter.isDeliciousShop}
                </if>
                <if test="restaurantInfoFilter.isBestNewShop != null">
                    AND tri.is_best_new_shop = #{restaurantInfoFilter.isBestNewShop}
                </if>
                <if test="restaurantInfoFilter.restaurantIdList != null and restaurantInfoFilter.restaurantIdList.size() > 0">
                    AND tri.restaurant_id IN
                    <foreach item="id" index="index" collection="restaurantInfoFilter.restaurantIdList" open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
            </if>

        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>




</mapper>
