<?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.iamberry.wechat.service.mapper.ProductPictureMapper">

 	<sql id="allField">
		picture_id pictureId,
		picture_produect_id pictureProductId,
		picture_url pictureUrl,
		picture_create_date pictureCreateDate
	</sql>
	<!-- 为某产品添加一个介绍图 -->
	<insert id="addProductPicture" parameterType="ProductPicture" 
			useGeneratedKeys="true" keyProperty="pictureId">
		INSERT INTO tb_iamberry_product_picture
		(
			picture_produect_id	,
			picture_url ,
			picture_create_date 
		)
		VALUES
		(
			#{pictureProductId},#{pictureUrl},#{pictureCreateDate}
		)
	</insert>
	
	<!-- 根据图片id 删除一个介绍图 -->
	<delete id="deleteProductPicture" parameterType="int">
		DELETE FROM tb_iamberry_product_picture
		WHERE picture_id=#{id}
	</delete>

	<!-- 根据产品id 查出该产品所有介绍图信息 -->
	<select id="getProductPictureByproductId" parameterType="int" resultType="ProductPicture">
		SELECT 
			<include refid="allField"></include>
		FROM tb_iamberry_product_picture 
		WHERE picture_produect_id=#{ID} 
		ORDER BY PICTURE_ID DESC
	</select>
</mapper>