<?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.yfd.platform.modules.specialDocument.mapper.FilesMapper">


    <!-- 批量插入文件表（存在唯一键冲突时忽略） -->
    <insert id="batchInsertFiles">
        INSERT INTO sd_files
        (id,project_id, node_id, file_name, file_path, file_size, upload_time, uploader)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.id},#{item.projectId}, #{item.nodeId}, #{item.fileName}, #{item.filePath},
            #{item.fileSize}, #{item.uploadTime}, #{item.uploader})
        </foreach>
    </insert>

    <update id="updateNodeIdByPathHierarchy">
        UPDATE sd_files a
            LEFT JOIN sd_nodes b ON b.project_id = a.project_id
            AND a.file_path = CONCAT( b.custom3, b.node_name, '/' )
            SET a.node_id = b.id
        WHERE
            b.id IS NOT NULL
          AND a.project_id = #{id}
    </update>

</mapper>
