| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092 | 
							- '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';
 
- const sourceTypeConst = require('../const/source_type');
 
- module.exports = app => {
 
-     class ReportController extends app.BaseController {
 
-         /**
 
-          * 获取审批界面所需的 原报、审批人数据等
 
-          * @param {Object} ctx - egg全局context
 
-          * @return {void}
 
-          * @private
 
-          */
 
-         async _getStageAuditViewData(ctx) {
 
-             if (!ctx.stage) return;
 
-             await ctx.service.stage.loadStageAuditViewData(ctx.stage);
 
-         }
 
-         async _chkIfStageAuditor(ctx, stage) {
 
-             //
 
-         }
 
-         async _filterStageList(ctx, stageList) {
 
-             //
 
-             // throw
 
-         }
 
-         async _createNodes(ctx, source_type, pid) {
 
-             const treeNodes = await ctx.service.rptTreeNode.getNodesBySourceType([pid], source_type); // 这个查定制的
 
-             const commonTreeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1]); // 这个查通用的
 
-             const nodeItems = JSON.parse(commonTreeNodes[0].items);
 
-             const commonArrs = [];
 
-             nodeItems.forEach(nodeItem => {
 
-                 const srcType = nodeItem.source_type ? nodeItem.source_type : 1;
 
-                 if (srcType === source_type) {
 
-                     commonArrs.push(nodeItem);
 
-                 }
 
-             });
 
-             // 加一个dummy的通用报表
 
-             const dummyCommonRptNode = { id: 1, name: '通用报表', pid: -1, rpt_type: 0, items: JSON.stringify(commonArrs) };
 
-             treeNodes.push(dummyCommonRptNode);
 
-             const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
 
-             return { treeNodes, commonArrs, custCfg };
 
-         }
 
-         async _getInvolveAcc(ctx, tId) {
 
-             // 获取所有项目参与者
 
-             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: tId };
 
-             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;
 
-             });
 
-             return { accountList, newAccountGroup, advance };
 
-         }
 
