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

	<sql id="allField">
		QR_ID qrId,
		QR_OPENID qrOpenid,
		QR_URL qrUrl,
		QR_VALUE qrValue,
		QR_CREATE_DATE qrCreateDate,
		QR_END_DATE qrEndDate,
		QR_UPDATE_DATE qrUpdateDate
	</sql>
	<select id="getTempQrcodeByOpenId" parameterType="String" resultType="TemporaryQrcode">
		SELECT 
			<include refid="allField"></include>
		FROM TB_IAMBERRY_USER_TEMPORARY_QRCODE
		WHERE QR_OPENID=#{openid}
	</select>
	
	<select id="getTempQrcodeById" parameterType="Integer" resultType="TemporaryQrcode">
		SELECT 
			<include refid="allField"></include>
		FROM TB_IAMBERRY_USER_TEMPORARY_QRCODE
		WHERE QR_ID=#{qrId}
	</select>
	
	<insert id="insertTempQrcode" parameterType="TemporaryQrcode"
		useGeneratedKeys="true" keyProperty="qrId">
		INSERT INTO TB_IAMBERRY_USER_TEMPORARY_QRCODE
		(
			QR_OPENID ,
			QR_URL ,
			QR_VALUE ,
			QR_CREATE_DATE ,
			QR_END_DATE ,
			QR_UPDATE_DATE 
		)
		VALUES
		(
			#{qrOpenid},#{qrUrl},#{qrValue},NOW(),#{qrEndDate},#{qrUpdateDate}
		)
	</insert>
	
	<update id="updateTempQrcodeURLByOpenid" parameterType="TemporaryQrcode">
		UPDATE TB_IAMBERRY_USER_TEMPORARY_QRCODE 
		<set>
	     	<if test="qrUrl!=null and qrUrl!=''">
				QR_URL=#{qrUrl},
	        </if>
	        <if test="qrValue!=null and qrValue!=''">
				QR_VALUE=#{qrValue},
	        </if>
	        <if test="qrEndDate!=null and qrEndDate!=''">
				QR_END_DATE=#{qrEndDate},
	        </if>
	        <if test="qrUpdateDate!=null and qrUpdateDate!=''">
				QR_UPDATE_DATE=#{qrUpdateDate}
	        </if>
		</set>
		WHERE QR_OPENID=#{qrOpenid}
	</update>
</mapper>