report_controller.js 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. 'use strict';
  2. /**
  3. * Created by Tony on 2019/7/5.
  4. */
  5. const tenderMenu = require('../../config/menu').tenderMenu;
  6. const measureType = require('../const/tender').measureType;
  7. const auditConst = require('../const/audit');
  8. const shenpiConst = require('../const/shenpi');
  9. const accountGroup = require('../const/account_group').group;
  10. const JpcEx = require('../reports/rpt_component/jpc_ex');
  11. const JV = require('../reports/rpt_component/jpc_value_define');
  12. const rpt_xl_util = require('../reports/util/rpt_excel_util');
  13. const rptDataExtractor = require('../reports/util/rpt_calculation_data_util');
  14. const fsUtil = require('../public/js/fsUtil');
  15. const fs = require('fs');
  16. const rptCronJob = require('../reports/util/rpt_tmp_file_sweep');
  17. const RPT_DEF_PROPERTIES = require('../const/report_defined_properties');
  18. const reportConst = require('../const/report');
  19. // const stringUtil = require('../public/js/string_util_light');
  20. const needCustomTables = [
  21. 'mem_custom_select',
  22. 'mem_gather_stage_bills', 'mem_gather_deal_bills', 'mem_gather_stage_pay', 'mem_gather_tender_info',
  23. 'mem_stage_sum_bills', 'mem_stage_sum_pay',
  24. 'mem_jh_gather_im_change', 'mem_jh_im_change', 'mem_jh_gather_stage_bills_compare',
  25. 'mem_material_sum_gl',
  26. ];
  27. const PermissionCheck = require('../const/account_permission').PermissionCheck;
  28. const STD_COMP_STAMP_SIZE_WIDTH = Math.round(5 * 96 / 2.54); // 公章标准尺寸(宽4.2厘米)转成像素
  29. const STD_COMP_STAMP_SIZE_HEIGHT = STD_COMP_STAMP_SIZE_WIDTH; // 公章标准尺寸(高4.2厘米)转成像素
  30. const NORMAL_SIGN_STR = 'normal_sign';
  31. const COMPANY_SIGN_STR = 'company_stamp';
  32. const PRIVATE_SIGN_STR = 'private_stamp';
  33. module.exports = app => {
  34. class ReportController extends app.BaseController {
  35. /**
  36. * 获取审批界面所需的 原报、审批人数据等
  37. * @param {Object} ctx - egg全局context
  38. * @return {void}
  39. * @private
  40. */
  41. async _getStageAuditViewData(ctx) {
  42. if (!ctx.stage) return;
  43. const times = ctx.stage.status === auditConst.stage.status.checkNo ? ctx.stage.times - 1 : ctx.stage.times;
  44. ctx.stage.user = await ctx.service.projectAccount.getAccountInfoById(ctx.stage.user_id);
  45. ctx.stage.auditHistory = [];
  46. if (times >= 1) {
  47. for (let i = 1; i <= times; i++) {
  48. ctx.stage.auditHistory.push(await ctx.service.stageAudit.getAuditors(ctx.stage.id, i));
  49. }
  50. }
  51. // 获取审批流程中左边列表
  52. ctx.stage.auditors2 = await ctx.service.stageAudit.getAuditGroupByListWithOwner(ctx.stage.id, times);
  53. if (ctx.stage.status === auditConst.stage.status.uncheck || ctx.stage.status === auditConst.stage.status.checkNo) {
  54. ctx.stage.auditorList = await ctx.service.stageAudit.getAuditors(ctx.stage.id, ctx.stage.times);
  55. }
  56. }
  57. async _chkIfStageAuditor(ctx, stage) {
  58. //
  59. }
  60. async _filterStageList(ctx, stageList) {
  61. //
  62. // throw
  63. }
  64. /**
  65. * 报表显示页面
  66. *
  67. * @param {Object} ctx - egg全局context
  68. * @return {void}
  69. */
  70. async index(ctx) {
  71. try {
  72. await this._getStageAuditViewData(ctx);
  73. const pageShow = ctx.session.sessionProject.page_show;
  74. pageShow.showArchive = 1;
  75. const tender = ctx.tender;
  76. const stage = ctx.stage;
  77. let stage_id = -1;
  78. let stage_order = -1;
  79. let sorder = -1;
  80. let stage_times = -1;
  81. let stage_status = -1;
  82. const treeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1, tender.data.project_id]);
  83. const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
  84. const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
  85. const stageList = await ctx.service.stage.getValidStagesShort(tender.id);
  86. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.data.project_id } }); // 找公司章用的
  87. const isAdmin = ctx.session.sessionUser.is_admin;
  88. // console.log('this.ctx.session.sessionUser.accountId: ' + this.ctx.session.sessionUser.accountId);
  89. if (stage && stage.status === auditConst.stage.status.uncheck) {
  90. // 得判断账号是否在审核人列表中(不含原报)
  91. if (stage.auditorList === undefined || stage.auditorList === null) {
  92. stage.auditorList = await ctx.service.stageAudit.getAuditors(ctx.stage.id, ctx.stage.times);
  93. }
  94. let isAudit = false;
  95. for (const audit of stage.auditorList) {
  96. if (audit.aid === this.ctx.session.sessionUser.accountId) {
  97. isAudit = true;
  98. break;
  99. }
  100. }
  101. if (isAudit) {
  102. throw '未上报!';
  103. }
  104. } else {
  105. // 剔除未上报期(审核人(非原报人)才需要判断)
  106. for (let idx = stageList.length - 1; idx >= 0; idx--) {
  107. if (stageList[idx].status === auditConst.stage.status.uncheck) {
  108. if (stageList[idx].auditorList === undefined || stageList[idx].auditorList === null) {
  109. stageList[idx].auditorList = await ctx.service.stageAudit.getAuditors(stageList[idx].id, stageList[idx].times);
  110. }
  111. let isAudit = false;
  112. for (const audit of stageList[idx].auditorList) {
  113. if (audit.aid === this.ctx.session.sessionUser.accountId) {
  114. isAudit = true;
  115. break;
  116. }
  117. }
  118. if (isAudit) {
  119. stageList.splice(idx, 1);
  120. }
  121. }
  122. }
  123. }
  124. let lastAuditor = null;
  125. if (stage) {
  126. lastAuditor = await ctx.service.stageAudit.getLastestAuditor(ctx.stage.id, ctx.stage.times, auditConst.stage.status.checked);
  127. } else {
  128. lastAuditor = stageList.length > 0 ? await ctx.service.stageAudit.getLastestAuditor(stageList[stageList.length - 1].id, stageList[stageList.length - 1].times, auditConst.stage.status.checked) : null;
  129. }
  130. let archiveList = [];
  131. if (stage) {
  132. const archives = await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, ctx.stage.id);
  133. if (archives.length > 0) {
  134. archiveList = JSON.parse(archives[0].content);
  135. }
  136. } else {
  137. const archives = stageList.length > 0 ? await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, stageList[stageList.length - 1].id) : [];
  138. // console.log(archives);
  139. if (archives && archives.length > 0) {
  140. archiveList = JSON.parse(archives[0].content);
  141. }
  142. }
  143. // const archiveList = await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, ctx.stage.id);
  144. let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(tender.data.project_id);
  145. const roleList = await ctx.service.signatureRole.getSignatureRolesByTenderId(tender.id);
  146. const usedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(tender.id);
  147. // ctx.session.sessionUser.is_admin
  148. // const pageShow = ctx.session.sessionProject.page_show;
  149. // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
  150. if (!ctx.session.sessionUser.is_admin && pageShow.individualSign === 1) {
  151. // 削减其他account
  152. const newAccList = [];
  153. for (const acc of prjAccList) {
  154. if (acc.id === this.ctx.session.sessionUser.accountId) {
  155. newAccList.push(acc);
  156. }
  157. }
  158. prjAccList = newAccList;
  159. }
  160. // 分类列表
  161. const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
  162. // 获取用户权限
  163. const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
  164. const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
  165. // 获取用户可查看的标段
  166. const tenderList = await this.ctx.service.tender.getList('', userPermission);
  167. for (const t of tenderList) {
  168. if (t.ledger_status === auditConst.ledger.status.checked) {
  169. t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
  170. // if (t.lastStage) {
  171. // await this.ctx.service.stage.checkStageGatherData(t.lastStage, this.ctx.session.sessionUser.is_admin);
  172. // }
  173. }
  174. }
  175. // 获取汇总表,历史选择
  176. const cid = this.ctx.helper._.map(treeNodes, 'id');
  177. const customSelects = {};
  178. if (ctx.stage) {
  179. customSelects.audit_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  180. reportConst.rptCustomType[JV.NODE_CUS_AUDIT_SELECT], ctx.tender.id, ctx.stage.id);
  181. customSelects.stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(
  182. ctx.stage.stage_id, ctx.stage.stage_times);
  183. customSelects.stageFlow.forEach(x => {
  184. if (!x) return;
  185. x.visible = (!ctx.session.sessionUser.is_admin && ctx.session.sessionProject.page_show.individualSign === 1)
  186. ? x.aid === ctx.session.sessionUser.accountId : true;
  187. });
  188. } else {
  189. customSelects.audit_select = [];
  190. }
  191. customSelects.gather_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  192. reportConst.rptCustomType[JV.NODE_CUS_GATHER_SELECT], ctx.tender.id, -1);
  193. customSelects.stage_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  194. reportConst.rptCustomType[JV.NODE_CUS_STAGE_SELECT], ctx.tender.id, -1);
  195. customSelects.change_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  196. reportConst.rptCustomType[JV.NODE_CUS_CHANGE_SELECT], ctx.tender.id, -1);
  197. customSelects.material_sum_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  198. reportConst.rptCustomType[JV.NODE_CUS_MATERIAL_SUM_SELECT], ctx.tender.id, -1);
  199. const dataSelects = {};
  200. dataSelects.material_select = await ctx.service.rptCustomDefine.getDataSelectByRpt(cid,
  201. reportConst.rptDataType[JV.NODE_CUS_MATERIAL_SELECT]);
  202. const materialList = await ctx.service.material.getValidMaterials(ctx.tender.id);
  203. // const allTpls = await ctx.service.rptTpl.getAllTplByIds(tmpRptIds);
  204. // for (const tpl of allTpls) {
  205. // const fName = tpl.id + '_' + tpl.rpt_tpl_name + '.js';
  206. // console.log('fName: ' + fName);
  207. // fsUtil.writeObjToFile(tpl, 'D:/Temp/计量临时/' + fName);
  208. // }
  209. // 完成历史任务,下一批
  210. // const filePath = 'D:/Temp/计量临时/';
  211. // const tplFiles = [];
  212. // fs.readdir(filePath, (err, files) => {
  213. // if (err) throw err;
  214. // files.forEach(file => {
  215. // const fPath = filePath + file;
  216. // // console.log('\'' + fPath + '\'');
  217. // tplFiles.push(fPath);
  218. // });
  219. // });
  220. //
  221. // setTimeout(function() {
  222. // console.log(tplFiles);
  223. // }, 2000);
  224. // 下一批
  225. // let cnt = 0;
  226. // for (const file of rptFiles) {
  227. // const tplObj = JSON.parse(fs.readFileSync(file, 'utf-8'));
  228. // const rst = await ctx.service.rptTpl.insertRptTpl(tplObj);
  229. // cnt++;
  230. // console.log(file);
  231. // }
  232. // console.log(cnt + ' 完成!');
  233. // console.log(maxStageAmt[0].maxAmt);
  234. // 备注:在报表界面初始化的时候,暂时不需要check stage,只有在点中某张表的时候才需要(签名交互需要)
  235. // if ((stage === null || stage === undefined) && stageList.length > 0) {
  236. // await ctx.service.stage.checkStage(stageList[stageList.length - 1].id);
  237. // stage = ctx.stage;
  238. // console.log(stage);
  239. // }
  240. if (stage !== null && stage !== undefined) {
  241. stage_id = stage.id;
  242. stage_order = stage.order;
  243. sorder = stage.curOrder;
  244. stage_times = stage.times;
  245. stage_status = stage.status;
  246. }
  247. for (const prjAcc of prjAccList) {
  248. prjAcc.account_group = accountGroup[prjAcc.account_group];
  249. }
  250. let rpt_tpl_items = '{ customize: [], common: [] }';
  251. if (custTreeNodes.length > 0) {
  252. rpt_tpl_items = custTreeNodes[0].rpt_tpl_items;
  253. }
  254. // 获取所有项目参与者
  255. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  256. where: { project_id: ctx.session.sessionProject.id, enable: 1 },
  257. columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
  258. });
  259. const newAccountGroup = accountGroup.map((item, idx) => {
  260. const groupList = accountList.filter(item => item.account_group === idx);
  261. return { groupName: item, groupList };
  262. });
  263. const renderData = {
  264. accountGroup: newAccountGroup,
  265. accountList,
  266. unitList: JSON.stringify(unitList),
  267. tender: tender.data,
  268. tenderInfo: tender.info,
  269. rpt_tpl_data: JSON.stringify(treeNodes),
  270. cust_tpl_data: rpt_tpl_items,
  271. cust_cfg: JSON.stringify(custCfg),
  272. project_id: tender.data.project_id,
  273. tender_id: tender.id,
  274. tender_name: tender.data.name,
  275. stg_id: stage_id,
  276. stg_order: stage_order,
  277. cur_order: sorder,
  278. stg_times: stage_times,
  279. stg_status: stage_status,
  280. stage_list: JSON.stringify(stageList),
  281. prj_account_list: JSON.stringify(prjAccList),
  282. role_list: JSON.stringify(roleList),
  283. used_list: JSON.stringify(usedList),
  284. tenderMenu,
  285. preUrl: '/tender/' + ctx.tender.id + '/measure/stage/' + ctx.params.order,
  286. measureType,
  287. categoryData,
  288. tenderList,
  289. auditConst: auditConst.stage,
  290. ledgerAuditConst: auditConst.ledger,
  291. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.report.main),
  292. customSelects,
  293. rptCustomType: reportConst.rptCustomType,
  294. materialList,
  295. stages: stageList,
  296. dataSelects,
  297. // pageShow: JSON.stringify(pageShow),
  298. pageShow,
  299. authMobile: accountInfo.auth_mobile,
  300. shenpiConst,
  301. archiveList,
  302. lastAuditor,
  303. rpt_id: ctx.query.rpt_id,
  304. isAdmin,
  305. OSS_PATH: ctx.app.config.fujianOssPath,
  306. viewPmData: PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission),
  307. };
  308. await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
  309. // await this.layout('report/index.ejs', renderData);
  310. // 在这里启动一个cron job,删除临时创建的excel文件
  311. if (!rptCronJob.started) {
  312. try {
  313. // console.log('rptCronJob.started: ' + rptCronJob.started);
  314. rptCronJob.started = true;
  315. // console.log('this.app.baseDir: ' + this.app.baseDir);
  316. rptCronJob.createJob(null, this.app.baseDir + '/app/public/download');
  317. } catch (ex) {
  318. rptCronJob.started = false;
  319. }
  320. }
  321. } catch (err) {
  322. this.log(err);
  323. ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage');
  324. }
  325. }
  326. /**
  327. * 报表打印页面
  328. *
  329. * @param {Object} ctx - egg全局context
  330. * @return {void}
  331. */
  332. async showPrintPage(ctx) {
  333. try {
  334. // const params = JSON.parse(ctx.request.body.params);
  335. const pageSize = ctx.params.size;
  336. // console.log('pageSize: ' + pageSize);
  337. const renderData = {
  338. size: pageSize,
  339. // orientation: params.orientation,
  340. };
  341. await ctx.render('report/rpt_print.ejs', renderData);
  342. } catch (err) {
  343. this.log(err);
  344. console.log(err);
  345. }
  346. }
  347. async showIndividualPage(ctx) {
  348. try {
  349. // const params = JSON.parse(ctx.request.body.params);
  350. const pageSize = ctx.params.size;
  351. // console.log('pageSize: ' + pageSize);
  352. const renderData = {
  353. size: pageSize,
  354. // orientation: params.orientation,
  355. };
  356. await ctx.render('report/rpt_individual.ejs', renderData);
  357. } catch (err) {
  358. this.log(err);
  359. console.log(err);
  360. }
  361. }
  362. async _getReport(ctx, params) {
  363. // console.log('in getReport');
  364. // console.log(params);
  365. let rptTpl = await ctx.service.rptTpl.getTplById(params.rpt_tpl_id);
  366. if (!rptTpl || rptTpl.length !== 1) {
  367. throw '获取模板失败';
  368. }
  369. rptTpl = JSON.parse(rptTpl[0].rpt_content);
  370. // console.log('get the template!');
  371. const customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
  372. ? await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id)
  373. : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, params.rpt_tpl_id);
  374. let copyCustomSelect = this.ctx.helper.clone(customSelect);
  375. if (!params.gather_select && copyCustomSelect) delete copyCustomSelect.gather_select;
  376. if (!params.stage_select && copyCustomSelect) delete copyCustomSelect.stage_select;
  377. if (!params.material_sum_select && copyCustomSelect) delete copyCustomSelect.material_sum_select;
  378. if (params.change_select) {
  379. copyCustomSelect = { tid: params.tender_id, rid: params.rpt_tpl_id, sid: -1, change_select: params.change_select };
  380. }
  381. const pageRst = await getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir, copyCustomSelect);
  382. for (const page of pageRst.items) {
  383. page[JV.PROP_WATERMARK_CELLS] = [];
  384. }
  385. let waterMarkStr = null;
  386. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  387. // 加水印
  388. fillWaterMark([pageRst]);
  389. if (params.needWaterMark) {
  390. waterMarkStr = await getWatermarkPicData(pageRst, this.app.baseDir);
  391. }
  392. }
  393. // console.log(pageRst);
  394. // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
  395. const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id, params.stage_id); // 新需求中,允许在非审核状态下设置签名
  396. const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
  397. const stgAuditForOrg = await ctx.service.stageAudit.getStageAudit(params.stage_id, 1);
  398. // console.log('after role stage!');
  399. // console.log(roleRel);
  400. mergeStampSignature(ctx, params.stage_status, pageRst, roleRel[0]);
  401. mergeTextSignature(params.isTextSignature, params.stage_status, pageRst, roleRel[0]);
  402. await encodeSignatureDataUri(roleRel, this.app.baseDir);
  403. if (params.getPicFlag) {
  404. await encodeDummySignatureDataUri(pageRst, this.app.baseDir); // 注意草图数据量问题!
  405. }
  406. const stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(params.stage_id, params.stage_times);
  407. stageFlow.forEach(x => {
  408. if (!x) return;
  409. x.visible = (!ctx.session.sessionUser.is_admin && ctx.session.sessionProject.page_show.individualSign === 1)
  410. ? x.aid === ctx.session.sessionUser.accountId : true;
  411. });
  412. // console.log('encodeSignatureDataUri!');
  413. return {
  414. data: pageRst,
  415. signatureRelInfo: roleRel,
  416. stageAudit: stgAudit,
  417. stageAuditOrg: stgAuditForOrg,
  418. debugInfo: ctx.session.sessionUser.loginStatus ? ctx.debugInfo : null,
  419. customDefine: rptTpl[JV.NODE_CUSTOM_DEFINE],
  420. stageFlow,
  421. customSelect,
  422. waterMarkStr,
  423. };
  424. }
  425. /**
  426. * 获取报表数据
  427. *
  428. * @param {Object} ctx - egg全局context
  429. * @return {void}
  430. */
  431. async getReport(ctx) {
  432. try {
  433. // console.log('in getReport');
  434. const params = JSON.parse(ctx.request.body.params);
  435. ctx.body = await this._getReport(ctx, params);
  436. // // console.log(params);
  437. // let rptTpl = await ctx.service.rptTpl.getTplById(params.rpt_tpl_id);
  438. // if (!rptTpl || rptTpl.length !== 1) {
  439. // throw '获取模板失败';
  440. // }
  441. // rptTpl = JSON.parse(rptTpl[0].rpt_content);
  442. // // console.log('get the template!');
  443. // const pageRst = await getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
  444. // // console.log(pageRst);
  445. // // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
  446. // const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id); // 新需求中,允许在非审核状态下设置签名
  447. // const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
  448. // // console.log('after role stage!');
  449. // // console.log(roleRel);
  450. // await encodeSignatureDataUri(roleRel, this.app.baseDir);
  451. // await encodeDummySignatureDataUri(pageRst, this.app.baseDir);
  452. // const stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(params.stage_id, params.stage_times);
  453. // const customSelect = await ctx.service.rptCustomDefine.getDataByCondition({
  454. // tid: params.tender_id, sid: params.stage_id, rid: params.rpt_tpl_id
  455. // });
  456. //
  457. // // console.log('encodeSignatureDataUri!');
  458. // ctx.body = {
  459. // data: pageRst,
  460. // signatureRelInfo: roleRel,
  461. // stageAudit: stgAudit,
  462. // debugInfo: ctx.app.config.is_debug ? ctx.debugInfo : null,
  463. // customDefine: rptTpl[JV.NODE_CUSTOM_DEFINE],
  464. // stageFlow,
  465. // customSelect,
  466. // };
  467. // // ctx.body = { data: { msg: 'test the network' } };
  468. ctx.status = 201;
  469. } catch (ex) {
  470. console.log(ex);
  471. this.setMessage(ex.toString(), this.messageType.ERROR);
  472. }
  473. }
  474. /**
  475. * 获取多批次报表数据
  476. *
  477. * @param {Object} ctx - egg全局context
  478. * @return {void}
  479. */
  480. async getMultiReportsEx(ctx) {
  481. // 原则说明:把所有报表模板集中获取,统一filter,只读一次数据!
  482. const params = JSON.parse(ctx.request.body.params);
  483. const pageShow = ctx.session.sessionProject.page_show;
  484. if (pageShow !== null && pageShow !== undefined && parseInt(pageShow.closeExportPdf) === 1) {
  485. ctx.body = { data: [], signatureRelInfo: [], stageAudit: [] };
  486. ctx.status = 201;
  487. return;
  488. }
  489. await this._saveCustomSelects(params);
  490. const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir) || [];
  491. for (const pageRst of pageRstArr) {
  492. for (const page of pageRst.items) {
  493. page[JV.PROP_WATERMARK_CELLS] = [];
  494. }
  495. }
  496. let waterMarkStr = null;
  497. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  498. // 加水印
  499. fillWaterMark(pageRstArr);
  500. if (params.needWaterMark) {
  501. waterMarkStr = await getWatermarkPicData(pageRstArr[0], this.app.baseDir);
  502. }
  503. }
  504. const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
  505. const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
  506. // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
  507. roleRel.sort(function(rr1, rr2) {
  508. return params.rpt_ids.indexOf(parseInt(rr1.rpt_id)) - params.rpt_ids.indexOf(parseInt(rr2.rpt_id));
  509. });
  510. // console.log('roleRel: ');
  511. // console.log(roleRel);
  512. mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRel, params.rpt_ids);
  513. mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRel, params.rpt_ids);
  514. await encodeSignatureDataUri(roleRel, this.app.baseDir);
  515. if (params.getPicFlag) {
  516. for (const pageRst of pageRstArr) {
  517. await encodeDummySignatureDataUri(pageRst, this.app.baseDir); // 注意草图数据量问题!
  518. }
  519. }
  520. // console.log(pageRstArr);
  521. ctx.body = { data: pageRstArr, signatureRelInfo: roleRel, stageAudit: stgAudit, waterMarkStr };
  522. ctx.status = 201;
  523. }
  524. async _saveCustomSelects(params) {
  525. for (const [i, cs] of params.customSelect.entries()) {
  526. if (!cs) continue;
  527. cs.tender_id = params.tender_id;
  528. cs.stage_id = params.stage_id;
  529. cs.rpt_tpl_id = params.rpt_ids[i];
  530. await this.ctx.service.rptCustomDefine.saveCustomSelect(cs);
  531. }
  532. }
  533. async createExcelFilesEx(ctx) {
  534. const params = JSON.parse(ctx.request.body.params);
  535. const pageShow = ctx.session.sessionProject.page_show;
  536. if (pageShow !== null && pageShow !== undefined && parseInt(pageShow.closeExportExcel) === 1) {
  537. ctx.body = { data: [] };
  538. ctx.status = 201;
  539. return;
  540. }
  541. await this._saveCustomSelects(params);
  542. const baseDir = this.app.baseDir;
  543. function getExcelByPageData(pageRst, rpt_name, innerRoleRel) {
  544. return new Promise(function(resolve, reject) {
  545. rpt_xl_util.exportExcel(pageRst, params.pageSize, rpt_name, params.isOneSheet, null, null, baseDir, innerRoleRel,
  546. (err, uuidName) => {
  547. if (err) return reject(err);
  548. const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
  549. resolve(fileRst);
  550. }
  551. );
  552. });
  553. }
  554. const stgAudit = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times)) : [];
  555. const stgAuditForOrg = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, 1)) : [];
  556. const stageList = (params.stage_status === 3) ? (await ctx.service.stage.getValidStagesShort(params.tender_id)) : [];
  557. const roleRelArr = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
  558. // const roleRel = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id)) : [];
  559. const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, baseDir);
  560. // console.log('params.stage_status: ' + params.stage_status);
  561. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/testBuiltPageResult1.js');
  562. for (const pageRst of pageRstArr) {
  563. for (const page of pageRst.items) {
  564. page[JV.PROP_WATERMARK_CELLS] = [];
  565. }
  566. }
  567. let waterMarkStr = null;
  568. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  569. // if (params.stage_status !== 3 && params.closeWatermark === 0 && params.option === JV.PAGING_OPTION_NORMAL) {
  570. // 加水印(注意:还得看用户设置是否需要加水印)
  571. fillWaterMark(pageRstArr);
  572. if (params.needWaterMark) {
  573. waterMarkStr = await getWatermarkPicData(pageRstArr[0], baseDir);
  574. }
  575. }
  576. mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids);
  577. mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids);
  578. await this.ctx.helper.recursiveMkdirSync(baseDir + '/app/public/download');
  579. const runnableRst = [];
  580. /*
  581. for (let idx = 0; idx < pageRstArr.length; idx++) {
  582. let roleRel = null;
  583. for (const roleR of roleRelArr) {
  584. if (roleR.rpt_id === params.rpt_ids[idx]) {
  585. roleRel = JSON.parse(roleR.rel_content);
  586. break;
  587. }
  588. }
  589. // console.log('roleRel.rel_content: ' + roleRel.rel_content);
  590. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/testBuiltPageResult.jsp');
  591. if (params.stage_status === 3) {
  592. mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
  593. mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
  594. }
  595. runnableRst.push(getExcelByPageData(pageRstArr[idx], params.rpt_names[idx], roleRel));
  596. }
  597. /*/
  598. // 1. merge签名相关信息
  599. // const pageBrkSize = 6291456; // 6M, 1024*1024*6
  600. const pageBrkSize = 62914560; // 60M, 1024*1024*6*10
  601. for (let idx = 0; idx < pageRstArr.length; idx++) {
  602. let roleRel = null;
  603. for (const roleR of roleRelArr) {
  604. if (roleR.rpt_id === params.rpt_ids[idx]) {
  605. roleRel = JSON.parse(roleR.rel_content);
  606. break;
  607. }
  608. }
  609. if (params.stage_status === 3) {
  610. mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
  611. mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
  612. }
  613. // 2. 判断草图大小是否需要分页
  614. const picSize = await _chkRawPicSize(pageRstArr[idx], baseDir);
  615. // const picSize = 262914560; // 测试用,强制分页
  616. if (picSize > pageBrkSize) {
  617. // let pageBrkAmt = Math.ceil(picSize / pageBrkSize);
  618. let pageBrkAmt = Math.floor(pageRstArr[idx].items.length / Math.ceil(picSize / pageBrkSize));
  619. if (pageBrkAmt < 10) {
  620. // 不用管
  621. } else if (pageBrkAmt < 100) {
  622. pageBrkAmt = Math.floor(pageBrkAmt / 10) * 10;
  623. } else if (pageBrkAmt < 1000) {
  624. pageBrkAmt = Math.floor(pageBrkAmt / 100) * 100;
  625. } else {
  626. // 暂时不管
  627. }
  628. const newRptNames = []; // 这个为导出控制分页用
  629. const newPageDataRst = _resetPageDataByBreaks([pageRstArr[idx]], pageBrkAmt, [params.rpt_names[idx]], newRptNames);
  630. for (let dtlIdx = 0; dtlIdx < newPageDataRst.length; dtlIdx++) {
  631. runnableRst.push(getExcelByPageData(newPageDataRst[dtlIdx], newRptNames[dtlIdx], roleRel));
  632. }
  633. } else {
  634. runnableRst.push(getExcelByPageData(pageRstArr[idx], params.rpt_names[idx], roleRel));
  635. }
  636. }
  637. // */
  638. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/计量导出pageArr.js');
  639. const uuidRst = await Promise.all(runnableRst);
  640. ctx.body = { data: uuidRst, waterMarkStr };
  641. ctx.status = 201;
  642. }
  643. _getExcelByPageData(pageRst, rpt_name, pageSize, baseDir, innerRoleRel) {
  644. return new Promise(function(resolve, reject) {
  645. rpt_xl_util.exportExcel(pageRst, pageSize, rpt_name, true, null, null, baseDir, innerRoleRel,
  646. (err, uuidName) => {
  647. if (err) return reject(err);
  648. const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
  649. resolve(fileRst);
  650. }
  651. );
  652. });
  653. }
  654. async createExcelFilesFromDirectData(ctx) {
  655. const params = JSON.parse(ctx.request.body.params);
  656. const names = params.rptNames;
  657. const pageDataArr = params.pageData;
  658. const runnableRst = [];
  659. for (let idx = 0; idx < names.length; idx++) {
  660. runnableRst.push(this._getExcelByPageData(pageDataArr[idx], names[idx], 'A4', this.app.baseDir, null));
  661. }
  662. const uuidRst = await Promise.all(runnableRst);
  663. ctx.body = { data: uuidRst, waterMarkStr: null };
  664. ctx.status = 201;
  665. }
  666. async createExcelFilesFromLocal(ctx) {
  667. const baseDir = this.app.baseDir;
  668. function getExcelByPageData(pageRst, rpt_name, innerRoleRel) {
  669. return new Promise(function(resolve, reject) {
  670. rpt_xl_util.exportExcel(pageRst, 'A4', rpt_name, true, null, null, baseDir, innerRoleRel,
  671. (err, uuidName) => {
  672. if (err) return reject(err);
  673. const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
  674. resolve(fileRst);
  675. }
  676. );
  677. });
  678. }
  679. try {
  680. console.log('start:');
  681. const pageRst = JSON.parse(fs.readFileSync('D:/GitHome/temp/计量excel原始数据_A3BZ6_5384_112表(清单).js', 'utf-8'));
  682. console.log('read it');
  683. const runnableRst = [];
  684. const pageBrkSize = 6291456; // 6M, 1024*1024*6
  685. // const pageBrkSize = 1048576; // 1M, 1024*1024*1
  686. console.log('pageBrkSize:' + pageBrkSize);
  687. const picSize = await _chkRawPicSize(pageRst, baseDir);
  688. console.log('picSize:' + picSize);
  689. if (picSize > pageBrkSize) {
  690. let pageBrkAmt = Math.floor(pageRst.items.length / Math.ceil(picSize / pageBrkSize));
  691. console.log('pageBrkAmt:' + pageBrkAmt);
  692. if (pageBrkAmt < 10) {
  693. // 不用管
  694. } else if (pageBrkAmt < 100) {
  695. pageBrkAmt = Math.floor(pageBrkAmt / 10) * 10;
  696. } else if (pageBrkAmt < 1000) {
  697. pageBrkAmt = Math.floor(pageBrkAmt / 100) * 100;
  698. } else {
  699. // 暂时不管
  700. }
  701. const newRptNames = []; // 这个为导出控制分页用
  702. const newPageDataRst = _resetPageDataByBreaks([pageRst], pageBrkAmt, ['工程计量表(计量单元-清单)'], newRptNames);
  703. for (let dtlIdx = 0; dtlIdx < newPageDataRst.length; dtlIdx++) {
  704. runnableRst.push(getExcelByPageData(newPageDataRst[dtlIdx], newRptNames[dtlIdx], null));
  705. }
  706. } else {
  707. runnableRst.push(getExcelByPageData(pageRst, '工程计量表(计量单元-清单)', null));
  708. }
  709. const uuidRst = await Promise.all(runnableRst);
  710. ctx.body = { data: uuidRst, waterMarkStr: null };
  711. ctx.status = 201;
  712. } catch (ex) {
  713. console.log(ex.toString());
  714. ctx.status = 500;
  715. }
  716. }
  717. async createExcelFilesInOneBookEx(ctx) {
  718. const params = JSON.parse(ctx.request.body.params);
  719. const baseDir = this.app.baseDir;
  720. function getExcelByPageData(pageRstArr, rpt_name, innerRoleRel) {
  721. return new Promise(function(resolve, reject) {
  722. rpt_xl_util.exportExcelInOneBook(pageRstArr, params.pageSize, rpt_name, baseDir, innerRoleRel,
  723. (err, uuidName) => {
  724. if (err) return reject(err);
  725. const fileRst = { uuid: uuidName, reportName: rpt_name };
  726. resolve(fileRst);
  727. }
  728. );
  729. });
  730. }
  731. const roleRelArr = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
  732. // console.log(`baseDir: ${baseDir}`);
  733. // fsUtil.writeObjToFile(roleRelArr, 'D:/GitHome/temp/签名信息.js');
  734. const stgAudit = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times)) : [];
  735. const stgAuditForOrg = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, 1)) : [];
  736. const stageList = (params.stage_status === 3) ? (await ctx.service.stage.getValidStagesShort(params.tender_id)) : [];
  737. const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
  738. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/pageRstArrForExcel.js');
  739. for (const pageRst of pageRstArr) {
  740. for (const page of pageRst.items) {
  741. page[JV.PROP_WATERMARK_CELLS] = [];
  742. }
  743. }
  744. let waterMarkStr = null;
  745. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  746. // if (params.stage_status !== 3 && params.closeWatermark === 0 && params.option === JV.PAGING_OPTION_NORMAL) {
  747. // 加水印
  748. fillWaterMark(pageRstArr);
  749. if (params.needWaterMark) {
  750. waterMarkStr = await getWatermarkPicData(pageRstArr[0], this.app.baseDir);
  751. }
  752. }
  753. mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids);
  754. mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids);
  755. await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
  756. const runnableRst = [];
  757. let rptRoleRelArr = [];
  758. const reAssignSignatureName = function(pageData, roleRel, rpt_name_key) {
  759. const keyMap = {};
  760. for (const pageItem of pageData.items) {
  761. for (const signCell of pageItem[JV.PROP_SIGNATURE_CELLS]) {
  762. if (!keyMap.hasOwnProperty(signCell.signature_name)) {
  763. keyMap[signCell.signature_name] = rpt_name_key + '_' + signCell.signature_name;
  764. }
  765. }
  766. }
  767. for (const pageItem of pageData.items) {
  768. for (const signCell of pageItem[JV.PROP_SIGNATURE_CELLS]) {
  769. if (keyMap.hasOwnProperty(signCell.signature_name)) {
  770. signCell.signature_name = keyMap[signCell.signature_name];
  771. }
  772. }
  773. }
  774. for (const roleSign of roleRel) {
  775. if (keyMap.hasOwnProperty(roleSign.signature_name)) {
  776. roleSign.signature_name = keyMap[roleSign.signature_name];
  777. }
  778. }
  779. // console.log('keyMap of : ' + rpt_name_key);
  780. // console.log(keyMap);
  781. };
  782. for (let idx = 0; idx < pageRstArr.length; idx++) {
  783. let roleRel = null;
  784. for (const roleR of roleRelArr) {
  785. if (roleR.rpt_id === params.rpt_ids[idx]) {
  786. roleRel = JSON.parse(roleR.rel_content);
  787. if (params.stage_status === 3) {
  788. mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
  789. mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
  790. }
  791. // 这里要做些电子签名的signature_name转换,以防重名
  792. reAssignSignatureName(pageRstArr[idx], roleRel, params.rpt_names[idx]);
  793. rptRoleRelArr = rptRoleRelArr.concat(roleRel);
  794. break;
  795. }
  796. }
  797. }
  798. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/pageRstArrForExcelAfterReAssign.js');
  799. // fsUtil.writeObjToFile(rptRoleRelArr, 'D:/GitHome/temp/签名信息_新.js');
  800. runnableRst.push(getExcelByPageData(pageRstArr, params.rptName, rptRoleRelArr));
  801. const uuidRst = await Promise.all(runnableRst);
  802. ctx.body = { data: uuidRst, waterMarkStr };
  803. ctx.status = 201;
  804. }
  805. async getFileByUUID(ctx) {
  806. // console.log('downloading : ' + ctx.params.uuid);
  807. const uuid = ctx.params.uuid;
  808. const rptName = ctx.params.rptName;
  809. const suffix = '.' + ctx.params.suffix;
  810. try {
  811. const rptNameURI = encodeURI(rptName);
  812. const filePath = this.app.baseDir + '/app/public/download/';
  813. // console.log('filePath: ' + filePath);
  814. // await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
  815. ctx.set({
  816. 'Content-Type': 'application/vnd.openxmlformats',
  817. 'Content-Disposition': 'attachment; filename="' + rptNameURI + suffix + "\"; filename*=utf-8''" + rptNameURI + suffix,
  818. });
  819. ctx.body = await fs.readFileSync(filePath + uuid + suffix);
  820. } catch (e) {
  821. console.log(e);
  822. }
  823. }
  824. /**
  825. * 更新用户通用报表显示配置
  826. *
  827. * @param {Object} ctx - egg全局context
  828. * @return {void}
  829. */
  830. async updateCustNode(ctx) {
  831. const params = JSON.parse(ctx.request.body.params);
  832. // console.log(params);
  833. const custId = this.ctx.session.sessionUser.accountId;
  834. const newNodeItems = JSON.stringify(params.nodeItems);
  835. const rst = await ctx.service.rptTreeNodeCust.updateCustNode(custId, newNodeItems);
  836. // console.log(rst);
  837. ctx.body = { data: rst };
  838. // ctx.body = { data: { msg: 'test the network' } };
  839. ctx.status = 201;
  840. }
  841. async setCustomDefine(ctx) {
  842. try {
  843. const data = JSON.parse(ctx.request.body.data);
  844. await this.ctx.service.rptCustomDefine.saveCustomSelect(data);
  845. // const sid = data.gather_select ? -1 : data.stage_id;
  846. // const filter = {tid: data.tender_id, sid: sid, rid: data.rpt_tpl_id};
  847. // const count = await ctx.service.rptCustomDefine.count(filter);
  848. // const updateData = {};
  849. // if (data.audit_select) updateData.audit_select = JSON.stringify(data.audit_select);
  850. // if (data.gather_select) updateData.gather_select = JSON.stringify(data.gather_select);
  851. // if (count > 0) {
  852. // await ctx.service.rptCustomDefine.update(updateData, filter);
  853. // } else {
  854. // updateData.tid = data.tender_id;
  855. // updateData.sid = sid;
  856. // updateData.rid = data.rpt_tpl_id;
  857. // await ctx.service.rptCustomDefine.db.insert(ctx.service.rptCustomDefine.tableName, updateData);
  858. // }
  859. const result = await this._getReport(ctx, data);
  860. ctx.body = { err: 0, msg: '', data: result };
  861. } catch (err) {
  862. ctx.helper.log(err);
  863. ctx.body = this.ajaxErrorBody(err, '保存数据出错');
  864. }
  865. }
  866. }
  867. return ReportController;
  868. };
  869. async function checkStg(ctx, params) {
  870. if (ctx.stage === null || ctx.stage === undefined || parseInt(ctx.stage.id) !== parseInt(params.stage_id)) {
  871. await ctx.service.stage.checkStage(params.stage_id);
  872. if (ctx.stage) {
  873. params.stage_order = ctx.stage.curOrder;
  874. }
  875. }
  876. }
  877. async function getAllPagesCommon(ctx, rptTpl, params, option, outputType, baseDir, customSelect) {
  878. const rptDataUtil = new rptDataExtractor();
  879. rptDataUtil.initialize(rptTpl);
  880. const filter = rptDataUtil.getDataRequestFilter();
  881. const rawDataObj = await ctx.service.report.getReportData(params, filter.tables, filter.memFieldKeys,
  882. rptTpl[JV.NODE_CUSTOM_DEFINE], customSelect);
  883. // console.log(rawDataObj);
  884. try {
  885. const printCom = JpcEx.createNew();
  886. if (params.pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
  887. if (params.orientation && (params.orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = params.orientation;
  888. // let defProperties = await ctx.service.rptPreDefineCfg.getCfgById('Administrator');
  889. // defProperties = JSON.parse(defProperties[0].defined_content);
  890. const defProperties = RPT_DEF_PROPERTIES;
  891. // console.log('defProperties: ');
  892. // console.log(defProperties);
  893. // console.log('before assemble');
  894. // fsUtil.writeObjToFile(rawDataObj, 'D:/GitHome/temp/JL_Assemble_RawDataDataBefore' + (new Date()).getTime() + '.js');
  895. const tplData = rptDataUtil.assembleData(ctx, rawDataObj, baseDir, printCom, customSelect);
  896. // console.log(tplData);
  897. if (params.custCfg) {
  898. setupCustomizeCfg(params.custCfg, rptTpl, defProperties);
  899. } else {
  900. // setupCustomizeCfg(defProperties, rptTpl, defProperties);
  901. }
  902. const dftOption = params.option || JV.PAGING_OPTION_NORMAL;
  903. printCom.initialize(rptTpl);
  904. // 在ctx.helper里夹带私货,增加当前期status及times
  905. // ctx.helper.current_stage_status = params.stage_status;
  906. // ctx.helper.current_stage_times = params.stage_times;
  907. printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType, customSelect);
  908. // console.log(JSON.stringify(rptTpl));
  909. const maxPages = printCom.totalPages;
  910. let pageRst = null;
  911. if (maxPages > 0) {
  912. pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg, customSelect);
  913. } else {
  914. pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  915. }
  916. // fsUtil.writeObjToFile(pageRst, 'D:/GitHome/temp/计量testBuiltPageResult.jsp');
  917. // console.log(pageRst);
  918. pageRst.id = params.rpt_tpl_id;
  919. return pageRst;
  920. } catch (ex) {
  921. console.log('报表数据异常, tender id: ' + params.tender_id);
  922. console.log(ex);
  923. }
  924. }
  925. async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
  926. for (let idx = 0; idx < params.rpt_ids.length; idx++) {
  927. params.rpt_ids[idx] = parseInt(params.rpt_ids[idx]); // 转换一下,以防万一
  928. }
  929. const rptTpls = await ctx.service.rptTpl.getAllTplByIds(params.rpt_ids);
  930. rptTpls.sort(function(rpt1, rpt2) {
  931. return params.rpt_ids.indexOf(rpt1.id) - params.rpt_ids.indexOf(rpt2.id);
  932. });
  933. for (let rtIdx = 0; rtIdx < rptTpls.length; rtIdx++) {
  934. const id = rptTpls[rtIdx].id;
  935. rptTpls[rtIdx] = JSON.parse(rptTpls[rtIdx].rpt_content);
  936. rptTpls[rtIdx].id = id;
  937. }
  938. const rptDataUtil = new rptDataExtractor();
  939. const filterTables = [];
  940. const memFieldKeys = {};
  941. for (const rptTpl of rptTpls) {
  942. rptDataUtil.initialize(rptTpl);
  943. const filter = rptDataUtil.getDataRequestFilter();
  944. // console.log(filter);
  945. for (const table of filter.tables) {
  946. if (filterTables.indexOf(table) < 0 && needCustomTables.indexOf(table) < 0) {
  947. filterTables.push(table);
  948. }
  949. // memFieldKeys[table] = [];
  950. }
  951. for (const tableKeyProp in filter.memFieldKeys) {
  952. if (needCustomTables.indexOf(tableKeyProp) >= 0) continue;
  953. if (!memFieldKeys.hasOwnProperty(tableKeyProp)) {
  954. memFieldKeys[tableKeyProp] = [];
  955. }
  956. for (const mfKey of filter.memFieldKeys[tableKeyProp]) {
  957. if (memFieldKeys[tableKeyProp].indexOf(mfKey) < 0) {
  958. memFieldKeys[tableKeyProp].push(mfKey);
  959. }
  960. }
  961. }
  962. }
  963. const rawDataObj = await ctx.service.report.getReportData(params, filterTables, memFieldKeys, {}, {});
  964. try {
  965. const rptPageRstArray = [];
  966. // 1. 这里只用一份数据,根据实际应用情况,先备份
  967. // const backupData = {};
  968. // for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
  969. // backupData[filterTables[filterIdx]] = [];
  970. // Object.assign(backupData[filterTables[filterIdx]], rawDataObj[filterTables[filterIdx]]);
  971. // }
  972. // 2. 一个一个模板创建数据
  973. // let defProperties = await ctx.service.rptPreDefineCfg.getCfgById('Administrator');
  974. // defProperties = JSON.parse(defProperties[0].defined_content);
  975. const defProperties = RPT_DEF_PROPERTIES;
  976. for (let tplIdx = 0; tplIdx < rptTpls.length; tplIdx++) {
  977. const rptTpl = (rptTpls[tplIdx]._doc) ? rptTpls[tplIdx]._doc : rptTpls[tplIdx];
  978. rptDataUtil.initialize(rptTpl);
  979. let customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
  980. ? await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, rptTpl.id)
  981. : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, rptTpl.id);
  982. if (rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_CHANGE_SELECT] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_CHANGE_SELECT].enable) {
  983. customSelect = { tid: params.tender_id, rid: params.rpt_tpl_id, sid: -1, change_select: params.customSelect[tplIdx].change_select };
  984. }
  985. // 从汇总的rawDataObj中拷贝所需数据表至curRawDataObj,以供后续使用
  986. const curRawDataObj = {};
  987. const filter = rptDataUtil.getDataRequestFilter();
  988. for (const table of filter.tables) {
  989. curRawDataObj[table] = ctx.helper.clone(rawDataObj[table]);
  990. }
  991. // 如果是用户交互类型的表,则应该单独获取数据
  992. if ((params.customSelect && params.customSelect[tplIdx]) || rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_OPTION]) {
  993. const cfTables = [],
  994. cmFieldKeys = [];
  995. const curFilter = rptDataUtil.getDataRequestFilter();
  996. for (const table of curFilter.tables) {
  997. if (needCustomTables.indexOf(table) >= 0) {
  998. cfTables.push(table);
  999. }
  1000. }
  1001. for (const tableKeyProp in filter.memFieldKeys) {
  1002. if (needCustomTables.indexOf(tableKeyProp) < 0) continue;
  1003. if (!cmFieldKeys.hasOwnProperty(tableKeyProp)) {
  1004. cmFieldKeys[tableKeyProp] = [];
  1005. }
  1006. for (const mfKey of filter.memFieldKeys[tableKeyProp]) {
  1007. if (cmFieldKeys[tableKeyProp].indexOf(mfKey) < 0) {
  1008. cmFieldKeys[tableKeyProp].push(mfKey);
  1009. }
  1010. }
  1011. }
  1012. const customRawDataObj = await ctx.service.report.getReportData(params, cfTables, cmFieldKeys,
  1013. rptTpl[JV.NODE_CUSTOM_DEFINE], customSelect);
  1014. for (const prop in customRawDataObj) {
  1015. curRawDataObj[prop] = customRawDataObj[prop];
  1016. }
  1017. }
  1018. const tplData = rptDataUtil.assembleData(ctx, curRawDataObj, baseDir, null, customSelect);
  1019. const printCom = JpcEx.createNew();
  1020. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
  1021. if (params.pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
  1022. if (params.orientation && (params.orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = params.orientation;
  1023. if (params.custCfg) setupCustomizeCfg(params.custCfg, rptTpl, defProperties);
  1024. const dftOption = params.option || JV.PAGING_OPTION_NORMAL;
  1025. printCom.initialize(rptTpl);
  1026. // console.log(rptTpl);
  1027. printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType, customSelect);
  1028. const maxPages = printCom.totalPages;
  1029. let pageRst = null;
  1030. // console.log(maxPages);
  1031. if (maxPages > 0) {
  1032. pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg, customSelect);
  1033. } else {
  1034. pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  1035. }
  1036. pageRst.id = rptTpl.id;
  1037. rptPageRstArray.push(pageRst);
  1038. // 注意:这里需要把备份数据assign回去!!!
  1039. // if (tplIdx < rptTpls.length - 1) {
  1040. // for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
  1041. // backupData[filterTables[filterIdx]] = [];
  1042. // Object.assign(rawDataObj[filterTables[filterIdx]], backupData[filterTables[filterIdx]]);
  1043. // }
  1044. // }
  1045. }
  1046. return rptPageRstArray;
  1047. } catch (ex) {
  1048. console.log('报表数据异常(getMultiRptsCommon): project_id ' + params.project_id + ', tender_id: ' + params.tender_id + ', stage_id: ' + params.stage_id);
  1049. console.log(ex);
  1050. } finally {
  1051. //
  1052. }
  1053. }
  1054. function setupCustomizeCfg(customizeCfg, rptTpl, defProperties) {
  1055. const tmpObj = {};
  1056. // 1. 字体
  1057. const newFonts = [];
  1058. for (const font of defProperties.fonts) {
  1059. const copyFont = {};
  1060. copyFont.ID = font.ID;
  1061. for (const fontProp of JV.FONT_PROPS) {
  1062. copyFont[fontProp] = font[fontProp];
  1063. }
  1064. newFonts.push(copyFont);
  1065. tmpObj[font.ID] = copyFont;
  1066. }
  1067. const private_setup_font = function(propStr, newFont) {
  1068. if (tmpObj[propStr]) {
  1069. tmpObj[propStr].Name = newFont.Name;
  1070. tmpObj[propStr].FontHeight = String(newFont.FontHeight);
  1071. tmpObj[propStr].FontBold = newFont.FontBold;
  1072. tmpObj[propStr].FontItalic = newFont.FontItalic;
  1073. tmpObj[propStr].FontUnderline = newFont.FontUnderline;
  1074. }
  1075. };
  1076. for (const custFont of customizeCfg.fonts) {
  1077. switch (custFont.CfgDispName) {
  1078. case '表标题':
  1079. private_setup_font('ReportTitle_Main', custFont);
  1080. break;
  1081. case '列标题':
  1082. private_setup_font('HeaderColumn', custFont);
  1083. private_setup_font('FooterColumn', custFont);
  1084. break;
  1085. case '正文内容':
  1086. private_setup_font('Content', custFont);
  1087. break;
  1088. case '合计':
  1089. private_setup_font('GrandTotal', custFont);
  1090. private_setup_font('SectionTotal', custFont);
  1091. break;
  1092. case '表眉/表脚':
  1093. private_setup_font('Header', custFont);
  1094. private_setup_font('Footer', custFont);
  1095. break;
  1096. default:
  1097. break;
  1098. }
  1099. }
  1100. // 1.1 窄体
  1101. if (tmpObj.Content_Narrow) {
  1102. if (customizeCfg.isNarrow) {
  1103. tmpObj.Content_Narrow.Name = 'Arial Narrow';
  1104. } else {
  1105. if (tmpObj.Content) {
  1106. tmpObj.Content_Narrow.Name = tmpObj.Content.Name;
  1107. } else {
  1108. tmpObj.Content_Narrow.Name = '宋体';
  1109. }
  1110. }
  1111. }
  1112. defProperties.fonts = newFonts;
  1113. // 2. 页边距
  1114. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT] = customizeCfg.margins[JV.PROP_LEFT] / 10;
  1115. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT] = customizeCfg.margins[JV.PROP_RIGHT] / 10;
  1116. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP] = customizeCfg.margins[JV.PROP_TOP] / 10;
  1117. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM] = customizeCfg.margins[JV.PROP_BOTTOM] / 10;
  1118. // 3. 边框宽度
  1119. if (customizeCfg.hasOwnProperty('borderThick')) {
  1120. for (let i = 0; i < defProperties.styles.length; i++) {
  1121. const style = defProperties.styles[i];
  1122. if (style.ID === 'BORDER_ALL_AROUND') {
  1123. for (const border of style.border_style) {
  1124. border.LineWeight = customizeCfg.borderThick;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. // 4. 边框竖线
  1130. if (!(customizeCfg.showVerticalLine)) {
  1131. const private_copy_border = function(src) {
  1132. const rst = {};
  1133. rst.Position = src.Position;
  1134. rst.LineWeight = src.LineWeight;
  1135. rst.DashStyle = src.DashStyle;
  1136. rst.Color = src.Color;
  1137. return rst;
  1138. };
  1139. const newStyles = [];
  1140. for (let i = 0; i < defProperties.styles.length; i++) {
  1141. const style = defProperties.styles[i];
  1142. newStyles.push(style);
  1143. if (style.ID === 'BORDER_ALL_AROUND') {
  1144. const newStyle = {};
  1145. newStyle.ID = style.ID;
  1146. newStyle.CfgDispName = style.CfgDispName;
  1147. newStyle.border_style = [];
  1148. for (const border of style.border_style) {
  1149. const newBorder = private_copy_border(border);
  1150. newStyle.border_style.push(newBorder);
  1151. if (border.Position === 'Left' || border.Position === 'Right') {
  1152. newBorder.LineWeight = 0;
  1153. }
  1154. }
  1155. newStyles[newStyles.length - 1] = newStyle;
  1156. }
  1157. }
  1158. defProperties.styles = newStyles;
  1159. }
  1160. // 5. 补0
  1161. const private_Setup_Format = function(tabFields) {
  1162. if (tabFields) {
  1163. for (const tabField of tabFields) {
  1164. if (tabField[JV.PROP_FORMAT]) {
  1165. tabField[JV.PROP_FORMAT] = tabField[JV.PROP_FORMAT].replace(new RegExp('#', 'gm'), '0');
  1166. }
  1167. }
  1168. }
  1169. };
  1170. if (customizeCfg.fillZero) {
  1171. if (rptTpl[JV.NODE_FLOW_INFO]) {
  1172. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS]);
  1173. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS]);
  1174. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS]);
  1175. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP] && rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
  1176. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  1177. for (const discrete of rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  1178. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1179. }
  1180. }
  1181. if (rptTpl[JV.NODE_FLOW_INFO_EX]) {
  1182. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS]);
  1183. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_PAGE_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS]);
  1184. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_SEG_SUM]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS]);
  1185. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_SUM_FIELDS]);
  1186. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP] && rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES]) private_Setup_Format(rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][JV.PROP_SUM_FIELDS]);
  1187. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  1188. for (const discrete of rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  1189. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1190. }
  1191. }
  1192. }
  1193. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  1194. if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT][JV.PROP_BILL_FIELDS]);
  1195. if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  1196. for (const discrete of rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  1197. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1198. }
  1199. }
  1200. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  1201. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_CONTENT][JV.TAB_CROSS_FIELDS]);
  1202. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW][JV.TAB_CROSS_FIELDS]);
  1203. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL][JV.TAB_CROSS_FIELDS]);
  1204. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL_SUM]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_COL_SUM][JV.TAB_CROSS_FIELDS]);
  1205. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_EXT][JV.TAB_CROSS_FIELDS]);
  1206. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT]) private_Setup_Format(rptTpl[JV.NODE_CROSS_INFO][JV.NODE_CROSS_ROW_SUM_EXT][JV.TAB_CROSS_FIELDS]);
  1207. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  1208. for (const discrete of rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  1209. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1210. }
  1211. }
  1212. }
  1213. }
  1214. }
  1215. function isFileExisted(file) {
  1216. return new Promise(function(resolve, reject) {
  1217. fs.access(file, err => {
  1218. if (err) {
  1219. reject(false);
  1220. } else {
  1221. resolve(true);
  1222. }
  1223. });
  1224. });
  1225. }
  1226. function fillWaterMark(pageRstArray) {
  1227. const orgWaterMarkWidth = 600;
  1228. const orgWaterMarkHeight = 288;
  1229. const createWaterCell = function(area) {
  1230. const w = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT];
  1231. const h = area[JV.PROP_BOTTOM] - area[JV.PROP_TOP];
  1232. const left = Math.round(area[JV.PROP_LEFT] + w / 2 - orgWaterMarkWidth / 2);
  1233. const right = left + orgWaterMarkWidth;
  1234. const top = Math.round(area[JV.PROP_TOP] + h / 2 - orgWaterMarkHeight / 2);
  1235. const bottom = top + orgWaterMarkHeight;
  1236. return {
  1237. signature_name: JV.SIGNATURE_NAME_DUMMY_WATER_MARK,
  1238. path: '/public/images/not_Approve.png',
  1239. sign_path: '/public/images/not_Approve.png',
  1240. pic: null,
  1241. control: 'Title',
  1242. style: 'Default_None',
  1243. area: {
  1244. Left: left,
  1245. Right: right,
  1246. Top: top,
  1247. Bottom: bottom,
  1248. },
  1249. };
  1250. };
  1251. for (const pageRst of pageRstArray) {
  1252. for (const page of pageRst.items) {
  1253. page[JV.PROP_WATERMARK_CELLS] = [];
  1254. if (page[JV.PROP_PAGE_MERGE_BORDER]) {
  1255. const wmCell = createWaterCell(page[JV.PROP_PAGE_MERGE_BORDER]);
  1256. page[JV.PROP_WATERMARK_CELLS].push(wmCell);
  1257. } else if (page[JV.PAGE_SPECIAL_MERGE_POS]) {
  1258. if (page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT]) {
  1259. for (let i = 0; i < page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT].length; i++) {
  1260. const area = {};
  1261. area[JV.PROP_LEFT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT][i];
  1262. area[JV.PROP_RIGHT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_RIGHT][i];
  1263. area[JV.PROP_TOP] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_TOP][i];
  1264. area[JV.PROP_BOTTOM] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_BOTTOM][i];
  1265. const wmCell = createWaterCell(area);
  1266. page[JV.PROP_WATERMARK_CELLS].push(wmCell);
  1267. }
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. async function encodeSignatureDataUri(roleRel, baseDir) {
  1274. if (roleRel) {
  1275. for (const singleRoleRel of roleRel) {
  1276. if (singleRoleRel.rel_content !== null && singleRoleRel.rel_content !== undefined && singleRoleRel.rel_content !== '') {
  1277. const roleRelContent = JSON.parse(singleRoleRel.rel_content);
  1278. for (const role of roleRelContent) {
  1279. // console.log(role);
  1280. if (role.sign_path !== '') {
  1281. const filePath = baseDir + '/app' + role.sign_path;
  1282. try {
  1283. const res = await isFileExisted(filePath);
  1284. if (res) {
  1285. const bData = fs.readFileSync(filePath);
  1286. const base64Str = bData.toString('base64');
  1287. const datauri = 'data:image/png;base64,' + base64Str;
  1288. role.sign_pic = datauri;
  1289. } else {
  1290. console.log('文件不存在:' + filePath);
  1291. }
  1292. } catch (err) {
  1293. console.error(err);
  1294. }
  1295. }
  1296. }
  1297. singleRoleRel.rel_content = JSON.stringify(roleRelContent);
  1298. } else {
  1299. singleRoleRel.rel_content = [];
  1300. }
  1301. }
  1302. }
  1303. }
  1304. async function encodeDummySignatureDataUri(pageRst, baseDir) {
  1305. if (pageRst) {
  1306. for (const page of pageRst.items) {
  1307. for (const signature of page[JV.PROP_SIGNATURE_CELLS]) {
  1308. if (signature.signature_name === JV.SIGNATURE_NAME_DUMMY) {
  1309. if (signature.path !== '') {
  1310. const filePath = baseDir + '/app' + signature.path;
  1311. try {
  1312. const res = await isFileExisted(filePath);
  1313. if (res) {
  1314. const bData = fs.readFileSync(filePath);
  1315. const base64Str = bData.toString('base64');
  1316. const datauri = 'data:image/png;base64,' + base64Str;
  1317. signature.pic = datauri;
  1318. signature.path = '';
  1319. } else {
  1320. console.log('文件不存在:' + filePath);
  1321. }
  1322. } catch (err) {
  1323. console.error(err);
  1324. }
  1325. }
  1326. }
  1327. }
  1328. // 考虑优化,水印只需要一张即可,不需要每页都设置
  1329. // for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
  1330. // if (signature.path !== '') {
  1331. // const filePath = baseDir + '/app' + signature.path;
  1332. // try {
  1333. // const res = await isFileExisted(filePath);
  1334. // if (res) {
  1335. // const bData = fs.readFileSync(filePath);
  1336. // const base64Str = bData.toString('base64');
  1337. // const datauri = 'data:image/png;base64,' + base64Str;
  1338. // signature.pic = datauri;
  1339. // signature.path = '';
  1340. // } else {
  1341. // console.log('文件不存在:' + filePath);
  1342. // }
  1343. // } catch (err) {
  1344. // console.error(err);
  1345. // }
  1346. // }
  1347. // }
  1348. }
  1349. }
  1350. }
  1351. async function getWatermarkPicData(pageRst, baseDir) {
  1352. let rst = '';
  1353. if (pageRst) {
  1354. for (const page of pageRst.items) {
  1355. for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
  1356. if (signature.path !== '') {
  1357. const filePath = baseDir + '/app' + signature.path;
  1358. try {
  1359. const res = await isFileExisted(filePath);
  1360. if (res) {
  1361. const bData = fs.readFileSync(filePath);
  1362. const base64Str = bData.toString('base64');
  1363. rst = 'data:image/png;base64,' + base64Str;
  1364. break;
  1365. } else {
  1366. console.log('文件不存在:' + filePath);
  1367. }
  1368. } catch (err) {
  1369. console.error(err);
  1370. }
  1371. }
  1372. if (rst !== null) break;
  1373. }
  1374. }
  1375. }
  1376. return rst;
  1377. }
  1378. async function createExportRequestJob(ctx) {
  1379. const params = JSON.parse(ctx.request.body.params);
  1380. // const uuidArr = params.uuidArr;
  1381. const baseDir = this.app.baseDir;
  1382. const roleRelArr = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
  1383. const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
  1384. await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
  1385. for (let idx = 0; idx < pageRstArr.length; idx++) {
  1386. let roleRel = null;
  1387. for (const roleR of roleRelArr) {
  1388. if (roleR.rpt_id === params.rpt_ids[idx]) {
  1389. roleRel = JSON.parse(roleR.rel_content);
  1390. break;
  1391. }
  1392. }
  1393. if (params.exportType === 'xlsx') {
  1394. const zip = rpt_xl_util.exportExcel(pageRstArr[idx], params.pageSize, null, params.isOneSheet, null, null, baseDir, roleRel, null); // 给个null报表名称,返回zip对象自己处理,这样就不用改接口结构了
  1395. zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
  1396. .pipe(fs.createWriteStream(baseDir + '/app/public/download/' + params.uuidArr[idx] + '.xlsx'));
  1397. } else if (params.exportType === 'pdf') {
  1398. // PDF的后期补上
  1399. }
  1400. }
  1401. }
  1402. function mergeTextSignature(isTxtSignature, status, pageData, singleRoleRel, rpt_ids) {
  1403. // 依据需求,有些用户不需要签名图片,那么从源头上把签名从signature_cells转移到cells下,省得后续 预览、打印、导出PDF、导出EXCEL每个地方都改动
  1404. const _mergeSingle = function(_page, _roleRelList, isDeleteSignCell) {
  1405. // console.log(_roleRelList);
  1406. let roleRelContent = [];
  1407. if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
  1408. roleRelContent = JSON.parse(_roleRelList.rel_content);
  1409. }
  1410. for (const page of _page.items) {
  1411. if (page.signature_cells) {
  1412. const deleteSCellsIdx = [];
  1413. for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
  1414. const sCell = page.signature_cells[scIdx];
  1415. if (sCell.signature_name !== JV.SIGNATURE_NAME_DUMMY) {
  1416. sCell.Value = ''; // 这里要先清除原有信息
  1417. sCell.path = '';
  1418. sCell.pic = '';
  1419. let needTransferText = true;
  1420. if (status === 3) {
  1421. for (const role_rel of roleRelContent) {
  1422. if (sCell.signature_name === role_rel.signature_name) {
  1423. sCell.Value = role_rel.user_name; // 只有审核通过了才需要文本签名内容
  1424. if (role_rel.sign_output && role_rel.sign_output.indexOf(NORMAL_SIGN_STR) < 0) {
  1425. // 用户选择不签名,则不迁移
  1426. needTransferText = false;
  1427. }
  1428. break;
  1429. }
  1430. }
  1431. }
  1432. if (needTransferText) {
  1433. const newCell = {
  1434. font: 'Footer',
  1435. control: sCell.control,
  1436. style: sCell.style,
  1437. Value: sCell.Value,
  1438. area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
  1439. };
  1440. page.cells.push(newCell); // 迁移
  1441. deleteSCellsIdx.push(scIdx);
  1442. }
  1443. }
  1444. }
  1445. // 删除 page.signature_cells 签名(草图不能删);
  1446. // console.log('isDeleteSignCell: ' + isDeleteSignCell);
  1447. // console.log(deleteSCellsIdx);
  1448. if (isDeleteSignCell) {
  1449. for (let dIdx = deleteSCellsIdx.length - 1; dIdx >= 0; dIdx--) {
  1450. page.signature_cells.splice(deleteSCellsIdx[dIdx], 1);
  1451. }
  1452. }
  1453. }
  1454. }
  1455. };
  1456. if (isTxtSignature) {
  1457. if (pageData instanceof Array) {
  1458. pageData.forEach((dtlPage, index) => {
  1459. let dftRolRel = [];
  1460. const rpt_id = rpt_ids[index];
  1461. for (const roleRel of singleRoleRel) {
  1462. if (roleRel.rpt_id === rpt_id) {
  1463. dftRolRel = roleRel;
  1464. }
  1465. }
  1466. // console.log(dftRolRel);
  1467. _mergeSingle(dtlPage, dftRolRel, true);
  1468. });
  1469. } else {
  1470. _mergeSingle(pageData, singleRoleRel, false);
  1471. }
  1472. }
  1473. }
  1474. // 因机制问题,此方法必须在mergeTextSignature之前调用
  1475. async function mergeStampSignature(ctx, status, pageData, singleRoleRel, rpt_ids) {
  1476. const dupPicPaths = [];
  1477. const _getMaxRect = function(page) {
  1478. const rect = [100000000, 100000000, 0, 0];
  1479. for (const cell of page.cells) {
  1480. if (rect[0] > cell.area.Left) {
  1481. rect[0] = cell.area.Left;
  1482. }
  1483. if (rect[1] > cell.area.Top) {
  1484. rect[1] = cell.area.Top;
  1485. }
  1486. if (rect[2] < cell.area.Right) {
  1487. rect[2] = cell.area.Right;
  1488. }
  1489. if (rect[3] < cell.area.Bottom) {
  1490. rect[3] = cell.area.Bottom;
  1491. }
  1492. }
  1493. return rect;
  1494. };
  1495. const createStampArea = function(orgCell, controls, maxRect) {
  1496. const ctrl = controls[orgCell.control];
  1497. const rst = { Left: orgCell.area.Left, Right: orgCell.area.Right, Top: orgCell.area.Top, Bottom: orgCell.area.Bottom };
  1498. let pLeft = orgCell.area.Left,
  1499. pTop = orgCell.area.Top;
  1500. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  1501. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
  1502. pLeft = orgCell.area.Left;
  1503. break;
  1504. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
  1505. pLeft = (orgCell.area.Left + orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH) / 2;
  1506. break;
  1507. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
  1508. pLeft = orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH;
  1509. break;
  1510. default:break;
  1511. }
  1512. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  1513. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
  1514. pTop = orgCell.area.Top;
  1515. break;
  1516. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
  1517. pTop = (orgCell.area.Top + orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT) / 2;
  1518. break;
  1519. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
  1520. pTop = orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT;
  1521. break;
  1522. default:break;
  1523. }
  1524. rst.Left = pLeft;
  1525. rst.Top = pTop;
  1526. rst.Right = pLeft + STD_COMP_STAMP_SIZE_WIDTH;
  1527. rst.Bottom = pTop + STD_COMP_STAMP_SIZE_WIDTH;
  1528. // 最后一步,如超过报表范围,则要调整坐标
  1529. // if (rst.Left < maxRect[0]) {
  1530. // const width = maxRect[0] - rst.Left;
  1531. // rst.Left += width;
  1532. // rst.Right += width;
  1533. // }
  1534. // if (rst.Top < maxRect[1]) {
  1535. // const height = maxRect[1] - rst.Top;
  1536. // rst.Top += height;
  1537. // rst.Bottom += height;
  1538. // }
  1539. // if (rst.Right > maxRect[2]) {
  1540. // const width = maxRect[2] - rst.Right; // 负
  1541. // rst.Left += width;
  1542. // rst.Right += width;
  1543. // }
  1544. // if (rst.Bottom > maxRect[3]) {
  1545. // const height = maxRect[3] - rst.Bottom;
  1546. // rst.Top += height;
  1547. // rst.Bottom += height;
  1548. // }
  1549. return rst;
  1550. };
  1551. const _mergeSingleStamp = async function(_page, _roleRelList) {
  1552. let roleRelContent = [];
  1553. if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
  1554. roleRelContent = JSON.parse(_roleRelList.rel_content);
  1555. }
  1556. for (const page of _page.items) {
  1557. const maxRect = _getMaxRect(page);
  1558. if (page.signature_cells) {
  1559. const newStampCells = [];
  1560. for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
  1561. const sCell = page.signature_cells[scIdx];
  1562. for (const role_rel of roleRelContent) {
  1563. if (sCell.signature_name === role_rel.signature_name) {
  1564. if (Array.isArray(role_rel.sign_output) && role_rel.sign_output.length > 0) {
  1565. for (const signType of role_rel.sign_output) {
  1566. switch (signType) {
  1567. case COMPANY_SIGN_STR:
  1568. case PRIVATE_SIGN_STR:
  1569. // 创建一个新的cell
  1570. let stampPath = (signType === COMPANY_SIGN_STR) ? role_rel.company_stamp_path : role_rel.private_stamp_path;
  1571. stampPath = ctx.app.config.fujianOssPath + stampPath;
  1572. if (dupPicPaths.indexOf(stampPath) < 0) {
  1573. dupPicPaths.push(stampPath);
  1574. // await _chkRawPicSizeOSS(ctx, stampPath);
  1575. }
  1576. const newStampCell = {
  1577. signature_name: JV.SIGNATURE_NAME_DUMMY,
  1578. control: sCell.control,
  1579. style: sCell.style,
  1580. path: stampPath,
  1581. isStamp: true,
  1582. maxRect,
  1583. orgArea: sCell.area,
  1584. area: createStampArea(sCell, _page[JV.NODE_CONTROL_COLLECTION], maxRect),
  1585. };
  1586. newStampCells.push(newStampCell);
  1587. break;
  1588. default: break;
  1589. }
  1590. }
  1591. }
  1592. }
  1593. }
  1594. }
  1595. if (newStampCells.length > 0) {
  1596. page.signature_cells = page.signature_cells.concat(newStampCells);
  1597. }
  1598. }
  1599. }
  1600. };
  1601. if (status === 3) {
  1602. if (pageData instanceof Array) {
  1603. pageData.forEach((dtlPage, index) => {
  1604. let dftRolRel = [];
  1605. const rpt_id = rpt_ids[index];
  1606. for (const roleRel of singleRoleRel) {
  1607. if (roleRel.rpt_id === rpt_id) {
  1608. dftRolRel = roleRel;
  1609. }
  1610. }
  1611. _mergeSingleStamp(dtlPage, dftRolRel);
  1612. });
  1613. } else {
  1614. _mergeSingleStamp(pageData, singleRoleRel);
  1615. }
  1616. }
  1617. }
  1618. function mergeSignAudit(pageData, currRoleRelList, currAuditList) {
  1619. for (const page of pageData.items) {
  1620. if (page.signature_audit_cells) {
  1621. for (const sCell of page.signature_audit_cells) {
  1622. sCell.Value = ''; // 这里要先清除原有信息
  1623. if (currRoleRelList && currRoleRelList.length > 0) {
  1624. for (const role_rel of currRoleRelList) {
  1625. if (sCell.signature_name === role_rel.signature_name + '_审核意见') {
  1626. let preDate = '';
  1627. sCell.Value = '同意'; // 只有选择了签名的,才需要初始化一个默认的意见(之前的逻辑在有多个签名,哪怕只选择了一个,其他的意见都会有默认意见)
  1628. if (currAuditList && currAuditList.length > 0) {
  1629. for (const audit_rel of currAuditList) {
  1630. if (role_rel.acc_id === audit_rel.aid) {
  1631. if (audit_rel.end_time > preDate && audit_rel.status === 3) {
  1632. sCell.Value = audit_rel.opinion;
  1633. preDate = audit_rel.end_time;
  1634. }
  1635. // 不能break,实际会有多个审核意见,以最后一个为准
  1636. }
  1637. }
  1638. }
  1639. break;
  1640. }
  1641. }
  1642. }
  1643. }
  1644. }
  1645. }
  1646. }
  1647. function mergeSignDate(pageData, current_stage_id, currRoleRelList, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
  1648. if (currRoleRelList && currRoleRelList.length > 0 && STAGE_AUDIT && STAGE_AUDIT.length > 0) {
  1649. for (let rridx = 0; rridx < currRoleRelList.length; rridx++) {
  1650. const role_rel = currRoleRelList[rridx];
  1651. if (role_rel.sign_date === undefined || role_rel.sign_date === null || role_rel.sign_date === '') {
  1652. const dftDate = _getSignDateByAllScenarios(role_rel.acc_id, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST);
  1653. role_rel.sign_date = dftDate;
  1654. }
  1655. }
  1656. }
  1657. if (currRoleRelList && currRoleRelList.length > 0) {
  1658. for (const page of pageData.items) {
  1659. if (page.signature_date_cells) {
  1660. for (const sCell of page.signature_date_cells) {
  1661. sCell.Value = _getSignDateDftName();
  1662. for (const role_rel of currRoleRelList) {
  1663. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  1664. if (role_rel.sign_date !== '') {
  1665. if (typeof role_rel.sign_date === 'string') {
  1666. role_rel.sign_date = new Date(role_rel.sign_date);
  1667. }
  1668. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  1669. }
  1670. break;
  1671. }
  1672. }
  1673. }
  1674. }
  1675. }
  1676. }
  1677. }
  1678. function _getSignDateByAllScenarios(userAccId, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
  1679. let rst = '';
  1680. let hasAudit = false;
  1681. for (const stg_audit of STAGE_AUDIT) {
  1682. if (stg_audit.aid === userAccId) {
  1683. hasAudit = true;
  1684. if (stg_audit.status === 3) {
  1685. rst = stg_audit.end_time;
  1686. } else {
  1687. rst = '';
  1688. }
  1689. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  1690. }
  1691. }
  1692. let isOrgRpt = false;
  1693. for (const stg of STAGE_LIST) {
  1694. if (stg.id === current_stage_id) {
  1695. if (stg.user_id === userAccId) {
  1696. isOrgRpt = true;
  1697. }
  1698. break;
  1699. }
  1700. }
  1701. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  1702. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  1703. rst = STAGE_AUDIT_ORG[0].begin_time;
  1704. }
  1705. }
  1706. if (!isOrgRpt && !hasAudit) {
  1707. // 非审批流程人员以及非原报,则显示期截至时间
  1708. for (const stg of STAGE_LIST) {
  1709. if (stg.id === current_stage_id && stg.period) {
  1710. const period = stg.period.split(' ~ ');
  1711. if (period.length === 2) {
  1712. rst = period[1];
  1713. }
  1714. }
  1715. }
  1716. }
  1717. return rst;
  1718. }
  1719. function _getSignDateDftName() {
  1720. return ' 年 月 日';
  1721. }
  1722. async function _chkRawPicSize(pageData, baseDir) {
  1723. let rst = 0;
  1724. const picKeys = [];
  1725. for (let pi = 0; pi < pageData.items.length; pi++) {
  1726. // 每页判断
  1727. for (let ci = 0; ci < pageData.items[pi][JV.PROP_SIGNATURE_CELLS].length; ci++) {
  1728. const picPath = pageData.items[pi][JV.PROP_SIGNATURE_CELLS][ci].path;
  1729. // if (picPath && picPath.indexOf('/sign') < 0 && picKeys.indexOf(picPath) < 0) {
  1730. if (picPath && picPath !== '' && picKeys.indexOf(picPath) < 0) {
  1731. // 签名图片也要计算在内,反正不重复
  1732. picKeys.push(picPath);
  1733. }
  1734. // signature_cells PROP_SIGNATURE_CELLS
  1735. }
  1736. }
  1737. // console.log(picKeys);
  1738. for (const pKey of picKeys) {
  1739. const filePath = `${baseDir}/app${pKey}`;
  1740. console.log('filePath: ' + filePath);
  1741. let isExist = false;
  1742. try {
  1743. isExist = await isFileExisted(filePath);
  1744. } catch (ex) {
  1745. isExist = false;
  1746. }
  1747. console.log('isExist: ' + isExist);
  1748. if (isExist) {
  1749. const obj = fs.statSync(filePath);
  1750. if (obj) {
  1751. rst += obj.size;
  1752. } else {
  1753. console.log('no statSync resutl: ' + filePath);
  1754. }
  1755. // rst += fs.statSync(filePath).size;
  1756. } else {
  1757. console.log(`${pKey} not exists!`);
  1758. }
  1759. }
  1760. return rst;
  1761. }
  1762. async function _chkRawPicSizeOSS(ctx, picPath) {
  1763. // 计量的草图、签章都放在OSS服务器上,需要另外的方式来获取,考虑到效率问题,机制上得有所变化
  1764. const rst = [0, 0];
  1765. try {
  1766. const pf = await ctx.app.signPdfOss.get(picPath);
  1767. console.log('get pic successfully!');
  1768. console.log(pf);
  1769. } catch (ex) {
  1770. console.log(ex);
  1771. } finally {
  1772. console.log('finally!');
  1773. }
  1774. return rst;
  1775. }
  1776. function _resetPageDataByBreaks(pageDataArr, breakAmt, rpt_names, newRptNames) {
  1777. const rst = [];
  1778. for (let pi = 0; pi < pageDataArr.length; pi++) {
  1779. const pageItem = pageDataArr[pi];
  1780. const currentRptName = rpt_names[pi];
  1781. if (pageItem.items.length > breakAmt) {
  1782. let pa = Math.floor(pageItem.items.length / breakAmt);
  1783. if (pageItem.items.length % breakAmt > 0) {
  1784. pa++;
  1785. }
  1786. for (let idx = 0; idx < pa; idx++) {
  1787. const newPageDataObj = { items: [] };
  1788. // newPageDataObj[JV.NODE_PAGE_INFO] = JSON.parse(JSON.stringify(pageItem[JV.NODE_PAGE_INFO]));
  1789. newPageDataObj[JV.NODE_PAGE_INFO] = pageItem[JV.NODE_PAGE_INFO];
  1790. // newPageDataObj[JV.BAND_PROP_MERGE_BAND] = JSON.parse(JSON.stringify(pageItem[JV.BAND_PROP_MERGE_BAND]));
  1791. newPageDataObj[JV.BAND_PROP_MERGE_BAND] = pageItem[JV.BAND_PROP_MERGE_BAND];
  1792. newPageDataObj[JV.NODE_FONT_COLLECTION] = pageItem[JV.NODE_FONT_COLLECTION];
  1793. newPageDataObj[JV.NODE_STYLE_COLLECTION] = pageItem[JV.NODE_STYLE_COLLECTION];
  1794. newPageDataObj[JV.NODE_CONTROL_COLLECTION] = pageItem[JV.NODE_CONTROL_COLLECTION];
  1795. for (let dIdx = idx * breakAmt; dIdx < (Math.min((idx + 1) * breakAmt, pageItem.items.length)); dIdx++) {
  1796. newPageDataObj.items.push(pageItem.items[dIdx]);
  1797. }
  1798. rst.push(newPageDataObj);
  1799. newRptNames.push(currentRptName + '_' + (idx + 1));
  1800. }
  1801. } else {
  1802. rst.push(pageItem);
  1803. newRptNames.push(currentRptName);
  1804. }
  1805. }
  1806. return rst;
  1807. }