<?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.menuMgt.mapper.MenuMgtMapper">
  <select id="selectMenuMgtList" resultType="MenuMgt" parameterType="MenuMgt">
    select menu_key as menuKey,
           cat1_cd as cat1Cd,
           cat2_cd as cat2Cd,
           cat3_cd as cat3Cd,
           menu_url as menuUrl,
           approval_chk as approvalChk
    from menu_mgt
    <where>
      <if test='cat1Cd != null and cat1Cd != ""'>
        and cat1_cd = #{cat1Cd}
      </if>
      <if test='cat2Cd != null and cat2Cd != ""'>
        and cat2_cd = #{cat2Cd}
      </if>
      <if test='cat3Cd != null and cat3Cd != ""'>
        and cat3_cd = #{cat3Cd}
      </if>
      <if test='menuUrl != null and menuUrl != ""'>
        and menu_url like  '%'||#{menuUrl}||'%'
      </if>
    </where>
    order by cat1_cd, cat2_cd, cat3_cd
    limit #{rowCnt} offset #{firstIndex}
  </select>
  <select id="selectMenuMgtListCnt" resultType="int" parameterType="MenuMgt">
    select count(*)
    from menu_mgt
    <where>
      <if test='cat1Cd != null and cat1Cd != ""'>
        and cat1_cd = #{cat1Cd}
      </if>
      <if test='cat2Cd != null and cat2Cd != ""'>
        and cat2_cd = #{cat2Cd}
      </if>
      <if test='cat3Cd != null and cat3Cd != ""'>
        and cat3_cd = #{cat3Cd}
      </if>
      <if test='menuUrl != null and menuUrl != ""'>
        and menu_url like  '%'||#{menuUrl}||'%'
      </if>
    </where>
  </select>

  <select id="selectAccessMenuListWhereUserSeq" resultType="MenuMgt" parameterType="int">
    select ab.cat1_cd,
           ab.cat2_cd,
           ab.cat3_cd,
           ab.menu_url
    from access_config aa
           inner join menu_mgt ab on aa.menu_key = ab.menu_key
    where aa.user_seq = #{userSeq}
      and aa.access_auth is not null
    order by cat1_cd, cat2_cd, cat3_cd
  </select>
</mapper>