<?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.RefundRecordRepository">

    <resultMap id="BaseResultMap" type="com.erp.finance.entity.RefundRecord">
        <id column="id" property="id"/>
        <result column="refund_no" property="refundNo"/>
        <result column="order_no" property="orderNo"/>
        <result column="short_id" property="shortId"/>
        <result column="refund_amount" property="refundAmount"/>
        <result column="refund_reason" property="refundReason"/>
        <result column="refund_time" property="refundTime"/>
        <result column="income_record_id" property="incomeRecordId"/>
        <result column="original_amount" property="originalAmount"/>
        <result column="refund_method" property="refundMethod"/>
        <result column="refund_account" property="refundAccount"/>
        <result column="status" property="status"/>
        <result column="type" property="type"/>
        <result column="source_id" property="sourceId"/>
        <result column="source" property="source"/>
        <result column="operator" property="operator"/>
        <result column="complete_time" property="completeTime"/>
        <result column="fail_reason" property="failReason"/>
        <result column="external_refund_no" property="externalRefundNo"/>
        <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_refund_record
        WHERE deleted = 0
        <if test="orderNo != null and orderNo != ''">
            AND order_no = #{orderNo}
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="type != null and type != ''">
            AND type = #{type}
        </if>
        <if test="startDate != null">
            AND refund_time &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            AND refund_time &lt;= #{endDate}
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="findByRefundNo" resultMap="BaseResultMap">
        SELECT * FROM fin_refund_record WHERE refund_no = #{refundNo} AND deleted = 0 LIMIT 1
    </select>

    <select id="findBySourceId" resultMap="BaseResultMap">
        SELECT * FROM fin_refund_record WHERE source_id = #{sourceId} AND source = #{source} AND deleted = 0 LIMIT 1
    </select>

</mapper>
