Forráskód Böngészése

code sync from yanghu

TonyKang 7 éve
szülő
commit
999d701ebf

+ 41 - 23
modules/reports/controllers/rpt_controller.js

@@ -22,7 +22,7 @@ import rpt_pdf_util from "../util/rpt_pdf_util";
 import rpt_svg_util from "../util/rpt_svg_util";
 import fs from "fs";
 import strUtil from "../../../public/stringUtil";
-import rptDataExtractor from "../util/rpt_construct_data_util";
+import rptDataExtractor from "../util/rpt_yanghu_data_util";
 
 //统一回调函数
 let callback = function(req, res, err, data){
@@ -244,28 +244,34 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, custo
             rptTplDataFacade.prepareProjectData(user_id, prj_id, filter, function (err, msg, rawDataObj) {
                 if (!err) {
                     let buildPageData = function() {
-                        let tplData = rptDataUtil.assembleData(rawDataObj);
-                        let printCom = JpcEx.createNew();
-                        if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
-                        //console.log("orientation: " + (orientation === 'null'));
-                        if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
-                        let defProperties = rptUtil.getReportDefaultCache();
-                        if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
-                        let dftOption = option||JV.PAGING_OPTION_NORMAL;
-                        printCom.initialize(rptTpl);
-                        printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
-                        let maxPages = printCom.totalPages;
-                        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);
-                        } else {
-                            cb('Have errors while on going...', null);
+                        try {
+                            let tplData = rptDataUtil.assembleData(rawDataObj);
+                            let printCom = JpcEx.createNew();
+                            if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
+                            //console.log("orientation: " + (orientation === 'null'));
+                            if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
+                            let defProperties = rptUtil.getReportDefaultCache();
+                            if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
+                            let dftOption = option||JV.PAGING_OPTION_NORMAL;
+                            printCom.initialize(rptTpl);
+                            printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, outputType);
+                            let maxPages = printCom.totalPages;
+                            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);
+                            } else {
+                                cb('Have errors while on going...', null);
+                            }
+                        } catch (ex) {
+                            console.log("报表数据异常: userId " + user_id + ", project id: " + prj_id);
+                            console.log(ex);
+                            cb('Exception occurs while on going...', null);
                         }
                     };
                     //*/
@@ -372,6 +378,18 @@ module.exports = {
             }
         })
     },
+    getMultiReportsEx: function (req, res) {
+        //原则说明:把所有报表模板集中获取,统一filter,只读一次数据!(有空再整)
+        let params = JSON.parse(req.body.params),
+            prj_id = params.prj_id,
+            rpt_ids = params.rpt_ids.split(','),
+            pageSize = params.pageSize,
+            orientation = params.orientation,
+            customizeCfg = params.custCfg,
+            option = params.option;
+        let user_id = req.session.sessionUser.id;
+        let dftOption = option||JV.PAGING_OPTION_NORMAL;
+    },
 
     getReportAllPagesSvg: function (req, res) {
         let params = JSON.parse(req.body.params),

+ 94 - 0
modules/reports/rpt_component/jpc_flow_tab.js

@@ -819,6 +819,87 @@ JpcFlowTabSrv.prototype.createNew = function(){
         }
         return rst;
     };
