<?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,
		    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 1 = '1'
		<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>
		ORDER BY log_date DESC
		LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
	</select>
	
	<select id="selectUseHistoryCnt" resultType="int" >
		SELECT
			COUNT(*)
		FROM
			map_use_history a JOIN t_user b ON a.userid=b.userid
		WHERE 1 = 1
		<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>
	</select>
</mapper>