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

	<!-- 공급업체 목록 -->
	<select id="getSupplyCompanyList" parameterType="SupplyCompany" resultType="CommonCode">
		/* TsaRenderer.getSupplyCompanyList */
		SELECT SUPPLY_COMP_CD  AS CD
		     , SUPPLY_COMP_NM  AS CD_NM
		FROM   TB_SUPPLY_COMPANY
		WHERE  USE_YN = 'Y'
		<if test='supplyCompCd != null and supplyCompCd != ""'>
		AND    SUPPLY_COMP_CD = #{supplyCompCd}
		</if>
		<if test='selfYn == "Y"'>
		AND    DISTRIBUTION_GB IN ('G065_10','G065_11','G065_12')
		</if>
		<if test='selfYn == "N"'>
		AND    DISTRIBUTION_GB = 'G065_20'
		</if>
		ORDER  BY SUPPLY_COMP_NM
	</select>
	
	<!-- 공통코드 목록 -->
	<select id="getCommonCodeList" parameterType="CommonCode" resultType="CommonCode">
		/* TsaRenderer.getCommonCodeList */
		SELECT CD
		     , CD_NM
		FROM   TB_COMMON_CODE
		WHERE  1 = 1
		<if test="useYn != null and useYn != ''">
		AND    USE_YN = #{useYn}
		</if>
		AND    CD_GB = #{cdGb}
		<if test="cd != null and cd != ''">
		AND    CD = #{cd}
		</if>
		<if test="cdNm != null and cdNm != ''">
		AND    CD_NM = #{cdNm}
		</if>
		<if test="cdDesc != null and cdDesc != ''">
		AND    CD_DESC = #{cdDesc}
		</if>
		<if test="exceptCds != null and exceptCds != ''">
		AND    CD NOT IN
		    <foreach collection="exceptCds" item="item" index="index"  open="(" close=")" separator=",">
		    #{item}
		    </foreach>
		</if>
		ORDER  BY CD_GB, DISP_ORD
	</select>
	
	<!-- 최상위메뉴 목록 -->
	<select id="getTopMenuList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getTopMenuList */
		WITH RECURSIVE CONNECTBY AS (
		    SELECT 1                                    AS LVL
		         , MENU_ID
		         , MENU_NM
		         , CONCAT(MENU_ID,LPAD(DISP_ORD,4,'0')) AS ORDBY
		    FROM   TB_MENU
		    WHERE  USE_YN = 'Y'
		    <choose>
		        <when test="pmenuId != null and pmenuId != ''">
		    AND    PMENU_ID = #{pmenuId}
		        </when>
		        <otherwise>
		    AND    PMENU_ID = 'ROOT'
		        </otherwise>
		    </choose>
		    
		    UNION ALL
		    
		    SELECT A.LVL + 1                              AS LVL
		         , B.MENU_ID
		         , B.MENU_NM
		         , CONCAT(A.ORDBY,LPAD(B.DISP_ORD,4,'0')) AS ORDBY
		    FROM   CONNECTBY A
		    INNER JOIN TB_MENU B ON A.MENU_ID = B.PMENU_ID
		    WHERE  B.USE_YN = 'Y'
		)
		SELECT MENU_ID AS CD
		     , MENU_NM AS CD_NM
		FROM   CONNECTBY
		WHERE  LVL = 1
		ORDER  BY ORDBY
	</select>

	<!-- 전체메뉴 목록 -->
	<select id="getAllMenuList" resultType="CommonCode">
		/* TsaRenderer.getAllMenuList */
		WITH RECURSIVE CONNECTBY AS (
		    SELECT 1                                    AS LVL
		         , MENU_ID
		         , MENU_NM
		         , MENU_GB
		         , CONCAT(MENU_ID,LPAD(DISP_ORD,4,'0')) AS ORDBY
		    FROM   TB_MENU
		    WHERE  USE_YN = 'Y'
		    AND    PMENU_ID = 'ROOT'
		    
		    UNION ALL
		    
		    SELECT A.LVL + 1                              AS LVL
		         , B.MENU_ID
		         , B.MENU_NM
		         , B.MENU_GB
		         , CONCAT(A.ORDBY,LPAD(B.DISP_ORD,4,'0')) AS ORDBY
		    FROM   CONNECTBY A
		           INNER JOIN TB_MENU B ON A.MENU_ID = B.PMENU_ID
		    WHERE  B.USE_YN = 'Y'
		)
		SELECT MENU_ID                                                 AS CD
		     , CONCAT(REPEAT('--',(LVL - 1)),'[',MENU_ID,'] ',MENU_NM) AS CD_NM
		FROM   CONNECTBY
		WHERE  MENU_GB = 'M'
		ORDER  BY ORDBY
	</select>

	<!-- 벤더별 외부몰 목록 -->
	<select id="getVendorExtmallList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getVendorExtmallList */
		SELECT DISTINCT
		       EXTMALL_ID AS CD
		     , EXTMALL_NM AS CD_NM
		FROM   TB_EXTMALL
		WHERE  VENDOR_ID = #{vendorId}
		AND    USE_YN = 'Y'
		ORDER  BY EXTMALL_ID
	</select>

	<!-- 벤더별 외부몰판매매장 목록 -->
	<select id="getVendorExtmallSellStoreList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getVendorExtmallSellStoreList */
		SELECT A.SELL_STORE_CD AS CD
		     , B.SELL_STORE_NM AS CD_NM
		FROM   TB_EXTMALL A
		     , TB_SELL_STORE B
		WHERE  A.SELL_STORE_CD = B.SELL_STORE_CD
		AND    A.VENDOR_ID = #{vendorId}
		AND    A.USE_YN = 'Y'
		AND    B.USE_YN = 'Y'
		GROUP  BY A.SELL_STORE_CD, B.SELL_STORE_NM
		ORDER  BY B.SELL_STORE_NM
	</select>

	<!-- 브랜드 목록 -->
	<select id="getBrandList" parameterType="Brand" resultType="CommonCode">
		/* TsaRenderer.getBrandList */
		SELECT BRAND_CD  AS CD
		     , BRAND_ENM AS CD_NM
		FROM   TB_BRAND
		WHERE  1 = 1
		<if test='supplyCompCd != null and supplyCompCd != ""'>
		AND    SUPPLY_COMP_CD = #{supplyCompCd}
		</if>
		<if test='brandGrpNm != null and brandGrpNm != ""'>
		AND    BRAND_GRP_NM = #{brandGrpNm}
		</if>
		<if test='useYn != null and useYn != ""'>
		AND    USE_YN = #{useYn}
		</if>
		ORDER  BY SUPPLY_COMP_CD, DISP_ORD
	</select>

	<!-- 권한별 브랜드 목록 -->
	<select id="getAuthBrandList" parameterType="int" resultType="CommonCode">
		/* TsaRenderer.getAuthBrandList */
		SELECT A.BRAND_CD  AS CD
		     , A.BRAND_ENM AS CD_NM
		FROM   TB_BRAND A
		INNER JOIN TB_BRAND_MD B ON A.BRAND_CD = B.BRAND_CD
		WHERE  A.USE_YN = 'Y'
		AND    B.MD_NO = #{userNo}
		GROUP  BY A.BRAND_CD, A.BRAND_ENM
		ORDER  BY A.BRAND_CD
	</select>

	<!-- 출고처 목록 -->
	<select id="getDeliveryLocList" parameterType="DeliveryLoc" resultType="CommonCode">
		/* TsaRenderer.getDeliveryLocList */
		SELECT DELV_LOC_CD AS CD
		     , DELV_LOC_NM AS CD_NM
		FROM   TB_DELIVERY_LOC
		WHERE  USE_YN = 'Y'
		<if test='supplyCompCd != null and supplyCompCd != ""'>
		AND    SUPPLY_COMP_CD = #{supplyCompCd}
		</if>
		<if test='delvLocClsf != null and delvLocClsf != ""'>
		AND    DELV_LOC_CLSF = #{delvLocClsf}
		</if>
		ORDER  BY DELV_LOC_NM
	</select>

	<!-- 정보고시 목록 -->
	<select id="getCateInfoList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getCateInfoList */
		SELECT NI_CLSF_CD AS CD
		     , B.CD_NM
		FROM   TB_NOTI_INFO A
		INNER JOIN TB_GOODS G ON G.SUPPLY_COMP_CD = A.SUPPLY_COMP_CD
		INNER JOIN TB_COMMON_CODE B ON A.NI_CLSF_CD = B.CD
		WHERE  G.GOODS_CD = #{goodsCd}
		AND    B.CD_GB = 'G004'
		AND    B.USE_YN = 'Y'
		GROUP  BY NI_CLSF_CD, B.CD_NM
		ORDER  BY NI_CLSF_CD
	</select>

	<!-- 품목 목록 -->
	<select id="getItemkindList" parameterType="Itemkind" resultType="CommonCode">
		/* TsaRenderer.getItemkindList */
		SELECT ITEMKIND_CD AS CD
		     , ITEMKIND_NM AS CD_NM
		FROM   TB_ITEMKIND
		WHERE  USE_YN = 'Y'
		<if test='itemkindCd != null and itemkindCd != ""'>
		AND    ITEMKIND_CD = #{itemkindCd}
		</if>
		ORDER  BY ITEMKIND_CD
	</select>

	<!-- 브랜드그룹 목록 -->
	<select id="getBrandGroupList" resultType="CommonCode">
		/* TsaRenderer.getBrandGroupList */
		SELECT BRAND_GRP_NM AS CD
		     , BRAND_GRP_NM AS CD_NM
		FROM   TB_BRAND
		WHERE  USE_YN = 'Y'
		AND    BRAND_GRP_NM IS NOT NULL
		GROUP  BY BRAND_GRP_NM
		ORDER  BY BRAND_GRP_NM
	</select>

	<!-- 컬러 목록 -->
	<select id="getColorList" parameterType="Color" resultType="CommonCode">
		/* TsaRenderer.getColorList */
		SELECT COLOR_CD  AS CD
		     , COLOR_ENM AS CD_NM
		     , COLOR_KNM AS CD_DESC
		     , USE_YN
		FROM   TB_COLOR
		WHERE  USE_YN = 'Y'
		<if test='colorCd != null and colorCd != ""'>
		AND    COLOR_CD = #{colorCd}
		</if>
		ORDER  BY COLOR_CD
	</select>

	<!-- 사용중 대카테고리 목록 -->
	<select id="getTCategoryList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getTCategoryList */
		SELECT TCATE_CD AS CD
		     , TCATE_NM AS CD_NM
		FROM   TB_CATEGORY_4SRCH
		WHERE  1 = 1
		<if test='cateGb != null and cateGb != ""'>
		AND    CATE_GB = #{cateGb}
		</if>
		GROUP  BY TCATE_CD, TCATE_NM
		ORDER  BY TCATE_CD
	</select>

	<!-- 브랜드에 등록된 MD 목록 -->
	<select id="getBrandMdList" resultType="CommonCode">
		/* TsaRenderer.getBrandMdList */
		SELECT DISTINCT
		       A.MD_NO   AS CD
		     , C.USER_NM AS CD_NM
		FROM   TB_BRAND_MD A
		INNER JOIN TB_BRAND B ON A.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_USER C ON A.MD_NO = C.USER_NO
		ORDER  BY C.USER_NM
	</select>

	<!-- 택배사명 목록 조회 -->
	<select id="getShipCompanyList" resultType="CommonCode">
		/* TsaDelivery.getShipCompanyList */
		SELECT SHIP_COMP_CD  AS CD
		     , SHIP_COMP_NM  AS CD_NM
		FROM   TB_SHIP_COMPANY
		WHERE  1 = 1
		<if test='useYn != null and useYn != ""'>
		AND    USE_YN = #{useYn}
		</if>
	</select>

	<!-- MD별 브랜드 목록 조회 -->
	<select id="getMdBrandList" resultType="CommonCode">
		/* TsaRenderer.getMdBrandList*/
		SELECT DISTINCT
		       A.BRAND_CD AS CD
		     , B.BRAND_ENM AS CD_NM
		FROM   TB_BRAND_MD A
		     , TB_BRAND B
		WHERE  A.BRAND_CD = B.BRAND_CD
		<if test='mdNo != null and mdNo != "" and mdNo != "all"'>
		AND    A.MD_NO = #{mdNo}
		</if>
	</select>

	<!-- MD별 브랜드그룹조회 -->
	<select id="getMdBrandGrpList" resultType="CommonCode">
		/* TsaRenderer.getMdBrandGrpList*/
		SELECT DISTINCT
		       B.BRAND_GRP_NM AS CD
		     , B.BRAND_GRP_NM AS CD_NM
		FROM   TB_BRAND_MD A
		      ,TB_BRAND B
		WHERE  A.BRAND_CD = B.BRAND_CD
		<if test='mdNo != null and mdNo != "" and mdNo != "all"'>
		AND    A.MD_NO = #{mdNo}
		</if>
		GROUP  BY BRAND_GRP_NM
	</select>

	<select id="getInstaAccount" resultType="CommonCode">
		/* TsaRenderer.getInstaAccount*/
		SELECT DISTINCT
		       IT.INSTA_ACCOUNT AS CD
		     , IT.INSTA_ACCOUNT AS CD_NM
		FROM   TB_INSTAGRAM_TOKEN IT
	</select>

	<!-- 판매몰조회 -->
	<select id="getSellStoreList" resultType="CommonCode">
		/* TsaRenderer.getSellStoreList*/
		SELECT DISTINCT
		       SELL_STORE_CD AS CD
		     , SELL_STORE_NM AS CD_NM
		FROM   TB_SELL_STORE
	</select>

	<!-- 1:1문의용 답변문구 목록 -->
	<select id="getAnswerPhaseList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getAnswerPhaseList */
		SELECT ANS_SQ     AS CD
		     , ANS_TITLE  AS CD_NM
		FROM   TB_ANS_PHASE
		WHERE  ANS_CLSF = #{ansClsf}
		AND    USE_YN = 'Y'
	</select>

	<!-- 제휴링크 목록 -->
	<select id="getAflinkList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getAflinkList */
		SELECT AF_LINK_CD AS CD
		     , AF_LINK_NM AS CD_NM
		FROM   TB_AF_LINK
		WHERE  AF_CHANNEL = #{afChannel}
		AND    USE_YN = 'Y'
	</select>
	
	<!-- 색상그룹코드 RGB 목록 -->
	<select id="getColorGrpCdRgbList" resultType="CommonCode">
		/* TsaRenderer.getColorGrpCdRgbList */
		SELECT CD
			 , CD_DESC AS CD_NM
		FROM TB_COMMON_CODE
		WHERE 1=1
		AND CD_GB = 'G072'
		AND USE_YN = 'Y'
	</select>
	
	<!-- 업체별 배송비정책 목록 -->
	<select id="getSupplyDeliveryFeePolicyList" parameterType="String" resultType="CommonCode">
		/* TsaRenderer.getSupplyDeliveryFeePolicyList */
		SELECT DELV_FEE_CD AS CD
			 , CONCAT(MIN_ORD_AMT,'/',DELV_FEE) AS CD_NM
		FROM TB_DELV_FEE_POLICY
		WHERE 1=1
		AND SUPPLY_COMP_CD = #{supplyCompCd}
		AND USE_YN = 'Y'
		ORDER BY DELV_FEE_CD
	</select>

</mapper>