FileManage/java/src/main/resources/mapper/specialDocument/NodesMapper.xml

41 lines
1.4 KiB
XML

<?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>
<delete id="deleteNodesRecursively">
WITH RECURSIVE node_tree AS (
SELECT id
FROM sd_nodes
WHERE id = #{nodeId}
UNION ALL
SELECT n.id
FROM sd_nodes n
INNER JOIN node_tree t ON n.parent_id = t.id
)
DELETE FROM sd_nodes WHERE id IN (SELECT id FROM node_tree)
</delete>
</mapper>