<?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.WxInstrumentFileRelateMapper">
    
    <resultMap type="WxInstrumentFileRelate" id="WxInstrumentFileRelateResult">
        <result property="id"    column="id"    />
        <result property="classify"    column="classify"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="file"    column="file"    />
        <result property="fileType"    column="file_type"    />
        <result property="message"    column="message"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectWxInstrumentFileRelateVo">
        select id, classify, instrument_id, file, file_type, message, status, create_by, create_time from wx_instrument_file_relate
    </sql>

    <select id="selectWxInstrumentFileRelateList" parameterType="WxInstrumentFileRelate" resultMap="WxInstrumentFileRelateResult">
        <include refid="selectWxInstrumentFileRelateVo"/>
        <where>  
            <if test="classify != null "> and classify = #{classify}</if>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="file != null  and file != ''"> and file = #{file}</if>
            <if test="fileType != null  and fileType != ''"> and file_type = #{fileType}</if>
            <if test="message != null  and message != ''"> and message = #{message}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by create_time asc
    </select>
    
    <select id="selectWxInstrumentFileRelateById" parameterType="Long" resultMap="WxInstrumentFileRelateResult">
        <include refid="selectWxInstrumentFileRelateVo"/>
        where id = #{id}
    </select>
    <select id="selectByInstrumentIdAndClassify" resultMap="WxInstrumentFileRelateResult">
        <include refid="selectWxInstrumentFileRelateVo"/>
        where instrument_id = #{instrumentId} and classify = #{classify}
    </select>

    <insert id="insertWxInstrumentFileRelate" parameterType="WxInstrumentFileRelate" useGeneratedKeys="true" keyProperty="id">
        insert into wx_instrument_file_relate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="classify != null">classify,</if>
            <if test="instrumentId != null">instrument_id,</if>
            <if test="file != null and file != ''">file,</if>
            <if test="fileType != null and fileType != ''">file_type,</if>
            <if test="message != null and message != ''">message,</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="classify != null">#{classify},</if>
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="file != null and file != ''">#{file},</if>
            <if test="fileType != null and fileType != ''">#{fileType},</if>
            <if test="message != null and message != ''">#{message},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateWxInstrumentFileRelate" parameterType="WxInstrumentFileRelate">
        update wx_instrument_file_relate
        <trim prefix="SET" suffixOverrides=",">
            <if test="classify != null">classify = #{classify},</if>
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="file != null and file != ''">file = #{file},</if>
            <if test="fileType != null and fileType != ''">file_type = #{fileType},</if>
            <if test="message != null and message != ''">message = #{message},</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="deleteWxInstrumentFileRelateById" parameterType="Long">
        delete from wx_instrument_file_relate where id = #{id}
    </delete>

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


    <delete id="deleteByInstrumentIdAndClassify">
        delete from wx_instrument_file_relate where instrument_id = #{instrumentId} and classify = #{classify}
    </delete>
</mapper>