<?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.WxInstrumentModeMapper">
    
    <resultMap type="WxInstrumentMode" id="WxInstrumentModeResult">
        <result property="id"    column="id"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="modeId"    column="mode_id"    />
        <result property="modeSort"    column="mode_sort"    />
        <result property="isNew"    column="is_new"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectWxInstrumentModeVo">
        select id, instrument_id, mode_id, mode_sort, is_new, status, create_by, create_time from wx_instrument_mode
    </sql>

    <select id="selectWxInstrumentModeList" parameterType="WxInstrumentMode" resultMap="WxInstrumentModeResult">
        <include refid="selectWxInstrumentModeVo"/>
        <where>  
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="modeId != null "> and mode_id = #{modeId}</if>
            <if test="isNew != null "> and is_new = #{isNew}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by mode_sort asc
    </select>
    
    <select id="selectWxInstrumentModeById" parameterType="Long" resultMap="WxInstrumentModeResult">
        <include refid="selectWxInstrumentModeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWxInstrumentMode" parameterType="WxInstrumentMode" useGeneratedKeys="true" keyProperty="id">
        insert into wx_instrument_mode
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id,</if>
            <if test="modeId != null">mode_id,</if>
            <if test="modeSort != null">mode_sort,</if>
            <if test="isNew != null">is_new,</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="instrumentId != null">#{instrumentId},</if>
            <if test="modeId != null">#{modeId},</if>
            <if test="modeSort != null">#{modeSort},</if>
            <if test="isNew != null">#{isNew},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateWxInstrumentMode" parameterType="WxInstrumentMode">
        update wx_instrument_mode
        <trim prefix="SET" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="modeId != null">mode_id = #{modeId},</if>
            <if test="modeSort != null">mode_sort = #{modeSort},</if>
            <if test="isNew != null">isNew = #{isNew},</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="deleteWxInstrumentModeById" parameterType="Long">
        delete from wx_instrument_mode where id = #{id}
    </delete>

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

    <delete id="deleteByInstrumentId" parameterType="Long">
        delete from wx_instrument_mode where instrument_id = #{instrumentId}
    </delete>
</mapper>