Browse Source

修复重复bug

laiguoran 2 years ago
parent
commit
35c0dc44a5
1 changed files with 11 additions and 3 deletions
  1. 11 3
      app/service/payment_folder.js

+ 11 - 3
app/service/payment_folder.js

@@ -130,6 +130,7 @@ module.exports = app => {
                 if (folderList.length > 0) {
                     const leafFolderList = this._.filter(folderList, { is_leaf: 1 });
                     const parentFolderIdList = this._.map(this._.filter(folderList, { is_leaf: 0 }), 'id');
+                    const allNotExistFolderIds = [];
                     for (const lf of leafFolderList) {
                         let parentPathArray = lf.parent_path !== '' ? lf.parent_path.split('-') : [];
                         if (parentPathArray.length > 0) {
@@ -139,14 +140,21 @@ module.exports = app => {
                         }
                         const notExistFolderIds = this._.difference(parentPathArray, parentFolderIdList);
                         if (notExistFolderIds.length > 0) {
-                            const newFolderList = await this.getAllDataByCondition({ where: { id: notExistFolderIds } });
-                            console.log(newFolderList);
-                            folderList = [...folderList, ...newFolderList];
+                            for (const id of notExistFolderIds) {
+                                if (!this._.includes(allNotExistFolderIds, id)) {
+                                    allNotExistFolderIds.push(id);
+                                }
+                            }
                         }
                     }
+                    if (allNotExistFolderIds.length > 0) {
+                        const newFolderList = await this.getAllDataByCondition({ where: { id: allNotExistFolderIds } });
+                        folderList = [...folderList, ...newFolderList];
+                    }
                 }
             }
             if (folderList.length > 0) {
+                // folderList = this._.uniqBy(folderList, 'id');
                 for (const f of folderList) {
                     const userInfo = this._.find(accountList, { id: f.uid });
                     f.user_name = userInfo ? userInfo.name : '';