<?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.ItemUnitMapper">

    <select id="selectItemUnitGridList" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /*selectItemUnitGridList*/
                iunit.brand_unit_unq_no, iunit.brand_id, iunit.item_id, iunit.item_nm, iunit.spply_id,
                iunit.spply_nm, date_format(iunit.cont_stt_dt,'%Y.%m.%d') as cont_stt_dt, date_format(iunit.cont_end_dt,'%Y.%m.%d') as cont_end_dt,
                iunit.curr, fn_code_nm('CURR', iunit.curr) as curr_nm, iunit.unit, fn_code_nm('DSTRBT_COST_UNIT', iunit.unit) as unit_nm,
                iunit.unit_amt, iunit.lead_time, iunit.spply_item_id,
                iunit.unit_st_cd, fn_code_nm('UNIT_ST_CD', iunit.unit_st_cd) as unit_st_nm, iunit.stdd_qty
        from  brand_item_unit_info iunit
        join  item_base_info item on iunit.brand_id = item.brand_id and iunit.item_id = item.item_id
        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 iunit.brand_id = #{sBrandId}
        <if test="fromDt != null and fromDt != '' and toDt != null and toDt != ''">
          and iunit.cont_stt_dt between #{fromDt} and #{toDt}
          and #{toDt}  between iunit.cont_stt_dt and iunit.cont_end_dt
        </if>
        <if test="sUnitStCd != null and sUnitStCd != ''">
        and   iunit.unit_st_cd = #{sUnitStCd}
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
        and   iunit.spply_id = #{sSpplyId}
        </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   iunit.item_id like concat('%',#{sItemNm},'%') or iunit.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 iunit.item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by iunit.item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by iunit.item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectItemUnitGridCnt" resultType="int">
        select /*selectBrandGridCnt*/
                count(*)
        from  brand_item_unit_info iunit
        join  item_base_info item on iunit.brand_id = item.brand_id and iunit.item_id = item.item_id
        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 iunit.brand_id = #{sBrandId}
        <if test="fromDt != null and fromDt != '' and toDt != null and toDt != ''">
            and iunit.cont_stt_dt between #{fromDt} and #{toDt}
            and #{toDt}  between iunit.cont_stt_dt and iunit.cont_end_dt
        </if>
        <if test="sUnitStCd != null and sUnitStCd != ''">
            and   iunit.unit_st_cd = #{sUnitStCd}
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
            and   iunit.spply_id = #{sSpplyId}
        </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   iunit.item_id like concat('%',#{sItemNm},'%') or iunit.item_nm like concat('%',#{sItemNm},'%')
        </if>
    </select>

    <select id="selectItemUnitInfo" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /*selectItemUnitInfo*/
                iunit.brand_unit_unq_no, iunit.brand_id, fn_brand_nm(iunit.brand_id) as  brand_nm,  iunit.item_id, iunit.item_nm, iunit.spply_id,
                iunit.spply_nm, date_format(iunit.cont_stt_dt,'%Y.%m.%d') as cont_stt_dt, date_format(iunit.cont_end_dt,'%Y.%m.%d') as cont_end_dt,
                iunit.curr, fn_code_nm('CURR', iunit.curr) as curr_nm, iunit.unit, fn_code_nm('DSTRBT_COST_UNIT', iunit.unit) as unit,
                iunit.unit_amt, iunit.lead_time, iunit.spply_item_id,
                iunit.dlv_cndt, fn_code_nm('DLV_CNDT', iunit.dlv_cndt) as dlv_cndt_nm,
                iunit.unit_st_cd, fn_code_nm('UNIT_ST_CD', iunit.unit_st_cd) as unit_st_nm, iunit.stdd_qty,
                iunit.store_sale_stdd_qty, iunit.store_sale_unit_amt, iunit.short_cont_file_no,
                date_format(iunit.sys_reg_dttm,'%Y.%m.%d %H:%i:%s') as sys_reg_dttm, iunit.sys_reg_id, date_format(iunit.sys_chg_dttm,'%Y.%m.%d %H:%i:%s') as  sys_chg_dttm, iunit.sys_chg_id
        from  brand_item_unit_info iunit
        where iunit.brand_unit_unq_no = #{brandUnitUnqNo}
        and   iunit.brand_id = #{brandId}
    </select>

    <select id="selectItemUnitDupCnt" resultType="int">
        select /* selectItemUnitDupCnt */
               count(*) as cnt
        from   brand_item_unit_info
        where  brand_id = #{brandId}
        and    spply_id = #{spplyId}
        and    item_id  = #{itemId}
        and    date_format(cont_end_dt,'%Y%m%d') <![CDATA[ >= ]]> date_format(#{contSttDt} ,'%Y%m%d')
    </select>

    <select id="selectItemUnitChaPass" resultType="String">
        select  case when cont_stt_dt = #{contSttDt} then 'Y' else 'N' end
        from  brand_item_unit_info
        where brand_unit_unq_no =#{brandUnitUnqNo}
    </select>

    <update id="updateItemUnitContEnd" >
        update /* updateItemUnitContEnd */
                brand_item_unit_info
        set    cont_end_dt =  DATE_SUB(date_format(#{contEndDt},'%Y%m%d'), INTERVAL 1 DAY)
        where  brand_id = #{brandId}
        and    brand_unit_unq_no = #{brandUnitUnqNo}

    </update>

    <insert id="insertItemUnitInfo" >
        insert into  /**  insertItemUnitInfo */
        brand_item_unit_info
            (brand_unit_unq_no, brand_id, item_id, item_nm, spply_id,
            spply_nm, cont_stt_dt, cont_end_dt, curr, unit,
            unit_amt, lead_time, dlv_cndt, short_cont_file_no, spply_item_id,
            unit_st_cd, stdd_qty, store_sale_stdd_qty, store_sale_unit_amt,
            sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        values
            ( fn_get_dealno(33,''), #{entity.brandId}, #{entity.itemId}, #{entity.itemNm}, #{entity.spplyId},
            #{entity.spplyNm}, #{entity.contSttDt}, #{entity.contEndDt}, #{entity.curr}, #{entity.unit},
            #{entity.unitAmt}, #{entity.leadTime}, #{entity.dlvCndt}, #{entity.shortContFileNo}, #{entity.spplyItemId},
            #{entity.unitStCd}, #{entity.stddQty}, #{entity.storeSaleStddQty}, #{entity.storeSaleUnitAmt},
            now(), #{userId}, now(), #{userId})
    </insert>

    <update id="updateItemUnitInfo" >
            update brand_item_unit_info
            set sys_chg_dttm    = now()
            ,sys_chg_id      = #{userId}
            ,cont_stt_dt     = #{entity.contSttDt}
            ,cont_end_dt     = #{entity.contEndDt}
            ,curr            = #{entity.curr}
            ,unit            = #{entity.unit}
            ,unit_amt        = #{entity.unitAmt}
            ,lead_time       = #{entity.leadTime}
            ,dlv_cndt        = #{entity.dlvCndt}
            ,short_cont_file_no = #{entity.shortContFileNo}
            ,unit_st_cd      = #{entity.unitStCd}
            ,stdd_qty        = #{entity.stddQty}
            ,store_sale_stdd_qty = #{entity.storeSaleStddQty}
            ,store_sale_unit_amt = #{entity.storeSaleUnitAmt}
        where brand_unit_unq_no = #{entity.brandUnitUnqNo}
    </update>

    <insert id="insertMergItemUnitInfo" >
        insert into  /** Merge insertMergItemUnitInfo */
        brand_item_unit_info
        (brand_unit_unq_no, brand_id, item_id, item_nm, spply_id,
        spply_nm, cont_stt_dt, cont_end_dt, curr, unit,
        unit_amt, lead_time, dlv_cndt, short_cont_file_no, spply_item_id,
        unit_st_cd, stdd_qty, store_sale_stdd_qty, store_sale_unit_amt,
        sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        values
            ( fn_get_dealno(33,''), #{entity.brandId}, #{entity.itemId}, #{entity.itemNm}, #{entity.spplyId},
            #{entity.spplyNm}, #{entity.contSttDt}, #{entity.contEndDt}, #{entity.curr}, #{entity.unit},
            #{entity.unitAmt}, #{entity.leadTime}, #{entity.dlvCndt}, #{entity.shortContFileNo}, #{entity.spplyItemId},
            #{entity.unitStCd}, #{entity.stddQty}, #{entity.storeSaleStddQty}, #{entity.storeSaleUnitAmt},
            now(), #{userId}, now(), #{userId})
        on duplicate key
        update
            sys_chg_dttm    = now()
            ,sys_chg_id      = #{userId}
            ,cont_stt_dt     = VALUES(cont_stt_dt)
            ,cont_end_dt     = VALUES(cont_end_dt)
            ,curr            = VALUES(curr)
            ,unit            = VALUES(unit)
            ,unit_amt        = VALUES(unit_amt)
            ,lead_time       = VALUES(lead_time)
            ,dlv_cndt        = VALUES(dlv_cndt)
            ,short_cont_file_no = VALUES(short_cont_file_no)
            ,unit_st_cd      = VALUES(unit_st_cd)
            ,stdd_qty        = VALUES(stdd_qty)
            ,store_sale_stdd_qty =VALUES(store_sale_stdd_qty)
            ,store_sale_unit_amt = VALUES(store_sale_unit_amt)
    </insert>

    <select id="selectPopItemBrandUnitGridList" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /* selectPopItemBrandUnitGridList */
                iInfo.item_id,iInfo.item_nm,iInfo.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',iInfo.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
                ,bInfo.unit, fn_code_nm('DSTRBT_COST_UNIT', bInfo.unit) as unit_nm, bInfo.stdd_qty, bInfo.unit_amt, bInfo.brand_unit_unq_no
                ,'B' as unit_gubun, bInfo.spply_id, fn_spply_nm(bInfo.spply_id) as spplyNm
                <if test="sWhsId == null or sWhsId == '' or sLocation = null or sLocation == ''">
                ,0 as whs_pass_qty
                </if>
                <if test="sWhsId != null and sWhsId != '' and sLocation != null and sLocation != ''">
                , nvl((stck.stck_qty - stck.wait_qty),0) as whs_pass_qty
                </if>
        from item_base_info iInfo
        join brand_item_unit_info bInfo on iInfo.brand_id = bInfo.brand_id and iInfo.item_id = bInfo.item_id and date_format(now(),'%Y%m%d') between bInfo.cont_stt_dt and bInfo.cont_end_dt
        <if test="sSpplyId != null and sSpplyId != '' ">
          and bInfo.spply_id = #{sSpplyId}
        </if>

        <if test="sWhsId != null and sWhsId != '' and sLocation != null and sLocation != ''">
            left outer join stck_mgnt_base_info stck on stck.brand_id = iInfo.brand_id and stck.item_id = iInfo.item_id and whs_id = #{sWhsId} and location = #{sLocation}
        </if>
        where iInfo.brand_id = #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </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 iInfo.item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by iInfo.item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by iInfo.item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectPopItemBrandUnitGridCnt" resultType="int">
        select  /* selectPopItemBrandUnitGridCnt */
                count(*)
        from item_base_info iInfo
        join brand_item_unit_info bInfo on iInfo.brand_id = bInfo.brand_id and iInfo.item_id = bInfo.item_id and date_format(now(),'%Y%m%d') between bInfo.cont_stt_dt and bInfo.cont_end_dt
        <if test="sSpplyId != null and sSpplyId != '' ">
            and bInfo.spply_id = #{sSpplyId}
        </if>
        where iInfo.brand_id = #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
    </select>


    <select id="selectPopNewItemBrandUnitGridList" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /* selectPopNewItemBrandUnitGridList */
        iInfo.item_id,iInfo.item_nm,iInfo.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',iInfo.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
        ,iInfo.unit, fn_code_nm('DSTRBT_COST_UNIT', iInfo.unit) as unit_nm, bInfo.stdd_qty, bInfo.unit_amt, bInfo.brand_unit_unq_no
        ,'B' as unit_gubun, bInfo.spply_id
        <if test="sWhsId == null or sWhsId == '' or sLocation = null or sLocation == ''">
            ,0 as whs_pass_qty
        </if>
        <if test="sWhsId != null and sWhsId != '' and sLocation != null and sLocation != ''">
            , nvl((stck.stck_qty - stck.wait_qty),0) as whs_pass_qty
        </if>
        from item_base_info iInfo
        left outer join brand_item_unit_info bInfo on iInfo.brand_id = bInfo.brand_id and iInfo.item_id = bInfo.item_id and date_format(now(),'%Y%m%d') between bInfo.cont_stt_dt and bInfo.cont_end_dt
        <if test="sSpplyId != null and sSpplyId != '' ">
            and bInfo.spply_id = #{sSpplyId}
        </if>

        <if test="sWhsId != null and sWhsId != '' and sLocation != null and sLocation != ''">
            left outer join stck_mgnt_base_info stck on stck.brand_id = iInfo.brand_id and stck.item_id = iInfo.item_id and whs_id = #{sWhsId} and location = #{sLocation}
        </if>
        where iInfo.brand_id = #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </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 iInfo.item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by iInfo.item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by iInfo.item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectPopNewItemBrandUnitGridCnt" resultType="int">
        select  /* selectPopNewItemBrandUnitGridCnt */
        count(*)
        from item_base_info iInfo
        left outer join brand_item_unit_info bInfo on iInfo.brand_id = bInfo.brand_id and iInfo.item_id = bInfo.item_id and date_format(now(),'%Y%m%d') between bInfo.cont_stt_dt and bInfo.cont_end_dt
        <if test="sSpplyId != null and sSpplyId != '' ">
            and bInfo.spply_id = #{sSpplyId}
        </if>
        where iInfo.brand_id = #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
    </select>

    <select id="selectPopItemStoreUnitGridList" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /* selectPopItemStoreUnitGridList */
                iInfo.item_id,iInfo.item_nm,iInfo.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',iInfo.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
                ,sInfo.unit, fn_code_nm('DSTRBT_COST_UNIT', sInfo.unit) as unit_nm, sInfo.stdd_qty, sInfo.unit_amt, sInfo.store_unit_unq_no
                ,'S' as unit_gubun, sInfo.brand_unit_unq_no
                , 0 as whs_pass_qty, '' as spply_id
        from item_base_info iInfo
        join store_base_info store on iInfo.brand_id = store.brand_id   and store.store_id = #{sStoreId}
        join store_item_unit_info sInfo on iInfo.brand_id = sInfo.brand_id and iInfo.item_id = sInfo.item_id and sInfo.unit_target_cd = 'Y'
        and store.store_id = sInfo.store_id  and sInfo.store_id =  #{sStoreId}
        and date_format(now(),'%Y%m%d') between sInfo.cont_stt_dt and sInfo.cont_end_dt
        where iInfo.brand_id =  #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </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 iInfo.item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by iInfo.item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by iInfo.item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectPopItemStoreUnitGridCnt" resultType="int">
        select  /* selectPopItemStoreUnitGridCnt */
               count(*)
        from item_base_info iInfo
        join store_base_info store on iInfo.brand_id = store.brand_id   and store.store_id = #{sStoreId}
        join store_item_unit_info sInfo on iInfo.brand_id = sInfo.brand_id and iInfo.item_id = sInfo.item_id and sInfo.unit_target_cd = 'Y'
        and store.store_id = sInfo.store_id  and sInfo.store_id =  #{sStoreId}
        and date_format(now(),'%Y%m%d') between sInfo.cont_stt_dt and sInfo.cont_end_dt
        where iInfo.brand_id =  #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
    </select>

    <select id="selectPopNewItemStoreUnitGridList" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /* selectPopNewItemStoreUnitGridList */
        iInfo.item_id,iInfo.item_nm,iInfo.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',iInfo.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
        ,iInfo.unit, fn_code_nm('DSTRBT_COST_UNIT', iInfo.unit) as unit_nm, sInfo.stdd_qty, sInfo.unit_amt, sInfo.store_unit_unq_no
        ,'S' as unit_gubun, sInfo.brand_unit_unq_no
        , 0 as whs_pass_qty, '' as spply_id
        from item_base_info iInfo
        join store_base_info store on iInfo.brand_id = store.brand_id   and store.store_id = #{sStoreId}
        join store_item_unit_info sInfo on iInfo.brand_id = sInfo.brand_id and iInfo.item_id = sInfo.item_id and sInfo.unit_target_cd = 'Y'
        and store.store_id = sInfo.store_id  and sInfo.store_id =  #{sStoreId}
        and date_format(now(),'%Y%m%d') between sInfo.cont_stt_dt and sInfo.cont_end_dt
        where iInfo.brand_id =  #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </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 iInfo.item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by iInfo.item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by iInfo.item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectPopNewItemStoreUnitGridCnt" resultType="int">
        select  /* selectPopNewItemStoreUnitGridCnt */
        count(*)
        from item_base_info iInfo
        join store_base_info store on iInfo.brand_id = store.brand_id   and store.store_id = #{sStoreId}
        join store_item_unit_info sInfo on iInfo.brand_id = sInfo.brand_id and iInfo.item_id = sInfo.item_id and sInfo.unit_target_cd = 'Y'
        and store.store_id = sInfo.store_id  and sInfo.store_id =  #{sStoreId}
        and date_format(now(),'%Y%m%d') between sInfo.cont_stt_dt and sInfo.cont_end_dt
        where iInfo.brand_id =  #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        <if test="sItemNm != null and sItemNm != ''">
            and  (iInfo.item_nm like concat('%',#{sItemNm},'%') or iInfo.item_id like concat('%',#{sItemNm},'%'))
        </if>
        <if test="sPodrPssblDvsn != null and sPodrPssblDvsn != ''">
            and   iInfo.podr_pssbl_dvsn = #{sPodrPssblDvsn}
        </if>
    </select>


    <select id="selectBarcodeItemBrandUnitInfo" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /* selectBarcodeItemBrandUnitInfo */
            iInfo.item_id,iInfo.item_nm,iInfo.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',iInfo.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
            ,bInfo.unit, fn_code_nm('DSTRBT_COST_UNIT', bInfo.unit) as unit_nm, bInfo.stdd_qty, bInfo.unit_amt, bInfo.brand_unit_unq_no
            ,'B' as unit_gubun, bInfo.spply_id, fn_spply_nm(bInfo.spply_id) as spplyNm
            ,0 as whs_pass_qty
        from item_base_info iInfo
        join brand_item_unit_info bInfo on iInfo.brand_id = bInfo.brand_id and iInfo.item_id = bInfo.item_id and date_format(now(),'%Y%m%d') between bInfo.cont_stt_dt and bInfo.cont_end_dt
        where iInfo.brand_id = #{sBrandId}
        and   iInfo.barcode = #{sBarcode}
        AND   iInfo.item_st_cd = 'IS00'
        and   iInfo.podr_pssbl_dvsn = 'PO01'
    </select>


    <select id="selectBarcodeItemStoreUnitInfo" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /* selectBarcodeItemStoreUnitInfo */
                iInfo.item_id,iInfo.item_nm,iInfo.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',iInfo.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
                ,sInfo.unit, fn_code_nm('DSTRBT_COST_UNIT', sInfo.unit) as unit_nm, sInfo.stdd_qty, sInfo.unit_amt, sInfo.store_unit_unq_no
                ,'S' as unit_gubun, sInfo.brand_unit_unq_no
                , 0 as whs_pass_qty, '' as spply_id
        from item_base_info iInfo
        join store_base_info store on iInfo.brand_id = store.brand_id   and store.store_id = #{sStoreId}
        join store_item_unit_info sInfo on iInfo.brand_id = sInfo.brand_id and iInfo.item_id = sInfo.item_id and sInfo.unit_target_cd = 'Y'
        and store.store_id = sInfo.store_id  and sInfo.store_id =  #{sStoreId}
        and date_format(now(),'%Y%m%d') between sInfo.cont_stt_dt and sInfo.cont_end_dt
        where iInfo.brand_id =  #{sBrandId}
        and   iInfo.barcode = #{sBarcode}
        AND   iInfo.item_st_cd = 'IS00'
        and   iInfo.podr_pssbl_dvsn = 'PO01'
    </select>

    <select id="selectPopWishGridList" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        SELECT mgnt.wish_list_mgnt_no, mgnt.wish_list_nm
        FROM store_wish_list_mgnt mgnt
        WHERE 1 = 1
        AND mgnt.store_id =  #{sStoreId}
        AND mgnt.del_yn = 'N'
    </select>

    <select id="selectPopItemStoreUnitWishGridList" resultType="com.oqpo.api.entity.stinfo.ItemUnitEntity">
        select  /* selectPopItemStoreUnitWishGridList */
            iInfo.item_id,iInfo.item_nm,iInfo.podr_pssbl_dvsn, fn_code_nm('PODR_PSSBL_DVSN',iInfo.podr_pssbl_dvsn) AS podr_pssbl_dvsn_nm
            ,sInfo.unit, fn_code_nm('DSTRBT_COST_UNIT', sInfo.unit) as unit_nm, sInfo.stdd_qty, sInfo.unit_amt, sInfo.store_unit_unq_no
            ,'S' as unit_gubun, sInfo.brand_unit_unq_no
            , 0 as whs_pass_qty, '' as spply_id
        from item_base_info iInfo
        join store_base_info store on iInfo.brand_id = store.brand_id   and store.store_id = #{sStoreId}
        join store_item_unit_info sInfo on iInfo.brand_id = sInfo.brand_id and iInfo.item_id = sInfo.item_id and sInfo.unit_target_cd = 'Y'
                and store.store_id = sInfo.store_id  and sInfo.store_id =  #{sStoreId}
                and date_format(now(),'%Y%m%d') between sInfo.cont_stt_dt and sInfo.cont_end_dt
        join store_wish_list_mgnt wishmng on sInfo.store_id = wishmng.store_id and  wishmng.wish_list_mgnt_no = #{sWishListMgntNo} and wishmng.del_yn = 'N'
        join store_wish_list_ptcl wishptcl on wishmng.wish_list_mgnt_no = wishptcl.wish_list_mgnt_no and iInfo.item_id = wishptcl.item_id
        where iInfo.brand_id =  #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        and   iInfo.podr_pssbl_dvsn = 'PO01'
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by iInfo.item_nm asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by iInfo.item_nm desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by iInfo.item_nm asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectPopItemStoreUnitWishGridCnt" resultType="int">
        select  /* selectPopItemStoreUnitWishGridCnt */
        count(*)
        from item_base_info iInfo
        join store_base_info store on iInfo.brand_id = store.brand_id   and store.store_id = #{sStoreId}
        join store_item_unit_info sInfo on iInfo.brand_id = sInfo.brand_id and iInfo.item_id = sInfo.item_id and sInfo.unit_target_cd = 'Y'
             and store.store_id = sInfo.store_id  and sInfo.store_id =  #{sStoreId}
             and date_format(now(),'%Y%m%d') between sInfo.cont_stt_dt and sInfo.cont_end_dt
        join store_wish_list_mgnt wishmng on sInfo.store_id = wishmng.store_id and  wishmng.wish_list_mgnt_no = #{sWishListMgntNo} and wishmng.del_yn = 'N'
        join store_wish_list_ptcl wishptcl on wishmng.wish_list_mgnt_no = wishptcl.wish_list_mgnt_no and iInfo.item_id = wishptcl.item_id
        where iInfo.brand_id =  #{sBrandId}
        AND   iInfo.item_st_cd = 'IS00'
        and   iInfo.podr_pssbl_dvsn = 'PO01'
    </select>
</mapper>
