<?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.cool.store.mapper.PartnerUserWechatBindMapper">


    <resultMap id="BaseResultMap" type="com.cool.store.entity.PartnerUserWechatBindDO">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="open_id" property="openId" jdbcType="VARCHAR" />
        <result column="bind_time" property="bindTime" jdbcType="TIMESTAMP" />
        <result column="partner_id" property="partnerId" jdbcType="VARCHAR" />
        <result column="union_id" property="unionId" jdbcType="VARCHAR" />
        <result column="service_account_open_id" property="serviceAccountOpenId" jdbcType="VARCHAR" />
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    </resultMap>

    <insert id="insert" parameterType="com.cool.store.entity.PartnerUserWechatBindDO">
        INSERT INTO xfsg_partner_user_wechat_bind (
        open_id,
        bind_time,
        partner_id,
        union_id,
        create_time
        ) VALUES (
        #{openId, jdbcType=VARCHAR},
        #{bindTime, jdbcType=TIMESTAMP},
        #{partnerId, jdbcType=VARCHAR},
        #{unionId, jdbcType=VARCHAR},
        #{createTime, jdbcType=TIMESTAMP}
        )
    </insert>

    <update id="update" parameterType="com.cool.store.entity.PartnerUserWechatBindDO">
        UPDATE xfsg_partner_user_wechat_bind
        <set>
            <if test="unionId != null">
                union_id = #{unionId, jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id}
    </update>

    <update id="updateByUnionId" >
        UPDATE xfsg_partner_user_wechat_bind
        set service_account_open_id = #{serviceAccountOpenId}
        where union_id = #{unionId}
    </update>

    <select id="selectByPartnerAndOpenId" resultMap="BaseResultMap">
        select * from xfsg_partner_user_wechat_bind where partner_id = #{partnerId} and open_id = #{openId}
    </select>




</mapper>
