<?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.rtnmng.RtnReqMapper">

    <insert id="insertRtnReqBaseInfo" >
       INSERT INTO rtn_req_base_info  /* RtnReqMapper.insertRtnReqBaseInfo */
        (rtn_req_unq_no, store_id, brand_id, rtn_req_dt, rtn_req_tm
        , rtn_req_st_cd, rtn_req_mgr_id, rtn_req_mgr_nm,  rtn_req_mgr_tel_no
        , whs_dvsn, col_req_dt, note, rtn_rjct_dt, rtn_rjct_nm
        , rtn_rjct_id, rtn_rjct_rsn, rtn_req_amt, rtn_req_item_qty, rtn_whs_id, rtn_location
        , sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        VALUES
        (#{entity.rtnReqUnqNo}, #{entity.storeId}, #{entity.brandId}, case when #{entity.rtnReqStCd} = 'RR20' then  date_format(now(),'%Y%m%d') else null end , #{entity.rtnReqTm}
        , #{entity.rtnReqStCd}, #{userId}, #{entity.rtnReqMgrNm}, #{entity.rtnReqMgrTelNo}
        , #{entity.whsDvsn}, #{entity.colReqDt}, #{entity.note}, #{entity.rtnRjctDt}, #{entity.rtnRjctNm}
        , #{entity.rtnRjctId}, #{entity.rtnRjctRsn}, #{entity.rtnReqAmt}, #{entity.rtnReqItemQty}, #{entity.rtnWhsId}, #{entity.rtnLocation}
        , NOW(), #{userId}, NOW(), #{userId})

    </insert>

    <update id="updateRtnReqBaseInfo">
        UPDATE rtn_req_base_info SET   /* RtnReqMapper.updateRtnReqBaseInfo */
                rtn_req_dt = case when #{entity.rtnReqStCd} = 'RR20' then  date_format(now(),'%Y%m%d')  else null end,
                rtn_req_tm = #{entity.rtnReqTm},
                rtn_req_st_cd = #{entity.rtnReqStCd},
                whs_dvsn = #{entity.whsDvsn},
                col_req_dt = #{entity.colReqDt},
                note = #{entity.note},
                rtn_req_amt = #{entity.rtnReqAmt},
                rtn_req_item_qty = #{entity.rtnReqItemQty},
                rtn_whs_id = #{entity.rtnWhsId},
                rtn_location = #{entity.rtnLocation},
                sys_chg_dttm = NOW(),
                sys_chg_id = #{userId}
        WHERE rtn_req_unq_no = #{entity.rtnReqUnqNo}
        AND   brand_id = #{entity.brandId}
    </update>


    <insert id="insertRtnReqDtlPtcl" >
        INSERT INTO rtn_req_dtl_ptcl  /* RtnReqMapper.insertRtnReqDtlPtcl */
        (rtn_req_unq_no, rtn_req_dtl_no, item_id, item_nm, unit
        , rtn_qty, rtn_amt, rtn_dvsn, rtn_rsn
        , spply_id, unit_amt, store_unit_unq_no, brand_unit_unq_no, rtn_rsn_dvsn, unit_gubun
        , sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        VALUES
        <foreach collection="gridInsertData" item="item" separator=",">
        (#{item.rtnReqUnqNo}, #{item.rtnReqDtlNo}, #{item.itemId}, #{item.itemNm}, #{item.unit}
        , #{item.rtnQty}, #{item.rtnAmt}, #{item.rtnDvsn}, #{item.rtnRsn}
        , #{item.spplyId}, #{item.unitAmt}, #{item.storeUnitUnqNo}, #{item.brandUnitUnqNo}, #{item.rtnRsnDvsn}, #{item.unitGubun}
        , NOW(), #{userId}, NOW(), #{userId})
        </foreach>
    </insert>

    <update id="updateRtnReqDtlPtcl">
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE rtn_req_dtl_ptcl SET    /* RtnReqMapper.updateRtnReqDtlPtcl */
                    rtn_qty = #{item.rtnQty},
                    rtn_amt = #{item.rtnAmt},
                    rtn_dvsn = #{item.rtnDvsn},
                    rtn_rsn = #{item.rtnRsn},
                    rtn_rsn_dvsn = #{item.rtnRsnDvsn},
                    sys_chg_dttm = NOW(),
                    sys_chg_id = #{userId}
            WHERE rtn_req_unq_no = #{item.rtnReqUnqNo}
            AND rtn_req_dtl_no  = #{item.rtnReqDtlNo}
        </foreach>
    </update>

    <delete id="deleteRtnReqDtlPtcl">
        DELETE FROM rtn_req_dtl_ptcl  /* RtnReqMapper.deleteRtnReqDtlPtcl */
        WHERE rtn_req_unq_no = #{rtnReqUnqNo}
        AND rtn_req_dtl_no in
        <foreach collection="gridDeleteData" item="item" separator="," open="(" close=")">
            #{item.rtnReqDtlNo}
        </foreach>
    </delete>

    <select id="selectMaxRtnReqDtlNo" resultType="int">
            SELECT nvl(Max(convert(rtn_req_dtl_no,int)),0)
            FROM rtn_req_dtl_ptcl
            WHERE  rtn_req_unq_no = #{rtnReqUnqNo}
    </select>

    <select id="selectSumRtnAmt" resultType="com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity">
            select count(*) as rtn_req_item_qty,  nvl(sum(rtn_amt),0) as rtn_req_amt
            from  rtn_req_dtl_ptcl
            where rtn_req_unq_no = #{rtnReqUnqNo}
    </select>

    <select id="selectRtnReqGridList" resultType="com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity">
        select  base.brand_id, fn_brand_nm(base.brand_id) as brand_nm
                ,base.store_id , fn_store_nm(base.brand_id, base.store_id) as store_nm
                , base.rtn_req_unq_no
                , base.rtn_req_st_cd, fn_code_nm(upper('rtn_req_st_cd'), base.rtn_req_st_cd) as rtn_req_st_nm
                , base.rtn_whs_id, base.rtn_location, fn_whs_nm(base.brand_id, base.rtn_whs_id) as rtn_whs_nm
                , fn_whs_location_nm(base.brand_id, base.rtn_whs_id, base.rtn_location) as rtn_location_nm
                , date_format(base.rtn_req_dt, '%Y.%m.%d') as rtn_req_dt, base.rtn_req_item_qty, base.rtn_req_amt
                , date_format(base.col_req_dt, '%Y.%m.%d') as col_req_dt, base.rtn_req_mgr_nm, base.rtn_req_mgr_id
                , date_format(base.rtn_rjct_dt, '%Y.%m.%d') as rtn_rjct_dt, base.rtn_rjct_nm
        from rtn_req_base_info base
        where 1 = 1
        and base.brand_id = #{sBrandId}
        and base.col_req_dt between #{fromDt} and #{toDt}
        <if test="sStoreId != null and sStoreId != ''">
            and base.store_id = #{sStoreId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
        and base.rtn_whs_id = #{sWhsId}
        </if>
        <if test="sRtnReqStCd != null and sRtnReqStCd != ''">
        and base.rtn_req_st_cd = #{sRtnReqStCd}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
        and base.rtn_req_unq_no in (select  ptcl.rtn_req_unq_no
                                    from rtn_req_base_info sbase,
                                        rtn_req_dtl_ptcl  ptcl
                                    where sbase.rtn_req_unq_no = ptcl.rtn_req_unq_no
                                    and   sbase.brand_id = #{sBrandId}
                                    and   sbase.col_req_dt between #{fromDt} and #{toDt}
                                    <if test="sStoreId != null and sStoreId != ''">
                                        and sbase.store_id = #{sStoreId}
                                    </if>
                                    <if test="sWhsId != null and sWhsId != ''">
                                        and sbase.rtn_whs_id = #{sWhsId}
                                    </if>
                                    <if test="sRtnReqStCd != null and sRtnReqStCd != ''">
                                        and sbase.rtn_req_st_cd = #{sRtnReqStCd}
                                    </if>
                                    and   (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.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 base.rtn_req_unq_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by base.rtn_req_unq_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by base.rtn_req_unq_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectRtnReqGridCnt" resultType="int">
        select count(*)
        from rtn_req_base_info base
        where 1 = 1
        and base.brand_id = #{sBrandId}
        and base.col_req_dt between #{fromDt} and #{toDt}
        <if test="sStoreId != null and sStoreId != ''">
            and base.store_id = #{sStoreId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
            and base.rtn_whs_id = #{sWhsId}
        </if>
        <if test="sRtnReqStCd != null and sRtnReqStCd != ''">
            and base.rtn_req_st_cd = #{sRtnReqStCd}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and base.rtn_req_unq_no in (select  ptcl.rtn_req_unq_no
                                        from rtn_req_base_info sbase,
                                        rtn_req_dtl_ptcl  ptcl
                                        where sbase.rtn_req_unq_no = ptcl.rtn_req_unq_no
                                        and   sbase.brand_id = #{sBrandId}
                                        and   sbase.col_req_dt between #{fromDt} and #{toDt}
                                        <if test="sStoreId != null and sStoreId != ''">
                                            and sbase.store_id = #{sStoreId}
                                        </if>
                                        <if test="sWhsId != null and sWhsId != ''">
                                            and sbase.rtn_whs_id = #{sWhsId}
                                        </if>
                                        <if test="sRtnReqStCd != null and sRtnReqStCd != ''">
                                            and sbase.rtn_req_st_cd = #{sRtnReqStCd}
                                        </if>
                                        and   (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%')) )
        </if>
    </select>

    <select id="selectRtnReqInfo" resultType="com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity">
        SELECT rtn_req_unq_no, brand_id, fn_brand_nm(brand_id) as brand_nm
                , store_id, fn_store_nm(brand_id, store_id) as store_nm
                , date_format(rtn_req_dt,'%Y.%m.%d') as rtn_req_dt, rtn_req_st_cd, fn_code_nm('RTN_REQ_ST_Cd',rtn_req_st_cd) as rtn_req_st_nm
                , rtn_req_mgr_id, rtn_req_mgr_nm, whs_dvsn, fn_code_nm('WHS_DVSN',whs_dvsn) as whs_dvsn_nm
                , date_format(col_req_dt,'%Y.%m.%d') as col_req_dt, note, date_format(rtn_rjct_dt,'%Y.%m.%d') as rtn_rjct_dt, rtn_rjct_nm, rtn_rjct_id
                , rtn_rjct_rsn, rtn_req_amt, rtn_req_item_qty
                , rtn_whs_id, fn_whs_nm(brand_id, rtn_whs_id) as rtn_whs_nm
                , rtn_location, fn_whs_location_nm(brand_id, rtn_whs_id, rtn_location) as rtn_location_nm
                , date_format(sys_reg_dttm,'%Y.%m.%d') AS sys_reg_dttm, sys_reg_id, date_format(sys_chg_dttm,'%Y.%m.%d') AS sys_chg_dttm, sys_chg_id
        FROM rtn_req_base_info
        WHERE 1=1
        AND   brand_id = #{brandId}
        <if test="storeId != null and storeId != ''">
            and store_id = #{storeId}
        </if>
        AND   rtn_req_unq_no = #{rtnReqUnqNo}
    </select>

    <select id="selectRtnReqDtlList" resultType="com.oqpo.api.entity.rtnmng.RtnReqDtlPtclEntity">
        SELECT rtn_req_unq_no, rtn_req_dtl_no, item_id, item_nm, unit
                , rtn_qty, rtn_amt, rtn_dvsn, fn_code_nm('RTN_DVSN',rtn_dvsn) as rtn_dvsn_nm
                , rtn_rsn, spply_id
                , unit_amt, store_unit_unq_no, brand_unit_unq_no, rtn_rsn_dvsn, fn_code_nm('RTN_RSN_DVSN',rtn_rsn_dvsn) as rtn_rsn_dvsn_nm
                , unit_gubun, fn_code_nm('UNIT_GUBUN',unit_gubun) as unit_gubun_nm
                , rtn_req_dtl_st_cd , fn_code_nm('RTN_REQ_DTL_ST_CD', rtn_req_dtl_st_cd) as rtn_req_dtl_st_nm
        FROM rtn_req_dtl_ptcl
        WHERE rtn_req_unq_no = #{rtnReqUnqNo}
    </select>


    <select id="selectRtnReqTargetGridList" resultType="com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity">
        select base.brand_id, fn_brand_nm(base.brand_id) as brand_nm, base.rtn_req_unq_no
            , ptcl.rtn_req_dtl_no as 'rtnReqDtlInfo.rtn_req_dtl_no', base.rtn_whs_id, base.rtn_location
            , fn_whs_nm(base.brand_id, base.rtn_whs_id) as rtn_whs_nm
            , fn_whs_location_nm(base.brand_id, base.rtn_whs_id,base.rtn_location) as rtn_location_nm
            , ptcl.spply_id  as 'rtnReqDtlInfo.spply_id', fn_spply_nm(ptcl.spply_id) as 'rtnReqDtlInfo.spply_nm'
            , ptcl.item_id as 'rtnReqDtlInfo.item_id', ptcl.item_nm as 'rtnReqDtlInfo.item_nm', ptcl.rtn_qty as 'rtnReqDtlInfo.rtn_qty'
            , ptcl.rtn_amt as 'rtnReqDtlInfo.rtn_amt'
            , ptcl.rtn_dvsn as 'rtnReqDtlInfo.rtn_dvsn', fn_code_nm(upper('rtn_dvsn'), ptcl.rtn_dvsn) as 'rtnReqDtlInfo.rtn_dvsn_nm'
            , date_format(base.rtn_req_dt, '%Y.%m.%d') as rtn_req_dt
            , date_format(base.col_req_dt, '%Y.%m.%d') as col_req_dt
            , ptcl.rtn_rsn_dvsn as 'rtnReqDtlInfo.rtn_rsn_dvsn', fn_code_nm(upper('rtn_rsn_dvsn'), ptcl.rtn_rsn_dvsn) as 'rtnReqDtlInfo.rtn_rsn_dvsn_nm'
            , base.store_id, base.whs_dvsn, fn_code_nm('WHS_DVSN', base.whs_dvsn) as whs_dvsn_nm
        from rtn_req_base_info base
        , rtn_req_dtl_ptcl ptcl
        where 1 = 1
        and base.rtn_req_unq_no = ptcl.rtn_req_unq_no
        and base.brand_id = #{sBrandId}
        and base.rtn_req_dt between #{fromDt} and #{toDt}
        and base.rtn_req_st_cd = 'RR20'
        and ptcl.rtn_req_dtl_st_cd = 'RRD20'
        <if test="sStoreId != null and sStoreId != ''">
        and base.store_id = #{sStoreId}
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
        and ptcl.spply_id = #{sSpplyId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
        and base.rtn_whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
        and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.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 base.rtn_req_dt asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by base.rtn_req_dt desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by base.rtn_req_dt desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectRtnReqTargetGridCnt" resultType="int">
        select count(*)
        from rtn_req_base_info base
        , rtn_req_dtl_ptcl ptcl
        where 1 = 1
        and base.rtn_req_unq_no = ptcl.rtn_req_unq_no
        and base.brand_id = #{sBrandId}
        and base.rtn_req_dt between #{fromDt} and #{toDt}
        and base.rtn_req_st_cd = 'RR20'
        and ptcl.rtn_req_dtl_st_cd = 'RRD20'
        <if test="sStoreId != null and sStoreId != ''">
            and base.store_id = #{sStoreId}
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
            and ptcl.spply_id = #{sSpplyId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
            and base.rtn_whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
    </select>

    <select id="selectRtnRejectPrTargetList" resultType="com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity">
        select  /* PchReq.selectPchRejectPrTargetList */
              base.rtn_req_unq_no, ptcl.rtn_req_dtl_no as 'rtnReqDtlInfo.rtn_req_dtl_no'
            , ptcl.item_id as 'rtnReqDtlInfo.item_id', ptcl.item_nm as 'rtnReqDtlInfo.item_nm'
            , ptcl.rtn_qty as 'rtnReqDtlInfo.rtn_qty', ptcl.rtn_amt as 'rtnReqDtlInfo.rtn_amt'
            , ptcl.rtn_req_dtl_st_cd as 'rtnReqDtlInfo.rtn_req_dtl_st_cd'
            , fn_code_nm('RTN_REQ_DTL_ST_CD', ptcl.rtn_req_dtl_st_cd) as 'rtnReqDtlInfo.rtn_req_dtl_st_nm'
        from rtn_req_base_info base
     			, rtn_req_dtl_ptcl ptcl
        where 1 = 1
        and base.rtn_req_unq_no = ptcl.rtn_req_unq_no
        and base.rtn_req_st_cd = 'RR20'
        and base.rtn_req_unq_no  = #{rtnReqUnqNo}
    </select>

    <update id="updateRejRtnReqBaseInfo">
         UPDATE /* rtnReq.updateRejRtnReqBaseInfo */
            rtn_req_base_info
            SET rtn_req_st_cd = 'RR40',
                rtn_rjct_rsn = #{rtnRjctRsn},
                rtn_rjct_nm = #{rtnRjctNm},
				rtn_rjct_dt = date_format(now(),'%Y%m%d'),
                rtn_rjct_id = #{userId},
                sys_chg_dttm = NOW(),
                sys_chg_id = #{userId}
            WHERE rtn_req_unq_no = #{rtnReqUnqNo}
    </update>


    <select id="selectRtnPoTargetGridList" resultType="com.oqpo.api.entity.rtnmng.RtnReqBaseInfoEntity">
        select base.brand_id, fn_brand_nm(base.brand_id) as brand_nm, base.rtn_req_unq_no
                , ptcl.rtn_req_dtl_no as 'rtnReqDtlInfo.rtn_req_dtl_no', base.rtn_whs_id, base.rtn_location
                , fn_whs_nm(base.brand_id, base.rtn_whs_id) as rtn_whs_nm
                , fn_whs_location_nm(base.brand_id, base.rtn_whs_id,base.rtn_location) as rtn_location_nm
                , ptcl.spply_id  as 'rtnReqDtlInfo.spply_id', fn_spply_nm(ptcl.spply_id) as 'rtnReqDtlInfo.spply_nm'
                , ptcl.item_id as 'rtnReqDtlInfo.item_id', ptcl.item_nm as 'rtnReqDtlInfo.item_nm', ptcl.rtn_qty as 'rtnReqDtlInfo.rtn_qty'
                , ptcl.rtn_amt as 'rtnReqDtlInfo.rtn_amt'
                , ptcl.rtn_dvsn as 'rtnReqDtlInfo.rtn_dvsn', fn_code_nm(upper('rtn_dvsn'), ptcl.rtn_dvsn) as 'rtnReqDtlInfo.rtn_dvsn_nm'
                , date_format(base.rtn_req_dt, '%Y.%m.%d') as rtn_req_dt
                , date_format(base.col_req_dt, '%Y.%m.%d') as col_req_dt
                , ptcl.rtn_rsn_dvsn as 'rtnReqDtlInfo.rtn_rsn_dvsn', fn_code_nm(upper('rtn_rsn_dvsn'), ptcl.rtn_rsn_dvsn) as 'rtnReqDtlInfo.rtn_rsn_dvsn_nm'
                , base.store_id, base.whs_dvsn, fn_code_nm('WHS_DVSN', base.whs_dvsn) as whs_dvsn_nm
                , ptcl.unit as 'rtnReqDtlInfo.unit' , ptcl.unit_amt as 'rtnReqDtlInfo.unit_amt', ptcl.rtn_rsn as 'rtnReqDtlInfo.rtn_rsn'
        from rtn_req_base_info base
            , rtn_req_dtl_ptcl ptcl
        where 1 = 1
        and base.rtn_req_unq_no = ptcl.rtn_req_unq_no
        and base.brand_id = #{brandId}
        and base.rtn_req_st_cd = 'RR20'
        and concat(base.rtn_req_unq_no, ptcl.rtn_req_dtl_no) in
        <foreach collection="gridUpdateData" item="item" separator="," open="(" close=")">
            concat(#{item.rtnReqUnqNo},#{item.rtnReqDtlNo})
        </foreach>
    </select>

    <update id="updateRtnReqStCd">
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE /* RtnReq.updateRtnReqStCd */
            rtn_req_base_info SET
            rtn_req_st_cd = #{item.rtnReqStCd},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
            WHERE rtn_req_unq_no = #{item.rtnReqUnqNo}
        </foreach>
    </update>

    <update id="updateAllRtnReqDtlStCd">
            UPDATE /* RtnReq.updateAllRtnReqDtlStCd */
            rtn_req_dtl_ptcl SET
            rtn_req_dtl_st_cd = #{rtnReqDtlStCd},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
            WHERE rtn_req_unq_no = #{rtnReqUnqNo}
    </update>

    <select id="selectRtnRejectIngCnt" resultType="int">
        select  count(*)
        from  rtn_req_dtl_ptcl ptcl
        where 1 = 1
        and ptcl.rtn_req_unq_no  = #{rtnReqUnqNo}
        and ptcl.rtn_req_dtl_st_cd = 'RRD30'
    </select>

    <update id="updateSelRtnReqDtlStCd">
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE /* RtnReq.updateAllRtnReqDtlStCd */
            rtn_req_dtl_ptcl SET
            rtn_req_dtl_st_cd = #{item.rtnReqDtlStCd},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
            WHERE rtn_req_unq_no = #{item.rtnReqUnqNo}
            and   rtn_req_dtl_no = #{item.rtnReqDtlNo}
        </foreach>
    </update>

    <select id="selectRtnReqDtlStatusList" resultType="com.oqpo.api.entity.rtnmng.RtnReqDtlPtclEntity">
        select rtn_req_dtl_st_cd, count(*) as rtn_req_status_cnt
        from rtn_req_dtl_ptcl
        where rtn_req_unq_no = #{rtnReqUnqNo}
        group by rtn_req_dtl_st_cd
    </select>

</mapper>
