<?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.account.mapper.account.AccountRequestFundsDetailMapper">

    <select id="getPage" resultType="com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo">
        select
            arfd.id,
            arfd.account_request_funds_id,
            arfd.cost_type,
            arfd.amount,
            arfd.remarks,
            arfd.create_user,
            arfd.create_time,
            arfd.update_user,
            arfd.update_time
        from account_request_funds_detail arfd
            ${ew.customSqlSegment}
    </select>

    <select id="getListByContractId" resultType="com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo">
        SELECT
            t2.currency,
            t2.rate,
            t1.*
        FROM
            account_request_funds_detail t1
        LEFT JOIN account_request_funds t2 ON t1.account_request_funds_id = t2.id
        LEFT JOIN account_payment t3 ON t2.id = t3.business_id
        WHERE
            t1.contract_id = #{contractId}
          AND t3.`status` = 10
    </select>

    <select id="listByAccountRequestFundsId" resultType="com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo">
        SELECT arfd.*,
               IF(arfd.data_type = 1, c.`code`, s.`code`) contractCode
        FROM account_request_funds_detail arfd
                 LEFT JOIN contract c ON arfd.contract_id = c.id
                 LEFT JOIN sample s ON arfd.contract_id = s.id
        WHERE arfd.account_request_funds_id = #{accountRequestFundsId}
    </select>

    <select id="getList" resultType="com.fjhx.account.entity.account.po.AccountRequestFundsDetail">
        SELECT fd.*,
               sc.code contractCode
        FROM account_request_funds_detail fd
                 LEFT JOIN contract sc ON fd.contract_id = sc.id
    </select>

</mapper>
