Browse Source

移动节点相关

MaiXinRong 1 year ago
parent
commit
64bf299ac2
2 changed files with 39 additions and 34 deletions
  1. 2 0
      app/service/filing.js
  2. 37 34
      app/service/filing_template.js

+ 2 - 0
app/service/filing.js

@@ -211,10 +211,12 @@ module.exports = app => {
             } else {
                 const orgSibling = await this.getAllDataByCondition({ where: { tree_pid: filing.tree_pid, is_deleted: 0 } });
                 orgSibling.forEach(x => {
+                    if (x.id === filing.id) return;
                     if (x.tree_order < filing.tree_order) return;
                     siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
                 });
                 sibling.forEach(x => {
+                    if (x.id === filing.id) return;
                     if (x.tree_order < data.tree_order) return;
                     siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
                 })

+ 37 - 34
app/service/filing_template.js

@@ -163,6 +163,7 @@ module.exports = app => {
             }
         }
         async move(templateId, data) {
+            console.log(data);
             const filing = await this.getDataById(data.id);
             if (!filing) throw '移动的分类不存在,请刷新页面后重试';
             const parent = await this.getDataById(data.tree_pid);
@@ -171,45 +172,47 @@ module.exports = app => {
             const posterity = await this.getPosterityData(templateId, filing.id);
 
             const result = [];
-            const conn = await this.db.beginTransaction();
-            try {
-                const updateData = { id: filing.id, tree_order: data.tree_order, tree_pid: data.tree_pid, tree_level: parent ? parent.tree_level + 1 : 1, filing_type };
-                conn.update(this.tableName, updateData);
-                result.push(updateData);
-                if (posterity.length > 0) {
-                    const posterityUpdateData = posterity.map(x => { return { id: x.id, filing_type, tree_level: parent.tree_level + 1 - filing.tree_level + x.tree_level }});
-                    conn.updateRows(this.tableName, posterityUpdateData);
-                }
-                const siblingUpdateData = [];
-                if (data.tree_pid === filing.tree_pid) {
-                    if (data.tree_order < filing.tree_order) {
-                        sibling.forEach(x => {
-                            if (x.id === filing.id) return;
-                            if (x.tree_order < data.tree_order) return;
-                            if (x.tree_order > filing.tree_order) return;
-                            siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
-                        });
-                    } else {
-                        sibling.forEach(x => {
-                            if (x.id === filing.id) return;
-                            if (x.tree_order < filing.tree_order) return;
-                            if (x.tree_order > data.tree_order) return;
-                            siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
-                        });
-                    }
+            const updateData = { id: filing.id, tree_order: data.tree_order, tree_pid: data.tree_pid, tree_level: parent ? parent.tree_level + 1 : 1, filing_type };
+            result.push(updateData);
+            const posterityUpdateData = posterity.map(x => { return { id: x.id, filing_type, tree_level: parent.tree_level + 1 - filing.tree_level + x.tree_level }});
+            result.push(posterityUpdateData);
+            const siblingUpdateData = [];
+            if (data.tree_pid === filing.tree_pid) {
+                if (data.tree_order < filing.tree_order) {
+                    sibling.forEach(x => {
+                        if (x.id === filing.id) return;
+                        if (x.tree_order < data.tree_order) return;
+                        if (x.tree_order > filing.tree_order) return;
+                        siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
+                    });
                 } else {
-                    const orgSibling = await this.getAllDataByCondition({ where: { temp_id: templateId, tree_pid: filing.tree_pid } });
-                    orgSibling.forEach(x => {
+                    sibling.forEach(x => {
+                        if (x.id === filing.id) return;
                         if (x.tree_order < filing.tree_order) return;
+                        if (x.tree_order > data.tree_order) return;
                         siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
                     });
-                    sibling.forEach(x => {
-                        if (x.tree_order < data.tree_order) return;
-                        siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
-                    })
                 }
-                await conn.updateRows(this.tableName, siblingUpdateData);
-                result.push(...siblingUpdateData);
+            } else {
+                const orgSibling = await this.getAllDataByCondition({ where: { temp_id: templateId, tree_pid: filing.tree_pid } });
+                orgSibling.forEach(x => {
+                    if (x.id === filing.id) return;
+                    if (x.tree_order < filing.tree_order) return;
+                    siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
+                });
+                sibling.forEach(x => {
+                    if (x.id === filing.id) return;
+                    if (x.tree_order < data.tree_order) return;
+                    siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
+                })
+            }
+            result.push(...siblingUpdateData);
+
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.update(this.tableName, updateData);
+                if (posterityUpdateData.length > 0) await conn.updateRows(this.tableName, posterityUpdateData);
+                if (siblingUpdateData.length > 0) await conn.updateRows(this.tableName, siblingUpdateData);
                 await conn.commit();
                 return { update: result };
             } catch(err) {