report_controller.js 75 KB

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