| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542 | 
							- 'use strict';
 
- /**
 
-  * Created by Tony on 2019/7/5.
 
-  */
 
- const tenderMenu = require('../../config/menu').tenderMenu;
 
- const measureType = require('../const/tender').measureType;
 
- const auditConst = require('../const/audit');
 
- const shenpiConst = require('../const/shenpi');
 
- const accountGroup = require('../const/account_group').group;
 
- const JpcEx = require('../reports/rpt_component/jpc_ex');
 
- const JV = require('../reports/rpt_component/jpc_value_define');
 
- const rpt_xl_util = require('../reports/util/rpt_excel_util');
 
- const rptDataExtractor = require('../reports/util/rpt_calculation_data_util');
 
- 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');
 
- const advanceConst = require('../const/advance');
 
- // const stringUtil = require('../public/js/string_util_light');
 
- const needCustomTables = [
 
-     'mem_custom_select',
 
-     'mem_gather_stage_bills', 'mem_gather_deal_bills', 'mem_gather_stage_pay', 'mem_gather_tender_info',
 
-     'mem_stage_sum_bills', 'mem_stage_sum_pay',
 
-     'mem_jh_gather_im_change', 'mem_jh_im_change', 'mem_jh_gather_stage_bills_compare',
 
-     'mem_material_sum_gl',
 
- ];
 
- const PermissionCheck = require('../const/account_permission').PermissionCheck;
 
- const STD_COMP_STAMP_SIZE_WIDTH = Math.round(5 * 96 / 2.54); // 公章标准尺寸(宽4.2厘米)转成像素
 
- const STD_COMP_STAMP_SIZE_HEIGHT = STD_COMP_STAMP_SIZE_WIDTH; // 公章标准尺寸(高4.2厘米)转成像素
 
- const NORMAL_SIGN_STR = 'normal_sign';
 
- const COMPANY_SIGN_STR = 'company_stamp';
 
- const PRIVATE_SIGN_STR = 'private_stamp';
 
- module.exports = app => {
 
-     class ReportController extends app.BaseController {
 
-         /**
 
-          * 获取审批界面所需的 原报、审批人数据等
 
-          * @param {Object} ctx - egg全局context
 
-          * @return {void}
 
-          * @private
 
-          */
 
-         async _getStageAuditViewData(ctx) {
 
-             if (!ctx.stage) return;
 
-             const times = ctx.stage.status === auditConst.stage.status.checkNo ? ctx.stage.times - 1 : ctx.stage.times;
 
-             ctx.stage.user = await ctx.service.projectAccount.getAccountInfoById(ctx.stage.user_id);
 
-             ctx.stage.auditHistory = [];
 
-             if (times >= 1) {
 
-                 for (let i = 1; i <= times; i++) {
 
-                     ctx.stage.auditHistory.push(await ctx.service.stageAudit.getAuditors(ctx.stage.id, i));
 
-                 }
 
-             }
 
-             // 获取审批流程中左边列表
 
-             ctx.stage.auditors2 = await ctx.service.stageAudit.getAuditGroupByListWithOwner(ctx.stage.id, times);
 
-             if (ctx.stage.status === auditConst.stage.status.uncheck || ctx.stage.status === auditConst.stage.status.checkNo) {
 
-                 ctx.stage.auditorList = await ctx.service.stageAudit.getAuditors(ctx.stage.id, ctx.stage.times);
 
-             }
 
-         }
 
-         async _chkIfStageAuditor(ctx, stage) {
 
-             //
 
-         }
 
-         async _filterStageList(ctx, stageList) {
 
-             //
 
-             // throw
 
-         }
 
-         /**
 
-          * 报表显示页面
 
-          *
 
-          * @param {Object} ctx - egg全局context
 
-          * @return {void}
 
-          */
 
-         async index(ctx) {
 
-             try {
 
-                 await this._getStageAuditViewData(ctx);
 
-                 const pageShow = ctx.session.sessionProject.page_show;
 
-                 pageShow.showArchive = 1;
 
-                 const tender = ctx.tender;
 
-                 const stage = ctx.stage;
 
-                 let stage_id = -1;
 
-                 let stage_order = -1;
 
-                 let sorder = -1;
 
-                 let stage_times = -1;
 
-                 let stage_status = -1;
 
-                 const treeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1, tender.data.project_id]);
 
-                 const filterNames = ['01.支付审批报表'];
 
-                 if (treeNodes && treeNodes.length > 0) {
 
-                     for (let tIdx = treeNodes.length - 1; tIdx >= 0; tIdx--) {
 
-                         if (filterNames.includes(treeNodes[tIdx].name)) {
 
-                             treeNodes.splice(tIdx, 1);
 
-                         }
 
-                     }
 
-                 }
 
-                 const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
 
-                 const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
 
-                 const stageList = await ctx.service.stage.getValidStagesShort(tender.id);
 
-                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.data.project_id } }); // 找公司章用的
 
-                 const isAdmin = ctx.session.sessionUser.is_admin;
 
-                 // console.log('this.ctx.session.sessionUser.accountId: ' + this.ctx.session.sessionUser.accountId);
 
-                 if (stage && stage.status === auditConst.stage.status.uncheck) {
 
-                     // 得判断账号是否在审核人列表中(不含原报)
 
-                     if (stage.auditorList === undefined || stage.auditorList === null) {
 
-                         stage.auditorList = await ctx.service.stageAudit.getAuditors(ctx.stage.id, ctx.stage.times);
 
-                     }
 
-                     let isAudit = false;
 
-                     for (const audit of stage.auditorList) {
 
-                         if (audit.aid === this.ctx.session.sessionUser.accountId) {
 
-                             isAudit = true;
 
-                             break;
 
-                         }
 
-                     }
 
-                     if (isAudit) {
 
-                         throw '未上报!';
 
-                     }
 
-                 } else {
 
-                     // 剔除未上报期(审核人(非原报人)才需要判断)
 
-                     for (let idx = stageList.length - 1; idx >= 0; idx--) {
 
-                         if (stageList[idx].status === auditConst.stage.status.uncheck) {
 
-                             if (stageList[idx].auditorList === undefined || stageList[idx].auditorList === null) {
 
-                                 stageList[idx].auditorList = await ctx.service.stageAudit.getAuditors(stageList[idx].id, stageList[idx].times);
 
-                             }
 
-                             let isAudit = false;
 
-                             for (const audit of stageList[idx].auditorList) {
 
-                                 if (audit.aid === this.ctx.session.sessionUser.accountId) {
 
-                                     isAudit = true;
 
-                                     break;
 
-                                 }
 
-                             }
 
-                             if (isAudit) {
 
-                                 stageList.splice(idx, 1);
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 let lastAuditor = null;
 
-                 if (stage) {
 
-                     lastAuditor = await ctx.service.stageAudit.getLastestAuditor(ctx.stage.id, ctx.stage.times, auditConst.stage.status.checked);
 
-                 } else {
 
-                     lastAuditor = stageList.length > 0 ? await ctx.service.stageAudit.getLastestAuditor(stageList[stageList.length - 1].id, stageList[stageList.length - 1].times, auditConst.stage.status.checked) : null;
 
-                 }
 
-                 let archiveList = [];
 
-                 if (stage) {
 
-                     const archives = await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, ctx.stage.id);
 
-                     if (archives.length > 0) {
 
-                         archiveList = JSON.parse(archives[0].content);
 
-                     }
 
-                 } else {
 
-                     const archives = stageList.length > 0 ? await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, stageList[stageList.length - 1].id) : [];
 
-                     // console.log(archives);
 
-                     if (archives && archives.length > 0) {
 
-                         archiveList = JSON.parse(archives[0].content);
 
-                     }
 
-                 }
 
-                 // const archiveList = await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, ctx.stage.id);
 
-                 let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(tender.data.project_id);
 
-                 const roleList = await ctx.service.signatureRole.getSignatureRolesByTenderId(tender.id);
 
-                 const usedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(tender.id);
 
-                 // ctx.session.sessionUser.is_admin
 
-                 // const pageShow = ctx.session.sessionProject.page_show;
 
-                 // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
 
-                 if (!ctx.session.sessionUser.is_admin && pageShow.individualSign === 1) {
 
-                     // 削减其他account
 
-                     const newAccList = [];
 
-                     for (const acc of prjAccList) {
 
-                         if (acc.id === this.ctx.session.sessionUser.accountId) {
 
-                             newAccList.push(acc);
 
-                         }
 
-                     }
 
-                     prjAccList = newAccList;
 
-                 }
 
-                 // 分类列表
 
-                 const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
 
-                 // 获取用户权限
 
-                 const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
 
-                 const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
 
-                 // 获取用户可查看的标段
 
-                 const tenderList = await this.ctx.service.tender.getList('', userPermission);
 
-                 for (const t of tenderList) {
 
-                     if (t.ledger_status === auditConst.ledger.status.checked) {
 
-                         t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
 
-                         // if (t.lastStage) {
 
-                         //     await this.ctx.service.stage.checkStageGatherData(t.lastStage, this.ctx.session.sessionUser.is_admin);
 
-                         // }
 
-                     }
 
-                 }
 
-                 // 获取汇总表,历史选择
 
-                 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(
 
-                         ctx.stage.stage_id, ctx.stage.stage_times);
 
-                     customSelects.stageFlow.forEach(x => {
 
-                         if (!x) return;
 
-                         x.visible = (!ctx.session.sessionUser.is_admin && ctx.session.sessionProject.page_show.individualSign === 1)
 
-                             ? x.aid === ctx.session.sessionUser.accountId : true;
 
-                     });
 
-                 } else {
 
-                     customSelects.audit_select = [];
 
-                 }
 
-                 customSelects.gather_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
 
-                     reportConst.rptCustomType[JV.NODE_CUS_GATHER_SELECT], ctx.tender.id, -1);
 
