<?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.tenant.repository.finance.ReconciliationRepository">

    <!-- 对账记录分页 -->
    <select id="findPage" resultType="com.erp.tenant.entity.finance.Reconciliation">
        SELECT r.* FROM reconciliations r
        WHERE r.tenant_id = #{tenantId} AND r.deleted_at IS NULL
        <if test="status != null">
            AND r.status = #{status}
        </if>
        <if test="keyword != null and keyword != ''">
            AND r.counterparty_name LIKE CONCAT('%', #{keyword}, '%')
        </if>
        ORDER BY r.created_at DESC
    </select>

</mapper>
