report_controller.js 75 KB

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