<?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.flossom.common.core.mapper.WxUserIntegralLogMapper">

    <resultMap type="WxUserIntegralLog" id="WxUserIntegralLogResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="source"    column="source"    />
        <result property="floatScore"    column="float_score"    />
        <result property="soureId"    column="soure_id"    />
        <result property="remarkContent"    column="remark_content"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
    </resultMap>

    <sql id="selectWxUserIntegralLogVo">
        select id,user_id, user_name, user_phone, source, float_score, soure_id, remark_content, create_time, create_by from wx_user_integral_log
    </sql>

    <select id="selectWxUserIntegralLogList" parameterType="WxUserIntegralLog" resultMap="WxUserIntegralLogResult">
        <include refid="selectWxUserIntegralLogVo"/>
        <where>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="floatScore != null "> and float_score = #{floatScore}</if>
            <if test="soureId != null "> and soure_id = #{soureId}</if>
            <if test="remarkContent != null  and remarkContent != ''"> and remark_content = #{remarkContent}</if>
        </where>
    </select>

    <select id="selectWxUserIntegralLogById" parameterType="Long" resultMap="WxUserIntegralLogResult">
        <include refid="selectWxUserIntegralLogVo"/>
        where id = #{id}
    </select>

    <select id="obtainUserIntegral" resultType="com.flossom.common.core.domain.entity.WxUserIntegralLog">
        <include refid="selectWxUserIntegralLogVo"/>
        WHERE
            user_id = #{userId}
        ORDER BY
            create_time DESC
    </select>

    <insert id="insertWxUserIntegralLog" parameterType="WxUserIntegralLog" useGeneratedKeys="true" keyProperty="id">
        insert into wx_user_integral_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="source != null">source,</if>
            <if test="floatScore != null">float_score,</if>
            <if test="soureId != null">soure_id,</if>
            <if test="remarkContent != null">remark_content,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="source != null">#{source},</if>
            <if test="floatScore != null">#{floatScore},</if>
            <if test="soureId != null">#{soureId},</if>
            <if test="remarkContent != null">#{remarkContent},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
         </trim>
    </insert>

    <update id="updateWxUserIntegralLog" parameterType="WxUserIntegralLog">
        update wx_user_integral_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="source != null">source = #{source},</if>
            <if test="floatScore != null">float_score = #{floatScore},</if>
            <if test="soureId != null">soure_id = #{soureId},</if>
            <if test="remarkContent != null">remark_content = #{remarkContent},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxUserIntegralLogById" parameterType="Long">
        delete from wx_user_integral_log where id = #{id}
    </delete>

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