瀏覽代碼

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

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