report_controller.js 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  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. await ctx.service.stage.loadStageAuditViewData(ctx.stage);
  46. }
  47. async _chkIfStageAuditor(ctx, stage) {
  48. //
  49. }
  50. async _filterStageList(ctx, stageList) {
  51. //
  52. // throw
  53. }
  54. async _createNodes(ctx, source_type, pid) {
  55. const treeNodes = await ctx.service.rptTreeNode.getNodesBySourceType([pid], source_type); // 这个查定制的
  56. const commonTreeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1]); // 这个查通用的
  57. const nodeItems = JSON.parse(commonTreeNodes[0].items);
  58. const commonArrs = [];
  59. nodeItems.forEach(nodeItem => {
  60. const srcType = nodeItem.source_type ? nodeItem.source_type : 1;
  61. if (srcType === source_type) {
  62. commonArrs.push(nodeItem);
  63. }
  64. });
  65. // 加一个dummy的通用报表
  66. const dummyCommonRptNode = { id: 1, name: '通用报表', pid: -1, rpt_type: 0, items: JSON.stringify(commonArrs) };
  67. treeNodes.push(dummyCommonRptNode);
  68. const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
  69. return { treeNodes, commonArrs, custCfg };
  70. }
  71. async _getInvolveAcc(ctx, tId) {
  72. // 获取所有项目参与者
  73. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  74. where: { project_id: ctx.session.sessionProject.id, enable: 1 },
  75. columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
  76. });
  77. const newAccountGroup = accountGroup.map((item, idx) => {
  78. const groupList = accountList.filter(item => item.account_group === idx);
  79. return { groupName: item, groupList };
  80. });
  81. const where = { tid: tId };
  82. const advance = await ctx.service.advance.getAllDataByCondition({
  83. columns: ['id', 'order', 'status', 'selected', 'type'],
  84. where,
  85. orders: [['type', 'asc'], ['create_time', 'desc']],
  86. });
  87. advance.forEach(x => {
  88. x.statusStr = auditConst.advance.statusString[x.status];
  89. x.typeStr = advanceConst.typeColMap[x.type].text;
  90. });
  91. return { accountList, newAccountGroup, advance };
  92. }
  93. /**
  94. * 报表显示页面
  95. *
  96. * @param {Object} ctx - egg全局context
  97. * @return {void}
  98. */
  99. async index(ctx) {
  100. // 普通情况(计量期入口)
  101. try {
  102. await this._getStageAuditViewData(ctx);
  103. const pageShow = ctx.session.sessionProject.page_show;
  104. pageShow.showArchive = 1;
  105. const tender = ctx.tender;
  106. const stage = ctx.stage;
  107. let stage_id = -1;
  108. let stage_order = -1;
  109. let sorder = -1;
  110. let stage_times = -1;
  111. let stage_status = -1;
  112. const { treeNodes, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.tender, tender.data.project_id);
  113. const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
  114. const stageList = await ctx.service.stage.getValidStagesShort(tender.id);
  115. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.data.project_id } }); // 找公司章用的
  116. const isAdmin = ctx.session.sessionUser.is_admin;
  117. // console.log('this.ctx.session.sessionUser.accountId: ' + this.ctx.session.sessionUser.accountId);
  118. if (stage && stage.status === auditConst.stage.status.uncheck) {
  119. // 得判断账号是否在审核人列表中(不含原报)
  120. if (stage.auditorList === undefined || stage.auditorList === null) {
  121. stage.auditorList = await ctx.service.stageAudit.getAuditors(ctx.stage.id, ctx.stage.times);
  122. }
  123. let isAudit = false;
  124. for (const audit of stage.auditorList) {
  125. if (audit.aid === this.ctx.session.sessionUser.accountId) {
  126. isAudit = true;
  127. break;
  128. }
  129. }
  130. if (isAudit) {
  131. throw '未上报!';
  132. }
  133. } else {
  134. // 剔除未上报期(审核人(非原报人)才需要判断)
  135. for (let idx = stageList.length - 1; idx >= 0; idx--) {
  136. if (stageList[idx].status === auditConst.stage.status.uncheck) {
  137. if (stageList[idx].auditorList === undefined || stageList[idx].auditorList === null) {
  138. stageList[idx].auditorList = await ctx.service.stageAudit.getAuditors(stageList[idx].id, stageList[idx].times);
  139. }
  140. let isAudit = false;
  141. for (const audit of stageList[idx].auditorList) {
  142. if (audit.aid === this.ctx.session.sessionUser.accountId) {
  143. isAudit = true;
  144. break;
  145. }
  146. }
  147. if (isAudit) {
  148. stageList.splice(idx, 1);
  149. }
  150. }
  151. }
  152. }
  153. let lastAuditor = null;
  154. if (stage) {
  155. lastAuditor = await ctx.service.stageAudit.getLastestAuditor(ctx.stage.id, ctx.stage.times, auditConst.stage.status.checked);
  156. } else {
  157. lastAuditor = stageList.length > 0 ? await ctx.service.stageAudit.getLastestAuditor(stageList[stageList.length - 1].id, stageList[stageList.length - 1].times, auditConst.stage.status.checked) : null;
  158. }
  159. let archiveList = [];
  160. if (stage) {
  161. const archives = await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, ctx.stage.id);
  162. if (archives.length > 0) {
  163. archiveList = JSON.parse(archives[0].content);
  164. }
  165. } else {
  166. const archives = stageList.length > 0 ? await ctx.service.rptArchive.getPrjStgArchive(tender.data.project_id, stageList[stageList.length - 1].id) : [];
  167. // console.log(archives);
  168. if (archives && archives.length > 0) {
  169. archiveList = JSON.parse(archives[0].content);
  170. }
  171. }
  172. let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(tender.data.project_id);
  173. const roleList = await ctx.service.signatureRole.getSignatureRolesByTenderId(tender.id);
  174. const usedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(tender.id);
  175. // ctx.session.sessionUser.is_admin
  176. // const pageShow = ctx.session.sessionProject.page_show;
  177. // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
  178. if (!ctx.session.sessionUser.is_admin && pageShow.individualSign === 1) {
  179. // 削减其他account
  180. const newAccList = [];
  181. for (const acc of prjAccList) {
  182. if (acc.id === this.ctx.session.sessionUser.accountId) {
  183. newAccList.push(acc);
  184. }
  185. }
  186. prjAccList = newAccList;
  187. }
  188. // 分类列表
  189. const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
  190. // 获取用户权限
  191. const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
  192. const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
  193. // 获取用户可查看的标段
  194. const tenderList = await this.ctx.service.tender.getList('', userPermission);
  195. for (const t of tenderList) {
  196. if (t.ledger_status === auditConst.ledger.status.checked) {
  197. t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
  198. // if (t.lastStage) {
  199. // await this.ctx.service.stage.checkStageGatherData(t.lastStage, this.ctx.session.sessionUser.is_admin);
  200. // }
  201. }
  202. }
  203. // 获取汇总表,历史选择
  204. const cid = this.ctx.helper._.map(treeNodes, 'id');
  205. const customSelects = {};
  206. if (ctx.stage) {
  207. customSelects.audit_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  208. reportConst.rptCustomType[JV.NODE_CUS_AUDIT_SELECT], ctx.tender.id, ctx.stage.id);
  209. customSelects.stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(
  210. ctx.stage.stage_id, ctx.stage.stage_times);
  211. customSelects.stageFlow.forEach(x => {
  212. if (!x) return;
  213. x.visible = (!ctx.session.sessionUser.is_admin && ctx.session.sessionProject.page_show.individualSign === 1)
  214. ? x.aid === ctx.session.sessionUser.accountId : true;
  215. });
  216. } else {
  217. customSelects.audit_select = [];
  218. }
  219. customSelects.gather_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  220. reportConst.rptCustomType[JV.NODE_CUS_GATHER_SELECT], ctx.tender.id, -1);
  221. customSelects.stage_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  222. reportConst.rptCustomType[JV.NODE_CUS_STAGE_SELECT], ctx.tender.id, -1);
  223. customSelects.change_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  224. reportConst.rptCustomType[JV.NODE_CUS_CHANGE_SELECT], ctx.tender.id, -1);
  225. customSelects.material_sum_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
  226. reportConst.rptCustomType[JV.NODE_CUS_MATERIAL_SUM_SELECT], ctx.tender.id, -1);
  227. const dataSelects = {};
  228. dataSelects.material_select = await ctx.service.rptCustomDefine.getDataSelectByRpt(cid,
  229. reportConst.rptDataType[JV.NODE_CUS_MATERIAL_SELECT]);
  230. const materialList = await ctx.service.material.getValidMaterials(ctx.tender.id);
  231. if (stage !== null && stage !== undefined) {
  232. stage_id = stage.id;
  233. stage_order = stage.order;
  234. sorder = stage.curOrder;
  235. stage_times = stage.times;
  236. stage_status = stage.status;
  237. }
  238. for (const prjAcc of prjAccList) {
  239. prjAcc.account_group = prjAcc.company;
  240. }
  241. const cust_select_keys = JSON.stringify(['common', 'customize']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
  242. const rpt_tpl_items = { customize: [], common: [] };
  243. if (custTreeNodes.length > 0) {
  244. const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
  245. if (cust_select_item.common) rpt_tpl_items.common = cust_select_item.common;
  246. if (cust_select_item.customize) rpt_tpl_items.customize = cust_select_item.customize;
  247. }
  248. // 获取所有项目参与者
  249. const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, this.ctx.tender.id);
  250. const renderData = {
  251. accountGroup: newAccountGroup,
  252. accountList,
  253. unitList: JSON.stringify(unitList),
  254. tender: tender.data,
  255. tenderInfo: tender.info,
  256. rpt_tpl_data: JSON.stringify(treeNodes),
  257. cust_tpl_data: JSON.stringify(rpt_tpl_items),
  258. cust_select_keys,
  259. cust_cfg: JSON.stringify(custCfg),
  260. project_id: tender.data.project_id,
  261. tender_id: tender.id,
  262. tender_name: tender.data.name,
  263. budget_id: -1,
  264. sp_id: -1,
  265. detail_id: -1,
  266. stg_id: stage_id,
  267. stg_order: stage_order,
  268. cur_order: sorder,
  269. stg_times: stage_times,
  270. stg_status: stage_status,
  271. stage_list: JSON.stringify(stageList),
  272. prj_account_list: JSON.stringify(prjAccList),
  273. role_list: JSON.stringify(roleList),
  274. used_list: JSON.stringify(usedList),
  275. tenderMenu,
  276. preUrl: '/tender/' + ctx.tender.id + '/measure/stage/' + ctx.params.order,
  277. measureType,
  278. categoryData,
  279. tenderList,
  280. auditConst: auditConst.stage,
  281. ledgerAuditConst: auditConst.ledger,
  282. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.report.main),
  283. customSelects,
  284. rptCustomType: reportConst.rptCustomType,
  285. materialList,
  286. stages: stageList,
  287. dataSelects,
  288. // pageShow: JSON.stringify(pageShow),
  289. pageShow,
  290. authMobile: accountInfo.auth_mobile,
  291. shenpiConst,
  292. archiveList,
  293. lastAuditor,
  294. rpt_id: ctx.query.rpt_id,
  295. isAdmin,
  296. prePay: JSON.stringify(advance),
  297. OSS_PATH: ctx.app.config.fujianOssPath,
  298. viewPmData: PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission),
  299. auditType: auditConst.auditType,
  300. source_type: 1,
  301. bglObj: 'null',
  302. changes: 'null',
  303. };
  304. await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
  305. // await this.layout('report/index.ejs', renderData);
  306. // 在这里启动一个cron job,删除临时创建的excel文件
  307. if (!rptCronJob.started) {
  308. try {
  309. // console.log('rptCronJob.started: ' + rptCronJob.started);
  310. rptCronJob.started = true;
  311. // console.log('this.app.baseDir: ' + this.app.baseDir);
  312. rptCronJob.createJob(null, this.app.baseDir + '/app/public/download');
  313. } catch (ex) {
  314. rptCronJob.started = false;
  315. }
  316. }
  317. } catch (err) {
  318. this.log(err);
  319. ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage');
  320. }
  321. }
  322. async indexForPaymentSafe(ctx) {
  323. // 安全生产费入口
  324. try {
  325. await this._getStageAuditViewData(ctx);
  326. const pageShow = ctx.session.sessionProject.page_show;
  327. // pageShow.showArchive = 1;
  328. pageShow.showArchive = 0;
  329. // pageShow.closeWatermark = 1;
  330. const tenderId = ctx.params.id;
  331. const paymentDetail_id = ctx.params.did;
  332. // 支付审批: ctx.params.did 是 zh_payment_detail表的id, 通过这个did在 zh_payment_detail_audit表里找审核信息(td_id = ctx.params.did)
  333. // 没有计量期的概念!!!
  334. // const paymentAuditorList = await ctx.service.paymentDetailAudit.getAuditors(paymentDetail_id);
  335. const tender = ctx.paymentTender;
  336. const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.payment_safe, tender.pid);
  337. const stageList = [];
  338. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.pid } }); // 找公司章用的
  339. const isAdmin = ctx.session.sessionUser.is_admin;
  340. const lastAuditor = null;
  341. const archiveList = [];
  342. let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(tender.pid);
  343. const roleList = await ctx.service.signatureRole.getSignatureRolesByTenderId(tender.id);
  344. const usedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(tender.id);
  345. // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
  346. if (!ctx.session.sessionUser.is_admin && pageShow.individualSign === 1) {
  347. // 削减其他account
  348. const newAccList = [];
  349. for (const acc of prjAccList) {
  350. if (acc.id === this.ctx.session.sessionUser.accountId) {
  351. newAccList.push(acc);
  352. }
  353. }
  354. prjAccList = newAccList;
  355. }
  356. // 分类列表
  357. const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
  358. // 获取用户权限
  359. const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
  360. // const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
  361. // 获取用户可查看的标段
  362. // ...
  363. const tenderList = [];
  364. const cid = this.ctx.helper._.map(treeNodes, 'id');
  365. const customSelects = null;
  366. const dataSelects = {};
  367. dataSelects.material_select = await ctx.service.rptCustomDefine.getDataSelectByRpt(cid,
  368. reportConst.rptDataType[JV.NODE_CUS_MATERIAL_SELECT]);
  369. const materialList = await ctx.service.material.getValidMaterials();
  370. const stage_id = -100;
  371. let stage_order = -1;
  372. let sorder = -1;
  373. let stage_times = -1;
  374. let stage_status = -1;
  375. const paymentDetailList = await ctx.service.paymentDetail.getDetail(paymentDetail_id);
  376. if (paymentDetailList && paymentDetailList.length > 0) {
  377. const payment = paymentDetailList[0];
  378. stage_status = payment.status;
  379. stage_order = payment.order;
  380. sorder = stage_order;
  381. stage_times = payment.times;
  382. stageList.push({ id: stage_id, user_id: payment.uid, status: payment.status });
  383. }
  384. for (const prjAcc of prjAccList) {
  385. prjAcc.account_group = prjAcc.company;
  386. }
  387. const cust_select_keys = JSON.stringify(['common_safe', 'customize_safe']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求,安全生产费没有这个,就过了
  388. const rpt_tpl_items = { customize: [], common: [] };
  389. commonArrs.forEach(item => {
  390. rpt_tpl_items.common.push(item.name);
  391. });
  392. // 获取所有项目参与者
  393. const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
  394. const renderData = {
  395. accountGroup: newAccountGroup,
  396. accountList,
  397. unitList: JSON.stringify(unitList),
  398. tender: null,
  399. tenderInfo: null,
  400. rpt_tpl_data: JSON.stringify(treeNodes),
  401. cust_tpl_data: JSON.stringify(rpt_tpl_items),
  402. cust_select_keys,
  403. cust_cfg: JSON.stringify(custCfg),
  404. project_id: tender.pid,
  405. tender_id: tenderId,
  406. tender_name: tender.name,
  407. detail_id: paymentDetail_id,
  408. stg_id: stage_id,
  409. budget_id: -1,
  410. sp_id: -1,
  411. stg_order: stage_order,
  412. cur_order: sorder,
  413. stg_times: stage_times,
  414. stg_status: stage_status,
  415. stage_list: JSON.stringify(stageList),
  416. prj_account_list: JSON.stringify(prjAccList),
  417. role_list: JSON.stringify(roleList),
  418. used_list: JSON.stringify(usedList),
  419. tenderMenu,
  420. preUrl: '/tender/' + tenderId + '/measure/stage/' + ctx.params.order,
  421. measureType,
  422. categoryData,
  423. tenderList,
  424. auditConst: auditConst.stage,
  425. ledgerAuditConst: auditConst.ledger,
  426. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.report.main),
  427. customSelects,
  428. rptCustomType: reportConst.rptCustomType,
  429. materialList,
  430. stages: stageList,
  431. dataSelects,
  432. pageShow,
  433. authMobile: accountInfo.auth_mobile,
  434. shenpiConst,
  435. archiveList,
  436. lastAuditor,
  437. rpt_id: ctx.query.rpt_id,
  438. isAdmin,
  439. prePay: JSON.stringify(advance),
  440. OSS_PATH: ctx.app.config.fujianOssPath,
  441. viewPmData: PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission),
  442. source_type: 101,
  443. bglObj: 'null',
  444. changes: 'null',
  445. };
  446. /*
  447. //*/
  448. await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
  449. } catch (err) {
  450. this.log(err);
  451. // ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage');
  452. }
  453. }
  454. async indexForDynamicGrandTotal(ctx) {
  455. // 动态决算(动态投资)入口 (以独立报表为蓝本(index入口))
  456. try {
  457. await this._getStageAuditViewData(ctx);
  458. const pageShow = ctx.session.sessionProject.page_show;
  459. // pageShow.closeWatermark = 1;
  460. pageShow.showArchive = 0;
  461. pageShow.closeShowAllCustomized = 0;
  462. const tenderId = -1;
  463. const paymentDetail_id = -1;
  464. // const tender = ctx.paymentTender;
  465. const pid = ctx.budget.pid;
  466. const budget_id = ctx.budget.id;
  467. const subProj = await ctx.service.subProject.getDataByCondition({ budget_id });
  468. const sp_id = subProj.id;
  469. const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.budget, pid);
  470. const stageList = [];
  471. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid } }); // 找公司章用的
  472. const isAdmin = ctx.session.sessionUser.is_admin;
  473. const lastAuditor = null;
  474. const archiveList = [];
  475. let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(pid);
  476. const roleList = [];
  477. const usedList = [];
  478. // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
  479. if (!ctx.session.sessionUser.is_admin && pageShow.individualSign === 1) {
  480. // 削减其他account
  481. const newAccList = [];
  482. for (const acc of prjAccList) {
  483. if (acc.id === this.ctx.session.sessionUser.accountId) {
  484. newAccList.push(acc);
  485. }
  486. }
  487. prjAccList = newAccList;
  488. }
  489. // 分类列表
  490. const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
  491. // 获取用户权限
  492. const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
  493. // const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
  494. // 获取用户可查看的标段
  495. // ...
  496. const tenderList = [];
  497. const cid = this.ctx.helper._.map(treeNodes, 'id');
  498. const customSelects = null;
  499. const dataSelects = {};
  500. dataSelects.material_select = await ctx.service.rptCustomDefine.getDataSelectByRpt(cid,
  501. reportConst.rptDataType[JV.NODE_CUS_MATERIAL_SELECT]);
  502. const materialList = await ctx.service.material.getValidMaterials();
  503. const stage_id = -200;
  504. const stage_order = -1;
  505. const sorder = -1;
  506. const stage_times = -1;
  507. const stage_status = -1;
  508. for (const prjAcc of prjAccList) {
  509. prjAcc.account_group = prjAcc.company;
  510. }
  511. const cust_select_keys = JSON.stringify(['common_dynamic', 'customize_dynamic']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
  512. const rpt_tpl_items = { customize: [], common: [] };
  513. const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
  514. if (custTreeNodes.length > 0) {
  515. const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
  516. if (cust_select_item.common_dynamic) rpt_tpl_items.common = cust_select_item.common_dynamic;
  517. if (cust_select_item.customize_dynamic) rpt_tpl_items.customize = cust_select_item.customize_dynamic;
  518. if (!cust_select_item.hasOwnProperty('common_dynamic') && !cust_select_item.hasOwnProperty('customize_dynamic')) {
  519. commonArrs.forEach(item => {
  520. rpt_tpl_items.common.push(item.name);
  521. });
  522. }
  523. } else {
  524. commonArrs.forEach(item => {
  525. rpt_tpl_items.common.push(item.name);
  526. });
  527. }
  528. // 获取所有项目参与者
  529. const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
  530. const renderData = {
  531. accountGroup: newAccountGroup,
  532. accountList,
  533. unitList: JSON.stringify(unitList),
  534. tender: null,
  535. tenderInfo: null,
  536. rpt_tpl_data: JSON.stringify(treeNodes),
  537. cust_tpl_data: JSON.stringify(rpt_tpl_items),
  538. cust_select_keys,
  539. cust_cfg: JSON.stringify(custCfg),
  540. project_id: pid,
  541. tender_id: tenderId,
  542. budget_id,
  543. sp_id,
  544. tender_name: ctx.budget.name,
  545. detail_id: paymentDetail_id,
  546. stg_id: stage_id,
  547. stg_order: stage_order,
  548. cur_order: sorder,
  549. stg_times: stage_times,
  550. stg_status: stage_status,
  551. stage_list: JSON.stringify(stageList),
  552. prj_account_list: JSON.stringify(prjAccList),
  553. role_list: JSON.stringify(roleList),
  554. used_list: JSON.stringify(usedList),
  555. tenderMenu,
  556. preUrl: '/tender/' + tenderId + '/measure/stage/' + ctx.params.order,
  557. measureType,
  558. categoryData,
  559. tenderList,
  560. auditConst: auditConst.stage,
  561. ledgerAuditConst: auditConst.ledger,
  562. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.report.main),
  563. customSelects,
  564. rptCustomType: reportConst.rptCustomType,
  565. materialList,
  566. stages: stageList,
  567. dataSelects,
  568. pageShow,
  569. authMobile: accountInfo.auth_mobile,
  570. shenpiConst,
  571. archiveList,
  572. lastAuditor,
  573. rpt_id: ctx.query.rpt_id,
  574. isAdmin,
  575. prePay: JSON.stringify(advance),
  576. OSS_PATH: ctx.app.config.fujianOssPath,
  577. viewPmData: PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission),
  578. source_type: 200,
  579. bglObj: 'null',
  580. changes: 'null',
  581. };
  582. await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
  583. } catch (err) {
  584. this.log(err);
  585. }
  586. }
  587. async _indexForBGL(ctx, source_type, stage_id) {
  588. // 变更令、变更方案、变更立项、变更申请 报表入口
  589. try {
  590. await this._getStageAuditViewData(ctx);
  591. const pageShow = ctx.session.sessionProject.page_show;
  592. pageShow.closeWatermark = 1;
  593. pageShow.showArchive = 1;
  594. pageShow.closeShowAllCustomized = 0;
  595. const tenderId = ctx.params.id;
  596. const bglObj = {};
  597. if (stage_id === -300) {
  598. bglObj.BUSINESS_ID = ctx.params.cid;
  599. bglObj.change = await ctx.service.change.getChangeByCid(ctx.params.cid);
  600. bglObj.currentBz = bglObj.change;
  601. bglObj.status = bglObj.change.status;
  602. // const audit = await ctx.service.changeAudit.getChangeByCid(ctx.params.cid);
  603. }
  604. if (stage_id === -301) {
  605. bglObj.BUSINESS_ID = ctx.params.cplnid;
  606. bglObj.change_plan = await ctx.service.changePlan.getDataById(ctx.params.cplnid);
  607. bglObj.currentBz = bglObj.change_plan;
  608. bglObj.status = bglObj.change_plan.status;
  609. }
  610. if (stage_id === -302) {
  611. bglObj.BUSINESS_ID = ctx.params.cprjid;
  612. bglObj.change_project = await ctx.service.changeProject.getDataById(ctx.params.cprjid);
  613. bglObj.currentBz = bglObj.change_project;
  614. bglObj.status = bglObj.change_project.status;
  615. }
  616. if (stage_id === -303) {
  617. bglObj.BUSINESS_ID = ctx.params.caid;
  618. bglObj.change_apply = await ctx.service.changeApply.getDataById(ctx.params.caid);
  619. bglObj.currentBz = bglObj.change_apply;
  620. bglObj.status = bglObj.change_apply.status;
  621. }
  622. const changeId = ctx.params.cid;
  623. const paymentDetail_id = -1;
  624. const pid = ctx.session.sessionProject.id;
  625. const budget_id = -1;
  626. const sp_id = -1;
  627. const { treeNodes, custCfg } = await this._createNodes(ctx, source_type, pid);
  628. const state = ctx.session.sessionProject.page_show.openChangeState && ctx.query.state ? parseInt(ctx.query.state) : 0;
  629. const changes = await ctx.service.change.getListByStatus(tenderId, 0, 0, 0, 0, state);
  630. let change_times = 1;
  631. const stageList = [];
  632. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid } }); // 找公司章用的
  633. const isAdmin = ctx.session.sessionUser.is_admin;
  634. let lastAuditor = null;
  635. for (let cIdx = 0; cIdx < changes.length; cIdx++) {
  636. if (changes[cIdx].cid === changeId) {
  637. if (changes[cIdx].times > change_times) change_times = changes[cIdx].times;
  638. if (changes[cIdx].status === 3) {
  639. const changeAudit = await ctx.service.changeAudit.getLastUser(changeId, changes[cIdx].times, 3);
  640. if (changeAudit) {
  641. lastAuditor = { end_time: changeAudit.sin_time, sdesc: changeAudit.sdesc };
  642. }
  643. }
  644. break;
  645. }
  646. }
  647. let archiveList = [];
  648. const archives = await ctx.service.rptArchive.getArchiveByBzId(pid, stage_id, bglObj.BUSINESS_ID);
  649. if (archives.length > 0) {
  650. archiveList = JSON.parse(archives[0].content);
  651. }
  652. let prjAccList = await ctx.service.projectAccount.getAllAccountByProjectId(pid);
  653. const roleList = [];
  654. const usedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(tenderId);
  655. // 根据需求,如果开启了‘开启个人「签字」’功能,则只能是本身用户签名,管理员例外
  656. if (!ctx.session.sessionUser.is_admin && pageShow.individualSign === 1) {
  657. // 削减其他account
  658. const newAccList = [];
  659. for (const acc of prjAccList) {
  660. if (acc.id === this.ctx.session.sessionUser.accountId) {
  661. newAccList.push(acc);
  662. }
  663. }
  664. prjAccList = newAccList;
  665. }
  666. // 分类列表
  667. const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
  668. // 获取用户权限
  669. const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
  670. // const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
  671. // 获取用户可查看的标段
  672. // ...
  673. const tenderList = [];
  674. const cid = this.ctx.helper._.map(treeNodes, 'id');
  675. const customSelects = null;
  676. const dataSelects = {};
  677. dataSelects.material_select = await ctx.service.rptCustomDefine.getDataSelectByRpt(cid,
  678. reportConst.rptDataType[JV.NODE_CUS_MATERIAL_SELECT]);
  679. const materialList = await ctx.service.material.getValidMaterials();
  680. const stage_order = -1;
  681. const sorder = -1;
  682. const stage_times = -1;
  683. const stage_status = -1;
  684. for (const prjAcc of prjAccList) {
  685. // prjAcc.account_group = accountGroup[prjAcc.account_group];
  686. prjAcc.account_group = prjAcc.company;
  687. }
  688. const cust_select_keys = JSON.stringify(['common', 'customize']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
  689. const rpt_tpl_items = { customize: [], common: [] };
  690. if (treeNodes && treeNodes.length > 0) {
  691. for (let tIdx = treeNodes.length - 1; tIdx >= 0; tIdx--) {
  692. if (treeNodes[tIdx].name === '通用报表') {
  693. const items = JSON.parse(treeNodes[tIdx].items);
  694. for (let itemIdx = items.length - 1; itemIdx >= 0; itemIdx--) {
  695. rpt_tpl_items.common.push(items[itemIdx].name);
  696. }
  697. } else {
  698. rpt_tpl_items.customize.push(treeNodes[tIdx].name);
  699. }
  700. }
  701. }
  702. // 获取所有项目参与者
  703. const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
  704. const renderData = {
  705. accountGroup: newAccountGroup,
  706. accountList,
  707. unitList: JSON.stringify(unitList),
  708. tender: null,
  709. tenderInfo: null,
  710. rpt_tpl_data: JSON.stringify(treeNodes),
  711. cust_tpl_data: JSON.stringify(rpt_tpl_items),
  712. cust_select_keys,
  713. cust_cfg: JSON.stringify(custCfg),
  714. project_id: pid,
  715. tender_id: tenderId,
  716. budget_id,
  717. sp_id,
  718. tender_name: ctx.tender.data.name,
  719. detail_id: paymentDetail_id,
  720. stg_id: stage_id,
  721. stg_order: stage_order,
  722. cur_order: sorder,
  723. stg_times: stage_times,
  724. stg_status: stage_status,
  725. stage_list: JSON.stringify(stageList),
  726. prj_account_list: JSON.stringify(prjAccList),
  727. role_list: JSON.stringify(roleList),
  728. used_list: JSON.stringify(usedList),
  729. tenderMenu,
  730. preUrl: '/tender/' + tenderId + '/measure/stage/' + ctx.params.order,
  731. measureType,
  732. categoryData,
  733. tenderList,
  734. auditConst: auditConst.stage,
  735. ledgerAuditConst: auditConst.ledger,
  736. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.report.main),
  737. customSelects,
  738. rptCustomType: reportConst.rptCustomType,
  739. materialList,
  740. stages: stageList,
  741. dataSelects,
  742. pageShow,
  743. authMobile: accountInfo.auth_mobile,
  744. shenpiConst,
  745. archiveList,
  746. lastAuditor,
  747. rpt_id: ctx.query.rpt_id,
  748. isAdmin,
  749. prePay: JSON.stringify(advance),
  750. OSS_PATH: ctx.app.config.fujianOssPath,
  751. viewPmData: PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission),
  752. source_type,
  753. bglObj: JSON.stringify(bglObj),
  754. changes: JSON.stringify(changes),
  755. bizId: bglObj.BUSINESS_ID,
  756. };
  757. await this.layout('report/index.ejs', renderData, 'report/rpt_all_popup.ejs');
  758. } catch (err) {
  759. this.log(err);
  760. }
  761. }
  762. async indexForChange(ctx) {
  763. // 变更令报表入口
  764. await this._indexForBGL(ctx, sourceTypeConst.sourceType.change, -300);
  765. }
  766. async indexForChangePlan(ctx) {
  767. // 变更方案报表入口
  768. await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_plan, -301);
  769. }
  770. async indexForChangeProject(ctx) {
  771. // 变更立项报表入口
  772. await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_project, -302);
  773. }
  774. async indexForChangeApply(ctx) {
  775. // 变更申请报表入口
  776. await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_apply, -303);
  777. }
  778. /**
  779. * 报表打印页面
  780. *
  781. * @param {Object} ctx - egg全局context
  782. * @return {void}
  783. */
  784. async showPrintPage(ctx) {
  785. try {
  786. // const params = JSON.parse(ctx.request.body.params);
  787. const pageSize = ctx.params.size;
  788. // console.log('pageSize: ' + pageSize);
  789. const renderData = {
  790. size: pageSize,
  791. // orientation: params.orientation,
  792. };
  793. await ctx.render('report/rpt_print.ejs', renderData);
  794. } catch (err) {
  795. this.log(err);
  796. console.log(err);
  797. }
  798. }
  799. async showIndividualPage(ctx) {
  800. try {
  801. // const params = JSON.parse(ctx.request.body.params);
  802. const pageSize = ctx.params.size;
  803. // console.log('pageSize: ' + pageSize);
  804. const renderData = {
  805. size: pageSize,
  806. OSS_PATH: ctx.app.config.fujianOssPath,
  807. // orientation: params.orientation,
  808. };
  809. await ctx.render('report/rpt_individual.ejs', renderData);
  810. } catch (err) {
  811. this.log(err);
  812. console.log(err);
  813. }
  814. }
  815. _mergeBlankRoleSignDate(roleRel, auditors) {
  816. // 有些签名信息的sign_date是空白的(从前一业务copy过来并清理),需要根据审核信息来自动填写上审核时间
  817. // 1. 用户ID 2. sign_date为空白
  818. if (roleRel && auditors) {
  819. roleRel.forEach(record => {
  820. const contents = JSON.parse(record.rel_content);
  821. let hasMerge = false;
  822. contents.forEach(role => {
  823. if (!role.sign_date || role.sign_date === '') {
  824. auditors.forEach(audit => {
  825. if (audit.aid === role.acc_id) {
  826. role.sign_date = audit.end_time;
  827. hasMerge = true;
  828. }
  829. });
  830. }
  831. });
  832. if (hasMerge) {
  833. record.rel_content = JSON.stringify(contents);
  834. }
  835. });
  836. }
  837. }
  838. async _commonGetAudit(ctx, params, stgAudit) {
  839. switch (params.stage_id) {
  840. case -300: // 变更令
  841. const changeAudit = await ctx.service.changeAudit.getAuditors(params.change_id, params.change_times, true);
  842. const change = await ctx.service.change.getChangeByCid(params.change_id);
  843. let orgChangeStatus = 3;
  844. if ([1, 9].includes(change.status)) orgChangeStatus = 1; // 原报只要已上报(非1、9),status都是3
  845. stgAudit.push({ aid: change.uid, status: orgChangeStatus, opinion: '', end_time: change.in_time, order: 0 }); // 加上原报
  846. changeAudit.forEach(audit => {
  847. stgAudit.push({ aid: audit.uid, status: audit.status, opinion: audit.sdesc, end_time: audit.sin_time, order: audit.usite });
  848. });
  849. break;
  850. case -301: // 变更方案
  851. const changePlanAudit = await ctx.service.changePlanAudit.getAuditors(params.business_id, params.change_plan_times, true);
  852. const change_plan = await ctx.service.changePlan.getDataById(params.business_id);
  853. let orgChangePlanStatus = 3;
  854. if ([1, 9].includes(change_plan.status)) orgChangePlanStatus = 1; // 原报只要已上报(非1、9),status都是3
  855. stgAudit.push({ aid: change_plan.uid, status: orgChangePlanStatus, opinion: '', end_time: change_plan.in_time, order: 0 }); // 加上原报
  856. changePlanAudit.forEach(audit => {
  857. stgAudit.push({ aid: audit.aid, status: audit.status, opinion: audit.opinion, end_time: audit.end_time, times: audit.times, order: audit.order });
  858. });
  859. break;
  860. case -302: // 变更立项
  861. const changeProjectAudit = await ctx.service.changeProjectAudit.getAuditors(params.business_id, params.change_project_times, true);
  862. const change_project = await ctx.service.changeProject.getDataById(params.business_id);
  863. let orgChangePrjStatus = 3;
  864. if ([1, 9].includes(change_project.status)) orgChangePrjStatus = 1; // 原报只要已上报(非1、9),status都是3
  865. stgAudit.push({ aid: change_project.uid, status: orgChangePrjStatus, opinion: '', end_time: change_project.in_time, order: 0 }); // 加上原报
  866. changeProjectAudit.forEach(audit => {
  867. stgAudit.push({ aid: audit.aid, status: audit.status, opinion: audit.opinion, end_time: audit.end_time, times: audit.times, order: audit.order });
  868. });
  869. break;
  870. case -303: // 变更申请
  871. const changeApplyAudit = await ctx.service.changeApplyAudit.getAuditors(params.business_id, params.change_apply_times, true);
  872. const change_apply = await ctx.service.changeApply.getDataById(params.business_id);
  873. let orgChangeApplyStatus = 3;
  874. if ([1, 9].includes(change_apply.status)) orgChangeApplyStatus = 1; // 原报只要已上报(非1、9),status都是3
  875. stgAudit.push({ aid: change_apply.uid, status: orgChangeApplyStatus, opinion: '', end_time: change_apply.in_time, order: 0 }); // 加上原报
  876. changeApplyAudit.forEach(audit => {
  877. stgAudit.push({ aid: audit.aid, status: audit.status, opinion: audit.opinion, end_time: audit.end_time, times: audit.times, order: audit.order });
  878. });
  879. break;
  880. default:
  881. break;
  882. }
  883. }
  884. async _getReport(ctx, params) {
  885. // console.log('in getReport');
  886. // console.log(params);
  887. let rptTpl = await ctx.service.rptTpl.getTplById(params.rpt_tpl_id);
  888. if (!rptTpl || rptTpl.length !== 1) {
  889. throw '获取模板失败';
  890. }
  891. const source_type = params.source_type ? params.source_type : rptTpl[0].source_type;
  892. rptTpl = JSON.parse(rptTpl[0].rpt_content);
  893. rptTpl.source_type = source_type || sourceTypeConst.defaultSourceType;
  894. rptTpl.id = params.rpt_tpl_id;
  895. // console.log('get the template!');
  896. const customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
  897. ? await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id)
  898. : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, params.rpt_tpl_id);
  899. let copyCustomSelect = this.ctx.helper.clone(customSelect);
  900. if (!params.gather_select && copyCustomSelect) delete copyCustomSelect.gather_select;
  901. if (!params.stage_select && copyCustomSelect) delete copyCustomSelect.stage_select;
  902. if (!params.material_sum_select && copyCustomSelect) delete copyCustomSelect.material_sum_select;
  903. if (params.change_select) {
  904. copyCustomSelect = { tid: params.tender_id, rid: params.rpt_tpl_id, sid: -1, change_select: params.change_select };
  905. }
  906. const pageRst = await ctx.service.jpcReport.getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir, copyCustomSelect);
  907. for (const page of pageRst.items) {
  908. page[JV.PROP_WATERMARK_CELLS] = [];
  909. }
  910. let waterMarkStr = null;
  911. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  912. // 加水印
  913. fillWaterMark([pageRst]);
  914. if (params.needWaterMark) {
  915. waterMarkStr = await getWatermarkPicData(pageRst, this.app.baseDir);
  916. }
  917. }
  918. // console.log(pageRst);
  919. const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_tpl_id, params.stage_id, params.business_id); // 新需求中,允许在非审核状态下设置签名
  920. let stgAudit = null,
  921. stgAuditForOrg = null,
  922. stageFlow = null,
  923. stageList = [];
  924. if (params.stage_id > 0) {
  925. stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
  926. stgAuditForOrg = await ctx.service.stageAudit.getStageAudit(params.stage_id, 1);
  927. stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
  928. stageFlow = await ctx.service.stageAudit.getAuditGroupByListWithOwner(params.stage_id, params.stage_times);
  929. } else if ([-100, -200].includes(params.stage_id)) {
  930. stgAudit = await ctx.service.paymentDetailAudit.getAuditors(params.detail_id, params.stage_times);
  931. stgAuditForOrg = await ctx.service.paymentDetailAudit.getAuditors(params.detail_id, 1);
  932. stageFlow = await ctx.service.paymentDetailAudit.getAuditorsWithOwner(params.detail_id);
  933. const paymentDetailList = await ctx.service.paymentDetail.getDetail(params.detail_id);
  934. if (paymentDetailList && paymentDetailList.length > 0) {
  935. const payment = paymentDetailList[0];
  936. stageList.push({ id: params.stage_id, user_id: payment.uid, status: payment.status });
  937. }
  938. } else if ([-300, -301, -302, -303].includes(params.stage_id)) {
  939. // 变更令相关的
  940. stgAudit = [];
  941. stgAuditForOrg = [];
  942. stageFlow = [];
  943. await this._commonGetAudit(ctx, params, stgAudit);
  944. stgAudit.sort(function(stg1, stg2) {
  945. return stg1.order - stg2.order;
  946. });
  947. this._mergeBlankRoleSignDate(roleRel, stgAudit);
  948. }
  949. stageFlow.forEach(x => {
  950. if (!x) return;
  951. x.visible = (!ctx.session.sessionUser.is_admin && ctx.session.sessionProject.page_show.individualSign === 1)
  952. ? x.aid === ctx.session.sessionUser.accountId : true;
  953. });
  954. mergeStampSignature(ctx, params.stage_status, pageRst, roleRel[0], null, stgAudit, stageList);
  955. mergeTextSignature(params.isTextSignature, params.stage_status, pageRst, roleRel[0], [], stgAudit, stageList);
  956. await encodeSignatureDataUri(roleRel, this.app.baseDir);
  957. if (params.getPicFlag) {
  958. await encodeDummySignatureDataUri(pageRst, this.app.baseDir); // 注意草图数据量问题!
  959. }
  960. // console.log('encodeSignatureDataUri!');
  961. // fsUtil.writeObjToFile(pageRst, 'D:/GitHome/Temp/testBuiltPageResult2.js');
  962. return {
  963. data: pageRst,
  964. signatureRelInfo: roleRel,
  965. stageAudit: stgAudit,
  966. stageAuditOrg: stgAuditForOrg,
  967. debugInfo: ctx.session.sessionUser.loginStatus ? ctx.debugInfo : null,
  968. customDefine: rptTpl[JV.NODE_CUSTOM_DEFINE],
  969. stageFlow,
  970. customSelect,
  971. waterMarkStr,
  972. };
  973. }
  974. /**
  975. * 获取报表数据
  976. *
  977. * @param {Object} ctx - egg全局context
  978. * @return {void}
  979. */
  980. async getReport(ctx) {
  981. try {
  982. // console.log('in getReport');
  983. const params = JSON.parse(ctx.request.body.params);
  984. ctx.body = await this._getReport(ctx, params);
  985. ctx.status = 201;
  986. } catch (ex) {
  987. console.log(ex);
  988. this.setMessage(ex.toString(), this.messageType.ERROR);
  989. }
  990. }
  991. async getTestReport(ctx) {
  992. try {
  993. const file = 'D:/GitHome/Temp/导出PDF_格式样本1.js';
  994. const tplObj = JSON.parse(fs.readFileSync(file, 'utf-8'));
  995. ctx.body = { data: tplObj };
  996. ctx.status = 201;
  997. } catch (ex) {
  998. this.setMessage(ex.toString(), this.messageType.ERROR);
  999. }
  1000. }
  1001. /**
  1002. * 获取多批次报表数据
  1003. *
  1004. * @param {Object} ctx - egg全局context
  1005. * @return {void}
  1006. */
  1007. async getMultiReportsEx(ctx) {
  1008. // 原则说明:把所有报表模板集中获取,统一filter,只读一次数据!
  1009. const params = JSON.parse(ctx.request.body.params);
  1010. const pageShow = ctx.session.sessionProject.page_show;
  1011. if (pageShow !== null
  1012. && pageShow !== undefined
  1013. && params.outputType
  1014. && ((params.outputType === 'PDF' && parseInt(pageShow.closeExportPdf) === 1)
  1015. || (params.outputType === 'Excel' && parseInt(pageShow.closeExportExcel) === 1)
  1016. )
  1017. ) {
  1018. ctx.body = { data: [], signatureRelInfo: [], stageAudit: [] };
  1019. ctx.status = 201;
  1020. return;
  1021. }
  1022. if (params.stage_id > 0) {
  1023. await this._saveCustomSelects(params);
  1024. }
  1025. // const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir) || [];
  1026. const pageRstArr = await ctx.service.jpcReport.getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir) || [];
  1027. for (const pageRst of pageRstArr) {
  1028. for (const page of pageRst.items) {
  1029. page[JV.PROP_WATERMARK_CELLS] = [];
  1030. }
  1031. }
  1032. let waterMarkStr = null;
  1033. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  1034. // 加水印
  1035. fillWaterMark(pageRstArr);
  1036. if (params.needWaterMark) {
  1037. waterMarkStr = await getWatermarkPicData(pageRstArr[0], this.app.baseDir);
  1038. }
  1039. }
  1040. const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id, params.business_id); // 新需求:在审批流程中的签名需要显示
  1041. roleRel.sort(function(rr1, rr2) {
  1042. return params.rpt_ids.indexOf(parseInt(rr1.rpt_id)) - params.rpt_ids.indexOf(parseInt(rr2.rpt_id));
  1043. });
  1044. let stgAudit = null,
  1045. stageList = [];
  1046. if (params.stage_id > 0) {
  1047. stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
  1048. stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
  1049. } else if ([-100, -200].includes(params.stage_id)) {
  1050. stgAudit = await ctx.service.paymentDetailAudit.getAuditors(params.detail_id);
  1051. const paymentDetailList = await ctx.service.paymentDetail.getDetail(params.detail_id);
  1052. if (paymentDetailList && paymentDetailList.length > 0) {
  1053. const payment = paymentDetailList[0];
  1054. stageList.push({ id: params.stage_id, user_id: payment.uid, status: payment.status });
  1055. }
  1056. } else if ([-300, -301, -302, -303].includes(params.stage_id)) {
  1057. stgAudit = [];
  1058. await this._commonGetAudit(ctx, params, stgAudit);
  1059. this._mergeBlankRoleSignDate(roleRel, stgAudit);
  1060. }
  1061. mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRel, params.rpt_ids, stgAudit, stageList);
  1062. mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRel, params.rpt_ids, stgAudit, stageList, !!params.closeArchiveSignature, !!params.isArchive);
  1063. await encodeSignatureDataUri(roleRel, this.app.baseDir);
  1064. if (params.getPicFlag) {
  1065. for (const pageRst of pageRstArr) {
  1066. await encodeDummySignatureDataUri(pageRst, this.app.baseDir); // 注意草图数据量问题!
  1067. }
  1068. }
  1069. // console.log(pageRstArr);
  1070. ctx.body = { data: pageRstArr, signatureRelInfo: roleRel, stageAudit: stgAudit, waterMarkStr };
  1071. ctx.status = 201;
  1072. }
  1073. async _saveCustomSelects(params) {
  1074. for (const [i, cs] of params.customSelect.entries()) {
  1075. if (!cs) continue;
  1076. cs.tender_id = params.tender_id;
  1077. cs.stage_id = params.stage_id;
  1078. cs.rpt_tpl_id = params.rpt_ids[i];
  1079. await this.ctx.service.rptCustomDefine.saveCustomSelect(cs);
  1080. }
  1081. }
  1082. async createExcelFilesEx(ctx) {
  1083. const params = JSON.parse(ctx.request.body.params);
  1084. const pageShow = ctx.session.sessionProject.page_show;
  1085. if (pageShow !== null && pageShow !== undefined && parseInt(pageShow.closeExportExcel) === 1) {
  1086. ctx.body = { data: [] };
  1087. ctx.status = 201;
  1088. return;
  1089. }
  1090. await this._saveCustomSelects(params);
  1091. const baseDir = this.app.baseDir;
  1092. function getExcelByPageData(pageRst, rpt_name, innerRoleRel) {
  1093. return new Promise(function(resolve, reject) {
  1094. rpt_xl_util.exportExcel(pageRst, params.pageSize, rpt_name, params.isOneSheet, null, null, baseDir, innerRoleRel,
  1095. (err, uuidName) => {
  1096. if (err) return reject(err);
  1097. const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
  1098. resolve(fileRst);
  1099. }
  1100. );
  1101. });
  1102. }
  1103. // const stgAudit = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times)) : [];
  1104. const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
  1105. const stgAuditForOrg = (params.stage_status === 3) ? (await ctx.service.stageAudit.getStageAudit(params.stage_id, 1)) : [];
  1106. // const stageList = (params.stage_status === 3) ? (await ctx.service.stage.getValidStagesShort(params.tender_id)) : [];
  1107. const stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
  1108. const roleRelArr = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id, params.business_id)) : [];
  1109. const pageRstArr = await ctx.service.jpcReport.getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, baseDir);
  1110. // console.log('params.stage_status: ' + params.stage_status);
  1111. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/testBuiltPageResult1.js');
  1112. for (const pageRst of pageRstArr) {
  1113. for (const page of pageRst.items) {
  1114. page[JV.PROP_WATERMARK_CELLS] = [];
  1115. }
  1116. }
  1117. let waterMarkStr = null;
  1118. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  1119. // if (params.stage_status !== 3 && params.closeWatermark === 0 && params.option === JV.PAGING_OPTION_NORMAL) {
  1120. // 加水印(注意:还得看用户设置是否需要加水印)
  1121. fillWaterMark(pageRstArr);
  1122. if (params.needWaterMark) {
  1123. waterMarkStr = await getWatermarkPicData(pageRstArr[0], baseDir);
  1124. }
  1125. }
  1126. mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
  1127. mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
  1128. await this.ctx.helper.recursiveMkdirSync(baseDir + '/app/public/download');
  1129. const runnableRst = [];
  1130. // 1. merge签名相关信息
  1131. const pageBrkSize = 62914560; // 60M, 1024*1024*6*10
  1132. for (let idx = 0; idx < pageRstArr.length; idx++) {
  1133. let roleRel = null;
  1134. for (const roleR of roleRelArr) {
  1135. if (roleR.rpt_id === params.rpt_ids[idx]) {
  1136. roleRel = JSON.parse(roleR.rel_content);
  1137. break;
  1138. }
  1139. }
  1140. if (params.stage_status === 3) {
  1141. mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
  1142. mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
  1143. }
  1144. // 2. 判断草图大小是否需要分页
  1145. const picSize = await _chkRawPicSize(pageRstArr[idx], baseDir);
  1146. // const picSize = 262914560; // 测试用,强制分页
  1147. if (picSize > pageBrkSize) {
  1148. // let pageBrkAmt = Math.ceil(picSize / pageBrkSize);
  1149. let pageBrkAmt = Math.floor(pageRstArr[idx].items.length / Math.ceil(picSize / pageBrkSize));
  1150. if (pageBrkAmt < 10) {
  1151. // 不用管
  1152. } else if (pageBrkAmt < 100) {
  1153. pageBrkAmt = Math.floor(pageBrkAmt / 10) * 10;
  1154. } else if (pageBrkAmt < 1000) {
  1155. pageBrkAmt = Math.floor(pageBrkAmt / 100) * 100;
  1156. } else {
  1157. // 暂时不管
  1158. }
  1159. const newRptNames = []; // 这个为导出控制分页用
  1160. const newPageDataRst = _resetPageDataByBreaks([pageRstArr[idx]], pageBrkAmt, [params.rpt_names[idx]], newRptNames);
  1161. for (let dtlIdx = 0; dtlIdx < newPageDataRst.length; dtlIdx++) {
  1162. runnableRst.push(getExcelByPageData(newPageDataRst[dtlIdx], newRptNames[dtlIdx], roleRel));
  1163. }
  1164. } else {
  1165. runnableRst.push(getExcelByPageData(pageRstArr[idx], params.rpt_names[idx], roleRel));
  1166. }
  1167. }
  1168. // */
  1169. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/计量导出pageArr.js');
  1170. const uuidRst = await Promise.all(runnableRst);
  1171. ctx.body = { data: uuidRst, waterMarkStr };
  1172. ctx.status = 201;
  1173. }
  1174. _getExcelByPageData(pageRst, rpt_name, pageSize, baseDir, innerRoleRel) {
  1175. return new Promise(function(resolve, reject) {
  1176. rpt_xl_util.exportExcel(pageRst, pageSize, rpt_name, true, null, null, baseDir, innerRoleRel,
  1177. (err, uuidName) => {
  1178. if (err) return reject(err);
  1179. const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
  1180. resolve(fileRst);
  1181. }
  1182. );
  1183. });
  1184. }
  1185. async createExcelFilesFromDirectData(ctx) {
  1186. const params = JSON.parse(ctx.request.body.params);
  1187. const names = params.rptNames;
  1188. const pageDataArr = params.pageData;
  1189. const runnableRst = [];
  1190. for (let idx = 0; idx < names.length; idx++) {
  1191. runnableRst.push(this._getExcelByPageData(pageDataArr[idx], names[idx], 'A4', this.app.baseDir, null));
  1192. }
  1193. const uuidRst = await Promise.all(runnableRst);
  1194. ctx.body = { data: uuidRst, waterMarkStr: null };
  1195. ctx.status = 201;
  1196. }
  1197. async createExcelFilesFromLocal(ctx) {
  1198. const baseDir = this.app.baseDir;
  1199. function getExcelByPageData(pageRst, rpt_name, innerRoleRel) {
  1200. return new Promise(function(resolve, reject) {
  1201. rpt_xl_util.exportExcel(pageRst, 'A4', rpt_name, true, null, null, baseDir, innerRoleRel,
  1202. (err, uuidName) => {
  1203. if (err) return reject(err);
  1204. const fileRst = { uuid: uuidName, reportName: rpt_name.replace(new RegExp('%', 'gm'), '_') };
  1205. resolve(fileRst);
  1206. }
  1207. );
  1208. });
  1209. }
  1210. try {
  1211. console.log('start:');
  1212. const pageRst = JSON.parse(fs.readFileSync('D:/GitHome/temp/计量excel原始数据_A3BZ6_5384_112表(清单).js', 'utf-8'));
  1213. console.log('read it');
  1214. const runnableRst = [];
  1215. const pageBrkSize = 6291456; // 6M, 1024*1024*6
  1216. // const pageBrkSize = 1048576; // 1M, 1024*1024*1
  1217. console.log('pageBrkSize:' + pageBrkSize);
  1218. const picSize = await _chkRawPicSize(pageRst, baseDir);
  1219. console.log('picSize:' + picSize);
  1220. if (picSize > pageBrkSize) {
  1221. let pageBrkAmt = Math.floor(pageRst.items.length / Math.ceil(picSize / pageBrkSize));
  1222. console.log('pageBrkAmt:' + pageBrkAmt);
  1223. if (pageBrkAmt < 10) {
  1224. // 不用管
  1225. } else if (pageBrkAmt < 100) {
  1226. pageBrkAmt = Math.floor(pageBrkAmt / 10) * 10;
  1227. } else if (pageBrkAmt < 1000) {
  1228. pageBrkAmt = Math.floor(pageBrkAmt / 100) * 100;
  1229. } else {
  1230. // 暂时不管
  1231. }
  1232. const newRptNames = []; // 这个为导出控制分页用
  1233. const newPageDataRst = _resetPageDataByBreaks([pageRst], pageBrkAmt, ['工程计量表(计量单元-清单)'], newRptNames);
  1234. for (let dtlIdx = 0; dtlIdx < newPageDataRst.length; dtlIdx++) {
  1235. runnableRst.push(getExcelByPageData(newPageDataRst[dtlIdx], newRptNames[dtlIdx], null));
  1236. }
  1237. } else {
  1238. runnableRst.push(getExcelByPageData(pageRst, '工程计量表(计量单元-清单)', null));
  1239. }
  1240. const uuidRst = await Promise.all(runnableRst);
  1241. ctx.body = { data: uuidRst, waterMarkStr: null };
  1242. ctx.status = 201;
  1243. } catch (ex) {
  1244. console.log(ex.toString());
  1245. ctx.status = 500;
  1246. }
  1247. }
  1248. async createExcelFilesInOneBookEx(ctx) {
  1249. const params = JSON.parse(ctx.request.body.params);
  1250. const baseDir = this.app.baseDir;
  1251. function getExcelByPageData(pageRstArr, rpt_name, innerRoleRel) {
  1252. return new Promise(function(resolve, reject) {
  1253. rpt_xl_util.exportExcelInOneBook(pageRstArr, params.pageSize, rpt_name, baseDir, innerRoleRel,
  1254. (err, uuidName) => {
  1255. if (err) return reject(err);
  1256. const fileRst = { uuid: uuidName, reportName: rpt_name };
  1257. resolve(fileRst);
  1258. }
  1259. );
  1260. });
  1261. }
  1262. const roleRelArr = (params.stage_status === 3) ? (await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_ids, params.stage_id)) : [];
  1263. // console.log(`baseDir: ${baseDir}`);
  1264. // fsUtil.writeObjToFile(roleRelArr, 'D:/GitHome/temp/签名信息.js');
  1265. const stgAudit = await ctx.service.stageAudit.getStageAudit(params.stage_id, params.stage_times);
  1266. const stgAuditForOrg = await ctx.service.stageAudit.getStageAudit(params.stage_id, 1);
  1267. const stageList = await ctx.service.stage.getValidStagesShort(params.tender_id);
  1268. // const pageRstArr = await getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
  1269. const pageRstArr = await ctx.service.jpcReport.getMultiRptsCommon(ctx, params, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir);
  1270. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/pageRstArrForExcel.js');
  1271. for (const pageRst of pageRstArr) {
  1272. for (const page of pageRst.items) {
  1273. page[JV.PROP_WATERMARK_CELLS] = [];
  1274. }
  1275. }
  1276. let waterMarkStr = null;
  1277. if (params.stage_status !== 3 && params.closeWatermark === 0) {
  1278. // if (params.stage_status !== 3 && params.closeWatermark === 0 && params.option === JV.PAGING_OPTION_NORMAL) {
  1279. // 加水印
  1280. fillWaterMark(pageRstArr);
  1281. if (params.needWaterMark) {
  1282. waterMarkStr = await getWatermarkPicData(pageRstArr[0], this.app.baseDir);
  1283. }
  1284. }
  1285. mergeStampSignature(ctx, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
  1286. mergeTextSignature(params.isTextSignature, params.stage_status, pageRstArr, roleRelArr, params.rpt_ids, stgAudit, stageList);
  1287. await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
  1288. const runnableRst = [];
  1289. let rptRoleRelArr = [];
  1290. const reAssignSignatureName = function(pageData, roleRel, rpt_name_key) {
  1291. const keyMap = {};
  1292. for (const pageItem of pageData.items) {
  1293. for (const signCell of pageItem[JV.PROP_SIGNATURE_CELLS]) {
  1294. if (!keyMap.hasOwnProperty(signCell.signature_name)) {
  1295. keyMap[signCell.signature_name] = rpt_name_key + '_' + signCell.signature_name;
  1296. }
  1297. }
  1298. }
  1299. for (const pageItem of pageData.items) {
  1300. for (const signCell of pageItem[JV.PROP_SIGNATURE_CELLS]) {
  1301. if (keyMap.hasOwnProperty(signCell.signature_name)) {
  1302. signCell.signature_name = keyMap[signCell.signature_name];
  1303. }
  1304. }
  1305. }
  1306. for (const roleSign of roleRel) {
  1307. if (keyMap.hasOwnProperty(roleSign.signature_name)) {
  1308. roleSign.signature_name = keyMap[roleSign.signature_name];
  1309. }
  1310. }
  1311. // console.log('keyMap of : ' + rpt_name_key);
  1312. // console.log(keyMap);
  1313. };
  1314. for (let idx = 0; idx < pageRstArr.length; idx++) {
  1315. let roleRel = null;
  1316. for (const roleR of roleRelArr) {
  1317. if (roleR.rpt_id === params.rpt_ids[idx]) {
  1318. roleRel = JSON.parse(roleR.rel_content);
  1319. if (params.stage_status === 3) {
  1320. mergeSignAudit(pageRstArr[idx], roleRel, stgAudit);
  1321. mergeSignDate(pageRstArr[idx], params.stage_id, roleRel, stgAudit, stgAuditForOrg, stageList);
  1322. }
  1323. // 这里要做些电子签名的signature_name转换,以防重名
  1324. reAssignSignatureName(pageRstArr[idx], roleRel, params.rpt_names[idx]);
  1325. rptRoleRelArr = rptRoleRelArr.concat(roleRel);
  1326. break;
  1327. }
  1328. }
  1329. }
  1330. // fsUtil.writeObjToFile(pageRstArr, 'D:/GitHome/temp/pageRstArrForExcelAfterReAssign.js');
  1331. // fsUtil.writeObjToFile(rptRoleRelArr, 'D:/GitHome/temp/签名信息_新.js');
  1332. runnableRst.push(getExcelByPageData(pageRstArr, params.rptName, rptRoleRelArr));
  1333. const uuidRst = await Promise.all(runnableRst);
  1334. ctx.body = { data: uuidRst, waterMarkStr };
  1335. ctx.status = 201;
  1336. }
  1337. async getFileByUUID(ctx) {
  1338. // console.log('downloading : ' + ctx.params.uuid);
  1339. const uuid = ctx.params.uuid;
  1340. const rptName = ctx.params.rptName;
  1341. const suffix = '.' + ctx.params.suffix;
  1342. try {
  1343. const rptNameURI = encodeURI(rptName);
  1344. const filePath = this.app.baseDir + '/app/public/download/';
  1345. // console.log('filePath: ' + filePath);
  1346. // await this.ctx.helper.recursiveMkdirSync(this.app.baseDir + '/app/public/download');
  1347. ctx.set({
  1348. 'Content-Type': 'application/vnd.openxmlformats',
  1349. 'Content-Disposition': 'attachment; filename="' + rptNameURI + suffix + "\"; filename*=utf-8''" + rptNameURI + suffix,
  1350. });
  1351. ctx.body = await fs.readFileSync(filePath + uuid + suffix);
  1352. } catch (e) {
  1353. console.log(e);
  1354. }
  1355. }
  1356. /**
  1357. * 更新用户通用报表显示配置
  1358. *
  1359. * @param {Object} ctx - egg全局context
  1360. * @return {void}
  1361. */
  1362. async updateCustNode(ctx) {
  1363. const params = JSON.parse(ctx.request.body.params);
  1364. // console.log(params);
  1365. const custId = this.ctx.session.sessionUser.accountId;
  1366. const newNodeItems = params.nodeItems;
  1367. const custSelectKeys = params.custSelectKeys;
  1368. const rst = await ctx.service.rptTreeNodeCust.updateCustNode(custId, newNodeItems, custSelectKeys);
  1369. // console.log(rst);
  1370. ctx.body = { data: rst };
  1371. // ctx.body = { data: { msg: 'test the network' } };
  1372. ctx.status = 201;
  1373. }
  1374. async setCustomDefine(ctx) {
  1375. try {
  1376. const data = JSON.parse(ctx.request.body.data);
  1377. await this.ctx.service.rptCustomDefine.saveCustomSelect(data);
  1378. const result = await this._getReport(ctx, data);
  1379. ctx.body = { err: 0, msg: '', data: result };
  1380. } catch (err) {
  1381. ctx.helper.log(err);
  1382. ctx.body = this.ajaxErrorBody(err, '保存数据出错');
  1383. }
  1384. }
  1385. }
  1386. return ReportController;
  1387. };
  1388. function isFileExisted(file) {
  1389. return new Promise(function(resolve, reject) {
  1390. fs.access(file, err => {
  1391. if (err) {
  1392. reject(false);
  1393. } else {
  1394. resolve(true);
  1395. }
  1396. });
  1397. });
  1398. }
  1399. function fillWaterMark(pageRstArray) {
  1400. const orgWaterMarkWidth = 600;
  1401. const orgWaterMarkHeight = 288;
  1402. const createWaterCell = function(area) {
  1403. const w = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT];
  1404. const h = area[JV.PROP_BOTTOM] - area[JV.PROP_TOP];
  1405. const left = Math.round(area[JV.PROP_LEFT] + w / 2 - orgWaterMarkWidth / 2);
  1406. const right = left + orgWaterMarkWidth;
  1407. const top = Math.round(area[JV.PROP_TOP] + h / 2 - orgWaterMarkHeight / 2);
  1408. const bottom = top + orgWaterMarkHeight;
  1409. return {
  1410. signature_name: JV.SIGNATURE_NAME_DUMMY_WATER_MARK,
  1411. path: '/public/images/not_Approve.png',
  1412. sign_path: '/public/images/not_Approve.png',
  1413. pic: null,
  1414. control: 'Title',
  1415. style: 'Default_None',
  1416. area: {
  1417. Left: left,
  1418. Right: right,
  1419. Top: top,
  1420. Bottom: bottom,
  1421. },
  1422. };
  1423. };
  1424. for (const pageRst of pageRstArray) {
  1425. for (const page of pageRst.items) {
  1426. page[JV.PROP_WATERMARK_CELLS] = [];
  1427. if (page[JV.PROP_PAGE_MERGE_BORDER]) {
  1428. const wmCell = createWaterCell(page[JV.PROP_PAGE_MERGE_BORDER]);
  1429. page[JV.PROP_WATERMARK_CELLS].push(wmCell);
  1430. } else if (page[JV.PAGE_SPECIAL_MERGE_POS]) {
  1431. if (page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT]) {
  1432. for (let i = 0; i < page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT].length; i++) {
  1433. const area = {};
  1434. area[JV.PROP_LEFT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_LEFT][i];
  1435. area[JV.PROP_RIGHT] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_RIGHT][i];
  1436. area[JV.PROP_TOP] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_TOP][i];
  1437. area[JV.PROP_BOTTOM] = page[JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_BOTTOM][i];
  1438. const wmCell = createWaterCell(area);
  1439. page[JV.PROP_WATERMARK_CELLS].push(wmCell);
  1440. }
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. async function encodeSignatureDataUri(roleRel, baseDir) {
  1447. if (roleRel) {
  1448. for (const singleRoleRel of roleRel) {
  1449. if (singleRoleRel.rel_content !== null && singleRoleRel.rel_content !== undefined && singleRoleRel.rel_content !== '') {
  1450. const roleRelContent = JSON.parse(singleRoleRel.rel_content);
  1451. for (const role of roleRelContent) {
  1452. // console.log(role);
  1453. if (role.sign_path !== '') {
  1454. const filePath = baseDir + '/app' + role.sign_path;
  1455. try {
  1456. const res = await isFileExisted(filePath);
  1457. if (res) {
  1458. const bData = fs.readFileSync(filePath);
  1459. const base64Str = bData.toString('base64');
  1460. const datauri = 'data:image/png;base64,' + base64Str;
  1461. role.sign_pic = datauri;
  1462. } else {
  1463. console.log('文件不存在:' + filePath);
  1464. }
  1465. } catch (err) {
  1466. console.error(err);
  1467. }
  1468. }
  1469. }
  1470. singleRoleRel.rel_content = JSON.stringify(roleRelContent);
  1471. } else {
  1472. singleRoleRel.rel_content = [];
  1473. }
  1474. }
  1475. }
  1476. }
  1477. async function encodeDummySignatureDataUri(pageRst, baseDir) {
  1478. if (pageRst) {
  1479. for (const page of pageRst.items) {
  1480. for (const signature of page[JV.PROP_SIGNATURE_CELLS]) {
  1481. if (signature.signature_name === JV.SIGNATURE_NAME_DUMMY) {
  1482. if (signature.path !== '') {
  1483. const filePath = baseDir + '/app' + signature.path;
  1484. try {
  1485. const res = await isFileExisted(filePath);
  1486. if (res) {
  1487. const bData = fs.readFileSync(filePath);
  1488. const base64Str = bData.toString('base64');
  1489. const datauri = 'data:image/png;base64,' + base64Str;
  1490. signature.pic = datauri;
  1491. signature.path = '';
  1492. } else {
  1493. console.log('文件不存在:' + filePath);
  1494. }
  1495. } catch (err) {
  1496. console.error(err);
  1497. }
  1498. }
  1499. }
  1500. }
  1501. // 考虑优化,水印只需要一张即可,不需要每页都设置
  1502. // for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
  1503. // if (signature.path !== '') {
  1504. // const filePath = baseDir + '/app' + signature.path;
  1505. // try {
  1506. // const res = await isFileExisted(filePath);
  1507. // if (res) {
  1508. // const bData = fs.readFileSync(filePath);
  1509. // const base64Str = bData.toString('base64');
  1510. // const datauri = 'data:image/png;base64,' + base64Str;
  1511. // signature.pic = datauri;
  1512. // signature.path = '';
  1513. // } else {
  1514. // console.log('文件不存在:' + filePath);
  1515. // }
  1516. // } catch (err) {
  1517. // console.error(err);
  1518. // }
  1519. // }
  1520. // }
  1521. }
  1522. }
  1523. }
  1524. async function getWatermarkPicData(pageRst, baseDir) {
  1525. let rst = '';
  1526. if (pageRst) {
  1527. for (const page of pageRst.items) {
  1528. for (const signature of page[JV.PROP_WATERMARK_CELLS]) {
  1529. if (signature.path !== '') {
  1530. const filePath = baseDir + '/app' + signature.path;
  1531. try {
  1532. const res = await isFileExisted(filePath);
  1533. if (res) {
  1534. const bData = fs.readFileSync(filePath);
  1535. const base64Str = bData.toString('base64');
  1536. rst = 'data:image/png;base64,' + base64Str;
  1537. break;
  1538. } else {
  1539. console.log('文件不存在:' + filePath);
  1540. }
  1541. } catch (err) {
  1542. console.error(err);
  1543. }
  1544. }
  1545. if (rst !== null) break;
  1546. }
  1547. }
  1548. }
  1549. return rst;
  1550. }
  1551. function mergeTextSignature(isTxtSignature, status, pageData, singleRoleRel, rpt_ids, stgAudit, stageList, closeArchiveSignature = false, isArchive = false) {
  1552. // 依据需求,有些用户不需要签名图片,那么从源头上把签名从signature_cells转移到cells下,省得后续 预览、打印、导出PDF、导出EXCEL每个地方都改动
  1553. const _mergeSingle = function(_page, _roleRelList, isDeleteSignCell, checkAudit = false) {
  1554. // console.log(_roleRelList);
  1555. let roleRelContent = [];
  1556. if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
  1557. roleRelContent = JSON.parse(_roleRelList.rel_content);
  1558. }
  1559. for (const page of _page.items) {
  1560. if (page.signature_cells) {
  1561. const deleteSCellsIdx = [];
  1562. for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
  1563. const sCell = page.signature_cells[scIdx];
  1564. if (sCell.signature_name !== JV.SIGNATURE_NAME_DUMMY) {
  1565. sCell.Value = ''; // 这里要先清除原有信息
  1566. sCell.path = '';
  1567. sCell.pic = '';
  1568. let needTransferText = true;
  1569. for (const role_rel of roleRelContent) {
  1570. if (sCell.signature_name === role_rel.signature_name) {
  1571. if (!checkAudit || _chkIfAudit(role_rel, stgAudit, stageList)) {
  1572. sCell.Value = role_rel.user_name; // 只有审核通过了才需要文本签名内容
  1573. if (role_rel.sign_output && role_rel.sign_output.indexOf(NORMAL_SIGN_STR) < 0) {
  1574. // 用户选择不签名,则不迁移
  1575. needTransferText = false;
  1576. }
  1577. break;
  1578. }
  1579. }
  1580. }
  1581. if (needTransferText) {
  1582. const newCell = {
  1583. font: 'Footer',
  1584. control: sCell.control,
  1585. style: sCell.style,
  1586. Value: sCell.Value,
  1587. area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
  1588. };
  1589. if (isArchive && closeArchiveSignature) {
  1590. // 如果正在归档 且 归档不显示签名标记为true时,不输出文本签名,但要有这个空格子(边框用)
  1591. newCell.Value = '';
  1592. }
  1593. page.cells.push(newCell); // 迁移
  1594. deleteSCellsIdx.push(scIdx);
  1595. }
  1596. }
  1597. }
  1598. // 删除 page.signature_cells 签名(草图不能删);
  1599. // console.log('isDeleteSignCell: ' + isDeleteSignCell);
  1600. // console.log(deleteSCellsIdx);
  1601. if (isDeleteSignCell) {
  1602. for (let dIdx = deleteSCellsIdx.length - 1; dIdx >= 0; dIdx--) {
  1603. page.signature_cells.splice(deleteSCellsIdx[dIdx], 1);
  1604. }
  1605. }
  1606. }
  1607. }
  1608. };
  1609. if (isTxtSignature) {
  1610. if (pageData instanceof Array) {
  1611. pageData.forEach((dtlPage, index) => {
  1612. let dftRolRel = [];
  1613. const rpt_id = rpt_ids[index];
  1614. for (const roleRel of singleRoleRel) {
  1615. if (roleRel.rpt_id === rpt_id) {
  1616. dftRolRel = roleRel;
  1617. }
  1618. }
  1619. // _mergeSingle(dtlPage, dftRolRel, true, status !== 3);
  1620. _mergeSingle(dtlPage, dftRolRel, false, status !== 3); // 因加了个标记(归档不输出签名),前端做了大量的签名处理工作,导致现在不能删除,否则还会出现遗漏
  1621. });
  1622. } else {
  1623. _mergeSingle(pageData, singleRoleRel, false, status !== 3);
  1624. }
  1625. }
  1626. }
  1627. function _chkIfAudit(role_rel, STAGE_AUDIT, STAGE_LIST) {
  1628. let rst = false;
  1629. for (const stg_audit of STAGE_AUDIT) {
  1630. if (role_rel.acc_id === stg_audit.aid) {
  1631. if (stg_audit.status === 3) {
  1632. rst = true;
  1633. } else {
  1634. rst = false;
  1635. }
  1636. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  1637. }
  1638. }
  1639. if (!rst) {
  1640. // 还有原报需要检测
  1641. for (const stg_ort_rpt of STAGE_LIST) {
  1642. if (role_rel.acc_id === stg_ort_rpt.user_id) {
  1643. if (stg_ort_rpt.status !== 1 && stg_ort_rpt.status !== 4) {
  1644. // 只要不是待上报(1)、退回审批(4) 状态,都需要显示
  1645. rst = true;
  1646. } else {
  1647. rst = false;
  1648. }
  1649. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  1650. }
  1651. }
  1652. }
  1653. // rst = true; //测试,未来将屏蔽
  1654. return rst;
  1655. }
  1656. // 因机制问题,此方法必须在mergeTextSignature之前调用
  1657. async function mergeStampSignature(ctx, status, pageData, singleRoleRel, rpt_ids, stgAudit, stageList) {
  1658. const dupPicPaths = [];
  1659. const _getMaxRect = function(page) {
  1660. const rect = [100000000, 100000000, 0, 0];
  1661. for (const cell of page.cells) {
  1662. rect[0] = rect[0] > cell.area.Left ? cell.area.Left : rect[0];
  1663. rect[1] = rect[1] > cell.area.Top ? cell.area.Top : rect[1];
  1664. rect[2] = rect[2] < cell.area.Right ? cell.area.Right : rect[2];
  1665. rect[3] = rect[3] < cell.area.Bottom ? cell.area.Bottom : rect[3];
  1666. }
  1667. for (const sCell of page.signature_cells) {
  1668. rect[0] = rect[0] > sCell.area.Left ? sCell.area.Left : rect[0];
  1669. rect[1] = rect[1] > sCell.area.Top ? sCell.area.Top : rect[1];
  1670. rect[2] = rect[2] < sCell.area.Right ? sCell.area.Right : rect[2];
  1671. rect[3] = rect[3] < sCell.area.Bottom ? sCell.area.Bottom : rect[3];
  1672. }
  1673. return rect;
  1674. };
  1675. const createStampArea = function(orgCell, controls, maxRect) {
  1676. const ctrl = controls[orgCell.control];
  1677. const rst = { Left: orgCell.area.Left, Right: orgCell.area.Right, Top: orgCell.area.Top, Bottom: orgCell.area.Bottom };
  1678. let pLeft = orgCell.area.Left,
  1679. pTop = orgCell.area.Top;
  1680. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  1681. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
  1682. pLeft = orgCell.area.Left;
  1683. break;
  1684. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
  1685. pLeft = (orgCell.area.Left + orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH) / 2;
  1686. break;
  1687. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
  1688. pLeft = orgCell.area.Right - STD_COMP_STAMP_SIZE_WIDTH;
  1689. break;
  1690. default:break;
  1691. }
  1692. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  1693. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
  1694. pTop = orgCell.area.Top;
  1695. break;
  1696. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
  1697. pTop = (orgCell.area.Top + orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT) / 2;
  1698. break;
  1699. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
  1700. pTop = orgCell.area.Bottom - STD_COMP_STAMP_SIZE_HEIGHT;
  1701. break;
  1702. default:break;
  1703. }
  1704. rst.Left = pLeft;
  1705. rst.Top = pTop;
  1706. rst.Right = pLeft + STD_COMP_STAMP_SIZE_WIDTH;
  1707. rst.Bottom = pTop + STD_COMP_STAMP_SIZE_WIDTH;
  1708. // 最后一步,如超过报表范围,则要调整坐标
  1709. // if (rst.Left < maxRect[0]) {
  1710. // const width = maxRect[0] - rst.Left;
  1711. // rst.Left += width;
  1712. // rst.Right += width;
  1713. // }
  1714. // if (rst.Top < maxRect[1]) {
  1715. // const height = maxRect[1] - rst.Top;
  1716. // rst.Top += height;
  1717. // rst.Bottom += height;
  1718. // }
  1719. // if (rst.Right > maxRect[2]) {
  1720. // const width = maxRect[2] - rst.Right; // 负
  1721. // rst.Left += width;
  1722. // rst.Right += width;
  1723. // }
  1724. // if (rst.Bottom > maxRect[3]) {
  1725. // const height = maxRect[3] - rst.Bottom;
  1726. // rst.Top += height;
  1727. // rst.Bottom += height;
  1728. // }
  1729. return rst;
  1730. };
  1731. const _mergeSingleStamp = async function(_page, _roleRelList, checkAudit = false) {
  1732. let roleRelContent = [];
  1733. if (_roleRelList && _roleRelList.rel_content !== null && _roleRelList.rel_content !== undefined && _roleRelList.rel_content !== '') {
  1734. roleRelContent = JSON.parse(_roleRelList.rel_content);
  1735. }
  1736. for (const page of _page.items) {
  1737. const maxRect = _getMaxRect(page);
  1738. if (page.signature_cells) {
  1739. const newStampCells = [];
  1740. for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
  1741. const sCell = page.signature_cells[scIdx];
  1742. for (const role_rel of roleRelContent) {
  1743. if (sCell.signature_name === role_rel.signature_name) {
  1744. if (!checkAudit || _chkIfAudit(role_rel, stgAudit, stageList)) {
  1745. if (Array.isArray(role_rel.sign_output) && role_rel.sign_output.length > 0) {
  1746. for (const signType of role_rel.sign_output) {
  1747. switch (signType) {
  1748. case COMPANY_SIGN_STR:
  1749. case PRIVATE_SIGN_STR:
  1750. // 创建一个新的cell
  1751. let stampPath = (signType === COMPANY_SIGN_STR) ? role_rel.company_stamp_path : role_rel.private_stamp_path;
  1752. stampPath = ctx.app.config.fujianOssPath + stampPath;
  1753. if (dupPicPaths.indexOf(stampPath) < 0) {
  1754. dupPicPaths.push(stampPath);
  1755. // await _chkRawPicSizeOSS(ctx, stampPath);
  1756. }
  1757. // 保存在签字信息中的签章信息
  1758. let signatureArea;
  1759. if (role_rel.areaData && role_rel.areaData[signType]) {
  1760. signatureArea = role_rel.areaData[signType];
  1761. }
  1762. const newStampCell = {
  1763. signature_name: JV.SIGNATURE_NAME_DUMMY,
  1764. control: sCell.control,
  1765. style: sCell.style,
  1766. path: stampPath,
  1767. isStamp: true,
  1768. maxRect,
  1769. orgArea: sCell.area,
  1770. area: signatureArea || createStampArea(sCell, _page[JV.NODE_CONTROL_COLLECTION], maxRect), // 有签章信息就直接取,没有的话就走原来的逻辑
  1771. signatureName: role_rel.signature_name, // 节点名称
  1772. signType, // 签章信息
  1773. isSaveSignature: !!signatureArea, // 是否有签章位置信息
  1774. };
  1775. newStampCells.push(newStampCell);
  1776. break;
  1777. default: break;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. if (newStampCells.length > 0) {
  1786. page.signature_cells = page.signature_cells.concat(newStampCells);
  1787. }
  1788. }
  1789. }
  1790. };
  1791. if (pageData instanceof Array) {
  1792. pageData.forEach((dtlPage, index) => {
  1793. let dftRolRel = [];
  1794. const rpt_id = rpt_ids[index];
  1795. for (const roleRel of singleRoleRel) {
  1796. if (roleRel.rpt_id === rpt_id) {
  1797. dftRolRel = roleRel;
  1798. }
  1799. }
  1800. _mergeSingleStamp(dtlPage, dftRolRel, status !== 3);
  1801. });
  1802. } else {
  1803. _mergeSingleStamp(pageData, singleRoleRel, status !== 3);
  1804. }
  1805. }
  1806. function mergeSignAudit(pageData, currRoleRelList, currAuditList) {
  1807. for (const page of pageData.items) {
  1808. if (page.signature_audit_cells) {
  1809. for (const sCell of page.signature_audit_cells) {
  1810. sCell.Value = ''; // 这里要先清除原有信息
  1811. if (currRoleRelList && currRoleRelList.length > 0) {
  1812. for (const role_rel of currRoleRelList) {
  1813. if (sCell.signature_name === role_rel.signature_name + '_审核意见') {
  1814. let preDate = '';
  1815. sCell.Value = '同意'; // 只有选择了签名的,才需要初始化一个默认的意见(之前的逻辑在有多个签名,哪怕只选择了一个,其他的意见都会有默认意见)
  1816. if (currAuditList && currAuditList.length > 0) {
  1817. for (const audit_rel of currAuditList) {
  1818. if (role_rel.acc_id === audit_rel.aid) {
  1819. if (audit_rel.end_time > preDate && audit_rel.status === 3) {
  1820. sCell.Value = audit_rel.opinion;
  1821. preDate = audit_rel.end_time;
  1822. }
  1823. // 不能break,实际会有多个审核意见,以最后一个为准
  1824. }
  1825. }
  1826. }
  1827. break;
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. }
  1835. function mergeSignDate(pageData, current_stage_id, currRoleRelList, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
  1836. if (currRoleRelList && currRoleRelList.length > 0 && STAGE_AUDIT && STAGE_AUDIT.length > 0) {
  1837. for (let rridx = 0; rridx < currRoleRelList.length; rridx++) {
  1838. const role_rel = currRoleRelList[rridx];
  1839. if (role_rel.sign_date === undefined || role_rel.sign_date === null || role_rel.sign_date === '') {
  1840. const dftDate = _getSignDateByAllScenarios(role_rel.acc_id, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST);
  1841. role_rel.sign_date = dftDate;
  1842. }
  1843. }
  1844. }
  1845. if (currRoleRelList && currRoleRelList.length > 0) {
  1846. for (const page of pageData.items) {
  1847. if (page.signature_date_cells) {
  1848. for (const sCell of page.signature_date_cells) {
  1849. sCell.Value = _getSignDateDftName();
  1850. for (const role_rel of currRoleRelList) {
  1851. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  1852. if (role_rel.sign_date !== '') {
  1853. if (typeof role_rel.sign_date === 'string') {
  1854. role_rel.sign_date = new Date(role_rel.sign_date);
  1855. }
  1856. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  1857. }
  1858. break;
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. function _getSignDateByAllScenarios(userAccId, current_stage_id, STAGE_AUDIT, STAGE_AUDIT_ORG, STAGE_LIST) {
  1867. let rst = '';
  1868. let hasAudit = false;
  1869. for (const stg_audit of STAGE_AUDIT) {
  1870. if (stg_audit.aid === userAccId) {
  1871. hasAudit = true;
  1872. if (stg_audit.status === 3) {
  1873. rst = stg_audit.end_time;
  1874. } else {
  1875. rst = '';
  1876. }
  1877. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  1878. }
  1879. }
  1880. let isOrgRpt = false;
  1881. for (const stg of STAGE_LIST) {
  1882. if (stg.id === current_stage_id) {
  1883. if (stg.user_id === userAccId) {
  1884. isOrgRpt = true;
  1885. }
  1886. break;
  1887. }
  1888. }
  1889. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  1890. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  1891. rst = STAGE_AUDIT_ORG[0].begin_time;
  1892. }
  1893. }
  1894. if (!isOrgRpt && !hasAudit) {
  1895. // 非审批流程人员以及非原报,则显示期截至时间
  1896. for (const stg of STAGE_LIST) {
  1897. if (stg.id === current_stage_id && stg.period) {
  1898. const period = stg.period.split(' ~ ');
  1899. if (period.length === 2) {
  1900. rst = period[1];
  1901. }
  1902. }
  1903. }
  1904. }
  1905. return rst;
  1906. }
  1907. function _getSignDateDftName() {
  1908. return ' 年 月 日';
  1909. }
  1910. async function _chkRawPicSize(pageData, baseDir) {
  1911. let rst = 0;
  1912. const picKeys = [];
  1913. for (let pi = 0; pi < pageData.items.length; pi++) {
  1914. // 每页判断
  1915. for (let ci = 0; ci < pageData.items[pi][JV.PROP_SIGNATURE_CELLS].length; ci++) {
  1916. const picPath = pageData.items[pi][JV.PROP_SIGNATURE_CELLS][ci].path;
  1917. // if (picPath && picPath.indexOf('/sign') < 0 && picKeys.indexOf(picPath) < 0) {
  1918. if (picPath && picPath !== '' && picKeys.indexOf(picPath) < 0) {
  1919. // 签名图片也要计算在内,反正不重复
  1920. picKeys.push(picPath);
  1921. }
  1922. // signature_cells PROP_SIGNATURE_CELLS
  1923. }
  1924. }
  1925. // console.log(picKeys);
  1926. for (const pKey of picKeys) {
  1927. const filePath = `${baseDir}/app${pKey}`;
  1928. console.log('filePath: ' + filePath);
  1929. let isExist = false;
  1930. try {
  1931. isExist = await isFileExisted(filePath);
  1932. } catch (ex) {
  1933. isExist = false;
  1934. }
  1935. console.log('isExist: ' + isExist);
  1936. if (isExist) {
  1937. const obj = fs.statSync(filePath);
  1938. if (obj) {
  1939. rst += obj.size;
  1940. } else {
  1941. console.log('no statSync resutl: ' + filePath);
  1942. }
  1943. // rst += fs.statSync(filePath).size;
  1944. } else {
  1945. console.log(`${pKey} not exists!`);
  1946. }
  1947. }
  1948. return rst;
  1949. }
  1950. async function _chkRawPicSizeOSS(ctx, picPath) {
  1951. // 计量的草图、签章都放在OSS服务器上,需要另外的方式来获取,考虑到效率问题,机制上得有所变化
  1952. const rst = [0, 0];
  1953. try {
  1954. const pf = await ctx.app.signPdfOss.get(picPath);
  1955. console.log('get pic successfully!');
  1956. console.log(pf);
  1957. } catch (ex) {
  1958. console.log(ex);
  1959. } finally {
  1960. console.log('finally!');
  1961. }
  1962. return rst;
  1963. }
  1964. function _resetPageDataByBreaks(pageDataArr, breakAmt, rpt_names, newRptNames) {
  1965. const rst = [];
  1966. for (let pi = 0; pi < pageDataArr.length; pi++) {
  1967. const pageItem = pageDataArr[pi];
  1968. const currentRptName = rpt_names[pi];
  1969. if (pageItem.items.length > breakAmt) {
  1970. let pa = Math.floor(pageItem.items.length / breakAmt);
  1971. if (pageItem.items.length % breakAmt > 0) {
  1972. pa++;
  1973. }
  1974. for (let idx = 0; idx < pa; idx++) {
  1975. const newPageDataObj = { items: [] };
  1976. // newPageDataObj[JV.NODE_PAGE_INFO] = JSON.parse(JSON.stringify(pageItem[JV.NODE_PAGE_INFO]));
  1977. newPageDataObj[JV.NODE_PAGE_INFO] = pageItem[JV.NODE_PAGE_INFO];
  1978. // newPageDataObj[JV.BAND_PROP_MERGE_BAND] = JSON.parse(JSON.stringify(pageItem[JV.BAND_PROP_MERGE_BAND]));
  1979. newPageDataObj[JV.BAND_PROP_MERGE_BAND] = pageItem[JV.BAND_PROP_MERGE_BAND];
  1980. newPageDataObj[JV.NODE_FONT_COLLECTION] = pageItem[JV.NODE_FONT_COLLECTION];
  1981. newPageDataObj[JV.NODE_STYLE_COLLECTION] = pageItem[JV.NODE_STYLE_COLLECTION];
  1982. newPageDataObj[JV.NODE_CONTROL_COLLECTION] = pageItem[JV.NODE_CONTROL_COLLECTION];
  1983. for (let dIdx = idx * breakAmt; dIdx < (Math.min((idx + 1) * breakAmt, pageItem.items.length)); dIdx++) {
  1984. newPageDataObj.items.push(pageItem.items[dIdx]);
  1985. }
  1986. rst.push(newPageDataObj);
  1987. newRptNames.push(currentRptName + '_' + (idx + 1));
  1988. }
  1989. } else {
  1990. rst.push(pageItem);
  1991. newRptNames.push(currentRptName);
  1992. }
  1993. }
  1994. return rst;
  1995. }