-                 customSelects.stage_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
 
-                     reportConst.rptCustomType[JV.NODE_CUS_STAGE_SELECT], ctx.tender.id, -1);
 
-                 customSelects.change_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
 
-                     reportConst.rptCustomType[JV.NODE_CUS_CHANGE_SELECT], ctx.tender.id, -1);
 
-                 customSelects.material_sum_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
 
-                     reportConst.rptCustomType[JV.NODE_CUS_MATERIAL_SUM_SELECT], ctx.tender.id, -1);
 
-                 const dataSelects = {};
 
-                 dataSelects.material_select = await ctx.service.rptCustomDefine.getDataSelectByRpt(cid,
 
-                     reportConst.rptDataType[JV.NODE_CUS_MATERIAL_SELECT]);
 
-                 const materialList = await ctx.service.material.getValidMaterials(ctx.tender.id);
 
-                 // const allTpls = await ctx.service.rptTpl.getAllTplByIds(tmpRptIds);
 
-                 // for (const tpl of allTpls) {
 
-                 //     const fName = tpl.id + '_' + tpl.rpt_tpl_name + '.js';
 
-                 //     console.log('fName: ' + fName);
 
-                 //     fsUtil.writeObjToFile(tpl, 'D:/Temp/计量临时/' + fName);
 
-                 // }
 
-                 // 完成历史任务,下一批
 
-                 // const filePath = 'D:/Temp/计量临时/';
 
-                 // const tplFiles = [];
 
-                 // fs.readdir(filePath, (err, files) => {
 
-                 //     if (err) throw err;
 
-                 //     files.forEach(file => {
 
-                 //         const fPath = filePath + file;
 
-                 //         // console.log('\'' + fPath + '\'');
 
-                 //         tplFiles.push(fPath);
 
-                 //     });
 
-                 // });
 
-                 //
 
-                 // setTimeout(function() {
 
-                 //     console.log(tplFiles);
 
-                 // }, 2000);
 
-                 // 下一批
 
-                 // let cnt = 0;
 
-                 // for (const file of rptFiles) {
 
-                 //     const tplObj = JSON.parse(fs.readFileSync(file, 'utf-8'));
 
-                 //     const rst = await ctx.service.rptTpl.insertRptTpl(tplObj);
 
-                 //     cnt++;
 
-                 //     console.log(file);
 
-                 // }
 
-                 // console.log(cnt + ' 完成!');
 
-                 // console.log(maxStageAmt[0].maxAmt);
 
-                 // 备注:在报表界面初始化的时候,暂时不需要check stage,只有在点中某张表的时候才需要(签名交互需要)
 
-                 // if ((stage === null || stage === undefined) && stageList.length > 0) {
 
-                 //     await ctx.service.stage.checkStage(stageList[stageList.length - 1].id);
 
-                 //     stage = ctx.stage;
 
-                 //     console.log(stage);
 
-                 // }
 
-                 if (stage !== null && stage !== undefined) {
 
-                     stage_id = stage.id;
 
-                     stage_order = stage.order;
 
-                     sorder = stage.curOrder;
 
-                     stage_times = stage.times;
 
-                     stage_status = stage.status;
 
-                 }
 
-                 for (const prjAcc of prjAccList) {
 
-                     prjAcc.account_group = accountGroup[prjAcc.account_group];
 
-                 }
 
-                 let rpt_tpl_items = '{ customize: [], common: [] }';
 
-                 if (custTreeNodes.length > 0) {
 
-                     rpt_tpl_items = custTreeNodes[0].rpt_tpl_items;
 
-                 }
 
-                 // 获取所有项目参与者
 
-                 const accountList = await ctx.service.projectAccount.getAllDataByCondition({
 
-                     where: { project_id: ctx.session.sessionProject.id, enable: 1 },
 
-                     columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
 
-                 });
 
-                 const newAccountGroup = accountGroup.map((item, idx) => {
 
-                     const groupList = accountList.filter(item => item.account_group === idx);
 
-                     return { groupName: item, groupList };
 
-                 });
 
-                 const where = { tid: this.ctx.tender.id };
 
-                 const advance = await ctx.service.advance.getAllDataByCondition({
 
-                     columns: ['id', 'order', 'status', 'selected', 'type'],
 
-                     where,
 
-                     orders: [['type', 'asc'], ['create_time', 'desc']],
 
-                 });
 
-                 advance.forEach(x => {
 
-                     x.statusStr = auditConst.advance.statusString[x.status];
 
-                     x.typeStr = advanceConst.typeColMap[x.type].text;
 
-                 });
 
-                 const renderData = {
 
-                     accountGroup: newAccountGroup,
 
-                     accountList,
 
-                     unitList: JSON.stringify(unitList),
 
-                     tender: tender.data,
 
-                     tenderInfo: tender.info,
 
-                     rpt_tpl_data: JSON.stringify(treeNodes),
 
-                     cust_tpl_data: rpt_tpl_items,
 
-                     cust_cfg: JSON.stringify(custCfg),
 
-                     project_id: tender.data.project_id,
 
-                     tender_id: tender.id,
 
-                     tender_name: tender.data.name,
 
-                     stg_id: stage_id,
 
-                     stg_order: stage_order,
 
-                     cur_order: sorder,
 
-                     stg_times: stage_times,
 
-                     stg_status: stage_status,
 
-                     stage_list: JSON.stringify(stageList),
 
-                     prj_account_list: JSON.stringify(prjAccList),
 
-                     role_list: JSON.stringify(roleList),
 
-                     used_list: JSON.stringify(usedList),
 
-                     tenderMenu,
 
-                     preUrl: '/tender/' + ctx.tender.id + '/measure/stage/' + ctx.params.order,
 
-                     measureType,
 
-                     categoryData,
 
-                     tenderList,
 
-                     auditConst: auditConst.stage,
 
-                     ledgerAuditConst: auditConst.ledger,
 
-                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.report.main),
 
-                     customSelects,
 
-                     rptCustomType: reportConst.rptCustomType,
 
-                     materialList,
 
-                     stages: stageList,
 
-                     dataSelects,
 
-                     // pageShow: JSON.stringify(pageShow),
 
-                     pageShow,
 
-                     authMobile: accountInfo.auth_mobile,
 
-                     shenpiConst,
 
-                     archiveList,
 
-                     lastAuditor,
 
-                     rpt_id: ctx.query.rpt_id,
 
-                     isAdmin,
 
-                     prePay: JSON.stringify(advance),
 
-                     OSS_PATH: ctx.app.config.fujianOssPath,
 
-                     viewPmData: PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission),
 
-                 };
 
-                 await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
 
-                 // await this.layout('report/index.ejs', renderData);
 
-                 // 在这里启动一个cron job,删除临时创建的excel文件
 
-                 if (!rptCronJob.started) {
 
-                     try {
 
-                         // console.log('rptCronJob.started: ' + rptCronJob.started);
 
-                         rptCronJob.started = true;
 
-                         // console.log('this.app.baseDir: ' + this.app.baseDir);
 
-                         rptCronJob.createJob(null, this.app.baseDir + '/app/public/download');
 
-                     } catch (ex) {
 
-                         rptCronJob.started = false;
 
-                     }
 
-                 }
 
-             } catch (err) {
 
-                 this.log(err);
 
-                 ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage');
 
-             }
 
-         }
 
