report_controller.js 93 KB

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