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

	<!-- 공급업체 목록 -->
	<select id="getSupplyCompanyList" parameterType="SupplyCompany" resultType="SupplyCompany">
		/* TsaBusiness.getSupplyCompanyList */
		SELECT SUPPLY_COMP_CD   /*공급업체코드*/
		     , SUPPLY_COMP_NM   /*공급업체명*/
		     , BIZ_GB           /*사업자구분*/
		     , BIZ_NO           /*사업자등록번호*/
		     , BIZ_KIND         /*업종*/
		     , BIZ_TYPE         /*업태*/
		     , OWNER_NM         /*대표자명*/
		     , BIZ_ZIPCODE      /*사업장우편번호*/
		     , BIZ_BASE_ADDR    /*사업장기본주소*/
		     , BIZ_DTL_ADDR     /*사업장상세주소*/
		     , MAIN_TELNO       /*대표전화번호*/
		     , MAIN_FAXNO       /*대표팩스번호*/
		     , HOMEPAGE_URL     /*홈페이지URL*/
		     , DISTRIBUTION_GB  /*유통구분*/
		     , SUPPLY_STAT      /*입점상태*/
		     , MIN_ORD_AMT      /*무료배송비최소주문금액*/
		     , DELV_FEE         /*배송비*/
		     , SELL_FEE_RATE    /*판매수수료율*/
		     , SETTLE_DAY       /*정산일*/
		     , BANK_CD          /*은행코드*/
		     , ACCOUNT_NO       /*계좌번호*/
		     , DEPOSITOR_NM     /*예금주명*/
		     , REMARKS          /*비고*/
		     , USE_YN           /*사용여부*/
		FROM   TB_SUPPLY_COMPANY
		WHERE  1 = 1
		<if test="supplyStat != null and supplyStat != ''">
		AND    SUPPLY_STAT = #{supplyStat}
		</if>
		<if test="searchTxt != null and searchTxt != ''">
			<if test='searchGb == "NAME"'>
			AND    UPPER(SUPPLY_COMP_NM) LIKE CONCAT('%',UPPER(#{searchTxt}),'%')
			</if>
			<if test='searchGb == "OWNER"'>
			AND    UPPER(OWNER_NM) LIKE CONCAT('%',UPPER(#{searchTxt}),'%')
			</if>
		</if>
	</select>
	
	<!-- 공급업체 저장 -->
	<insert id="saveSupplyCompany" parameterType="SupplyCompany">
		/* TsaBusiness.saveSupplyCompany */
		INSERT INTO TB_SUPPLY_COMPANY (
		       SUPPLY_COMP_CD
		     , SUPPLY_COMP_NM
		     , BIZ_GB
		     , BIZ_NO
		     , BIZ_KIND
		     , BIZ_TYPE
		     , OWNER_NM
		     , BIZ_ZIPCODE
		     , BIZ_BASE_ADDR
		     , BIZ_DTL_ADDR
		     , MAIN_TELNO
		     , MAIN_FAXNO
		     , HOMEPAGE_URL
		     , DISTRIBUTION_GB
		     , SUPPLY_STAT
		     , MIN_ORD_AMT
		     , DELV_FEE
		     , SELL_FEE_RATE
		     , SETTLE_DAY
		     , BANK_CD
		     , ACCOUNT_NO
		     , DEPOSITOR_NM
		     , REMARKS
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       (SELECT 'S'||LPAD(SUBSTRING(MAX(SUPPLY_COMP_CD),2) + 1,4,'0')
		        FROM   TB_SUPPLY_COMPANY
		        WHERE  SUPPLY_COMP_CD LIKE 'S%'
		       )
		     , #{supplyCompNm}
		     , #{bizGb}
		     , #{bizNo}
		     , #{bizKind}
		     , #{bizType}
		     , #{ownerNm}
		     , #{bizZipcode}
		     , #{bizBaseAddr}
		     , #{bizDtlAddr}
		     , #{mainTelno}
		     , #{mainFaxno}
		     , #{homepageUrl}
		     , #{distributionGb}
		     , #{supplyStat}
		     , IFNULL(#{minOrdAmt},0)
		     , IFNULL(#{delvFee},0)
		     , IFNULL(#{sellFeeRate},0.0)
		     , #{settleDay}
		     , #{bankCd}
		     , #{accountNo}
		     , #{depositorNm}
		     , #{remarks}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       SUPPLY_COMP_NM  = #{supplyCompNm}
		     , BIZ_GB          = #{bizGb}
		     , BIZ_NO          = #{bizNo}
		     , BIZ_KIND        = #{bizKind}
		     , BIZ_TYPE        = #{bizType}
		     , OWNER_NM        = #{ownerNm}
		     , BIZ_ZIPCODE     = #{bizZipcode}
		     , BIZ_BASE_ADDR   = #{bizBaseAddr}
		     , BIZ_DTL_ADDR    = #{bizDtlAddr}
		     , MAIN_TELNO      = #{mainTelno}
		     , MAIN_FAXNO      = #{mainFaxno}
		     , HOMEPAGE_URL    = #{homepageUrl}
		     , DISTRIBUTION_GB = #{distributionGb}
		     , SUPPLY_STAT     = #{supplyStat}
		     , MIN_ORD_AMT     = IFNULL(#{minOrdAmt},0)
		     , DELV_FEE        = IFNULL(#{delvFee},0)
		     , SELL_FEE_RATE   = IFNULL(#{sellFeeRate},0.0)
		     , SETTLE_DAY      = #{settleDay}
		     , BANK_CD         = #{bankCd}
		     , ACCOUNT_NO      = #{accountNo}
		     , DEPOSITOR_NM    = #{depositorNm}
		     , REMARKS         = #{remarks}
		     , USE_YN          = #{useYn}
		     , UPD_NO          = #{updNo}
		     , UPD_DT          = NOW()
	</insert>

</mapper>