<?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.younike.system.mapper.IntegralRecordMapper">
    
    <resultMap type="IntegralRecord" id="IntegralRecordResult">
        <result property="id"    column="id"    />
        <result property="change"    column="change"    />
        <result property="reason"    column="reason"    />
        <result property="result"    column="result"    />
        <result property="msg"    column="msg"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectIntegralRecordVo">
        select id, change, reason, result, msg, create_by, create_time from integral_record
    </sql>

    <select id="selectIntegralRecordList" parameterType="IntegralRecord" resultMap="IntegralRecordResult">
        <include refid="selectIntegralRecordVo"/>
        <where>  
            <if test="change != null "> and change = #{change}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="result != null "> and result = #{result}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
        </where>
    </select>
    
    <select id="selectIntegralRecordById" parameterType="Long" resultMap="IntegralRecordResult">
        <include refid="selectIntegralRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertIntegralRecord" parameterType="com.younike.system.domain.IntegralRecord" useGeneratedKeys="true" keyProperty="id">
        insert into integral_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="change != null">`change`,</if>
            <if test="reason != null">reason,</if>
            <if test="result != null">result,</if>
            <if test="msg != null">msg,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="change != null">#{change},</if>
            <if test="reason != null">#{reason},</if>
            <if test="result != null">#{result},</if>
            <if test="msg != null">#{msg},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateIntegralRecord" parameterType="com.younike.system.domain.IntegralRecord">
        update integral_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="change != null">`change` = #{change},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="result != null">result = #{result},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIntegralRecordById" parameterType="Long">
        delete from integral_record where id = #{id}
    </delete>

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