<?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.front.biz.dao.TsfReinboundDao">

	<!-- 페이징을 위한 select절 상단 -->
	<sql id="selectForPagingHeader">
		SELECT *
		FROM   (
	</sql>

	<!-- 페이징을 위한 select절 하단 -->
	<sql id="selectForPagingFooter">
		       ) ORIGINAL
		WHERE  NUMB BETWEEN #{pageable.startRow} AND #{pageable.endRow}
	</sql>
	
	<!-- 재입고알림 목록 -->
	<select id="getReinboundInformList" parameterType="Integer" resultType="ReinboundInform">
		/* TsfReinbound.getReinboundInformList */
		SELECT RI.RINBD_INFO_SQ                                   /*재입고알림번호*/
		     , RI.GOODS_CD                                        /*상품코드*/
		     , G.GOODS_NM                                         /*상품명*/
		     , RI.OPT_CD                                          /*옵션코드*/
		     , RI.OPT_CD1                                         /*옵션코드1*/
		     , RI.OPT_CD2                                         /*옵션코드2*/
		     , B.BRAND_ENM                                        /*브랜드영문명*/
		     , DATE_FORMAT(RI.REQ_DT,'%Y.%m.%d')    AS REQ_DT     /*요청일자*/
		     , DATEDIFF(CURRENT_DATE(),RI.REQ_DT)   AS PAST_DAYS  /*경과일수*/
		     , DATE_FORMAT(RI.INFORM_DT,'%Y.%m.%d') AS INFORM_DT  /*알림일자*/
		     , (SELECT MAX(SYS_IMG_NM)
		        FROM   TB_GOODS_IMG
		        WHERE  GOODS_CD = G.GOODS_CD
		        AND    COLOR_CD = G.MAIN_COLOR_CD
		        AND    DEFAULT_IMG_YN = 'Y' /*기본이미지만*/
		       )                                    AS SYS_IMG_NM /*상품이미지명*/
		FROM   TB_REINBOUND_INFORM RI
		     , TB_GOODS G
		     , TB_BRAND B
		WHERE  RI.GOODS_CD = G.GOODS_CD
		AND    G.BRAND_CD = B.BRAND_CD
		AND    RI.CUST_NO = #{custNo}
		AND    G.GOODS_STAT IN ('G008_70','G008_90') /*일시품절,승인완료*/
		AND    NOW() BETWEEN G.SELL_STDT AND G.SELL_EDDT /*유효한판매기간*/
		AND    G.SELF_MALL_YN = 'Y' /*자사몰에노출하는넘만*/
		ORDER  BY RI.INFORM_DT DESC, PAST_DAYS, RI.RINBD_INFO_SQ
	</select>
	
	<!-- 재입고알림 연장 -->
	<update id="updateReinboundInformContinue" parameterType="ReinboundInform">
		/* TsfReinbound.updateReinboundInformContinue */
		UPDATE TB_REINBOUND_INFORM
		SET    REQ_DT = NOW()
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		WHERE  RINBD_INFO_SQ = #{rinbdInfoSq}
		AND    CUST_NO = #{custNo} /*보안상추가*/
	</update>
	
</mapper>
