<?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.oqpo.api.mapper.stinfo.ItemMapper">

    <select id="selectPopItemGridList" resultType="com.oqpo.api.entity.stinfo.ItemEntity">
        select  /* selectPopItemGridList */
                item_id,item_nm,podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
        from item_base_info
        where brand_id = #{sBrandId}
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
        and  podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
        and  (item_id like concat('%%',#{sItemNm},'%') or item_nm like concat('%%',#{sItemNm},'%') )
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectPopItemGridCnt" resultType="int">
        select /*selectPopItemGridCnt*/
                count(*)
        from item_base_info
        where brand_id = #{sBrandId}
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and  podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and  (item_id like concat('%%',#{sItemNm},'%') or item_nm like concat('%%',#{sItemNm},'%') )
        </if>
    </select>


    <select id="selectItemGridList" resultType="com.oqpo.api.entity.stinfo.ItemEntity">
        select  /* selectItemGridList */
                item.item_id, item.item_nm,item.item_type,  fn_code_nm('ITEM_TYPE',item.item_type) AS item_type_nm
                ,iclas.item_class_mgnt_no as 'itemClassInfo.item_class_mgnt_no',  mclas.item_class_nm  as 'itemClassMngInfo.item_class_nm', item.item_st_cd,  fn_code_nm('ITEM_ST_CD',item.item_st_cd) AS item_st_nm
                ,item.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',item.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
                ,item.unit, fn_code_nm('DSTRBT_COST_UNIT',item.unit) AS unit_nm
                ,item.pch_item_yn, item.sale_item_yn, item.brand_id
        from item_base_info item
        left outer join item_class_ptcl iclas on item.ITEM_ID = iclas.ITEM_ID
        left outer join item_class_mgnt mclas on iclas.item_class_mgnt_no = mclas.item_class_mgnt_no
        <if test="sSpplyId != null and sSpplyId != ''">
        join brand_item_unit_info buinfo on item.brand_id = buinfo.brand_id and item.item_id = buinfo.item_id and buinfo.spply_id = #{sSpplyId}
            and date_format(now(), '%Y%m%d') between  buinfo.cont_stt_dt and buinfo.cont_end_dt
        </if>
        where item.brand_id = #{sBrandId}
        <if test="sItemStCd != null and sItemStCd != ''">
        and  item.item_st_cd = #{sItemStCd}
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
        and  item.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
        <if test="sItemType != null and sItemType != ''">
        and  item.item_type = #{sItemType}
        </if>
        <if test="sItemGubun == 'P'.toString()">
        and item.pch_item_yn = 'Y'
        </if>
        <if test="sItemGubun == 'S'.toString()">
        and item.sale_item_yn = 'Y'
        </if>
        <if test="sClass1 != null and sClass1 != ''">
        and  iclas.item_class1 = #{sClass1}
        </if>
        <if test="sClass2 != null and sClass2 != ''">
        and  iclas.item_class2 = #{sClass2}
        </if>
        <if test="sClass3 != null and sClass3 != ''">
        and  iclas.item_class3 = #{sClass3}
        </if>
        <if test="sClass4 != null and sClass4 != ''">
        and  iclas.item_class4 = #{sClass4}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
        and  (item.item_id like concat('%%',#{sItemNm},'%') or item.item_nm like concat('%%',#{sItemNm},'%') )
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by item.item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by item.item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by item.item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectItemGridCnt" resultType="int">
        select /*selectItemGridCnt*/
                count(*)
        from item_base_info item
        left outer join item_class_ptcl iclas on item.ITEM_ID = iclas.ITEM_ID
        left outer join item_class_mgnt mclas on iclas.item_class_mgnt_no = mclas.item_class_mgnt_no
        <if test="sSpplyId != null and sSpplyId != ''">
            join brand_item_unit_info buinfo on item.brand_id = buinfo.brand_id and item.item_id = buinfo.item_id and buinfo.spply_id = #{sSpplyId}
            and date_format(now(), '%Y%m%d') between  buinfo.cont_stt_dt and buinfo.cont_end_dt
        </if>
        where item.brand_id = #{sBrandId}
        <if test="sItemStCd != null and sItemStCd != ''">
            and  item.item_st_cd = #{sItemStCd}
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and  item.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
        <if test="sItemType != null and sItemType != ''">
            and  item.item_type = #{sItemType}
        </if>
        <if test="sItemGubun == 'P'.toString()">
            and item.pch_item_yn = 'Y'
        </if>
        <if test="sItemGubun == 'S'.toString()">
            and item.sale_item_yn = 'Y'
        </if>
        <if test="sClass1 != null and sClass1 != ''">
            and  iclas.item_class1 = #{sClass1}
        </if>
        <if test="sClass2 != null and sClass2 != ''">
            and  iclas.item_class2 = #{sClass2}
        </if>
        <if test="sClass3 != null and sClass3 != ''">
            and  iclas.item_class3 = #{sClass3}
        </if>
        <if test="sClass4 != null and sClass4 != ''">
            and  iclas.item_class4 = #{sClass4}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and  (item.item_id like concat('%%',#{sItemNm},'%') or item.item_nm like concat('%%',#{sItemNm},'%') )
        </if>
    </select>

    <select id="selectItemInfo" resultType="com.oqpo.api.entity.stinfo.ItemEntity">
        select item.item_id      , item.item_nm     , item.pch_unit, fn_code_nm('DSTRBT_COST_UNIT',item.pch_unit) as pch_unit_nm
             , item.weight     , item.volume     , item.width     , item.height     , item.high     , item.expry_yn
             , item.weight_unit     , item.volume_unit     , item.width_unit     , item.height_unit     , item.high_unit
             , fn_code_nm(upper('weight_unit'), item.weight_unit) as weight_unit_nm     ,  fn_code_nm(upper('volume_unit'), item.volume_unit) as volume_unit_nm
             , fn_code_nm(upper('width_unit'), item.width_unit) as width_unit_nm     , fn_code_nm(upper('height_unit'), item.height_unit) as height_unit_nm
             , fn_code_nm(upper('high_unit'), item.high_unit) as high_unit_nm
             , item.rtn_dvsn, fn_code_nm(upper('rtn_dvsn'), item.rtn_dvsn) as rtn_dvsn_nm     , item.brand_id
             , item.imp_dvsn, fn_code_nm(upper('imp_dvsn'), item.imp_dvsn) as imp_dvsn_nm     , item.asset_info
             , item.stck_unit     , fn_code_nm('DSTRBT_COST_UNIT',item.stck_unit) as stck_unit_nm
             ,  item.podr_pssbl_dvsn, fn_code_nm(upper('podr_pssbl_dvsn'), item.podr_pssbl_dvsn) as podr_pssbl_dvsn_nm     , item.pch_item_yn
             , item.sale_item_yn     , item.item_st_cd, fn_code_nm(upper('item_st_cd'), item.item_st_cd) as item_st_nm
             , item.item_type, fn_code_nm(upper('item_type'), item.item_type) as item_type_nm     , item.sale_unit
             , fn_code_nm('DSTRBT_COST_UNIT', item.sale_unit ) as sale_unit_nm     , item.unit
             , fn_code_nm('DSTRBT_COST_UNIT', item.unit ) as unit_nm     , expry_period
             , item.rtn_pssbl_yn     , item.item_image_file_no     , item.one_box_qty
             , date_format(item.sys_reg_dttm,'%Y.%m.%d %H%i%s') as sys_reg_dttm     , item.sys_reg_id
             , date_format(item.sys_chg_dttm,'%Y.%m.%d %H%i%s') as sys_chg_dttm     , item.sys_chg_id
             , iclas.item_class_mgnt_no as 'itemClassInfo.item_class_mgnt_no'	  , mclas.item_class_nm  as 'itemClassMngInfo.item_class_nm'
             , iclas.item_class1 as  'itemClassInfo.item_class1'  , iclas.item_class2 as  'itemClassInfo.item_class2'
             , iclas.item_class3 as  'itemClassInfo.item_class3' , iclas.item_class4 as  'itemClassInfo.item_class4'
             , mclas.item_level as  'itemClassInfo.item_level'
             , fn_item_class_nm(item.brand_id, iclas.item_class1, '','', '', 1) as  'itemClassInfo.item_class1_nm'
             , fn_item_class_nm(item.brand_id, iclas.item_class1, iclas.item_class2, '','',  2) as  'itemClassInfo.item_class2_nm'
             , fn_item_class_nm(item.brand_id, iclas.item_class1, iclas.item_class2, iclas.item_class3, '',  3) as  'itemClassInfo.item_class3_nm'
             , fn_item_class_nm(item.brand_id, iclas.item_class1, iclas.item_class2, iclas.item_class3, iclas.item_class4,  4) as  'itemClassInfo.item_class4_nm'
             , item.oq_menu_cd, item.oq_brand_id, item.barcode
             , item.store_deli_type, fn_code_nm('STORE_DELI_TYPE',item.store_deli_type) as store_deli_type_nm
        from item_base_info item
        left outer join item_class_ptcl iclas on item.ITEM_ID = iclas.ITEM_ID
        left outer join item_class_mgnt mclas on iclas.item_class_mgnt_no = mclas.item_class_mgnt_no
        where item.brand_id            =  #{brandId}
        and   item.item_id 				 =  #{itemId}
    </select>

    <insert id="insertItemInfo" >
        insert into item_base_info
        (
            item_id, item_nm, pch_unit, weight, volume
            , width, height, high, expry_yn, rtn_dvsn
            , weight_unit, volume_unit, width_unit, height_unit, high_unit
            , brand_id, imp_dvsn, asset_info, stck_unit, podr_pssbl_dvsn
            , pch_item_yn, sale_item_yn, item_st_cd, item_type, sale_unit
            , unit, expry_period, rtn_pssbl_yn, item_image_file_no, one_box_qty
            , sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id
            , oq_brand_id, oq_menu_cd, barcode, store_deli_type
        ) values
        (
            #{entity.itemId}, #{entity.itemNm}, #{entity.pchUnit}, #{entity.weight}, #{entity.volume}
            , #{entity.width}, #{entity.height}, #{entity.high}, #{entity.expryYn}, #{entity.rtnDvsn}
            , #{entity.weightUnit} , #{entity.volumeUnit} , #{entity.widthUnit} , #{entity.heightUnit} , #{entity.highUnit}
            , #{entity.brandId}, #{entity.impDvsn}, #{entity.assetInfo}, #{entity.stckUnit}, #{entity.podrPssblDvsn}
            , #{entity.pchItemYn}, #{entity.saleItemYn}, #{entity.itemStCd}, #{entity.itemType}, #{entity.saleUnit}
            , #{entity.unit}, #{entity.expryPeriod}, #{entity.rtnPssblYn}, #{entity.itemImageFileNo}, #{entity.oneBoxQty}
            , now(), #{userId}, now(), #{userId}
            , #{entity.oqBrandId}, #{entity.oqMenuCd}, #{entity.barcode}, #{entity.storeDeliType}
        )
    </insert>

    <insert id="insertItemClassInfo" >
        insert into item_class_ptcl
            ( item_class_mgnt_no
            , item_id
            , item_nm
            , item_class1
            , item_class2
            , item_class3
            , item_class4
            , sys_reg_dttm
            , sys_reg_id
            , sys_chg_dttm
            , sys_chg_id
        ) values
            ( #{entity.itemClassMgntNo}
            , #{entity.itemId}
            , #{entity.itemNm}
            , #{entity.itemClass1}
            , #{entity.itemClass2}
            , #{entity.itemClass3}
            , #{entity.itemClass4}
            , now()
            , #{userId}
            , now()
            , #{userId}
        )
    </insert>

    <update id="updateItemInfo">
        update item_base_info
        set item_nm            =  #{entity.itemNm}
          , pch_unit           =  #{entity.pchUnit}
          , weight             =  #{entity.weight}
          , volume             =  #{entity.volume}
          , width              =  #{entity.width}
          , height             =  #{entity.height}
          , high               =  #{entity.high}
          , weight_unit        =  #{entity.weightUnit}
          , volume_unit        =  #{entity.volumeUnit}
          , width_unit         =  #{entity.widthUnit}
          , height_unit        =  #{entity.heightUnit}
          , high_unit          =  #{entity.highUnit}
          , expry_yn           =  #{entity.expryYn}
          , rtn_dvsn           =  #{entity.rtnDvsn}
          , brand_id           =  #{entity.brandId}
          , imp_dvsn           =  #{entity.impDvsn}
          , asset_info         =  #{entity.assetInfo}
          , stck_unit          =  #{entity.stckUnit}
          , podr_pssbl_dvsn    =  #{entity.podrPssblDvsn}
          , pch_item_yn        =  #{entity.pchItemYn}
          , sale_item_yn       =  #{entity.saleItemYn}
          , item_st_cd         =  #{entity.itemStCd}
          , item_type          =  #{entity.itemType}
          , sale_unit          =  #{entity.saleUnit}
          , unit               =  #{entity.unit}
          , expry_period         =  #{entity.expryPeriod}
          , rtn_pssbl_yn       =  #{entity.rtnPssblYn}
          , item_image_file_no =  #{entity.itemImageFileNo}
          , one_box_qty        =  #{entity.oneBoxQty}
          , sys_chg_dttm       =  now()
          , sys_chg_id         =  #{userId}
          , oq_brand_id        =  #{entity.oqBrandId}
          , oq_menu_cd         =  #{entity.oqMenuCd}
          , barcode             = #{entity.barcode}
          , store_deli_type    = #{entity.storeDeliType}
        where brand_id            =  #{entity.brandId}
        and   item_id            =  #{entity.itemId}
    </update>

    <update id="updateItemClassInfo">
        update item_class_ptcl
            set item_nm            =  #{entity.itemNm}
              , item_class1        =  #{entity.itemClass1}
              , item_class2        =  #{entity.itemClass2}
              , item_class3        =  #{entity.itemClass3}
              , item_class4        =  #{entity.itemClass4}
              , sys_reg_dttm       =  now()
              , sys_reg_id         =  #{userId}
              , sys_chg_dttm       =  now()
              , sys_chg_id         =  #{userId}
        where item_class_mgnt_no =  #{entity.itemClassMgntNo}
        and   item_id            =  #{entity.itemId}
    </update>

    <delete id="deleteItemClassInfo">
        delete from  item_class_ptcl
        where item_id            =  #{itemId}
    </delete>

    <select id="selectItemClassMngNo" resultType="com.oqpo.api.entity.stinfo.ItemClassMngEntity">
        select item_class_mgnt_no , item_class_nm
        from item_class_mgnt
        where brand_id = #{brandId}
        <if test="class1 != null and class1 != ''">
            and  item_class1 = #{class1}
        </if>
        <if test="class1 == null or class1 == ''">
            and  (item_class1 is null or item_class1 = '' )
        </if>

        <if test="class2 != null and class2 != ''">
            and  item_class2 = #{class2}
        </if>
        <if test="class2 == null or class2 == ''">
            and  (item_class2 is null or item_class2 = '' )
        </if>

        <if test="class3 != null and class3 != ''">
            and  item_class3 = #{class3}
        </if>
        <if test="class3 == null or class3 == ''">
            and  (item_class3 is null or item_class3 = '' )
        </if>
        <if test="class4 != null and class4 != ''">
            and  item_class4 = #{class4}
        </if>
        <if test="class4 == null or class4 == ''">
            and  (item_class4 is null or item_class4 = '' )
        </if>
        limit 1
    </select>

    <insert id="insertItemClassMngInfo" >
        insert into item_class_mgnt
        ( item_class_mgnt_no, item_class1, item_class2, item_class3, item_class4, item_class_nm, item_level
        , del_yn, prn_seq, brand_id, sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id
        ) values
        ( #{entity.itemClassMgntNo}, #{entity.itemClass1}, #{entity.itemClass2}, #{entity.itemClass3}, #{entity.itemClass4}, #{entity.itemClassNm}, #{entity.itemLevel}
        , 'N', #{entity.prnSeq}, #{entity.brandId}, now(), #{userId}, now(), #{userId})
    </insert>

    <update id="updateItemClassMngInfo">
        update item_class_mgnt
        set item_class1        =  #{entity.itemClass1}
            , item_class2        =  #{entity.itemClass2}
            , item_class3        =  #{entity.itemClass3}
            , item_class4        =  #{entity.itemClass4}
            , item_class_nm      =  #{entity.itemClassNm}
            , prn_seq            =  #{entity.prnSeq}
            , brand_id           =  #{entity.brandId}
            , sys_reg_dttm       =  now()
            , sys_reg_id         =  #{userId}
            , sys_chg_dttm       =  now()
            , sys_chg_id         =  #{userId}
        where item_class_mgnt_no =  #{entity.itemClassMgntNo}
    </update>

    <update id="deleteItemClassMngInfo">
        update item_class_mgnt
        set   sys_chg_dttm       =  now()
            , sys_chg_id         =  #{userId}
            , del_yn             =  'Y'
        where 1=1
        and   item_class_mgnt_no  in
        <foreach collection="gridDeleteData" item="item" separator="," open="(" close=")">
            #{item.itemClassMgntNo}
        </foreach>
    </update>



    <select id="selectItemClassMngGridList" resultType="com.oqpo.api.entity.stinfo.ItemClassMngEntity">
        select /* selectItemClassMngGridList */
                 item_class_mgnt_no
                , item_class1        , item_class2        , item_class3        , item_class4        , item_class_nm
                , del_yn        , prn_seq        , brand_id, item_level
                , fn_item_class_nm(brand_id, item_class1, '','', '', 1) as  item_class1_nm
                , fn_item_class_nm(brand_id, item_class1, item_class2, '','',  2) as  item_class2_nm
                , fn_item_class_nm(brand_id, item_class1, item_class2, item_class3, '',  3) as  item_class3_nm
                , fn_item_class_nm(brand_id, item_class1, item_class2, item_class3, item_class4,  4) as  item_class4_nm
        from item_class_mgnt
        where brand_id = #{sBrandId}
        and   del_yn = 'N'
        <if test="sItemClass1 != null and sItemClass1 != ''">
        and   item_class1 = #{sItemClass1}
        </if>
        <if test="sItemClass2 != null and sItemClass2 != ''">
        and   item_class2 = #{sItemClass2}
        </if>
        <if test="sItemClass3 != null and sItemClass3 != ''">
        and   item_class3 = #{sItemClass3}
        </if>
        <if test="sItemClass4 != null and sItemClass4 != ''">
        and   item_class4 = #{sItemClass4}
        </if>
        <if test="sItemClassNm != null and sItemClassNm != ''">
        and   item_class_nm like concat('%',#{sItemClassNm},'%')
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by item_class1 asc, item_class2 asc, item_class3 asc , item_class4 asc , prn_seq asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by item_class1 desc, item_class2 desc, item_class3 desc , item_class4 desc , prn_seq desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by item_class1 asc, item_class2 asc, item_class3 asc , item_class4 asc , prn_seq asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectItemClassMngGridCnt" resultType="int">
        select /* selectItemClassMngGridCnt */
                count(*)
        from item_class_mgnt
        where brand_id = #{sBrandId}
        and   del_yn = 'N'
        <if test="sItemClass1 != null and sItemClass1 != ''">
            and   item_class1 = #{sItemClass1}
        </if>
        <if test="sItemClass2 != null and sItemClass2 != ''">
            and   item_class2 = #{sItemClass2}
        </if>
        <if test="sItemClass3 != null and sItemClass3 != ''">
            and   item_class3 = #{sItemClass3}
        </if>
        <if test="sItemClass4 != null and sItemClass4 != ''">
            and   item_class4 = #{sItemClass4}
        </if>
        <if test="sItemClassNm != null and sItemClassNm != ''">
            and   item_class_nm like concat('%',#{sItemClassNm},'%')
        </if>
    </select>

    <select id="selectItemClassMngInfo" resultType="com.oqpo.api.entity.stinfo.ItemClassMngEntity">
            select /* selectItemClassMngInfo */
                    item_class_mgnt_no
                    , item_class1        , item_class2        , item_class3        , item_class4        , item_class_nm
                    , del_yn        , prn_seq        , brand_id
            from item_class_mgnt
            where brand_id = #{brandId}
            and   item_class_mgnt_no =  #{itemClassMgntNo}
    </select>

    <select id="selectItemClassMaxClass" resultType="Integer">
            select
                    nvl(max(case when #{itemLevel} = 1 then cast(nvl(item_class1,0) as unsigned )
                            when #{itemLevel} = 2 then cast(nvl(item_class2,0) as unsigned )
                            when #{itemLevel} = 3 then cast(nvl(item_class3,0) as unsigned )
                            else   cast(nvl(item_class4,0) as unsigned )  end ),0) + 10 as mno
            from item_class_mgnt
            where brand_id = #{sBrandId}
            <if test="sItemClass1 != null and sItemClass1 != ''">
                and   item_class1 = #{sItemClass1}
            </if>
            <if test="sItemClass2 != null and sItemClass2 != ''">
                and   item_class2 = #{sItemClass2}
            </if>
            <if test="sItemClass3 != null and sItemClass3 != ''">
                and   item_class3 = #{sItemClass3}
            </if>
            <if test="sItemClass4 != null and sItemClass4 != ''">
                and   item_class4 = #{sItemClass4}
            </if>
    </select>

    <select id="selectItemLevelList" resultType="com.oqpo.api.entity.stinfo.ItemClassMngEntity">
        select case when item_level = 1 then item_class1
                    when item_level = 2 then item_class2
                    when item_level = 3 then item_class3
                    when item_level = 4 then item_class4
                    else "" end as item_class
                , item_class_nm
        from  item_class_mgnt
        where brand_id = #{sBrandId}
        and   del_yn = 'N'
        and   item_level = #{sItemLevel}
        <if test="sItemClass1 != null and sItemClass1 != ''">
            and   item_class1 = #{sItemClass1}
        </if>
        <if test="sItemClass2 != null and sItemClass2 != ''">
            and   item_class2 = #{sItemClass2}
        </if>
        <if test="sItemClass3 != null and sItemClass3 != ''">
            and   item_class3 = #{sItemClass3}
        </if>
    </select>

    <select id="selectItemClassBeLongList" resultType="com.oqpo.api.entity.stinfo.ItemClassMngEntity">
        select item_class_mgnt_no
        from  item_class_mgnt
        where brand_id = #{brandId}
        and   concat(item_class1 , item_class2, item_class3, item_class4) like (
                    select concat(item_class1 , item_class2, item_class3, item_class4,'%') as class_info
                    from item_class_mgnt
                    where item_class_mgnt_no =  #{itemClassMgntNo}
                    )
    </select>


    <select id="selectOqToItemId" resultType="com.oqpo.api.entity.stinfo.ItemEntity">
        select item_id, item_nm
        from   item_base_info
        where  brand_id = #{brandId}
        and    oq_menu_cd = #{oqMenuCd}
    </select>


</mapper>
