<?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.ischoolbar.programmer.dao.home.CartDao">
	<!-- 购物车插入操作 -->
	<insert id="add" parameterType="com.ischoolbar.programmer.entity.home.Cart">
		insert into cart(id,productId,userId,name,imageUrl,price,num,money,createTime) values(null,#{productId},#{userId},#{name},#{imageUrl},#{price},#{num},#{money},#{createTime})
	</insert>
	<!-- 购物车更新操作 -->
	<update id="edit" parameterType="com.ischoolbar.programmer.entity.home.Cart">
		update cart set num = #{num},money = #{money} where id = #{id}
	</update>
	<!-- 购物车信息搜索查询 -->
	<select id="findList" parameterType="Map" resultType="com.ischoolbar.programmer.entity.home.Cart">
		select * from cart where 1 = 1 
		<if test="userId != null">
			and userId = #{userId}  
		</if>
		<if test="orderBy != null and sort != null">
			order by ${orderBy} ${sort}   
		</if>
		<if test="offset != null and pageSize != null">
			limit #{offset},#{pageSize}
		</if>
	</select>
	<!-- 模糊搜索总条数 -->
	<select id="getTotal" parameterType="Map" resultType="Integer">
		select count(*) from cart where 1 = 1 
		<if test="userId != null">
			and userId = #{userId}  
		</if>
	</select>
	<!-- 根据id查询 -->
	<select id="findById" parameterType="Long" resultType="com.ischoolbar.programmer.entity.home.Cart">
		select * from cart where id = #{value}
	</select>
	<!-- 根据userid和productid查询 -->
	<select id="findByIds" parameterType="Map" resultType="com.ischoolbar.programmer.entity.home.Cart">
		select * from cart where userId = #{userId} and productId = #{productId}
	</select>
	<!-- 删除购物车信息 -->
	<delete id="delete" parameterType="String">
		delete from cart where id in(${value})
	</delete>
	<!-- 删除用户购物车信息 -->
	<delete id="deleteByUid" parameterType="Long">
		delete from cart where userId = #{value}
	</delete>
</mapper>