<?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 
		        A.INVC_NO     AS RECALLINVOICENO
		      , SUBSTR(A.CUST_USE_NO, INSTR(A.CUST_USE_NO,'-')+1, LENGTH(A.CUST_USE_NO)) AS CJ_ORD_CHG_SQ
		      , SUBSTR(A.CUST_USE_NO, 0,INSTR(A.CUST_USE_NO,'-')-1) AS CJ_ORD_NO
		      , TO_DATE(A.SCAN_YMD||A.SCAN_HOUR,'YYYYMMDDHH24MISS')   AS DELIVERY_DT
		      , A.CUST_USE_NO
		  FROM V_TRACE_ISTYLE020 A, V_RCPT_ISTYLE010 B
		 WHERE A.CUST_ID = B.CUST_ID
           AND A.CUST_USE_NO = B.CUST_USE_NO
           AND A.CUST_ID = '0010046850'  -- 고객번호 
		   AND A.RCPT_DV = '02' -- 반품 
		   AND A.EAI_PRGS_ST = '01' 
		   AND A.CRG_ST      = '01' 
		 GROUP BY A.INVC_NO, TO_DATE(A.SCAN_YMD||A.SCAN_HOUR,'YYYYMMDDHH24MISS'), A.CUST_USE_NO
	</select>
	
	<!-- cj 회수 상태 조회    -->	
	<select id="getCjWdStatList" resultType="Delivery">
		/*TsbWmsDelivery.getCjWdStatList*/
		SELECT
			  A.SERIAL
			, A.INVC_NO     AS RECALLINVOICENO
			, SUBSTR(A.CUST_USE_NO, INSTR(A.CUST_USE_NO,'-')+1, LENGTH(A.CUST_USE_NO)) AS CJ_ORD_CHG_SQ 
			, SUBSTR(A.CUST_USE_NO, 0,INSTR(A.CUST_USE_NO,'-')-1) AS CJ_ORD_NO
			, A.CRG_ST
			, A.NO_CLDV_RSN_CD
			, TO_DATE(A.SCAN_YMD||A.SCAN_HOUR,'YYYYMMDDHH24MISS')   AS DELIVERY_DT
			, A.DETAIL_RSN
		  FROM V_TRACE_ISTYLE020 A,  V_RCPT_ISTYLE010 B
		 WHERE A.CUST_ID = B.CUST_ID
		   AND A.CUST_USE_NO = B.CUST_USE_NO
		   AND A.CUST_ID = '0010046850'
		   AND A.RCPT_DV ='02'
		   AND A.EAI_PRGS_ST = '01'
		   AND A.CRG_ST NOT IN('01') 
		 ORDER BY A.CUST_USE_NO, A.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>