-         /**
 
-          * 报表打印页面
 
-          *
 
-          * @param {Object} ctx - egg全局context
 
-          * @return {void}
 
-          */
 
-         async showPrintPage(ctx) {
 
-             try {
 
-                 // const params = JSON.parse(ctx.request.body.params);
 
-                 const pageSize = ctx.params.size;
 
-                 // console.log('pageSize: ' + pageSize);
 
-                 const renderData = {
 
-                     size: pageSize,
 
-                     // orientation: params.orientation,
 
-                 };
 
-                 await ctx.render('report/rpt_print.ejs', renderData);
 
-             } catch (err) {
 
-                 this.log(err);
 
-                 console.log(err);
 
-             }
 
-         }
 
-         async showIndividualPage(ctx) {
 
-             try {
 
-                 // const params = JSON.parse(ctx.request.body.params);
 
-                 const pageSize = ctx.params.size;
 
-                 // console.log('pageSize: ' + pageSize);
 
-                 const renderData = {
 
-                     size: pageSize,
 
-                     OSS_PATH: ctx.app.config.fujianOssPath,
 
-                     // orientation: params.orientation,
 
-                 };
 
-                 await ctx.render('report/rpt_individual.ejs', renderData);
 
-             } catch (err) {
 
-                 this.log(err);
 
-                 console.log(err);
 
-             }
 
-         }
 
-         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);
 
-             rptTpl.id = params.rpt_tpl_id;
 
-             // console.log('get the template!');
 
-             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, params.rpt_tpl_id)
 
-                 : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, params.rpt_tpl_id);
 
-             let copyCustomSelect = this.ctx.helper.clone(customSelect);
 
-             if (!params.gather_select && copyCustomSelect) delete copyCustomSelect.gather_select;
 
-             if (!params.stage_select && copyCustomSelect) delete copyCustomSelect.stage_select;
 
-             if (!params.material_sum_select && copyCustomSelect) delete copyCustomSelect.material_sum_select;
 
-             if (params.change_select) {
 
-                 copyCustomSelect = { tid: params.tender_id, rid: params.rpt_tpl_id, sid: -1, change_select: params.change_select };
 
-             }
 
-             const pageRst = await ctx.service.jpcReport.getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir, copyCustomSelect);
 
-             for (const page of pageRst.items) {
 
-                 page[JV.PROP_WATERMARK_CELLS] = [];
 
-             }
 
-             let waterMarkStr = null;
 
-             if (params.stage_status !== 3 && params.closeWatermark === 0) {
 
-                 // 加水印
 
-                 fillWaterMark([pageRst]);
 
-                 if (params.needWaterMark) {
 
-                     waterMarkStr = await getWatermarkPicData(pageRst, 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, params.stage_id); // 新需求中,允许在非审核状态下设置签名
 
-             const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
 
-             const stgAuditForOrg = await ctx.service.stageAudit.getStageAudit(params.stage_id, 1);
 
-             const stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
 
-             // console.log('after role stage!');
 
-             // console.log(roleRel);
 
-             const stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(params.stage_id, params.stage_times);
 
-             stageFlow.forEach(x => {
 
-                 if (!x) return;
 
-                 x.visible = (!ctx.session.sessionUser.is_admin && ctx.session.sessionProject.page_show.individualSign === 1)
 
-                     ? x.aid === ctx.session.sessionUser.accountId : true;
 
-             });
 
-             mergeStampSignature(ctx, params.stage_status, pageRst, roleRel[0], null, stgAudit, stageList);
 
-             mergeTextSignature(params.isTextSignature, params.stage_status, pageRst, roleRel[0], [], stgAudit, stageList);
 
-             await encodeSignatureDataUri(roleRel, this.app.baseDir);
 
-             if (params.getPicFlag) {
 
-                 await encodeDummySignatureDataUri(pageRst, this.app.baseDir); // 注意草图数据量问题!
 
-             }
 
-             // console.log('encodeSignatureDataUri!');
 
-             // fsUtil.writeObjToFile(pageRst, 'D:/GitHome/Temp/testBuiltPageResult2.js');
 
-             return {
 
-                 data: pageRst,
 
-                 signatureRelInfo: roleRel,
 
-                 stageAudit: stgAudit,
 
-                 stageAuditOrg: stgAuditForOrg,
 
-                 debugInfo: ctx.session.sessionUser.loginStatus ? ctx.debugInfo : null,
 
-                 customDefine: rptTpl[JV.NODE_CUSTOM_DEFINE],
 
-                 stageFlow,
 
-                 customSelect,
 
-                 waterMarkStr,
 
-             };
 
-         }
 
-         /**
 
-          * 获取报表数据
 
-          *
 
-          * @param {Object} ctx - egg全局context
 
-          * @return {void}
 
-          */
 
-         async getReport(ctx) {
 
-             try {
 
-                 // console.log('in getReport');
 
-                 const params = JSON.parse(ctx.request.body.params);
 
-                 ctx.body = await this._getReport(ctx, params);
 
-                 ctx.status = 201;
 
-             } catch (ex) {
 
-                 console.log(ex);
 
-                 this.setMessage(ex.toString(), this.messageType.ERROR);
 
-             }
 
-         }
 
-         async getTestReport(ctx) {
 
-             try {
 
-                 const file = 'D:/GitHome/Temp/导出PDF_格式样本1.js';
 
-                 const tplObj = JSON.parse(fs.readFileSync(file, 'utf-8'));
 
-                 ctx.body = { data: tplObj };
 
-                 ctx.status = 201;
 
-             } catch (ex) {
 
-                 this.setMessage(ex.toString(), this.messageType.ERROR);
 
-             }
 
-         }
 
-         /**
 
-          * 获取多批次报表数据
 
-          *
 
-          * @param {Object} ctx - egg全局context
 
-          * @return {void}
 
-          */
 
-         async getMultiReportsEx(ctx) {
 
-             // 原则说明:把所有报表模板集中获取,统一filter,只读一次数据!
 
-             const params = JSON.parse(ctx.request.body.params);
 
-             const pageShow = ctx.session.sessionProject.page_show;
 
-             if (pageShow !== null
 
-                 && pageShow !== undefined
 
-                 && params.outputType
 
-                 && ((params.outputType === 'PDF' && parseInt(pageShow.closeExportPdf) === 1)
 
-                     || (params.outputType === 'Excel' && parseInt(pageShow.closeExportExcel) === 1)
 
-                 )
 
-             ) {
 
-                 ctx.body = { data: [], signatureRelInfo: [], stageAudit: [] };
 
-                 ctx.status = 201;
 
-                 return;
 
-             }
 
-             await this._saveCustomSelects(params);
 
-             // const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir) || [];
 
-             const pageRstArr = await ctx.service.jpcReport.getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir) || [];
 
-             for (const pageRst of pageRstArr) {
 
-                 for (const page of pageRst.items) {
 
-                     page[JV.PROP_WATERMARK_CELLS] = [];
 
-                 }
 
-             }
 
-             let waterMarkStr = null;
 
-             if (params.stage_status !== 3 && params.closeWatermark === 0) {
 
-                 // 加水印
 
-                 fillWaterMark(pageRstArr);
 
-                 if (params.needWaterMark) {
 
-                     waterMarkStr = await getWatermarkPicData(pageRstArr[0], this.app.baseDir);
 
-                 }
 
-             }
 
-             const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
 
-             // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
 
-             const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id); // 新需求:在审批流程中的签名需要显示
 
-             roleRel.sort(function(rr1, rr2) {
 
-                 return params.rpt_ids.indexOf(parseInt(rr1.rpt_id)) - params.rpt_ids.indexOf(parseInt(rr2.rpt_id));
 
-             });
 
-             // console.log('roleRel: ');
 
-             // console.log(roleRel);
 
-             const stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
 
-             mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRel, params.rpt_ids, stgAudit, stageList);
 
-             mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRel, params.rpt_ids, stgAudit, stageList);
 
-             await encodeSignatureDataUri(roleRel, this.app.baseDir);
 
-             if (params.getPicFlag) {
 
-                 for (const pageRst of pageRstArr) {
 
-                     await encodeDummySignatureDataUri(pageRst, this.app.baseDir); // 注意草图数据量问题!
 
-                 }
 
-             }
 
-             // console.log(pageRstArr);
 
-             ctx.body = { data: pageRstArr, signatureRelInfo: roleRel, stageAudit: stgAudit, waterMarkStr };
 
-             ctx.status = 201;
 
-         }
 
