<?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.neusoft.mapper.CartMapper">

	 <resultMap type="Cart" id="cartResultMap">
		 <id column="cartId" property="cartId"/>
		 <result column="foodId" property="foodId"/>
		 <result column="businessId" property="businessId"/>
		 <result column="userId" property="userId"/>
		 <result column="quantity" property="quantity"/>
		 <association property="food" javaType="Food"
					  select="com.neusoft.mapper.FoodMapper.getFoodById"
					  column="foodId"/>
		 <association property="business" javaType="Business"
					  select="com.neusoft.mapper.BusinessMapper.getBusinessById"
					  column="businessId"/>
	 </resultMap>
	 
	 <select id="listCart" parameterType="Cart" resultMap="cartResultMap">
		 select * from cart
		 <where>
			 userId=#{userId}
			 <if test="businessId!=null and businessId!=''">
			 	and businessId=#{businessId}
		 	</if>
	 	</where>
	 	order by cartId
	</select>
	 
	 <delete id="removeCart" parameterType="Cart">
		 delete from cart 
		 <where>
		 userId=#{userId} and businessId=#{businessId}
		 <if test="foodId!=null and foodId!=''">
		 and foodId=#{foodId}
	 	 </if>
	 </where>
	 </delete>
</mapper>