<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="sample.TcsSiteTradeMapper">
	<!-- 하자)현장업체계약 -->
	<resultMap type="sample.dto.TcsSiteTradeVo" id="tcsSiteTradeMap">
		<id property="cmpnCd" column="CMPN_CD" /><!-- 회사 코드 -->
		<id property="siteCd" column="SITE_CD" /><!-- 현장코드 -->
		<id property="covendId" column="COVEND_ID" /><!-- 협력업체 ID -->
		<id property="contSeq" column="CONT_SEQ" /><!-- 계약순번 -->
		<id property="jobGbCd" column="JOB_GB_CD" /><!-- 협력업체유형코드[CS004] -->
		<id property="contId" column="CONT_ID" /><!-- 계약 번호 -->
		<id property="contModId" column="CONT_MOD_ID" /><!-- 변경 계약번호 -->
		<id property="modNo" column="MOD_NO" /><!-- 변경 계약차수 -->
		<id property="poDocNo" column="PO_DOC_NO" /><!-- 발주 번호 -->
		<id property="contNm" column="CONT_NM" /><!-- 계약 명 -->
		<id property="contDt" column="CONT_DT" /><!-- 계약 일자 -->
		<id property="covendNm" column="COVEND_NM" /><!-- 업체 명 -->
		<id property="covendCorpRegNo" column="COVEND_CORP_REG_NO" /><!-- 업체 사업자번호 -->
		<id property="contAmt" column="CONT_AMT" /><!-- 계약 금액 -->
		<id property="contSupplyAmt" column="CONT_SUPPLY_AMT" /><!-- 공급 금액 -->
		<id property="contTerm" column="CONT_TERM" /><!-- 계약 기간 -->
		<id property="contStartDt" column="CONT_START_DT" /><!-- 계약 시작일 -->
		<id property="contEndDt" column="CONT_END_DT" /><!-- 계약 만료일 -->
		<id property="contGb" column="CONT_GB" /><!-- 계약 구분 -->
		<id property="statusCd" column="STATUS_CD" /><!-- 계약 상태 -->
		<id property="templateCd" column="TEMPLATE_CD" /><!-- 계약서 코드 -->
		<id property="templateNm" column="TEMPLATE_NM" /><!-- 계약서 코드명 -->
		<id property="chgContYn" column="CHG_CONT_YN" /><!-- 변경 계약 여부 -->
		<id property="curGb" column="CUR_GB" /><!-- 통화 단위 -->
		<id property="adjGb" column="ADJ_GB" /><!-- 정산 구분 -->
		<id property="rmkCn" column="RMK_CN" /><!-- 비고_내용 -->
		<id property="crtSysCd" column="CRT_SYS_CD" /><!-- 생성시스템코드 -->
		<id property="wrteDt" column="WRTE_DT" /><!-- 작성 일자 -->
		<id property="wrtePr" column="WRTE_PR" /><!-- 작성 자 -->
		<id property="mdftDt" column="MDFT_DT" /><!-- 수정 일자 -->
		<id property="mdftPr" column="MDFT_PR" /><!-- 수정 자 -->
	</resultMap>

	<!-- 하자)현장업체계약 - List -->
	<select id="selectTcsSiteTradeList" parameterType="sample.dto.TcsSiteTradeVo" resultMap="tcsSiteTradeMap"><![CDATA[
	SELECT 
		A.CMPN_CD AS CMPN_CD ,
		A.SITE_CD AS SITE_CD ,
		A.COVEND_ID AS COVEND_ID ,
		A.CONT_SEQ AS CONT_SEQ ,
		A.JOB_GB_CD AS JOB_GB_CD ,
		A.CONT_ID AS CONT_ID ,
		A.CONT_MOD_ID AS CONT_MOD_ID ,
		A.MOD_NO AS MOD_NO ,
		A.PO_DOC_NO AS PO_DOC_NO ,
		A.CONT_NM AS CONT_NM ,
		A.CONT_DT AS CONT_DT ,
		A.COVEND_NM AS COVEND_NM ,
		A.COVEND_CORP_REG_NO AS COVEND_CORP_REG_NO ,
		A.CONT_AMT AS CONT_AMT ,
		A.CONT_SUPPLY_AMT AS CONT_SUPPLY_AMT ,
		A.CONT_TERM AS CONT_TERM ,
		TO_CHAR(CONT_START_DT, 'YYYY-MM-DD') AS CONT_START_DT ,
		TO_CHAR(CONT_END_DT, 'YYYY-MM-DD') AS CONT_END_DT ,
		A.CONT_GB AS CONT_GB ,
		A.STATUS_CD AS STATUS_CD ,
		A.TEMPLATE_CD AS TEMPLATE_CD ,
		A.TEMPLATE_NM AS TEMPLATE_NM ,
		A.CHG_CONT_YN AS CHG_CONT_YN ,
		A.CUR_GB AS CUR_GB ,
		A.ADJ_GB AS ADJ_GB ,
		A.RMK_CN AS RMK_CN ,
		A.CRT_SYS_CD AS CRT_SYS_CD ,
		TO_CHAR(WRTE_DT, 'YYYY-MM-DD') AS WRTE_DT ,
		A.WRTE_PR AS WRTE_PR ,
		TO_CHAR(MDFT_DT, 'YYYY-MM-DD') AS MDFT_DT ,
		A.MDFT_PR AS MDFT_PR
	FROM 
		TCS_SITE_TRADE A 
	WHERE 
		1=1
	ORDER BY 
		1
	]]></select>

	<!-- 하자)현장업체계약 - View -->
	<select id="selectTcsSiteTradeView" parameterType="sample.dto.TcsSiteTradeVo" resultMap="tcsSiteTradeMap"><![CDATA[
	SELECT 
		A.CMPN_CD AS CMPN_CD ,
		A.SITE_CD AS SITE_CD ,
		A.COVEND_ID AS COVEND_ID ,
		A.CONT_SEQ AS CONT_SEQ ,
		A.JOB_GB_CD AS JOB_GB_CD ,
		A.CONT_ID AS CONT_ID ,
		A.CONT_MOD_ID AS CONT_MOD_ID ,
		A.MOD_NO AS MOD_NO ,
		A.PO_DOC_NO AS PO_DOC_NO ,
		A.CONT_NM AS CONT_NM ,
		A.CONT_DT AS CONT_DT ,
		A.COVEND_NM AS COVEND_NM ,
		A.COVEND_CORP_REG_NO AS COVEND_CORP_REG_NO ,
		A.CONT_AMT AS CONT_AMT ,
		A.CONT_SUPPLY_AMT AS CONT_SUPPLY_AMT ,
		A.CONT_TERM AS CONT_TERM ,
		TO_CHAR(CONT_START_DT, 'YYYY-MM-DD') AS CONT_START_DT ,
		TO_CHAR(CONT_END_DT, 'YYYY-MM-DD') AS CONT_END_DT ,
		A.CONT_GB AS CONT_GB ,
		A.STATUS_CD AS STATUS_CD ,
		A.TEMPLATE_CD AS TEMPLATE_CD ,
		A.TEMPLATE_NM AS TEMPLATE_NM ,
		A.CHG_CONT_YN AS CHG_CONT_YN ,
		A.CUR_GB AS CUR_GB ,
		A.ADJ_GB AS ADJ_GB ,
		A.RMK_CN AS RMK_CN ,
		A.CRT_SYS_CD AS CRT_SYS_CD ,
		TO_CHAR(WRTE_DT, 'YYYY-MM-DD') AS WRTE_DT ,
		A.WRTE_PR AS WRTE_PR ,
		TO_CHAR(MDFT_DT, 'YYYY-MM-DD') AS MDFT_DT ,
		A.MDFT_PR AS MDFT_PR
	FROM 
		TCS_SITE_TRADE A 
	WHERE 
		CMPN_CD = #{cmpnCd} AND
		SITE_CD = #{siteCd} AND
		COVEND_ID = #{covendId} AND
		CONT_SEQ = #{contSeq}
	]]></select>

	<!-- 하자)현장업체계약 - Insert -->
	<insert id="insertTcsSiteTrade" parameterType="sample.dto.TcsSiteTradeVo"><![CDATA[
	INSERT INTO 
		TCS_SITE_TRADE
	(
		A.CMPN_CD AS CMPN_CD ,
		A.SITE_CD AS SITE_CD ,
		A.COVEND_ID AS COVEND_ID ,
		A.CONT_SEQ AS CONT_SEQ ,
		A.JOB_GB_CD AS JOB_GB_CD ,
		A.CONT_ID AS CONT_ID ,
		A.CONT_MOD_ID AS CONT_MOD_ID ,
		A.MOD_NO AS MOD_NO ,
		A.PO_DOC_NO AS PO_DOC_NO ,
		A.CONT_NM AS CONT_NM ,
		A.CONT_DT AS CONT_DT ,
		A.COVEND_NM AS COVEND_NM ,
		A.COVEND_CORP_REG_NO AS COVEND_CORP_REG_NO ,
		A.CONT_AMT AS CONT_AMT ,
		A.CONT_SUPPLY_AMT AS CONT_SUPPLY_AMT ,
		A.CONT_TERM AS CONT_TERM ,
		TO_CHAR(CONT_START_DT, 'YYYY-MM-DD') AS CONT_START_DT ,
		TO_CHAR(CONT_END_DT, 'YYYY-MM-DD') AS CONT_END_DT ,
		A.CONT_GB AS CONT_GB ,
		A.STATUS_CD AS STATUS_CD ,
		A.TEMPLATE_CD AS TEMPLATE_CD ,
		A.TEMPLATE_NM AS TEMPLATE_NM ,
		A.CHG_CONT_YN AS CHG_CONT_YN ,
		A.CUR_GB AS CUR_GB ,
		A.ADJ_GB AS ADJ_GB ,
		A.RMK_CN AS RMK_CN ,
		A.CRT_SYS_CD AS CRT_SYS_CD ,
		TO_CHAR(WRTE_DT, 'YYYY-MM-DD') AS WRTE_DT ,
		A.WRTE_PR AS WRTE_PR ,
		TO_CHAR(MDFT_DT, 'YYYY-MM-DD') AS MDFT_DT ,
		A.MDFT_PR AS MDFT_PR
	) VALUES (
		#{cmpnCd} ,
		#{siteCd} ,
		#{covendId} ,
		#{contSeq} ,
		#{jobGbCd} ,
		#{contId} ,
		#{contModId} ,
		#{modNo} ,
		#{poDocNo} ,
		#{contNm} ,
		#{contDt} ,
		#{covendNm} ,
		#{covendCorpRegNo} ,
		#{contAmt} ,
		#{contSupplyAmt} ,
		#{contTerm} ,
		SYSDATE ,
		SYSDATE ,
		#{contGb} ,
		#{statusCd} ,
		#{templateCd} ,
		#{templateNm} ,
		#{chgContYn} ,
		#{curGb} ,
		#{adjGb} ,
		#{rmkCn} ,
		#{crtSysCd} ,
		SYSDATE ,
		#{wrtePr} ,
		SYSDATE ,
		#{mdftPr}
	)
	]]></insert>

	<!-- 하자)현장업체계약 - Update -->
	<update id="updateTcsSiteTrade" parameterType="sample.dto.TcsSiteTradeVo"><![CDATA[
	UPDATE 
		TCS_SITE_TRADE
	SET
		CMPN_CD = #{cmpnCd} ,
		SITE_CD = #{siteCd} ,
		COVEND_ID = #{covendId} ,
		CONT_SEQ = #{contSeq} ,
		JOB_GB_CD = #{jobGbCd} ,
		CONT_ID = #{contId} ,
		CONT_MOD_ID = #{contModId} ,
		MOD_NO = #{modNo} ,
		PO_DOC_NO = #{poDocNo} ,
		CONT_NM = #{contNm} ,
		CONT_DT = #{contDt} ,
		COVEND_NM = #{covendNm} ,
		COVEND_CORP_REG_NO = #{covendCorpRegNo} ,
		CONT_AMT = #{contAmt} ,
		CONT_SUPPLY_AMT = #{contSupplyAmt} ,
		CONT_TERM = #{contTerm} ,
		CONT_START_DT = SYSDATE ,
		CONT_END_DT = SYSDATE ,
		CONT_GB = #{contGb} ,
		STATUS_CD = #{statusCd} ,
		TEMPLATE_CD = #{templateCd} ,
		TEMPLATE_NM = #{templateNm} ,
		CHG_CONT_YN = #{chgContYn} ,
		CUR_GB = #{curGb} ,
		ADJ_GB = #{adjGb} ,
		RMK_CN = #{rmkCn} ,
		CRT_SYS_CD = #{crtSysCd} ,
		WRTE_DT = SYSDATE ,
		WRTE_PR = #{wrtePr} ,
		MDFT_DT = SYSDATE ,
		MDFT_PR = #{mdftPr}
	WHERE
		CMPN_CD = #{cmpnCd} AND
		SITE_CD = #{siteCd} AND
		COVEND_ID = #{covendId} AND
		CONT_SEQ = #{contSeq}
	]]></update>

	<!-- 하자)현장업체계약 - Delete -->
	<delete id="deleteTcsSiteTrade" parameterType="sample.dto.TcsSiteTradeVo"><![CDATA[
	DELETE 
		TCS_SITE_TRADE
	WHERE
		CMPN_CD = #{cmpnCd} AND
		SITE_CD = #{siteCd} AND
		COVEND_ID = #{covendId} AND
		CONT_SEQ = #{contSeq}
	]]></delete>
</mapper>