-         async _saveCustomSelects(params) {
 
-             for (const [i, cs] of params.customSelect.entries()) {
 
-                 if (!cs) continue;
 
-                 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);
 
-             const pageShow = ctx.session.sessionProject.page_show;
 
-             if (pageShow !== null && pageShow !== undefined && parseInt(pageShow.closeExportExcel) === 1) {
 
-                 ctx.body = { data: [] };
 
-                 ctx.status = 201;
 
-                 return;
 
-             }
 
-             await this._saveCustomSelects(params);
 
-             const baseDir = this.app.baseDir;
 
-             function getExcelByPageData(pageRst, rpt_name, innerRoleRel) {
 
-                 return new Promise(function(resolve, reject) {
 
-                     rpt_xl_util.exportExcel(pageRst, params.pageSize, rpt_name, params.isOneSheet, null, null, baseDir, innerRoleRel,
 
-                         (err, uuidName) => {
 
-                             if (err) return reject(err);
 
-                             const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
 
-                             resolve(fileRst);
 
-                         }
 
-                     );
 
-                 });
 
-             }
 
-             // const stgAudit = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times)) : [];
 
-             const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
 
-             const stgAuditForOrg = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, 1)) : [];
 
-             // const stageList = (params.stage_status === 3) ? (await ctx.service.stage.getValidStagesShort(params.tender_id)) : [];
 
-             const stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
 
-             const roleRelArr = (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)) : [];
 
-             // const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, baseDir);
 
-             const pageRstArr = await ctx.service.jpcReport.getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, baseDir);
 
-             // console.log('params.stage_status: ' + params.stage_status);
 
-             // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/testBuiltPageResult1.js');
 
-             for (const pageRst of pageRstArr) {
 
-                 for (const page of pageRst.items) {
 
-                     page[JV.PROP_WATERMARK_CELLS] = [];
 
-                 }
 
-             }
 
-             let waterMarkStr = null;
 
-             if (params.stage_status !== 3 && params.closeWatermark === 0) {
 
-             // if (params.stage_status !== 3 && params.closeWatermark === 0 && params.option === JV.PAGING_OPTION_NORMAL) {
 
-                 // 加水印(注意:还得看用户设置是否需要加水印)
 
-                 fillWaterMark(pageRstArr);
 
-                 if (params.needWaterMark) {
 
-                     waterMarkStr = await getWatermarkPicData(pageRstArr[0], baseDir);
 
-                 }
 
-             }
 
-             mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
 
-             mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
 
-             await this.ctx.helper.recursiveMkdirSync(baseDir + '/app/public/download');
 
-             const runnableRst = [];
 
-             /*
 
-             for (let idx = 0; idx < pageRstArr.length; idx++) {
 
-                 let roleRel = null;
 
-                 for (const roleR of roleRelArr) {
 
-                     if (roleR.rpt_id === params.rpt_ids[idx]) {
 
-                         roleRel = JSON.parse(roleR.rel_content);
 
-                         break;
 
-                     }
 
-                 }
 
-                 // console.log('roleRel.rel_content: ' + roleRel.rel_content);
 
-                 // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/testBuiltPageResult.jsp');
 
-                 if (params.stage_status === 3) {
 
-                     mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
 
-                     mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
 
-                 }
 
-                 runnableRst.push(getExcelByPageData(pageRstArr[idx], params.rpt_names[idx], roleRel));
 
-             }
 
-             /*/
 
-             // 1. merge签名相关信息
 
-             // const pageBrkSize = 6291456; // 6M, 1024*1024*6
 
-             const pageBrkSize = 62914560; // 60M, 1024*1024*6*10
 
-             for (let idx = 0; idx < pageRstArr.length; idx++) {
 
-                 let roleRel = null;
 
-                 for (const roleR of roleRelArr) {
 
-                     if (roleR.rpt_id === params.rpt_ids[idx]) {
 
-                         roleRel = JSON.parse(roleR.rel_content);
 
-                         break;
 
-                     }
 
-                 }
 
-                 if (params.stage_status === 3) {
 
-                     mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
 
-                     mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
 
-                 }
 
-                 // 2. 判断草图大小是否需要分页
 
-                 const picSize = await _chkRawPicSize(pageRstArr[idx], baseDir);
 
-                 // const picSize = 262914560; // 测试用,强制分页
 
-                 if (picSize > pageBrkSize) {
 
-                     // let pageBrkAmt = Math.ceil(picSize / pageBrkSize);
 
-                     let pageBrkAmt = Math.floor(pageRstArr[idx].items.length / Math.ceil(picSize / pageBrkSize));
 
-                     if (pageBrkAmt < 10) {
 
-                         // 不用管
 
-                     } else if (pageBrkAmt < 100) {
 
-                         pageBrkAmt = Math.floor(pageBrkAmt / 10) * 10;
 
-                     } else if (pageBrkAmt < 1000) {
 
-                         pageBrkAmt = Math.floor(pageBrkAmt / 100) * 100;
 
-                     } else {
 
-                         // 暂时不管
 
-                     }
 
-                     const newRptNames = []; // 这个为导出控制分页用
 
-                     const newPageDataRst = _resetPageDataByBreaks([pageRstArr[idx]], pageBrkAmt, [params.rpt_names[idx]], newRptNames);
 
-                     for (let dtlIdx = 0; dtlIdx < newPageDataRst.length; dtlIdx++) {
 
-                         runnableRst.push(getExcelByPageData(newPageDataRst[dtlIdx], newRptNames[dtlIdx], roleRel));
 
-                     }
 
-                 } else {
 
-                     runnableRst.push(getExcelByPageData(pageRstArr[idx], params.rpt_names[idx], roleRel));
 
-                 }
 
-             }
 
-             // */
 
-             // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/计量导出pageArr.js');
 
-             const uuidRst = await Promise.all(runnableRst);
 
-             ctx.body = { data: uuidRst, waterMarkStr };
 
-             ctx.status = 201;
 
-         }
 
-         _getExcelByPageData(pageRst, rpt_name, pageSize, baseDir, innerRoleRel) {
 
-             return new Promise(function(resolve, reject) {
 
-                 rpt_xl_util.exportExcel(pageRst, pageSize, rpt_name, true, null, null, baseDir, innerRoleRel,
 
-                     (err, uuidName) => {
 
-                         if (err) return reject(err);
 
-                         const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
 
-                         resolve(fileRst);
 
-                     }
 
-                 );
 
-             });
 
-         }
 
-         async createExcelFilesFromDirectData(ctx) {
 
-             const params = JSON.parse(ctx.request.body.params);
 
-             const names = params.rptNames;
 
-             const pageDataArr = params.pageData;
 
-             const runnableRst = [];
 
-             for (let idx = 0; idx < names.length; idx++) {
 
-                 runnableRst.push(this._getExcelByPageData(pageDataArr[idx], names[idx], 'A4', this.app.baseDir, null));
 
-             }
 
-             const uuidRst = await Promise.all(runnableRst);
 
-             ctx.body = { data: uuidRst, waterMarkStr: null };
 
-             ctx.status = 201;
 
-         }
 
-         async createExcelFilesFromLocal(ctx) {
 
-             const baseDir = this.app.baseDir;
 
-             function getExcelByPageData(pageRst, rpt_name, innerRoleRel) {
 
-                 return new Promise(function(resolve, reject) {
 
-                     rpt_xl_util.exportExcel(pageRst, 'A4', rpt_name, true, null, null, baseDir, innerRoleRel,
 
-                         (err, uuidName) => {
 
-                             if (err) return reject(err);
 
-                             const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
 
-                             resolve(fileRst);
 
-                         }
 
-                     );
 
-                 });
 
-             }
 
-             try {
 
-                 console.log('start:');
 
-                 const pageRst = JSON.parse(fs.readFileSync('D:/GitHome/temp/计量excel原始数据_A3BZ6_5384_112表(清单).js', 'utf-8'));
 
-                 console.log('read it');
 
-                 const runnableRst = [];
 
-                 const pageBrkSize = 6291456; // 6M, 1024*1024*6
 
-                 // const pageBrkSize = 1048576; // 1M, 1024*1024*1
 
-                 console.log('pageBrkSize:' + pageBrkSize);
 
-                 const picSize = await _chkRawPicSize(pageRst, baseDir);
 
-                 console.log('picSize:' + picSize);
 
-                 if (picSize > pageBrkSize) {
 
-                     let pageBrkAmt = Math.floor(pageRst.items.length / Math.ceil(picSize / pageBrkSize));
 
-                     console.log('pageBrkAmt:' + pageBrkAmt);
 
-                     if (pageBrkAmt < 10) {
 
-                         // 不用管
 
-                     } else if (pageBrkAmt < 100) {
 
-                         pageBrkAmt = Math.floor(pageBrkAmt / 10) * 10;
 
-                     } else if (pageBrkAmt < 1000) {
 
-                         pageBrkAmt = Math.floor(pageBrkAmt / 100) * 100;
 
-                     } else {
 
-                         // 暂时不管
 
-                     }
 
-                     const newRptNames = []; // 这个为导出控制分页用
 
-                     const newPageDataRst = _resetPageDataByBreaks([pageRst], pageBrkAmt, ['工程计量表(计量单元-清单)'], newRptNames);
 
-                     for (let dtlIdx = 0; dtlIdx < newPageDataRst.length; dtlIdx++) {
 
-                         runnableRst.push(getExcelByPageData(newPageDataRst[dtlIdx], newRptNames[dtlIdx], null));
 
-                     }
 
-                 } else {
 
-                     runnableRst.push(getExcelByPageData(pageRst, '工程计量表(计量单元-清单)', null));
 
-                 }
 
-                 const uuidRst = await Promise.all(runnableRst);
 
-                 ctx.body = { data: uuidRst, waterMarkStr: null };
 
-                 ctx.status = 201;
 
-             } catch (ex) {
 
-                 console.log(ex.toString());
 
-                 ctx.status = 500;
 
-             }
 
-         }
 
