<?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.RestaurantFoodInfoMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.RestaurantFoodInfo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="food_type_id" jdbcType="BIGINT" property="foodTypeId"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="url" jdbcType="VARCHAR" property="url"/>
        <result column="enable" jdbcType="TINYINT" property="enable"/>
        <result column="sales" jdbcType="INTEGER" property="sales"/>
        <result column="price" jdbcType="DECIMAL" property="price"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="price_unit" jdbcType="VARCHAR" property="priceUnit"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="restaurant_id" jdbcType="BIGINT" property="restaurantId"/>
        <result column="baling_charge" jdbcType="DECIMAL" property="balingCharge"/>
        <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="is_hot_food" jdbcType="TINYINT" property="isHotFood"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_restaurant_food_info
            (id,
            food_type_id,
            name,
            url,
            enable,
            sales,
            price,
            create_user_id,
            price_unit,
            create_time,
            restaurant_id,
            baling_charge,
            update_user_id,
            update_time,
            data_state,
            is_hot_food)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.foodTypeId},
            #{item.name},
            #{item.url},
            #{item.enable},
            #{item.sales},
            #{item.price},
            #{item.createUserId},
            #{item.priceUnit},
            #{item.createTime},
            #{item.restaurantId},
            #{item.balingCharge},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState})
            #{item.isHotFood})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="restaurantFoodInfoFilter != null">
            <if test="restaurantFoodInfoFilter.name != null and restaurantFoodInfoFilter.name != ''">
                <bind name = "safeRestaurantFoodInfoName" value = "'%' + restaurantFoodInfoFilter.name + '%'" />
                AND tour_restaurant_food_info.name LIKE #{safeRestaurantFoodInfoName}
            </if>
            <if test="restaurantFoodInfoFilter.id != null">
                AND tour_restaurant_food_info.id = #{restaurantFoodInfoFilter.id}
            </if>
            <if test="restaurantFoodInfoFilter.enable != null">
                AND tour_restaurant_food_info.enable = #{restaurantFoodInfoFilter.enable}
            </if>
            <if test="restaurantFoodInfoFilter.isHotFood != null">
                AND tour_restaurant_food_info.is_hot_food = #{restaurantFoodInfoFilter.isHotFood}
            </if>
            <if test="restaurantFoodInfoFilter.searchString != null and restaurantFoodInfoFilter.searchString != ''">
                <bind name = "safeRestaurantFoodInfoSearchString" value = "'%' + restaurantFoodInfoFilter.searchString + '%'" />
                AND IFNULL(tour_restaurant_food_info.name,'') LIKE #{safeRestaurantFoodInfoSearchString}
            </if>
            <if test="restaurantFoodInfoFilter.restaurantIdList != null and restaurantFoodInfoFilter.restaurantIdList.size() > 0">
                AND tour_restaurant_food_info.restaurant_id IN
                <foreach item="id" index="index" collection="restaurantFoodInfoFilter.restaurantIdList" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="restaurantFoodInfoFilter.restaurantId != null and restaurantFoodInfoFilter.restaurantId!= ''">
                AND tour_restaurant_food_info.restaurant_id = #{restaurantFoodInfoFilter.restaurantId}
            </if>
            <if test="restaurantFoodInfoFilter.foodTypeId != null and restaurantFoodInfoFilter.foodTypeId != '' ">
                AND tour_restaurant_food_info.food_type_id = #{restaurantFoodInfoFilter.foodTypeId}
            </if>
        </if>
    </sql>

    <select id="getRestaurantFoodInfoList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.RestaurantFoodInfo">
        SELECT * FROM tour_restaurant_food_info
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>

</mapper>
