<?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.sckw.product.dao.KwpGoodsViewLogMapper">
  <resultMap id="BaseResultMap" type="com.sckw.product.model.KwpGoodsViewLog">
    <!--@mbg.generated-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="ent_id" jdbcType="BIGINT" property="entId" />
    <result column="user_id" jdbcType="BIGINT" property="userId" />
    <result column="search_words" jdbcType="VARCHAR" property="searchWords" />
    <result column="source" jdbcType="INTEGER" property="source" />
    <result column="user_agent" jdbcType="VARCHAR" property="userAgent" />
    <result column="ip_address" jdbcType="VARCHAR" property="ipAddress" />
    <result column="search_time" jdbcType="TIMESTAMP" property="searchTime" />
    <result column="create_by" jdbcType="BIGINT" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
  </resultMap>

  <select id="searchViewCount" resultType="com.sckw.product.model.vo.res.GoodsViewLogVo">
      select kgvl.goods_id,
             kgvl.goods_name,
             kgvl.goods_type,
             count(kgvl.goods_id) as count
      from kwp_goods_view_log kgvl
      <where>
          kgvl.del_flag = 0

          <if test="start != null and end != null">
              and kgvl.search_time between #{start} and #{end}
          </if>
          group by kgvl.goods_id,
                   kgvl.goods_name,
                   kgvl.goods_type
          order by count desc
          limit 20
      </where>
  </select>
</mapper>