-         async createExcelFilesInOneBookEx(ctx) {
 
-             const params = JSON.parse(ctx.request.body.params);
 
-             const baseDir = this.app.baseDir;
 
-             function getExcelByPageData(pageRstArr, rpt_name, innerRoleRel) {
 
-                 return new Promise(function(resolve, reject) {
 
-                     rpt_xl_util.exportExcelInOneBook(pageRstArr, params.pageSize, rpt_name, baseDir, innerRoleRel,
 
-                         (err, uuidName) => {
 
-                             if (err) return reject(err);
 
-                             const fileRst = { uuid: uuidName, reportName: rpt_name };
 
-                             resolve(fileRst);
 
-                         }
 
-                     );
 
-                 });
 
-             }
 
-             const roleRelArr = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
 
-             // console.log(`baseDir: ${baseDir}`);
 
-             // fsUtil.writeObjToFile(roleRelArr, 'D:/GitHome/temp/签名信息.js');
 
-             const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
 
-             const stgAuditForOrg = await ctx.service.stageAudit.getStageAudit(params.stage_id, 1);
 
-             const stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
 
-             // const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
 
-             const pageRstArr = await ctx.service.jpcReport.getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
 
-             // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/pageRstArrForExcel.js');
 
-             for (const pageRst of pageRstArr) {
 
-                 for (const page of pageRst.items) {
 
-                     page[JV.PROP_WATERMARK_CELLS] = [];
 
-                 }
 
-             }
 
-             let waterMarkStr = null;
 
-             if (params.stage_status !== 3 && params.closeWatermark === 0) {
 
-             // if (params.stage_status !== 3 && params.closeWatermark === 0 && params.option === JV.PAGING_OPTION_NORMAL) {
 
-                 // 加水印
 
-                 fillWaterMark(pageRstArr);
 
-                 if (params.needWaterMark) {
 
-                     waterMarkStr = await getWatermarkPicData(pageRstArr[0], this.app.baseDir);
 
-                 }
 
-             }
 
-             mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
 
-             mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
 
-             await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
 
-             const runnableRst = [];
 
-             let rptRoleRelArr = [];
 
-             const reAssignSignatureName = function(pageData, roleRel, rpt_name_key) {
 
-                 const keyMap = {};
 
-                 for (const pageItem of pageData.items) {
 
-                     for (const signCell of pageItem[JV.PROP_SIGNATURE_CELLS]) {
 
-                         if (!keyMap.hasOwnProperty(signCell.signature_name)) {
 
-                             keyMap[signCell.signature_name] = rpt_name_key + '_' + signCell.signature_name;
 
-                         }
 
-                     }
 
-                 }
 
-                 for (const pageItem of pageData.items) {
 
-                     for (const signCell of pageItem[JV.PROP_SIGNATURE_CELLS]) {
 
-                         if (keyMap.hasOwnProperty(signCell.signature_name)) {
 
-                             signCell.signature_name = keyMap[signCell.signature_name];
 
-                         }
 
-                     }
 
-                 }
 
-                 for (const roleSign of roleRel) {
 
-                     if (keyMap.hasOwnProperty(roleSign.signature_name)) {
 
-                         roleSign.signature_name = keyMap[roleSign.signature_name];
 
-                     }
 
-                 }
 
-                 // console.log('keyMap of : ' + rpt_name_key);
 
-                 // console.log(keyMap);
 
-             };
 
-             for (let idx = 0; idx < pageRstArr.length; idx++) {
 
-                 let roleRel = null;
 
-                 for (const roleR of roleRelArr) {
 
-                     if (roleR.rpt_id === params.rpt_ids[idx]) {
 
-                         roleRel = JSON.parse(roleR.rel_content);
 
-                         if (params.stage_status === 3) {
 
-                             mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
 
-                             mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
 
-                         }
 
-                         // 这里要做些电子签名的signature_name转换,以防重名
 
-                         reAssignSignatureName(pageRstArr[idx], roleRel, params.rpt_names[idx]);
 
-                         rptRoleRelArr = rptRoleRelArr.concat(roleRel);
 
-                         break;
 
-                     }
 
-                 }
 
-             }
 
-             // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/pageRstArrForExcelAfterReAssign.js');
 
-             // fsUtil.writeObjToFile(rptRoleRelArr, 'D:/GitHome/temp/签名信息_新.js');
 
-             runnableRst.push(getExcelByPageData(pageRstArr, params.rptName, rptRoleRelArr));
 
-             const uuidRst = await Promise.all(runnableRst);
 
-             ctx.body = { data: uuidRst, waterMarkStr };
 
-             ctx.status = 201;
 
-         }
 
-         async getFileByUUID(ctx) {
 
-             // console.log('downloading : ' + ctx.params.uuid);
 
-             const uuid = ctx.params.uuid;
 
-             const rptName = ctx.params.rptName;
 
-             const suffix = '.' + ctx.params.suffix;
 
-             try {
 
-                 const rptNameURI = encodeURI(rptName);
 
-                 const filePath = this.app.baseDir + '/app/public/download/';
 
-                 // console.log('filePath: ' + filePath);
 
-                 // await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
 
-                 ctx.set({
 
-                     'Content-Type': 'application/vnd.openxmlformats',
 
-                     'Content-Disposition': 'attachment; filename="' + rptNameURI + suffix + "\"; filename*=utf-8''" + rptNameURI + suffix,
 
-                 });
 
-                 ctx.body = await fs.readFileSync(filePath + uuid + suffix);
 
-             } catch (e) {
 
-                 console.log(e);
 
-             }
 
-         }
 
-         /**
 
-          * 更新用户通用报表显示配置
 
-          *
 
-          * @param {Object} ctx - egg全局context
 
-          * @return {void}
 
-          */
 
-         async updateCustNode(ctx) {
 
-             const params = JSON.parse(ctx.request.body.params);
 
-             // console.log(params);
 
-             const custId = this.ctx.session.sessionUser.accountId;
 
-             const newNodeItems = JSON.stringify(params.nodeItems);
 
-             const rst = await ctx.service.rptTreeNodeCust.updateCustNode(custId, newNodeItems);
 
-             // console.log(rst);
 
-             ctx.body = { data: rst };
 
-             // ctx.body = { data: { msg: 'test the network' } };
 
-             ctx.status = 201;
 
-         }
 