-         /**
 
-          * 报表显示页面
 
-          *
 
-          * @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, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.tender, tender.data.project_id);
 
-                 const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
 
-                 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);
 
-                     }
 
-                 }
 
-                 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);
 
-                 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 = prjAcc.company;
 
-                 }
 
-                 const cust_select_keys = JSON.stringify(['common', 'customize']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
 
-                 const rpt_tpl_items = { customize: [], common: [] };
 
-                 if (custTreeNodes.length > 0) {
 
-                     const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
 
-                     if (cust_select_item.common) rpt_tpl_items.common = cust_select_item.common;
 
-                     if (cust_select_item.customize) rpt_tpl_items.customize = cust_select_item.customize;
 
-                 }
 
-                 // 获取所有项目参与者
 
-                 const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, this.ctx.tender.id);
 
-                 const renderData = {
 
-                     accountGroup: newAccountGroup,
 
-                     accountList,
 
-                     unitList: JSON.stringify(unitList),
 
-                     tender: tender.data,
 
-                     tenderInfo: tender.info,
 
-                     rpt_tpl_data: JSON.stringify(treeNodes),
 
-                     cust_tpl_data: JSON.stringify(rpt_tpl_items),
 
-                     cust_select_keys,
 
-                     cust_cfg: JSON.stringify(custCfg),
 
-                     project_id: tender.data.project_id,
 
-                     tender_id: tender.id,
 
-                     tender_name: tender.data.name,
 
-                     budget_id: -1,
 
-                     sp_id: -1,
 
-                     detail_id: -1,
 
-                     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),
 
-                     auditType: auditConst.auditType,
 
-                     source_type: 1,
 
-                     bglObj: 'null',
 
-                     changes: 'null',
 
-                 };
 
-                 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');
 
-             }
 
-         }
 
-         async indexForPaymentSafe(ctx) {
 
-             // 安全生产费入口
 
-             try {
 
-                 await this._getStageAuditViewData(ctx);
 
-                 const pageShow = ctx.session.sessionProject.page_show;
 
-                 // pageShow.showArchive = 1;
 
-                 pageShow.showArchive = 0;
 
-                 // pageShow.closeWatermark = 1;
 
-                 const tenderId = ctx.params.id;
 
-                 const paymentDetail_id = ctx.params.did;
 
-                 // 支付审批: ctx.params.did 是 zh_payment_detail表的id, 通过这个did在 zh_payment_detail_audit表里找审核信息(td_id = ctx.params.did)
 
-                 //          没有计量期的概念!!!
 
-                 // const paymentAuditorList = await ctx.service.paymentDetailAudit.getAuditors(paymentDetail_id);
 
-                 const tender = ctx.paymentTender;
 
-                 const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.payment_safe, tender.pid);
 
-                 const stageList = [];
 
-                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.pid } }); // 找公司章用的
 
-                 const isAdmin = ctx.session.sessionUser.is_admin;
 
-                 const lastAuditor = null;
 
-                 const archiveList = [];
 
-                 let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(tender.pid);
 
-                 const roleList = await ctx.service.signatureRole.getSignatureRolesByTenderId(tender.id);
 
-                 const usedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(tender.id);
 
-                 // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
 
-                 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 = [];
 
-                 const cid = this.ctx.helper._.map(treeNodes, 'id');
 
-                 const customSelects = null;
 
-                 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();
 
-                 const stage_id = -100;
 
-                 let stage_order = -1;
 
-                 let sorder = -1;
 
-                 let stage_times = -1;
 
-                 let stage_status = -1;
 
-                 const paymentDetailList = await ctx.service.paymentDetail.getDetail(paymentDetail_id);
 
-                 if (paymentDetailList && paymentDetailList.length > 0) {
 
-                     const payment = paymentDetailList[0];
 
-                     stage_status = payment.status;
 
-                     stage_order = payment.order;
 
-                     sorder = stage_order;
 
-                     stage_times = payment.times;
 
-                     stageList.push({ id: stage_id, user_id: payment.uid, status: payment.status });
 
-                 }
 
-                 for (const prjAcc of prjAccList) {
 
-                     prjAcc.account_group = prjAcc.company;
 
-                 }
 
-                 const cust_select_keys = JSON.stringify(['common_safe', 'customize_safe']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求,安全生产费没有这个,就过了
 
-                 const rpt_tpl_items = { customize: [], common: [] };
 
-                 commonArrs.forEach(item => {
 
-                     rpt_tpl_items.common.push(item.name);
 
-                 });
 
-                 // 获取所有项目参与者
 
-                 const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
 
-                 const renderData = {
 
-                     accountGroup: newAccountGroup,
 
-                     accountList,
 
-                     unitList: JSON.stringify(unitList),
 
-                     tender: null,
 
-                     tenderInfo: null,
 
-                     rpt_tpl_data: JSON.stringify(treeNodes),
 
-                     cust_tpl_data: JSON.stringify(rpt_tpl_items),
 
-                     cust_select_keys,
 
-                     cust_cfg: JSON.stringify(custCfg),
 
-                     project_id: tender.pid,
 
-                     tender_id: tenderId,
 
-                     tender_name: tender.name,
 
-                     detail_id: paymentDetail_id,
 
-                     stg_id: stage_id,
 
-                     budget_id: -1,
 
-                     sp_id: -1,
 
-                     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/' + tenderId + '/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,
 
-                     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),
 
-                     source_type: 101,
 
-                     bglObj: 'null',
 
-                     changes: 'null',
 
-                 };
 
-                 /*
 
-                 //*/
 
-                 await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
 
-             } catch (err) {
 
-                 this.log(err);
 
-                 // ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage');
 
-             }
 
-         }
 
