|
@@ -186,36 +186,52 @@ module.exports = app => {
|
|
|
const parent = await this.getDataById(data.tree_pid);
|
|
|
if (!parent) throw '移动后的分类不存在,请刷新页面后重试';
|
|
|
const sibling = await this.getAllDataByCondition({ where: { tree_pid: data.tree_pid, is_deleted: 0 } });
|
|
|
- const updateData = [{ id: filing.id, tree_order: data.tree_order, tree_pid: data.tree_pid, tree_level: parent.tree_level + 1 }];
|
|
|
+ const posterity = await this.getPosterityData(filing.id);
|
|
|
+ const updateData = { id: filing.id, tree_order: data.tree_order, tree_pid: data.tree_pid, tree_level: parent.tree_level + 1 };
|
|
|
+ const posterityUpdateData = posterity.map(x => {
|
|
|
+ updateData.push({ id: x.id, tree_level: parent.tree_level + 1 - filing.tree_level + x.tree_level });
|
|
|
+ });
|
|
|
+ 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;
|
|
|
- updateData.push({id: x.id, tree_order: x.tree_order + 1});
|
|
|
+ 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;
|
|
|
- updateData.push({id: x.id, tree_order: x.tree_order - 1});
|
|
|
+ siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
const orgSibling = await this.getAllDataByCondition({ where: { tree_pid: filing.tree_pid, is_deleted: 0 } });
|
|
|
orgSibling.forEach(x => {
|
|
|
if (x.tree_order < filing.tree_order) return;
|
|
|
- updateData.push({id: x.id, tree_order: x.tree_order - 1});
|
|
|
+ siblingUpdateData.push({id: x.id, tree_order: x.tree_order - 1});
|
|
|
});
|
|
|
sibling.forEach(x => {
|
|
|
if (x.tree_order < data.tree_order) return;
|
|
|
- updateData.push({id: x.id, tree_order: x.tree_order + 1});
|
|
|
+ siblingUpdateData.push({id: x.id, tree_order: x.tree_order + 1});
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ 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();
|
|
|
+ } catch (err) {
|
|
|
+ await conn.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
await this.db.updateRows(this.tableName, updateData);
|
|
|
- return { update: updateData };
|
|
|
+ return { update: [updateData, ...posterityUpdateData, ...siblingUpdateData] };
|
|
|
}
|
|
|
|
|
|
async sumFileCount(spid) {
|