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

	<sql id="shareAllField">
		SHARE_ID SHAREID,
		SHARE_IMG_URL SHAREIMGURL,
		SHARE_MESSAGE SHAREMESSAGE,
		SHARE_USER_OPENID SHAREUSEROPENID,
		SHARE_USER_TYPE SHAREUSERTYPE,
		SHARE_CREATE_DATE CREATEDATE
	</sql>
	<!-- 添加一个分享 -->
	<insert id="addShareInfo" parameterType="ShareInfo" 
		useGeneratedKeys="true" keyProperty="shareId">
		INSERT INTO TB_IAMBERRY_USER_SHARE
		(
			SHARE_IMG_URL,
			SHARE_MESSAGE,
			SHARE_USER_TYPE,
			SHARE_USER_OPENID,
			SHARE_CREATE_DATE
		)
		VALUES
		(
			#{shareImgUrl},
			#{shareMessage},
			#{shareUserType},
			#{shareUserOpenid},
			#{createDate}
		)
	</insert>
	
	<!-- 根据openid 和用户类型 查询一个分享信息 -->
	<select id="getShareInfoByOpenidAndType" parameterType="ShareInfo" resultType="ShareInfo">
		SELECT 
			<include refid="shareAllField"></include>
		FROM TB_IAMBERRY_USER_SHARE	
		<where> 
			<if test="shareUserOpenid != null and shareUserOpenid != ''">
				SHARE_USER_OPENID = #{shareUserOpenid}
			</if>
			<if test="shareUserType != null and shareUserType != ''">
				AND SHARE_USER_TYPE = #{shareUserType}
			</if>
		</where>
	</select>
	
	<!-- 根据 id 查询一个分享信息 -->
	<select id="getShareInfoById" parameterType="Integer" resultType="ShareInfo">
		SELECT 
			<include refid="shareAllField"></include>
		FROM TB_IAMBERRY_USER_SHARE	
		WHERE SHARE_ID = #{id}
	</select>
</mapper>