<?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.fjhx.sale.mapper.intermediate.IntermediateContractMapper">
    <select id="getPage" resultType="com.fjhx.sale.entity.intermediate.vo.IntermediateContractVo">
        SELECT
            d.id,
            c.CODE,
            c.amount,
            c.currency,
            c.sell_corporation_id,
            c.buy_corporation_id
        FROM
            documents d
        LEFT JOIN contract c ON d.contract_id = c.id
            ${ew.customSqlSegment}
    </select>
    <select id="getPage2" resultType="com.fjhx.sale.entity.intermediate.vo.IntermediateContractVo">
        SELECT
            t1.*,
            MAX( d.create_time ) ,
            d.id AS documentsId,
            c.`code`AS `code`,
            c.amount AS amount
        FROM
            intermediate_contract t1
                JOIN documents d ON FIND_IN_SET( d.id, t1.documents_ids )
                LEFT JOIN contract c ON d.contract_id = c.id
        ${ew.customSqlSegment}
    </select>

    <select id="contactList" resultType="com.fjhx.sale.entity.intermediate.vo.IntermediateContractVo">
        SELECT ic.sell_contact_name,
               ic.sell_contact_number,
               ic.buy_contact_name,
               ic.buy_contact_number
        FROM intermediate_contract ic
            ${ew.customSqlSegment}
    </select>

    <select id="getAllIds" resultType="java.lang.String">
        select GROUP_CONCAT(documents_ids)AS ids FROM intermediate_contract
    </select>
</mapper>
