<?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.kym.mapper.WalletDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.kym.entity.WalletDetail">
        <id column="id" property="id"/>
        <result column="company_id" property="companyId" />
        <result column="user_id" property="userId"/>
        <result column="type" property="type"/>
        <result column="current" property="current"/>
        <result column="order_no" property="orderNo"/>
        <result column="amount" property="amount"/>
        <result column="commission" property="commission"/>
        <result column="transaction_id" property="transactionId"/>
        <result column="transaction_time" property="transactionTime"/>
        <result column="status" property="status"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, company_id,user_id, type, currency, order_no, amount, commission, transaction_id, transaction_time, status, remark, create_time, update_time
    </sql>

    <resultMap id="AdminWalletDetailMap" type="com.kym.entity.vo.WalletDetailVo">
        <result column="user_id" property="userId"/>
        <result column="mobile_phone" property="mobilePhone"/>
        <result column="type" property="type"/>
        <result column="currency" property="currency"/>
        <result column="order_no" property="orderNo"/>
        <result column="amount" property="amount"/>
        <result column="grants_amount" property="grantsAmount"/>
        <result column="commission" property="commission"/>
        <result column="before_balance" property="beforeBalance"/>
        <result column="after_balance" property="afterBalance"/>
        <result column="before_grants_balance" property="beforeGrantsBalance"/>
        <result column="after_grants_balance" property="afterGrantsBalance"/>
        <result column="transaction_id" property="transactionId"/>
        <result column="transaction_time" property="transactionTime"/>
        <result column="status" property="status"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
    </resultMap>

    <select id="listAdminWalletDetail" parameterType="com.kym.entity.queryParams.WalletDetailQueryParam"
            resultMap="AdminWalletDetailMap">
        SELECT
            t1.user_id,
            t2.mobile_phone,
            t1.type,
            t1.currency,
            t1.order_no,
            t1.amount,
            t1.grants_amount,
            t1.commission,
            t1.before_balance,
            t1.after_balance,
            t1.before_grants_balance,
            t1.after_grants_balance,
            t1.transaction_id,
            t1.transaction_time,
            t1.status,
            t1.remark,
            t1.create_time
        FROM t_wallet_detail t1
        LEFT JOIN t_user t2 ON t1.user_id = t2.id
        <where>
            <if test="userId != null">
                AND t1.user_id = #{userId}
            </if>
            <if test="mobilePhone != null and mobilePhone != ''">
                AND t2.mobile_phone = #{mobilePhone}
            </if>
            <if test="type != null">
                AND t1.type = #{type}
            </if>
            <if test="status != null">
                AND t1.status = #{status}
            </if>
            <if test="startDate != null">
                AND t1.transaction_time &gt;= #{startDate}
            </if>
            <if test="endDate != null">
                AND t1.transaction_time &lt;= #{endDate}
            </if>
        </where>
        ORDER BY t1.id DESC
    </select>

</mapper>
