<?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.RestaurantCartMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.RestaurantCart">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="restaurant_id" jdbcType="BIGINT" property="restaurantId"/>
        <result column="restaurant_food_id" jdbcType="BIGINT" property="restaurantFoodId"/>
        <result column="count" jdbcType="INTEGER" property="count"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <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="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_restaurant_cart
            (id,
            user_id,
            restaurant_id,
            restaurant_food_id,
            count,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            deleted_flag)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.userId},
            #{item.restaurantId},
            #{item.restaurantFoodId},
            #{item.count},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.deletedFlag})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="restaurantCartFilter != null">
        </if>
    </sql>

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

    <select id="getRestaurantCartListAndFoodDetail" resultType="List" parameterType="com.tourism.webadmin.app.wechat.model.WechatRestaurantCart">
        SELECT
        cart.count,
        food.price,
        food.name,food.url,
        food.sales,
        food.price_unit,
        food.baling_charge
        FROM tour_restaurant_cart cart left join tour_restaurant_food_info food on cart.restaurant_food_id = food.id
        <where>
            <if test="enable != null and enable != ''">
                food.enable = #{enable}
            </if>
            <if test="user_id != null and user_id != ''">
                cart.user_id = #{userId}
            </if>
            <if test="restaurant_id != null and restaurant_id != ''">
                cart.restaurant_id = #{restaurantId}
            </if>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
