<?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.DealerRelationMapper">
 
 <sql id="AllField">
 	DEALER_ID dealerId,
	DEALER_FIRST dealerFirst,
	DEALER_SECOND dealerSecond,
	DEALER_THIRD dealerThird,
	DEALER_FOURTH dealerFourth,
	DEALER_FIFTH dealerFifth,
	DEALER_SIXTH dealerSixth,
	DEALER_COUNT dealerCount,
	DEALER_CREATE_DATE createDate,
	DEALER_UPDATE_DATE updateDate
 </sql>
 <select id="getDealerRelationById" parameterType="Integer" resultType="DealerRelation">
 	SELECT 
		<include refid="AllField"></include> 
	FROM TB_IAMBERRY_DEALERS
	WHERE DEALER_ID=#{id}
 </select>
 <insert id="insertDealerRelation" parameterType="DealerRelation"
 	useGeneratedKeys="true" keyProperty="dealerId">
 	INSERT INTO TB_IAMBERRY_DEALERS
		(
			DEALER_FIRST ,DEALER_SECOND ,DEALER_THIRD ,DEALER_FOURTH ,
			DEALER_FIFTH ,DEALER_SIXTH ,DEALER_COUNT ,DEALER_CREATE_DATE,DEALER_UPDATE_DATE 
		)
	VALUES
		( 
			#{dealerFirst},#{dealerSecond},#{dealerThird},#{dealerFourth},
			#{dealerFifth},#{dealerSixth},#{dealerCount},
			NOW(), #{updateDate}
		)
 </insert>
 
  <update id="updateRelation" parameterType="DealerRelation">
     update tb_iamberry_dealers 
	     <set>
	     	<if test="dealerFirst!=null and dealerFirst!=''">
	          DEALER_FIRST =#{dealerFirst}
	        </if>
	        <if test="dealerSecond!=null and dealerSecond!=''">
	          ,DEALER_SECOND =#{dealerSecond}
	        </if>
	        <if test="dealerThird!=null and dealerThird!=''">
	          ,DEALER_THIRD =#{dealerThird}
	        </if>
	        <if test="dealerFourth!=null and dealerFourth!=''">
	          ,DEALER_FOURTH =#{dealerFourth}
	        </if>
	        <if test="dealerFifth!=null and dealerFifth!=''">
	          ,DEALER_FIFTH =#{dealerFifth}
	        </if>
	        <if test="dealerSixth!=null and dealerSixth!=''">
	          ,DEALER_SIXTH =#{dealerSixth}
	        </if>
	        <if test="dealerCount!=null and dealerCount!=''">
	          ,DEALER_COUNT =#{dealerCount}
	        </if>
	     </set> 
	          WHERE DEALER_ID=#{dealerId}

    </update>
</mapper>