<?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.NodesMapper">

    <!-- 批量插入（存在唯一键冲突时忽略） -->
    <insert id="batchInsertIgnore">
        INSERT INTO sd_nodes
        (id,project_id, parent_id, node_order, node_type, node_name, custom3, create_time)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.id},#{item.projectId}, #{item.parentId}, #{item.nodeOrder}, #{item.nodeType},
            #{item.nodeName}, #{item.custom3}, #{item.createTime})
        </foreach>
    </insert>


    <update id="updateParentIdByPathHierarchy">
        UPDATE sd_nodes a
            LEFT JOIN sd_nodes b
        ON b.project_id = a.project_id
            AND a.custom3 = CONCAT( b.custom3,b.node_name, '/' )
            SET a.parent_id = b.id
        WHERE
            b.id IS NOT NULL
    </update>

</mapper>
