<?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.sunxung.factoring.mapper.salescontractmanagement.CSalesContractBasicInfoMapper">
	<resultMap type="CSalesContractBasicInfo" id="baseResultMap">
		<result property="id" column="id" />
		<result property="contractNumber" column="contract_number" />
<!--		<result property="contractPeriod" column="contract_period" />-->
<!--		<result property="contractPlanAmount" column="contract_plan_amount" />-->
<!--		<result property="checkOperator" column="check_operator" />-->
<!--		<result property="settlementOperator" column="settlement_operator" />-->
		<result property="contractName" column="contract_name" />
		<result property="userCreate" column="user_create" />
		<result property="userModified" column="user_modified" />
		<result property="gmtCreate" column="gmt_create" />
		<result property="gmtModified" column="gmt_modified" />
		<result property="cSalesContractManagementId" column="sales_contract_management_id" />
<!--		<association property="contractPlanAmountTypeDict" column="contract_plan_amount_type" resultMap="dictionaryResult" />-->
	</resultMap>

<!--	<resultMap id="dictionaryResult" type="Dictionary">-->
<!--		<result property="id" column="did" />-->
<!--		<result property="name" column="dname" />-->
<!--		<result property="code" column="dcode" />-->
<!--	</resultMap>-->
	<select id="get" parameterType="java.lang.Long" resultMap="baseResultMap">
		SELECT
			t1.id,
			t1.contract_number,
			t1.contract_period,
			t1.contract_plan_amount_type,
			t1.contract_plan_amount,
			t1.check_operator,
			t1.settlement_operator,
		    t1.sales_contract_management_id,
			t1.gmt_create,
			t1.contract_name,
			t2.id did,
			t2.code dcode,
			t2.name dname
		FROM
			sales_contract_basic_info t1
				LEFT JOIN t_dictionary t2 ON t1.contract_plan_amount_type = t2.id
		WHERE t1.id = #{id}
	</select>
	<select id="getSalesContractBasicByPurchContractNumber" parameterType="java.lang.String" resultMap="baseResultMap">
		select t1.*
		from
			sales_contract_basic_info t1
				left join sales_contract_management t2 on t1.sales_contract_management_id = t2.id
				left join purch_contract_management t3 on t3.business_number = t2.business_number
				left join purch_contract_basic_info t4 on t4.purch_contract_management_id = t3.id
		where t4.contract_number = #{purchContractNumber}
		ORDER BY t1.gmt_create DESC
		limit 1
	</select>

</mapper>
