<?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.faisp.userInfo.mapper.UserInfoMapper">
  <sql id="selectUserInfoWhere">
    <where>
      <choose>
        <when test="userStatus != null and userStatus != ''">
          user_status = #{userStatus}
        </when>
        <otherwise>
          user_status != 'D'
        </otherwise>
      </choose>
      <if test="userId != null and userId != ''">
        and user_id like '%'||#{userId}||'%'
      </if>
      <if test="userNm != null and userNm != ''">
        and user_nm like '%'||#{userNm}||'%'
      </if>
      <if test="ogCd != null and ogCd != ''">
        and og_cd = #{ogCd}
      </if>
      <if test="ofcCd != null and ofcCd != ''">
        and ofc_cd = #{ofcCd}
      </if>
    </where>
  </sql>
  <select id="selectUserInfoList" resultType="UserInfo" parameterType="UserInfo">
    select user_seq,
           user_id,
           user_nm,
           user_role,
           email,
           og_cd,
           ofc_cd,
           wrt_dt
    from user_info
    <include refid="selectUserInfoWhere"></include>
    order by og_cd, ofc_cd desc
    limit #{rowCnt} offset #{firstIndex}
  </select>

  <select id="selectUserInfoListCnt" resultType="int" parameterType="UserInfo">
    select count(*)
    from user_info
    <include refid="selectUserInfoWhere"></include>
  </select>
  
   <select id="selectManagerList" resultType="com.dbnt.faisp.util.ParamMap" parameterType="com.dbnt.faisp.util.ParamMap">
	     select user_seq,
		   	    user_id 
		   		user_name
		 from user_info
		 where og_cd in
		 <foreach collection="downOrganCdList" item="item" index="index" separator="," open="(" close=")">
        	#{item}
     	 </foreach>
     	 order by user_nm asc
  </select>

  <select id="selectDashboardConfigList" resultType="DashboardConfig" parameterType="int">
    select a.menu_key ,
           a.cat1_cd ,
           a.cat2_cd ,
           a.cat3_cd ,
           a.menu_url ,
           b.order_num
    from menu_mgt a
           inner join dashboard_config b
                      on a.menu_key = b.menu_key
    where b.user_seq = #{userSeq}
    order by b.order_num
  </select>
</mapper>