|
@@ -16,6 +16,7 @@ const fsUtil = require('../public/js/fsUtil');
|
|
|
const fs = require('fs');
|
|
|
const rptCronJob = require('../reports/util/rpt_tmp_file_sweep');
|
|
|
const RPT_DEF_PROPERTIES = require('../const/report_defined_properties');
|
|
|
+const reportConst = require('../const/report');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class ReportController extends app.BaseController {
|
|
@@ -59,6 +60,21 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 获取汇总表,历史选择
|
|
|
+ const cid = this.ctx.helper._.map(treeNodes, 'id');
|
|
|
+ const customSelects = {};
|
|
|
+ if (ctx.stage) {
|
|
|
+ customSelects.audit_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
|
|
|
+ reportConst.rptCustomType[JV.NODE_CUS_AUDIT_SELECT], ctx.tender.id, ctx.stage.id);
|
|
|
+ customSelects.stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(
|
|
|
+ params.stage_id, params.stage_times);
|
|
|
+ } else {
|
|
|
+ customSelects.audit_select = [];
|
|
|
+ }
|
|
|
+ customSelects.gather_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
|
|
|
+ reportConst.rptCustomType[JV.NODE_CUS_GATHER_SELECT], ctx.tender.id, -1);
|
|
|
+
|
|
|
+
|
|
|
// const allTpls = await ctx.service.rptTpl.getAllTplByIds(tmpRptIds);
|
|
|
// for (const tpl of allTpls) {
|
|
|
// const fName = tpl.id + '_' + tpl.rpt_tpl_name + '.js';
|
|
@@ -131,6 +147,8 @@ module.exports = app => {
|
|
|
tenderList,
|
|
|
auditConst,
|
|
|
jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.report.main),
|
|
|
+ customSelects,
|
|
|
+ rptCustomType: reportConst.rptCustomType,
|
|
|
};
|
|
|
await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
|
|
|
// await this.layout('report/index.ejs', renderData);
|
|
@@ -278,6 +296,7 @@ module.exports = app => {
|
|
|
async getMultiReportsEx(ctx) {
|
|
|
// 原则说明:把所有报表模板集中获取,统一filter,只读一次数据!
|
|
|
const params = JSON.parse(ctx.request.body.params);
|
|
|
+ await this._saveCustomSelects(params);
|
|
|
const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
|
|
|
const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
|
|
|
// const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
|
|
@@ -295,8 +314,18 @@ module.exports = app => {
|
|
|
ctx.status = 201;
|
|
|
}
|
|
|
|
|
|
+ async _saveCustomSelects(params) {
|
|
|
+ for (const [i, cs] of params.customSelect.entries()) {
|
|
|
+ cs.tender_id = params.tender_id;
|
|
|
+ cs.stage_id = params.stage_id;
|
|
|
+ cs.rpt_tpl_id = params.rpt_ids[i];
|
|
|
+ await this.ctx.service.rptCustomDefine.saveCustomSelect(cs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async createExcelFilesEx(ctx) {
|
|
|
const params = JSON.parse(ctx.request.body.params);
|
|
|
+ await this._saveCustomSelects(params);
|
|
|
const baseDir = this.app.baseDir;
|
|
|
function getExcelByPageData(pageRst, rpt_name, innerRoleRel) {
|
|
|
return new Promise(function(resolve, reject) {
|
|
@@ -417,20 +446,21 @@ module.exports = app => {
|
|
|
async setCustomDefine(ctx) {
|
|
|
try {
|
|
|
const data = JSON.parse(ctx.request.body.data);
|
|
|
- const sid = data.gather_select ? -1 : data.stage_id;
|
|
|
- const filter = {tid: data.tender_id, sid: sid, rid: data.rpt_tpl_id};
|
|
|
- const count = await ctx.service.rptCustomDefine.count(filter);
|
|
|
- const updateData = {};
|
|
|
- if (data.audit_select) updateData.audit_select = JSON.stringify(data.audit_select);
|
|
|
- if (data.gather_select) updateData.gather_select = JSON.stringify(data.gather_select);
|
|
|
- if (count > 0) {
|
|
|
- await ctx.service.rptCustomDefine.update(updateData, filter);
|
|
|
- } else {
|
|
|
- updateData.tid = data.tender_id;
|
|
|
- updateData.sid = sid;
|
|
|
- updateData.rid = data.rpt_tpl_id;
|
|
|
- await ctx.service.rptCustomDefine.db.insert(ctx.service.rptCustomDefine.tableName, updateData);
|
|
|
- }
|
|
|
+ await this.ctx.service.rptCustomDefine.saveCustomSelect(data);
|
|
|
+ // const sid = data.gather_select ? -1 : data.stage_id;
|
|
|
+ // const filter = {tid: data.tender_id, sid: sid, rid: data.rpt_tpl_id};
|
|
|
+ // const count = await ctx.service.rptCustomDefine.count(filter);
|
|
|
+ // const updateData = {};
|
|
|
+ // if (data.audit_select) updateData.audit_select = JSON.stringify(data.audit_select);
|
|
|
+ // if (data.gather_select) updateData.gather_select = JSON.stringify(data.gather_select);
|
|
|
+ // if (count > 0) {
|
|
|
+ // await ctx.service.rptCustomDefine.update(updateData, filter);
|
|
|
+ // } else {
|
|
|
+ // updateData.tid = data.tender_id;
|
|
|
+ // updateData.sid = sid;
|
|
|
+ // updateData.rid = data.rpt_tpl_id;
|
|
|
+ // await ctx.service.rptCustomDefine.db.insert(ctx.service.rptCustomDefine.tableName, updateData);
|
|
|
+ // }
|
|
|
const result = await this._getReport(ctx, data);
|
|
|
ctx.body = {err: 0, msg: '', data: result};
|
|
|
} catch (err) {
|
|
@@ -606,6 +636,8 @@ async function getAllPagesCommon(ctx, rptTpl, params, option, outputType, baseDi
|
|
|
}
|
|
|
|
|
|
async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
|
|
|
+ const needCustomTables = ['mem_gather_stage_bills', 'mem_gather_deal_bills', 'mem_gather_stage_pay', 'mem_gather_tender_info'];
|
|
|
+
|
|
|
for (let idx = 0; idx < params.rpt_ids.length; idx++) {
|
|
|
params.rpt_ids[idx] = parseInt(params.rpt_ids[idx]); // 转换一下,以防万一
|
|
|
}
|
|
@@ -635,12 +667,13 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
|
|
|
const filter = rptDataUtil.getDataRequestFilter();
|
|
|
// console.log(filter);
|
|
|
for (const table of filter.tables) {
|
|
|
- if (filterTables.indexOf(table) < 0) {
|
|
|
+ if (filterTables.indexOf(table) < 0 && needCustomTables.indexOf(table) < 0) {
|
|
|
filterTables.push(table);
|
|
|
}
|
|
|
// memFieldKeys[table] = [];
|
|
|
}
|
|
|
for (const tableKeyProp in filter.memFieldKeys) {
|
|
|
+ if (needCustomTables.indexOf(tableKeyProp) >= 0) continue;
|
|
|
if (!memFieldKeys.hasOwnProperty(tableKeyProp)) {
|
|
|
memFieldKeys[tableKeyProp] = [];
|
|
|
}
|
|
@@ -652,7 +685,7 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const rawDataObj = await ctx.service.report.getReportData(params, filterTables, memFieldKeys);
|
|
|
+ const rawDataObj = await ctx.service.report.getReportData(params, filterTables, memFieldKeys, {}, {});
|
|
|
try {
|
|
|
const rptPageRstArray = [];
|
|
|
// 1. 这里只用一份数据,根据实际应用情况,先备份
|
|
@@ -668,7 +701,9 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
|
|
|
for (let tplIdx = 0; tplIdx < rptTpls.length; tplIdx++) {
|
|
|
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);
|
|
|
+ const customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
|
|
|
+ ? await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, rptTpl.id)
|
|
|
+ : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, rptTpl.id);
|
|
|
|
|
|
// 从汇总的rawDataObj中拷贝所需数据表至curRawDataObj,以供后续使用
|
|
|
const curRawDataObj = {};
|
|
@@ -676,6 +711,34 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
|
|
|
for (const table of filter.tables) {
|
|
|
curRawDataObj[table] = ctx.helper.clone(rawDataObj[table]);
|
|
|
}
|
|
|
+ // 如果是用户交互类型的表,则应该单独获取数据
|
|
|
+ if (params.customSelect && params.customSelect[tplIdx]) {
|
|
|
+ const cfTables = [], cmFieldKeys = [];
|
|
|
+ const curFilter = rptDataUtil.getDataRequestFilter();
|
|
|
+ for (const table of curFilter.tables) {
|
|
|
+ if (needCustomTables.indexOf(table) >= 0) {
|
|
|
+ cfTables.push(table);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (const tableKeyProp in filter.memFieldKeys) {
|
|
|
+ if (needCustomTables.indexOf(tableKeyProp) < 0) continue;
|
|
|
+ if (!cmFieldKeys.hasOwnProperty(tableKeyProp)) {
|
|
|
+ cmFieldKeys[tableKeyProp] = [];
|
|
|
+ }
|
|
|
+ for (const mfKey of filter.memFieldKeys[tableKeyProp]) {
|
|
|
+ if (cmFieldKeys[tableKeyProp].indexOf(mfKey) < 0) {
|
|
|
+ cmFieldKeys[tableKeyProp].push(mfKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(customSelect);
|
|
|
+ const customRawDataObj = await ctx.service.report.getReportData(params, cfTables, cmFieldKeys,
|
|
|
+ rptTpl[JV.NODE_CUSTOM_DEFINE], customSelect);
|
|
|
+ console.log(customRawDataObj);
|
|
|
+ for (const prop in customRawDataObj) {
|
|
|
+ curRawDataObj[prop] = customRawDataObj[prop];
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
const tplData = rptDataUtil.assembleData(ctx, curRawDataObj, baseDir, null, customSelect);
|
|
|
const printCom = JpcEx.createNew();
|