<?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.WxInstrumentNameRelateMapper">
    
    <resultMap type="WxInstrumentNameRelate" id="WxInstrumentNameRelateResult">
        <result property="id"    column="id"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="productName"    column="product_name"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectWxInstrumentNameRelateVo">
        select id, instrument_id, product_name, status, create_by, create_time from wx_instrument_name_relate
    </sql>

    <select id="selectWxInstrumentNameRelateList" parameterType="WxInstrumentNameRelate" resultMap="WxInstrumentNameRelateResult">
        <include refid="selectWxInstrumentNameRelateVo"/>
        <where>  
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectWxInstrumentNameRelateById" parameterType="Long" resultMap="WxInstrumentNameRelateResult">
        <include refid="selectWxInstrumentNameRelateVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWxInstrumentNameRelate" parameterType="WxInstrumentNameRelate" useGeneratedKeys="true" keyProperty="id">
        insert into wx_instrument_name_relate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id,</if>
            <if test="productName != null and productName != ''">product_name,</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="productName != null and productName != ''">#{productName},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateWxInstrumentNameRelate" parameterType="WxInstrumentNameRelate">
        update wx_instrument_name_relate
        <trim prefix="SET" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="productName != null and productName != ''">product_name = #{productName},</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="deleteWxInstrumentNameRelateById" parameterType="Long">
        delete from wx_instrument_name_relate where id = #{id}
    </delete>

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