<?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.rightsSetting.dao.impl.RightsNowPopupDaoImpl">

    <resultMap type="com.pcloud.book.rightsSetting.entity.RightsNowPopup" id="RightsNowPopupMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="wechatUserId" column="wechat_user_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="rightsSettingId" column="rights_setting_id" jdbcType="INTEGER"/>
        <result property="popupType" column="popup_type" jdbcType="INTEGER"/>
        <result property="serveId" column="serve_id" jdbcType="INTEGER"/>
        <result property="serveType" column="serve_type" jdbcType="VARCHAR"/>
        <result property="recordType" column="record_type" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="readType" column="read_type" jdbcType="INTEGER"/>
        <result property="baseServeId" column="base_serve_id" jdbcType="INTEGER"/>
        <result property="baseServeType" column="base_serve_type" jdbcType="VARCHAR"/>
    </resultMap>


    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.rights_now_popup(wechat_user_id, book_id, channel_id, adviser_id, rights_setting_id, popup_type, serve_id, serve_type, record_type, create_time, update_time, read_type, base_serve_id, base_serve_type)
        values (#{wechatUserId}, #{bookId}, #{channelId}, #{adviserId}, #{rightsSettingId}, #{popupType}, #{serveId}, #{serveType},  #{recordType}, now(), now(), #{readType}, #{baseServeId}, #{baseServeType})
    </insert>

    <select id="getUserPopupClickCount" parameterType="map" resultType="integer">
        SELECT COUNT(1) FROM book.rights_now_popup
        WHERE wechat_user_id = #{wechatUserId}
        and book_id = #{bookId}
        and channel_id = #{channelId}
        and adviser_id = #{adviserId}
        and popup_type = #{popupType}
        AND record_type IN (2, 3)
    </select>

    <select id="getUserPopupClickCountByServe" parameterType="com.pcloud.book.rightsSetting.entity.RightsNowPopup" resultType="integer">
        SELECT COUNT(1) FROM book.rights_now_popup
        WHERE wechat_user_id = #{wechatUserId}
        and book_id = #{bookId}
        and channel_id = #{channelId}
        and adviser_id = #{adviserId}
        and popup_type = #{popupType}
        AND record_type IN (2, 3)
        and serve_id = #{serveId}
        and serve_type = #{serveType}
    </select>

</mapper>