-         async indexForDynamicGrandTotal(ctx) {
 
-             // 动态决算(动态投资)入口 (以独立报表为蓝本(index入口))
 
-             try {
 
-                 await this._getStageAuditViewData(ctx);
 
-                 const pageShow = ctx.session.sessionProject.page_show;
 
-                 // pageShow.closeWatermark = 1;
 
-                 pageShow.showArchive = 0;
 
-                 pageShow.closeShowAllCustomized = 0;
 
-                 const tenderId = -1;
 
-                 const paymentDetail_id = -1;
 
-                 // const tender = ctx.paymentTender;
 
-                 const pid = ctx.budget.pid;
 
-                 const budget_id = ctx.budget.id;
 
-                 const subProj = await ctx.service.subProject.getDataByCondition({ budget_id });
 
-                 const sp_id = subProj.id;
 
-                 const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.budget, pid);
 
-                 const stageList = [];
 
-                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid } }); // 找公司章用的
 
-                 const isAdmin = ctx.session.sessionUser.is_admin;
 
-                 const lastAuditor = null;
 
-                 const archiveList = [];
 
-                 let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(pid);
 
-                 const roleList = [];
 
-                 const usedList = [];
 
-                 // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
 
-                 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 = [];
 
-                 const cid = this.ctx.helper._.map(treeNodes, 'id');
 
-                 const customSelects = null;
 
-                 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();
 
-                 const stage_id = -200;
 
-                 const stage_order = -1;
 
-                 const sorder = -1;
 
-                 const stage_times = -1;
 
-                 const stage_status = -1;
 
-                 for (const prjAcc of prjAccList) {
 
-                     prjAcc.account_group = prjAcc.company;
 
-                 }
 
-                 const cust_select_keys = JSON.stringify(['common_dynamic', 'customize_dynamic']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
 
-                 const rpt_tpl_items = { customize: [], common: [] };
 
-                 const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
 
-                 if (custTreeNodes.length > 0) {
 
-                     const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
 
-                     if (cust_select_item.common_dynamic) rpt_tpl_items.common = cust_select_item.common_dynamic;
 
-                     if (cust_select_item.customize_dynamic) rpt_tpl_items.customize = cust_select_item.customize_dynamic;
 
-                     if (!cust_select_item.hasOwnProperty('common_dynamic') && !cust_select_item.hasOwnProperty('customize_dynamic')) {
 
-                         commonArrs.forEach(item => {
 
-                             rpt_tpl_items.common.push(item.name);
 
-                         });
 
-                     }
 
-                 } else {
 
-                     commonArrs.forEach(item => {
 
-                         rpt_tpl_items.common.push(item.name);
 
-                     });
 
-                 }
 
-                 // 获取所有项目参与者
 
-                 const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
 
-                 const renderData = {
 
-                     accountGroup: newAccountGroup,
 
-                     accountList,
 
-                     unitList: JSON.stringify(unitList),
 
-                     tender: null,
 
-                     tenderInfo: null,
 
-                     rpt_tpl_data: JSON.stringify(treeNodes),
 
-                     cust_tpl_data: JSON.stringify(rpt_tpl_items),
 
-                     cust_select_keys,
 
-                     cust_cfg: JSON.stringify(custCfg),
 
-                     project_id: pid,
 
-                     tender_id: tenderId,
 
-                     budget_id,
 
-                     sp_id,
 
-                     tender_name: ctx.budget.name,
 
-                     detail_id: paymentDetail_id,
 
-                     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/' + tenderId + '/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,
 
-                     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),
 
-                     source_type: 200,
 
-                     bglObj: 'null',
 
-                     changes: 'null',
 
-                 };
 
-                 await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
 
-             } catch (err) {
 
-                 this.log(err);
 
-             }
 
-         }
 
