MaiXinRong 5 tahun lalu
induk
melakukan
f2dc73b813
3 mengubah file dengan 51 tambahan dan 24 penghapusan
  1. 1 3
      app/controller/ledger_controller.js
  2. 10 10
      app/public/js/global.js
  3. 40 11
      app/service/ledger.js

+ 1 - 3
app/controller/ledger_controller.js

@@ -475,9 +475,7 @@ module.exports = app => {
                 const data = JSON.parse(LzString.decompressFromUTF16(compressData));
                 const responseData = { err: 0, msg: '', data: {}, };
                 const templateId = await this.ctx.service.valuation.getValuationTemplate(this.ctx.tender.data.valuation);
-                await ctx.service.ledger.importExcel(templateId, data);
-                responseData.data.bills = await ctx.service.ledger.getData(ctx.tender.id);
-                responseData.data.pos = await ctx.service.pos.getPosData({tid: this.ctx.tender.id});
+                responseData.data = await ctx.service.ledger.importExcel(templateId, data);
                 ctx.body = responseData;
             } catch (err) {
                 this.log(err);

+ 10 - 10
app/public/js/global.js

@@ -136,7 +136,7 @@ const postData = function (url, data, successCallback, errorCallBack, showWaitin
         data: {'data': JSON.stringify(data)},
         dataType: 'json',
         cache: false,
-        timeout: 40000,
+        timeout: 60000,
         beforeSend: function(xhr) {
             let csrfToken = Cookies.get('csrfToken');
             xhr.setRequestHeader('x-csrf-token', csrfToken);
@@ -180,7 +180,7 @@ const postDataCompress = function (url, data, successCallback, errorCallBack, ht
         data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
         dataType: 'json',
         cache: false,
-        timeout: 60000, // 导入清单Excel(10w行)预计需要时间
+        timeout: 80000, // 导入清单Excel(10w行)预计需要时间
         beforeSend: function(xhr) {
             let csrfToken = Cookies.get('csrfToken');
             xhr.setRequestHeader('x-csrf-token', csrfToken);
@@ -398,27 +398,28 @@ function showProgress() {
                 processObj.attr('aria-valuenow', pos + 1);
                 processObj.width((pos + 1) + '%');
             }
-        } else if (pos < 90) {                        // 10
+        } else if (pos < 90) {                        // 15
             count += 1;
-            if (count % 10 === 0) {
+            if (count % 15 === 0) {
                 processObj.attr('aria-valuenow', pos + 1);
                 processObj.width((pos + 1) + '%');
             }
-        }  else if (pos < 95) {                       // 15
+        }  else if (pos < 95) {                       // 20
             count += 1;
-            if (count % 30 === 0) {
+            if (count % 40 === 0) {
                 processObj.attr('aria-valuenow', pos + 1);
                 processObj.width((pos + 1) + '%');
             }
-        } else if (pos < 100) {                       // 25
+        } else if (pos < 100) {                       // 30
             count += 1;
-            if (count % 50 === 0) {
+            if (count % 60 === 0) {
                 processObj.attr('aria-valuenow', pos + 1);
             }
         }
     }, 100);
 }
 function doneProgress() {
+    clearInterval(progressInterval);
     $('.progress-bar').attr('aria-valuenow', 100).width('100%');
 }
 function closeProgress() {
@@ -433,8 +434,7 @@ function closeProgress() {
         if(msgDiv != null){
             document.body.removeChild(msgDiv);
         }
-        clearInterval(progressInterval);
-    }, 300);
+    }, 500);
 }
 
 /**

+ 40 - 11
app/service/ledger.js

@@ -812,6 +812,7 @@ module.exports = app => {
                 });
             }
             await transaction.insert(this.tableName, datas);
+            return datas;
         }
 
         /**
@@ -820,32 +821,60 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async importExcel(templateId, excelData) {
-            //console.time('analysis');
+            console.time('analysis');
             const AnalysisExcel = require('../lib/analysis_excel');
             const analysisExcel = new AnalysisExcel(this.ctx);
             const tempData = await this.ctx.service.tenderNodeTemplate.getData(templateId, true);
             const cacheTree = analysisExcel.analysisData(excelData, tempData);
             const cacheKey = keyPre + this.ctx.tender.id;
             const orgMaxId = parseInt(await this.cache.get(cacheKey));
-            //console.timeEnd('analysis');
+            console.timeEnd('analysis');
             const transaction = await this.db.beginTransaction();
             try {
-                //console.time('deleteBills');
+                console.time('deleteBills');
                 await transaction.delete(this.tableName, {tender_id: this.ctx.tender.id});
-                //console.timeEnd('deleteBills');
-                //console.time('deletePos');
+                console.timeEnd('deleteBills');
+                console.time('deletePos');
                 await transaction.delete(this.ctx.service.pos.tableName, {tid: this.ctx.tender.id});
-                //console.timeEnd('deletePos');
-                //console.time('insertBills');
-                await this._importCacheTreeNodes(transaction, cacheTree.items);
-                //console.timeEnd('insertBills');
-                //console.time('insertPos');
+                console.timeEnd('deletePos');
+                console.time('insertBills');
+                //const bills = await this._importCacheTreeNodes(transaction, cacheTree.items);
+                const datas = [];
+                for (const node of cacheTree.items) {
+                    datas.push({
+                        id: node.id,
+                        tender_id: this.ctx.tender.id,
+                        ledger_id: node.ledger_id,
+                        ledger_pid: node.ledger_pid,
+                        level: node.level,
+                        order: node.order,
+                        is_leaf: !node.children || node.children.length === 0,
+                        full_path: node.full_path,
+                        code: node.code,
+                        b_code: node.b_code,
+                        name: node.name,
+                        unit: node.unit,
+                        sgfh_qty: node.sgfh_qty,
+                        sgfh_tp: node.sgfh_tp,
+                        quantity: node.quantity,
+                        unit_price: node.unit_price,
+                        total_price: node.total_price,
+                        dgn_qty1: node.dgn_qty1,
+                        dgn_qty2: node.dgn_qty2,
+                        memo: node.memo,
+                        drawing_code: node.drawing_code,
+                    });
+                }
+                await transaction.insert(this.tableName, datas);
+                console.timeEnd('insertBills');
+                console.time('insertPos');
                 if (cacheTree.pos && cacheTree.pos.length > 0) {
                     await transaction.insert(this.ctx.service.pos.tableName, cacheTree.pos);
                 }
-                //console.timeEnd('insertPos');
+                console.timeEnd('insertPos');
                 await transaction.commit();
                 this.cache.set(cacheKey, cacheTree.items.length + 1, 'EX', this.ctx.app.config.cacheTime);
+                return {bills: datas, pos: cacheTree.pos}
             } catch (err) {
                 await transaction.rollback();
                 if (orgMaxId) {