<?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">
<!-- 命名，每一个映射对象不一样
	namespace:必须与对应的接口全类名一致
 -->
 <mapper namespace="com.iamberry.wechat.service.mapper.WdRelationMapper">
 
 <sql id="allField">
 	WD_ID wdId,
	WD_USER_OPENID openid,
	WD_FIRST wdFirst,
	WD_SECOND wdSecond,
	WD_THIRD wdThird,
	WD_FOURTH wdFourth,
	WD_COUNT wdCount,
	WD_CREATE_DATE createDate,
	WD_UPDATE_DATE updateDate
 </sql>
 
 <select id="getWdRelationByOpenid" parameterType="String" resultType="WdRelation">
 	SELECT 
		<include refid="allField"></include>
	FROM TB_IAMBERRY_WD
	WHERE WD_USER_OPENID=#{openid}
 </select>
 
 <insert id="insertWdRelation" parameterType="WdRelation"
 	useGeneratedKeys="true" keyProperty="wdId">
 	INSERT INTO TB_IAMBERRY_WD
		(
			WD_USER_OPENID ,
			WD_FIRST ,
			WD_SECOND ,
			WD_THIRD ,
			WD_FOURTH ,
			WD_COUNT ,
			WD_CREATE_DATE,
			WD_UPDATE_DATE
		)
	VALUES
		(
			#{openid},#{wdFirst},#{wdSecond},#{wdThird},
			#{wdFourth},#{wdCount},NOW(),#{updateDate}
		)
 </insert>
 
 <select id="getWdRelationByWd" parameterType="WdRelation" resultType="WdRelation">
 	SELECT 
		<include refid="allField"></include>
	FROM TB_IAMBERRY_WD
	<where>
		<if test="openid != null and openid != ''">
			WD_USER_OPENID=#{openid}
		</if>
		<if test="wdFirst != null and wdFirst != ''">
			AND WD_FIRST=#{wdFirst}
		</if>
	</where>
 </select>
 
 </mapper>