Explorar o código

报表,批量导出问题

MaiXinRong %!s(int64=5) %!d(string=hai) anos
pai
achega
e5e1bb05e3
Modificáronse 2 ficheiros con 33 adicións e 11 borrados
  1. 19 11
      app/controller/report_controller.js
  2. 14 0
      app/extend/helper.js

+ 19 - 11
app/controller/report_controller.js

@@ -638,11 +638,11 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
     try {
         const rptPageRstArray = [];
         // 1. 这里只用一份数据,根据实际应用情况,先备份
-        const backupData = {};
-        for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
-            backupData[filterTables[filterIdx]] = [];
-            Object.assign(backupData[filterTables[filterIdx]], rawDataObj[filterTables[filterIdx]]);
-        }
+        // const backupData = {};
+        // for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
+        //     backupData[filterTables[filterIdx]] = [];
+        //     Object.assign(backupData[filterTables[filterIdx]], rawDataObj[filterTables[filterIdx]]);
+        // }
         // 2. 一个一个模板创建数据
         // let defProperties = await ctx.service.rptPreDefineCfg.getCfgById('Administrator');
         // defProperties = JSON.parse(defProperties[0].defined_content);
@@ -651,6 +651,14 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
             const rptTpl = (rptTpls[tplIdx]._doc) ? rptTpls[tplIdx]._doc : rptTpls[tplIdx];
             rptDataUtil.initialize(rptTpl);
             const customSelect = await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, rptTpl.id);
+
+            // 从汇总的rawDataObj中拷贝所需数据表至curRawDataObj,以供后续使用
+            const curRawDataObj = {};
+            const filter = rptDataUtil.getDataRequestFilter();
+            for (const table of filter.tables) {
+                curRawDataObj[table] = ctx.helper.clone(rawDataObj[table]);
+            }
+
             const tplData = rptDataUtil.assembleData(ctx, rawDataObj, baseDir, null, customSelect);
             const printCom = JpcEx.createNew();
             rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
@@ -673,12 +681,12 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
             }
             rptPageRstArray.push(pageRst);
             // 注意:这里需要把备份数据assign回去!!!
-            if (tplIdx < rptTpls.length - 1) {
-                for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
-                    backupData[filterTables[filterIdx]] = [];
-                    Object.assign(rawDataObj[filterTables[filterIdx]], backupData[filterTables[filterIdx]]);
-                }
-            }
+            // if (tplIdx < rptTpls.length - 1) {
+            //     for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
+            //         backupData[filterTables[filterIdx]] = [];
+            //         Object.assign(rawDataObj[filterTables[filterIdx]], backupData[filterTables[filterIdx]]);
+            //     }
+            // }
         }
         return rptPageRstArray;
     } catch (ex) {

+ 14 - 0
app/extend/helper.js

@@ -941,4 +941,18 @@ module.exports = {
             this.ctx.debugInfo.other.push(data);
         }
     },
+
+    /**
+     * 深拷贝
+     * @param obj
+     * @returns {*}
+     */
+    clone: function (obj) {
+        if (obj === null) return null;
+        var o = obj instanceof Array ? [] : {};
+        for (var i in obj) {
+            o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? this.clone(obj[i]) : obj[i]);
+        }
+        return o;
+    },
 };