|
|
@@ -7,6 +7,7 @@
|
|
|
const JV = require('../rpt_component/jpc_value_define');
|
|
|
const $JE = require('../rpt_component/jpc_rte');
|
|
|
|
|
|
+const fs = require('fs');
|
|
|
const fsUtil = require('../../public/js/fsUtil');
|
|
|
const stringUtil = require('../../public/js/stringUtil');
|
|
|
const scMathUtil = require('../../public/js/scMathUtil');
|
|
|
@@ -172,14 +173,14 @@ class Rpt_Data_Extractor {
|
|
|
}
|
|
|
|
|
|
// 装配数据(把收集到的数据,依据报表模板的指示,预处理(如:排序、过滤、合计)及装配到相关指标)
|
|
|
- assembleData(rawDataObj) {
|
|
|
+ assembleData(rawDataObj, baseDir) {
|
|
|
const $PROJECT = { REPORT: {} };
|
|
|
const tpl = this.rptTpl;
|
|
|
this.COMMON.initialize(tpl, rawDataObj);
|
|
|
$PROJECT.COMMON = this.COMMON;
|
|
|
|
|
|
// console.log(rawDataObj);
|
|
|
- setupFunc($PROJECT.REPORT, rawDataObj);
|
|
|
+ setupFunc($PROJECT.REPORT, rawDataObj, baseDir);
|
|
|
|
|
|
if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
|
|
|
for (const preHandle of tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {
|
|
|
@@ -487,10 +488,11 @@ function adjustData(sourceData, adjustCfg) {
|
|
|
}
|
|
|
|
|
|
function sortData(sourceData, sortCfg, prjData) {
|
|
|
- let rst = getActDataArr(sourceData), tempRstArr = [];
|
|
|
- let sortType = sortCfg[JV.PROP_SORT_TYPE];
|
|
|
- let srcData = getActDataArr(sourceData);
|
|
|
- for (let item of srcData) {
|
|
|
+ let rst = getActDataArr(sourceData);
|
|
|
+ const tempRstArr = [];
|
|
|
+ const sortType = sortCfg[JV.PROP_SORT_TYPE];
|
|
|
+ const srcData = getActDataArr(sourceData);
|
|
|
+ for (const item of srcData) {
|
|
|
if (item._doc) {
|
|
|
tempRstArr.push(item._doc);
|
|
|
} else {
|
|
|
@@ -498,10 +500,10 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
}
|
|
|
}
|
|
|
function private_normal_sort(destArr, sortKeys) {
|
|
|
- destArr.sort(function(a, b){
|
|
|
+ destArr.sort(function(a, b) {
|
|
|
let compRst = 0;
|
|
|
- for (let comp of sortKeys) {
|
|
|
- let reverse = (comp.order === 'ascend')?1:(-1);
|
|
|
+ for (const comp of sortKeys) {
|
|
|
+ const reverse = (comp.order === 'ascend') ? 1 : (-1);
|
|
|
//
|
|
|
if (a[comp.key] > b[comp.key]) {
|
|
|
compRst = reverse;
|
|
|
@@ -515,29 +517,30 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
});
|
|
|
}
|
|
|
function private_parent_sort(parentArr, parentKeys, childArr, childKeys) {
|
|
|
- let tmpRst = {}, rst = [];
|
|
|
- for (let pItem of parentArr) {
|
|
|
+ const tmpRst = {};
|
|
|
+ const rst = [];
|
|
|
+ for (const pItem of parentArr) {
|
|
|
let pKey = 'key';
|
|
|
- for (let key of parentKeys) {
|
|
|
+ for (const key of parentKeys) {
|
|
|
pKey += '_' + pItem[key];
|
|
|
}
|
|
|
tmpRst[pKey] = [];
|
|
|
}
|
|
|
- for (let cItem of childArr) {
|
|
|
+ for (const cItem of childArr) {
|
|
|
let cKey = 'key';
|
|
|
- for (let key of childKeys) {
|
|
|
+ for (const key of childKeys) {
|
|
|
cKey += '_' + cItem[key];
|
|
|
}
|
|
|
if (tmpRst[cKey]) {
|
|
|
tmpRst[cKey].push(cItem);
|
|
|
} else {
|
|
|
- //unknown child value! should be filtered!
|
|
|
+ // unknown child value! should be filtered!
|
|
|
}
|
|
|
}
|
|
|
// childArr.splice(0);
|
|
|
- for (let pItem of parentArr) {
|
|
|
+ for (const pItem of parentArr) {
|
|
|
let pKey = 'key';
|
|
|
- for (let key of parentKeys) {
|
|
|
+ for (const key of parentKeys) {
|
|
|
pKey += '_' + pItem[key];
|
|
|
}
|
|
|
rst.push(tmpRst[pKey]);
|
|
|
@@ -549,15 +552,15 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
}
|
|
|
switch (sortType) {
|
|
|
case 'tree':
|
|
|
- let addLevel = true;
|
|
|
+ const addLevel = true;
|
|
|
rst = treeUtil.buildTreeNodeDirectly(tempRstArr, addLevel);
|
|
|
let newTopArr = [];
|
|
|
if ((sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES] && sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].length > 0) ||
|
|
|
(sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES] && sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].length > 0)) {
|
|
|
- let local_check_bills = function(tItem) {
|
|
|
+ const local_check_bills = function(tItem) {
|
|
|
let chkDtl = false;
|
|
|
if (tItem.flags && tItem.flags.length > 0) {
|
|
|
- for (let flagItem of tItem.flags) {
|
|
|
+ for (const flagItem of tItem.flags) {
|
|
|
if (sortCfg[JV.PROP_FILTER_OTHER_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
|
|
|
newTopArr.push(tItem);
|
|
|
chkDtl = true;
|
|
|
@@ -566,15 +569,15 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
}
|
|
|
}
|
|
|
if (!chkDtl && tItem.items && tItem.items.length > 0) {
|
|
|
- for (let dtlItem of tItem.items) {
|
|
|
+ for (const dtlItem of tItem.items) {
|
|
|
local_check_bills(dtlItem);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
- for (let topItem of rst) {
|
|
|
+ for (const topItem of rst) {
|
|
|
let chkTop = false;
|
|
|
if (topItem.flags && topItem.flags.length > 0) {
|
|
|
- for (let flagItem of topItem.flags) {
|
|
|
+ for (const flagItem of topItem.flags) {
|
|
|
if (sortCfg[JV.PROP_FILTER_TOP_BILLS_NODES].indexOf(flagItem.flag) >= 0) {
|
|
|
newTopArr.push(topItem);
|
|
|
chkTop = true;
|
|
|
@@ -589,7 +592,7 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
} else {
|
|
|
newTopArr = rst;
|
|
|
}
|
|
|
- let destArr = [];
|
|
|
+ const destArr = [];
|
|
|
// fsUtil.writeObjToFile(newTopArr, 'D:/GitHome/ConstructionCost/tmp/sortedAndFlattedRstBefore.jsp');
|
|
|
treeUtil.getFlatArray(newTopArr, destArr, true);
|
|
|
// console.log(destArr);
|
|
|
@@ -602,28 +605,28 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
// fsUtil.writeObjToFile(sourceData.data, 'D:/GitHome/ConstructionCost/tmp/normalSortedRst.jsp');
|
|
|
break;
|
|
|
case 'accord_to_parent':
|
|
|
- let pcKey = sortCfg[JV.PROP_PARENT_CHILD_SORT_KEY];
|
|
|
- let parentSrcData = getModuleDataByKey(prjData, pcKey[JV.PROP_PARENT_DATA_KEY]);
|
|
|
+ const pcKey = sortCfg[JV.PROP_PARENT_CHILD_SORT_KEY];
|
|
|
+ const parentSrcData = getModuleDataByKey(prjData, pcKey[JV.PROP_PARENT_DATA_KEY]);
|
|
|
if (parentSrcData) {
|
|
|
- let tempParentArr = [];
|
|
|
- for (let item of getActDataArr(parentSrcData)) {
|
|
|
+ const tempParentArr = [];
|
|
|
+ for (const item of getActDataArr(parentSrcData)) {
|
|
|
if (item._doc) {
|
|
|
tempParentArr.push(item._doc);
|
|
|
} else {
|
|
|
tempParentArr.push(item);
|
|
|
}
|
|
|
}
|
|
|
- let sortedRstArr = private_parent_sort(tempParentArr, pcKey[JV.PROP_PARENT_SORT_KEYS], tempRstArr, pcKey[JV.PROP_CHILD_SORT_KEYS]);
|
|
|
+ const sortedRstArr = private_parent_sort(tempParentArr, pcKey[JV.PROP_PARENT_SORT_KEYS], tempRstArr, pcKey[JV.PROP_CHILD_SORT_KEYS]);
|
|
|
if (sortCfg[JV.PROP_OTHER_SUB_SORT] && sortCfg[JV.PROP_OTHER_SUB_SORT].length > 0) {
|
|
|
- for (let sort of sortCfg[JV.PROP_OTHER_SUB_SORT]) {
|
|
|
+ for (const sort of sortCfg[JV.PROP_OTHER_SUB_SORT]) {
|
|
|
if (sort[JV.PROP_SORT_TYPE] === 'normal') {
|
|
|
- for (let subArr of sortedRstArr) {
|
|
|
+ for (const subArr of sortedRstArr) {
|
|
|
private_normal_sort(subArr, sort[JV.PROP_SORT_KEYS]);
|
|
|
}
|
|
|
} else if (sort[JV.PROP_SORT_TYPE] === 'self_define') {
|
|
|
- for (let subArr of sortedRstArr) {
|
|
|
+ for (const subArr of sortedRstArr) {
|
|
|
// console.log(subArr);
|
|
|
- let selfDefFunc = null;
|
|
|
+ const selfDefFunc = null;
|
|
|
eval('selfDefFunc = ' + sort[JV.PROP_SORT_TYPE_SELF_DEFINE_LOGIC]);
|
|
|
subArr.sort(selfDefFunc);
|
|
|
// console.log(subArr);
|
|
|
@@ -632,8 +635,8 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
}
|
|
|
}
|
|
|
tempRstArr.splice(0);
|
|
|
- for (let item of sortedRstArr) {
|
|
|
- for (let subItem of item) {
|
|
|
+ for (const item of sortedRstArr) {
|
|
|
+ for (const subItem of item) {
|
|
|
tempRstArr.push(subItem);
|
|
|
}
|
|
|
}
|
|
|
@@ -658,9 +661,11 @@ function sortData(sourceData, sortCfg, prjData) {
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
-function setupFunc(obj, ownRawObj) {
|
|
|
+function setupFunc(obj, ownRawObj, baseDir) {
|
|
|
obj.myOwnRawDataObj = ownRawObj;
|
|
|
+ obj.baseDir = baseDir;
|
|
|
obj.getProperty = ext_getProperty;
|
|
|
+ obj.getPicProperty = ext_getPicProperty;
|
|
|
// obj.getPropertyByForeignId = ext_getPropertyByForeignId;
|
|
|
obj.getArrayProperty = ext_getArrayValues;
|
|
|
obj.getBlank = ext_getBlank;
|
|
|
@@ -680,8 +685,8 @@ function assembleFields(fieldList, rstDataArr, $PROJECT) {
|
|
|
} else if (field.Precision.type === 'flexible') {
|
|
|
const vrst = eval(field.Precision.flexibleMapExpression);
|
|
|
if (vrst && vrst.length === 1) {
|
|
|
- field.flexiblePrecisionRefObj =vrst[0];
|
|
|
- vrst.splice(0,1);
|
|
|
+ field.flexiblePrecisionRefObj = vrst[0];
|
|
|
+ vrst.splice(0, 1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -763,6 +768,29 @@ function ext_getProperty(dataKey, propKey) {
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
+function ext_getPicProperty(dataKey, propKey, isPath) {
|
|
|
+ const rst = [];
|
|
|
+ const parentObj = this;
|
|
|
+ const dtObj = parentObj.myOwnRawDataObj[dataKey];
|
|
|
+ if (propKey && dtObj) {
|
|
|
+ const da = getActDataArr(dtObj);
|
|
|
+ for (const dItem of da) {
|
|
|
+ pri_push_property(propKey, dItem, rst);
|
|
|
+ }
|
|
|
+ if (isPath) {
|
|
|
+ for (let picIdx = 0; picIdx < rst.length; picIdx++) {
|
|
|
+ const filePath = parentObj.baseDir + '/app/' + rst[picIdx];
|
|
|
+ // fs.access
|
|
|
+ const bData = fs.readFileSync(filePath);
|
|
|
+ const base64Str = bData.toString('base64');
|
|
|
+ const datauri = 'data:image/png;base64,' + base64Str;
|
|
|
+ rst[picIdx] = datauri;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+}
|
|
|
+
|
|
|
function ext_getArrayValues(dataKey, itemKey) {
|
|
|
const rst = [];
|
|
|
const parentObj = this;
|
|
|
@@ -801,9 +829,19 @@ function ext_getArrayValues(dataKey, itemKey) {
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
-function ext_getBlank(dftVal) {
|
|
|
+function ext_getBlank(dataKey, dftVal) {
|
|
|
const rst = [];
|
|
|
+ const parentObj = this;
|
|
|
+ const dtObj = parentObj.myOwnRawDataObj[dataKey]; // dataKey是有必要的,必须知道是哪个Table
|
|
|
// 计量需要重写
|
|
|
+ if (dtObj) {
|
|
|
+ const dtData = getActDataArr(dtObj);
|
|
|
+ for (let i = 0; i < dtData.length; i++) {
|
|
|
+ if (dftVal !== null && dftVal !== undefined) {
|
|
|
+ rst.push(dftVal)
|
|
|
+ } else rst.push('');
|
|
|
+ }
|
|
|
+ }
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
@@ -837,7 +875,7 @@ function replaceActDataArr(dtObj, newArr) {
|
|
|
|
|
|
function pri_push_property(propKey, doc, rst) {
|
|
|
if (propKey instanceof Array) {
|
|
|
- //备注:这里的key数组表示取value的优先级
|
|
|
+ // 备注:这里的key数组表示取value的优先级
|
|
|
for (let pi = 0; pi < propKey.length; pi++) {
|
|
|
if (doc.hasOwnProperty('property')) {
|
|
|
if (doc['property'].hasOwnProperty(propKey[pi])) {
|
|
|
@@ -848,13 +886,13 @@ function pri_push_property(propKey, doc, rst) {
|
|
|
rst.push(doc[propKey[pi]]);
|
|
|
break;
|
|
|
} else {
|
|
|
- let lenBefore = rst.length;
|
|
|
+ const lenBefore = rst.length;
|
|
|
getDeepProperty(propKey[pi], doc, rst);
|
|
|
if (rst.length === (lenBefore + 1)) {
|
|
|
if (rst[lenBefore] !== null && rst[lenBefore] !== undefined && rst[lenBefore] !== '') {
|
|
|
break;
|
|
|
} else {
|
|
|
- rst.splice(-1, 1); //删除末尾一条数据,给后面留空间
|
|
|
+ rst.splice(-1, 1); // 删除末尾一条数据,给后面留空间
|
|
|
}
|
|
|
}
|
|
|
}
|