-         async setCustomDefine(ctx) {
 
-             try {
 
-                 const data = JSON.parse(ctx.request.body.data);
 
-                 await this.ctx.service.rptCustomDefine.saveCustomSelect(data);
 
-                 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;
 
- };
 
- function isFileExisted(file) {
 
-     return new Promise(function(resolve, reject) {
 
-         fs.access(file, err => {
 
-             if (err) {
 
-                 reject(false);
 
-             } else {
 
-                 resolve(true);
 
-             }
 
-         });
 
-     });
 
- }
 
- function fillWaterMark(pageRstArray) {
 
-     const orgWaterMarkWidth = 600;
 
-     const orgWaterMarkHeight = 288;
 
-     const createWaterCell = function(area) {
 
-         const w = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT];
 
-         const h = area[JV.PROP_BOTTOM] - area[JV.PROP_TOP];
 
-         const left = Math.round(area[JV.PROP_LEFT] + w / 2 - orgWaterMarkWidth / 2);
 
-         const right = left + orgWaterMarkWidth;
 
-         const top = Math.round(area[JV.PROP_TOP] + h / 2 - orgWaterMarkHeight / 2);
 
-         const bottom = top + orgWaterMarkHeight;
 
-         return {
 
-             signature_name: JV.SIGNATURE_NAME_DUMMY_WATER_MARK,
 
-             path: '/public/images/not_Approve.png',
 
-             sign_path: '/public/images/not_Approve.png',
 
-             pic: null,
 
-             control: 'Title',
 
-             style: 'Default_None',
 
-             area: {
 
-                 Left: left,
 
-                 Right: right,
 
-                 Top: top,
 
-                 Bottom: bottom,
 
-             },
 
-         };
 
-     };
 
-     for (const pageRst of pageRstArray) {
 
-         for (const page of pageRst.items) {
 
-             page[JV.PROP_WATERMARK_CELLS] = [];
 
-             if (page[JV.PROP_PAGE_MERGE_BORDER]) {
 
-                 const wmCell = createWaterCell(page[JV.PROP_PAGE_MERGE_BORDER]);
 
-                 page[JV.PROP_WATERMARK_CELLS].push(wmCell);
 
-             } else if (page[JV.PAGE_SPECIAL_MERGE_POS]) {
 
-                 if (page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT]) {
 
-                     for (let i = 0; i < page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT].length; i++) {
 
-                         const area = {};
 
-                         area[JV.PROP_LEFT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT][i];
 
-                         area[JV.PROP_RIGHT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_RIGHT][i];
 
-                         area[JV.PROP_TOP] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_TOP][i];
 
-                         area[JV.PROP_BOTTOM] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_BOTTOM][i];
 
-                         const wmCell = createWaterCell(area);
 
-                         page[JV.PROP_WATERMARK_CELLS].push(wmCell);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-     }
 
- }
 
- async function encodeSignatureDataUri(roleRel, baseDir) {
 
-     if (roleRel) {
 
-         for (const singleRoleRel of roleRel) {
 
-             if (singleRoleRel.rel_content !== null && singleRoleRel.rel_content !== undefined && singleRoleRel.rel_content !== '') {
 
-                 const roleRelContent = JSON.parse(singleRoleRel.rel_content);
 
-                 for (const role of roleRelContent) {
 
-                     // console.log(role);
 
-                     if (role.sign_path !== '') {
 
-                         const filePath = baseDir + '/app' + role.sign_path;
 
-                         try {
 
-                             const res = await isFileExisted(filePath);
 
-                             if (res) {
 
-                                 const bData = fs.readFileSync(filePath);
 
-                                 const base64Str = bData.toString('base64');
 
-                                 const datauri = 'data:image/png;base64,' + base64Str;
 
-                                 role.sign_pic = datauri;
 
-                             } else {
 
-                                 console.log('文件不存在:' + filePath);
 
-                             }
 
-                         } catch (err) {
 
-                             console.error(err);
 
-                         }
 
-                     }
 
-                 }
 
-                 singleRoleRel.rel_content = JSON.stringify(roleRelContent);
 
-             } else {
 
-                 singleRoleRel.rel_content = [];
 
-             }
 
-         }
 
-     }
 
- }
 