-         async _indexForBGL(ctx, source_type, stage_id) {
 
-             // 变更令、变更方案、变更立项、变更申请 报表入口
 
-             try {
 
-                 await this._getStageAuditViewData(ctx);
 
-                 const pageShow = ctx.session.sessionProject.page_show;
 
-                 pageShow.closeWatermark = 1;
 
-                 pageShow.showArchive = 1;
 
-                 pageShow.closeShowAllCustomized = 0;
 
-                 const tenderId = ctx.params.id;
 
-                 const bglObj = {};
 
-                 if (stage_id === -300) {
 
-                     bglObj.BUSINESS_ID = ctx.params.cid;
 
-                     bglObj.change = await ctx.service.change.getChangeByCid(ctx.params.cid);
 
-                     bglObj.currentBz = bglObj.change;
 
-                     bglObj.status = bglObj.change.status;
 
-                     // const audit = await ctx.service.changeAudit.getChangeByCid(ctx.params.cid);
 
-                 }
 
-                 if (stage_id === -301) {
 
-                     bglObj.BUSINESS_ID = ctx.params.cplnid;
 
-                     bglObj.change_plan = await ctx.service.changePlan.getDataById(ctx.params.cplnid);
 
-                     bglObj.currentBz = bglObj.change_plan;
 
-                     bglObj.status = bglObj.change_plan.status;
 
-                 }
 
-                 if (stage_id === -302) {
 
-                     bglObj.BUSINESS_ID = ctx.params.cprjid;
 
-                     bglObj.change_project = await ctx.service.changeProject.getDataById(ctx.params.cprjid);
 
-                     bglObj.currentBz = bglObj.change_project;
 
-                     bglObj.status = bglObj.change_project.status;
 
-                 }
 
-                 if (stage_id === -303) {
 
-                     bglObj.BUSINESS_ID = ctx.params.caid;
 
-                     bglObj.change_apply = await ctx.service.changeApply.getDataById(ctx.params.caid);
 
-                     bglObj.currentBz = bglObj.change_apply;
 
-                     bglObj.status = bglObj.change_apply.status;
 
-                 }
 
-                 const changeId = ctx.params.cid;
 
-                 const paymentDetail_id = -1;
 
-                 const pid = ctx.session.sessionProject.id;
 
-                 const budget_id = -1;
 
-                 const sp_id = -1;
 
-                 const { treeNodes, custCfg } = await this._createNodes(ctx, source_type, pid);
 
-                 const state = ctx.session.sessionProject.page_show.openChangeState && ctx.query.state ? parseInt(ctx.query.state) : 0;
 
-                 const changes = await ctx.service.change.getListByStatus(tenderId, 0, 0, 0, 0, state);
 
-                 let change_times = 1;
 
-                 const stageList = [];
 
-                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid } }); // 找公司章用的
 
-                 const isAdmin = ctx.session.sessionUser.is_admin;
 
-                 let lastAuditor = null;
 
-                 for (let cIdx = 0; cIdx < changes.length; cIdx++) {
 
-                     if (changes[cIdx].cid === changeId) {
 
-                         if (changes[cIdx].times > change_times) change_times = changes[cIdx].times;
 
-                         if (changes[cIdx].status === 3) {
 
-                             const changeAudit = await ctx.service.changeAudit.getLastUser(changeId, changes[cIdx].times, 3);
 
-                             if (changeAudit) {
 
-                                 lastAuditor = { end_time: changeAudit.sin_time, sdesc: changeAudit.sdesc };
 
-                             }
 
-                         }
 
-                         break;
 
-                     }
 
-                 }
 
-                 let archiveList = [];
 
-                 const archives = await ctx.service.rptArchive.getArchiveByBzId(pid, stage_id, bglObj.BUSINESS_ID);
 
-                 if (archives.length > 0) {
 
-                     archiveList = JSON.parse(archives[0].content);
 
-                 }
 
-                 let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(pid);
 
-                 const roleList = [];
 
-                 const usedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(tenderId);
 
-                 // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
 
-                 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 = [];
 
-                 const cid = this.ctx.helper._.map(treeNodes, 'id');
 
-                 const customSelects = null;
 
-                 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();
 
-                 const stage_order = -1;
 
-                 const sorder = -1;
 
-                 const stage_times = -1;
 
-                 const stage_status = -1;
 
-                 for (const prjAcc of prjAccList) {
 
-                     // prjAcc.account_group = accountGroup[prjAcc.account_group];
 
-                     prjAcc.account_group = prjAcc.company;
 
-                 }
 
