Ver código fonte

BUG1875(清单断链) + 处理空数据报表(返回preview page)

TonyKang 7 anos atrás
pai
commit
4dc7d07975

+ 6 - 1
modules/reports/controllers/rpt_controller.js

@@ -255,7 +255,12 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, custo
                         printCom.initialize(rptTpl);
                         printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
                         let maxPages = printCom.totalPages;
-                        let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
+                        let pageRst = null;
+                        if (maxPages > 0) {
+                            pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
+                        } else {
+                            pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
+                        }
                         if (pageRst) {
                             // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
                             cb(null, pageRst);

+ 39 - 1
public/web/treeDataHelper.js

@@ -18,7 +18,7 @@ let tree_Data_Helper = {
             return tmpNodeRst;
         };
         let private_buildNodeData = function(parentItem, idArr, treeLevel, tbID) {
-            let iter = [], nextNode = private_getStartNode(idArr);
+            let iter = [], nextNode = private_getStartNode(idArr), pushedIds = [];
             while (nextNode !== null && nextNode !== undefined ) {
                 if (parentItem) {
                     parentItem[CHILDREN_NODE].push(nextNode);
@@ -26,6 +26,7 @@ let tree_Data_Helper = {
                     rst.push(nextNode);
                 }
                 iter.push(nextNode);
+                pushedIds.push(nextNode[NODE_ID]);
                 nextNode[TOP_BILL_ID] = tbID;
                 if (parentItem === null) {
                     nextNode[TOP_BILL_ID] = nextNode[NODE_ID];
@@ -40,7 +41,44 @@ let tree_Data_Helper = {
                 }
                 if (addLevel) nextNode[TREE_LEVEL] = treeLevel;
                 nextNode = tmpNodes[prefix + nextNode[NEXT_ID]];
+                if (nextNode === null || nextNode === undefined) {
+                    //备注: 考虑到实际数据的健壮性,有些节点会掉链子,需要用 parentItem[SUB_ID] 比对已经加上的节点,如发现加上的节点数量不够,那就得在这里补充上去
+                    if (parentItem) {
+                        if (parentItem[SUB_ID].length > iter.length) {
+                            for (let subId of parentItem[SUB_ID]) {
+                                if (pushedIds.indexOf(subId) < 0) {
+                                    let restNode = tmpNodes[prefix + subId];
+                                    if (addLevel) restNode[TREE_LEVEL] = treeLevel;
+                                    restNode[TOP_BILL_ID] = tbID;
+                                    parentItem[CHILDREN_NODE].push(restNode);
+                                    iter.push(restNode);
+                                }
+                            }
+                        }
+                    } else {
+                        if (idArr.length > iter.length) {
+                            for (let topId of idArr) {
+                                if (pushedIds.indexOf(topId) < 0) {
+                                    let restNode = tmpNodes[prefix + topId];
+                                    if (addLevel) restNode[TREE_LEVEL] = treeLevel;
+                                    restNode[TOP_BILL_ID] = restNode[NODE_ID];
+                                    if (restNode.flags && restNode.flags.length > 0) {
+                                        for (let flag of restNode.flags) {
+                                            if (flag.fieldName === "fixed") {
+                                                restNode[TOP_BILL_ID] = flag.flag;
+                                                break;
+                                            }
+                                        }
+                                    }
+                                    rst.push(restNode);
+                                    iter.push(restNode);
+                                }
+                            }
+                        }
+                    }
+                }
             }
+            pushedIds = [];
             for (let i = 0; i < iter.length; i++) {
                 let rtbID = tbID;
                 if (parentItem === null) {

+ 2 - 2
test/unit/reports/test_tpl_09.js

@@ -25,10 +25,10 @@ cfgCacheUtil.setupDftCache();
 let fsUtil = require("../../../public/fsUtil");
 
 let demoPrjId = - 1;
-let demoRptId = 232, pagesize = "A4";
+let demoRptId = 444, pagesize = "A4";
 
 // demoPrjId = 720; //QA: DW3
-demoPrjId = 2260; //QA:
+demoPrjId = 4563; //QA:
 //*/
 // let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了
 let userId_Leng = "5acac1e885bf55000bd055ba";

+ 4 - 1
web/building_saas/report/js/jpc_output.js

@@ -376,7 +376,10 @@ let JpcCanvasOutput = {
         ctx.fillRect(10 + me.offsetX,size[1] + me.offsetY,size[0],10);
     },
     getReportSizeInPixel: function(rptTpl, resolution) {
-        let rst = rptTpl[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
+        let rst = [8.27, 11.69];
+        if (rptTpl && rptTpl[JV.NODE_PAGE_INFO] && rptTpl[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE]) {
+            rst = rptTpl[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
+        }
         rst[0] = Math.round(resolution[0] * rst[0]);
         rst[1] = Math.round(resolution[0] * rst[1]);
         return rst;

+ 7 - 3
web/building_saas/report/js/rpt_main.js

@@ -258,10 +258,11 @@ let zTreeOprObj = {
         hintBox.waitBox();
         CommonAjax.postEx("report_api/getReport", params, 15000, true,
             function(result){
+                hintBox.unWaitBox();
                 let pageRst = result;
-                if (pageRst) {
+                let canvas = document.getElementById("rptCanvas");
+                if (pageRst && pageRst.items && pageRst.items.length > 0) {
                     me.resetAfter(pageRst);
-                    let canvas = document.getElementById("rptCanvas");
                     me.currentRptPageRst = pageRst;
                     me.maxPages = pageRst.items.length;
                     me.currentPage = 1;
@@ -274,7 +275,10 @@ let zTreeOprObj = {
                         canvas.height = size[1] + 50;
                     }
                     me.showPage(1, canvas);
-                    hintBox.unWaitBox();
+                } else {
+                    //返回了无数据表
+                    JpcCanvasOutput.cleanCanvas(canvas);
+                    JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
                 }
             }, function(err){
                 hintBox.unWaitBox();