report_controller.js 82 KB

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