<?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.advertising.dao.impl.AdvertisingLinkClickDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingLinkClick" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <id column="link" property="link" jdbcType="VARCHAR" />
    <result column="user_id" property="userId" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, link, user_id, create_time
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingLinkClick" useGeneratedKeys="true" keyProperty="id">
    insert into advertising_link_click (id, link, user_id, 
      create_time)
    values (#{id,jdbcType=BIGINT}, #{link,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, 
     NOW())
  </insert>

  <select id="getCountByLink" parameterType="string" resultType="com.pcloud.book.advertising.dto.LinkRevertRecordDTO">
    SELECT
    COUNT(1) clickCount,
    COUNT(DISTINCT user_id) clickUserCount
    FROM advertising_link_click
    WHERE link = #{link}
  </select>

</mapper>