|
@@ -156,6 +156,39 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async _getReport(ctx, params) {
|
|
|
+ // console.log('in getReport');
|
|
|
+ // console.log(params);
|
|
|
+ let rptTpl = await ctx.service.rptTpl.getTplById(params.rpt_tpl_id);
|
|
|
+ if (!rptTpl || rptTpl.length !== 1) {
|
|
|
+ throw '获取模板失败';
|
|
|
+ }
|
|
|
+ rptTpl = JSON.parse(rptTpl[0].rpt_content);
|
|
|
+ // console.log('get the template!');
|
|
|
+ const pageRst = await getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
|
|
|
+ // console.log(pageRst);
|
|
|
+ // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
|
|
|
+ const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id); // 新需求中,允许在非审核状态下设置签名
|
|
|
+ const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
|
|
|
+ // console.log('after role stage!');
|
|
|
+ // console.log(roleRel);
|
|
|
+ await encodeSignatureDataUri(roleRel, this.app.baseDir);
|
|
|
+ await encodeDummySignatureDataUri(pageRst, this.app.baseDir);
|
|
|
+ const stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(params.stage_id, params.stage_times);
|
|
|
+ const customSelect = await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id);
|
|
|
+
|
|
|
+ // console.log('encodeSignatureDataUri!');
|
|
|
+ return {
|
|
|
+ data: pageRst,
|
|
|
+ signatureRelInfo: roleRel,
|
|
|
+ stageAudit: stgAudit,
|
|
|
+ debugInfo: ctx.app.config.is_debug ? ctx.debugInfo : null,
|
|
|
+ customDefine: rptTpl[JV.NODE_CUSTOM_DEFINE],
|
|
|
+ stageFlow,
|
|
|
+ customSelect,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取报表数据
|
|
|
*
|
|
@@ -166,25 +199,37 @@ module.exports = app => {
|
|
|
try {
|
|
|
// console.log('in getReport');
|
|
|
const params = JSON.parse(ctx.request.body.params);
|
|
|
- // console.log(params);
|
|
|
- let rptTpl = await ctx.service.rptTpl.getTplById(params.rpt_tpl_id);
|
|
|
- if (!rptTpl || rptTpl.length !== 1) {
|
|
|
- throw '获取模板失败';
|
|
|
- }
|
|
|
- rptTpl = JSON.parse(rptTpl[0].rpt_content);
|
|
|
- // console.log('get the template!');
|
|
|
- const pageRst = await getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
|
|
|
- // console.log(pageRst);
|
|
|
- // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
|
|
|
- const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id); // 新需求中,允许在非审核状态下设置签名
|
|
|
- const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
|
|
|
- // console.log('after role stage!');
|
|
|
- // console.log(roleRel);
|
|
|
- await encodeSignatureDataUri(roleRel, this.app.baseDir);
|
|
|
- await encodeDummySignatureDataUri(pageRst, this.app.baseDir);
|
|
|
- // console.log('encodeSignatureDataUri!');
|
|
|
- ctx.body = { data: pageRst, signatureRelInfo: roleRel, stageAudit: stgAudit, debugInfo: ctx.app.config.is_debug ? ctx.debugInfo : null };
|
|
|
- // ctx.body = { data: { msg: 'test the network' } };
|
|
|
+ ctx.body = await this._getReport(ctx, params);
|
|
|
+ // // console.log(params);
|
|
|
+ // let rptTpl = await ctx.service.rptTpl.getTplById(params.rpt_tpl_id);
|
|
|
+ // if (!rptTpl || rptTpl.length !== 1) {
|
|
|
+ // throw '获取模板失败';
|
|
|
+ // }
|
|
|
+ // rptTpl = JSON.parse(rptTpl[0].rpt_content);
|
|
|
+ // // console.log('get the template!');
|
|
|
+ // const pageRst = await getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
|
|
|
+ // // console.log(pageRst);
|
|
|
+ // // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
|
|
|
+ // const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id); // 新需求中,允许在非审核状态下设置签名
|
|
|
+ // const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
|
|
|
+ // // console.log('after role stage!');
|
|
|
+ // // console.log(roleRel);
|
|
|
+ // await encodeSignatureDataUri(roleRel, this.app.baseDir);
|
|
|
+ // await encodeDummySignatureDataUri(pageRst, this.app.baseDir);
|
|
|
+ // const stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(params.stage_id, params.stage_times);
|
|
|
+ // const customSelect = await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id);
|
|
|
+ //
|
|
|
+ // // console.log('encodeSignatureDataUri!');
|
|
|
+ // ctx.body = {
|
|
|
+ // data: pageRst,
|
|
|
+ // signatureRelInfo: roleRel,
|
|
|
+ // stageAudit: stgAudit,
|
|
|
+ // debugInfo: ctx.app.config.is_debug ? ctx.debugInfo : null,
|
|
|
+ // customDefine: rptTpl[JV.NODE_CUSTOM_DEFINE],
|
|
|
+ // stageFlow,
|
|
|
+ // customSelect,
|
|
|
+ // };
|
|
|
+ // // ctx.body = { data: { msg: 'test the network' } };
|
|
|
ctx.status = 201;
|
|
|
} catch (ex) {
|
|
|
console.log(ex);
|
|
@@ -341,6 +386,30 @@ module.exports = app => {
|
|
|
console.log(e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async setCustomDefine(ctx) {
|
|
|
+ try {
|
|
|
+ const data = JSON.parse(ctx.request.body.data);
|
|
|
+ console.log(data);
|
|
|
+ const filter = {tid: data.tender_id, sid: data.stage_id, 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 (count > 0) {
|
|
|
+ await ctx.service.rptCustomDefine.update(updateData, filter);
|
|
|
+ } else {
|
|
|
+ updateData.tid = data.tender_id;
|
|
|
+ updateData.sid = data.stage_id;
|
|
|
+ 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) {
|
|
|
+ ctx.helper.log(err);
|
|
|
+ ctx.body = this.ajaxErrorBody(err, '保存数据出错');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return ReportController;
|
|
|
};
|
|
@@ -485,13 +554,14 @@ async function getAllPagesCommon(ctx, rptTpl, params, option, outputType, baseDi
|
|
|
}
|
|
|
const dftOption = params.option || JV.PAGING_OPTION_NORMAL;
|
|
|
printCom.initialize(rptTpl);
|
|
|
+ const customDefine = await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id);
|
|
|
// ctx.helper
|
|
|
- printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType);
|
|
|
+ printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType, customDefine);
|
|
|
// console.log(JSON.stringify(rptTpl));
|
|
|
const maxPages = printCom.totalPages;
|
|
|
let pageRst = null;
|
|
|
if (maxPages > 0) {
|
|
|
- pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg);
|
|
|
+ pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg, customDefine);
|
|
|
} else {
|
|
|
pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
|
|
|
}
|
|
@@ -575,13 +645,15 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
|
|
|
const dftOption = params.option || JV.PAGING_OPTION_NORMAL;
|
|
|
|
|
|
printCom.initialize(rptTpl);
|
|
|
+ const customDefine = await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id);
|
|
|
// console.log(rptTpl);
|
|
|
- printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType);
|
|
|
+ printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType, customDefine);
|
|
|
const maxPages = printCom.totalPages;
|
|
|
let pageRst = null;
|
|
|
// console.log(maxPages);
|
|
|
+ const customDefine = await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id);
|
|
|
if (maxPages > 0) {
|
|
|
- pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg);
|
|
|
+ pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg, customDefine);
|
|
|
} else {
|
|
|
pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
|
|
|
}
|