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

    <resultMap id="BaseResultMap" type="com.erp.finance.entity.IncomeRecord">
        <id column="id" property="id"/>
        <result column="income_no" property="incomeNo"/>
        <result column="order_no" property="orderNo"/>
        <result column="short_id" property="shortId"/>
        <result column="platform" property="platform"/>
        <result column="shop_id" property="shopId"/>
        <result column="shop_name" property="shopName"/>
        <result column="amount" property="amount"/>
        <result column="discount_amount" property="discountAmount"/>
        <result column="actual_amount" property="actualAmount"/>
        <result column="payment_method" property="paymentMethod"/>
        <result column="payment_time" property="paymentTime"/>
        <result column="transaction_id" property="transactionId"/>
        <result column="account_no" property="accountNo"/>
        <result column="account_name" property="accountName"/>
        <result column="status" property="status"/>
        <result column="source" property="source"/>
        <result column="source_id" property="sourceId"/>
        <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_income_record
        WHERE deleted = 0
        <if test="orderNo != null and orderNo != ''">
            AND order_no = #{orderNo}
        </if>
        <if test="shortId != null and shortId != ''">
            AND short_id = #{shortId}
        </if>
        <if test="platform != null and platform != ''">
            AND platform = #{platform}
        </if>
        <if test="shopId != null">
            AND shop_id = #{shopId}
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </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="findByIncomeNo" resultMap="BaseResultMap">
        SELECT * FROM fin_income_record WHERE income_no = #{incomeNo} AND deleted = 0 LIMIT 1
    </select>

    <select id="findByOrderNo" resultMap="BaseResultMap">
        SELECT * FROM fin_income_record WHERE order_no = #{orderNo} AND deleted = 0 LIMIT 1
    </select>

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

</mapper>
