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

    <resultMap type="PointsTransaction" id="PointsTransactionResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="ddId"    column="dd_id"    />
        <result property="type"    column="type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="pointsChange"    column="points_change"    />
        <result property="currentPoints"    column="current_points"    />
    </resultMap>

    <sql id="selectPointsTransactionVo">
        select id, user_id, dd_id, type, create_time, update_time, remark, points_change, current_points from points_transaction
    </sql>

    <select id="selectPointsTransactionList" parameterType="PointsTransaction" resultMap="PointsTransactionResult">
        <include refid="selectPointsTransactionVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="ddId != null "> and dd_id = #{ddId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="pointsChange != null  and pointsChange != ''"> and points_change = #{pointsChange}</if>
            <if test="currentPoints != null  and currentPoints != ''"> and current_points = #{currentPoints}</if>
        </where>
    </select>

    <select id="selectPointsTransactionById" parameterType="Long" resultMap="PointsTransactionResult">
        <include refid="selectPointsTransactionVo"/>
        where id = #{id}
    </select>

    <insert id="insertPointsTransaction" parameterType="PointsTransaction" useGeneratedKeys="true" keyProperty="id">
        insert into points_transaction
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="ddId != null">dd_id,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="pointsChange != null and pointsChange != ''">points_change,</if>
            <if test="currentPoints != null and currentPoints != ''">current_points,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="ddId != null">#{ddId},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="pointsChange != null and pointsChange != ''">#{pointsChange},</if>
            <if test="currentPoints != null and currentPoints != ''">#{currentPoints},</if>
        </trim>
    </insert>

    <update id="updatePointsTransaction" parameterType="PointsTransaction">
        update points_transaction
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="ddId != null">dd_id = #{ddId},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="pointsChange != null and pointsChange != ''">points_change = #{pointsChange},</if>
            <if test="currentPoints != null and currentPoints != ''">current_points = #{currentPoints},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePointsTransactionById" parameterType="Long">
        delete from points_transaction where id = #{id}
    </delete>

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