<?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.IntegralLogMapper">
    
    <resultMap type="IntegralLog" id="IntegralLogResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="title"    column="title"    />
        <result property="mark"    column="mark"    />
        <result property="uid"    column="uid"    />
        <result property="type"    column="type"    />
        <result property="num"    column="num"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectIntegralLogVo">
        select id, order_id, title, mark, uid, type, num, created_at, updated_at from integral_log
    </sql>

    <select id="selectIntegralLogList" parameterType="IntegralLog" resultMap="IntegralLogResult">
        <include refid="selectIntegralLogVo"/>
        <where>  
            <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
            <if test="title != null  and title != ''"> and  title like concat('%', #{title}, '%')</if>
            <if test="mark != null  and mark != ''"> and mark like  concat('%', #{mark}, '%')</if>
            <if test="uid != null "> and uid = #{uid}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectIntegralLogById" parameterType="Long" resultMap="IntegralLogResult">
        <include refid="selectIntegralLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertIntegralLog" parameterType="IntegralLog" useGeneratedKeys="true" keyProperty="id">
        insert into integral_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="mark != null and mark != ''">mark,</if>
            <if test="uid != null">uid,</if>
            <if test="type != null">type,</if>
            <if test="num != null">num,</if>
             created_at,
             updated_at
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="mark != null and mark != ''">#{mark},</if>
            <if test="uid != null">#{uid},</if>
            <if test="type != null">#{type},</if>
            <if test="num != null">#{num},</if>
            NOW(),
            NOW()
         </trim>
    </insert>

    <update id="updateIntegralLog" parameterType="IntegralLog">
        update integral_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="mark != null and mark != ''">mark = #{mark},</if>
            <if test="uid != null">uid = #{uid},</if>
            <if test="type != null">type = #{type},</if>
            <if test="num != null">num = #{num},</if>
             updated_at=NOW()
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIntegralLogById" parameterType="Long">
        delete from integral_log where id = #{id}
    </delete>

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