<?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.BookQrcodeUserDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.BookQrcodeUser">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="classify_id" property="classifyId" jdbcType="BIGINT"/>
        <result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT"/>
        <result column="group_qrcode_id" property="groupQrcodeId" jdbcType="BIGINT"/>
        <result column="create_user" property="createUser" jdbcType="BIGINT"/>
        <result column="from_type" property="fromType" jdbcType="INTEGER"/>
    </resultMap>


    <insert id="insert" parameterType="bookQrcodeUser" useGeneratedKeys="true"
            keyProperty="id">
        insert into book_qrcode_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            classify_id,
            wechat_user_id,
            group_qrcode_id,
            create_user,
            create_time,
            from_type
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{classifyId,jdbcType=BIGINT},
            #{wechatUserId,jdbcType=BIGINT},
            #{groupQrcodeId,jdbcType=BIGINT},
            #{createUser,jdbcType=BIGINT},
            NOW(),
            #{fromType}
        </trim>
    </insert>

    <select id="getUserQrcode" resultType="GroupQrcode4ClassifyVO" parameterType="map">
        SELECT
        u.classify_id classifyId,
        u.group_qrcode_id groupQrcodeId,
        q.qrcode_url qrcodeUrl,
        q.group_name groupName
        FROM book_qrcode_user u JOIN book_group_qrcode q ON u.group_qrcode_id = q.id
        WHERE  u.classify_id =#{classifyId} AND wechat_user_id = #{wechatUserId}  limit 1
    </select>
</mapper>