<?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.ruoyi.bussiness.mapper.TExchangeCoinRecordMapper">
    
    <resultMap type="com.ruoyi.bussiness.domain.TExchangeCoinRecord" id="TExchangeCoinRecordResult">
        <result property="id"    column="id"    />
        <result property="fromCoin"    column="from_coin"    />
        <result property="toCoin"    column="to_coin"    />
        <result property="userId"    column="user_id"    />
        <result property="username"    column="username"    />
        <result property="address"    column="address"    />
        <result property="status"    column="status"    />
        <result property="amount"    column="amount"    />
        <result property="thirdRate"    column="third_rate"    />
        <result property="systemRate"    column="system_rate"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="searchValue"    column="search_value"    />
    </resultMap>

    <sql id="selectTExchangeCoinRecordVo">
        select id, from_coin, to_coin, user_id, username, address, status, amount, third_rate, system_rate, create_by, create_time, update_by, update_time, remark, search_value from t_exchange_coin_record
    </sql>

    <select id="selectTExchangeCoinRecordList" parameterType="TExchangeCoinRecord" resultMap="TExchangeCoinRecordResult">
        <include refid="selectTExchangeCoinRecordVo"/>
        <where>  
            <if test="fromCoin != null  and fromCoin != ''"> and from_coin = #{fromCoin}</if>
            <if test="toCoin != null  and toCoin != ''"> and to_coin = #{toCoin}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="thirdRate != null "> and third_rate = #{thirdRate}</if>
            <if test="systemRate != null "> and system_rate = #{systemRate}</if>
            <if test="searchValue != null  and searchValue != ''"> and search_value = #{searchValue}</if>
            <if test="adminParentIds != null and adminParentIds!=''">
                AND find_in_set(#{adminParentIds},admin_parent_ids)
            </if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTExchangeCoinRecordById" parameterType="Long" resultMap="TExchangeCoinRecordResult">
        <include refid="selectTExchangeCoinRecordVo"/>
        where id = #{id}
    </select>
    <select id="getListByLimit" resultType="com.ruoyi.bussiness.domain.TExchangeCoinRecord"
            parameterType="int">
        SELECT
            *
        FROM
            t_exchange_coin_record
        WHERE
            status = 0
        ORDER BY create_time limit #{size}
    </select>

    <select id="countByExchangeCoinRecord" resultType="java.lang.Integer"
            parameterType="com.ruoyi.bussiness.domain.TExchangeCoinRecord">
        SELECT
        COUNT(1)
        FROM
        t_exchange_coin_record
        <where>
            <if test="userId != null">
                AND user_id = #{userId}
            </if>
            <if test="address != null and address !=''">
                AND address = #{address}
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
            <if test="fromCoin != null and fromCoin != ''">
                AND from_coin = #{fromCoin}
            </if>
            <if test="toCoin != null and toCoin != ''">
                AND to_coin = #{toCoin}
            </if>
        </where>
    </select>

    <insert id="insertTExchangeCoinRecord" parameterType="TExchangeCoinRecord" useGeneratedKeys="true" keyProperty="id">
        insert into t_exchange_coin_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fromCoin != null and fromCoin != ''">from_coin,</if>
            <if test="toCoin != null and toCoin != ''">to_coin,</if>
            <if test="userId != null">user_id,</if>
            <if test="username != null">username,</if>
            <if test="address != null">address,</if>
            <if test="status != null">status,</if>
            <if test="amount != null">amount,</if>
            <if test="thirdRate != null">third_rate,</if>
            <if test="systemRate != null">system_rate,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="searchValue != null">search_value,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fromCoin != null and fromCoin != ''">#{fromCoin},</if>
            <if test="toCoin != null and toCoin != ''">#{toCoin},</if>
            <if test="userId != null">#{userId},</if>
            <if test="username != null">#{username},</if>
            <if test="address != null">#{address},</if>
            <if test="status != null">#{status},</if>
            <if test="amount != null">#{amount},</if>
            <if test="thirdRate != null">#{thirdRate},</if>
            <if test="systemRate != null">#{systemRate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="searchValue != null">#{searchValue},</if>
         </trim>
    </insert>

    <update id="updateTExchangeCoinRecord" parameterType="TExchangeCoinRecord">
        update t_exchange_coin_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="fromCoin != null and fromCoin != ''">from_coin = #{fromCoin},</if>
            <if test="toCoin != null and toCoin != ''">to_coin = #{toCoin},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="username != null">username = #{username},</if>
            <if test="address != null">address = #{address},</if>
            <if test="status != null">status = #{status},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="thirdRate != null">third_rate = #{thirdRate},</if>
            <if test="systemRate != null">system_rate = #{systemRate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="searchValue != null">search_value = #{searchValue},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTExchangeCoinRecordById" parameterType="Long">
        delete from t_exchange_coin_record where id = #{id}
    </delete>

    <delete id="deleteTExchangeCoinRecordByIds" parameterType="String">
        delete from t_exchange_coin_record where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>