+    JpcFlowTabResult.combinePageCells = function (rstPageCells, verticalCombinePos, horizonCombinePos) {
+        // let me = this;
+        if (verticalCombinePos.length > 0 || horizonCombinePos.length > 1) {
+            let cacheObj = {vCache:{}, hCache: {}, hCacheStr: []};
+            let removeCellIds = [];
+            for (let vPosArr of verticalCombinePos) {
+                let pStr = "_" + vPosArr[0] + "_" + vPosArr[1];
+                cacheObj.vCache[pStr] = [];
+            }
+            //horizonCombinePos不需要预记
+            for (let idx = 0; idx < rstPageCells.length; idx++) {
+                let cell = rstPageCells[idx];
+                for (let vPosArr of verticalCombinePos) {
+                    if (cell[JV.PROP_AREA][JV.PROP_LEFT] === vPosArr[0] && cell[JV.PROP_AREA][JV.PROP_RIGHT] === vPosArr[1]) {
+                        cacheObj.vCache["_" + vPosArr[0] + "_" + vPosArr[1]].push(idx);
+                    }
+                }
+                for (let hPosArr of horizonCombinePos) {
+                    if (cell[JV.PROP_AREA][JV.PROP_LEFT] === hPosArr[0] && cell[JV.PROP_AREA][JV.PROP_RIGHT] === hPosArr[1]) {
+                        let hpStr = "_" + cell[JV.PROP_AREA][JV.PROP_TOP] + "_" + cell[JV.PROP_AREA][JV.PROP_BOTTOM];
+                        if (cacheObj.hCacheStr.indexOf(hpStr) < 0) {
+                            cacheObj.hCache[hpStr] = [];
+                            cacheObj.hCacheStr.push(hpStr);
+                        }
+                        cacheObj.hCache[hpStr].push(idx);
+                    }
+                }
+            }
+            if (verticalCombinePos.length > 0) {
+                for (let vPosArr of verticalCombinePos) {
+                    let pStr = "_" + vPosArr[0] + "_" + vPosArr[1];
+                    //rstPageCells的结果已经是按顺序排列了,这里不用再排序
+                    if (cacheObj.vCache[pStr] && cacheObj.vCache[pStr].length > 0) {
+                        let preCell = rstPageCells[cacheObj.vCache[pStr][0]];
+                        for (let cIdx = 1; cIdx < cacheObj.vCache[pStr].length; cIdx++) {
+                            if (preCell.Value === "") {
+                                preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
+                            } else {
+                                if (preCell.Value === rstPageCells[cacheObj.vCache[pStr][cIdx]].Value) {
+                                    preCell[JV.PROP_AREA][JV.PROP_BOTTOM] = rstPageCells[cacheObj.vCache[pStr][cIdx]][JV.PROP_AREA][JV.PROP_BOTTOM];
+                                    removeCellIds.push(cacheObj.vCache[pStr][cIdx]);
+                                } else {
+                                    preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if (horizonCombinePos.length > 1) {
+                if (cacheObj.hCacheStr.length > 0) {
+                    for (let hStr of cacheObj.hCacheStr) {
+                        let preCell = rstPageCells[cacheObj.hCache[hStr][0]];
+                        for (let cIdx = 1; cIdx < cacheObj.hCache[hStr].length; cIdx++) {
+                            if (preCell.Value === "") {
+                                preCell = rstPageCells[cacheObj.hCache[hStr][cIdx]];
+                            } else {
+                                if (preCell.Value === rstPageCells[cacheObj.hCache[hStr][cIdx]].Value) {
+                                    if (preCell[JV.PROP_AREA][JV.PROP_RIGHT] < rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_RIGHT]) {
+                                        preCell[JV.PROP_AREA][JV.PROP_RIGHT] = rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_RIGHT];
+                                    } else {
+                                        preCell[JV.PROP_AREA][JV.PROP_LEFT] = rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_LEFT];
+                                    }
+                                    removeCellIds.push(cacheObj.hCache[hStr][cIdx]);
+                                } else {
+                                    preCell = rstPageCells[cacheObj.hCache[hStr][cIdx]];
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if (removeCellIds.length > 0) {
+                //这次真的要排序了
+                removeCellIds.sort(); //默认方式即可
+                for (let idx = removeCellIds.length - 1; idx >= 0; idx--) {
+                    rstPageCells.splice(removeCellIds[idx], 1);
+                }
+            }
+        }
+    };
     JpcFlowTabResult.outputPreviewContent = function(rptTpl, bands, unitFactor, controls, pageStatus, maxRec) {
         let me = this, rst = [];
         let tab = rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT];
@@ -843,6 +924,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
         let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
         let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_CONTENT];
         let tabEx = (rptTpl[JV.NODE_FLOW_INFO_EX])?rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]:null;
+        let verticalCombinePos = [], horizonCombinePos = []; //合并特性用
         let band = bands[tab[JV.PROP_BAND_NAME]];
         if (band) {
             let pageStatus = me.pageStatusLst[page - 1];
@@ -919,6 +1001,17 @@ JpcFlowTabSrv.prototype.createNew = function(){
                                 }
                             }
                         }
+                        if (rowIdx === 0 && tab_field[JV.PROP_COMBINE_TYPE] !== undefined && tab_field[JV.PROP_COMBINE_TYPE] !== null) {
+                            let rstCellItem = rst[rst.length - 1];
+                            let cbfPos = [];
+                            cbfPos.push(rstCellItem[JV.PROP_AREA][JV.PROP_LEFT]);
+                            cbfPos.push(rstCellItem[JV.PROP_AREA][JV.PROP_RIGHT]);
+                            if (tab_field[JV.PROP_COMBINE_TYPE] === 'vertical') {
+                                verticalCombinePos.push(cbfPos);
+                            } else if (tab_field[JV.PROP_COMBINE_TYPE] === 'horizon') {
+                                horizonCombinePos.push(cbfPos);
+                            }
+                        }
                     }
                     if (contentValuesIdx[rowIdx][0] === JV.TYPE_FOLLOW_MODE) {
                         for (let idx_ex = 0; idx_ex < tab_fields_ex.length; idx_ex++) {
@@ -1006,6 +1099,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
         for (let idIdx = eliminateCells.length - 1; idIdx >= 0; idIdx--) {
             rst.splice(eliminateCells[idIdx], 1);
         }
+        me.combinePageCells(rst, verticalCombinePos, horizonCombinePos);
         return rst;
     };
     JpcFlowTabResult.outputColumn = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, multiColIdx) {

+ 15 - 4
modules/reports/util/rpt_excel_util.js

@@ -275,24 +275,35 @@ function writeStyles(stylesObj){
 }
 function writeSharedString(sharedStrList){
     let rst = [];
+    let pri_func_write = function(cellVal) {
+        if (cellVal !== null) {
+            if ((typeof cellVal === 'string') && cellVal.indexOf(' ') === 0) {
+                rst.push('<si><t xml:space="preserve">' + cellVal + '</t></si>');
+            } else {
+                rst.push('<si><t>' + cellVal + '</t></si>');
+            }
+        }
+    };
     if (sharedStrList && sharedStrList.length > 0) {
         rst.push(dftHeadXml + '\r\n');
         rst.push('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="' + sharedStrList.length + '" uniqueCount="' + sharedStrList.length + '">');
         let regExp = new RegExp("<", "gm");
         for (let i = 0; i < sharedStrList.length; i++) {
-            //rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
             if (typeof sharedStrList[i] === 'string') {
                 //转换特殊字符,如 < , 则需要转义一下
                 sharedStrList[i] = sharedStrList[i].replace(regExp, "&lt;");
                 if (sharedStrList[i].indexOf('|') >= 0) {
                     //rst.push('<si><t>' + sharedStrList[i].split('|').join('\r\n') + '</t></si>');
-                    rst.push('<si><t>' + sharedStrList[i].split('|').join('\n') + '</t></si>');
+                    // rst.push('<si><t>' + sharedStrList[i].split('|').join('\n') + '</t></si>');
+                    pri_func_write(sharedStrList[i].split('|').join('\n'));
                 } else {
-                    rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                    // rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                    pri_func_write(sharedStrList[i]);
                 }
                 // rst.push('<si><t>' + sharedStrList[i].replace('|','\r\n') + '</t></si>');
             } else {
-                rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                // rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                pri_func_write(sharedStrList[i]);
             }
         }
         rst.push('</sst>');

+ 1 - 0
public/web/rpt_value_define.js

@@ -120,6 +120,7 @@ const JV = {
     PROP_POSITION: "Position",
     PROP_HIDDEN: "Hidden",
     PROP_IS_SERIAL: "isSerial",
+    PROP_COMBINE_TYPE: "combineType",
     PROP_IS_AUTO_HEIGHT: "isAutoHeight",
     PROP_FONT: "font",
     PROP_CONTROL: "control",