<?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.copyright.dao.impl.BookClickBuyRecordDaoImpl">

	<insert id="insert" useGeneratedKeys="true" parameterType="bookClickBuyRecord">
      INSERT INTO BOOK_CLICK_BUY_RECORD(
			BOOK_ID, CHANNEL_ID,ADVISER_ID, WECHAT_USER_ID, CREATED_USER, CREATED_DATE)
	    VALUES
       (#{bookId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT}, #{adviserId,jdbcType=BIGINT},#{wechatUserId},
		#{wechatUserId}, NOW())
    </insert>

	<select id="getClickBuyRecordCount" resultType="Integer" parameterType="map">
	SELECT
		COUNT(distinct WECHAT_USER_ID)
	FROM
		BOOK_CLICK_BUY_RECORD
	WHERE
		1=1
	<if test="adviserIds!=null">
		AND ADVISER_ID in
		<foreach collection="adviserIds" item="item" open="(" separator="," close=")">
			${item}
		</foreach>
	</if>
	<if test="removeAdviserIds!=null">
		AND ADVISER_ID not in
			<foreach collection="removeAdviserIds" item="item" open="(" separator="," close=")">
				${item}
			</foreach>
	</if>
	</select>
</mapper>