<?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.WxInstrumentInstructionsMapper">
    
    <resultMap type="WxInstrumentInstructions" id="WxInstrumentInstructionsResult">
        <result property="id"    column="id"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="name"    column="name"    />
        <result property="link"    column="link"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectWxInstrumentInstructionsVo">
        select id, instrument_id, name, link, status, create_by, create_time from wx_instrument_instructions
    </sql>

    <select id="selectWxInstrumentInstructionsList" parameterType="WxInstrumentInstructions" resultMap="WxInstrumentInstructionsResult">
        <include refid="selectWxInstrumentInstructionsVo"/>
        <where>  
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="link != null  and link != ''"> and link = #{link}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectWxInstrumentInstructionsById" parameterType="Long" resultMap="WxInstrumentInstructionsResult">
        <include refid="selectWxInstrumentInstructionsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWxInstrumentInstructions" parameterType="WxInstrumentInstructions" useGeneratedKeys="true" keyProperty="id">
        insert into wx_instrument_instructions
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="link != null and link != ''">link,</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="name != null and name != ''">#{name},</if>
            <if test="link != null and link != ''">#{link},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateWxInstrumentInstructions" parameterType="WxInstrumentInstructions">
        update wx_instrument_instructions
        <trim prefix="SET" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="link != null and link != ''">link = #{link},</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="deleteWxInstrumentInstructionsById" parameterType="Long">
        delete from wx_instrument_instructions where id = #{id}
    </delete>

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