<?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.pcloud.book.book.dao.impl.BookQrcodeWxworkDaoImpl">

    <resultMap type="com.pcloud.book.book.entity.BookQrcodeWxwork" id="BookQrcodeWxworkMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="bookId" column="book_id" jdbcType="INTEGER"/>
        <result property="channelId" column="channel_id" jdbcType="INTEGER"/>
        <result property="adviserId" column="adviser_id" jdbcType="INTEGER"/>
        <result property="bookQrcodeType" column="book_qrcode_type" jdbcType="INTEGER"/>
        <result property="bookQrcodeId" column="book_qrcode_id" jdbcType="INTEGER"/>
        <result property="wxworkQrcodeId" column="wxwork_qrcode_id" jdbcType="INTEGER"/>
        <result property="wxworkQrcodeType" column="wxwork_qrcode_type" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
       id, book_id, channel_id, adviser_id, book_qrcode_type, book_qrcode_id, wxwork_qrcode_id, wxwork_qrcode_type, create_time
    </sql>
    <!--查询单个-->
    <select id="getById" resultMap="BookQrcodeWxworkMap">
        select
          <include refid="Base_Column_List"/>
        from book.book_qrcode_wxwork
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.book_qrcode_wxwork(book_id, channel_id, adviser_id, book_qrcode_type, book_qrcode_id, wxwork_qrcode_id,
         wxwork_qrcode_type, create_time)
        values (#{bookId}, #{channelId}, #{adviserId}, #{bookQrcodeType}, #{bookQrcodeId}, #{wxworkQrcodeId},
         #{wxworkQrcodeType}, now())
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update book.book_qrcode_wxwork
        <set>
            <if test="bookId != null">
                book_id = #{bookId},
            </if>
            <if test="channelId != null">
                channel_id = #{channelId},
            </if>
            <if test="adviserId != null">
                adviser_id = #{adviserId},
            </if>
            <if test="bookQrcodeType != null">
                book_qrcode_type = #{bookQrcodeType},
            </if>
            <if test="bookQrcodeId != null">
                book_qrcode_id = #{bookQrcodeId},
            </if>
            <if test="wxworkQrcodeId != null">
                wxwork_qrcode_id = #{wxworkQrcodeId},
            </if>
            <if test="wxworkQrcodeType != null">
                wxwork_qrcode_type = #{wxworkQrcodeType},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from book.book_qrcode_wxwork where id = #{id}
    </delete>

    <delete id="deleteByQrcodeIdAndType" parameterType="map">
        delete from book.book_qrcode_wxwork
        where book_qrcode_type = #{bookQrcodeType}
        and  book_qrcode_id = #{bookQrcodeId}
        and wxwork_qrcode_type = #{wxworkQrcodeType}
    </delete>
    <select id="getByQrcodeIdAndType" resultMap="BookQrcodeWxworkMap" parameterType="map">
        select
        <include refid="Base_Column_List"/>
        from book.book_qrcode_wxwork
        where book_qrcode_type = #{bookQrcodeType}
        and  book_qrcode_id = #{bookQrcodeId}
        and wxwork_qrcode_type = #{wxworkQrcodeType}
    </select>

    <select id="getWxworkQrcodeByBook" parameterType="map" resultMap="BookQrcodeWxworkMap">
        select
        <include refid="Base_Column_List"/>
        from book.book_qrcode_wxwork
        where book_id = #{bookId}
        and channel_id = #{channelId}
        and adviser_id = #{adviserId}
        <if test="bookQrcodeType != null">
            and book_qrcode_type = #{bookQrcodeType}
        </if>
        order by wxwork_qrcode_type asc, create_time desc
    </select>

</mapper>