|
|
@@ -22,6 +22,7 @@ const rpt_svg_util = require("../util/rpt_svg_util");
|
|
|
const fs = require("fs");
|
|
|
const strUtil = require("../../../public/stringUtil");
|
|
|
const rptDataExtractor = require("../util/rpt_yanghu_data_util");
|
|
|
+const { output } = require("pdfkit");
|
|
|
|
|
|
//统一回调函数
|
|
|
let callback = function(req, res, err, data){
|
|
|
@@ -34,44 +35,6 @@ let callback = function(req, res, err, data){
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-function getAllPagesCommonOrg(rpt_id, pageSize, option, cb) {
|
|
|
- let rptTpl = null;
|
|
|
- rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
|
|
|
- rptTpl = rst;
|
|
|
- if (rptTpl) {
|
|
|
- if (rptTpl.ID_KEY) {
|
|
|
- return demoTemplateFacade.getDemoData(rptTpl.ID_KEY);
|
|
|
- } else {
|
|
|
- //callback(req, res, 'No report template data were found!', null);
|
|
|
- cb('No report template data were found!', null);
|
|
|
- }
|
|
|
- } else {
|
|
|
- //callback(req, res, 'No report template was found!', null);
|
|
|
- cb('No report template was found!', null);
|
|
|
- }
|
|
|
- }).then(function(tplData){
|
|
|
- if (tplData) {
|
|
|
- let printCom = JpcEx.createNew();
|
|
|
- rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
|
|
|
- let defProperties = rptUtil.getReportDefaultCache();
|
|
|
- let dftOption = option||JV.PAGING_OPTION_NORMAL;
|
|
|
- printCom.initialize(rptTpl);
|
|
|
- printCom.analyzeData(rptTpl, tplData, defProperties, dftOption, JV.OUTPUT_TYPE_NORMAL);
|
|
|
- let maxPages = printCom.totalPages;
|
|
|
- let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
|
|
|
- if (pageRst) {
|
|
|
- cb(null, pageRst);
|
|
|
- } else {
|
|
|
- //callback(req, res, "Have errors while on going...", null);
|
|
|
- cb('Have errors while on going...', null);
|
|
|
- }
|
|
|
- } else {
|
|
|
- //callback(req, res, 'No report data were found!', null);
|
|
|
- cb('No report data were found!', null);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
-}
|
|
|
function setupCustomizeCfg(customizeCfg, rptTpl, defProperties) {
|
|
|
let tmpObj = {};
|
|
|
//1. 字体
|
|
|
@@ -222,118 +185,121 @@ function setupCustomizeCfg(customizeCfg, rptTpl, defProperties) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
- let rptTpl = null;
|
|
|
- rptTplFacade.getRptTemplate(rpt_id).then(function(rst) {
|
|
|
- rptTpl = rst;
|
|
|
- if (rptTpl) {
|
|
|
- let rptDataUtil = new rptDataExtractor();
|
|
|
- rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
- let summaryRst = [];
|
|
|
- let filter = rptDataUtil.getDataRequestFilter(summaryRst);
|
|
|
- let promiseArr = [null, null];
|
|
|
- if (summaryRst.length > 0) {
|
|
|
- if (summaryRst.indexOf(`Construct`) >= 0 || summaryRst.indexOf(`ConstructDetail`) >= 0) {
|
|
|
- promiseArr[0] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.project);
|
|
|
- }
|
|
|
- if (summaryRst.indexOf(`Segment`) >= 0 || summaryRst.indexOf(`SegmentDetail`) >= 0) {
|
|
|
- promiseArr[1] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.engineering);
|
|
|
+
|
|
|
+function _combineData(destData, srcData) {
|
|
|
+ // 备注:这里有一个前提条件,就是基于相同的报表模板
|
|
|
+ for (let idx = 0; idx < destData[JV.DATA_DISCRETE_DATA].length; idx++) {
|
|
|
+ destData[JV.DATA_DISCRETE_DATA][idx] = destData[JV.DATA_DISCRETE_DATA][idx].concat(srcData[JV.DATA_DISCRETE_DATA][idx]);
|
|
|
+ }
|
|
|
+ for (let idx = 0; idx < destData[JV.DATA_MASTER_DATA].length; idx++) {
|
|
|
+ destData[JV.DATA_MASTER_DATA][idx] = destData[JV.DATA_MASTER_DATA][idx].concat(srcData[JV.DATA_MASTER_DATA][idx]);
|
|
|
+ }
|
|
|
+ for (let idx = 0; idx < destData[JV.DATA_MASTER_DATA_EX].length; idx++) {
|
|
|
+ destData[JV.DATA_MASTER_DATA_EX][idx] = destData[JV.DATA_MASTER_DATA_EX][idx].concat(srcData[JV.DATA_MASTER_DATA_EX][idx]);
|
|
|
+ }
|
|
|
+ for (let idx = 0; idx < destData[JV.DATA_DETAIL_DATA].length; idx++) {
|
|
|
+ destData[JV.DATA_DETAIL_DATA][idx] = destData[JV.DATA_DETAIL_DATA][idx].concat(srcData[JV.DATA_DETAIL_DATA][idx]);
|
|
|
+ }
|
|
|
+ for (let idx = 0; idx < destData[JV.DATA_DETAIL_DATA_EX].length; idx++) {
|
|
|
+ destData[JV.DATA_DETAIL_DATA_EX][idx] = destData[JV.DATA_DETAIL_DATA_EX][idx].concat(srcData[JV.DATA_DETAIL_DATA_EX][idx]);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function _createPntPageData(tplData, rptTpl, params, outputType, cb) {
|
|
|
+ try {
|
|
|
+ let printCom = JpcEx.createNew();
|
|
|
+ if (params.pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
|
|
|
+ if (params.orientation && (params.orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = params.orientation;
|
|
|
+ let defProperties = rptUtil.getReportDefaultCache();
|
|
|
+ if (params.custCfg) setupCustomizeCfg(params.custCfg, rptTpl, defProperties);
|
|
|
+ let dftOption = params.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, params.custCfg);
|
|
|
+ } 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("报表数据异常: project id: " + prj_id);
|
|
|
+ console.log(ex.toString());
|
|
|
+ cb('Exception occurs while on going...', null);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function getAllPagesForOneRptCommonEx(user_id, rpt_params, outputType, cb) {
|
|
|
+ //prj_ids, rpt_id, pageSize, orientation, customizeCfg
|
|
|
+ rptTpl = await rptTplFacade.getRptTemplate(rpt_params.rpt_tpl_id);
|
|
|
+ if (rptTpl) {
|
|
|
+ let rptDataUtil = new rptDataExtractor();
|
|
|
+ rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
+ let summaryRst = [];
|
|
|
+ let filter = rptDataUtil.getDataRequestFilter(summaryRst);
|
|
|
+ // 这里不考虑清单汇总及工料机汇总的情况了(有另外的分支处理,不会经过这里)
|
|
|
+ let multiRawData = await rptTplDataFacade.prepareMultiProjectData(user_id, rpt_params.prj_ids, filter);
|
|
|
+ try {
|
|
|
+ if (multiRawData.length > 0) {
|
|
|
+ //考虑到工料机的数据还需要再计算,所以还不能直接用,需要每个工程都处理一遍后,再合并
|
|
|
+ let tplData = rptDataUtil.assembleData(multiRawData[0]);
|
|
|
+ for (let idx = 1; idx < multiRawData.length; idx++) {
|
|
|
+ let tmpData = rptDataUtil.assembleData(multiRawData[idx]);
|
|
|
+ _combineData(tplData, tmpData);
|
|
|
}
|
|
|
+ _createPntPageData(tplData, rptTpl, rpt_params, outputType, cb);
|
|
|
+ } else {
|
|
|
+ cb('Have errors while on going...', null);
|
|
|
}
|
|
|
- rptTplDataFacade.prepareProjectData(user_id, prj_id, filter, function (err, msg, rawDataObj) {
|
|
|
- if (!err) {
|
|
|
- let buildPageData = function() {
|
|
|
- try {
|
|
|
- // fsUtil.writeObjToFile(rawDataObj, `D:/GitHome/YangHuCost/tmp/rawDataObj_${(new Date).getTime()}.jsp`);
|
|
|
- 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;
|
|
|
- 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_${(new Date).getTime()}.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.message);
|
|
|
- cb('Exception occurs while on going...', null);
|
|
|
- }
|
|
|
- };
|
|
|
- //*/
|
|
|
- //取汇总数据流程
|
|
|
- if (promiseArr[0] !== null) {
|
|
|
- promiseArr[0].then(function (rst) {
|
|
|
- rawDataObj.Construct = rst.parent;
|
|
|
- rawDataObj.ConstructDetail = rst.subList;
|
|
|
- if (promiseArr[1] !== null) {
|
|
|
- promiseArr[1].then(function (rst) {
|
|
|
- rawDataObj.Segment = rst.parent;
|
|
|
- rawDataObj.SegmentDetail = rst.subList;
|
|
|
- buildPageData(rawDataObj, rptDataUtil, rptTpl);
|
|
|
- });
|
|
|
- } else {
|
|
|
- buildPageData(rawDataObj, rptDataUtil, rptTpl);
|
|
|
- }
|
|
|
- });
|
|
|
- } else if (promiseArr[1] !== null) {
|
|
|
- promiseArr[1].then(function (rst) {
|
|
|
- rawDataObj.Segment = rst.parent;
|
|
|
- rawDataObj.SegmentDetail = rst.subList;
|
|
|
- buildPageData(rawDataObj, rptDataUtil, rptTpl);
|
|
|
- });
|
|
|
- } else {
|
|
|
- buildPageData(rawDataObj, rptDataUtil, rptTpl);
|
|
|
- }
|
|
|
- /*/
|
|
|
- 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 = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties, customizeCfg);
|
|
|
- if (pageRst) {
|
|
|
- // fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult.jsp");
|
|
|
- cb(null, pageRst);
|
|
|
- } else {
|
|
|
- cb('Have errors while on going...', null);
|
|
|
- }
|
|
|
- //*/
|
|
|
- } else {
|
|
|
- cb('No report data were found!', null);
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- cb('No report template was found!', null);
|
|
|
+ } catch(ex) {
|
|
|
+ //
|
|
|
}
|
|
|
- });
|
|
|
+ } else {
|
|
|
+ cb('No report template was found!', null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
- for (let idx = 0; idx < rpt_ids.length; idx++) {
|
|
|
- rpt_ids[idx] = parseInt(rpt_ids[idx]); //转换一下,以防万一
|
|
|
+async function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
+ let rpt_params = {pageSize: pageSize, orientation: orientation, custCfg: customizeCfg, option: option, prj_ids: [prj_id], rpt_tpl_id: rpt_id};
|
|
|
+ getAllPagesForOneRptCommonEx(user_id, rpt_params, outputType, cb);
|
|
|
+}
|
|
|
+
|
|
|
+async function getMultiRptsCommonEx(user_id, prj_ids_arr, rpt_ids, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
+ function getProjectPageData(rptTpl, prj_ids, multiRawData) {
|
|
|
+ let rpt_params = {pageSize: pageSize, orientation: orientation, custCfg: customizeCfg, option: option, prj_ids: prj_ids};
|
|
|
+ let util = new rptDataExtractor();
|
|
|
+ util.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ if (multiRawData.length > 0) {
|
|
|
+ //考虑到工料机的数据还需要再计算,所以还不能直接用,需要每个工程都处理一遍后,再合并
|
|
|
+ let tplData = util.assembleData(multiRawData[0]);
|
|
|
+ for (let idx = 1; idx < multiRawData.length; idx++) {
|
|
|
+ let tmpData = util.assembleData(multiRawData[idx]);
|
|
|
+ _combineData(tplData, tmpData);
|
|
|
+ }
|
|
|
+ _createPntPageData(tplData, rptTpl, rpt_params, outputType, (err, pageRst)=>{
|
|
|
+ if (err) {
|
|
|
+ return reject('No data were found!');
|
|
|
+ } else {
|
|
|
+ resolve(pageRst);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ return reject('No data were found!');
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- rptTplFacade.getRptTemplates(rpt_ids).then(function(rptTpls) {
|
|
|
- let rptDataUtil = new rptDataExtractor();
|
|
|
+ try {
|
|
|
+ for (let idx = 0; idx < rpt_ids.length; idx++) {
|
|
|
+ rpt_ids[idx] = parseInt(rpt_ids[idx]); //转换一下,以防万一
|
|
|
+ }
|
|
|
+ let rptTpls = await rptTplFacade.getRptTemplates(rpt_ids);
|
|
|
let filters = [];
|
|
|
if (rptTpls.length > 1) {
|
|
|
rptTpls.sort(function (item1, item2){
|
|
|
@@ -342,39 +308,79 @@ function getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, cus
|
|
|
return ID1 - ID2;
|
|
|
});
|
|
|
}
|
|
|
+ let rptDataUtil = new rptDataExtractor();
|
|
|
for (let rptTpl of rptTpls) {
|
|
|
rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
- let filter = rptDataUtil.getDataRequestFilter();
|
|
|
- for (let dtlFilter of filter) {
|
|
|
- if (filters.indexOf(dtlFilter) < 0) {
|
|
|
- filters.push(dtlFilter);
|
|
|
- }
|
|
|
+ filters.push(rptDataUtil.getDataRequestFilter()); // 这里不merge filter了,一个个独立
|
|
|
+ }
|
|
|
+ let parallelFunctions = [];
|
|
|
+ for (let tplIdx = 0; tplIdx < rptTpls.length; tplIdx++) {
|
|
|
+ // 不同的项目ID跟着报表模板走(大部分是只有一个项目,汇总类型的表会有多个)
|
|
|
+ let multiRawData = await rptTplDataFacade.prepareMultiProjectData(user_id, prj_ids_arr[tplIdx], filters[tplIdx]);
|
|
|
+ parallelFunctions.push(getProjectPageData(rptTpls[tplIdx], prj_ids_arr[tplIdx], multiRawData));
|
|
|
+ }
|
|
|
+ let rptPageRstArray = await Promise.all(parallelFunctions);
|
|
|
+ cb(null, rptPageRstArray);
|
|
|
+ } catch (ex) {
|
|
|
+ console.log(ex);
|
|
|
+ cb('Has exception!', null);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
+ for (let idx = 0; idx < rpt_ids.length; idx++) {
|
|
|
+ rpt_ids[idx] = parseInt(rpt_ids[idx]); //转换一下,以防万一
|
|
|
+ }
|
|
|
+ let rptTpls = await rptTplFacade.getRptTemplates(rpt_ids);
|
|
|
+
|
|
|
+ let rptDataUtil = new rptDataExtractor();
|
|
|
+ let filters = [];
|
|
|
+ if (rptTpls.length > 1) {
|
|
|
+ rptTpls.sort(function (item1, item2){
|
|
|
+ let i1 = (item1._doc)?item1._doc:item1, i2 = (item2._doc)?item2._doc:item2;
|
|
|
+ let ID1 = rpt_ids.indexOf(i1[JV.PROP_ID]), ID2 = rpt_ids.indexOf(i2[JV.PROP_ID]);
|
|
|
+ return ID1 - ID2;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ for (let rptTpl of rptTpls) {
|
|
|
+ rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
+ let filter = rptDataUtil.getDataRequestFilter();
|
|
|
+ for (let dtlFilter of filter) {
|
|
|
+ if (filters.indexOf(dtlFilter) < 0) {
|
|
|
+ filters.push(dtlFilter);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ // for (let dtlPrjIds of prj_ids_arr) {
|
|
|
+ if (rptTpls) {
|
|
|
//正常应该根据报表模板定义的数据类型来请求数据
|
|
|
+ // let multiRawData = await rptTplDataFacade.prepareMultiProjectData(user_id, dtlPrjIds, filters);
|
|
|
rptTplDataFacade.prepareProjectData(user_id, prj_id, filters, function (err, msg, rawDataObj) {
|
|
|
if (!err) {
|
|
|
try {
|
|
|
let rptPageRstArray = [];
|
|
|
//1. 这里只用一份数据,根据实际应用情况,只需要保留copy三样数据: bills, ration, ration_glj, projectGLJ
|
|
|
let savedBillsData = [], savedRationData = [], savedGljData = [], savedPrjGljData = [], savedFeeRateData = [];
|
|
|
- for (let dtlData of rawDataObj.prjData) {
|
|
|
- if (dtlData.moduleName === 'bills') {
|
|
|
- // Object.assign(savedBillsData, dtlData.data);
|
|
|
- savedBillsData = JSON.stringify(dtlData.data);
|
|
|
- } else if (dtlData.moduleName === 'ration') {
|
|
|
- // Object.assign(savedRationData, dtlData.data);
|
|
|
- savedRationData = JSON.stringify(dtlData.data);
|
|
|
- } else if (dtlData.moduleName === 'ration_glj') {
|
|
|
- // Object.assign(savedGljData, dtlData.data);
|
|
|
- savedGljData = JSON.stringify(dtlData.data);
|
|
|
- } else if (dtlData.moduleName === 'feeRate') {
|
|
|
- Object.assign(savedFeeRateData, dtlData.data._doc.rates);
|
|
|
- } else if (dtlData.moduleName === 'projectGLJ') {
|
|
|
- // Object.assign(savedPrjGljData, dtlData.data.gljList);
|
|
|
- savedPrjGljData = JSON.stringify(dtlData.data.gljList);
|
|
|
+ if (rpt_ids.length > 1) {
|
|
|
+ for (let dtlData of rawDataObj.prjData) {
|
|
|
+ if (dtlData.moduleName === 'bills') {
|
|
|
+ // Object.assign(savedBillsData, dtlData.data);
|
|
|
+ savedBillsData = JSON.stringify(dtlData.data);
|
|
|
+ } else if (dtlData.moduleName === 'ration') {
|
|
|
+ // Object.assign(savedRationData, dtlData.data);
|
|
|
+ savedRationData = JSON.stringify(dtlData.data);
|
|
|
+ } else if (dtlData.moduleName === 'ration_glj') {
|
|
|
+ // Object.assign(savedGljData, dtlData.data);
|
|
|
+ savedGljData = JSON.stringify(dtlData.data);
|
|
|
+ } else if (dtlData.moduleName === 'feeRate') {
|
|
|
+ Object.assign(savedFeeRateData, dtlData.data._doc.rates);
|
|
|
+ } else if (dtlData.moduleName === 'projectGLJ') {
|
|
|
+ // Object.assign(savedPrjGljData, dtlData.data.gljList);
|
|
|
+ savedPrjGljData = JSON.stringify(dtlData.data.gljList);
|
|
|
+ }
|
|
|
+ // 备注:经测试,feeRate目前只能用assign方式来保存,用JSON方式会报错
|
|
|
}
|
|
|
- // 备注:经测试,feeRate目前只能用assign方式来保存,用JSON方式会报错
|
|
|
}
|
|
|
//2. 一个一个模板创建数据
|
|
|
for (let tplIdx = 0; tplIdx < rptTpls.length; tplIdx++) {
|
|
|
@@ -402,22 +408,24 @@ function getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, cus
|
|
|
}
|
|
|
rptPageRstArray.push(pageRst);
|
|
|
//注意:这里需要把清单、定额、工料机数据assign回去!!!
|
|
|
- for (let dtlData of rawDataObj.prjData) {
|
|
|
- if (dtlData.moduleName === 'bills' && savedBillsData.length > 0) {
|
|
|
- // Object.assign(dtlData.data, savedBillsData);
|
|
|
- dtlData.data = JSON.parse(savedBillsData);
|
|
|
- } else if (dtlData.moduleName === 'ration' && savedRationData.length > 0) {
|
|
|
- // Object.assign(dtlData.data, savedRationData);
|
|
|
- dtlData.data = JSON.parse(savedRationData);
|
|
|
- } else if (dtlData.moduleName === 'ration_glj' && savedGljData.length > 0) {
|
|
|
- // Object.assign(dtlData.data, savedGljData);
|
|
|
- dtlData.data = JSON.parse(savedGljData);
|
|
|
- } else if (dtlData.moduleName === 'feeRate' && savedFeeRateData.length > 0) {
|
|
|
- Object.assign(dtlData.data._doc.rates, savedFeeRateData);
|
|
|
- // 备注:经测试,feeRate目前只能用assign方式来回滚,用JSON方式会报错
|
|
|
- } else if (dtlData.moduleName === 'projectGLJ' && savedPrjGljData.length > 0) {
|
|
|
- // Object.assign(dtlData.data.gljList, savedPrjGljData);
|
|
|
- dtlData.data.gljList = JSON.parse(savedPrjGljData);
|
|
|
+ if (rpt_ids.length > 1) {
|
|
|
+ for (let dtlData of rawDataObj.prjData) {
|
|
|
+ if (dtlData.moduleName === 'bills' && savedBillsData.length > 0) {
|
|
|
+ // Object.assign(dtlData.data, savedBillsData);
|
|
|
+ dtlData.data = JSON.parse(savedBillsData);
|
|
|
+ } else if (dtlData.moduleName === 'ration' && savedRationData.length > 0) {
|
|
|
+ // Object.assign(dtlData.data, savedRationData);
|
|
|
+ dtlData.data = JSON.parse(savedRationData);
|
|
|
+ } else if (dtlData.moduleName === 'ration_glj' && savedGljData.length > 0) {
|
|
|
+ // Object.assign(dtlData.data, savedGljData);
|
|
|
+ dtlData.data = JSON.parse(savedGljData);
|
|
|
+ } else if (dtlData.moduleName === 'feeRate' && savedFeeRateData.length > 0) {
|
|
|
+ Object.assign(dtlData.data._doc.rates, savedFeeRateData);
|
|
|
+ // 备注:经测试,feeRate目前只能用assign方式来回滚,用JSON方式会报错
|
|
|
+ } else if (dtlData.moduleName === 'projectGLJ' && savedPrjGljData.length > 0) {
|
|
|
+ // Object.assign(dtlData.data.gljList, savedPrjGljData);
|
|
|
+ dtlData.data.gljList = JSON.parse(savedPrjGljData);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -432,47 +440,44 @@ function getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, cus
|
|
|
cb('No report data were found!', null);
|
|
|
}
|
|
|
})
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function getBillsSummaryReportPages(req, user_id, prjIds, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
+async function getBillsSummaryReportPages(req, user_id, prjIds, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
let rptTpl = null;
|
|
|
- rptTplDataFacade.getBudgetSummayDatas(prjIds, req.session.sessionUser.id, req.session.sessionCompilation._id, req.session.sessionCompilation.overWriteUrl).then(function(summaryRawDataRst) {
|
|
|
- rptTplFacade.getRptTemplate(rpt_id).then(function(rptTpl) {
|
|
|
- let rptDataUtil = new rptDataExtractor();
|
|
|
- rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
- try {
|
|
|
- let tplData = rptDataUtil.assembleData(summaryRawDataRst);
|
|
|
- // fsUtil.writeObjToFile(summaryRawDataRst, "D:/GitHome/temp/billsSummaryRawDataRstRawData.jsp");
|
|
|
- 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) {
|
|
|
- cb(null, pageRst);
|
|
|
- } else {
|
|
|
- cb('Have errors while on going...', null);
|
|
|
- }
|
|
|
- } catch (ex) {
|
|
|
- console.log("报表数据异常: userId " + user_id + ", project id: " + JSON.stringify(prjIds));
|
|
|
- console.log(ex.message);
|
|
|
- cb('Exception occurs while on going...', null);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
+ let summaryRawDataRst = await rptTplDataFacade.getBudgetSummayDatas(prjIds, req.session.sessionUser.id, req.session.sessionCompilation._id, req.session.sessionCompilation.overWriteUrl);
|
|
|
+ rptTpl = await rptTplFacade.getRptTemplate(rpt_id);
|
|
|
+ let rptDataUtil = new rptDataExtractor();
|
|
|
+ rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
+ try {
|
|
|
+ let tplData = rptDataUtil.assembleData(summaryRawDataRst);
|
|
|
+ // fsUtil.writeObjToFile(summaryRawDataRst, "D:/GitHome/temp/billsSummaryRawDataRstRawData.jsp");
|
|
|
+ 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) {
|
|
|
+ cb(null, pageRst);
|
|
|
+ } else {
|
|
|
+ cb('Have errors while on going...', null);
|
|
|
+ }
|
|
|
+ } catch (ex) {
|
|
|
+ console.log("报表数据异常: userId " + user_id + ", project id: " + JSON.stringify(prjIds));
|
|
|
+ console.log(ex.message);
|
|
|
+ cb('Exception occurs while on going...', null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function getSummaryComboPages(req, user_id, prjIds, billsSummaryRpt_ids, gljSummaryRpt_ids, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
@@ -599,58 +604,14 @@ async function getGljSummaryReportPages(user_id, prjIds, rpt_id, pageSize, orien
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function getGljSummaryReportPages_oldstyle(user_id, prjIds, rpt_id, pageSize, orientation, customizeCfg, option, outputType, cb) {
|
|
|
- let rptTpl = null;
|
|
|
- rptTplDataFacade.getGLJSummayDatas(prjIds).then(function(summaryRawDataRst) {
|
|
|
- rptTplFacade.getRptTemplate(rpt_id).then(function(rptTpl) {
|
|
|
- let rptDataUtil = new rptDataExtractor();
|
|
|
- rptDataUtil.initialize((rptTpl._doc)?rptTpl._doc:rptTpl);
|
|
|
- try {
|
|
|
- // fsUtil.writeObjToFile(summaryRawDataRst, "D:/GitHome/temp/gljSummaryRawDataRstRawData.jsp");
|
|
|
- let tplData = rptDataUtil.assembleData(summaryRawDataRst);
|
|
|
- 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) {
|
|
|
- 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);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
module.exports = {
|
|
|
- getReportAllPages: function (req, res) {
|
|
|
- let params = JSON.parse(req.body.params),
|
|
|
- rpt_id = params.rpt_tpl_id,
|
|
|
- prj_id = params.prj_id,
|
|
|
- pageSize = params.pageSize,
|
|
|
- orientation = params.orientation,
|
|
|
- customizeCfg = params.custCfg
|
|
|
- ;
|
|
|
- // req.session.sessionUser.ssoId
|
|
|
+ getReportAllPages: async function (req, res) {
|
|
|
+ let params = JSON.parse(req.body.params);
|
|
|
let user_id = req.session.sessionUser.id;
|
|
|
- getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
|
|
|
+ if (!params.hasOwnProperty('prj_ids')) {
|
|
|
+ params.prj_ids = [params.prj_id];
|
|
|
+ }
|
|
|
+ getAllPagesForOneRptCommonEx(user_id, params, JV.OUTPUT_TYPE_NORMAL, function (err, pageRst) {
|
|
|
callback(req, res, err, pageRst);
|
|
|
});
|
|
|
},
|
|
|
@@ -659,6 +620,7 @@ module.exports = {
|
|
|
let params = JSON.parse(req.body.params),
|
|
|
prj_id = params.prj_id,
|
|
|
rpt_ids = params.rpt_ids,
|
|
|
+ prj_ids_arr = params.prj_ids_arr,
|
|
|
//--以下是汇总类数据----------
|
|
|
rpt_bill_tpl_ids = params.rpt_bill_tpl_ids,
|
|
|
rpt_glj_tpl_ids = params.rpt_glj_tpl_ids,
|
|
|
@@ -671,7 +633,8 @@ module.exports = {
|
|
|
let user_id = req.session.sessionUser.id;
|
|
|
let dftOption = option||JV.PAGING_OPTION_NORMAL;
|
|
|
if (rpt_ids && rpt_ids.length > 0) {
|
|
|
- getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_PDF, function (err, rptPageRstArray) {
|
|
|
+ getMultiRptsCommonEx(user_id, prj_ids_arr, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_PDF, function (err, rptPageRstArray) {
|
|
|
+ // getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_PDF, function (err, rptPageRstArray) {
|
|
|
if (err) {
|
|
|
callback(req, res, '数据有误', null);
|
|
|
} else {
|
|
|
@@ -691,7 +654,7 @@ module.exports = {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- getBillSummaryReportPages: function (req, res) {
|
|
|
+ getBillSummaryReportPages: async function (req, res) {
|
|
|
let params = JSON.parse(req.body.params),
|
|
|
rpt_id = params.rpt_tpl_id,
|
|
|
prjIds = params.prjIds,
|
|
|
@@ -719,26 +682,12 @@ module.exports = {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- getReportAllPagesSvg: function (req, res) {
|
|
|
- let params = JSON.parse(req.body.params),
|
|
|
- rpt_id = params.rpt_tpl_id,
|
|
|
- prj_id = params.prj_id,
|
|
|
- pageSize = params.pageSize,
|
|
|
- orientation = params.orientation,
|
|
|
- customizeCfg = params.custCfg
|
|
|
- ;
|
|
|
- let user_id = req.session.sessionUser.id;
|
|
|
- getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, null, JV.OUTPUT_TYPE_SVG, function (err, pageRst) {
|
|
|
- let svgRstStrArr = rpt_svg_util.exportSvgStr(pageRst, 0, 0);
|
|
|
- callback(req, res, err, svgRstStrArr);
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
createExcelFilesInOneBookEx: function (req, res) {
|
|
|
//采用了优化策略
|
|
|
let params = JSON.parse(req.body.params),
|
|
|
prj_id = params.prj_id,
|
|
|
rpt_ids = params.rpt_ids,
|
|
|
+ prj_ids_arr = params.prj_ids_arr,
|
|
|
//--以下是汇总类数据----------
|
|
|
rpt_bill_tpl_ids = params.rpt_bill_tpl_ids,
|
|
|
rpt_glj_tpl_ids = params.rpt_glj_tpl_ids,
|
|
|
@@ -753,7 +702,8 @@ module.exports = {
|
|
|
let dftOption = option||JV.PAGING_OPTION_NORMAL;
|
|
|
|
|
|
if (rpt_ids && rpt_ids.length > 0) {
|
|
|
- getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, rptPageRstArray) {
|
|
|
+ getMultiRptsCommonEx(user_id, prj_ids_arr, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_PDF, function (err, rptPageRstArray) {
|
|
|
+ // getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, rptPageRstArray) {
|
|
|
if(err){
|
|
|
console.log('导出Excel错误(生成数据过程错误), userId: ' + user_id + ', prjId' + prj_id);
|
|
|
callback(req, res, '数据有误', null);
|
|
|
@@ -787,6 +737,7 @@ module.exports = {
|
|
|
let params = JSON.parse(req.body.params),
|
|
|
prj_id = params.prj_id,
|
|
|
rpt_ids = params.rpt_ids,
|
|
|
+ prj_ids_arr = params.prj_ids_arr,
|
|
|
//--以下是汇总类数据----------
|
|
|
rpt_bill_tpl_ids = params.rpt_bill_tpl_ids,
|
|
|
rpt_glj_tpl_ids = params.rpt_glj_tpl_ids,
|
|
|
@@ -825,7 +776,8 @@ module.exports = {
|
|
|
});
|
|
|
};
|
|
|
if (rpt_ids && rpt_ids.length > 0) {
|
|
|
- getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, rptPageRstArray) {
|
|
|
+ getMultiRptsCommonEx(user_id, prj_ids_arr, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_PDF, function (err, rptPageRstArray) {
|
|
|
+ // getMultiRptsCommon(user_id, prj_id, rpt_ids, pageSize, orientation, customizeCfg, dftOption, JV.OUTPUT_TYPE_NORMAL, function (err, rptPageRstArray) {
|
|
|
if (err) {
|
|
|
console.log('导出Excel错误(生成数据过程错误), userId: ' + user_id + ', prjId' + prj_id);
|
|
|
callback(req, res, '数据生成错误', null);
|
|
|
@@ -953,6 +905,7 @@ module.exports = {
|
|
|
createPdfFilesEx: function (req, res) {
|
|
|
let params = JSON.parse(req.body.params),
|
|
|
prj_id = params.prj_id,
|
|
|
+ prj_ids_arr = params.prj_ids_arr,
|
|
|
rpt_ids = params.rpt_ids,
|
|
|
rpt_names = params.rpt_names,
|
|
|
//--以下是汇总类数据----------
|