<?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.TOwnCoinOrderMapper">
    
    <resultMap type="TOwnCoinOrder" id="TOwnCoinOrderResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="userId"    column="user_id"    />
        <result property="ownId"    column="own_id"    />
        <result property="ownCoin"    column="own_coin"    />
        <result property="amount"    column="amount"    />
        <result property="number"    column="number"    />
        <result property="price"    column="price"    />
        <result property="status"    column="status"    />
        <result property="adminUserIds"    column="admin_user_ids"    />
        <result property="adminParentIds"    column="admin_parent_ids"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTOwnCoinOrderVo">
        select id,user_id, order_id, own_id, own_coin, amount, number, price, status, admin_user_ids, admin_parent_ids, create_time, update_time from t_own_coin_order
    </sql>

    <select id="selectTOwnCoinOrderList" parameterType="TOwnCoinOrder" resultMap="TOwnCoinOrderResult">
        <include refid="selectTOwnCoinOrderVo"/>
        <where>  
            <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="ownId != null "> and own_id = #{ownId}</if>
            <if test="ownCoin != null  and ownCoin != ''"> and own_coin = #{ownCoin}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="number != null "> and number = #{number}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="adminUserIds != null  and adminUserIds != ''"> and admin_user_ids = #{adminUserIds}</if>
            <if test="adminParentIds != null  and adminParentIds != ''"> and admin_parent_ids = #{adminParentIds}</if>
        </where>
    </select>
    
    <select id="selectTOwnCoinOrderById" parameterType="Long" resultMap="TOwnCoinOrderResult">
        <include refid="selectTOwnCoinOrderVo"/>
        where id = #{id}
    </select>
    <select id="getAllAmountByUserIdAndCoinId" resultType="java.lang.Integer">
        SELECT IFNULL(sum(number),0) FROM t_own_coin_order WHERE own_id=#{ownId} and user_id=#{userId}
    </select>

    <insert id="insertTOwnCoinOrder" parameterType="TOwnCoinOrder" useGeneratedKeys="true" keyProperty="id">
        insert into t_own_coin_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="ownId != null">own_id,</if>
            <if test="ownCoin != null">own_coin,</if>
            <if test="amount != null">amount,</if>
            <if test="number != null">number,</if>
            <if test="price != null">price,</if>
            <if test="status != null">status,</if>
            <if test="adminUserIds != null">admin_user_ids,</if>
            <if test="adminParentIds != null">admin_parent_ids,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="ownId != null">#{ownId},</if>
            <if test="ownCoin != null">#{ownCoin},</if>
            <if test="amount != null">#{amount},</if>
            <if test="number != null">#{number},</if>
            <if test="price != null">#{price},</if>
            <if test="status != null">#{status},</if>
            <if test="adminUserIds != null">#{adminUserIds},</if>
            <if test="adminParentIds != null">#{adminParentIds},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTOwnCoinOrder" parameterType="TOwnCoinOrder">
        update t_own_coin_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="ownId != null">own_id = #{ownId},</if>
            <if test="ownCoin != null">own_coin = #{ownCoin},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="number != null">number = #{number},</if>
            <if test="price != null">price = #{price},</if>
            <if test="status != null">status = #{status},</if>
            <if test="adminUserIds != null">admin_user_ids = #{adminUserIds},</if>
            <if test="adminParentIds != null">admin_parent_ids = #{adminParentIds},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTOwnCoinOrderById" parameterType="Long">
        delete from t_own_coin_order where id = #{id}
    </delete>

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