<?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.inkasso.factoring.purchManagement.dao.CPurchContractBasicInfoMapper">

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, contract_number, contract_name, supplier_name, buyer_name, contract_period, repurch_method, contract_plan_amount_type, contract_plan_amount, purch_contract_management_id, user_create, user_modified, gmt_create, gmt_modified, contract_id
    </sql>
    <select id="getLatestBasicInfo"
            resultType="com.inkasso.factoring.purchManagement.entity.CPurchContractBasicInfo">
        select
        t1.id,
        t1.contract_number,
        t1.contract_name,
        t1.repurch_method,
        t1.contract_plan_amount_type,
        t1.contract_plan_amount,
        t1.c_purch_contract_management_id,
        t1.user_create,
        t1.user_modified,
        t1.gmt_create,
        t1.gmt_modified,
        t2.id did,
        t2.code dcode,
        t2.name dname,
        t3.id dtid,
        t3.code dtcode,
        t3.name dtname
        FROM
        c_purch_contract_basic_info t1
        LEFT JOIN t_dictionary t2 ON t1.contract_plan_amount_type = t2.id
        LEFT JOIN t_dictionary t3 ON t1.repurch_method = t3.id
        <if test="conclusion == null">
            WHERE t1.c_purch_contract_management_id = #{purchContractManageId}
        </if>
        <if test="conclusion != null">
            LEFT JOIN purch_contract_sign_approval t4 ON t1.id = t4.c_purch_contract_basic_info_id
            WHERE t1.c_purch_contract_management_id = #{purchContractManageId} AND t4.approval_conclusion = 'pass'
        </if>
        GROUP BY t1.gmt_create DESC LIMIT 1
    </select>

</mapper>