-                 const cust_select_keys = JSON.stringify(['common', 'customize']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
 
-                 const rpt_tpl_items = { customize: [], common: [] };
 
-                 if (treeNodes && treeNodes.length > 0) {
 
-                     for (let tIdx = treeNodes.length - 1; tIdx >= 0; tIdx--) {
 
-                         if (treeNodes[tIdx].name === '通用报表') {
 
-                             const items = JSON.parse(treeNodes[tIdx].items);
 
-                             for (let itemIdx = items.length - 1; itemIdx >= 0; itemIdx--) {
 
-                                 rpt_tpl_items.common.push(items[itemIdx].name);
 
-                             }
 
-                         } else {
 
-                             rpt_tpl_items.customize.push(treeNodes[tIdx].name);
 
-                         }
 
-                     }
 
-                 }
 
-                 // 获取所有项目参与者
 
-                 const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
 
-                 const renderData = {
 
-                     accountGroup: newAccountGroup,
 
-                     accountList,
 
-                     unitList: JSON.stringify(unitList),
 
-                     tender: null,
 
-                     tenderInfo: null,
 
-                     rpt_tpl_data: JSON.stringify(treeNodes),
 
-                     cust_tpl_data: JSON.stringify(rpt_tpl_items),
 
-                     cust_select_keys,
 
-                     cust_cfg: JSON.stringify(custCfg),
 
-                     project_id: pid,
 
-                     tender_id: tenderId,
 
-                     budget_id,
 
-                     sp_id,
 
-                     tender_name: ctx.tender.data.name,
 
-                     detail_id: paymentDetail_id,
 
-                     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/' + tenderId + '/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,
 
-                     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),
 
-                     source_type,
 
-                     bglObj: JSON.stringify(bglObj),
 
-                     changes: JSON.stringify(changes),
 
-                     bizId: bglObj.BUSINESS_ID,
 
-                 };
 
-                 await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
 
-             } catch (err) {
 
-                 this.log(err);
 
-             }
 
-         }
 
-         async indexForChange(ctx) {
 
-             // 变更令报表入口
 
-             await this._indexForBGL(ctx, sourceTypeConst.sourceType.change, -300);
 
-         }
 
-         async indexForChangePlan(ctx) {
 
-             // 变更方案报表入口
 
-             await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_plan, -301);
 
-         }
 
-         async indexForChangeProject(ctx) {
 
-             // 变更立项报表入口
 
-             await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_project, -302);
 
-         }
 
-         async indexForChangeApply(ctx) {
 
-             // 变更申请报表入口
 
-             await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_apply, -303);
 
-         }
 
