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

    <resultMap type="WxUserInstrumentLog" id="WxUserInstrumentLogResult">
        <result property="id"    column="id"    />
        <result property="userInstrumentId"    column="user_instrument_id"    />
        <result property="userId"    column="user_id"    />
        <result property="serial"    column="serial"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="instrumentName"    column="instrument_name"    />
        <result property="serialImage"    column="serial_image"    />
        <result property="guarantee"    column="guarantee"    />
        <result property="guaranteeEndtime"    column="guarantee_endtime"    />
        <result property="bindingStatus"    column="binding_status"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectWxUserInstrumentLogVo">
        select id, user_id, serial, instrument_id, instrument_name, serial_image, guarantee, guarantee_endtime, binding_status, status, create_by, create_time from wx_user_instrument_log
    </sql>

    <select id="selectWxUserInstrumentLogList" parameterType="WxUserInstrumentLog" resultMap="WxUserInstrumentLogResult">
        <include refid="selectWxUserInstrumentLogVo"/>
        <where>
            <if test="userInstrumentId != null "> and user_instrument_id = #{userInstrumentId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="serial != null  and serial != ''"> and serial = #{serial}</if>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="instrumentName != null  and instrumentName != ''"> and instrument_name like concat('%', #{instrumentName}, '%')</if>
            <if test="serialImage != null  and serialImage != ''"> and serial_image = #{serialImage}</if>
            <if test="guarantee != null "> and guarantee = #{guarantee}</if>
            <if test="guaranteeEndtime != null "> and guarantee_endtime = #{guaranteeEndtime}</if>
            <if test="bindingStatus != null "> and binding_status = #{bindingStatus}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectWxUserInstrumentLogById" parameterType="Long" resultMap="WxUserInstrumentLogResult">
        <include refid="selectWxUserInstrumentLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertWxUserInstrumentLog" parameterType="WxUserInstrumentLog" useGeneratedKeys="true" keyProperty="id">
        insert into wx_user_instrument_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userInstrumentId != null">user_instrument_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="serial != null and serial != ''">serial,</if>
            <if test="instrumentId != null">instrument_id,</if>
            <if test="instrumentName != null and instrumentName != ''">instrument_name,</if>
            <if test="serialImage != null and serialImage != ''">serial_image,</if>
            <if test="guarantee != null">guarantee,</if>
            <if test="guaranteeEndtime != null">guarantee_endtime,</if>
            <if test="bindingStatus != null">binding_status,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userInstrumentId != null">#{userInstrumentId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="serial != null and serial != ''">#{serial},</if>
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="instrumentName != null and instrumentName != ''">#{instrumentName},</if>
            <if test="serialImage != null and serialImage != ''">#{serialImage},</if>
            <if test="guarantee != null">#{guarantee},</if>
            <if test="guaranteeEndtime != null">#{guaranteeEndtime},</if>
            <if test="bindingStatus != null">#{bindingStatus},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateWxUserInstrumentLog" parameterType="WxUserInstrumentLog">
        update wx_user_instrument_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="userInstrumentId != null">user_instrument_id = #{userInstrumentId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="serial != null and serial != ''">serial = #{serial},</if>
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="instrumentName != null and instrumentName != ''">instrument_name = #{instrumentName},</if>
            <if test="serialImage != null and serialImage != ''">serial_image = #{serialImage},</if>
            <if test="guarantee != null">guarantee = #{guarantee},</if>
            <if test="guaranteeEndtime != null">guarantee_endtime = #{guaranteeEndtime},</if>
            <if test="bindingStatus != null">binding_status = #{bindingStatus},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxUserInstrumentLogById" parameterType="Long">
        delete from wx_user_instrument_log where id = #{id}
    </delete>

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

    <delete id="deleteByUserId" parameterType="Long">
        delete from wx_user_instrument_log where user_id = #{userId}
    </delete>
</mapper>
