<?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.dbnt.kcscbackend.admin.users.mapper.AdminUsersMapper">

	<select id="selectUserList" parameterType="UserInfo" resultType="UserInfo">
		select user_seq,
					a.user_id,
					a.email,
					b.item_nm as user_se,
					a.user_nm,
					a.phone_num,
					a.user_role,
					a.status,
					c.item_nm as status_value
		from user_info a
				inner join tc_code_item b on a.user_se = b.item_cd
				inner join tc_code_item c on a.status = c.item_cd
		<include refid="selectUserListWhere"></include>
		order by user_seq desc
		limit #{rowCnt} offset #{firstIndex}
	</select>

	<select id="selectUserListCnt" parameterType="UserInfo" resultType="int">
		select count(*)
		from user_info
		<include refid="selectUserListWhere"></include>
	</select>

	<sql id="selectUserListWhere">
		<where>
			<if test='userSe != null and userSe != ""'>
				and user_se = #{userSe}
			</if>
			<if test='searchKeyword != null and searchKeyword != ""'>
				<if test='searchCondition == "id"'>
					and user_id like '%'||#{searchKeyword}||'%'
				</if>
				<if test='searchCondition == "name"'>
					and user_nm like '%'||#{searchKeyword}||'%'
				</if>
				<if test='searchCondition == "email"'>
					and email like '%'||#{searchKeyword}||'%'
				</if>
				<if test='searchCondition == "phoneNum"'>
					and phone_num like '%'||#{searchKeyword}||'%'
				</if>
			</if>
		</where>
	</sql>
</mapper>