Browse Source

修复导入相同清单时数据异常问题

laiguoran 2 years ago
parent
commit
09b687d0d2
2 changed files with 12 additions and 14 deletions
  1. 5 7
      app/public/js/material_checklist.js
  2. 7 7
      app/service/change_ledger.js

+ 5 - 7
app/public/js/material_checklist.js

@@ -173,7 +173,6 @@ $(document).ready(() => {
         const removeData = [];
         for (const mc of materialChecklistData) {
             const gcl = _.find(gclGatherData, { b_code: mc.b_code, name: mc.name, unit: mc.unit, unit_price: mc.unit_price });
-            console.log(gcl);
             // 判断是否已不存在工料清单,台账修改过后删除之
             if (!gcl) {
                 removeData.push(mc.id);
@@ -1118,11 +1117,14 @@ $(document).ready(() => {
                     tree = _.filter(jsonData, function (item) {
                         return item.b_code !== null;
                     });
+                    let lastIndex = 0;// 防止导入相同的清单导致导入的含量数量增多
                     for (const [i,t] of tree.entries()) {
-                        const jIndex1 = _.findIndex(jsonData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price });
+                        const jIndex1 = _.findIndex(jsonData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price }, lastIndex);
+                        lastIndex = jIndex1;
                         if (i + 1 < tree.length) {
-                            const jIndex2 = _.findIndex(jsonData, { b_code: tree[i+1].b_code, name: tree[i+1].name, unit: tree[i+1].unit, unit_price: tree[i+1].unit_price });
+                            const jIndex2 = _.findIndex(jsonData, { b_code: tree[i+1].b_code, name: tree[i+1].name, unit: tree[i+1].unit, unit_price: tree[i+1].unit_price }, lastIndex);
                             t.children = jsonData.slice(jIndex1 + 1, jIndex2);
+                            lastIndex = jIndex2;
                         } else {
                             t.children = jsonData.slice(jIndex1 + 1);
                         }
@@ -1375,10 +1377,6 @@ $(document).ready(() => {
                 }
             }
         }
-        console.log('hello');
-        stopProgress($('#list-progress'));
-        setTimeout(function () { $('#okedit').modal('hide') }, 2000);
-        showSjsData();
     }
 
     function transExcel(results) {

+ 7 - 7
app/service/change_ledger.js

@@ -145,14 +145,14 @@ module.exports = app => {
                 const sqlParam = [this.setting.kid, this.ctx.service.ledger.tableName, mid];
                 const queryResult = await this.db.queryOne(sql, sqlParam);
                 maxId = queryResult.max_id || 0;
-                if (this.newBills) {
-                    const sql2 = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
-                    const sqlParam2 = [this.setting.kid, this.tableName, mid];
-                    const queryResult2 = await this.db.queryOne(sql2, sqlParam2);
-                    if (maxId < queryResult2.max_id || 0) {
-                        maxId = queryResult2.max_id || 0;
-                    }
+                // if (this.newBills) {
+                const sql2 = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
+                const sqlParam2 = [this.setting.kid, this.tableName, mid];
+                const queryResult2 = await this.db.queryOne(sql2, sqlParam2);
+                if (maxId < queryResult2.max_id || 0) {
+                    maxId = queryResult2.max_id || 0;
                 }
+                // }
                 const oldCacheKey = 'change_ledger_maxLid:' + mid;
                 this.cache.del(oldCacheKey);
                 this.cache.set(cacheKey, maxId, 'EX', this.ctx.app.config.cacheTime);