report_controller.js 74 KB

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