فهرست منبع

导入组成物,过滤掉重复的

vian 5 سال پیش
والد
کامیت
32daf5ee0c
1فایلهای تغییر یافته به همراه13 افزوده شده و 1 حذف شده
  1. 13 1
      modules/std_glj_lib/models/gljModel.js

+ 13 - 1
modules/std_glj_lib/models/gljModel.js

@@ -737,6 +737,8 @@ class GljDao  extends OprDao{
         const allGLJs = await gljModel.find({repositoryId: gljLibId}, {ID: true, code: true}).lean();
         const codeMapping = {};
         allGLJs.forEach(glj => codeMapping[glj.code] = glj);
+        const updateGLJs = [];
+        //const forTest = [];
         // 跳过列头
         for (let row = 1; row < sheetData.length; row++) {
             const rowData = sheetData[row];
@@ -751,6 +753,11 @@ class GljDao  extends OprDao{
             if (!glj.component) {
                 glj.component = [];
             }
+            const componentIsExist = glj.component.some(item => item.ID === component.ID);
+            if (componentIsExist) {
+                //forTest.push(code);
+                continue;
+            }
             const componentGLJ = { ID: component.ID };  
             if (multiConsumeAmt.length) { // 多消耗量
                 const consumeAmtProperty = {};
@@ -762,10 +769,15 @@ class GljDao  extends OprDao{
                 componentGLJ.consumeAmt = +rowData[colMapping.consumeAmt]
             }
             glj.component.push(componentGLJ);
+            if (updateGLJs.indexOf(glj) < 0) {
+                updateGLJs.push(glj);
+            }
         }
         // 更新数据
         const tasks = [];
-        allGLJs.filter(glj => glj.component && glj.component.length).forEach(glj => {
+        //console.log(`[new Set(forTest)]`);
+        //console.log([new Set(forTest)]);
+        updateGLJs.filter(glj => glj.component && glj.component.length).forEach(glj => {
             tasks.push({
                 updateOne: {
                     filter: {