<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.group.dao.impl.WxUserWechatRelevanceDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.WxUserWechatRelevance">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT"/>
        <result column="wx_id" property="wxId" jdbcType="VARCHAR"/>
        <result column="random_code" property="randomCode" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>


    <sql id="Base_Column_List">
        id, wechat_user_id, wx_id, random_code, create_time
    </sql>

    <insert id="insert" parameterType="com.pcloud.book.group.entity.WxUserWechatRelevance" useGeneratedKeys="true"
            keyProperty="id">
        insert into wx_user_wechat_relevance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            wechat_user_id,
            wx_id,
            random_code,
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{wechatUserId,jdbcType=BIGINT},
            #{wxId,jdbcType=VARCHAR},
            #{randomCode,jdbcType=VARCHAR},
            NOW()
        </trim>
    </insert>

    <!--更新wxId-->
    <update id="updateWxIdByRandomCode" parameterType="map">
        update wx_user_wechat_relevance
        set wx_id=#{wxId}
        where random_code=#{randomCode}
    </update>

    <!--根据微信id获取-->
    <select id="getByWechatUserId" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from wx_user_wechat_relevance
        where wechat_user_id=#{wechatUserId}
        limit 1
    </select>

    <!--根据随机码获取-->
    <select id="getByRandomCode" parameterType="string" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from wx_user_wechat_relevance
        where random_code=#{randomCode}
        limit 1
    </select>

</mapper>