<?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.purchase.mapper.purchase.PurchasePayRecordDetailMapper">
    <sql id="pageOrList">
        SELECT
            *
        FROM
            (
                SELECT
                    pprd.id,
                    pprd.purchase_id,
                    pprd.amount,
                    pprd.pay_date,
                    pprd.create_user,
                    pprd.create_time,
                    pprd.update_user,
                    pprd.update_time,
                    ppr.pay_account,
                    pprd.remark,
                    ppr.id purchasePayRecordId,
                    1 AS type
                FROM
                    purchase_pay_record_detail pprd
                        LEFT JOIN purchase_pay_record ppr ON pprd.purchase_pay_record_id = ppr.id UNION ALL
                SELECT
                    prr.id,
                    prr.purchase_id,
                    prr.amount,
                    prr.refund_date AS payDate,
                    prr.create_user,
                    prr.create_time,
                    prr.update_user,
                    prr.update_time,
                    prr.refund_account AS payAccount,
                    prr.remark,
                    NULL purchasePayRecordId,
                    2 AS type
                FROM
                    purchase_refund_record prr
            ) t1
            ${ew.customSqlSegment}
    </sql>
    <select id="getPage" resultType="com.fjhx.purchase.entity.purchase.vo.PurchasePayRecordDetailVo">
        <include refid="pageOrList"></include>
    </select>
    <select id="getList" resultType="com.fjhx.purchase.entity.purchase.vo.PurchasePayRecordDetailVo">
        <include refid="pageOrList"></include>
    </select>

</mapper>
