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

    <resultMap type="WxInstrumentSerial" id="WxInstrumentSerialResult">
        <result property="id"    column="id"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="serial"    column="serial"    />
        <result property="source"    column="source"    />
        <result property="bindingStatus"    column="binding_status"    />
        <result property="validStatus"    column="valid_status"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectWxInstrumentSerialVo">
        select id, source,instrument_id, serial, binding_status, valid_status, status, create_by, create_time, remark from wx_instrument_serial
    </sql>

    <select id="selectWxInstrumentSerialList" parameterType="WxInstrumentSerial" resultMap="WxInstrumentSerialResult">
        <include refid="selectWxInstrumentSerialVo"/>
        <where>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="serial != null  and serial != ''"> and serial  like concat('%', #{serial}, '%')</if>
            <if test="source != null  and source != ''"> and `source`  like concat('%', #{source}, '%')</if>
            <if test="bindingStatus != null "> and binding_status = #{bindingStatus}</if>
            <if test="validStatus != null "> and valid_status = #{validStatus}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="remark != null "> and remark  like concat('%', #{remark}, '%')</if>
            <if test="queryInstrumentIds!=null and queryInstrumentIds !=''">
                and
                <foreach collection="queryInstrumentIds.split(',')" index="index" item="item" open="(" separator="OR"
                         close=")">
                    instrument_id = #{item}
                </foreach>
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectEntityListBySerial" parameterType="WxInstrumentSerial" resultMap="WxInstrumentSerialResult">
        <include refid="selectWxInstrumentSerialVo"/>
        <where>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="serial != null  and serial != ''"> and serial = #{serial} </if>
            <if test="bindingStatus != null "> and binding_status = #{bindingStatus}</if>
            <if test="validStatus != null "> and valid_status = #{validStatus}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by create_time desc
        limit 1
    </select>

    <select id="selectWxInstrumentSerialById" parameterType="Long" resultMap="WxInstrumentSerialResult">
        <include refid="selectWxInstrumentSerialVo"/>
        where id = #{id}
    </select>

    <insert id="insertWxInstrumentSerial" parameterType="WxInstrumentSerial" useGeneratedKeys="true" keyProperty="id">
        insert into wx_instrument_serial
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id,</if>
            <if test="serial != null and serial != ''">serial,</if>
            <if test="source != null and source != ''">`source`,</if>
            <if test="bindingStatus != null">binding_status,</if>
            <if test="validStatus != null">valid_status,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="serial != null and serial != ''">#{serial},</if>
            <if test="source != null and source != ''">#{source},</if>
            <if test="bindingStatus != null">#{bindingStatus},</if>
            <if test="validStatus != null">#{validStatus},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWxInstrumentSerial" parameterType="WxInstrumentSerial">
        update wx_instrument_serial
        <trim prefix="SET" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="serial != null and serial != ''">serial = #{serial},</if>
            <if test="source != null and source != ''">`source` = #{source},</if>
            <if test="bindingStatus != null">binding_status = #{bindingStatus},</if>
            <if test="validStatus != null">valid_status = #{validStatus},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateBySerial" parameterType="WxInstrumentSerial">
        update wx_instrument_serial
        <trim prefix="SET" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="source != null and source != ''">`source` = #{source},</if>
            <if test="bindingStatus != null">binding_status = #{bindingStatus},</if>
            <if test="validStatus != null">valid_status = #{validStatus},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where serial = #{serial}
    </update>


    <update id="updateAll" parameterType="WxInstrumentSerial">
        update wx_instrument_serial
        <trim prefix="SET" suffixOverrides=",">
            <if test="validStatus != null">valid_status = #{validStatus},</if>
        </trim>
    </update>

    <delete id="deleteWxInstrumentSerialById" parameterType="Long">
        delete from wx_instrument_serial where id = #{id}
    </delete>

    <delete id="deleteAll">
        delete from wx_instrument_serial
    </delete>

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