<?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.system.mapper.UserMarginMapper">
    
    <resultMap type="UserMargin" id="UserMarginResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="type"    column="type"    />
        <result property="amount"    column="amount"    />
        <result property="cretim"    column="cretim"    />
    </resultMap>

    <sql id="selectUserMarginVo">
        select id, user_id, type, amount, cretim from user_margin
    </sql>

    <select id="selectUserMarginList" parameterType="UserMargin" resultMap="UserMarginResult">
        <include refid="selectUserMarginVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="cretim != null "> and cretim = #{cretim}</if>
        </where>
    </select>
    
    <select id="selectUserMarginById" parameterType="Long" resultMap="UserMarginResult">
        <include refid="selectUserMarginVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertUserMargin" parameterType="UserMargin" useGeneratedKeys="true" keyProperty="id">
        insert into user_margin
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="type != null">type,</if>
            <if test="amount != null">amount,</if>
            <if test="cretim != null">cretim,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="type != null">#{type},</if>
            <if test="amount != null">#{amount},</if>
            <if test="cretim != null">#{cretim},</if>
         </trim>
    </insert>

    <update id="updateUserMargin" parameterType="UserMargin">
        update user_margin
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="cretim != null">cretim = #{cretim},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserMarginById" parameterType="Long">
        delete from user_margin where id = #{id}
    </delete>

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