report_controller.js 93 KB

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