- async function encodeDummySignatureDataUri(pageRst, baseDir) {
 
-     if (pageRst) {
 
-         for (const page of pageRst.items) {
 
-             for (const signature of page[JV.PROP_SIGNATURE_CELLS]) {
 
-                 if (signature.signature_name === JV.SIGNATURE_NAME_DUMMY) {
 
-                     if (signature.path !== '') {
 
-                         const filePath = baseDir + '/app' + signature.path;
 
-                         try {
 
-                             const res = await isFileExisted(filePath);
 
-                             if (res) {
 
-                                 const bData = fs.readFileSync(filePath);
 
-                                 const base64Str = bData.toString('base64');
 
-                                 const datauri = 'data:image/png;base64,' + base64Str;
 
-                                 signature.pic = datauri;
 
-                                 signature.path = '';
 
-                             } else {
 
-                                 console.log('文件不存在:' + filePath);
 
-                             }
 
-                         } catch (err) {
 
-                             console.error(err);
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             // 考虑优化,水印只需要一张即可,不需要每页都设置
 
-             // for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
 
-             //     if (signature.path !== '') {
 
-             //         const filePath = baseDir + '/app' + signature.path;
 
-             //         try {
 
-             //             const res = await isFileExisted(filePath);
 
-             //             if (res) {
 
-             //                 const bData = fs.readFileSync(filePath);
 
-             //                 const base64Str = bData.toString('base64');
 
-             //                 const datauri = 'data:image/png;base64,' + base64Str;
 
-             //                 signature.pic = datauri;
 
-             //                 signature.path = '';
 
-             //             } else {
 
-             //                 console.log('文件不存在:' + filePath);
 
-             //             }
 
-             //         } catch (err) {
 
-             //             console.error(err);
 
-             //         }
 
-             //     }
 
-             // }
 
-         }
 
-     }
 
- }
 
- async function getWatermarkPicData(pageRst, baseDir) {
 
-     let rst = '';
 
-     if (pageRst) {
 
-         for (const page of pageRst.items) {
 
-             for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
 
-                 if (signature.path !== '') {
 
-                     const filePath = baseDir + '/app' + signature.path;
 
-                     try {
 
-                         const res = await isFileExisted(filePath);
 
-                         if (res) {
 
-                             const bData = fs.readFileSync(filePath);
 
-                             const base64Str = bData.toString('base64');
 
-                             rst = 'data:image/png;base64,' + base64Str;
 
-                             break;
 
-                         } else {
 
-                             console.log('文件不存在:' + filePath);
 
-                         }
 
-                     } catch (err) {
 
-                         console.error(err);
 
-                     }
 
-                 }
 
-                 if (rst !== null) break;
 
-             }
 
-         }
 
-     }
 
-     return rst;
 
- }
 
- function mergeTextSignature(isTxtSignature, status, pageData, singleRoleRel, rpt_ids, stgAudit, stageList) {
 
-     // 依据需求,有些用户不需要签名图片,那么从源头上把签名从signature_cells转移到cells下,省得后续 预览、打印、导出PDF、导出EXCEL每个地方都改动
 
-     const _mergeSingle = function(_page, _roleRelList, isDeleteSignCell, checkAudit = false) {
 
-         // console.log(_roleRelList);
 
-         let roleRelContent = [];
 
-         if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
 
-             roleRelContent = JSON.parse(_roleRelList.rel_content);
 
-         }
 
-         for (const page of _page.items) {
 
-             if (page.signature_cells) {
 
-                 const deleteSCellsIdx = [];
 
-                 for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
 
-                     const sCell = page.signature_cells[scIdx];
 
-                     if (sCell.signature_name !== JV.SIGNATURE_NAME_DUMMY) {
 
-                         sCell.Value = ''; // 这里要先清除原有信息
 
-                         sCell.path = '';
 
-                         sCell.pic = '';
 
-                         let needTransferText = true;
 
-                         for (const role_rel of roleRelContent) {
 
-                             if (sCell.signature_name === role_rel.signature_name) {
 
-                                 if (!checkAudit || _chkIfAudit(role_rel, stgAudit, stageList)) {
 
-                                     sCell.Value = role_rel.user_name; // 只有审核通过了才需要文本签名内容
 
-                                     if (role_rel.sign_output && role_rel.sign_output.indexOf(NORMAL_SIGN_STR) < 0) {
 
-                                         // 用户选择不签名,则不迁移
 
-                                         needTransferText = false;
 
-                                     }
 
-                                     break;
 
-                                 }
 
-                             }
 
-                         }
 
-                         if (needTransferText) {
 
-                             const newCell = {
 
-                                 font: 'Footer',
 
-                                 control: sCell.control,
 
-                                 style: sCell.style,
 
-                                 Value: sCell.Value,
 
-                                 area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
 
-                             };
 
-                             page.cells.push(newCell); // 迁移
 
-                             deleteSCellsIdx.push(scIdx);
 
-                         }
 
-                     }
 
-                 }
 
-                 // 删除 page.signature_cells 签名(草图不能删);
 
-                 // console.log('isDeleteSignCell: ' + isDeleteSignCell);
 
-                 // console.log(deleteSCellsIdx);
 
-                 if (isDeleteSignCell) {
 
-                     for (let dIdx = deleteSCellsIdx.length - 1; dIdx >= 0; dIdx--) {
 
-                         page.signature_cells.splice(deleteSCellsIdx[dIdx], 1);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-     };
 
-     if (isTxtSignature) {
 
-         if (pageData instanceof Array) {
 
-             pageData.forEach((dtlPage, index) => {
 
-                 let dftRolRel = [];
 
-                 const rpt_id = rpt_ids[index];
 
-                 for (const roleRel of singleRoleRel) {
 
-                     if (roleRel.rpt_id === rpt_id) {
 
-                         dftRolRel = roleRel;
 
-                     }
 
-                 }
 
-                 // console.log(dftRolRel);
 
-                 _mergeSingle(dtlPage, dftRolRel, true, status !== 3);
 
-             });
 
-         } else {
 
-             _mergeSingle(pageData, singleRoleRel, false, status !== 3);
 
-         }
 
-     }
 
- }
 
- function _chkIfAudit(role_rel, STAGE_AUDIT, STAGE_LIST) {
 
-     let rst = false;
 
-     for (const stg_audit of STAGE_AUDIT) {
 
-         if (role_rel.acc_id === stg_audit.aid) {
 
-             if (stg_audit.status === 3) {
 
-                 rst = true;
 
-             } else {
 
-                 rst = false;
 
-             }
 
-             // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
 
-         }
 
-     }
 
-     if (!rst) {
 
-         // 还有原报需要检测
 
-         for (const stg_ort_rpt of STAGE_LIST) {
 
-             if (role_rel.acc_id === stg_ort_rpt.user_id) {
 
-                 if (stg_ort_rpt.status !== 1 && stg_ort_rpt.status !== 4) {
 
-                     // 只要不是待上报(1)、退回审批(4) 状态,都需要显示
 
-                     rst = true;
 
-                 } else {
 
-                     rst = false;
 
-                 }
 
-                 // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
 
-             }
 
-         }
 
-     }
 
-     // rst = true; //测试,未来将屏蔽
 
-     return rst;
 
- }
 
- // 因机制问题,此方法必须在mergeTextSignature之前调用
 
- async function mergeStampSignature(ctx, status, pageData, singleRoleRel, rpt_ids, stgAudit, stageList) {
 
-     const dupPicPaths = [];
 
-     const _getMaxRect = function(page) {
 
-         const rect = [100000000, 100000000, 0, 0];
 
-         for (const cell of page.cells) {
 
-             if (rect[0] > cell.area.Left) {
 
-                 rect[0] = cell.area.Left;
 
-             }
 
-             if (rect[1] > cell.area.Top) {
 
-                 rect[1] = cell.area.Top;
 
-             }
 
-             if (rect[2] < cell.area.Right) {
 
-                 rect[2] = cell.area.Right;
 
-             }
 
-             if (rect[3] < cell.area.Bottom) {
 
-                 rect[3] = cell.area.Bottom;
 
-             }
 
-         }
 
-         return rect;
 
-     };
 
-     const createStampArea = function(orgCell, controls, maxRect) {
 
-         const ctrl = controls[orgCell.control];
 
-         const rst = { Left: orgCell.area.Left, Right: orgCell.area.Right, Top: orgCell.area.Top, Bottom: orgCell.area.Bottom };
 
-         let pLeft = orgCell.area.Left,
 
-             pTop = orgCell.area.Top;
 
-         switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
 
-             case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
 
-                 pLeft = orgCell.area.Left;
 
-                 break;
 
-             case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
 
-                 pLeft = (orgCell.area.Left + orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH) / 2;
 
-                 break;
 
-             case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
 
-                 pLeft = orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH;
 
-                 break;
 
-             default:break;
 
-         }
 
-         switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
 
-             case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
 
-                 pTop = orgCell.area.Top;
 
-                 break;
 
-             case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
 
-                 pTop = (orgCell.area.Top + orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT) / 2;
 
-                 break;
 
-             case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
 
-                 pTop = orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT;
 
-                 break;
 
-             default:break;
 
-         }
 
-         rst.Left = pLeft;
 
-         rst.Top = pTop;
 
-         rst.Right = pLeft + STD_COMP_STAMP_SIZE_WIDTH;
 
-         rst.Bottom = pTop + STD_COMP_STAMP_SIZE_WIDTH;
 
-         // 最后一步,如超过报表范围,则要调整坐标
 
-         // if (rst.Left < maxRect[0]) {
 
-         //     const width = maxRect[0] - rst.Left;
 
-         //     rst.Left += width;
 
-         //     rst.Right += width;
 
-         // }
 
-         // if (rst.Top < maxRect[1]) {
 
-         //     const height = maxRect[1] - rst.Top;
 
-         //     rst.Top += height;
 
-         //     rst.Bottom += height;
 
-         // }
 
-         // if (rst.Right > maxRect[2]) {
 
-         //     const width = maxRect[2] - rst.Right; // 负
 
-         //     rst.Left += width;
 
-         //     rst.Right += width;
 
-         // }
 
-         // if (rst.Bottom > maxRect[3]) {
 
-         //     const height = maxRect[3] - rst.Bottom;
 
-         //     rst.Top += height;
 
-         //     rst.Bottom += height;
 
-         // }
 
-         return rst;
 
-     };
 
-     const _mergeSingleStamp = async function(_page, _roleRelList, checkAudit = false) {
 
-         let roleRelContent = [];
 
-         if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
 
-             roleRelContent = JSON.parse(_roleRelList.rel_content);
 
-         }
 
-         for (const page of _page.items) {
 
-             const maxRect = _getMaxRect(page);
 
-             if (page.signature_cells) {
 
-                 const newStampCells = [];
 
-                 for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
 
-                     const sCell = page.signature_cells[scIdx];
 
-                     for (const role_rel of roleRelContent) {
 
-                         if (sCell.signature_name === role_rel.signature_name) {
 
-                             if (!checkAudit || _chkIfAudit(role_rel, stgAudit, stageList)) {
 
-                                 if (Array.isArray(role_rel.sign_output) && role_rel.sign_output.length > 0) {
 
-                                     for (const signType of role_rel.sign_output) {
 
-                                         switch (signType) {
 
-                                             case COMPANY_SIGN_STR:
 
-                                             case PRIVATE_SIGN_STR:
 
-                                                 // 创建一个新的cell
 
-                                                 let stampPath = (signType === COMPANY_SIGN_STR) ? role_rel.company_stamp_path : role_rel.private_stamp_path;
 
-                                                 stampPath = ctx.app.config.fujianOssPath + stampPath;
 
-                                                 if (dupPicPaths.indexOf(stampPath) < 0) {
 
-                                                     dupPicPaths.push(stampPath);
 
-                                                     // await _chkRawPicSizeOSS(ctx, stampPath);
 
-                                                 }
 
-                                                 // 保存在签字信息中的签章信息
 
-                                                 let signatureArea;
 
-                                                 if (role_rel.areaData && role_rel.areaData[signType]) {
 
-                                                     signatureArea = role_rel.areaData[signType];
 
-                                                 }
 
-                                                 const newStampCell = {
 
-                                                     signature_name: JV.SIGNATURE_NAME_DUMMY,
 
-                                                     control: sCell.control,
 
-                                                     style: sCell.style,
 
-                                                     path: stampPath,
 
-                                                     isStamp: true,
 
-                                                     maxRect,
 
-                                                     orgArea: sCell.area,
 
-                                                     area: signatureArea || createStampArea(sCell, _page[JV.NODE_CONTROL_COLLECTION], maxRect), // 有签章信息就直接取,没有的话就走原来的逻辑
 
-                                                     signatureName: role_rel.signature_name, // 节点名称
 
-                                                     signType, // 签章信息
 
-                                                     isSaveSignature: !!signatureArea, // 是否有签章位置信息
 
-                                                 };
 
-                                                 newStampCells.push(newStampCell);
 
-                                                 break;
 
-                                             default: break;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 if (newStampCells.length > 0) {
 
-                     page.signature_cells = page.signature_cells.concat(newStampCells);
 
-                 }
 
-             }
 
-         }
 
-     };
 
-     if (pageData instanceof Array) {
 
-         pageData.forEach((dtlPage, index) => {
 
-             let dftRolRel = [];
 
-             const rpt_id = rpt_ids[index];
 
-             for (const roleRel of singleRoleRel) {
 
-                 if (roleRel.rpt_id === rpt_id) {
 
-                     dftRolRel = roleRel;
 
-                 }
 
-             }
 
-             _mergeSingleStamp(dtlPage, dftRolRel, status !== 3);
 
-         });
 
-     } else {
 
-         _mergeSingleStamp(pageData, singleRoleRel, status !== 3);
 
-     }
 
- }
 
- function mergeSignAudit(pageData, currRoleRelList, currAuditList) {
 
-     for (const page of pageData.items) {
 
-         if (page.signature_audit_cells) {
 
-             for (const sCell of page.signature_audit_cells) {
 
-                 sCell.Value = ''; // 这里要先清除原有信息
 
-                 if (currRoleRelList && currRoleRelList.length > 0) {
 
-                     for (const role_rel of currRoleRelList) {
 
-                         if (sCell.signature_name === role_rel.signature_name + '_审核意见') {
 
-                             let preDate = '';
 
-                             sCell.Value = '同意'; // 只有选择了签名的,才需要初始化一个默认的意见(之前的逻辑在有多个签名,哪怕只选择了一个,其他的意见都会有默认意见)
 
-                             if (currAuditList && currAuditList.length > 0) {
 
-                                 for (const audit_rel of currAuditList) {
 
-                                     if (role_rel.acc_id === audit_rel.aid) {
 
-                                         if (audit_rel.end_time > preDate && audit_rel.status === 3) {
 
-                                             sCell.Value = audit_rel.opinion;
 
-                                             preDate = audit_rel.end_time;
 
-                                         }
 
-                                         // 不能break,实际会有多个审核意见,以最后一个为准
 
-                                     }
 
-                                 }
 
-                             }
 
-                             break;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-     }
 
- }
 
- function mergeSignDate(pageData, current_stage_id, currRoleRelList, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
 
-     if (currRoleRelList && currRoleRelList.length > 0 && STAGE_AUDIT && STAGE_AUDIT.length > 0) {
 
-         for (let rridx = 0; rridx < currRoleRelList.length; rridx++) {
 
-             const role_rel = currRoleRelList[rridx];
 
-             if (role_rel.sign_date === undefined || role_rel.sign_date === null || role_rel.sign_date === '') {
 
-                 const dftDate = _getSignDateByAllScenarios(role_rel.acc_id, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST);
 
-                 role_rel.sign_date = dftDate;
 
-             }
 
-         }
 
-     }
 
-     if (currRoleRelList && currRoleRelList.length > 0) {
 
-         for (const page of pageData.items) {
 
-             if (page.signature_date_cells) {
 
-                 for (const sCell of page.signature_date_cells) {
 
-                     sCell.Value = _getSignDateDftName();
 
-                     for (const role_rel of currRoleRelList) {
 
-                         if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
 
-                             if (role_rel.sign_date !== '') {
 
-                                 if (typeof role_rel.sign_date === 'string') {
 
-                                     role_rel.sign_date = new Date(role_rel.sign_date);
 
-                                 }
 
-                                 sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
 
-                             }
 
-                             break;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-     }
 
- }
 
- function _getSignDateByAllScenarios(userAccId, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
 
-     let rst = '';
 
-     let hasAudit = false;
 
-     for (const stg_audit of STAGE_AUDIT) {
 
-         if (stg_audit.aid === userAccId) {
 
-             hasAudit = true;
 
-             if (stg_audit.status === 3) {
 
-                 rst = stg_audit.end_time;
 
-             } else {
 
-                 rst = '';
 
-             }
 
-             // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
 
-         }
 
-     }
 
-     let isOrgRpt = false;
 
-     for (const stg of STAGE_LIST) {
 
-         if (stg.id === current_stage_id) {
 
-             if (stg.user_id === userAccId) {
 
-                 isOrgRpt = true;
 
-             }
 
-             break;
 
-         }
 
-     }
 
-     if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
 
-         if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
 
-             rst = STAGE_AUDIT_ORG[0].begin_time;
 
-         }
 
-     }
 
-     if (!isOrgRpt && !hasAudit) {
 
-         // 非审批流程人员以及非原报,则显示期截至时间
 
-         for (const stg of STAGE_LIST) {
 
-             if (stg.id === current_stage_id && stg.period) {
 
-                 const period = stg.period.split(' ~ ');
 
-                 if (period.length === 2) {
 
-                     rst = period[1];
 
-                 }
 
-             }
 
-         }
 
-     }
 
-     return rst;
 
- }
 
- function _getSignDateDftName() {
 
-     return '    年  月  日';
 
- }
 
- async function _chkRawPicSize(pageData, baseDir) {
 
-     let rst = 0;
 
-     const picKeys = [];
 
-     for (let pi = 0; pi < pageData.items.length; pi++) {
 
-         // 每页判断
 
-         for (let ci = 0; ci < pageData.items[pi][JV.PROP_SIGNATURE_CELLS].length; ci++) {
 
-             const picPath = pageData.items[pi][JV.PROP_SIGNATURE_CELLS][ci].path;
 
-             // if (picPath && picPath.indexOf('/sign') < 0 && picKeys.indexOf(picPath) < 0) {
 
-             if (picPath && picPath !== '' && picKeys.indexOf(picPath) < 0) {
 
-                 // 签名图片也要计算在内,反正不重复
 
-                 picKeys.push(picPath);
 
-             }
 
-             // signature_cells PROP_SIGNATURE_CELLS
 
-         }
 
-     }
 
-     // console.log(picKeys);
 
-     for (const pKey of picKeys) {
 
-         const filePath = `${baseDir}/app${pKey}`;
 
-         console.log('filePath: ' + filePath);
 
-         let isExist = false;
 
-         try {
 
-             isExist = await isFileExisted(filePath);
 
-         } catch (ex) {
 
-             isExist = false;
 
-         }
 
-         console.log('isExist: ' + isExist);
 
-         if (isExist) {
 
-             const obj = fs.statSync(filePath);
 
-             if (obj) {
 
-                 rst += obj.size;
 
-             } else {
 
-                 console.log('no statSync resutl: ' + filePath);
 
-             }
 
-             // rst += fs.statSync(filePath).size;
 
-         } else {
 
-             console.log(`${pKey} not exists!`);
 
-         }
 
-     }
 
-     return rst;
 
- }
 
- async function _chkRawPicSizeOSS(ctx, picPath) {
 
-     // 计量的草图、签章都放在OSS服务器上,需要另外的方式来获取,考虑到效率问题,机制上得有所变化
 
-     const rst = [0, 0];
 
-     try {
 
-         const pf = await ctx.app.signPdfOss.get(picPath);
 
-         console.log('get pic successfully!');
 
-         console.log(pf);
 
-     } catch (ex) {
 
-         console.log(ex);
 
-     } finally {
 
-         console.log('finally!');
 
-     }
 
-     return rst;
 
- }
 
- function _resetPageDataByBreaks(pageDataArr, breakAmt, rpt_names, newRptNames) {
 
-     const rst = [];
 
-     for (let pi = 0; pi < pageDataArr.length; pi++) {
 
-         const pageItem = pageDataArr[pi];
 
-         const currentRptName = rpt_names[pi];
 
-         if (pageItem.items.length > breakAmt) {
 
-             let pa = Math.floor(pageItem.items.length / breakAmt);
 
-             if (pageItem.items.length % breakAmt > 0) {
 
-                 pa++;
 
-             }
 
-             for (let idx = 0; idx < pa; idx++) {
 
-                 const newPageDataObj = { items: [] };
 
-                 // newPageDataObj[JV.NODE_PAGE_INFO] = JSON.parse(JSON.stringify(pageItem[JV.NODE_PAGE_INFO]));
 
-                 newPageDataObj[JV.NODE_PAGE_INFO] = pageItem[JV.NODE_PAGE_INFO];
 
-                 // newPageDataObj[JV.BAND_PROP_MERGE_BAND] = JSON.parse(JSON.stringify(pageItem[JV.BAND_PROP_MERGE_BAND]));
 
-                 newPageDataObj[JV.BAND_PROP_MERGE_BAND] = pageItem[JV.BAND_PROP_MERGE_BAND];
 
-                 newPageDataObj[JV.NODE_FONT_COLLECTION] = pageItem[JV.NODE_FONT_COLLECTION];
 
-                 newPageDataObj[JV.NODE_STYLE_COLLECTION] = pageItem[JV.NODE_STYLE_COLLECTION];
 
-                 newPageDataObj[JV.NODE_CONTROL_COLLECTION] = pageItem[JV.NODE_CONTROL_COLLECTION];
 
-                 for (let dIdx = idx * breakAmt; dIdx < (Math.min((idx + 1) * breakAmt, pageItem.items.length)); dIdx++) {
 
-                     newPageDataObj.items.push(pageItem.items[dIdx]);
 
-                 }
 
-                 rst.push(newPageDataObj);
 
-                 newRptNames.push(currentRptName + '_' + (idx + 1));
 
-             }
 
-         } else {
 
-             rst.push(pageItem);
 
-             newRptNames.push(currentRptName);
 
-         }
 
-     }
 
-     return rst;
 
- }
 
 
  |