<?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.admin.biz.dao.TsaReviewDao">

	<!--상품평 목록  -->
	<select id="getReviewList" parameterType="Review" resultType="Review">
		/* TsaReview.getReviewList */
		SELECT R.REVIEW_SQ                                                /*상품평일련번호*/
		     , R.GOODS_CD                                                 /*상품코드*/
		     , G.GOODS_NM                                                 /*상품명*/
		     , (SELECT 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' /*디폴트이미지*/
		        LIMIT 1
		       )                                        AS GOODS_IMG      /*상품이미지*/
		     , R.REVIEW_GB                                                /*상품평구분*/
		     , R.CUST_NO                                                  /*고객번호*/
		     , C.CUST_NM                                                  /*고객명*/
		     , R.ORD_NO                                                   /*주문번호*/
		     , R.ORD_DTL_NO                                               /*주문상세번호*/
		     , R.REVIEW_TITLE                                             /*상품평제목*/
		     , R.REVIEW_CONTENT                                           /*상품평내용*/
		     , R.SCORE                                                    /*구매평점*/
		     , R.HEIGHT                                                   /*키*/
		     , R.WEIGHT                                                   /*몸무게*/
		     , R.SCORE_SIZE                                               /*사이즈점수*/
		     , R.SCORE_COLOR                                              /*컬러점수*/
		     , R.SCORE_FIT                                                /*핏점수*/
		     , R.SCORE_THICK                                              /*두께감점수*/
		     , R.SCORE_WEIGHT                                             /*무게감점수*/
		     , R.SCORE_BALL                                               /*볼넓이점수*/
		     , R.GIVE_DUE_PNT                                             /*지급예정포인트*/
		     , R.PNT_GIVE_STAT                                            /*포인트지급상태*/
		     , R.DISP_YN                                                  /*표시여부*/
		     , R.DEL_YN                                                   /*삭제여부*/
		     , R.CONFIRM_YN                                               /*확인여부*/
		     , FN_GET_USER_NM(R.CONFIRM_UNO)            AS CONFIRM_UNM    /*확인자명*/
		     , DATE_FORMAT(R.CONFIRM_DT,'%Y%m%d%H%i%S') AS CONFIRM_DT     /*확인일시*/ 
		     , R.ADM_RPL                                                  /*관리자댓글*/
		     , FN_GET_USER_NM(R.ADM_RPL_REG_NO)         AS ADM_RPL_GRE_NM /*관리자댓글작성자명*/
		     , DATE_FORMAT(R.ADM_RPL_DT,'%Y%m%d%H%i%S') AS ADM_RPL_DT     /*관리자댓글작성일시*/
		FROM   TB_REVIEW R
		     , TB_CUSTOMER C
		     , TB_GOODS G
		WHERE  R.CUST_NO = C.CUST_NO
		AND    R.GOODS_CD = G.GOODS_CD
		<if test="goodsCds != null and goodsCds != ''">
		AND    (
		        <foreach collection="goodsCds" item="item" index="index" separator="or">
		        UPPER(R.GOODS_CD) LIKE CONCAT('%',UPPER(#{item}),'%') 
		        </foreach>
		       )
		</if>
		<if test="startDt != null and startDt != ''">
		AND    R.REG_DT <![CDATA[>=]]> STR_TO_DATE(#{startDt},'%Y-%m-%d')
		</if>
		<if test="endDt != null and endDt != ''">
		AND    R.REG_DT <![CDATA[<]]> DATE_ADD(STR_TO_DATE(#{endDt},'%Y-%m-%d'),INTERVAL 1 DAY)
		</if>
		<if test="reviewGb != null and reviewGb != ''">
		AND    R.REVIEW_GB = #{reviewGb}
		</if>
		<if test="pntGiveStat != null and pntGiveStat != ''">
		AND    R.PNT_GIVE_STAT = #{pntGiveStat}
		</if>
		<if test="dispYn != null and dispYn != ''">
		AND    R.DISP_YN = #{dispYn}
		</if>
		<if test="searchGb == 'memNm'">
		AND    UPPER(C.CUST_NM) LIKE CONCAT('%',UPPER(#{searchTxt}),'%')
		</if>
		<if test="searchGb == 'email'">
		AND    UPPER(C.EMAIL) LIKE CONCAT('%',UPPER(#{searchTxt}),'%')
		</if>
		ORDER  BY R.REG_DT DESC
	</select>
	
</mapper>