<?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.erp.finance.repository.PaymentRecordRepository">

    <resultMap id="BaseResultMap" type="com.erp.finance.entity.PaymentRecord">
        <id column="id" property="id"/>
        <result column="payment_no" property="paymentNo"/>
        <result column="ap_no" property="apNo"/>
        <result column="ap_id" property="apId"/>
        <result column="purchase_order_no" property="purchaseOrderNo"/>
        <result column="supplier_id" property="supplierId"/>
        <result column="supplier_name" property="supplierName"/>
        <result column="amount" property="amount"/>
        <result column="payment_method" property="paymentMethod"/>
        <result column="from_account" property="fromAccount"/>
        <result column="to_account" property="toAccount"/>
        <result column="payment_time" property="paymentTime"/>
        <result column="bank_flow_no" property="bankFlowNo"/>
        <result column="status" property="status"/>
        <result column="purpose" property="purpose"/>
        <result column="related_id" property="relatedId"/>
        <result column="related_type" property="relatedType"/>
        <result column="operator" property="operator"/>
        <result column="remark" property="remark"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="deleted" property="deleted"/>
    </resultMap>

    <select id="selectPageList" resultMap="BaseResultMap">
        SELECT * FROM fin_payment_record
        WHERE deleted = 0
        <if test="apNo != null and apNo != ''">
            AND ap_no = #{apNo}
        </if>
        <if test="purchaseOrderNo != null and purchaseOrderNo != ''">
            AND purchase_order_no = #{purchaseOrderNo}
        </if>
        <if test="supplierId != null">
            AND supplier_id = #{supplierId}
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="purpose != null and purpose != ''">
            AND purpose = #{purpose}
        </if>
        <if test="startDate != null">
            AND payment_time &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            AND payment_time &lt;= #{endDate}
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="findByPaymentNo" resultMap="BaseResultMap">
        SELECT * FROM fin_payment_record WHERE payment_no = #{paymentNo} AND deleted = 0 LIMIT 1
    </select>

    <select id="findByApId" resultMap="BaseResultMap">
        SELECT * FROM fin_payment_record WHERE ap_id = #{apId} AND deleted = 0 LIMIT 1
    </select>

</mapper>
