<?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.TsaGoodsDao">

	<!-- 품목 목록 -->
	<select id="getItemkindList" parameterType="Itemkind" resultType="Itemkind">
		/* TsaGoods.getItemkindList */
		SELECT ITEMKIND_CD
		     , ITEMKIND_NM
		     /* , ITEMKIND_ENM*/
		     , NI_CLSF_CD
		     , USE_YN
		FROM TB_ITEMKIND
		WHERE 1 = 1
		<if test="itemkindCd != null and itemkindCd != ''">
		AND ITEMKIND_CD = #{itemkindCd} 
		</if>
		<if test="useYn != null and useYn != ''">
		AND USE_YN = #{useYn} 
		</if>
		ORDER BY ITEMKIND_CD
	</select>

	<!-- 품목 등록/저장 -->
	<insert id="saveItemkindInfo" parameterType="Itemkind">
		/* TsaGoods.saveItemkindInfo */
		INSERT INTO TB_ITEMKIND (
		       ITEMKIND_CD
		     , ITEMKIND_NM
		     , NI_CLSF_CD
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{itemkindCd}
		     , #{itemkindNm}
		     , #{niClsfCd}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       ITEMKIND_NM = #{itemkindNm}
		     , NI_CLSF_CD = #{niClsfCd}
		     , USE_YN = #{useYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</insert>
	
	<!-- 품목 삭제 -->
	<delete id="deleteItemkindInfo" parameterType="Itemkind">
		/* TsaGoods.deleteItemkindInfo */
		DELETE FROM TB_ITEMKIND
		 WHERE ITEMKIND_CD = #{itemkindCd}
	</delete>
	
	<!-- 색상 조회 -->
	<select id="getColorList" parameterType="Color" resultType="Color" >
		/* TsaGoods.getColorList */
		SELECT COLOR_CD
		     , COLOR_ENM
		     , COLOR_KNM
		     , COLOR_FILE
		     , COLOR_GRP_NM
		     , USE_YN
		     , FN_GET_USER_NM(REG_NO) AS REG_NM
		     , DATE_FORMAT(REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		     , FN_GET_USER_NM(UPD_NO) AS UPD_NM
		     , DATE_FORMAT(UPD_DT, '%Y%m%d%H%i%S') AS UPD_DT
		     , COLOR_GRP_CD
		FROM TB_COLOR
		WHERE 1 = 1
		<if test='colorCd != null and colorCd != ""'>
		AND COLOR_CD = #{colorCd}
		</if>
		<if test='useYn != null and useYn != ""'>
		AND USE_YN = #{useYn}
		</if>
		ORDER BY COLOR_CD
	</select>
	
	<!-- 색상 저장 -->
	<update id="saveColor" parameterType="Color">
		/* TsaGoods.saveColor */
		INSERT INTO TB_COLOR (
		       COLOR_CD
		     , COLOR_ENM
		     , COLOR_KNM
		     , COLOR_FILE
		     , COLOR_GRP_NM
		     , COLOR_GRP_CD
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{colorCd}
		     , #{colorEnm}
		     , #{colorKnm}
		     , #{colorFile}
		     , #{colorGrpNm}
		     , #{colorGrpCd}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       COLOR_ENM = #{colorEnm}
		     , COLOR_KNM = #{colorKnm}
		     , COLOR_FILE = UPPER(#{colorFile})
		     , COLOR_GRP_NM = UPPER(#{colorGrpNm})
		     , COLOR_GRP_CD = UPPER(#{colorGrpCd})
		     , USE_YN = #{useYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</update>
	
	<!-- 정보고시분류 목록 -->
	<select id="getNotiInfoList" parameterType="NotiInfo" resultType="NotiInfo">
		/* TsaGoods.getNotiInfoList */
		SELECT DISTINCT B.SUPPLY_COMP_CD
		     , B.NI_CLSF_CD
		     , C.CD_NM AS NI_CLSF_NM
		     , C.DISP_ORD
		FROM TB_NOTI_INFO B
		INNER JOIN TB_COMMON_CODE C ON B.NI_CLSF_CD = C.CD 
		WHERE B.SUPPLY_COMP_CD = CASE #{supplyCompCd} 
		                         WHEN 'S0001' THEN 'S0001'
		                         WHEN 'S0002' THEN 'S0002'
		                         ELSE 'E' END 
		AND C.CD_GB = 'G004'   /*고시정보*/
		ORDER BY C.DISP_ORD
	</select>
	
	<!-- 정보고시 상세 목록 -->
	<select id="getNotiInfoItemList" parameterType="NotiInfo" resultType="NotiInfo">
		/* TsaGoods.getNotiInfoItemList */
		SELECT B.SUPPLY_COMP_CD
		     , B.NI_CLSF_CD
		     , B.NI_ITEM_CD
		     , FN_GET_CODE_NM('G005', B.NI_ITEM_CD) AS NI_ITEM_NM
		     , B.NI_CONTENT
		     , B.DISP_ORD
		     , B.REQ_YN
		     , B.DISP_YN
		FROM TB_NOTI_INFO B
		WHERE B.SUPPLY_COMP_CD = CASE #{supplyCompCd} 
		                         WHEN 'S0001' THEN 'S0001'
		                         WHEN 'S0002' THEN 'S0002'
		                         ELSE 'E' END 
		<if test="niClsfCd != null and niClsfCd != ''">
		AND B.NI_CLSF_CD = #{niClsfCd}
		</if>
		ORDER BY B.NI_CLSF_CD, B.DISP_ORD
	</select>

	<!-- 정보고시 항목 등록 -->
	<insert id="saveNotiInfo" parameterType="NotiInfo">
		/* TsaGoods.saveNotiInfo */
		INSERT INTO TB_NOTI_INFO (
		       SUPPLY_COMP_CD
		     , NI_CLSF_CD
		     , NI_ITEM_CD
		     , NI_CONTENT
		     , DISP_ORD
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{supplyCompCd}
		     , #{niClsfCd}
		     , #{niItemCd}
		     , #{niContent}
		     , #{dispOrd}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       NI_CONTENT = #{niContent}
		     , DISP_ORD = #{dispOrd}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</insert>
	
	<!-- WMS 색상 매핑 조회 -->
	<select id="getWmsColorMappingList" parameterType="WmsColorMapping" resultType="WmsColorMapping" >
		/* TsaGoods.getWmsColorMappingList */
		SELECT SUPPLY_COMP_CD
		     , WMS_COLOR_CD
		     , WMS_COLOR_NM
		     , COLOR_CD
		     , USE_YN
		     , FN_GET_USER_NM(REG_NO) AS REG_NM
		     , DATE_FORMAT(REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		     , FN_GET_USER_NM(UPD_NO) AS UPD_NM
		     , DATE_FORMAT(UPD_DT, '%Y%m%d%H%i%S') AS UPD_DT
		FROM TB_WMS_COLOR_MAPPING
		WHERE SUPPLY_COMP_CD = #{supplyCompCd}
		ORDER BY WMS_COLOR_CD
	</select>
	
	<!-- WMS 색상 매핑 저장 -->
	<update id="saveWmsColorMapping" parameterType="WmsColorMapping">
		/* TsaGoods.saveWmsColorMapping */
		INSERT INTO TB_WMS_COLOR_MAPPING (
		       SUPPLY_COMP_CD
		     , WMS_COLOR_CD
		     , WMS_COLOR_NM
		     , COLOR_CD
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{supplyCompCd}
		     , #{wmsColorCd}
		     , #{wmsColorNm}
		     , #{colorCd}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       COLOR_CD = #{colorCd}
		     , USE_YN = #{useYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</update>
	
	<!-- WMS 스타일년도 매핑 조회 -->
	<select id="getWmsStyleYearMappingList" parameterType="WmsStyleYearMapping" resultType="WmsStyleYearMapping" >
		/* TsaGoods.getWmsStyleYearMappingList */
		SELECT SUPPLY_COMP_CD
		     , WMS_STYLE_YEAR_CD
		     , WMS_STYLE_YEAR_NM
		     , STYLE_YEAR
		     , USE_YN
		     , FN_GET_USER_NM(REG_NO) AS REG_NM
		     , DATE_FORMAT(REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		     , FN_GET_USER_NM(UPD_NO) AS UPD_NM
		     , DATE_FORMAT(UPD_DT, '%Y%m%d%H%i%S') AS UPD_DT
		FROM TB_WMS_STYLE_YEAR_MAPPING
		WHERE SUPPLY_COMP_CD = #{supplyCompCd}
		ORDER BY WMS_STYLE_YEAR_CD
	</select>
	
	<!-- WMS 스타일년도 매핑 저장 -->
	<update id="saveWmsStyleYearMapping" parameterType="WmsStyleYearMapping">
		/* TsaGoods.saveWmsStyleYearMapping */
		INSERT INTO TB_WMS_STYLE_YEAR_MAPPING (
		       SUPPLY_COMP_CD
		     , WMS_STYLE_YEAR_CD
		     , WMS_STYLE_YEAR_NM
		     , STYLE_YEAR
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{supplyCompCd}
		     , #{wmsStyleYearCd}
		     , #{wmsStyleYearNm}
		     , #{styleYear}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       STYLE_YEAR = #{styleYear}
		     , USE_YN = #{useYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</update>
	
	<!-- WMS 시즌 매핑 조회 -->
	<select id="getWmsSeasonMappingList" parameterType="WmsSeasonMapping" resultType="WmsSeasonMapping" >
		/* TsaGoods.getWmsSeasonMappingList */
		SELECT SUPPLY_COMP_CD
		     , WMS_SEASON_CD
		     , WMS_SEASON_NM
		     , SEASON_CD
		     , USE_YN
		     , FN_GET_USER_NM(REG_NO) AS REG_NM
		     , DATE_FORMAT(REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		     , FN_GET_USER_NM(UPD_NO) AS UPD_NM
		     , DATE_FORMAT(UPD_DT, '%Y%m%d%H%i%S') AS UPD_DT
		FROM TB_WMS_SEASON_MAPPING
		WHERE SUPPLY_COMP_CD = #{supplyCompCd}
		ORDER BY WMS_SEASON_CD
	</select>
	
	<!-- WMS 시즌 매핑 저장 -->
	<update id="saveWmsSeasonMapping" parameterType="WmsSeasonMapping">
		/* TsaGoods.saveWmsSeasonMapping */
		INSERT INTO TB_WMS_STYLE_YEAR_MAPPING (
		       SUPPLY_COMP_CD
		     , WMS_SEASON_CD
		     , WMS_SEASON_NM
		     , SEASON_CD
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{supplyCompCd}
		     , #{wmsSeasonCd}
		     , #{wmsSeasonNm}
		     , #{seasonCd}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       SEASON_CD = #{seasonCd}
		     , USE_YN = #{useYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</update>
	
	<!-- 상품 목록 건수 -->
	<select id="getGoodsListCount" parameterType="GoodsSearch" resultType="int">
		/* TsaGoods.getGoodsListCount */
		        SELECT COUNT(*) AS TOTCNT
		        FROM TB_GOODS G
		        INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		        INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		        INNER JOIN TB_GOODS_SUMMARY GS ON G.GOODS_CD = GS.GOODS_CD
		        <if test="searchGb != null and searchGb =='EXTEND'">
		        INNER JOIN TB_GOODS_EXTEND GE ON G.GOODS_CD =  GE.EXTEND_GOODS_CD
		                                      AND GE.GOODS_CD IN
		            <foreach collection="conditionList" item="item" index="index"  open="(" close=")" separator=",">
		                                          UPPER(#{item})
		            </foreach>
		        </if>
		        <if test="searchGb != null and searchGb =='MASTER'">
		        INNER JOIN TB_GOODS_EXTEND GE ON G.GOODS_CD =  GE.GOODS_CD
		                                      AND GE.EXTEND_GOODS_CD IN
		            <foreach collection="conditionList" item="item" index="index"  open="(" close=")" separator=",">
		                                          UPPER(#{item})
		            </foreach>
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        INNER JOIN (
		                     SELECT SEARCH_CD
		                          , TMP_DISP_ORD
		                     FROM (
		                           SELECT SEARCH_CD
		                                , MIN(DISP_ORD) AS TMP_DISP_ORD
		                           FROM TB_SEARCH_DATA
		                           WHERE REG_NO = #{regNo}
		                           GROUP BY SEARCH_CD) T
		                   ) SD
		                   ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		                        OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                        <if test="mdNo != null and mdNo != ''">
		                        AND G.BRAND_CD IN (
		                                           SELECT DISTINCT BRAND_CD
		                                           FROM TB_BRAND_MD
		                                           WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                           )
		                       </if>
		                   )
		        </if>
		        LEFT OUTER JOIN TB_GOODS_IMG GI ON G.GOODS_CD = GI.GOODS_CD
		                                        AND G.MAIN_COLOR_CD = GI.COLOR_CD
		        WHERE 1=1
		        <if test="searchGb == null or searchGb =='BASIC' or searchGb =='EXTEND' or searchGb =='MASTER'" >
		        <include refid="getGoodsListCondition_sql"/>
		        </if>
	</select>

	<!-- 상품 목록 -->
	<select id="getGoodsList" parameterType="GoodsSearch" resultType="Goods">
		/* TsaGoods.getGoodsList */
		SELECT Z.*
		    , (CASE WHEN Z.GOODS_TYPE = 'G056_N' THEN (SELECT NVL(SUM(CURR_STOCK_QTY - BASE_STOCK_QTY),0) FROM VW_STOCK WHERE GOODS_CD = Z.GOODS_CD) 
		            ELSE (SELECT NVL(SUM(CURR_STOCK_QTY - BASE_STOCK_QTY),0) FROM VW_STOCK_COMPOSE WHERE GOODS_CD = Z.GOODS_CD) 
		            END) AS STOCK_QTY_SUM
		    , (SELECT ITEMKIND_NM FROM TB_ITEMKIND WHERE ITEMKIND_CD = Z.ITEMKIND_CD ) AS ITEMKIND_NM
		    , FN_GET_USER_NM(REG_NO) AS REG_NM
		    , FN_GET_USER_NM(UPD_NO) AS UPD_NM
		    <if test='goodsPriceYn != null and goodsPriceYn == "Y"'>
		    , GB.CURR_PRICE AS BENEFIT_CURR_PRICE
		    </if>
		FROM (
		    SELECT A.*, @rownum := @rownum + 1 AS RNUM FROM (
		        SELECT
		                G.GOODS_CD
		              , G.GOODS_TYPE
		              , B.BRAND_ENM
		              , B.BRAND_GRP_NM
		              , G.BRAND_CD
		              , G.ITEMKIND_CD
		              , G.SUPPLY_COMP_CD
		              , G.SUPPLY_GOODS_CD
		              , G.GOODS_NUM
		              , G.GOODS_NM
		              , G.GOODS_STAT
		              , G.LIST_PRICE
		              , G.CURR_PRICE
		              , G.DC_RATE
		              , G.SELF_GOODS_YN
		              , G.SELF_MALL_YN
		              , G.FORMAL_GB
		              , G.STYLE_YEAR
		              , G.SEASON_CD
		              , G.ERP_STOCK_LINK_YN
		              , G.ERP_PRICE_LINK_YN
		              , G.CHANGEABLE_YN
		              , G.RETURNABLE_YN
		              , G.NEW_CUST_ORD_YN
		              , G.GIFT_PACK_YN
		              , G.DELV_FEE_CD
		              , DATE_FORMAT(G.FRST_CFRM_DT, '%Y%m%d%H%i%S') AS FRST_CFRM_DT
		              , G.SELL_FEE_RATE
		              , DATE_FORMAT(G.PRICE_UPD_DT,'%Y%m%d%H%i%S') AS PRICE_UPD_DT
		              , CASE WHEN IMG_PATH1 IS NULL THEN
		                     'N'
		                ELSE
		                     'Y'
		                END AS GOODS_IMAGE_YN
		              , GI.IMG_PATH1
		              , GI.IMG_PATH6
		              , GI.IMG_TYPE
		              , G.REG_NO
		              , DATE_FORMAT(G.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		              , G.UPD_NO
		              , DATE_FORMAT(G.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		              , GS.SELL_DAY15_QTY
		              <choose>
		                  <when test="searchGb != null and searchGb =='EXCEL'">
		              , SD.TMP_DISP_ORD
		                  </when>
		                  <otherwise>
		              , 0 AS TMP_DISP_ORD
		                  </otherwise>
		              </choose>
		        FROM TB_GOODS G
		        JOIN ( SELECT @rownum := 0) R
		        INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		        INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		        INNER JOIN TB_GOODS_SUMMARY GS ON G.GOODS_CD = GS.GOODS_CD
		        <if test="searchGb != null and searchGb =='EXTEND'">
		        INNER JOIN TB_GOODS_EXTEND GE ON G.GOODS_CD =  GE.EXTEND_GOODS_CD
		                                      AND GE.GOODS_CD IN
		            <foreach collection="conditionList" item="item" index="index"  open="(" close=")" separator=",">
		                                          UPPER(#{item})
		            </foreach>
		        </if>
		        <if test="searchGb != null and searchGb =='MASTER'">
		        INNER JOIN TB_GOODS_EXTEND GE ON G.GOODS_CD =  GE.GOODS_CD
		                                      AND GE.EXTEND_GOODS_CD IN
		            <foreach collection="conditionList" item="item" index="index"  open="(" close=")" separator=",">
		                                          UPPER(#{item})
		            </foreach>
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        INNER JOIN (
		                     SELECT SEARCH_CD
		                          , TMP_DISP_ORD
		                     FROM (
		                           SELECT SEARCH_CD
		                                , MIN(DISP_ORD) AS TMP_DISP_ORD
		                           FROM TB_SEARCH_DATA
		                           WHERE REG_NO = #{regNo}
		                           GROUP BY SEARCH_CD) T
		                   ) SD
		                   ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		                        OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                        <if test="mdNo != null and mdNo != ''">
		                        AND G.BRAND_CD IN (
		                                           SELECT DISTINCT BRAND_CD
		                                           FROM TB_BRAND_MD
		                                           WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                           )
		                       </if>
		                   )
		        </if>
		        LEFT OUTER JOIN TB_GOODS_IMG GI ON G.GOODS_CD = GI.GOODS_CD
		                                        AND G.MAIN_COLOR_CD = GI.COLOR_CD
		        WHERE 1=1
		        <if test="searchGb == null or searchGb =='BASIC' or searchGb =='EXTEND' or searchGb =='MASTER'" >
		        <include refid="getGoodsListCondition_sql"/>
		        ORDER BY G.REG_DT DESC, G.GOODS_CD
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        ORDER BY SD.TMP_DISP_ORD
		        </if>
		<include refid="getListPagingCondition_sql"/>
	</select>
	
	<!-- 상품 목록 조건 정보 -->
	<sql id="getGoodsListCondition_sql">
		        <if test='conditionList != null and conditionList.length>0'>
		            <choose>
		              <when test='search != null and search == "searchGoodsCd"'>
		        AND (
		              <foreach collection="conditionList" item="item" index="index" separator="or">
		               UPPER(G.GOODS_CD) LIKE CONCAT('%',UPPER(#{item}),'%') 
		              </foreach>
		             )
		              </when>
		              <when test='search != null and search == "searchGoodsNum"'>
		        AND (
		              <foreach collection="conditionList" item="item" index="index" separator="or">
		               UPPER(G.GOODS_NUM) LIKE CONCAT('%',UPPER(#{item}),'%')
		              </foreach>
		             )
		              </when>
		              <when test='search != null and search == "searchSupplyGoodsCd"'>
		        AND (
		              <foreach collection="conditionList" item="item" index="index" separator="or">
		               UPPER(G.SUPPLY_GOODS_CD) LIKE CONCAT('%',UPPER(#{item}),'%')
		              </foreach>
		             )
		              </when>
		              <when test='search != null and search == "searchExtendGoodsCd"'>
		        AND 1 = 1
		              </when>
		              <when test='search != null and search == "searchMasterGoodsCd"'>
		        AND 1 = 1
		              </when>
		              <otherwise>
		        AND UPPER(G.REG_ID) LIKE CONCAT('%',UPPER(#{item}),'%')
		              </otherwise>
		            </choose>
		        </if>
		        <if test="goodsCd != null and goodsCd != ''">
		        AND UPPER(G.GOODS_CD) LIKE CONCAT('%',UPPER(#{goodsCd}),'%')
		        </if>
		         <if test="goodsNm != null and goodsNm != ''">
		        AND UPPER(G.GOODS_NM) LIKE CONCAT('%',UPPER(#{goodsNm}),'%')
		        </if>
		        <if test="goodsType != null and goodsType != ''">
		        AND G.GOODS_TYPE = #{goodsType}
		        </if>
		        <if test="supplyCompCd != null and supplyCompCd != ''">
		        AND G.SUPPLY_COMP_CD = #{supplyCompCd}
		        </if>
		        <if test="brandCd != null and brandCd != ''">
		        AND G.BRAND_CD = #{brandCd}
		        </if>
		        <if test="multiBrand != null and multiBrand != ''">
		        AND G.BRAND_CD IN
		            <foreach collection="multiBrand" item="item" index="index"  open="(" close=")" separator=",">
		        #{item}
		            </foreach>
		        </if>
		        <if test="selfMallYn != null and selfMallYn != ''">
		        AND G.SELF_MALL_YN = #{selfMallYn}
		        </if>
		        <if test="itemkindCd != null and itemkindCd != ''">
		        AND G.ITEMKIND_CD = #{itemkindCd}
		        </if>
		        <if test="multiItemkindCd != null and multiItemkindCd != ''">
		        AND G.ITEMKIND_CD IN
		            <foreach collection="multiItemkindCd" item="item" index="index"  open="(" close=")" separator=",">
		        #{item}
		            </foreach>
		        </if>
		        <if test="goodsStat != null and goodsStat != ''">
		        AND G.GOODS_STAT = #{goodsStat}
		        </if>
		        <if test="multiGoodsStat != null and multiGoodsStat != ''">
		        AND G.GOODS_STAT IN
		            <foreach collection="multiGoodsStat" item="item" index="index"  open="(" close=")" separator=",">
		        #{item}
		            </foreach>
		        </if>
		        <if test="styleYear != null and styleYear != ''">
		        AND G.STYLE_YEAR = (SELECT CD_NM FROM TB_COMMON_CODE WHERE CD = #{styleYear} AND CD_GB='G023')
		        </if>
		        <if test="multiStyleYear != null and multiStyleYear != ''">
		        AND G.STYLE_YEAR IN (SELECT CD_NM 
		                             FROM TB_COMMON_CODE 
		                             WHERE CD_GB='G023' 
		                             AND CD IN 
		                             <foreach collection="multiStyleYear" item="item" index="index"  open="(" close=")" separator=",">
		                             #{item}
		                             </foreach>
		                             )
		        </if>
		        <if test="seasonCd != null and seasonCd != ''">
		        AND G.SEASON_CD = #{seasonCd}
		        </if>
		        <if test="multiSeasonCd != null and multiSeasonCd != ''">
		        AND G.SEASON_CD IN
		            <foreach collection="multiSeasonCd" item="item" index="index"  open="(" close=")" separator=",">
		        #{item}
		            </foreach>
		        </if>
		        <if test="sexGb != null and sexGb != ''">
		        AND G.SEX_GB = #{sexGb}
		        </if>
		        <if test="changeableYn != null and changeableYn != ''">
		        AND G.CHANGEABLE_YN = #{changeableYn}
		        </if>
		        <if test="returnableYn != null and returnableYn != ''">
		        AND G.RETURNABLE_YN = #{returnableYn}
		        </if>
		        <if test="returnFeeFreeYn != null and returnFeeFreeYn != ''">
		        AND G.RETURN_FEE_FREE_YN = #{returnFeeFreeYn}
		        </if>
		        <if test="changeFeeFreeYn != null and changeFeeFreeYn != ''">
		        AND G.CHANGE_FEE_FREE_YN = #{changeFeeFreeYn}
		        </if>
		        <if test="formalGb != null and formalGb != ''">
		        AND G.FORMAL_GB = #{formalGb}
		        </if>
		        <if test='soldOutYn != null and soldOutYn == "Y"'>
		        AND EXISTS (
		                    SELECT GOODS_CD 
		                    FROM VW_STOCK
		                    WHERE SOLDOUT_YN = 'Y'
		                    AND GOODS_CD = G.GOODS_CD
		                   )
		        </if>
		        <if test='soldOutYn != null and soldOutYn == "N"'>
		        AND NOT EXISTS (
		                    SELECT GOODS_CD 
		                    FROM VW_STOCK
		                    WHERE SOLDOUT_YN = 'Y'
		                    AND GOODS_CD = G.GOODS_CD
		                   )
		        </if>
		        <if test="erpStockLinkYn != null and erpStockLinkYn != ''">
		        AND G.ERP_STOCK_LINK_YN = #{erpStockLinkYn}
		        </if>
		        <if test="erpPriceLinkYn != null and erpPriceLinkYn != ''">
		        AND G.ERP_PRICE_LINK_YN = #{erpPriceLinkYn}
		        </if>
		        <if test="mdNo != null and mdNo != ''">
		        AND G.BRAND_CD IN (
		            SELECT DISTINCT BRAND_CD
		            FROM   TB_BRAND_MD
		            WHERE  MD_NO = CAST(#{mdNo} AS UNSIGNED)
		        )
		        </if>
		        <if test="currPriceSt != null and currPriceSt != ''">
		        AND G.CURR_PRICE >= #{currPriceSt}
		        </if>
		        <if test="currPriceEd != null and currPriceEd != ''">
		        <![CDATA[
		        AND G.CURR_PRICE <= #{currPriceEd}
		         ]]>
		        </if>
		        <if test="dcRateSt != null and dcRateSt != ''">
		        AND G.DC_RATE >= #{dcRateSt}
		        </if>
		        <if test="dcRateEd != null and dcRateEd != ''">
		        <![CDATA[
		        AND G.DC_RATE <= #{dcRateEd}
		        ]]>
		        </if>
		        <if test='dateGbn != null and dateGbn == "P"'>
		            <if test="stDate != null and stDate != ''">
		        AND G.PRICE_UPD_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="edDate != null and edDate != ''">
		            <![CDATA[
		        AND G.PRICE_UPD_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		            ]]>
		            </if>
		        </if>
		        <if test='dateGbn != null and dateGbn == "R"'>
		            <if test="stDate != null and stDate != ''">
		        AND G.REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="edDate != null and edDate != ''">
		            <![CDATA[
		        AND G.REG_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		            ]]>
		            </if>
		        </if>
		        <if test='dateGbn != null and dateGbn == "S"'>
		            <if test="stDate != null and stDate != ''">
		        AND G.FRST_CFRM_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="edDate != null and edDate != ''">
		            <![CDATA[
		        AND G.FRST_CFRM_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		            ]]>
		            </if>
		        </if>
		        <if test="stockQtySt != null and stockQtySt != ''">
		        AND ST.CURR_STOCK_QTY >= #{stockQtySt}
		        </if>
		        <if test="stockQtyEd != null and stockQtyEd != ''">
		        <![CDATA[
		        AND ST.CURR_STOCK_QTY <= #{stockQtyEd}
		        ]]>
		        </if>
		        <if test="ageGrpCd != null and ageGrpCd != ''">
		        AND G.AGE_GRP_CD = #{ageGrpCd}
		        </if>
		        <if test="cateCd != null and cateCd != ''">
		        AND G.GOODS_CD IN (
		            SELECT GOODS_CD
		            FROM   TB_CATEGORY_GOODS
		            WHERE  CATE_CD = #{cateCd}
		        )
		        </if>
	</sql>
	
	<!-- 목록 페이징 정보 -->
	<sql id="getListPagingCondition_sql">
		<choose>
		<when test="pageable != null">
		    ) A
		)Z
		<if test='goodsPriceYn != null and goodsPriceYn == "Y"'>
		LEFT OUTER JOIN TB_GOODS_BENEFIT_PRICE GB ON Z.GOODS_CD = GB.GOODS_CD AND GB.CUST_GB = 'G100_00'
		</if> 
		WHERE RNUM BETWEEN  #{pageable.startRow} AND #{pageable.endRow}
		</when>
		<otherwise>
		    ) A
		)Z
		<if test='goodsPriceYn != null and goodsPriceYn == "Y"'>
		LEFT OUTER JOIN TB_GOODS_BENEFIT_PRICE GB ON Z.GOODS_CD = GB.GOODS_CD AND GB.CUST_GB = 'G100_00'
		</if> 
		</otherwise>
		</choose>
	</sql>
	
	<!-- 상품 목록 기본정보 엑셀  -->
	<select id="getGoodsInfoExcelList" parameterType="GoodsSearch" resultType="paramMap">
		/* TsaGoods.getGoodsInfoExcelList */
		SELECT G.GOODS_CD
		     , B.BRAND_ENM
		     , B.BRAND_GRP_NM
		     , G.BRAND_CD
		     , G.ITEMKIND_CD
		     , (SELECT SUPPLY_COMP_NM FROM TB_SUPPLY_COMPANY WHERE SUPPLY_COMP_CD = G.SUPPLY_COMP_CD) AS SUPPLY_COMP_CD
		     , G.SUPPLY_GOODS_CD
		     , G.GOODS_NUM
		     , G.GOODS_NM
		     , G.GOODS_TYPE
		     , FN_GET_CODE_NM('G008', G.GOODS_STAT) AS GOODS_STAT
		     , G.LIST_PRICE
		     , G.CURR_PRICE
		     , G.DC_RATE
		     , G.SELF_GOODS_YN
		     , FN_GET_CODE_NM('G009', G.FORMAL_GB) AS FORMAL_GB
		     , G.STYLE_YEAR
		     , FN_GET_CODE_NM('G006', G.SEASON_CD) AS SEASON_CD
		     , G.ERP_STOCK_LINK_YN
		     , G.CHANGEABLE_YN
		     , G.RETURNABLE_YN
		     , G.SELL_FEE_RATE
		     , DATE_FORMAT(G.PRICE_UPD_DT, '%Y-%m-%d %H:%i:%S') AS PRICE_UPD_DT
		     , DATE_FORMAT(G.FRST_CFRM_DT, '%Y-%m-%d %H:%i:%S') AS FRST_CFRM_DT
		     , CASE WHEN IMG_PATH1 IS NULL THEN
		           'N'
		       ELSE
		           'Y'
		       END AS GOODS_IMAGE_YN
		     /*, (CASE WHEN G.GOODS_TYPE = 'N' THEN (SELECT NVL(SUM(CURR_STOCK_QTY - BASE_STOCK_QTY),0) FROM VW_STOCK WHERE GOODS_CD = G.GOODS_CD) 
		             ELSE (SELECT NVL(SUM(CURR_STOCK_QTY - BASE_STOCK_QTY),0) FROM VW_STOCK_EXTEND WHERE GOODS_CD = G.GOODS_CD) 
		             END) AS STOCK_QTY_SUM*/
		     , (SELECT ITEMKIND_NM FROM TB_ITEMKIND WHERE ITEMKIND_CD = G.ITEMKIND_CD) AS ITEMKIND_NM
		     , GI.IMG_PATH1
		     , GI.IMG_PATH6
		     , GI.IMG_TYPE
		     , G.REG_NO
		     , DATE_FORMAT(G.REG_DT, '%Y-%m-%d %H:%i:%S') AS REG_DT
		     , G.UPD_NO
		     , DATE_FORMAT(G.UPD_DT, '%Y-%m-%d %H:%i:%S') AS UPD_DT
		FROM TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		INNER JOIN TB_GOODS_SUMMARY GS ON G.GOODS_CD = GS.GOODS_CD
		<if test="searchGb != null and searchGb =='EXTEND'">
		INNER JOIN TB_GOODS_EXTEND GE ON G.GOODS_CD =  GE.EXTEND_GOODS_CD
		                              AND GE.GOODS_CD IN
		    <foreach collection="conditionList" item="item" index="index"  open="(" close=")" separator=",">
		                              UPPER(#{item})
		    </foreach>
		</if>
		<if test="searchGb != null and searchGb =='MASTER'">
		INNER JOIN TB_GOODS_EXTEND GE ON G.GOODS_CD =  GE.GOODS_CD
		                              AND GE.EXTEND_GOODS_CD IN
		    <foreach collection="conditionList" item="item" index="index"  open="(" close=")" separator=",">
		                          UPPER(#{item})
		    </foreach>
		</if>
		<if test="searchGb != null and searchGb =='EXCEL'">
		INNER JOIN (
		             SELECT SEARCH_CD
		                  , TMP_DISP_ORD
		             FROM (
		                   SELECT SEARCH_CD
		                        , MIN(DISP_ORD) AS TMP_DISP_ORD
		                   FROM TB_SEARCH_DATA
		                   WHERE REG_NO = #{regNo}
		                   GROUP BY SEARCH_CD) T
		          ) SD
		           ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		                 OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                <if test="mdNo != null and mdNo != ''">
		                AND G.BRAND_CD IN (
		                                   SELECT DISTINCT BRAND_CD
		                                   FROM TB_BRAND_MD
		                                   WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                  )
		               </if>
		              )
		</if>
		LEFT OUTER JOIN TB_GOODS_IMG GI ON G.GOODS_CD = GI.GOODS_CD
		                                AND G.MAIN_COLOR_CD = GI.COLOR_CD
		WHERE 1=1
		<if test="searchGb == null or searchGb =='BASIC' or searchGb =='EXTEND' or searchGb =='MASTER'" >
		<include refid="getGoodsListCondition_sql"/>
		ORDER BY G.REG_DT DESC
		</if>
		<if test="searchGb == null or searchGb =='EXCEL'">
		ORDER BY SD.TMP_DISP_ORD
		</if>
	</select>
	
	<!-- 상품 정보 -->
	<select id="getGoods" parameterType="Goods" resultType="Goods">
		/* TsaGoods.getGoods */
		SELECT G.GOODS_CD
		     , G.GOODS_NM
		     , G.GOODS_TNM
		     , G.GOODS_SNM
		     , G.GOODS_SNM1
		     , G.BRAND_CD
		     , B.BRAND_GRP_NM
		     , B.BRAND_NO
		     , G.ITEMKIND_CD
		     , G.STYLE_YEAR
		     , G.SEASON_CD
		     , G.SEX_GB
		     , G.GOODS_NUM
		     , G.MAIN_COLOR_CD
		     , G.GOODS_TYPE
		     , G.LIST_PRICE
		     , G.CURR_PRICE
		     , G.CURR_BPRICE
		     , DATE_FORMAT(G.PRICE_UPD_DT, '%Y%m%d%H%i%S') AS PRICE_UPD_DT
		     , G.COST_PRICE
		     , G.DC_RATE
		     , G.GOODS_STAT
		     , G.SELF_GOODS_YN
		     , G.SELF_MALL_YN
		     , G.GOODS_GB
		     , G.DISTRIBUTION_GB
		     , G.SUPPLY_COMP_CD
		     , G.SUPPLY_GOODS_CD
		     , G.AGE_GRP_CD
		     , G.DELV_FEE_CD
		     , D.DELV_FEE
		     , D.MIN_ORD_AMT
		     , G.PNT_PRATE
		     , G.PNT_MRATE
		     , G.SELL_FEE_RATE
		     , G.FORMAL_GB
		     , G.RETURNABLE_YN
		     , G.CHANGEABLE_YN
		     , G.PRE_PPNT_USABLE_YN
		     , G.PRE_MPNT_USABLE_YN
		     , G.NEW_CUST_ORD_YN
		     , G.MIN_ORD_QTY
		     , G.MAX_ORD_QTY
		     , G.DAY_MAX_ORD_QTY
		     , G.GIFT_PACK_YN
		     , G.ERP_STOCK_LINK_YN
		     , G.ERP_PRICE_LINK_YN
		     , G.NEW_CUST_ORD_YN
		     , G.ADULT_YN
		     , FN_GET_CODE_NM('G076', G.ORIGIN_CD) AS MAKE_NM
		     , G.ORIGIN_CD
		     , G.MAKE_YMD
		     , G.TAX_GB
		     , G.GOODS_TYPE
		     , FN_GET_CODE_NM('G056', G.GOODS_TYPE) AS GOODS_TYPE_NM
		     , DATE_FORMAT(G.FRST_CFRM_DT, '%Y%m%d%H%i%S') AS FRST_CFRM_DT
		     , (SELECT I.NI_CLSF_CD FROM TB_ITEMKIND I WHERE I.ITEMKIND_CD = G.ITEMKIND_CD) AS NI_CLSF_CD
		     , GI.IMG_TYPE
		     , GI.IMG_PATH1
		     , GI.IMG_PATH6
		     , CASE WHEN IMG_PATH1 IS NULL THEN
		           'N'
		       ELSE
		           'Y'
		       END AS GOODS_IMAGE_YN
		     , (SELECT B.CD_NM 
		       FROM TB_ITEMKIND A
		          , TB_COMMON_CODE B 
		       WHERE A.ITEMKIND_CD = G.ITEMKIND_CD 
		       AND A.NI_CLSF_CD = B.CD 
		       AND B.CD_GB = 'G004') AS  NI_CLSF_NM
		     , FN_GET_USER_NM(G.UPD_NO) AS UPD_NM
		     , E.CERT_NUM
		     , E.CERT_DT
		FROM TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		LEFT OUTER JOIN TB_GOODS_IMG GI ON G.GOODS_CD = GI.GOODS_CD
		                                AND G.MAIN_COLOR_CD = GI.COLOR_CD
		LEFT OUTER JOIN TB_DELV_FEE_POLICY D ON G.SUPPLY_COMP_CD = D.SUPPLY_COMP_CD
		                                     AND G.DELV_FEE_CD =  D.DELV_FEE_CD
		LEFT OUTER JOIN TB_GOODS_SAFE_NO E ON G.GOODS_CD = E.GOODS_CD
		WHERE 1 = 1 
		<choose>
		<when test="goodsCd != null and goodsCd != ''">
		AND G.GOODS_CD = #{goodsCd}
		</when>
		<otherwise>
		AND G.SUPPLY_COMP_CD = #{supplyCompCd}
		AND G.SUPPLY_GOODS_CD = #{supplyGoodsCd}
		</otherwise>
		</choose>
	</select>
	
	<!-- 상품 상세 정보 조회 -->
	<select id="getGoodsDescList" parameterType="GoodsDesc" resultType="GoodsDesc">
		/* TsaGoods.getGoodsDescList */
		SELECT GOODS_CD
		     , DESC_GB
		     , SEQ
		     , GOODS_DESC
		FROM TB_GOODS_DESC
		WHERE GOODS_CD = #{goodsCd}
		AND DESC_GB = #{descGb}
		ORDER BY SEQ
	</select>
	
	<!-- 상품 고시정보 조회 -->
	<select id="getGoodsNotiInfoList" parameterType="GoodsNotiInfo" resultType="GoodsNotiInfo">
		/* TsaGoods.getGoodsNotiInfoList */
		SELECT C.GOODS_CD
		     , C.NI_CLSF_CD
		     , FN_GET_CODE_NM('G005', C.NI_ITEM_CD) AS NI_ITEM_NM
		     , C.NI_ITEM_CD
		     , C.NI_CONTENT
		     , C.DISP_ORD
		     , A.DISP_YN
		     , A.REQ_YN
		FROM TB_GOODS_NOTI_INFO C
		INNER JOIN TB_NOTI_INFO A ON C.NI_CLSF_CD = A.NI_CLSF_CD
		                          AND C.NI_ITEM_CD = A.NI_ITEM_CD
		                          AND A.SUPPLY_COMP_CD = CASE #{supplyCompCd} 
		                                                 WHEN 'S0001' THEN 'S0001'
		                                                 WHEN 'S0002' THEN 'S0002'
		                                                 ELSE 'E' END
		WHERE C.GOODS_CD = #{goodsCd}
		AND C.NI_CLSF_CD = #{niClsfCd}
		ORDER BY C.DISP_ORD
	</select>
	
	<!-- 상품의 정보고시 항목 목록 -->
	<select id="getNotiGoodsInfoList" parameterType="NotiInfo" resultType="NotiInfo">
		/* TsaGoods.getNotiGoodsInfoList */
		SELECT  N.SUPPLY_COMP_CD
		      , N.NI_CLSF_CD
		      , N.NI_ITEM_CD
		      , FN_GET_CODE_NM('G005', N.NI_ITEM_CD) AS NI_ITEM_NM
		      , CASE WHEN NI_ITEM_CD = 'G005_003' THEN NVL(G.COLOR_NM,N.NI_CONTENT)
		             WHEN NI_ITEM_CD = 'G005_004' THEN NVL(G.SIZE_NAME,N.NI_CONTENT)
		             WHEN NI_ITEM_CD = 'G005_006' THEN NVL(FN_GET_CODE_NM('G076', G.ORIGIN_CD),N.NI_CONTENT)
		             WHEN NI_ITEM_CD = 'G005_097' AND FN_GET_CODE_NM('G076', G.ORIGIN_CD) IN ('대한민국', '한국', 'KOREA') THEN 'N'
		             WHEN NI_ITEM_CD = 'G005_097' AND FN_GET_CODE_NM('G076', G.ORIGIN_CD) NOT IN ('대한민국', '한국', 'KOREA') THEN 'Y'
		             WHEN NI_ITEM_CD = 'G005_005' AND G.BRAND_CD= 'T007' THEN G.SUPPLY_COMP_NM
		             WHEN NI_ITEM_CD = 'G005_009' THEN NVL(G.MAKE_YMD, N.NI_CONTENT)
		        ELSE N.NI_CONTENT
		        END
		        AS  NI_CONTENT
		      , N.DISP_ORD
		      , N.REQ_YN
		      , N.DISP_YN
		 FROM (
		     SELECT G.GOODS_CD
		         , G.ITEMKIND_CD
		         , G.SUPPLY_COMP_CD
		         , G.ORIGIN_CD
		         , G.MAKE_YMD
		         , (SELECT GROUP_CONCAT(DISTINCT T.OPT_CD1) FROM TB_OPTION T WHERE T.GOODS_CD = G.GOODS_CD)  AS COLOR_NM
		         , (SELECT GROUP_CONCAT(DISTINCT T.OPT_CD2) FROM TB_OPTION T WHERE T.GOODS_CD = G.GOODS_CD)  AS SIZE_NAME
		         , G.BRAND_CD
		         , (SELECT SUPPLY_COMP_NM FROM tb_supply_company SC WHERE SC.SUPPLY_COMP_CD = G.SUPPLY_COMP_CD) AS SUPPLY_COMP_NM 
		     FROM TB_GOODS G
		     WHERE 1=1
		     AND G.GOODS_CD = #{goodsCd}
		   ) G
		  , TB_NOTI_INFO N
		 WHERE 1 = 1
		 AND N.NI_CLSF_CD = #{niClsfCd}
		 AND N.SUPPLY_COMP_CD =  CASE G.SUPPLY_COMP_CD
		                              WHEN 'S0001' THEN 'S0001'
		                              WHEN 'S0002' THEN 'S0002'
		                         ELSE 'E' END 
		 ORDER BY  G.GOODS_CD , N.NI_CLSF_CD, N.DISP_ORD
	</select>
	
	<!-- 상품 기본정보 이력 생성 -->
	<insert id="createGoodsHst" parameterType="Goods">
		/* TsaGoods.createGoodsHst */
		INSERT INTO TB_GOODS_HST 
		(       GOODS_CD
		      , BRAND_CD
		      , ITEMKIND_CD
		      , GOODS_NM
		      , GOODS_TNM
		      , GOODS_SNM
		      , GOODS_SNM1
		      , MAIN_COLOR_CD
		      , STYLE_YEAR
		      , SEASON_CD
		      , SEX_GB
		      , GOODS_NUM
		      , GOODS_TYPE
		      , LIST_PRICE
		      , CURR_PRICE
		      , CURR_BPRICE
		      , PRICE_UPD_DT
		      , COST_PRICE
		      , DC_RATE
		      , GOODS_STAT
		      , SELF_MALL_YN
		      , GOODS_GB
		      , DISTRIBUTION_GB
		      , SELF_GOODS_YN
		      , SUPPLY_COMP_CD
		      , SUPPLY_GOODS_CD
		      , AGE_GRP_CD
		      , DELV_FEE_CD
		      , PNT_PRATE
		      , PNT_MRATE
		      , SELL_FEE_RATE
		      , FORMAL_GB
		      , CHANGEABLE_YN
		      , RETURNABLE_YN
		      , CHANGE_FEE_FREE_YN
		      , RETURN_FEE_FREE_YN
		      , PRE_PPNT_USABLE_YN
		      , PRE_MPNT_USABLE_YN
		      , MIN_ORD_QTY
		      , MAX_ORD_QTY
		      , DAY_MAX_ORD_QTY
		      , GIFT_PACK_YN
		      , FRST_CFRM_DT
		      , ORIGIN_CD
		      , MAKE_YMD
		      , TAX_GB
		      , ERP_PRICE_LINK_YN
		      , ERP_STOCK_LINK_YN
		      , NEW_CUST_ORD_YN
		      , ADULT_YN
		      , REG_NO
		      , REG_DT
		      , UPD_NO
		      , UPD_DT
		)
		SELECT GOODS_CD            
		     , BRAND_CD            
		     , ITEMKIND_CD         
		     , GOODS_NM            
		     , GOODS_TNM           
		     , GOODS_SNM           
		     , GOODS_SNM1          
		     , MAIN_COLOR_CD
		     , STYLE_YEAR          
		     , SEASON_CD           
		     , SEX_GB              
		     , GOODS_NUM           
		     , GOODS_TYPE          
		     , LIST_PRICE          
		     , CURR_PRICE          
		     , CURR_BPRICE         
		     , PRICE_UPD_DT        
		     , COST_PRICE
		     , DC_RATE             
		     , GOODS_STAT          
		     , SELF_MALL_YN             
		     , GOODS_GB            
		     , DISTRIBUTION_GB     
		     , SELF_GOODS_YN       
		     , SUPPLY_COMP_CD      
		     , SUPPLY_GOODS_CD     
		     , AGE_GRP_CD          
		     , DELV_FEE_CD            
		     , PNT_PRATE           
		     , PNT_MRATE           
		     , SELL_FEE_RATE       
		     , FORMAL_GB           
		     , CHANGEABLE_YN       
		     , RETURNABLE_YN       
		     , CHANGE_FEE_FREE_YN  
		     , RETURN_FEE_FREE_YN  
		     , PRE_PPNT_USABLE_YN  
		     , PRE_MPNT_USABLE_YN  
		     , MIN_ORD_QTY         
		     , MAX_ORD_QTY         
		     , DAY_MAX_ORD_QTY     
		     , GIFT_PACK_YN
		     , FRST_CFRM_DT        
		     , ORIGIN_CD             
		     , MAKE_YMD            
		     , TAX_GB              
		     , ERP_PRICE_LINK_YN   
		     , ERP_STOCK_LINK_YN   
		     , NEW_CUST_ORD_YN
		     , ADULT_YN
		     , #{regNo}              
		     , NOW()              
		     , UPD_NO              
		     , UPD_DT              
		FROM TB_GOODS
		WHERE GOODS_CD = #{goodsCd}
	</insert>
	
	<!-- 상품  수정 항목 일괄변경 -->
	<update id="updateGoodsState" parameterType="Goods">
		/* TsaGoods.updateGoodsState */
		UPDATE TB_GOODS SET
		      UPD_NO = #{updNo}
		    , UPD_DT = NOW()
		<if test="goodsStat != null and goodsStat != ''" >
		    , GOODS_STAT = #{goodsStat}
		    , FRST_CFRM_DT = IF(#{chGoodsStatYn} = 'Y', COALESCE(FRST_CFRM_DT, NOW()) , FRST_CFRM_DT)
		</if>
		<if test="erpStockLinkYn != null and erpStockLinkYn != ''" >
		    , ERP_STOCK_LINK_YN = #{erpStockLinkYn}
		</if>
		<if test="erpPriceLinkYn != null and erpPriceLinkYn != ''" >
		    , ERP_PRICE_LINK_YN = #{erpPriceLinkYn}
		</if>
		<if test="formalGb != null and formalGb != ''" >
		    , FORMAL_GB = #{formalGb}
		    , PNT_PRATE = IFNULL(#{pntPrate}, PNT_PRATE)
		    , PNT_MRATE = IFNULL(#{pntMrate}, PNT_MRATE)
		</if>
		<if test='procJob == "pntPrate" and pntPrate != null' >
		    , PNT_PRATE = #{pntPrate}
		</if>
		<if test='procJob == "pntMrate"  and pntMrate != null' >
		    , PNT_MRATE = #{pntMrate}
		</if>
		<if test="returnableYn != null and returnableYn != ''" >
		    , RETURNABLE_YN = #{returnableYn}
		</if>
		<if test="changeableYn != null and changeableYn != ''" >
		    , CHANGEABLE_YN = #{changeableYn}
		</if>
		<if test="prePpntUsableYn != null and prePpntUsableYn != ''" >
		    , PRE_PPNT_USABLE_YN = #{prePpntUsableYn}
		</if>
		<if test="preMpntUsableYn != null and preMpntUsableYn != ''" >
		    , PRE_MPNT_USABLE_YN = #{preMpntUsableYn}
		</if>
		<if test="newCustOrdYn != null and newCustOrdYn != ''" >
		    , NEW_CUST_ORD_YN = #{newCustOrdYn}
		</if>
		<if test='procJob == "minOrdAmt"  and minOrdAmt != null and minOrdAmt != ""' >
		    , MIN_ORD_AMT = #{minOrdAmt}
		</if>
		<if test='blankFlag != null and blankFlag == "Y"'>
		    , GOODS_TNM = ''
		</if>
		<if test="goodsTnm != null and goodsTnm != ''" >
		    , GOODS_TNM = #{goodsTnm}
		</if>
		<if test="minOrdQty != null and minOrdQty > 0" >
		    , MIN_ORD_QTY = #{minOrdQty}
		</if>
		<if test="maxOrdQty != null and maxOrdQty > 0" >
		    , MAX_ORD_QTY = #{maxOrdQty}
		</if>
		<if test="dayMaxOrdQty != null and dayMaxOrdQty > 0" >
		    , DAY_MAX_ORD_QTY = #{dayMaxOrdQty}
		</if>
		<if test="giftPackYn != null and giftPackYn != ''" >
		    , GIFT_PACK_YN = #{giftPackYn}
		</if>
		<if test="delvFeeCd != null and delvFeeCd != ''" >
		    , DELV_FEE_CD = #{delvFeeCd}
		</if>
		
		WHERE GOODS_CD = #{goodsCd}
	</update>
	
	<!-- 상품 이미지 필수  항목 입력 여부  조회 -->
	<select id="getGoodsImgsYn" parameterType="Goods" resultType="Goods">
		/* TsaGoods.getGoodsImgsYn */
		SELECT A.GOODS_CD
		     , A.SUPPLY_COMP_CD
		     , (SELECT I.NI_CLSF_CD FROM TB_ITEMKIND I WHERE I.ITEMKIND_CD = A.ITEMKIND_CD) AS NI_CLSF_CD
		     , CASE WHEN B.IMG_PATH1 IS NULL THEN
		            'N'
		       ELSE
		            'Y'
		       END AS GOODS_IMAGE_YN
		FROM TB_GOODS A
		LEFT OUTER JOIN TB_GOODS_IMG B ON A.GOODS_CD = B.GOODS_CD
		                               AND A.MAIN_COLOR_CD = B.COLOR_CD
		WHERE 1 = 1
		<choose>
		<when test="goodsCd != null and goodsCd != ''">
		AND A.GOODS_CD  = #{goodsCd}
		</when>
		<otherwise>
		AND A.GOODS_CD IN
		    <foreach collection="arrGoodsCd" item="item" index="index"  open="(" close=")" separator=",">
		#{item}
		    </foreach>
		</otherwise>
		</choose>
	</select>
	
	<!-- 상품 정보 이력 -->
	<select id="getGoodsHstList" parameterType="Goods" resultType="GoodsHst">
		/*TsaGoods.getGoodsHstList*/
		SELECT CURR_PRICE
		     , CURR_BPRICE
		     , GOODS_NM
		     , GOODS_TNM
		     , GOODS_SNM
		     , FORMAL_GB
		     , GOODS_STAT
		     , SELL_FEE_RATE
		     , ERP_STOCK_LINK_YN
		     , CHANGEABLE_YN
		     , PRE_PPNT_USABLE_YN
		     , PRE_MPNT_USABLE_YN
		     , GOODS_SNM1
		     , ITEMKIND_CD
		     , SELF_MALL_YN
		     , GIFT_PACK_YN
		     , DATE_FORMAT(FRST_CFRM_DT, '%Y%m%d%H%i%S') AS FRST_CFRM_DT
		     , UPD_NO
		     , FN_GET_USER_NM(UPD_NO) AS UPD_NM
		     , DATE_FORMAT(UPD_DT, '%Y%m%d%H%i%S') AS UPD_DT
		     , REG_NO
		     , FN_GET_USER_NM(REG_NO) AS REG_NM
		     , DATE_FORMAT(REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		FROM TB_GOODS_HST
		WHERE GOODS_CD = #{goodsCd}
		ORDER BY REG_DT DESC
	</select>
	
	<!-- 상품 품목 변경 -->
	<update id="updateGoodItemKindCd" parameterType="Goods">
		/* TsaGoods.updateGoodItemKindCd */
		UPDATE TB_GOODS
		SET ITEMKIND_CD = #{itemkindCd}
		  , UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		WHERE GOODS_CD = #{goodsCd}
	</update >
	
	<!-- 상품 자동 검색어 조회-->
	<select id="getGoodsSnm" parameterType="String" resultType="String">
		/* TsaGoods.getGoodsSnm */
		WITH RECURSIVE TMP_COLOR_GOODS AS (
		    SELECT GOODS_CD
		         , REPLACE(CONCAT(GROUP_CONCAT(COLOR_GRP_CD),';',GROUP_CONCAT(COLOR_ENM),';',GROUP_CONCAT(CD_NM)),',',';') AS COLOR_INFO
		    FROM (
		        SELECT DISTINCT G.GOODS_CD, C.COLOR_GRP_CD, C.COLOR_ENM, D.CD_NM
		        FROM TB_GOODS G
		        LEFT OUTER JOIN TB_OPTION E ON G.GOODS_CD = E.GOODS_CD
		        LEFT OUTER JOIN TB_COLOR C ON E.OPT_CD1 = C.COLOR_CD
		                                   AND C.USE_YN= 'Y' 
		        LEFT OUTER JOIN TB_COMMON_CODE D ON C.COLOR_GRP_CD = D.CD
		                                   AND D.USE_YN= 'Y' 
		        WHERE G.GOODS_CD = #{goodsCd}
		        ) Z
		        GROUP BY GOODS_CD
		)
		SELECT UPPER(CONCAT(
		       G.GOODS_CD,';',
		       REPLACE(G.GOODS_NM,' ',''),';',
		       B.BRAND_ENM,';',
		       B.BRAND_KNM,';',
		       B.BRAND_GRP_NM,';',
		       G.STYLE_YEAR,';',
		       FN_GET_CODE_NM('G006',G.SEASON_CD),';',
		       FN_GET_CODE_NM('G007',G.SEX_GB),';',
		       NVL2(D.COLOR_INFO,CONCAT(D.COLOR_INFO,';'),''),
		       REPLACE(I.ITEMKIND_NM,'>',';')
		       )) AS GOODS_SNM
		FROM TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		LEFT OUTER JOIN TB_ITEMKIND I ON G.ITEMKIND_CD = I.ITEMKIND_CD
		LEFT OUTER JOIN TMP_COLOR_GOODS D ON G.GOODS_CD = D.GOODS_CD
		WHERE G.GOODS_CD = #{goodsCd}
	</select>
	
	<!-- 상품검색어 수정 -->
	<update id="updateGoodsSnm" parameterType="Goods">
		/* TsaGoods.updateGoodsSnm */
		UPDATE TB_GOODS A
		SET UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		  , GOODS_SNM = #{goodsSnm} 
		WHERE GOODS_CD = #{goodsCd}
	</update>
	
	<!-- 상품 품목변경 고시정보 조회  -->
	<select id="getNewNotiInfo" parameterType="Goods" resultType="GoodsNotiInfo">
		/* TsaGoods.getNewNotiInfo */
		SELECT D.NI_CLSF_CD
		     , NVL(C.NI_ITEM_CD, D.NI_ITEM_CD) AS NI_ITEM_CD
		     , NVL(C.NI_CONTENT, D.NI_CONTENT) AS NI_CONTENT
		     , D.DISP_ORD
		FROM (
		       SELECT A.NI_CLSF_CD
		          , A.NI_ITEM_CD
		          , A.NI_CONTENT
		          , A.DISP_ORD
		       FROM TB_NOTI_INFO A
		          , TB_ITEMKIND B
		       WHERE A.NI_CLSF_CD = B.NI_CLSF_CD
		       AND A.SUPPLY_COMP_CD = #{supplyCompCd}
		       AND B.ITEMKIND_CD = #{itemkindCd}
		     ) D
		    LEFT OUTER JOIN (
		       SELECT NI_ITEM_CD
		            , NI_CONTENT 
		       FROM TB_GOODS_NOTI_INFO
		       WHERE GOODS_CD = #{goodsCd}
		     ) C
		     ON (
		       C.NI_ITEM_CD = D.NI_ITEM_CD
		     )
		ORDER BY D.DISP_ORD
	</select>
	
	<!-- 상품 품목변경 고시정보 삭제  -->
	<delete id="deleteGoodsNotiInfo" parameterType="Goods">
		/* TsaGoods.deleteGoodsNotiInfo */
		DELETE FROM TB_GOODS_NOTI_INFO
		WHERE GOODS_CD = #{goodsCd}
	</delete>
	
	<!-- 상품 고시 정보  저장 -->
	<update id="saveGoodsNotiInfo" parameterType="GoodsNotiInfo">
		/* TsaGoods.saveGoodsNotiInfo */
		INSERT INTO TB_GOODS_NOTI_INFO(
		       GOODS_CD
		     , NI_CLSF_CD
		     , NI_ITEM_CD
		     , NI_CONTENT
		     , DISP_ORD
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{goodsCd}
		     , #{niClsfCd}
		     , #{niItemCd}
		     , #{niContent}
		     , #{dispOrd}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       NI_CONTENT = #{niContent}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</update>
	
	<!-- 상품 사이즈 조회 -->
	<select id="getGoodsSizeList" parameterType="Goods" resultType="Option">
		/* TsaGoods.getGoodsSizeList */
		WITH RECURSIVE TMP_GOODS AS (
		    SELECT A.GOODS_CD 
		         , A.GOODS_TYPE 
		         , IFNULL(B.COMPS_GOODS_CD, A.GOODS_CD) AS COMPS_GOODS_CD
		         , IFNULL(B.DISP_ORD,1) AS DISP_ORD
		         , A.SELF_GOODS_YN
		    FROM TB_GOODS A 
		    LEFT OUTER JOIN TB_GOODS_COMPOSE B ON A.GOODS_CD = B.GOODS_CD
		    WHERE A.GOODS_CD = #{goodsCd}
		    )
		SELECT #{goodsCd} AS GOODS_CD
		     , A.GOODS_CD AS COMPS_GOODS_CD
		     , A.OPT_CD
		     , CONCAT(A.OPT_CD1,  NVL2(A.OPT_CD2, '', CONCAT('/', A.OPT_CD2))) AS OPT_NM 
		     , A.OPT_CD1
		     , A.OPT_CD2
		     , A.ADD_PRICE
		     , A.BASE_STOCK_QTY
		     , A.CURR_STOCK_QTY
		     , IFNULL(B.STOCK_QTY,0) AS SALE_STOCK_QTY
		     , GREATEST(GREATEST(A.CURR_STOCK_QTY - A.BASE_STOCK_QTY, 0) - IFNULL(B.STOCK_QTY, 0), 0) AS ABLE_STOCK_QTY
		     , A.SOLDOUT_YN
		     , A.DISP_ORD
		     , A.DISP_YN
		     , COUNT(*) OVER(PARTITION BY A.GOODS_CD ) AS RCOUNT
		     , ROW_NUMBER() OVER(PARTITION BY A.GOODS_CD ORDER BY A.DISP_ORD) AS RNUM
		FROM  TMP_GOODS C 
		INNER JOIN TB_OPTION A ON C.COMPS_GOODS_CD = A.GOODS_CD 
		LEFT OUTER JOIN (
		                 SELECT Z.GOODS_CD
		                      , Z.OPT_CD
		                      , SUM((CASE Z.SELL_GB WHEN '10' THEN 1
		                                            WHEN '20' THEN 1
		                                            ELSE -1 END) * Z.SELL_QTY) AS STOCK_QTY
		                 FROM TB_SELL_QTY Z
		                 INNER JOIN TMP_GOODS Y ON Z.GOODS_CD = Y.COMPS_GOODS_CD
		                 GROUP BY Z.GOODS_CD, Z.OPT_CD
		                ) B
		           ON (  A.GOODS_CD = B.GOODS_CD
		             AND A.OPT_CD = B.OPT_CD)
		WHERE 1 = 1
		AND C.GOODS_CD = #{goodsCd}
		ORDER BY C.DISP_ORD, A.DISP_ORD
	</select>
	
	<!-- 상품 색상목록 조회 -->
	<select id="getGoodsColorList" parameterType="Goods" resultType="GoodsImg">
		/* TsaGoods.getGoodsColorList */
		SELECT A.GOODS_CD 
		     , NVL(A.OPT_CD1, A.MAIN_COLOR_CD) AS OPT_CD1
		     , A.MAIN_COLOR_CD
		     , IF(A.MAIN_COLOR_CD = NVL(A.OPT_CD1, A.MAIN_COLOR_CD), 'Y','N') AS  MAIN_COLOR_YN 
		     , GI.IMG_PATH1
		     , GI.IMG_PATH6
		     , NVL(GI.IMG_TYPE,'G030_A') AS IMG_TYPE
		     , C.COLOR_ENM 
		FROM (
		      SELECT A.GOODS_CD 
		           , A.MAIN_COLOR_CD 
		           , B.OPT_CD1 
		      FROM TB_GOODS A
		      LEFT OUTER JOIN TB_OPTION B ON A.GOODS_CD = B.GOODS_CD
		      WHERE A.GOODS_CD  = #{goodsCd}
		      GROUP BY A.GOODS_CD , B.OPT_CD1
		     ) A 
		LEFT OUTER JOIN TB_COLOR C ON A.OPT_CD1 = C.COLOR_CD 
		LEFT OUTER JOIN TB_GOODS_IMG GI ON A.GOODS_CD  = GI.GOODS_CD 
		                                AND A.OPT_CD1 = GI.COLOR_CD
	</select>
	
	<!-- 구성상품 목록 -->
	<select id="getGoodsDetailComposeList" parameterType="Goods" resultType="GoodsCompose">
		/* TsaGoods.getGoodsDetailComposeList */
		SELECT A.GOODS_CD
		     , A.GOODS_TYPE
		     , FN_GET_CODE_NM('G056', A.GOODS_TYPE) AS GOODS_TYPE_NM
		     , A.COMPS_GOODS_CD
		     , B.GOODS_NM AS COMPS_GOODS_NM
		     , A.DISP_ORD
		     , A.QTY
		     , A.COMPS_CURR_PRICE
		     , A.COMPS_CURR_PRICE AS COMPS_CURR_PRICE_ORG
		     , A.COMPS_GOODS_OPT_NM
		     , A.BASE_YN
		     , A.USE_YN
		     , B.CURR_PRICE
		     , B.GOODS_STAT
		     , B.SELF_GOODS_YN
		     , B.SUPPLY_COMP_CD
		     , I.IMG_PATH1
		     , I.IMG_PATH6
		     , I.IMG_TYPE
		     , A.REG_NO
		     , FN_GET_USER_NM(A.REG_NO) AS REG_NM
		     , DATE_FORMAT(A.REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		     , A.UPD_NO
		     , FN_GET_USER_NM(A.UPD_NO) AS UPD_NM
		     , DATE_FORMAT(A.UPD_DT, '%Y%m%d%H%i%S') AS UPD_DT
		FROM TB_GOODS_COMPOSE A
		INNER JOIN  TB_GOODS B ON A.COMPS_GOODS_CD = B.GOODS_CD
		LEFT OUTER JOIN TB_GOODS_IMG I ON A.COMPS_GOODS_CD = I.GOODS_CD
		                               AND B.MAIN_COLOR_CD = I.COLOR_CD
		WHERE A.GOODS_CD = #{goodsCd}
		ORDER BY A.DISP_ORD 
	</select>
	
	<!-- 상품 기본 정보 등록 -->
	<insert id="createGoods" parameterType="Goods">
		/* TsaGoods.createGoods */
		INSERT INTO TB_GOODS (
		    GOODS_CD
		  , BRAND_CD
		  , ITEMKIND_CD
		  , GOODS_NM
		  , GOODS_TNM
		  , GOODS_SNM
		  , GOODS_SNM1
		  , MAIN_COLOR_CD
		  , STYLE_YEAR
		  , SEASON_CD
		  , SEX_GB
		  , GOODS_NUM
		  , GOODS_TYPE
		  , LIST_PRICE
		  , CURR_PRICE
		  , COST_PRICE
		  , DC_RATE
		  , GOODS_STAT
		  , SELF_MALL_YN
		  , GOODS_GB
		  , DISTRIBUTION_GB
		  , SELF_GOODS_YN
		  , SUPPLY_COMP_CD
		  , SUPPLY_GOODS_CD
		  , AGE_GRP_CD
		  , DELV_FEE_CD
		  , PNT_PRATE
		  , PNT_MRATE
		  , SELL_FEE_RATE
		  , FORMAL_GB
		  , GIFT_PACK_YN
		  , ORIGIN_CD
		  , MAKE_YMD
		  , TAX_GB
		  , ERP_STOCK_LINK_YN
		  , NEW_CUST_ORD_YN
		  , ADULT_YN
		  , REG_NO
		  , REG_DT
		  , UPD_NO
		  , UPD_DT
		)
		VALUES(
		    #{goodsCd}
		  , #{brandCd}
		  , #{itemkindCd}
		  , NVL(#{goodsNm},'상품명없음')
		  , #{goodsTnm}
		  , #{goodsSnm}
		  , #{goodsSnm1}
		  , #{mainColorCd}
		  , #{styleYear}
		  , #{seasonCd}
		  , #{sexGb}
		  , #{goodsNum}
		  , NVL(#{goodsType},'N')
		  , #{listPrice}
		  , #{currPrice}
		  , #{costPrice}
		  , #{dcRate}
		  , #{goodsStat}
		  , NVL(#{selfMallYn},'Y') 
		  , #{goodsGb}
		  , #{distributionGb}
		  , #{selfGoodsYn}
		  , #{supplyCompCd}
		  , #{supplyGoodsCd}
		  , #{ageGrpCd}
		  , #{delvFeeCd}
		  , #{pntPrate}
		  , #{pntMrate}
		  , #{sellFeeRate}
		  , #{formalGb}
		  , NVL(#{giftPackYn},'N')
		  , #{originCd}
		  , #{makeYmd}
		  , #{taxGb}
		  , NVL(#{erpStockLinkYn},'N')
		  , NVL(#{newCustOrdYn},'N')
		  , NVL(#{adultYn},'N')
		  , #{regNo}
		  , NOW()
		  , #{updNo}
		  , NOW()
		)
	</insert>
	
	<!-- 상품 기본 정보 등록 -->
	<insert id="createGoodsSmmary" parameterType="Goods">
		/* TsaGoods.createGoodsSmmary */
		INSERT INTO TB_GOODS_SUMMARY (
		    GOODS_CD
		  , REG_NO
		  , REG_DT
		  , UPD_NO
		  , UPD_DT
		)
		VALUES(
		    #{goodsCd}
		  , #{regNo}
		  , NOW()
		  , #{updNo}
		  , NOW()
		)
	</insert>
	
	<!-- 상품 기본 정보 수정 -->
	<update id="updateGoods" parameterType="Goods">
		/* TsaGoods.updateGoods */
		UPDATE TB_GOODS
		SET GOODS_TNM = #{goodsTnm}
		  , GOODS_NM = #{goodsNm}
		  , SEASON_CD = #{seasonCd}
		  , SEX_GB = #{sexGb}
		  , CURR_PRICE = #{currPrice}
		  <if test="currBprice != null and currBprice != ''">
		  , CURR_BPRICE = #{currBprice}
		  , PRICE_UPD_DT = NOW()
		  </if>
		  , COST_PRICE = #{costPrice}
		  , DC_RATE = #{dcRate}
		  , GOODS_STAT = #{goodsStat}
		  , GOODS_GB = #{goodsGb}
		  , DELV_FEE_CD = #{delvFeeCd}
		  , PNT_PRATE = #{pntPrate}
		  , PNT_MRATE = #{pntMrate}
		  , FORMAL_GB = #{formalGb}
		  , MIN_ORD_QTY = #{minOrdQty}
		  , MAX_ORD_QTY = #{maxOrdQty}
		  , DAY_MAX_ORD_QTY = #{dayMaxOrdQty}
		  , ERP_STOCK_LINK_YN = #{erpStockLinkYn}
		  , GOODS_SNM1 = #{goodsSnm1}
		  , SELF_MALL_YN = #{selfMallYn}
		  , GOODS_SNM = #{goodsSnm}
		  , FRST_CFRM_DT = (CASE #{chGoodsStatYn} WHEN 'Y' THEN NVL2(FRST_CFRM_DT, NOW(), FRST_CFRM_DT)
		                                          ELSE FRST_CFRM_DT END)
		  , PRE_PPNT_USABLE_YN = #{prePpntUsableYn}
		  , PRE_MPNT_USABLE_YN = #{preMpntUsableYn}
		  , DISTRIBUTION_GB = #{distributionGb}
		  , RETURNABLE_YN = #{returnableYn}
		  , CHANGEABLE_YN = #{changeableYn}
		  , NEW_CUST_ORD_YN = #{newCustOrdYn}
		  , AGE_GRP_CD = #{ageGrpCd}
		  , SELL_FEE_RATE = #{sellFeeRate}
		  , GIFT_PACK_YN = #{giftPackYn}
		  , MAIN_COLOR_CD = #{mainColorCd}
		  , NEW_CUST_ORD_YN = #{newCustOrdYn}
		  , ADULT_YN = #{adultYn}
		  , UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		WHERE GOODS_CD = #{goodsCd}
	</update>
	
	<!-- 상품 상세정보 삭제 -->
	<delete id="deleteGoodsDesc" parameterType="GoodsDesc">
		/* TsaGoods.deleteGoodsDesc */
		DELETE FROM TB_GOODS_DESC
		WHERE GOODS_CD = #{goodsCd}
		AND DESC_GB = #{descGb}
	</delete>
	
	<!-- 상품 상세정보 등록 -->
	<insert id="createGoodsDesc" parameterType="GoodsDesc">
		/* TsaGoods.createGoodsDesc */
		INSERT INTO TB_GOODS_DESC (
		    GOODS_CD
		  , DESC_GB
		  , SEQ
		  , GOODS_DESC
		  , REG_NO
		  , REG_DT
		)
		VALUES(
		    #{goodsCd}
		  , #{descGb}
		  , #{seq}
		  , REPLACE(#{goodsDesc},char(13), CONCAT(char(13),char(10)))
		  , #{regNo}
		  , NOW()
		)
	</insert>
	
	<!-- 구상 상품등록/저장 -->
	<insert id="saveGoodsCompose" parameterType="GoodsCompose">
		/* TsaGoods.saveGoodsCompose */
		INSERT INTO TB_GOODS_COMPOSE (
		           GOODS_CD
		         , COMPS_GOODS_CD
		         , GOODS_TYPE
		         , DISP_ORD
		         , QTY
		         , COMPS_CURR_PRICE
		         , COMPS_GOODS_OPT_NM
		         , BASE_YN
		         , USE_YN
		         , REG_NO
		         , REG_DT
		         , UPD_NO
		         , UPD_DT
		    )
		    VALUES (
		           #{goodsCd}
		         , #{compsGoodsCd}
		         , #{goodsType}
		         , #{dispOrd}
		         , #{qty}
		         , (CASE WHEN #{goodsType} = 'G056_S' THEN #{compsCurrPrice}
		                ELSE 0 END)
		         , #{compsGoodsOptNm}
		         , #{baseYn}
		         , #{useYn}
		         , #{regNo}
		         , NOW()
		         , #{updNo}
		         , NOW()
		    )
		ON DUPLICATE KEY UPDATE 
		           DISP_ORD = #{dispOrd}
		         , COMPS_GOODS_OPT_NM = #{compsGoodsOptNm}
		         , COMPS_CURR_PRICE = (CASE WHEN #{goodsType} = 'G056_S' THEN #{compsCurrPrice}
		                                    ELSE 0 END)
		         , USE_YN = #{useYn}
		         , UPD_NO = #{updNo}
		         , UPD_DT = NOW()
	</insert>
	
	<!-- 상품 옵션/재고 정보 이력생성 -->
	<insert id="createStockHst" parameterType="Option">
	/* TsaGoods.createStockHst */
		INSERT INTO TB_OPTION_HST 
		(     OPTION_HST_SQ
		    , GOODS_CD
		    , OPT_CD
		    , OPT_CD1
		    , OPT_CD2
		    , BASE_STOCK_QTY
		    , CURR_STOCK_QTY
		    , ADD_PRICE
		    , SOLDOUT_YN
		    , DISP_ORD
		    , DISP_YN
		    , REG_NO
		    , REG_DT
		    , UPD_NO
		    , UPD_DT
		)
		SELECT NULL
		     , GOODS_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , BASE_STOCK_QTY
		     , CURR_STOCK_QTY
		     , ADD_PRICE
		     , SOLDOUT_YN
		     , DISP_ORD
		     , DISP_YN
		     , #{regNo}
		     , NOW()
		     , UPD_NO
		     , UPD_DT
		FROM TB_OPTION
		WHERE GOODS_CD = #{goodsCd}
		<if test='optCd != null and optCd != ""'>
		AND OPT_CD = #{optCd}
		</if>
	</insert>
	
	<!-- 상품 옵션/재고 정보 저장 -->
	<update id="saveStock" parameterType="Option">
		/* TsaGoods.saveStock */
		INSERT INTO TB_OPTION(
		       GOODS_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , BASE_STOCK_QTY
		     , CURR_STOCK_QTY
		     , ADD_PRICE
		     , SOLDOUT_YN
		     , DISP_ORD
		     , DISP_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{goodsCd}
		     , #{optCd}
		     , #{optCd1}
		     , #{optCd2}
		     , #{baseStockQty}
		     , #{currStockQty}
		     , #{addPrice}
		     , #{soldoutYn}
		     , #{dispOrd}
		     , #{dispYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE 
		        BASE_STOCK_QTY = #{baseStockQty}
		      , ADD_PRICE = #{addPrice}
		      , SOLDOUT_YN = #{soldoutYn}
		      , DISP_ORD = #{dispOrd}
		      , DISP_YN = #{dispYn}
		      , UPD_NO = #{updNo}
		      , UPD_DT = NOW()
		      <if test='selfGoodsYn != null and selfGoodsYn == "N"'>
		      , CURR_STOCK_QTY = #{currStockQty}
		      </if>
	</update>
	
	<!-- 상품코드 생성 -->
	<insert id="createGoodsSequence" parameterType="Goods">
		/* TsaGoods.createGoodsSequence */
		<selectKey keyProperty="goodsSq" resultType="int" order="AFTER">
		SELECT MAX(GOODS_SQ) FROM TB_GOODS_SEQUENCE
		</selectKey>
		INSERT INTO TB_GOODS_SEQUENCE (GOODS_SQ) VALUES (NULL)
	</insert>

	<!-- 상품 타이틀 예약관리 목록 건수 -->
	<select id="getGoodsTitleReserveCount" parameterType="GoodsSearch" resultType="int">
		/* TsaGoods.getGoodsTitleReserveCount */
		SELECT COUNT(*) AS TOTCNT
		FROM TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		INNER JOIN TB_GOODS_TNM_RES GR ON G.GOODS_CD = GR.GOODS_CD
		<if test="searchGb == null or searchGb =='BASIC'" >
		    <if test="applyStdt != null and applyStdt != ''">
		                               AND GR.APPLY_EDDT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		    </if>
		    <if test="applyEddt != null and applyEddt != ''">
		    <![CDATA[
		                               AND GR.APPLY_STDT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		    ]]>
		    </if>
		    <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		                               AND GR.APPLY_EDDT >= NOW() 
		    </if>
		    <if test="goodsTnmRes != null and goodsTnmRes != ''">
		                               AND UPPER(GR.GOODS_TNM) LIKE CONCAT('%',UPPER(#{goodsTnmRes}),'%')
		    </if>
		</if>
		<if test="searchGb != null and searchGb =='EXCEL'">
		INNER JOIN (
		            SELECT SEARCH_CD
		                 , TMP_DISP_ORD
		            FROM (
		                  SELECT SEARCH_CD
		                       , MIN(DISP_ORD) AS TMP_DISP_ORD
		                  FROM TB_SEARCH_DATA
		                  WHERE REG_NO = #{regNo}
		                  GROUP BY SEARCH_CD) T
		          ) SD
		          ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		               OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		               <if test="mdNo != null and mdNo != ''">
		               AND G.BRAND_CD IN (
		                                  SELECT DISTINCT BRAND_CD
		                                  FROM TB_BRAND_MD
		                                  WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                  )
		              </if>
		           )
		</if>
		WHERE 1=1
		<if test="searchGb == null or searchGb =='BASIC'" >
		<include refid="getGoodsListCondition_sql"/>
		</if>
	</select>

	<!-- 상품 타이틀 예약관리 목록 -->
	<select id="getGoodsTitleReserveList" parameterType="GoodsSearch" resultType="GoodsTnmRes">
		/* TsaGoods.getGoodsTitleReserveList */
		SELECT Z.*
		FROM (
		    SELECT A.*, @rownum := @rownum + 1 AS RNUM FROM (
		        SELECT
		                G.GOODS_CD
		              , B.BRAND_ENM
		              , B.BRAND_GRP_NM
		              , G.BRAND_CD
		              , G.SUPPLY_COMP_CD
		              , G.SUPPLY_GOODS_CD
		              , G.GOODS_NM
		              , G.GOODS_TNM
		              , G.SELF_GOODS_YN
		              , G.GOODS_STAT
		              , GR.GOODS_TNM_RES_SQ
		              , GR.GOODS_TNM AS REG_GOODS_TNM
		              , DATE_FORMAT(GR.APPLY_STDT,'%Y%m%d%H%i%S') AS APPLY_STDT
		              , DATE_FORMAT(GR.APPLY_EDDT,'%Y%m%d%H%i%S') AS APPLY_EDDT
		              , GR.REG_NO
		              , FN_GET_USER_NM(GR.REG_NO) AS REG_NM
		              , DATE_FORMAT(GR.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		        FROM TB_GOODS G
		        JOIN ( SELECT @rownum := 0) R
		        INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		        INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		        INNER JOIN TB_GOODS_TNM_RES GR ON G.GOODS_CD = GR.GOODS_CD
		        <if test="searchGb == null or searchGb =='BASIC'" >
		            <if test="applyStdt != null and applyStdt != ''">
		                                       AND GR.APPLY_EDDT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="applyEddt != null and applyEddt != ''">
		            <![CDATA[
		                                       AND GR.APPLY_STDT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		            ]]>
		            </if>
		            <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		                                       AND GR.APPLY_EDDT >= NOW() 
		            </if>
		            <if test="goodsTnmRes != null and goodsTnmRes != ''">
		                                       AND UPPER(GR.GOODS_TNM) LIKE CONCAT('%',UPPER(#{goodsTnmRes}),'%')
		            </if>
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        INNER JOIN (
		                    SELECT SEARCH_CD
		                         , TMP_DISP_ORD
		                    FROM (
		                          SELECT SEARCH_CD
		                               , MIN(DISP_ORD) AS TMP_DISP_ORD
		                          FROM TB_SEARCH_DATA
		                          WHERE REG_NO = #{regNo}
		                          GROUP BY SEARCH_CD) T
		                  ) SD
		                  ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		                       OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                       <if test="mdNo != null and mdNo != ''">
		                      AND G.BRAND_CD IN (
		                                          SELECT DISTINCT BRAND_CD
		                                          FROM TB_BRAND_MD
		                                          WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                          )
		                      </if>
		                   )
		        </if>
		        WHERE 1=1
		        <if test="searchGb == null or searchGb =='BASIC'" >
		        <include refid="getGoodsListCondition_sql"/>
		        ORDER BY  GR.APPLY_STDT DESC, GR.APPLY_EDDT DESC, G.GOODS_CD, GR.GOODS_TNM_RES_SQ
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        ORDER BY SD.TMP_DISP_ORD
		        </if>
		<include refid="getListPagingCondition_sql"/>
	</select>

	<!-- 상품 타이틀 예약조회(기간 체크용) -->
	<select id="getGoodsTnmDupChkCount" parameterType="GoodsTnmRes" resultType="int">
		/* TsaGoods.getGoodsTnmDupChkCount */
		SELECT COUNT(GOODS_CD)
		FROM TB_GOODS_TNM_RES
		WHERE 1=1
		<![CDATA[
		AND APPLY_STDT <= DATE_FORMAT(#{applyStdt}, '%Y%m%d%H%i%S')
		]]>
		AND APPLY_EDDT >= DATE_FORMAT(#{applyEddt},'%Y%m%d%H%i%S')
		AND GOODS_CD = #{goodsCd}
	</select>
	
	<!-- 상품 타이틀 예약 등록 -->
	<insert id="createGoodTnmRes" parameterType="GoodsTnmRes">
		/* TsaGoods.createGoodTnmRes */
		INSERT INTO TB_GOODS_TNM_RES (
		    GOODS_TNM_RES_SQ
		  , GOODS_CD
		  , GOODS_TNM
		  , APPLY_STDT
		  , APPLY_EDDT
		  , REG_NO
		  , REG_DT
		  , UPD_NO
		  , UPD_DT
		)
		VALUES(
		    NULL
		  , #{goodsCd}
		  , #{goodsTnm}
		  , STR_TO_DATE(#{applyStdt},'%Y%m%d%H%i%S')
		  , STR_TO_DATE(#{applyEddt},'%Y%m%d%H%i%S')
		  , #{regNo}
		  , NOW()
		  , #{updNo}
		  , NOW()
		)
	</insert>
	
	<!-- 상품 타이틀 수정 -->
	<update id="updateGoodTnm" parameterType="Goods">
		/* TsaGoods.updateGoodTnm */
		UPDATE TB_GOODS
		SET GOODS_TNM = #{goodsTnm}
		  , UPD_NO = #{updNo} 
		  , UPD_DT = NOW()
		WHERE GOODS_CD = #{goodsCd}
	</update >
	
	<!-- 상품 타이틀 예약 삭제 -->
	<delete id="deleteGoodTnmRes" parameterType="GoodsTnmRes">
		/* TsaGoods.deleteGoodTnmRes */
		DELETE FROM TB_GOODS_TNM_RES 
		WHERE GOODS_TNM_RES_SQ = #{goodsTnmResSq}
	</delete>
	
	<!-- 상품 타이틀 예약건 초기화 -->
	<update id="updateGoodTnmInit" parameterType="Goods">
		/* TsaGoods.updateGoodTnmInit */
		UPDATE TB_GOODS
		SET UPD_NO = #{updNo} 
		  , UPD_DT = NOW()
		  , GOODS_TNM = (SELECT S.GOODS_TNM
		                 FROM (
		                       SELECT GT.GOODS_CD
		                            , GT.GOODS_TNM
		                            , RANK() OVER(PARTITION BY GT.GOODS_CD ORDER BY GT.GOODS_TNM_RES_SQ DESC) RANK 
		                       FROM TB_GOODS_TNM_RES GT
		                       WHERE GT.APPLY_YN = 'N'
		                       AND NOW() BETWEEN GT.APPLY_STDT AND GT.APPLY_EDDT
		                       AND GT.GOODS_CD  = #{goodsCd}
		                      ) S
		                 WHERE S.RANK = 1
		                 )
		WHERE GOODS_CD = #{goodsCd}
	</update >
	
	<!-- 상품 타이틀 예약건 초기화 조회 -->
	<select id="getGoodTnmInit" parameterType="Goods"  resultType="Goods">
		/* TsaGoods.getGoodTnmInit */
		SELECT GOODS_CD
		     , GOODS_TNM
		     , (SELECT S.GOODS_TNM
		        FROM (
		              SELECT GT.GOODS_CD
		                   , GT.GOODS_TNM
		                   , RANK() OVER(PARTITION BY GT.GOODS_CD ORDER BY GT.GOODS_TNM_RES_SQ DESC) RANK 
		              FROM TB_GOODS_TNM_RES GT
		              WHERE GT.APPLY_YN = 'N'
		              AND NOW() BETWEEN GT.APPLY_STDT AND GT.APPLY_EDDT
		              AND GT.GOODS_CD  = #{goodsCd}
		             ) S
		        WHERE S.RANK = 1
		        ) AS GOOD_TNM_INIT
		FROM TB_GOODS
		WHERE GOODS_CD = #{goodsCd}
	</select>
	
	<!-- 상품예약판매 목록 건수 -->
	<select id="getGoodsResSellCount" parameterType="GoodsSearch" resultType="int">
		/* TsaGoods.getGoodsResSellCount */
		SELECT COUNT(*) AS TOTCNT
		FROM TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		INNER JOIN TB_GOODS_RES_SELL GR ON G.GOODS_CD = GR.GOODS_CD
		<if test="searchGb == null or searchGb =='BASIC'" >
		    <if test="applyStdt != null and applyStdt != ''">
		AND GR.DELV_RES_DT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		    </if>
		    <if test="applyEddt != null and applyEddt != ''">
		    <![CDATA[
		AND GR.DELV_RES_DT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		    ]]>
		    </if>
		    <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		AND GR.DELV_RES_DT >= NOW() 
		    </if>
		</if>
		<if test="searchGb != null and searchGb =='EXCEL'">
		INNER JOIN (
		            SELECT SEARCH_CD
		                 , TMP_DISP_ORD
		            FROM (
		                  SELECT SEARCH_CD
		                       , MIN(DISP_ORD) AS TMP_DISP_ORD
		                  FROM TB_SEARCH_DATA
		                  WHERE REG_NO = #{regNo}
		                  GROUP BY SEARCH_CD) T
		         ) SD
		         ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		               OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		               <if test="mdNo != null and mdNo !='' ">
		               AND G.BRAND_CD IN (
		                                  SELECT DISTINCT BRAND_CD
		                                  FROM TB_BRAND_MD
		                                  WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                  )
		              </if>
		           )
		</if>
		WHERE 1=1
		<if test="searchGb == null or searchGb =='BASIC'" >
		    <include refid="getGoodsListCondition_sql"/>
		</if>
	</select>

	<!-- 상품예약판매 목록 -->
	<select id="getGoodsResSellList" parameterType="GoodsSearch" resultType="GoodsResSell">
		/* TsaGoods.getGoodsResSellList */
		SELECT Z.*
		FROM (
		      SELECT A.*, @rownum := @rownum + 1 AS RNUM
		      FROM (
		            SELECT
		                   G.GOODS_CD
		                   , B.BRAND_ENM
		                   , G.BRAND_CD
		                   , G.SUPPLY_COMP_CD
		                   , G.SUPPLY_GOODS_CD
		                   , G.GOODS_NM
		                   , G.GOODS_STAT
		                   , GR.GOODS_RES_SELL_SQ
		                   , GR.USE_YN
		                   , DATE_FORMAT(GR.DELV_RES_DT,'%Y%m%d%H%i%S') AS DELV_RES_DT
		                   , GR.REG_NO
		                   , FN_GET_USER_NM(GR.REG_NO) AS REG_NM
		                   , DATE_FORMAT(GR.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		                   , GR.UPD_NO
		                   , FN_GET_USER_NM(GR.UPD_NO) AS UPD_NM
		                   , DATE_FORMAT(GR.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		            FROM TB_GOODS G
		            JOIN ( SELECT @rownum := 0) R
		            INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		            INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		            INNER JOIN TB_GOODS_RES_SELL GR ON G.GOODS_CD = GR.GOODS_CD
		            <if test="searchGb == null or searchGb =='BASIC'" >
		                <if test="applyStdt != null and applyStdt != ''">
		            AND GR.DELV_RES_DT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		                </if>
		                <if test="applyEddt != null and applyEddt != ''">
		                <![CDATA[
		            AND GR.DELV_RES_DT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		                ]]>
		                </if>
		                <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		            AND GR.DELV_RES_DT >= NOW() 
		                </if>
		            </if>
		            <if test="searchGb != null and searchGb =='EXCEL'">
		            INNER JOIN (
		                        SELECT SEARCH_CD
		                             , TMP_DISP_ORD
		                        FROM (
		                              SELECT SEARCH_CD
		                                   , MIN(DISP_ORD) AS TMP_DISP_ORD
		                              FROM TB_SEARCH_DATA
		                              WHERE REG_NO = #{regNo}
		                              GROUP BY SEARCH_CD) T
		                     ) SD
		                     ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		                           OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                           <if test="mdNo != null and mdNo != ''">
		                           AND G.BRAND_CD IN (
		                                              SELECT DISTINCT BRAND_CD
		                                              FROM TB_BRAND_MD
		                                              WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                              )
		                          </if>
		                       )
		            </if>
		            WHERE 1=1
		            <if test="searchGb == null or searchGb =='BASIC'" >
		            <include refid="getGoodsListCondition_sql"/>
		            ORDER BY  GR.DELV_RES_DT DESC, G.GOODS_CD, GR.GOODS_RES_SELL_SQ
		            </if>
		            <if test="searchGb != null and searchGb =='EXCEL'">
		            ORDER BY SD.TMP_DISP_ORD
		            </if>
		<include refid="getListPagingCondition_sql"/>
	</select>

	<!-- 상품예약판매 조회(기간 체크용) -->
	<select id="getGoodsResSellDupChkCount" parameterType="GoodsResSell" resultType="int">
		/* TsaGoods.getGoodsResSellDupChkCount */
		SELECT COUNT(GOODS_CD)
		FROM TB_GOODS_RES_SELL
		WHERE 1=1
		AND GOODS_CD = #{goodsCd}
		AND DELV_RES_DT > NOW()
	</select>

	<!-- 상품예약판매 등록 -->
	<insert id="createGoodResSell" parameterType="GoodsResSell">
		/* TsaGoods.createGoodResSell */
		INSERT INTO TB_GOODS_RES_SELL (
		  GOODS_RES_SELL_SQ
		, GOODS_CD
		, DELV_RES_DT
		, REG_NO
		, REG_DT
		, UPD_NO
		, UPD_DT
		)
		VALUES(
		  NULL
		, #{goodsCd}
		, STR_TO_DATE(#{delvResDt},'%Y%m%d%H%i%S')
		, #{regNo}
		, NOW()
		, #{updNo}
		, NOW()
		)
	</insert>

	<!-- 상품예약판매 등록 시 재고연동 비활성화 -->
	<update id="updateGoodsErpStockLinkYn" parameterType="GoodsResSell">
		/* TsaGoods.updateGoodsErpStockLinkYn */
		UPDATE TB_GOODS
		SET ERP_STOCK_LINK_YN = 'N'
		    , UPD_NO = #{updNo}
		    , UPD_DT =NOW()
		WHERE GOODS_CD = #{goodsCd}
	</update>

	<!-- 상품예약판매 삭제 -->
	<delete id="deleteGoodResSell" parameterType="GoodsResSell">
		/* TsaGoods.deleteGoodResSell */
		DELETE FROM TB_GOODS_RES_SELL
		WHERE GOODS_RES_SELL_SQ = #{goodsResSellSq}
	</delete>
	
	<!-- 네이버 EP 제외 상품 목록 건수 -->
	<select id="getGoodsEpSkipCount" parameterType="GoodsSearch" resultType="int">
		/* TsaGoods.getGoodsEpSkipCount */
		SELECT COUNT(*) AS TOTCNT
		FROM TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		INNER JOIN TB_GOODS_EP_SKIP GE ON G.GOODS_CD = GE.GOODS_CD
		<if test="searchGb == null or searchGb =='BASIC'" >
		<if test="applyStdt != null and applyStdt != ''">
		                               AND GE.APPLY_EDDT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		</if>
		<if test="applyEddt != null and applyEddt != ''">
		<![CDATA[
		                               AND GE.APPLY_STDT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		]]>
		</if>
		<if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		                               AND GE.APPLY_EDDT >= NOW() 
		</if>
		</if>
		<if test="searchGb != null and searchGb =='EXCEL'">
		INNER JOIN (
		    SELECT SEARCH_CD
		         , TMP_DISP_ORD
		    FROM (
		          SELECT SEARCH_CD
		               , MIN(DISP_ORD) AS TMP_DISP_ORD
		          FROM TB_SEARCH_DATA
		          WHERE REG_NO = #{regNo}
		          GROUP BY SEARCH_CD) T
		  ) SD
		  ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		       OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		       <if test="mdNo != null and mdNo != ''">
		       AND G.BRAND_CD IN (
		                          SELECT DISTINCT BRAND_CD
		                          FROM TB_BRAND_MD
		                          WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                          )
		      </if>
		   )
		</if>
		WHERE 1=1
		<if test="searchGb == null or searchGb =='BASIC'" >
		<include refid="getGoodsListCondition_sql"/>
		</if>
	</select>

	<!-- 네이버 EP 제외 상품 목록 -->
	<select id="getGoodsEpSkipList" parameterType="GoodsSearch" resultType="GoodsEpSkip">
		/* TsaGoods.getGoodsEpSkipList */
		SELECT Z.*
		FROM (
		    SELECT A.*, @rownum := @rownum + 1 AS RNUM FROM (
		        SELECT
		                G.GOODS_CD
		              , B.BRAND_ENM
		              , G.BRAND_CD
		              , G.SUPPLY_COMP_CD
		              , G.SUPPLY_GOODS_CD
		              , G.GOODS_NM
		              , G.GOODS_STAT
		              , GE.GOODS_EP_SKIP_SQ
		              , DATE_FORMAT(GE.APPLY_STDT,'%Y%m%d%H%i%S') AS APPLY_STDT
		              , DATE_FORMAT(GE.APPLY_EDDT,'%Y%m%d%H%i%S') AS APPLY_EDDT
		              , GE.REG_NO
		              , FN_GET_USER_NM(GE.REG_NO) AS REG_NM
		              , DATE_FORMAT(GE.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		              , GE.UPD_NO
		              , FN_GET_USER_NM(GE.UPD_NO) AS UPD_NM
		              , DATE_FORMAT(GE.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		        FROM TB_GOODS G
		        JOIN ( SELECT @rownum := 0) R
		        INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		        INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		        INNER JOIN TB_GOODS_EP_SKIP GE ON G.GOODS_CD = GE.GOODS_CD
		        <if test="searchGb == null or searchGb =='BASIC'" >
		            <if test="applyStdt != null and applyStdt != ''">
		                                       AND GE.APPLY_EDDT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="applyEddt != null and applyEddt != ''">
		            <![CDATA[
		                                       AND GE.APPLY_STDT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		            ]]>
		            </if>
		            <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		                                       AND GE.APPLY_EDDT >= NOW() 
		            </if>
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        INNER JOIN (
		                    SELECT SEARCH_CD
		                         , TMP_DISP_ORD
		                    FROM (
		                          SELECT SEARCH_CD
		                               , MIN(DISP_ORD) AS TMP_DISP_ORD
		                          FROM TB_SEARCH_DATA
		                          WHERE REG_NO = #{regNo}
		                          GROUP BY SEARCH_CD) T
		                  ) SD
		                  ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		                       OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                       <if test="mdNo != null and mdNo != ''">
		                      AND G.BRAND_CD IN (
		                                          SELECT DISTINCT BRAND_CD
		                                          FROM TB_BRAND_MD
		                                          WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                          )
		                      </if>
		                   )
		        </if>
		        WHERE 1=1
		        <if test="searchGb == null or searchGb =='BASIC'">
		        <include refid="getGoodsListCondition_sql"/>
		        ORDER BY GE.APPLY_STDT DESC, GE.APPLY_EDDT DESC, G.GOODS_CD, GE.GOODS_EP_SKIP_SQ
		        </if>
		         <if test="searchGb != null and searchGb =='EXCEL'">
		        ORDER BY SD.TMP_DISP_ORD
		        </if>
		<include refid="getListPagingCondition_sql"/>
	</select>

	<!-- 네이버 EP 제외 상품 조회(기간 체크용) -->
	<select id="getGoodsEpSkipDupChkCount" parameterType="GoodsEpSkip" resultType="int">
		/* TsaGoods.getGoodsEpSkipDupChkCount */
		SELECT COUNT(GOODS_CD)
		FROM TB_GOODS_EP_SKIP
		WHERE 1=1
		<![CDATA[
		AND APPLY_STDT <= DATE_FORMAT(#{applyStdt}, '%Y%m%d')
		]]>
		AND APPLY_EDDT >= DATE_FORMAT(#{applyEddt},'%Y%m%d%')
		AND GOODS_CD = #{goodsCd}
	</select>

	<!-- 네이버 EP 제외 상품 예약 등록 -->
	<insert id="createGoodEpSkip" parameterType="GoodsEpSkip">
		/* TsaGoods.createGoodEpSkip */
		INSERT INTO TB_GOODS_EP_SKIP (
		GOODS_EP_SKIP_SQ
		, GOODS_CD
		, APPLY_STDT
		, APPLY_EDDT
		, REG_NO
		, REG_DT
		, UPD_NO
		, UPD_DT
		)
		VALUES(
		  NULL
		, #{goodsCd}
		, STR_TO_DATE(#{applyStdt},'%Y%m%d%H%i%S')
		, STR_TO_DATE(#{applyEddt},'%Y%m%d%H%i%S')
		, #{regNo}
		, NOW()
		, #{updNo}
		, NOW()
		)
	</insert>

	<!-- 네이버 EP 제외 상품 예약 삭제 -->
	<delete id="deleteGoodEpSkip" parameterType="GoodsEpSkip">
		/* TsaGoods.deleteGoodEpSkip */
		DELETE FROM TB_GOODS_EP_SKIP
		WHERE GOODS_EP_SKIP_SQ = #{goodsEpSkipSq}
	</delete>
	
	<!-- 상품상세 공지사항 목록 -->
	<select id="getNoticeList" parameterType="GoodsSearch" resultType="Notice">
		/* TsaGoods.getNoticeList */
		SELECT A.NOTICE_SQ                                  
		     , A.NOTICE_TYPE                                
		     , A.NOTICE_TITLE                               
		     , A.NOTICE_CONTENT                             
		     , DATE_FORMAT(A.NOTICE_STDT,'%Y-%m-%d')  AS NOTICE_STDT 
		     , DATE_FORMAT(A.NOTICE_EDDT,'%Y-%m-%d')  AS NOTICE_EDDT 
		     , A.USE_YN                                          
		     , FN_GET_USER_NM(A.REG_NO)             AS REG_NM    
		     , DATE_FORMAT(A.REG_DT,'%Y-%m-%d %H:%i:%S') AS REG_DT
		     , FN_GET_USER_NM(A.UPD_NO)             AS UPD_NM    
		     , DATE_FORMAT(A.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT    
		FROM   TB_NOTICE A
		WHERE  A.NOTICE_TYPE = 'G047_30'
		<if test="stDate != null and stDate !=''">
		AND A.NOTICE_EDDT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		</if>
		<if test="edDate != null and edDate !=''">
		<![CDATA[
		AND A.NOTICE_STDT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		]]>
		</if>
		<if test='useYn != null and useYn !=""'>
		AND A.USE_YN = #{useYn}
		</if>
		<if test="noticeTitle != null and noticeTitle !=''">
		AND LOWER(A.NOTICE_TITLE) LIKE CONCAT('%',LOWER(#{noticeTitle}),'%')
		</if>
		<if test='conditionList != null and conditionList.length>0'>
		AND A.NOTICE_SQ IN (
		                    SELECT NOTICE_SQ
		                    FROM TB_NOTICE_GOODS
		                    WHERE GOODS_CD IN (
		                                       SELECT GOODS_CD 
		                                       FROM TB_GOODS G
		                                       WHERE 1 = 1
		                                       AND (
		    <choose>
		      <when test='search != null and search == "searchGoodsCd"'>
		          <foreach collection="conditionList" item="item" index="index" separator="or">
		       UPPER(G.GOODS_CD) LIKE CONCAT('%',UPPER(#{item}),'%') 
		          </foreach>
		      </when>
		      <when test='search != null and search == "searchGoodsNm"'>
		          <foreach collection="conditionList" item="item" index="index" separator="or">
		       UPPER(G.GOODS_NM) LIKE CONCAT('%',UPPER(#{item}),'%')
		          </foreach>
		      </when>
		      <when test='search != null and search == "searchGoodsNum"'>
		          <foreach collection="conditionList" item="item" index="index" separator="or">
		       UPPER(G.GOODS_NUM) LIKE CONCAT('%',UPPER(#{item}),'%')
		          </foreach>
		      </when>
		      <when test='search != null and search == "searchSupplyGoodsCd"'>
		          <foreach collection="conditionList" item="item" index="index" separator="or">
		       UPPER(G.SUPPLY_GOODS_CD) LIKE CONCAT('%',UPPER(#{item}),'%')
		          </foreach>
		      </when>
		    </choose>
		                                            )
		                                      )
		                   )
		</if>
		<if test="supplyCompCd != null and supplyCompCd  != ''">
		AND A.NOTICE_SQ IN (
		                    SELECT NOTICE_SQ
		                    FROM TB_NOTICE_GOODS
		                    WHERE GOODS_CD IN (
		                                       SELECT GOODS_CD 
		                                       FROM TB_GOODS 
		                                       WHERE SUPPLY_COMP_CD = #{supplyCompCd}
		                                       <if test="brandCd != null and brandCd  != ''">
		                                       AND BRAND_CD = #{brandCd} 
		                                       </if>
		                                      )
		                   )
		</if>
		ORDER  BY A.NOTICE_SQ DESC
	</select>
	
	<!-- 상품상세 공지사항 상품 목록 -->
	<select id="getNoticeGoodsList" parameterType="Notice" resultType="NoticeGoods">
		/* TsaGoods.getNoticeGoodsList */
		SELECT A.NOTICE_SQ
		     , A.GOODS_CD
		     , B.GOODS_NM
		FROM TB_NOTICE_GOODS A
		INNER JOIN TB_GOODS B ON A.GOODS_CD = B.GOODS_CD
		WHERE NOTICE_SQ = #{noticeSq}
		ORDER BY A.GOODS_CD
	</select>
	
	<!-- 상품상세 공지사항 상품저장 -->
	<insert id="saveNoticeGoods" parameterType="NoticeGoods">
		/* TsaGoods.saveNoticeGoods */
		INSERT INTO TB_NOTICE_GOODS (
		       NOTICE_SQ
		     , GOODS_CD
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{noticeSq}
		     , #{goodsCd}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       GOODS_CD = #{goodsCd}
		      ,UPD_NO = #{updNo}
		      ,UPD_DT = NOW()
	</insert>
	
	<!-- 상품상세 공지사항 상품 삭제 -->
	<delete id="deleteNoticeGoods" parameterType="NoticeGoods">
		/* TsaGoods.deleteNoticeGoods */
		DELETE FROM TB_NOTICE_GOODS 
		WHERE NOTICE_SQ =  #{noticeSq}
		AND GOODS_CD = #{goodsCd}
	</delete>
	
	<!-- 상품 가격예약 목록 건수 -->
	<select id="getGoodsPriceResCount" parameterType="GoodsSearch" resultType="int">
		/* TsaGoods.getGoodsPriceResCount */
		SELECT COUNT(*) AS TOTCNT
		FROM TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		INNER JOIN TB_GOODS_PRICE_RES GR ON G.GOODS_CD = GR.GOODS_CD
		<if test="searchGb == null or searchGb =='BASIC'" >
		    <if test="applyStdt != null and applyStdt != ''">
		                               AND GR.APPLY_EDDT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		    </if>
		    <if test="applyEddt != null and applyEddt != ''">
		    <![CDATA[
		                               AND GR.APPLY_STDT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		    ]]>
		    </if>
		    <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		                               AND GR.APPLY_EDDT >= NOW() 
		    </if>
		    <if test="goodsPriceResSt != null and goodsPriceResSt != ''">
		                               AND GR.RES_GOODS_PRICE >= #{goodsPriceResSt}
		    </if>
		    <if test="goodsPriceResEd != null and goodsPriceResEd != ''">
		    <![CDATA[
		                               AND GR.RES_GOODS_PRICE <= #{goodsPriceResEd}
		     ]]>
		    </if>
		</if>
		<if test="searchGb != null and (searchGb =='EXCEL' or searchGb =='EXCELRESULT')">
		INNER JOIN (
		            SELECT SEARCH_CD
		                 , TMP_DISP_ORD
		            FROM (
		                  SELECT SEARCH_CD
		                       , MIN(DISP_ORD) AS TMP_DISP_ORD
		                  FROM TB_SEARCH_DATA
		                  WHERE REG_NO = #{regNo}
		                  GROUP BY SEARCH_CD) T
		          ) SD
		          ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		               OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		               <if test="mdNo != null and mdNo != ''">
		               AND G.BRAND_CD IN (
		                                  SELECT DISTINCT BRAND_CD
		                                  FROM TB_BRAND_MD
		                                  WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                  )
		              </if>
		           )
		</if>
		WHERE 1=1
		<if test="searchGb == null or searchGb =='BASIC'" >
		<include refid="getGoodsListCondition_sql"/>
		</if>
	</select>

	<!-- 상품 가격예약 목록 -->
	<select id="getGoodsPriceResList" parameterType="GoodsSearch" resultType="GoodsPriceRes">
		/* TsaGoods.getGoodsPriceResList */
		SELECT Z.*
		FROM (
		    SELECT A.*, @rownum := @rownum + 1 AS RNUM FROM (
		        SELECT
		                G.GOODS_CD
		              , G.CURR_PRICE
		              , G.LIST_PRICE
		              , B.BRAND_ENM
		              , B.BRAND_GRP_NM
		              , G.BRAND_CD
		              , G.SUPPLY_COMP_CD
		              , G.SUPPLY_GOODS_CD
		              , G.GOODS_NM
		              , G.GOODS_TNM
		              , G.SELF_GOODS_YN
		              , G.GOODS_STAT
		              , GR.GOODS_PRICE_RES_SQ
		              , GR.RES_GOODS_PRICE
		              , GR.END_GOODS_PRICE
		              , GR.SELL_FEE_RATE
		              , DATE_FORMAT(GR.APPLY_STDT,'%Y%m%d%H%i%S') AS APPLY_STDT
		              , DATE_FORMAT(GR.APPLY_EDDT,'%Y%m%d%H%i%S') AS APPLY_EDDT
		              , GR.CFRM_YN
		              , GR.CFRM_NO
		              , FN_GET_USER_NM(GR.REG_NO) AS CFRM_NM
		              , DATE_FORMAT(GR.CFRM_DT,'%Y%m%d%H%i%S') AS CFRM_DT
		              , GR.APPLY_YN
		              , GR.REG_NO
		              , FN_GET_USER_NM(GR.REG_NO) AS REG_NM
		              , DATE_FORMAT(GR.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		              , FN_GET_USER_NM(GR.UPD_NO) AS UPD_NM
		              , DATE_FORMAT(GR.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		        FROM TB_GOODS G
		        JOIN ( SELECT @rownum := 0) R
		        INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		        INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		        INNER JOIN TB_GOODS_PRICE_RES GR ON G.GOODS_CD = GR.GOODS_CD
		        <if test="searchGb == null or searchGb =='BASIC'" >
		            <if test="applyStdt != null and applyStdt != ''">
		                                       AND GR.APPLY_EDDT >= DATE_FORMAT(#{applyStdt}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="applyEddt != null and applyEddt != ''">
		            <![CDATA[
		                                       AND GR.APPLY_STDT < DATE_FORMAT(DATE_ADD(#{applyEddt}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		            ]]>
		            </if>
		            <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		                                       AND GR.APPLY_EDDT >= NOW() 
		            </if>
		            <if test="goodsPriceResSt != null and goodsPriceResSt != ''">
		                                       AND GR.RES_GOODS_PRICE >= #{goodsPriceResSt}
		            </if>
		            <if test="goodsPriceResEd != null and goodsPriceResEd != ''">
		            <![CDATA[
		                                       AND GR.RES_GOODS_PRICE <= #{goodsPriceResEd}
		             ]]>
		            </if>
		        </if>
		        <if test="searchGb != null and (searchGb =='EXCEL' or searchGb =='EXCELRESULT')">
		        INNER JOIN (
		                    SELECT SEARCH_CD
		                         , TMP_DISP_ORD
		                    FROM (
		                          SELECT SEARCH_CD
		                               , MIN(DISP_ORD) AS TMP_DISP_ORD
		                          FROM TB_SEARCH_DATA
		                          WHERE REG_NO = #{regNo}
		                          GROUP BY SEARCH_CD) T
		                  ) SD
		                  ON ( (G.GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')
		                       OR G.SUPPLY_GOODS_CD LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                       <if test="mdNo != null and mdNo != ''">
		                      AND G.BRAND_CD IN (
		                                          SELECT DISTINCT BRAND_CD
		                                          FROM TB_BRAND_MD
		                                          WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                          )
		                      </if>
		                   )
		        </if>
		        WHERE 1=1
		        AND G.SELF_GOODS_YN = #{selfGoodsYn}
		        <if test="searchGb == null or searchGb =='BASIC'" >
		        <include refid="getGoodsListCondition_sql"/>
		        ORDER BY  GR.APPLY_STDT DESC, GR.APPLY_EDDT DESC, G.GOODS_CD, GR.GOODS_PRICE_RES_SQ
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        ORDER BY SD.TMP_DISP_ORD
		        </if>
		<include refid="getListPagingCondition_sql"/>
	</select>

	<!-- 상품 가격예약 조회(기간 체크용) -->
	<select id="getGoodsPriceResDupChkCount" parameterType="GoodsPriceRes" resultType="int">
		/* TsaGoods.getGoodsPriceResDupChkCount */
		SELECT COUNT(GOODS_CD)
		FROM TB_GOODS_PRICE_RES
		WHERE GOODS_CD = #{goodsCd}
		<![CDATA[
		AND APPLY_STDT <= DATE_FORMAT(#{applyStdt}, '%Y%m%d%H%i%S')
		]]>
		AND APPLY_EDDT >= DATE_FORMAT(#{applyEddt},'%Y%m%d%H%i%S')
	</select>

	<!-- 상품 가격예약 등록 -->
	<insert id="createGoodPriceRes" parameterType="GoodsPriceRes">
		/* TsaGoods.createGoodPriceRes */
		INSERT INTO TB_GOODS_PRICE_RES (
		  GOODS_PRICE_RES_SQ
		, GOODS_CD
		, RES_GOODS_PRICE
		, END_GOODS_PRICE
		, SELL_FEE_RATE
		, APPLY_STDT
		, APPLY_EDDT
		, CFRM_YN
		, CFRM_NO
		, CFRM_DT
		, APPLY_YN
		, REG_NO
		, REG_DT
		, UPD_NO
		, UPD_DT
		)
		VALUES(
		  NULL
		, #{goodsCd}
		, #{resGoodsPrice}
		, #{endGoodsPrice}
		, #{sellFeeRate}
		, STR_TO_DATE(#{applyStdt},'%Y%m%d%H%i%S')
		, STR_TO_DATE(#{applyEddt},'%Y%m%d%H%i%S')
		, NVL(#{cfrmYn},'N')
		, #{cfrmNo}
		, #{cfrmDt}
		, NVL(#{applyYn},'N')
		, #{regNo}
		, NOW()
		, #{updNo}
		, NOW()
		)
	</insert>

	<!-- 상품 가격예약 삭제 -->
	<delete id="deleteGoodPriceRes" parameterType="GoodsPriceRes">
		/* TsaGoods.deleteGoodPriceRes */
		DELETE FROM TB_GOODS_PRICE_RES
		WHERE GOODS_PRICE_RES_SQ = #{goodsPriceResSq}
		AND APPLY_YN = 'N'
	</delete>

	<!-- 상품 동영상 조회 -->
	<select id="getGoodsVideoList" parameterType="GoodsVideo" resultType="GoodsVideo">
		/* TsaGoods.getGoodsVideoList */
		SELECT A.VIDEO_SQ
		     , B.BRAND_CD
		     , B.BRAND_ENM
		     , B.BRAND_GRP_NM
		     , A.DISPLOC_VAL AS GOODS_CD
		     , E.VIDEO_GB
		     , E.VIDEO_VAL
		     , A.DISP_YN
		     , A.REG_NO
		     , FN_GET_USER_NM(A.REG_NO) AS REG_NM
		     , DATE_FORMAT(A.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		     , A.UPD_NO
		     , FN_GET_USER_NM(A.UPD_NO) AS REG_NM
		     , DATE_FORMAT(A.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		FROM TB_VIDEO_DISPLOC A
		INNER JOIN TB_VIDEO E ON A.VIDEO_SQ = E.VIDEO_SQ
		INNER JOIN (SELECT C.GOODS_CD
		                 , C.BRAND_CD
		                 , D.BRAND_ENM
		                 , D.BRAND_GRP_NM
		            FROM TB_GOODS C
		            INNER JOIN TB_BRAND D ON C.BRAND_CD = D.BRAND_CD
		            WHERE 1 = 1
		            <if test='goodsNm != null and goodsNm != "" '>
		            AND C.GOODS_NM = #{goodsNm}
		            </if>
		            <if test='goodsNum != null and goodsNum != "" '>
		            AND C.GOODS_NUM = #{goodsNum}
		            </if>
		            <if test='supplyGoodsCd != null and supplyGoodsCd != "" '>
		            AND C.SUPPLY_GOODS_CD = #{supplyGoodsCd}
		            </if>
		            <if test='brandEnm != null and brandEnm != "" '>
		            AND (
		                 D.BRAND_ENM LIKE #{brandEnm}||'%'
		                 OR
		                 D.BRAND_KNM LIKE #{brandEnm}||'%'
		                )
		            </if>
		            ) B
		           ON (A.DISPLOC_VAL = B.GOODS_CD
		           )
		WHERE A.DISPLOC_VAL = B.GOODS_CD
		AND A.DISPLOC_GB = 'G'
		<if test='goodsCd != null and goodsCd != "" '>
		AND A.DISPLOC_VAL = #{goodsCd}
		</if>
		<if test='stDate != null and stDate != "" '>
		<![CDATA[
		AND A.REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d')
		]]>
		</if>
		<if test='edDate != null and edDate != "" '>
		<![CDATA[
		AND A.REG_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		]]>
		</if>
		ORDER BY A.DISPLOC_VAL
	</select>
		
	<!-- 상품 동영상 노출안함으로 변경 -->
	<update id="updateNotUseGoodsVideo" parameterType="Video">
		/* TsaGoods.updateNotUseGoodsVideo */
		UPDATE TB_VIDEO_DISPLOC
		SET DISP_YN = 'N'
		  , UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		WHERE VIDEO_SQ = #{videoSq}
	</update>
	
	<!-- 동영상 코드 조회 -->
	<select id="getVideoSeq" parameterType="Video" resultType="String">
		/* TsaGoods.getVideoSeq */
		SELECT MAX(VIDEO_SQ) AS VIDEO_SQ
		FROM TB_VIDEO
		WHERE VIDEO_GB = #{videoGb}
		AND VIDEO_VAL = #{videoVal}
	</select>
	
	<!-- 동영상  등록 -->
	<insert id="createVideo" parameterType="Video">
		/* TsaGoods.createVideo */
		INSERT INTO TB_VIDEO
		    (
		           VIDEO_SQ
		         , VIDEO_GB
		         , VIDEO_VAL
		         , FYEAR
		         , TYEAR
		         , SEASON_STR
		         , VIDEO_TITLE
		         , VIDEO_TITLE2
		         , DISP_YN
		         , REG_NO
		         , REG_DT
		         , UPD_NO
		         , UPD_DT
		    )
		    VALUES (
		           NULL
		         , #{videoGb}
		         , #{videoVal}
		         , #{fyear}
		         , #{tyear}
		         , #{seasonStr}
		         , #{videoTitle}
		         , #{videoTitle2}
		         , #{dispYn}
		         , #{regNo}
		         , NOW()
		         , #{updNo}
		         , NOW()
		    )
	</insert>
	
	<!-- 동영상  수정 -->
	<update id="updateVideo" parameterType="Video">
		/* TsaGoods.saveVideo */
		UPDATE TB_VIDEO SET
		           DISP_YN = #{dispYn}
		         , VIDEO_GB = #{videoGb}
		         , VIDEO_VAL = #{videoVal}
		         , FYEAR = #{fyear}
		         , TYEAR = #{tyear}
		         , SEASON_STR = #{seasonStr}
		         , VIDEO_TITLE = #{videoTitle}
		         , VIDEO_TITLE2 = #{videoTitle2}
		         , UPD_NO = #{updNo}
		         , UPD_DT = NOW()
	</update>
	
	<!-- 동영상 위치 노출안함으로 처리 -->
	<update id="delVideoDispLoc" parameterType="Video">
		/* TsaGoods.initVideoDispLoc */
		UPDATE TB_VIDEO_DISPLOC
		SET DISP_YN = 'N'
		WHERE VIDEO_SQ = #{videoSq}
		AND DISPLOC_GB = #{displocGb}
	</update>
	
	<!-- 동영상 위치 등록 -->
	<insert id="saveVideoDispLoc" parameterType="Video">
		/* TsaGoods.saveVideoDispLoc */
		INSERT INTO TB_VIDEO_DISPLOC
		    (
		           VIDEO_SQ
		         , DISPLOC_GB
		         , DISPLOC_VAL
		         , DISP_YN
		         , REG_NO
		         , REG_DT
		         , UPD_NO
		         , UPD_DT
		    )
		    VALUES (
		           #{videoSq}
		         , #{displocGb}
		         , #{displocVal}
		         , #{dispYn}
		         , #{regNo}
		         , NOW()
		         , #{updNo}
		         , NOW()
		    )
		ON DUPLICATE KEY UPDATE
		       DISP_YN = #{dispYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</insert>
	
	<!-- 상품 옵션 존재여부 확인 -->
	<select id="getGoodsOptionCount" parameterType="Option" resultType="int">
		/* TsaGoods.getGoodsOptionCount */
		SELECT COUNT(*)
		FROM TB_OPTION
		WHERE GOODS_CD = #{goodsCd}
		<if test='optCd != null and optCd != ""'>
		AND OPT_CD = #{optCd}
		</if>
	</select>
	
	<!-- 상품 가격 승인 목록 -->
	<select id="getGoodsSupplyPriceList"  parameterType="GoodsPriceRes" resultType="GoodsPriceRes">
		/* TsaGoods.getGoodsSupplyPriceList */
		SELECT X.GOODS_PRICE_RES_SQ
		     , X.GOODS_CD
		     , X.RES_GOODS_PRICE
		     , X.END_GOODS_PRICE
		     , X.SELL_FEE_RATE
		     , X.CFRM_YN
		     , X.CFRM_NM
		     , X.CFRM_NO
		     , X.CFRM_DT
		     , X.APPLY_YN
		     , X.REG_NM
		     , X.REG_DT
		     , X.UPD_NM
		     , X.UPD_DT
		     , X.LIST_PRICE
		     , X.CURR_PRICE
		     , X.GOODS_STAT
		     , X.GOODS_SELL_FEE_RATE
		     , X.SUPPLY_COMP_CD
		     , X.SUPPLY_COMP_NM
		     , X.BRAND_CD
		     , X.BRAND_ENM
		FROM (
		    SELECT A.GOODS_PRICE_RES_SQ
		         , A.GOODS_CD
		         , A.RES_GOODS_PRICE
		         , A.END_GOODS_PRICE
		         , A.SELL_FEE_RATE
		         , A.CFRM_YN
		         , FN_GET_USER_NM(A.CFRM_NO) AS CFRM_NM
		         , A.CFRM_NO
		         , DATE_FORMAT(A.CFRM_DT,'%Y%m%d%H%i%S') AS CFRM_DT
		         , A.APPLY_YN
		         , FN_GET_USER_NM(A.REG_NO) AS REG_NM
		         , DATE_FORMAT(A.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		         , FN_GET_USER_NM(A.UPD_NO) AS UPD_NM
		         , DATE_FORMAT(A.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		         , G.LIST_PRICE
		         , G.CURR_PRICE
		         , G.SELL_FEE_RATE AS GOODS_SELL_FEE_RATE
		         , ROW_NUMBER() OVER(PARTITION BY A.GOODS_CD ORDER BY A.REG_DT DESC) AS RNUM
		         , G.GOODS_STAT
		         , G.BRAND_CD
		         , B.BRAND_ENM
		         , G.SUPPLY_COMP_CD
		         , S.SUPPLY_COMP_NM
		    FROM TB_GOODS_PRICE_RES A
		    INNER JOIN TB_GOODS G ON A.GOODS_CD = G.GOODS_CD
		                          AND G.SELF_GOODS_YN = 'N'
		    INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		    INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		    WHERE 1 = 1
		    <if test="goodsCd != null and goodsCd != ''">
		    AND UPPER(G.GOODS_CD) = LIKE UPPER('%' || #{goodsCd} || '%')
		    </if>
		    <if test="supplyCompCd != null and supplyCompCd != ''">
		    AND G.SUPPLY_COMP_CD = #{supplyCompCd}
		    </if>
		    <if test="brandCd != null and brandCd != ''">
		    AND G.BRAND_CD = #{brandCd}
		    </if>
		    <if test="searchBrandCd != null and searchBrandCd != ''">
		    AND G.BRAND_CD = #{searchBrandCd}
		    </if>
		    <if test="cfrmYn != null and cfrmYn != ''">
		    AND A.CFRM_YN = #{cfrmYn}
		    </if>
		    <if test='confirmY != null and confirmY == "N"'>
		        <if test='dateGbn != null and dateGbn == "R"'>
		            <if test="stDate != null and stDate != ''">
		    AND A.REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="edDate != null and edDate != ''">
		            <![CDATA[
		    AND A.REG_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		            ]]>
		            </if>
		        </if>
		        <if test='dateGbn != null and dateGbn == "P"'>
		            <if test="stDate != null and stDate != ''">
		    AND A.CFRM_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		            </if>
		            <if test="edDate != null and edDate != ''">
		            <![CDATA[
		    AND A.CFRM_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S') 
		            ]]>
		            </if>
		        </if>
		    </if>
		) X
		WHERE 1 = 1
		<if test='confirmY != null and confirmY == "Y"'>
		AND RNUM = 1
		AND CFRM_DT IS NULL
		</if>
		ORDER BY X.REG_DT DESC, X.GOODS_CD
	</select>
	
	<!-- 상품 가격수정 -->
	<update id="updateGoodsPrice" parameterType="Goods">
		/* TsaGoods.updateGoodsPrice */
		UPDATE TB_GOODS
		SET CURR_PRICE = #{currPrice}
		  , CURR_BPRICE = #{currBprice}
		  , PRICE_UPD_DT = NOW()
		  , DC_RATE = #{dcRate}
		  , UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		WHERE GOODS_CD = #{goodsCd}
	</update>
	
	<!-- 상품 판매수수료율수정 -->
	<update id="updateSellFeeRate" parameterType="Goods">
		/* TsaGoods.updateSellFeeRate */
		UPDATE TB_GOODS
		SET SELL_FEE_RATE = #{sellFeeRate}
		  , UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		WHERE GOODS_CD = #{goodsCd}
	</update>
	
	<!-- 상품 가격승인 적용일자 변경 -->
	<update id="updateGoodsSupplyPricecfrmDt" parameterType="GoodsPriceRes">
		/* TsaGoods.updateGoodsSupplyPricecfrmDt */
		UPDATE TB_GOODS_PRICE_RES
		SET UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		  , CFRM_DT = NOW()
		  , CFRM_NO = #{regNo}
		  , CFRM_YN = 'Y'
		  , APPLY_YN = 'Y'
		WHERE GOODS_CD = #{goodsCd}
		AND GOODS_PRICE_RES_SQ = #{goodsPriceResSq}
		AND CFRM_DT IS NULL
	</update>
	
	<!--  상품 안전인증번호 저장 -->
	<insert id="saveGoodsSafeNo"  parameterType="GoodsSafeNo">
		/* TsbGoods.saveGoodsSafeNo */
		INSERT INTO TB_GOODS_SAFE_NO (
		    GOODS_CD
		  , CERT_NUM
		  , CERT_DIV
		  , CERT_STATE
		  , CERT_DT
		  , REG_NO
		  , REG_DT
		  , UPD_NO
		  , UPD_DT
		)
		VALUES (
		    #{goodsCd}
		  , #{certNum}
		  , #{certDiv}
		  , #{certState}
		  , #{certDt}
		  , #{regNo}
		  , NOW()
		  , #{updNo}
		  , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       CERT_NUM = #{certNum}
		     , CERT_DIV = #{certDiv}
		     , CERT_STATE = #{certState}
		     , CERT_DT = #{certDt}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</insert>
	
	<!-- 상품 네이버 최저가 목록 -->
	<select id="getGoodsNaverPriceList" parameterType="GoodsSearch" resultType="GoodsNaverLowestPrice">
		/* TsaGoods.getGoodsNaverPriceList */
		        SELECT
		                GE.REQ_YMD
		              , G.GOODS_CD
		              , GE.MALL_NM
		              , GE.MALL_LINK
		              , GE.LOWEST_PRICE
		              , B.BRAND_ENM
		              , G.BRAND_CD
		              , G.GOODS_NUM
		              , G.GOODS_NM
		              , G.LIST_PRICE
		              , G.CURR_PRICE
		              , NVL(GB.PC_CURR_PRICE,G.CURR_PRICE) AS BENEFIT_PRICE
		              , FN_GET_USER_NM(GE.REG_NO) AS UPD_NM
		              , DATE_FORMAT(GE.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		              , FN_GET_USER_NM(GE.UPD_NO) AS UPD_NM
		              , DATE_FORMAT(GE.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		               <choose>
		                  <when test="searchGb != null and searchGb =='EXCEL'">
		              , SD.TMP_DISP_ORD
		                  </when>
		                  <otherwise>
		              , 0 AS TMP_DISP_ORD
		                  </otherwise>
		              </choose>
		        FROM TB_GOODS G
		        INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		        INNER JOIN TB_SUPPLY_COMPANY S ON G.SUPPLY_COMP_CD = S.SUPPLY_COMP_CD
		        INNER JOIN TB_GOODS_NAVER_LOWEST_PRICE GE ON G.GOODS_NUM = GE.GOODS_CD
		        LEFT OUTER JOIN TB_GOODS_BENEFIT_PRICE GB ON G.GOODS_CD = GB.GOODS_CD AND GB.CUST_GB = 'G100_00'
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        INNER JOIN (
		                     SELECT SEARCH_CD
		                          , TMP_DISP_ORD
		                     FROM (
		                           SELECT SEARCH_CD
		                                , MIN(DISP_ORD) AS TMP_DISP_ORD
		                           FROM TB_SEARCH_DATA
		                           WHERE REG_NO = #{regNo}
		                           GROUP BY SEARCH_CD) T
		                   ) SD
		                   ON ( (G.GOODS_NUM LIKE CONCAT(SD.SEARCH_CD,'%')) 
		                        <if test="mdNo != null and mdNo != ''">
		                        AND G.BRAND_CD IN (
		                                           SELECT DISTINCT BRAND_CD
		                                           FROM TB_BRAND_MD
		                                           WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                                           )
		                       </if>
		                   )
		        </if>
		        WHERE 1=1
		        <if test="mdNo != null and mdNo != ''">
		        AND G.BRAND_CD IN (
		                           SELECT DISTINCT BRAND_CD
		                           FROM TB_BRAND_MD
		                           WHERE MD_NO = CAST(#{mdNo} AS UNSIGNED)
		                          )
		        </if>
		        <if test="searchGb == null or searchGb =='BASIC' " >
		        <include refid="getGoodsListCondition_sql"/>
		        ORDER BY GE.REQ_YMD, G.GOODS_CD
		        </if>
		        <if test="searchGb != null and searchGb =='EXCEL'">
		        ORDER BY SD.TMP_DISP_ORD
		        </if>
	</select>
	
	<!-- 상품 네이버 최저가 최종 작업일 -->
	<select id="getGoodsNaverLowestPriceReqYmd" resultType="String">
		/* TsaGoods.getGoodsNaverLowestPriceReqYmd */
		SELECT MAX(REQ_YMD)
		FROM TB_GOODS_NAVER_LOWEST_PRICE
	</select>
	
	<!-- 상품 네이버 최저가 삭제 -->
	<delete id="deleteGoodsNaverLowestPrice">
		/* TsaGoods.deleteGoodsNaverLowestPrice */
		TRUNCATE TABLE TB_GOODS_NAVER_LOWEST_PRICE
	</delete>
	
	<!-- 상품 네이버 최저가 저장 -->
	<insert id="saveGoodsNaverLowestPrice"  parameterType="GoodsNaverLowestPrice" >
		/* TsaGoods.saveGoodsNaverLowestPrice */
		INSERT INTO TB_GOODS_NAVER_LOWEST_PRICE (
		    REQ_YMD
		  , GOODS_CD
		  , MALL_NM
		  , MALL_LINK
		  , LOWEST_PRICE
		  , REG_NO
		  , REG_DT
		  , UPD_NO
		  , UPD_DT
		)
		VALUES(
		    #{reqYmd}
		  , #{goodsCd}
		  , #{mallNm}
		  , #{mallLink}
		  , #{lowestPrice}
		  , #{regNo}
		  , NOW()
		  , #{updNo}
		  , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       MALL_NM = #{mallNm}
		     , MALL_LINK = #{mallLink}
		     , LOWEST_PRICE = #{lowestPrice}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</insert>
	
	<!-- 상품 구매등급 목록 -->
	<select id="getGoodsDetailOrderGradeList" parameterType="Goods" resultType="Goods">
		/* TsaGoods.getGoodsDetailOrderGradeList */
		SELECT  G.GOODS_CD
		      , A.CUST_GRADE
		      , FN_GET_CODE_NM('G101', A.CUST_GRADE) AS CUST_GRADE_NAME
		 FROM TB_GOODS_ORDER_GRADE A 
		 INNER JOIN TB_GOODS G ON A.GOODS_CD = G.GOODS_CD
		 WHERE A.GOODS_CD = #{goodsCd}
		 ORDER BY G.GOODS_CD, A.CUST_GRADE
	</select>
	
	<!-- 상품 구매등급 삭제 -->
	<delete id="deleteGoodsCustGrade" parameterType="Goods" >
		/* TsaGoods.saveGoodsNaverLowestPrice */
		DELETE FROM TB_GOODS_ORDER_GRADE
		WHERE GOODS_CD = #{goodsCd}
	</delete>
	
	<!-- 상품 구매등급 저장 -->
	<insert id="createGoodsCustGrade"  parameterType="Goods" >
		/* TsaGoods.createGoodsCustGrade */
		INSERT INTO TB_GOODS_ORDER_GRADE (
		    GOODS_CD
		  , CUST_GRADE
		  , REG_NO
		  , REG_DT
		)
		VALUES(
		    #{goodsCd}
		  , #{custGrade}
		  , #{regNo}
		  , NOW()
		)
	</insert>
	
	<!-- 광고 키워드 목록 -->
	<select id="getAdKeywordList" parameterType="AdKeyword" resultType="AdKeyword">
		/* TsaGoods.getAdKeywordList */
		SELECT A.AD_KEYWORD_SQ
		     , A.AD_KEYWORD
		     , A.USE_YN
		     , DATE_FORMAT(A.AD_KEYWORD_STDT,'%Y-%m-%d')  AS AD_KEYWORD_STDT 
		     , DATE_FORMAT(A.AD_KEYWORD_EDDT,'%Y-%m-%d')  AS AD_KEYWORD_EDDT 
		     , FN_GET_USER_NM(A.REG_NO)             AS REG_NM    
		     , DATE_FORMAT(A.REG_DT,'%Y-%m-%d %H:%i:%S') AS REG_DT
		     , FN_GET_USER_NM(A.UPD_NO)             AS UPD_NM    
		     , DATE_FORMAT(A.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT    
		FROM   TB_AD_KEYWORD A
		WHERE  1 = 1
		<if test="stDate != null and stDate !=''">
		AND A.AD_KEYWORD_EDDT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		</if>
		<if test="edDate != null and edDate !=''">
		<![CDATA[
		AND A.AD_KEYWORD_STDT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		]]>
		</if>
		<if test='useYn != null and useYn !=""'>
		AND A.USE_YN = #{useYn}
		</if>
		<if test="adKeyword != null and adKeyword !=''">
		AND LOWER(A.AD_KEYWORD) LIKE CONCAT('%',LOWER(#{adKeyword}),'%')
		</if>
		<if test='goodsCd != null and goodsCd != "" '>
		AND A.AD_KEYWORD_SQ IN (
		                    SELECT AD_KEYWORD_SQ
		                    FROM TB_AD_KEYWORD_GOODS
		                    WHERE GOODS_CD = #{goodsCd}
		                        )
		</if>
		ORDER  BY A.AD_KEYWORD_SQ DESC
	</select>
	
	<!-- 광고 키워드 저장 -->
	<insert id="saveAdKeyword" parameterType="AdKeyword">
		/* TsaGoods.saveAdKeyword */
		INSERT INTO TB_AD_KEYWORD (
		       AD_KEYWORD_SQ
		     , AD_KEYWORD
		     , AD_KEYWORD_STDT
		     , AD_KEYWORD_EDDT
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{adKeywordSq}
		     , #{adKeyword}
		     , #{adKeywordStdt}
		     , #{adKeywordEddt}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       AD_KEYWORD_STDT = #{adKeywordStdt}
		      ,AD_KEYWORD_EDDT = #{adKeywordEddt}
		      ,USE_YN = #{useYn}
		      ,UPD_NO = #{updNo}
		      ,UPD_DT = NOW()
	</insert>
	
	<!-- 광고 키워드 상품 목록 -->
	<select id="getAdKeywordGoodsList" parameterType="AdKeyword" resultType="AdKeywordGoods">
		/* TsaGoods.getAdKeywordGoodsList */
		SELECT A.AD_KEYWORD_SQ
		     , A.GOODS_CD
		     , A.DISP_ORD
		     , B.GOODS_NM
		FROM TB_AD_KEYWORD_GOODS A
		INNER JOIN TB_GOODS B ON A.GOODS_CD = B.GOODS_CD
		WHERE AD_KEYWORD_SQ = #{adKeywordSq}
		ORDER BY A.DISP_ORD, A.GOODS_CD
	</select>
	
	<!-- 광고 키워드 상품저장 -->
	<insert id="saveAdKeywordGoods" parameterType="AdKeywordGoods">
		/* TsaGoods.saveAdKeywordGoods */
		INSERT INTO TB_AD_KEYWORD_GOODS (
		       AD_KEYWORD_SQ
		     , GOODS_CD
		     , DISP_ORD
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{adKeywordSq}
		     , #{goodsCd}
		     , #{dispOrd}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
	</insert>
	
	<!-- 광고 키워드 삭제 -->
	<delete id="deleteAdKeywordGoods" parameterType="AdKeywordGoods">
		/* TsaGoods.deleteAdKeywordGoods */
		DELETE FROM TB_AD_KEYWORD_GOODS 
		WHERE AD_KEYWORD_SQ =  #{adKeywordSq}
		<if test="arrGoodsCd != null and arrGoodsCd.length>0">
		AND GOODS_CD IN
		    <foreach collection="arrGoodsCd" item="item" index="index"  open="(" close=")" separator=",">
		#{item}
		    </foreach>
		</if>
	</delete>
	
	<!-- 재입고알림 목록 건수 -->
	<select id="getReinboundInformCount" parameterType="GoodsSearch" resultType="int">
	/* TsaGoods.getReinboundInformCount */
		SELECT COUNT(*) AS TOTCNT
		FROM TB_REINBOUND_INFORM IA
		INNER JOIN TB_GOODS G ON IA.GOODS_CD = G.GOODS_CD
		                      AND G.GOODS_STAT IN ('G008_70', 'G008_90', 'G008_96')
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_SUPPLY_COMPANY SC ON G.SUPPLY_COMP_CD = SC.SUPPLY_COMP_CD
		INNER JOIN VW_STOCK VS ON IA.GOODS_CD = VS.GOODS_CD
		                       AND IA.OPT_CD = VS.OPT_CD
		INNER JOIN TB_CUSTOMER C ON IA.CUST_NO = C.CUST_NO
		LEFT OUTER JOIN TB_GOODS_IMG GI ON IA.GOODS_CD = GI.GOODS_CD
		                                AND IA.OPT_CD1 = GI.COLOR_CD
		WHERE 1=1
		<if test='alarmYn != null and alarmYn == "Y"'>
		AND IA.INFORM_DT IS NOT NULL
		</if>
		<if test='alarmYn != null and alarmYn == "N"'>
		AND IA.INFORM_DT IS NULL
		</if>
		<if test='condition != null and condition != "" '>
		    <choose>
		        <when test='search != null and search == "searchGoodsNm"'>
		AND UPPER(G.GOODS_NM) LIKE  CONCAT('%',UPPER(#{condition}),'%')
		        </when>
				<when test='search != null and search == "searchGoodsCd"'>
		AND UPPER(G.GOODS_CD) LIKE  CONCAT('%',UPPER(#{condition}),'%')
				</when>
		    </choose>
		</if>
		<if test='dateGbn != null and dateGbn == "reqDt"'>
		    <if test="stDate != null and stDate != ''">
		AND IA.REQ_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		    </if>
		    <if test="edDate != null and edDate != ''">
		    <![CDATA[
		AND IA.REQ_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		    ]]>
			</if>
		</if>
		<if test='dateGbn != null and dateGbn == "alarmDt"'>
		    <if test="stDate != null and stDate != ''">
		AND IA.INFORM_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		    </if>
		    <if test="edDate != null and edDate != ''">
		    <![CDATA[
		AND IA.INFORM_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		    ]]>
		    </if>
		</if>
		<if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		              AND DATE_FORMAT(IA.REQ_DT, '%Y%m%d')  >= DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -15 DAY), '%Y%m%d') 
		              </if>
		<include refid="getGoodsListCondition_sql"/>
		ORDER BY IA.REG_DT DESC
	</select>

	<!-- 재입고알림 목록 -->
	<select id="getReinboundInformList" parameterType="GoodsSearch" resultType="ReinboundInform">
		/* TsaGoods.getReinboundInformList */
		SELECT Z.*
		FROM (
		       SELECT A.*, @rownum := @rownum + 1 AS RNUM 
		       FROM (
		              SELECT IA.RINBD_INFO_SQ
		                   , IA.GOODS_CD
		                   , IA.OPT_CD
		                   , IA.OPT_CD1
		                   , IA.OPT_CD2
		                   , DATE_FORMAT(IA.REQ_DT,'%Y%m%d')  AS REQ_DT
		                   , DATE_FORMAT(IA.INFORM_DT,'%Y%m%d%H%i%S')  AS INFORM_DT
		                   , FN_GET_USER_NM(IA.REG_NO)             AS REG_NM
		                   , DATE_FORMAT(IA.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		                   , FN_GET_USER_NM(IA.UPD_NO)             AS UPD_NM
		                   , DATE_FORMAT(IA.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		                   , IA.CUST_NO
		                   , C.CUST_ID
		                   , C.CUST_NM
		                   , C.CELL_PHNNO
		                   , G.GOODS_NM
		                   , G.GOODS_STAT
		                   , B.BRAND_ENM
		                   , G.SELF_MALL_YN
		                   , GI.IMG_TYPE
		                   , GI.IMG_PATH1
		                   , GI.IMG_PATH6
		                   , VS.CURR_STOCK_QTY
		                   , VS.SOLDOUT_YN
		              FROM TB_REINBOUND_INFORM IA
		              JOIN ( SELECT @rownum := 0) R
		              INNER JOIN TB_GOODS G ON IA.GOODS_CD = G.GOODS_CD
		                                    AND G.GOODS_STAT IN ('G008_70', 'G008_90', 'G008_96')
		              INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		              INNER JOIN TB_SUPPLY_COMPANY SC ON G.SUPPLY_COMP_CD = SC.SUPPLY_COMP_CD
		              INNER JOIN VW_STOCK VS ON IA.GOODS_CD = VS.GOODS_CD
		                                     AND IA.OPT_CD = VS.OPT_CD
		              INNER JOIN TB_CUSTOMER C ON IA.CUST_NO = C.CUST_NO
		              LEFT OUTER JOIN TB_GOODS_IMG GI ON IA.GOODS_CD = GI.GOODS_CD
		                                              AND IA.OPT_CD1 = GI.COLOR_CD 
		              WHERE 1=1
		              <if test="rinbdInfoSq != null and rinbdInfoSq != ''">
		              AND IA.RINBD_INFO_SQ = #{rinbdInfoSq}
		              </if>
		              <if test='alarmYn != null and alarmYn == "Y"'>
		              AND IA.INFORM_DT IS NOT NULL
		              </if>
		              <if test='alarmYn != null and alarmYn == "N"'>
		              AND IA.INFORM_DT IS NULL
		              </if>
		              <if test='condition != null and condition != "" '>
		                  <choose>
		                      <when test='search != null and search == "searchGoodsNm"'>
		              AND UPPER(G.GOODS_NM) LIKE  CONCAT('%',UPPER(#{condition}),'%')
		                      </when>
		                      <when test='search != null and search == "searchGoodsCd"'>
		              AND UPPER(G.GOODS_CD) LIKE  CONCAT('%',UPPER(#{condition}),'%')
		                      </when>
		                  </choose>
		              </if>
		              <if test='dateGbn != null and dateGbn == "reqDt"'>
		                  <if test="stDate != null and stDate != ''">
		              AND IA.REQ_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		                  </if>
		                  <if test="edDate != null and edDate != ''">
		                  <![CDATA[
		              AND IA.REQ_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		                  ]]>
		                  </if>
		              </if>
		              <if test='dateGbn != null and dateGbn == "alarmDt"'>
		                  <if test="stDate != null and stDate != ''">
		              AND IA.INFORM_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		                  </if>
		                  <if test="edDate != null and edDate != ''">
		                  <![CDATA[
		              AND IA.INFORM_DT < DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
		                  ]]>
		                  </if>
		              </if>
		              <if test='beforSkipFlag != null and beforSkipFlag == "Y"'>
		              AND DATE_FORMAT(IA.REQ_DT, '%Y%m%d')  >= DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -15 DAY), '%Y%m%d') 
		              </if>
		              <include refid="getGoodsListCondition_sql"/>
		              ORDER BY IA.REG_DT DESC
		<include refid="getListPagingCondition_sql"/>
	</select>
	
	<!-- 재입고 알림톡 발송처리 -->
	<update id="updateReinboundInform" parameterType="ReinboundInform">
		/* TsaGoods.updateReinboundInform */
		UPDATE TB_REINBOUND_INFORM
		SET INFORM_DT = NOW()
		  , UPD_NO = #{updNo}
		  , UPD_DT = NOW()
		WHERE RINBD_INFO_SQ = #{rinbdInfoSq}
	</update>
	
	<!-- 상품이미지 목록 -->
	<select id="getGoodsImageList" parameterType="GoodsImg" resultType="GoodsImg">
		/* TsaGoods.getGoodsImageList */
		SELECT GOODS_CD
		     , COLOR_CD
		     , DISP_ORD
		     , ORG_IMG_NM /* S0001/20201221/14505664_L.jpg */
		     , SUBSTRING_INDEX(SYS_IMG_NM , '/', -1) AS SYS_IMG_NM
		     , SUBSTRING_INDEX(SYS_IMG_NM , '/', 2) AS SYS_IMG_URL
		     , DEFAULT_IMG_YN
		FROM   TB_GOODS_IMG_DX5
		WHERE  GOODS_CD = #{goodsCd}
		AND    COLOR_CD = #{colorCd}
		ORDER  BY DISP_ORD
	</select>
	
	<!-- 상품이미지 전체 삭제 -->
	<delete id="deleteGoodsImageTotal" parameterType="GoodsImg">
		/* TsaGoods.deleteGoodsImageTotal */
		DELETE
		FROM TB_GOODS_IMG_DX5
		WHERE GOODS_CD = #{goodsCd}
		AND COLOR_CD = #{colorCd}
	</delete>

	<!-- 상품이미지 삭제 -->
	<delete id="deleteGoodsImage" parameterType="GoodsImg">
		/* TsaGoods.deleteGoodsImage */
		DELETE
		FROM TB_GOODS_IMG_DX5
		WHERE GOODS_CD = #{goodsCd}
		AND COLOR_CD = #{colorCd}
		AND DISP_ORD = #{dispOrd}
	</delete>

	<!-- 상품이미지 등록 -->
	<insert id="createGoodsImage" parameterType="GoodsImg">
		/* TsaGoods.createGoodsImage */
		INSERT INTO TB_GOODS_IMG_DX5 (
		       GOODS_CD
		     , COLOR_CD
		     , DISP_ORD
		     , ORG_IMG_NM
		     , SYS_IMG_NM
		     , DEFAULT_IMG_YN
		     , REG_NO
		     , REG_DT
		)
		VALUES (
		       #{goodsCd}
		     , #{colorCd}
		     , #{dispOrd}
		     , #{orgImgNm}
		     , #{sysImgNm}
		     , #{defaultImgYn}
		     , #{regNo}
		     , NOW()
		)
	</insert>
	
</mapper>