<?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.aucma.dms.mapper.DmsInstanceFileMapper">
 
    <resultMap type="DmsInstanceFile" id="DmsInstanceFileResult">
        <result property="instanceFileId"    column="instance_file_id"    />
        <result property="targetType"    column="target_type"    />
        <result property="targetId"    column="target_id"    />
        <result property="filePath"    column="file_path"    />
    </resultMap>
 
    <sql id="selectDmsInstanceFileVo">
        select instance_file_id, target_type, target_id, file_path from dms_instance_file
    </sql>
 
    <select id="selectDmsInstanceFileList" parameterType="DmsInstanceFile" resultMap="DmsInstanceFileResult">
        <include refid="selectDmsInstanceFileVo"/>
        <where>
            <if test="targetType != null  and targetType != ''"> and target_type = #{targetType}</if>
            <if test="targetId != null "> and target_id = #{targetId}</if>
            <if test="filePath != null  and filePath != ''"> and file_path = #{filePath}</if>
        </where>
    </select>
 
    <select id="selectDmsInstanceFileByInstanceFileId" parameterType="Long" resultMap="DmsInstanceFileResult">
        <include refid="selectDmsInstanceFileVo"/>
        where instance_file_id = #{instanceFileId}
    </select>
 
    <insert id="insertDmsInstanceFile" parameterType="DmsInstanceFile" useGeneratedKeys="true" keyProperty="instanceFileId">
        insert into dms_instance_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="targetType != null and targetType != ''">target_type,</if>
            <if test="targetId != null">target_id,</if>
            <if test="filePath != null and filePath != ''">file_path,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="targetType != null and targetType != ''">#{targetType},</if>
            <if test="targetId != null">#{targetId},</if>
            <if test="filePath != null and filePath != ''">#{filePath},</if>
         </trim>
    </insert>
 
    <update id="updateDmsInstanceFile" parameterType="DmsInstanceFile">
        update dms_instance_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="targetType != null and targetType != ''">target_type = #{targetType},</if>
            <if test="targetId != null">target_id = #{targetId},</if>
            <if test="filePath != null and filePath != ''">file_path = #{filePath},</if>
        </trim>
        where instance_file_id = #{instanceFileId}
    </update>
 
    <delete id="deleteDmsInstanceFileByInstanceFileId" parameterType="Long">
        delete from dms_instance_file where instance_file_id = #{instanceFileId}
    </delete>
 
    <delete id="deleteDmsInstanceFileByInstanceFileIds" parameterType="String">
        delete from dms_instance_file where instance_file_id in
        <foreach item="instanceFileId" collection="array" open="(" separator="," close=")">
            #{instanceFileId}
        </foreach>
    </delete>
 
 
 
 
    <insert id="batchDmsInstanceFile">
        insert into dms_instance_file( instance_file_id, target_type, target_id, file_path) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.instanceFileId}, #{item.targetType}, #{item.targetId}, #{item.filePath})
        </foreach>
    </insert>
    <delete id="deleteDmsInstanceFileByUpdate">
       delete from dms_instance_file where target_type = '1' and target_id = #{targetId}
    </delete>
 
    <delete id="deleteDmsInstanceFileByTargetId" parameterType="Long">
        delete from dms_instance_file where target_id = #{targetId}
    </delete>
 
    <select id="selectDmsInstanceFileConvertList" parameterType="DmsInstanceFile" resultMap="DmsInstanceFileResult">
        select instance_file_id, target_type, target_id, file_path as name,file_path as url from dms_instance_file
        <where>
            <if test="targetType != null  and targetType != ''"> and target_type = #{targetType}</if>
            <if test="targetId != null "> and target_id = #{targetId}</if>
            <if test="filePath != null  and filePath != ''"> and file_path = #{filePath}</if>
        </where>
    </select>
 
</mapper>
