<?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.mca.map.mapper.UseHistoryMapper">

	<!--해당 회원의 전체 요청 리스트 가져오기-->
	<select id="selectUseHistoryList" parameterType="useHistorySearchVO" resultType="useHistoryVO" >
		SELECT
			log_date AS logDate,
		  client_type,
      log_type,
      req_area AS reqArea,
      a.userid,
      b.name,
      b.company
		FROM
			map_use_history a JOIN t_user b ON a.userid=b.userid
		<where>
      <if test='searchKeyword != null and searchKeyword != ""'>
        <choose>
          <when test='searchCondition eq "all"'>

              AND (b.name LIKE CONCAT('%',#{searchKeyword},'%')
              OR b.company LIKE CONCAT('%',#{searchKeyword},'%')
              OR a.req_area LIKE CONCAT('%',#{searchKeyword},'%'))
          </when>
          <otherwise>
              AND ${searchCondition} LIKE CONCAT('%',#{searchKeyword},'%')
          </otherwise>
        </choose>
      </if>
    </where>
		ORDER BY log_date DESC
		LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
	</select>

<!--	방문자수-->
	<select id="selectUseVisit" parameterType="useHistorySearchVO" resultType="int">
		SELECT
			COUNT(*)
		FROM
			map_use_history
		WHERE
			log_type = '0'
		  AND log_date >= CONCAT(#{searchStartDate}, ' 00:00:00')
		  AND log_date &lt;= CONCAT(#{searchEndDate}, ' 23:59:59')
	</select>

	<select id="selectUseHistoryCnt" resultType="int" >
		SELECT
			COUNT(*)
		FROM
			map_use_history a JOIN t_user b ON a.userid=b.userid
		<where>
      <if test='searchKeyword != null and searchKeyword != ""'>
        <choose>
          <when test='searchCondition eq "all"'>
              AND (b.name LIKE CONCAT('%',#{searchKeyword},'%')
              OR b.company LIKE CONCAT('%',#{searchKeyword},'%')
              OR a.req_area LIKE CONCAT('%',#{searchKeyword},'%'))
          </when>
          <otherwise>
              AND ${searchCondition} LIKE CONCAT('%',#{searchKeyword},'%')
          </otherwise>
        </choose>
      </if>
    </where>
	</select>

  <select id="selectDayMapUseData" parameterType="useHistorySearchVO" resultType="ChartVO" >
    select DATE_FORMAT(log_date ,'%m-%d') as param01,
      count(*) as value01
    from map_use_history
    where log_date >= CONCAT(#{searchStartDate}, ' 00:00:00')
      and log_date &lt;= CONCAT(#{searchEndDate}, ' 23:59:59')
    group by param01
  </select>
</mapper>