<?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.bonus.canteen.core.order.mapper.OrderShoppingCartMapper">
    
    <resultMap type="com.bonus.canteen.core.order.domain.OrderShoppingCart" id="OrderShoppingCartResult">
        <result property="shoppingCartId"    column="shopping_cart_id"    />
        <result property="userId"    column="user_id"    />
        <result property="menuId"    column="menu_id"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="goodsImgUrl"    column="goods_img_url"    />
        <result property="quantity"    column="quantity"    />
        <result property="orderType"    column="order_type"    />
        <result property="detailType"    column="detail_type"    />
        <result property="orderDate"    column="order_date"    />
        <result property="mealtimeType"    column="mealtime_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectOrderShoppingCartVo">
        select shopping_cart_id, user_id, menu_id, canteen_id, stall_id, goods_id, goods_name, goods_img_url, quantity, order_type, detail_type, order_date, mealtime_type, create_by, create_time, update_by, update_time from order_shopping_cart
    </sql>

    <select id="selectOrderShoppingCartList" parameterType="com.bonus.canteen.core.order.domain.OrderShoppingCart" resultMap="OrderShoppingCartResult">
        <include refid="selectOrderShoppingCartVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="menuId != null "> and menu_id = #{menuId}</if>
            <if test="canteenId != null "> and canteen_id = #{canteenId}</if>
            <if test="stallId != null "> and stall_id = #{stallId}</if>
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="goodsImgUrl != null  and goodsImgUrl != ''"> and goods_img_url = #{goodsImgUrl}</if>
            <if test="quantity != null "> and quantity = #{quantity}</if>
            <if test="orderType != null "> and order_type = #{orderType}</if>
            <if test="detailType != null "> and detail_type = #{detailType}</if>
            <if test="orderDate != null "> and order_date = #{orderDate}</if>
            <if test="mealtimeType != null "> and mealtime_type = #{mealtimeType}</if>
        </where>
    </select>
    
    <select id="selectOrderShoppingCartByShoppingCartId" parameterType="Long" resultMap="OrderShoppingCartResult">
        <include refid="selectOrderShoppingCartVo"/>
        where shopping_cart_id = #{shoppingCartId}
    </select>

    <insert id="insertOrderShoppingCart" parameterType="com.bonus.canteen.core.order.domain.OrderShoppingCart">
        insert into order_shopping_cart
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shoppingCartId != null">shopping_cart_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="menuId != null">menu_id,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="goodsName != null and goodsName != ''">goods_name,</if>
            <if test="goodsImgUrl != null">goods_img_url,</if>
            <if test="quantity != null">quantity,</if>
            <if test="orderType != null">order_type,</if>
            <if test="detailType != null">detail_type,</if>
            <if test="orderDate != null">order_date,</if>
            <if test="mealtimeType != null">mealtime_type,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shoppingCartId != null">#{shoppingCartId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="menuId != null">#{menuId},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="goodsName != null and goodsName != ''">#{goodsName},</if>
            <if test="goodsImgUrl != null">#{goodsImgUrl},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="detailType != null">#{detailType},</if>
            <if test="orderDate != null">#{orderDate},</if>
            <if test="mealtimeType != null">#{mealtimeType},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateOrderShoppingCart" parameterType="com.bonus.canteen.core.order.domain.OrderShoppingCart">
        update order_shopping_cart
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="menuId != null">menu_id = #{menuId},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
            <if test="goodsImgUrl != null">goods_img_url = #{goodsImgUrl},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="detailType != null">detail_type = #{detailType},</if>
            <if test="orderDate != null">order_date = #{orderDate},</if>
            <if test="mealtimeType != null">mealtime_type = #{mealtimeType},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where shopping_cart_id = #{shoppingCartId}
    </update>

    <delete id="deleteOrderShoppingCartByShoppingCartId" parameterType="Long">
        delete from order_shopping_cart where shopping_cart_id = #{shoppingCartId}
    </delete>

    <delete id="deleteOrderShoppingCartByShoppingCartIds" parameterType="String">
        delete from order_shopping_cart where shopping_cart_id in 
        <foreach item="shoppingCartId" collection="array" open="(" separator="," close=")">
            #{shoppingCartId}
        </foreach>
    </delete>

</mapper>