<?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.purchcontractmanagement.PurchContractPriceRuleMapper">
	<resultMap type="PurchContractPriceRule" id="baseResultMap">
		<result property="id" column="id" />
		<result property="tradePlatformOffer" column="trade_platform_offer" />
		<result property="factoringOffer" column="factoring_offer" />
		<result property="factoringFinanceDeadline" column="factoring_finance_deadline" />
		<result property="differAmount" column="differ_amount" />
		<result property="purchContractBasicInfoId" column="purch_contract_basic_info_id" />
		<result property="userCreate" column="user_create" />
		<result property="userModified" column="user_modified" />
		<result property="gmtCreate" column="gmt_create" />
		<result property="monthlyInterestRate" column="monthly_interest_rate" />
		<result property="gmtModified" column="gmt_modified" />
		<association property="accrualMarginCalcMethodDict" column="accrual_margin_calc_method" 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="findByPurchContId" parameterType="java.lang.Long" resultMap="baseResultMap">
		SELECT
			t1.id,
			t1.accrual_margin_calc_method,
			t1.trade_platform_offer,
			t1.factoring_offer,
			t1.factoring_finance_deadline,
			t1.differ_amount,
		    t1.monthly_interest_rate,
			t1.purch_contract_basic_info_id,
			t1.user_create,
			t1.user_modified,
			t1.gmt_create,
			t1.gmt_modified,
			t2.id did,
			t2.code dcode,
			t2.name dname
		FROM
			purch_contract_price_rule t1
				LEFT JOIN t_dictionary t2 ON t1.accrual_margin_calc_method = t2.id
		WHERE t1.purch_contract_basic_info_id = #{purchContId}
	</select>

</mapper>
