report_controller.js 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  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(4.2 * 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. return pageRst;
  917. } catch (ex) {
  918. console.log('报表数据异常, tender id: ' + params.tender_id);
  919. console.log(ex);
  920. }
  921. }
  922. async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
  923. for (let idx = 0; idx < params.rpt_ids.length; idx++) {
  924. params.rpt_ids[idx] = parseInt(params.rpt_ids[idx]); // 转换一下,以防万一
  925. }
  926. const rptTpls = await ctx.service.rptTpl.getAllTplByIds(params.rpt_ids);
  927. rptTpls.sort(function(rpt1, rpt2) {
  928. return params.rpt_ids.indexOf(rpt1.id) - params.rpt_ids.indexOf(rpt2.id);
  929. });
  930. for (let rtIdx = 0; rtIdx < rptTpls.length; rtIdx++) {
  931. const id = rptTpls[rtIdx].id;
  932. rptTpls[rtIdx] = JSON.parse(rptTpls[rtIdx].rpt_content);
  933. rptTpls[rtIdx].id = id;
  934. }
  935. const rptDataUtil = new rptDataExtractor();
  936. const filterTables = [];
  937. const memFieldKeys = {};
  938. for (const rptTpl of rptTpls) {
  939. rptDataUtil.initialize(rptTpl);
  940. const filter = rptDataUtil.getDataRequestFilter();
  941. // console.log(filter);
  942. for (const table of filter.tables) {
  943. if (filterTables.indexOf(table) < 0 && needCustomTables.indexOf(table) < 0) {
  944. filterTables.push(table);
  945. }
  946. // memFieldKeys[table] = [];
  947. }
  948. for (const tableKeyProp in filter.memFieldKeys) {
  949. if (needCustomTables.indexOf(tableKeyProp) >= 0) continue;
  950. if (!memFieldKeys.hasOwnProperty(tableKeyProp)) {
  951. memFieldKeys[tableKeyProp] = [];
  952. }
  953. for (const mfKey of filter.memFieldKeys[tableKeyProp]) {
  954. if (memFieldKeys[tableKeyProp].indexOf(mfKey) < 0) {
  955. memFieldKeys[tableKeyProp].push(mfKey);
  956. }
  957. }
  958. }
  959. }
  960. const rawDataObj = await ctx.service.report.getReportData(params, filterTables, memFieldKeys, {}, {});
  961. try {
  962. const rptPageRstArray = [];
  963. // 1. 这里只用一份数据,根据实际应用情况,先备份
  964. // const backupData = {};
  965. // for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
  966. // backupData[filterTables[filterIdx]] = [];
  967. // Object.assign(backupData[filterTables[filterIdx]], rawDataObj[filterTables[filterIdx]]);
  968. // }
  969. // 2. 一个一个模板创建数据
  970. // let defProperties = await ctx.service.rptPreDefineCfg.getCfgById('Administrator');
  971. // defProperties = JSON.parse(defProperties[0].defined_content);
  972. const defProperties = RPT_DEF_PROPERTIES;
  973. for (let tplIdx = 0; tplIdx < rptTpls.length; tplIdx++) {
  974. const rptTpl = (rptTpls[tplIdx]._doc) ? rptTpls[tplIdx]._doc : rptTpls[tplIdx];
  975. rptDataUtil.initialize(rptTpl);
  976. let customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
  977. ? await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, rptTpl.id)
  978. : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, rptTpl.id);
  979. 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) {
  980. customSelect = { tid: params.tender_id, rid: params.rpt_tpl_id, sid: -1, change_select: params.customSelect[tplIdx].change_select };
  981. }
  982. // 从汇总的rawDataObj中拷贝所需数据表至curRawDataObj,以供后续使用
  983. const curRawDataObj = {};
  984. const filter = rptDataUtil.getDataRequestFilter();
  985. for (const table of filter.tables) {
  986. curRawDataObj[table] = ctx.helper.clone(rawDataObj[table]);
  987. }
  988. // 如果是用户交互类型的表,则应该单独获取数据
  989. if ((params.customSelect && params.customSelect[tplIdx]) || rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_OPTION]) {
  990. const cfTables = [],
  991. cmFieldKeys = [];
  992. const curFilter = rptDataUtil.getDataRequestFilter();
  993. for (const table of curFilter.tables) {
  994. if (needCustomTables.indexOf(table) >= 0) {
  995. cfTables.push(table);
  996. }
  997. }
  998. for (const tableKeyProp in filter.memFieldKeys) {
  999. if (needCustomTables.indexOf(tableKeyProp) < 0) continue;
  1000. if (!cmFieldKeys.hasOwnProperty(tableKeyProp)) {
  1001. cmFieldKeys[tableKeyProp] = [];
  1002. }
  1003. for (const mfKey of filter.memFieldKeys[tableKeyProp]) {
  1004. if (cmFieldKeys[tableKeyProp].indexOf(mfKey) < 0) {
  1005. cmFieldKeys[tableKeyProp].push(mfKey);
  1006. }
  1007. }
  1008. }
  1009. const customRawDataObj = await ctx.service.report.getReportData(params, cfTables, cmFieldKeys,
  1010. rptTpl[JV.NODE_CUSTOM_DEFINE], customSelect);
  1011. for (const prop in customRawDataObj) {
  1012. curRawDataObj[prop] = customRawDataObj[prop];
  1013. }
  1014. }
  1015. const tplData = rptDataUtil.assembleData(ctx, curRawDataObj, baseDir, null, customSelect);
  1016. const printCom = JpcEx.createNew();
  1017. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
  1018. if (params.pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
  1019. if (params.orientation && (params.orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = params.orientation;
  1020. if (params.custCfg) setupCustomizeCfg(params.custCfg, rptTpl, defProperties);
  1021. const dftOption = params.option || JV.PAGING_OPTION_NORMAL;
  1022. printCom.initialize(rptTpl);
  1023. // console.log(rptTpl);
  1024. printCom.analyzeData(ctx.helper, rptTpl, tplData, defProperties, dftOption, outputType, customSelect);
  1025. const maxPages = printCom.totalPages;
  1026. let pageRst = null;
  1027. // console.log(maxPages);
  1028. if (maxPages > 0) {
  1029. pageRst = printCom.outputAsSimpleJSONPageArray(ctx.helper, rptTpl, tplData, 1, maxPages, defProperties, params.custCfg, customSelect);
  1030. } else {
  1031. pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  1032. }
  1033. rptPageRstArray.push(pageRst);
  1034. // 注意:这里需要把备份数据assign回去!!!
  1035. // if (tplIdx < rptTpls.length - 1) {
  1036. // for (let filterIdx = 0; filterIdx < filterTables.length; filterIdx++) {
  1037. // backupData[filterTables[filterIdx]] = [];
  1038. // Object.assign(rawDataObj[filterTables[filterIdx]], backupData[filterTables[filterIdx]]);
  1039. // }
  1040. // }
  1041. }
  1042. return rptPageRstArray;
  1043. } catch (ex) {
  1044. console.log('报表数据异常(getMultiRptsCommon): project_id ' + params.project_id + ', tender_id: ' + params.tender_id + ', stage_id: ' + params.stage_id);
  1045. console.log(ex);
  1046. } finally {
  1047. //
  1048. }
  1049. }
  1050. function setupCustomizeCfg(customizeCfg, rptTpl, defProperties) {
  1051. const tmpObj = {};
  1052. // 1. 字体
  1053. const newFonts = [];
  1054. for (const font of defProperties.fonts) {
  1055. const copyFont = {};
  1056. copyFont.ID = font.ID;
  1057. for (const fontProp of JV.FONT_PROPS) {
  1058. copyFont[fontProp] = font[fontProp];
  1059. }
  1060. newFonts.push(copyFont);
  1061. tmpObj[font.ID] = copyFont;
  1062. }
  1063. const private_setup_font = function(propStr, newFont) {
  1064. if (tmpObj[propStr]) {
  1065. tmpObj[propStr].Name = newFont.Name;
  1066. tmpObj[propStr].FontHeight = String(newFont.FontHeight);
  1067. tmpObj[propStr].FontBold = newFont.FontBold;
  1068. tmpObj[propStr].FontItalic = newFont.FontItalic;
  1069. tmpObj[propStr].FontUnderline = newFont.FontUnderline;
  1070. }
  1071. };
  1072. for (const custFont of customizeCfg.fonts) {
  1073. switch (custFont.CfgDispName) {
  1074. case '表标题':
  1075. private_setup_font('ReportTitle_Main', custFont);
  1076. break;
  1077. case '列标题':
  1078. private_setup_font('HeaderColumn', custFont);
  1079. private_setup_font('FooterColumn', custFont);
  1080. break;
  1081. case '正文内容':
  1082. private_setup_font('Content', custFont);
  1083. break;
  1084. case '合计':
  1085. private_setup_font('GrandTotal', custFont);
  1086. private_setup_font('SectionTotal', custFont);
  1087. break;
  1088. case '表眉/表脚':
  1089. private_setup_font('Header', custFont);
  1090. private_setup_font('Footer', custFont);
  1091. break;
  1092. default:
  1093. break;
  1094. }
  1095. }
  1096. // 1.1 窄体
  1097. if (tmpObj.Content_Narrow) {
  1098. if (customizeCfg.isNarrow) {
  1099. tmpObj.Content_Narrow.Name = 'Arial Narrow';
  1100. } else {
  1101. if (tmpObj.Content) {
  1102. tmpObj.Content_Narrow.Name = tmpObj.Content.Name;
  1103. } else {
  1104. tmpObj.Content_Narrow.Name = '宋体';
  1105. }
  1106. }
  1107. }
  1108. defProperties.fonts = newFonts;
  1109. // 2. 页边距
  1110. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT] = customizeCfg.margins[JV.PROP_LEFT] / 10;
  1111. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT] = customizeCfg.margins[JV.PROP_RIGHT] / 10;
  1112. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_TOP] = customizeCfg.margins[JV.PROP_TOP] / 10;
  1113. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_BOTTOM] = customizeCfg.margins[JV.PROP_BOTTOM] / 10;
  1114. // 3. 边框宽度
  1115. if (customizeCfg.hasOwnProperty('borderThick')) {
  1116. for (let i = 0; i < defProperties.styles.length; i++) {
  1117. const style = defProperties.styles[i];
  1118. if (style.ID === 'BORDER_ALL_AROUND') {
  1119. for (const border of style.border_style) {
  1120. border.LineWeight = customizeCfg.borderThick;
  1121. }
  1122. }
  1123. }
  1124. }
  1125. // 4. 边框竖线
  1126. if (!(customizeCfg.showVerticalLine)) {
  1127. const private_copy_border = function(src) {
  1128. const rst = {};
  1129. rst.Position = src.Position;
  1130. rst.LineWeight = src.LineWeight;
  1131. rst.DashStyle = src.DashStyle;
  1132. rst.Color = src.Color;
  1133. return rst;
  1134. };
  1135. const newStyles = [];
  1136. for (let i = 0; i < defProperties.styles.length; i++) {
  1137. const style = defProperties.styles[i];
  1138. newStyles.push(style);
  1139. if (style.ID === 'BORDER_ALL_AROUND') {
  1140. const newStyle = {};
  1141. newStyle.ID = style.ID;
  1142. newStyle.CfgDispName = style.CfgDispName;
  1143. newStyle.border_style = [];
  1144. for (const border of style.border_style) {
  1145. const newBorder = private_copy_border(border);
  1146. newStyle.border_style.push(newBorder);
  1147. if (border.Position === 'Left' || border.Position === 'Right') {
  1148. newBorder.LineWeight = 0;
  1149. }
  1150. }
  1151. newStyles[newStyles.length - 1] = newStyle;
  1152. }
  1153. }
  1154. defProperties.styles = newStyles;
  1155. }
  1156. // 5. 补0
  1157. const private_Setup_Format = function(tabFields) {
  1158. if (tabFields) {
  1159. for (const tabField of tabFields) {
  1160. if (tabField[JV.PROP_FORMAT]) {
  1161. tabField[JV.PROP_FORMAT] = tabField[JV.PROP_FORMAT].replace(new RegExp('#', 'gm'), '0');
  1162. }
  1163. }
  1164. }
  1165. };
  1166. if (customizeCfg.fillZero) {
  1167. if (rptTpl[JV.NODE_FLOW_INFO]) {
  1168. 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]);
  1169. 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]);
  1170. 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]);
  1171. 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]);
  1172. if (rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  1173. for (const discrete of rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO]) {
  1174. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1175. }
  1176. }
  1177. if (rptTpl[JV.NODE_FLOW_INFO_EX]) {
  1178. 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]);
  1179. 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]);
  1180. 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]);
  1181. 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]);
  1182. 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]);
  1183. if (rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  1184. for (const discrete of rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_DISCRETE_INFO]) {
  1185. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1186. }
  1187. }
  1188. }
  1189. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  1190. 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]);
  1191. if (rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  1192. for (const discrete of rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO]) {
  1193. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1194. }
  1195. }
  1196. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  1197. 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]);
  1198. 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]);
  1199. 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]);
  1200. 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]);
  1201. 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]);
  1202. 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]);
  1203. if (rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  1204. for (const discrete of rptTpl[JV.NODE_CROSS_INFO][JV.NODE_DISCRETE_INFO]) {
  1205. private_Setup_Format(discrete[JV.PROP_DISCRETE_FIELDS]);
  1206. }
  1207. }
  1208. }
  1209. }
  1210. }
  1211. function isFileExisted(file) {
  1212. return new Promise(function(resolve, reject) {
  1213. fs.access(file, err => {
  1214. if (err) {
  1215. reject(false);
  1216. } else {
  1217. resolve(true);
  1218. }
  1219. });
  1220. });
  1221. }
  1222. function fillWaterMark(pageRstArray) {
  1223. const orgWaterMarkWidth = 600;
  1224. const orgWaterMarkHeight = 288;
  1225. const createWaterCell = function(area) {
  1226. const w = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT];
  1227. const h = area[JV.PROP_BOTTOM] - area[JV.PROP_TOP];
  1228. const left = Math.round(area[JV.PROP_LEFT] + w / 2 - orgWaterMarkWidth / 2);
  1229. const right = left + orgWaterMarkWidth;
  1230. const top = Math.round(area[JV.PROP_TOP] + h / 2 - orgWaterMarkHeight / 2);
  1231. const bottom = top + orgWaterMarkHeight;
  1232. return {
  1233. signature_name: JV.SIGNATURE_NAME_DUMMY_WATER_MARK,
  1234. path: '/public/images/not_Approve.png',
  1235. sign_path: '/public/images/not_Approve.png',
  1236. pic: null,
  1237. control: 'Title',
  1238. style: 'Default_None',
  1239. area: {
  1240. Left: left,
  1241. Right: right,
  1242. Top: top,
  1243. Bottom: bottom,
  1244. },
  1245. };
  1246. };
  1247. for (const pageRst of pageRstArray) {
  1248. for (const page of pageRst.items) {
  1249. page[JV.PROP_WATERMARK_CELLS] = [];
  1250. if (page[JV.PROP_PAGE_MERGE_BORDER]) {
  1251. const wmCell = createWaterCell(page[JV.PROP_PAGE_MERGE_BORDER]);
  1252. page[JV.PROP_WATERMARK_CELLS].push(wmCell);
  1253. } else if (page[JV.PAGE_SPECIAL_MERGE_POS]) {
  1254. if (page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT]) {
  1255. for (let i = 0; i < page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT].length; i++) {
  1256. const area = {};
  1257. area[JV.PROP_LEFT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT][i];
  1258. area[JV.PROP_RIGHT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_RIGHT][i];
  1259. area[JV.PROP_TOP] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_TOP][i];
  1260. area[JV.PROP_BOTTOM] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_BOTTOM][i];
  1261. const wmCell = createWaterCell(area);
  1262. page[JV.PROP_WATERMARK_CELLS].push(wmCell);
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. async function encodeSignatureDataUri(roleRel, baseDir) {
  1270. if (roleRel) {
  1271. for (const singleRoleRel of roleRel) {
  1272. if (singleRoleRel.rel_content !== null && singleRoleRel.rel_content !== undefined && singleRoleRel.rel_content !== '') {
  1273. const roleRelContent = JSON.parse(singleRoleRel.rel_content);
  1274. for (const role of roleRelContent) {
  1275. // console.log(role);
  1276. if (role.sign_path !== '') {
  1277. const filePath = baseDir + '/app' + role.sign_path;
  1278. try {
  1279. const res = await isFileExisted(filePath);
  1280. if (res) {
  1281. const bData = fs.readFileSync(filePath);
  1282. const base64Str = bData.toString('base64');
  1283. const datauri = 'data:image/png;base64,' + base64Str;
  1284. role.sign_pic = datauri;
  1285. } else {
  1286. console.log('文件不存在:' + filePath);
  1287. }
  1288. } catch (err) {
  1289. console.error(err);
  1290. }
  1291. }
  1292. }
  1293. singleRoleRel.rel_content = JSON.stringify(roleRelContent);
  1294. } else {
  1295. singleRoleRel.rel_content = [];
  1296. }
  1297. }
  1298. }
  1299. }
  1300. async function encodeDummySignatureDataUri(pageRst, baseDir) {
  1301. if (pageRst) {
  1302. for (const page of pageRst.items) {
  1303. for (const signature of page[JV.PROP_SIGNATURE_CELLS]) {
  1304. if (signature.signature_name === JV.SIGNATURE_NAME_DUMMY) {
  1305. if (signature.path !== '') {
  1306. const filePath = baseDir + '/app' + signature.path;
  1307. try {
  1308. const res = await isFileExisted(filePath);
  1309. if (res) {
  1310. const bData = fs.readFileSync(filePath);
  1311. const base64Str = bData.toString('base64');
  1312. const datauri = 'data:image/png;base64,' + base64Str;
  1313. signature.pic = datauri;
  1314. signature.path = '';
  1315. } else {
  1316. console.log('文件不存在:' + filePath);
  1317. }
  1318. } catch (err) {
  1319. console.error(err);
  1320. }
  1321. }
  1322. }
  1323. }
  1324. // 考虑优化,水印只需要一张即可,不需要每页都设置
  1325. // for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
  1326. // if (signature.path !== '') {
  1327. // const filePath = baseDir + '/app' + signature.path;
  1328. // try {
  1329. // const res = await isFileExisted(filePath);
  1330. // if (res) {
  1331. // const bData = fs.readFileSync(filePath);
  1332. // const base64Str = bData.toString('base64');
  1333. // const datauri = 'data:image/png;base64,' + base64Str;
  1334. // signature.pic = datauri;
  1335. // signature.path = '';
  1336. // } else {
  1337. // console.log('文件不存在:' + filePath);
  1338. // }
  1339. // } catch (err) {
  1340. // console.error(err);
  1341. // }
  1342. // }
  1343. // }
  1344. }
  1345. }
  1346. }
  1347. async function getWatermarkPicData(pageRst, baseDir) {
  1348. let rst = '';
  1349. if (pageRst) {
  1350. for (const page of pageRst.items) {
  1351. for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
  1352. if (signature.path !== '') {
  1353. const filePath = baseDir + '/app' + signature.path;
  1354. try {
  1355. const res = await isFileExisted(filePath);
  1356. if (res) {
  1357. const bData = fs.readFileSync(filePath);
  1358. const base64Str = bData.toString('base64');
  1359. rst = 'data:image/png;base64,' + base64Str;
  1360. break;
  1361. } else {
  1362. console.log('文件不存在:' + filePath);
  1363. }
  1364. } catch (err) {
  1365. console.error(err);
  1366. }
  1367. }
  1368. if (rst !== null) break;
  1369. }
  1370. }
  1371. }
  1372. return rst;
  1373. }
  1374. async function createExportRequestJob(ctx) {
  1375. const params = JSON.parse(ctx.request.body.params);
  1376. // const uuidArr = params.uuidArr;
  1377. const baseDir = this.app.baseDir;
  1378. const roleRelArr = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
  1379. const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
  1380. await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
  1381. for (let idx = 0; idx < pageRstArr.length; idx++) {
  1382. let roleRel = null;
  1383. for (const roleR of roleRelArr) {
  1384. if (roleR.rpt_id === params.rpt_ids[idx]) {
  1385. roleRel = JSON.parse(roleR.rel_content);
  1386. break;
  1387. }
  1388. }
  1389. if (params.exportType === 'xlsx') {
  1390. const zip = rpt_xl_util.exportExcel(pageRstArr[idx], params.pageSize, null, params.isOneSheet, null, null, baseDir, roleRel, null); // 给个null报表名称,返回zip对象自己处理,这样就不用改接口结构了
  1391. zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
  1392. .pipe(fs.createWriteStream(baseDir + '/app/public/download/' + params.uuidArr[idx] + '.xlsx'));
  1393. } else if (params.exportType === 'pdf') {
  1394. // PDF的后期补上
  1395. }
  1396. }
  1397. }
  1398. function mergeTextSignature(isTxtSignature, status, pageData, singleRoleRel, rpt_ids) {
  1399. // 依据需求,有些用户不需要签名图片,那么从源头上把签名从signature_cells转移到cells下,省得后续 预览、打印、导出PDF、导出EXCEL每个地方都改动
  1400. const _mergeSingle = function(_page, _roleRelList, isDeleteSignCell) {
  1401. // console.log(_roleRelList);
  1402. let roleRelContent = [];
  1403. if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
  1404. roleRelContent = JSON.parse(_roleRelList.rel_content);
  1405. }
  1406. for (const page of _page.items) {
  1407. if (page.signature_cells) {
  1408. const deleteSCellsIdx = [];
  1409. for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
  1410. const sCell = page.signature_cells[scIdx];
  1411. if (sCell.signature_name !== JV.SIGNATURE_NAME_DUMMY) {
  1412. sCell.Value = ''; // 这里要先清除原有信息
  1413. sCell.path = '';
  1414. sCell.pic = '';
  1415. let needTransferText = true;
  1416. if (status === 3) {
  1417. for (const role_rel of roleRelContent) {
  1418. if (sCell.signature_name === role_rel.signature_name) {
  1419. sCell.Value = role_rel.user_name; // 只有审核通过了才需要文本签名内容
  1420. if (role_rel.sign_output && role_rel.sign_output.indexOf(NORMAL_SIGN_STR) < 0) {
  1421. // 用户选择不签名,则不迁移
  1422. needTransferText = false;
  1423. }
  1424. break;
  1425. }
  1426. }
  1427. }
  1428. if (needTransferText) {
  1429. const newCell = {
  1430. font: 'Footer',
  1431. control: sCell.control,
  1432. style: sCell.style,
  1433. Value: sCell.Value,
  1434. area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
  1435. };
  1436. page.cells.push(newCell); // 迁移
  1437. deleteSCellsIdx.push(scIdx);
  1438. }
  1439. }
  1440. }
  1441. // 删除 page.signature_cells 签名(草图不能删);
  1442. // console.log('isDeleteSignCell: ' + isDeleteSignCell);
  1443. // console.log(deleteSCellsIdx);
  1444. if (isDeleteSignCell) {
  1445. for (let dIdx = deleteSCellsIdx.length - 1; dIdx >= 0; dIdx--) {
  1446. page.signature_cells.splice(deleteSCellsIdx[dIdx], 1);
  1447. }
  1448. }
  1449. }
  1450. }
  1451. };
  1452. if (isTxtSignature) {
  1453. if (pageData instanceof Array) {
  1454. pageData.forEach((dtlPage, index) => {
  1455. let dftRolRel = [];
  1456. const rpt_id = rpt_ids[index];
  1457. for (const roleRel of singleRoleRel) {
  1458. if (roleRel.rpt_id === rpt_id) {
  1459. dftRolRel = roleRel;
  1460. }
  1461. }
  1462. // console.log(dftRolRel);
  1463. _mergeSingle(dtlPage, dftRolRel, true);
  1464. });
  1465. } else {
  1466. _mergeSingle(pageData, singleRoleRel, false);
  1467. }
  1468. }
  1469. }
  1470. // 因机制问题,此方法必须在mergeTextSignature之前调用
  1471. async function mergeStampSignature(ctx, status, pageData, singleRoleRel, rpt_ids) {
  1472. const dupPicPaths = [];
  1473. const _getMaxRect = function(page) {
  1474. const rect = [100000000, 100000000, 0, 0];
  1475. for (const cell of page.cells) {
  1476. if (rect[0] > cell.area.Left) {
  1477. rect[0] = cell.area.Left;
  1478. }
  1479. if (rect[1] > cell.area.Top) {
  1480. rect[1] = cell.area.Top;
  1481. }
  1482. if (rect[2] < cell.area.Right) {
  1483. rect[2] = cell.area.Right;
  1484. }
  1485. if (rect[3] < cell.area.Bottom) {
  1486. rect[3] = cell.area.Bottom;
  1487. }
  1488. }
  1489. return rect;
  1490. };
  1491. const createStampArea = function(orgCell, controls, maxRect) {
  1492. const ctrl = controls[orgCell.control];
  1493. const rst = { Left: orgCell.area.Left, Right: orgCell.area.Right, Top: orgCell.area.Top, Bottom: orgCell.area.Bottom };
  1494. let pLeft = orgCell.area.Left,
  1495. pTop = orgCell.area.Top;
  1496. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  1497. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
  1498. pLeft = orgCell.area.Left;
  1499. break;
  1500. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
  1501. pLeft = (orgCell.area.Left + orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH) / 2;
  1502. break;
  1503. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
  1504. pLeft = orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH;
  1505. break;
  1506. default:break;
  1507. }
  1508. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  1509. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
  1510. pTop = orgCell.area.Top;
  1511. break;
  1512. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
  1513. pTop = (orgCell.area.Top + orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT) / 2;
  1514. break;
  1515. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
  1516. pTop = orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT;
  1517. break;
  1518. default:break;
  1519. }
  1520. rst.Left = pLeft;
  1521. rst.Top = pTop;
  1522. rst.Right = pLeft + STD_COMP_STAMP_SIZE_WIDTH;
  1523. rst.Bottom = pTop + STD_COMP_STAMP_SIZE_WIDTH;
  1524. // 最后一步,如超过报表范围,则要调整坐标
  1525. // if (rst.Left < maxRect[0]) {
  1526. // const width = maxRect[0] - rst.Left;
  1527. // rst.Left += width;
  1528. // rst.Right += width;
  1529. // }
  1530. // if (rst.Top < maxRect[1]) {
  1531. // const height = maxRect[1] - rst.Top;
  1532. // rst.Top += height;
  1533. // rst.Bottom += height;
  1534. // }
  1535. // if (rst.Right > maxRect[2]) {
  1536. // const width = maxRect[2] - rst.Right; // 负
  1537. // rst.Left += width;
  1538. // rst.Right += width;
  1539. // }
  1540. // if (rst.Bottom > maxRect[3]) {
  1541. // const height = maxRect[3] - rst.Bottom;
  1542. // rst.Top += height;
  1543. // rst.Bottom += height;
  1544. // }
  1545. return rst;
  1546. };
  1547. const _mergeSingleStamp = async function(_page, _roleRelList) {
  1548. let roleRelContent = [];
  1549. if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
  1550. roleRelContent = JSON.parse(_roleRelList.rel_content);
  1551. }
  1552. for (const page of _page.items) {
  1553. const maxRect = _getMaxRect(page);
  1554. if (page.signature_cells) {
  1555. const newStampCells = [];
  1556. for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
  1557. const sCell = page.signature_cells[scIdx];
  1558. for (const role_rel of roleRelContent) {
  1559. if (sCell.signature_name === role_rel.signature_name) {
  1560. if (Array.isArray(role_rel.sign_output) && role_rel.sign_output.length > 0) {
  1561. for (const signType of role_rel.sign_output) {
  1562. switch (signType) {
  1563. case COMPANY_SIGN_STR:
  1564. case PRIVATE_SIGN_STR:
  1565. // 创建一个新的cell
  1566. let stampPath = (signType === COMPANY_SIGN_STR) ? role_rel.company_stamp_path : role_rel.private_stamp_path;
  1567. stampPath = ctx.app.config.fujianOssPath + stampPath;
  1568. if (dupPicPaths.indexOf(stampPath) < 0) {
  1569. dupPicPaths.push(stampPath);
  1570. // await _chkRawPicSizeOSS(ctx, stampPath);
  1571. }
  1572. const newStampCell = {
  1573. signature_name: JV.SIGNATURE_NAME_DUMMY,
  1574. control: sCell.control,
  1575. style: sCell.style,
  1576. path: stampPath,
  1577. isStamp: true,
  1578. maxRect,
  1579. orgArea: sCell.area,
  1580. area: createStampArea(sCell, _page[JV.NODE_CONTROL_COLLECTION], maxRect),
  1581. };
  1582. newStampCells.push(newStampCell);
  1583. break;
  1584. default: break;
  1585. }
  1586. }
  1587. }
  1588. }
  1589. }
  1590. }
  1591. if (newStampCells.length > 0) {
  1592. page.signature_cells = page.signature_cells.concat(newStampCells);
  1593. }
  1594. }
  1595. }
  1596. };
  1597. if (status === 3) {
  1598. if (pageData instanceof Array) {
  1599. pageData.forEach((dtlPage, index) => {
  1600. let dftRolRel = [];
  1601. const rpt_id = rpt_ids[index];
  1602. for (const roleRel of singleRoleRel) {
  1603. if (roleRel.rpt_id === rpt_id) {
  1604. dftRolRel = roleRel;
  1605. }
  1606. }
  1607. _mergeSingleStamp(dtlPage, dftRolRel);
  1608. });
  1609. } else {
  1610. _mergeSingleStamp(pageData, singleRoleRel);
  1611. }
  1612. }
  1613. }
  1614. function mergeSignAudit(pageData, currRoleRelList, currAuditList) {
  1615. for (const page of pageData.items) {
  1616. if (page.signature_audit_cells) {
  1617. for (const sCell of page.signature_audit_cells) {
  1618. sCell.Value = ''; // 这里要先清除原有信息
  1619. if (currRoleRelList && currRoleRelList.length > 0) {
  1620. for (const role_rel of currRoleRelList) {
  1621. if (sCell.signature_name === role_rel.signature_name + '_审核意见') {
  1622. let preDate = '';
  1623. sCell.Value = '同意'; // 只有选择了签名的,才需要初始化一个默认的意见(之前的逻辑在有多个签名,哪怕只选择了一个,其他的意见都会有默认意见)
  1624. if (currAuditList && currAuditList.length > 0) {
  1625. for (const audit_rel of currAuditList) {
  1626. if (role_rel.acc_id === audit_rel.aid) {
  1627. if (audit_rel.end_time > preDate && audit_rel.status === 3) {
  1628. sCell.Value = audit_rel.opinion;
  1629. preDate = audit_rel.end_time;
  1630. }
  1631. // 不能break,实际会有多个审核意见,以最后一个为准
  1632. }
  1633. }
  1634. }
  1635. break;
  1636. }
  1637. }
  1638. }
  1639. }
  1640. }
  1641. }
  1642. }
  1643. function mergeSignDate(pageData, current_stage_id, currRoleRelList, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
  1644. if (currRoleRelList && currRoleRelList.length > 0 && STAGE_AUDIT && STAGE_AUDIT.length > 0) {
  1645. for (let rridx = 0; rridx < currRoleRelList.length; rridx++) {
  1646. const role_rel = currRoleRelList[rridx];
  1647. if (role_rel.sign_date === undefined || role_rel.sign_date === null || role_rel.sign_date === '') {
  1648. const dftDate = _getSignDateByAllScenarios(role_rel.acc_id, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST);
  1649. role_rel.sign_date = dftDate;
  1650. }
  1651. }
  1652. }
  1653. if (currRoleRelList && currRoleRelList.length > 0) {
  1654. for (const page of pageData.items) {
  1655. if (page.signature_date_cells) {
  1656. for (const sCell of page.signature_date_cells) {
  1657. sCell.Value = _getSignDateDftName();
  1658. for (const role_rel of currRoleRelList) {
  1659. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  1660. if (role_rel.sign_date !== '') {
  1661. if (typeof role_rel.sign_date === 'string') {
  1662. role_rel.sign_date = new Date(role_rel.sign_date);
  1663. }
  1664. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  1665. }
  1666. break;
  1667. }
  1668. }
  1669. }
  1670. }
  1671. }
  1672. }
  1673. }
  1674. function _getSignDateByAllScenarios(userAccId, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
  1675. let rst = '';
  1676. let hasAudit = false;
  1677. for (const stg_audit of STAGE_AUDIT) {
  1678. if (stg_audit.aid === userAccId) {
  1679. hasAudit = true;
  1680. if (stg_audit.status === 3) {
  1681. rst = stg_audit.end_time;
  1682. } else {
  1683. rst = '';
  1684. }
  1685. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  1686. }
  1687. }
  1688. let isOrgRpt = false;
  1689. for (const stg of STAGE_LIST) {
  1690. if (stg.id === current_stage_id) {
  1691. if (stg.user_id === userAccId) {
  1692. isOrgRpt = true;
  1693. }
  1694. break;
  1695. }
  1696. }
  1697. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  1698. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  1699. rst = STAGE_AUDIT_ORG[0].begin_time;
  1700. }
  1701. }
  1702. if (!isOrgRpt && !hasAudit) {
  1703. // 非审批流程人员以及非原报,则显示期截至时间
  1704. for (const stg of STAGE_LIST) {
  1705. if (stg.id === current_stage_id && stg.period) {
  1706. const period = stg.period.split(' ~ ');
  1707. if (period.length === 2) {
  1708. rst = period[1];
  1709. }
  1710. }
  1711. }
  1712. }
  1713. return rst;
  1714. }
  1715. function _getSignDateDftName() {
  1716. return ' 年 月 日';
  1717. }
  1718. async function _chkRawPicSize(pageData, baseDir) {
  1719. let rst = 0;
  1720. const picKeys = [];
  1721. for (let pi = 0; pi < pageData.items.length; pi++) {
  1722. // 每页判断
  1723. for (let ci = 0; ci < pageData.items[pi][JV.PROP_SIGNATURE_CELLS].length; ci++) {
  1724. const picPath = pageData.items[pi][JV.PROP_SIGNATURE_CELLS][ci].path;
  1725. // if (picPath && picPath.indexOf('/sign') < 0 && picKeys.indexOf(picPath) < 0) {
  1726. if (picPath && picPath !== '' && picKeys.indexOf(picPath) < 0) {
  1727. // 签名图片也要计算在内,反正不重复
  1728. picKeys.push(picPath);
  1729. }
  1730. // signature_cells PROP_SIGNATURE_CELLS
  1731. }
  1732. }
  1733. // console.log(picKeys);
  1734. for (const pKey of picKeys) {
  1735. const filePath = `${baseDir}/app${pKey}`;
  1736. console.log('filePath: ' + filePath);
  1737. let isExist = false;
  1738. try {
  1739. isExist = await isFileExisted(filePath);
  1740. } catch (ex) {
  1741. isExist = false;
  1742. }
  1743. console.log('isExist: ' + isExist);
  1744. if (isExist) {
  1745. const obj = fs.statSync(filePath);
  1746. if (obj) {
  1747. rst += obj.size;
  1748. } else {
  1749. console.log('no statSync resutl: ' + filePath);
  1750. }
  1751. // rst += fs.statSync(filePath).size;
  1752. } else {
  1753. console.log(`${pKey} not exists!`);
  1754. }
  1755. }
  1756. return rst;
  1757. }
  1758. async function _chkRawPicSizeOSS(ctx, picPath) {
  1759. // 计量的草图、签章都放在OSS服务器上,需要另外的方式来获取,考虑到效率问题,机制上得有所变化
  1760. const rst = [0, 0];
  1761. try {
  1762. const pf = await ctx.app.signPdfOss.get(picPath);
  1763. console.log('get pic successfully!');
  1764. console.log(pf);
  1765. } catch (ex) {
  1766. console.log(ex);
  1767. } finally {
  1768. console.log('finally!');
  1769. }
  1770. return rst;
  1771. }
  1772. function _resetPageDataByBreaks(pageDataArr, breakAmt, rpt_names, newRptNames) {
  1773. const rst = [];
  1774. for (let pi = 0; pi < pageDataArr.length; pi++) {
  1775. const pageItem = pageDataArr[pi];
  1776. const currentRptName = rpt_names[pi];
  1777. if (pageItem.items.length > breakAmt) {
  1778. let pa = Math.floor(pageItem.items.length / breakAmt);
  1779. if (pageItem.items.length % breakAmt > 0) {
  1780. pa++;
  1781. }
  1782. for (let idx = 0; idx < pa; idx++) {
  1783. const newPageDataObj = { items: [] };
  1784. // newPageDataObj[JV.NODE_PAGE_INFO] = JSON.parse(JSON.stringify(pageItem[JV.NODE_PAGE_INFO]));
  1785. newPageDataObj[JV.NODE_PAGE_INFO] = pageItem[JV.NODE_PAGE_INFO];
  1786. // newPageDataObj[JV.BAND_PROP_MERGE_BAND] = JSON.parse(JSON.stringify(pageItem[JV.BAND_PROP_MERGE_BAND]));
  1787. newPageDataObj[JV.BAND_PROP_MERGE_BAND] = pageItem[JV.BAND_PROP_MERGE_BAND];
  1788. newPageDataObj[JV.NODE_FONT_COLLECTION] = pageItem[JV.NODE_FONT_COLLECTION];
  1789. newPageDataObj[JV.NODE_STYLE_COLLECTION] = pageItem[JV.NODE_STYLE_COLLECTION];
  1790. newPageDataObj[JV.NODE_CONTROL_COLLECTION] = pageItem[JV.NODE_CONTROL_COLLECTION];
  1791. for (let dIdx = idx * breakAmt; dIdx < (Math.min((idx + 1) * breakAmt, pageItem.items.length)); dIdx++) {
  1792. newPageDataObj.items.push(pageItem.items[dIdx]);
  1793. }
  1794. rst.push(newPageDataObj);
  1795. newRptNames.push(currentRptName + '_' + (idx + 1));
  1796. }
  1797. } else {
  1798. rst.push(pageItem);
  1799. newRptNames.push(currentRptName);
  1800. }
  1801. }
  1802. return rst;
  1803. }