<?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.ProductImageTextMapper">

	<sql id="allField">
		imagetext_id imagetextId,
		imagetext_produect_id imagetextProduectId,
		imagetext_context imagetextContext,
		imagetext_create_date imagetextCreateDate
	</sql>
 	<!-- 为某产品添加一个图文 -->
	<insert id="addProductImageText" parameterType="ProductImageText" 
			useGeneratedKeys="true" keyProperty="imagetextId">
		INSERT INTO tb_iamberry_product_imagetext
		(
			imagetext_produect_id	,
			imagetext_context ,
			imagetext_create_date 
		)
		VALUES
		(
			#{imagetextProduectId},#{imagetextContext},#{imagetextCreateDate}
		)
	</insert>
	
	<!-- 根据产品id 查询该产品的图文信息 -->
	<select id="getProductImageTextByProduectId" resultType="ProductImageText" parameterType="int">
		SELECT 
			<include refid="allField"/>
		FROM tb_iamberry_product_imagetext
		WHERE imagetext_produect_id=#{imagetextProduectId}
	</select>
	
	<!-- 根据 图文id 修改一个产品的图文信息 -->
	<update id="updateProductImageTextById" parameterType="ProductImageText">
		update tb_iamberry_product_imagetext
		<set>
			<if test="imagetextProduectId!=null and imagetextProduectId!=''">
				imagetext_produect_id=#{imagetextProduectId},
			</if>
			<if test="imagetextContext!=null and imagetextContext!=''">
				imagetext_context=#{imagetextContext},
			</if>
			<if test="imagetextCreateDate!=null and imagetextCreateDate!=''">
				imagetext_create_date=#{imagetextCreateDate},
			</if>
		</set>
		WHERE imagetext_id=#{imagetextId}
	</update>

</mapper>