<?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.WxWechatUserCorrelationDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.WxWechatUserCorrelation">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="book_group_id" property="bookGroupId" jdbcType="BIGINT"/>
        <result column="wx_id" property="wxId" jdbcType="VARCHAR"/>
        <result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>


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

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

    <!--根据微信id和社群码id获取-->
    <select id="getByWxIdAndBookGroupId" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from wx_wechat_user_correlation
        where wx_id=#{wxId}
        and book_group_id=#{bookGroupId}
    </select>
</mapper>