-         /**
 
-          * 报表打印页面
 
-          *
 
-          * @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);
 
-             }
 
-         }
 
-         _mergeBlankRoleSignDate(roleRel, auditors) {
 
-             // 有些签名信息的sign_date是空白的(从前一业务copy过来并清理),需要根据审核信息来自动填写上审核时间
 
-             // 1. 用户ID 2. sign_date为空白
 
-             if (roleRel && auditors) {
 
-                 roleRel.forEach(record => {
 
-                     const contents = JSON.parse(record.rel_content);
 
-                     let hasMerge = false;
 
-                     contents.forEach(role => {
 
-                         if (!role.sign_date || role.sign_date === '') {
 
-                             auditors.forEach(audit => {
 
-                                 if (audit.aid === role.acc_id) {
 
-                                     role.sign_date = audit.end_time;
 
-                                     hasMerge = true;
 
-                                 }
 
-                             });
 
-                         }
 
-                     });
 
-                     if (hasMerge) {
 
-                         record.rel_content = JSON.stringify(contents);
 
-                     }
 
-                 });
 
-             }
 
-         }
 
-         async _commonGetAudit(ctx, params, stgAudit) {
 
-             switch (params.stage_id) {
 
-                 case -300: // 变更令
 
-                     const changeAudit = await ctx.service.changeAudit.getAuditors(params.change_id, params.change_times, true);
 
-                     const change = await ctx.service.change.getChangeByCid(params.change_id);
 
-                     let orgChangeStatus = 3;
 
-                     if ([1, 9].includes(change.status)) orgChangeStatus = 1; // 原报只要已上报(非1、9),status都是3
 
-                     stgAudit.push({ aid: change.uid, status: orgChangeStatus, opinion: '', end_time: change.in_time, order: 0 }); // 加上原报
 
-                     changeAudit.forEach(audit => {
 
-                         stgAudit.push({ aid: audit.uid, status: audit.status, opinion: audit.sdesc, end_time: audit.sin_time, order: audit.usite });
 
-                     });
 
-                     break;
 
-                 case -301: // 变更方案
 
-                     const changePlanAudit = await ctx.service.changePlanAudit.getAuditors(params.business_id, params.change_plan_times, true);
 
-                     const change_plan = await ctx.service.changePlan.getDataById(params.business_id);
 
-                     let orgChangePlanStatus = 3;
 
-                     if ([1, 9].includes(change_plan.status)) orgChangePlanStatus = 1; // 原报只要已上报(非1、9),status都是3
 
-                     stgAudit.push({ aid: change_plan.uid, status: orgChangePlanStatus, opinion: '', end_time: change_plan.in_time, order: 0 }); // 加上原报
 
-                     changePlanAudit.forEach(audit => {
 
-                         stgAudit.push({ aid: audit.aid, status: audit.status, opinion: audit.opinion, end_time: audit.end_time, times: audit.times, order: audit.order });
 
-                     });
 
-                     break;
 
-                 case -302: // 变更立项
 
-                     const changeProjectAudit = await ctx.service.changeProjectAudit.getAuditors(params.business_id, params.change_project_times, true);
 
-                     const change_project = await ctx.service.changeProject.getDataById(params.business_id);
 
-                     let orgChangePrjStatus = 3;
 
-                     if ([1, 9].includes(change_project.status)) orgChangePrjStatus = 1; // 原报只要已上报(非1、9),status都是3
 
-                     stgAudit.push({ aid: change_project.uid, status: orgChangePrjStatus, opinion: '', end_time: change_project.in_time, order: 0 }); // 加上原报
 
-                     changeProjectAudit.forEach(audit => {
 
-                         stgAudit.push({ aid: audit.aid, status: audit.status, opinion: audit.opinion, end_time: audit.end_time, times: audit.times, order: audit.order });
 
-                     });
 
-                     break;
 
-                 case -303: // 变更申请
 
-                     const changeApplyAudit = await ctx.service.changeApplyAudit.getAuditors(params.business_id, params.change_apply_times, true);
 
-                     const change_apply = await ctx.service.changeApply.getDataById(params.business_id);
 
-                     let orgChangeApplyStatus = 3;
 
-                     if ([1, 9].includes(change_apply.status)) orgChangeApplyStatus = 1; // 原报只要已上报(非1、9),status都是3
 
-                     stgAudit.push({ aid: change_apply.uid, status: orgChangeApplyStatus, opinion: '', end_time: change_apply.in_time, order: 0 }); // 加上原报
 
-                     changeApplyAudit.forEach(audit => {
 
-                         stgAudit.push({ aid: audit.aid, status: audit.status, opinion: audit.opinion, end_time: audit.end_time, times: audit.times, order: audit.order });
 
-                     });
 
-                     break;
 
-                 default:
 
-                     break;
 
-             }
 
-         }
 
-         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 '获取模板失败';
 
-             }
 
-             const source_type = params.source_type ? params.source_type : rptTpl[0].source_type;
 
-             rptTpl = JSON.parse(rptTpl[0].rpt_content);
 
-             rptTpl.source_type = source_type || sourceTypeConst.defaultSourceType;
 
-             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 = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id, params.stage_id, params.business_id); // 新需求中,允许在非审核状态下设置签名
 
-             let stgAudit = null,
 
-                 stgAuditForOrg = null,
 
-                 stageFlow = null,
 
-                 stageList = [];
 
-             if (params.stage_id > 0) {
 
-                 stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
 
-                 stgAuditForOrg = await ctx.service.stageAudit.getStageAudit(params.stage_id, 1);
 
-                 stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
 
-                 stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(params.stage_id, params.stage_times);
 
-             } else if ([-100, -200].includes(params.stage_id)) {
 
-                 stgAudit = await ctx.service.paymentDetailAudit.getAuditors(params.detail_id, params.stage_times);
 
-                 stgAuditForOrg = await ctx.service.paymentDetailAudit.getAuditors(params.detail_id, 1);
 
-                 stageFlow = await ctx.service.paymentDetailAudit.getAuditorsWithOwner(params.detail_id);
 
-                 const paymentDetailList = await ctx.service.paymentDetail.getDetail(params.detail_id);
 
-                 if (paymentDetailList && paymentDetailList.length > 0) {
 
-                     const payment = paymentDetailList[0];
 
-                     stageList.push({ id: params.stage_id, user_id: payment.uid, status: payment.status });
 
-                 }
 
-             } else if ([-300, -301, -302, -303].includes(params.stage_id)) {
 
-                 // 变更令相关的
 
-                 stgAudit = [];
 
-                 stgAuditForOrg = [];
 
-                 stageFlow = [];
 
-                 await this._commonGetAudit(ctx, params, stgAudit);
 
-                 stgAudit.sort(function(stg1, stg2) {
 
-                     return stg1.order - stg2.order;
 
-                 });
 
-                 this._mergeBlankRoleSignDate(roleRel, stgAudit);
 
-             }
 
-             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;
 
-             }
 
-             if (params.stage_id > 0) {
 
-                 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 roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id, params.business_id); // 新需求:在审批流程中的签名需要显示
 
-             roleRel.sort(function(rr1, rr2) {
 
-                 return params.rpt_ids.indexOf(parseInt(rr1.rpt_id)) - params.rpt_ids.indexOf(parseInt(rr2.rpt_id));
 
-             });
 
-             let stgAudit = null,
 
-                 stageList = [];
 
-             if (params.stage_id > 0) {
 
-                 stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
 
-                 stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
 
-             } else if ([-100, -200].includes(params.stage_id)) {
 
-                 stgAudit = await ctx.service.paymentDetailAudit.getAuditors(params.detail_id);
 
-                 const paymentDetailList = await ctx.service.paymentDetail.getDetail(params.detail_id);
 
-                 if (paymentDetailList && paymentDetailList.length > 0) {
 
-                     const payment = paymentDetailList[0];
 
-                     stageList.push({ id: params.stage_id, user_id: payment.uid, status: payment.status });
 
-                 }
 
-             } else if ([-300, -301, -302, -303].includes(params.stage_id)) {
 
-                 stgAudit = [];
 
-                 await this._commonGetAudit(ctx, params, stgAudit);
 
-                 this._mergeBlankRoleSignDate(roleRel, stgAudit);
 
-             }
 
-             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, params.business_id)) : [];
 
-             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 = [];
 
-             // 1. merge签名相关信息
 
-             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 = params.nodeItems;
 
-             const custSelectKeys = params.custSelectKeys;
 
-             const rst = await ctx.service.rptTreeNodeCust.updateCustNode(custId, newNodeItems, custSelectKeys);
 
-             // 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;
 
-                     }
 
-                 }
 
-                 // _mergeSingle(dtlPage, dftRolRel, true, status !== 3);
 
-                 _mergeSingle(dtlPage, dftRolRel, false, 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) {
 
-             rect[0] = rect[0] > cell.area.Left ? cell.area.Left : rect[0];
 
-             rect[1] = rect[1] > cell.area.Top ? cell.area.Top : rect[1];
 
-             rect[2] = rect[2] < cell.area.Right ? cell.area.Right : rect[2];
 
-             rect[3] = rect[3] < cell.area.Bottom ? cell.area.Bottom : rect[3];
 
-         }
 
-         for (const sCell of page.signature_cells) {
 
-             rect[0] = rect[0] > sCell.area.Left ? sCell.area.Left : rect[0];
 
-             rect[1] = rect[1] > sCell.area.Top ? sCell.area.Top : rect[1];
 
-             rect[2] = rect[2] < sCell.area.Right ? sCell.area.Right : rect[2];
 
-             rect[3] = rect[3] < sCell.area.Bottom ? sCell.area.Bottom : rect[3];
 
-         }
 
-         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;
 
- }
 
 
  |