<?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.style24.batch.biz.dao.TsbCjDeliveryDao">
	
	
	<!-- cj 회수 송장번호 조회    -->	
	<select id="getCjWdInvoiceList" resultType="Delivery">
		/*TsbWmsDelivery.getCjWdInvoiceList*/
		SELECT 
		      INVC_NO     AS RECALLINVOICENO
		      , SUBSTR(CUST_USE_NO, INSTR(CUST_USE_NO,'-')+1, LENGTH(CUST_USE_NO)) AS ORD_CHG_SQ
		      , SUBSTR(CUST_USE_NO, 0,INSTR(CUST_USE_NO,'-')-1) AS ORD_NO
		      , TO_DATE(SCAN_YMD||SCAN_HOUR,'YYYYMMDDHH24MISS')   AS DELIVERY_DT
		      , CUST_USE_NO
		  FROM V_TRACE_ISTYLE020
		 WHERE CUST_ID = '0010046850'  -- 고객번호 
		   AND RCPT_DV = '02' -- 반품 
		   AND EAI_PRGS_ST = '01' 
		   AND CRG_ST      = '01' 
		 GROUP BY INVC_NO, TO_DATE(SCAN_YMD||SCAN_HOUR,'YYYYMMDDHH24MISS'), CUST_USE_NO
	</select>
	
	<!-- cj 회수 상태 조회    -->	
	<select id="getCjWdStatList" resultType="Delivery">
		/*TsbWmsDelivery.getCjWdStatList*/
		SELECT
			  SERIAL
			, INVC_NO     AS RECALLINVOICENO
			, SUBSTR(CUST_USE_NO, INSTR(CUST_USE_NO,'-')+1, LENGTH(CUST_USE_NO)) AS ORD_CHG_SQ 
            , SUBSTR(CUST_USE_NO, 0,INSTR(CUST_USE_NO,'-')-1) AS ORD_NO
			, CRG_ST
			, NO_CLDV_RSN_CD
			, TO_DATE(SCAN_YMD||SCAN_HOUR,'YYYYMMDDHH24MISS')   AS DELIVERY_DT
			, DETAIL_RSN
		  FROM V_TRACE_ISTYLE020 
		 WHERE CUST_ID = '0010046850'
		   AND RCPT_DV ='02'
		   AND EAI_PRGS_ST = '01'
           AND CRG_ST NOT IN('01') 
		 ORDER BY CUST_USE_NO, CRG_ST
	</select>
	
	<!-- cj 회수상태 수신 결과 업데이트   -->	
	<update id="updateCjWdStat" parameterType="Delivery">
		/*TsbWmsDelivery.updateCjWdStat*/
		UPDATE V_TRACE_ISTYLE020 SET
			  EAI_PRGS_ST = '03'
			, MODI_EMP_ID = 'STYLE24'
			, MODI_DTIME  = SYSDATE
		WHERE SERIAL      = #{serial}
		  AND EAI_PRGS_ST ='01'
		
	</update>	
	
	<!-- cj 회수상태 수신 결과 업데이트   -->	
	<update id="updateCjInvcNo" parameterType="Delivery">
		/*TsbWmsDelivery.updateCjInvcNo*/
		UPDATE V_TRACE_ISTYLE020 SET
			  EAI_PRGS_ST = '03'
			, MODI_EMP_ID = 'STYLE24'
			, MODI_DTIME  = SYSDATE
		WHERE INVC_NO      = #{recallinvoiceno}
		  AND EAI_PRGS_ST = '01'
		  AND CRG_ST      = '01'
		  AND CUST_USE_NO = #{custUseNo}

	</update>	
		
</mapper>