datacollect_controller.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author EllisRan
  6. * @date 2021/9/26
  7. * @version
  8. */
  9. const tenderConst = require('../const/tender');
  10. const codeRuleConst = require('../const/code_rule');
  11. const settingConst = require('../const/setting.js');
  12. const tenderMenu = require('../../config/menu').tenderMenu;
  13. const auditConst = require('../const/audit');
  14. const shenpiConst = require('../const/shenpi');
  15. const accountGroup = require('../const/account_group').group;
  16. const accountPermission = require('../const/account_permission');
  17. const measureType = require('../const/tender').measureType;
  18. const billsPosConvert = require('../lib/bills_pos_convert');
  19. const path = require('path');
  20. const sendToWormhole = require('stream-wormhole');
  21. const scheduleConst = require('../const/schedule');
  22. const changeConst = require('../const/change');
  23. const tenderInfoModel = require('../lib/tender_info');
  24. module.exports = app => {
  25. class DatacollectController extends app.BaseController {
  26. /**
  27. * 构造函数
  28. *
  29. * @param {Object} ctx - egg全局变量
  30. * @return {void}
  31. */
  32. constructor(ctx) {
  33. super(ctx);
  34. ctx.showProject = true;
  35. ctx.showTitle = true;
  36. }
  37. /**
  38. * 期列表(Get)
  39. * @param ctx
  40. * @return {Promise<void>}
  41. */
  42. async index(ctx) {
  43. try {
  44. // 获取标段审批信息
  45. const tenderidList = [];
  46. console.log(ctx.session.sessionProject.dataCollect);
  47. const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  48. const renderData = {
  49. noticeList,
  50. acLedger: auditConst.ledger,
  51. acStage: auditConst.stage,
  52. acChange: auditConst.flow,
  53. acRevise: auditConst.revise,
  54. acMaterial: auditConst.material,
  55. acAdvance: auditConst.advance,
  56. pushType: auditConst.pushType,
  57. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.datacollect.index),
  58. };
  59. await this.layout('datacollect/index.ejs', renderData);
  60. } catch (err) {
  61. this.log(err);
  62. ctx.redirect(this.menu.menu.dashboard.url);
  63. }
  64. }
  65. async loadData(ctx) {
  66. try {
  67. const responseData = { err: 0, msg: '', data: {} };
  68. // const tenderidList = [];
  69. // const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  70. const tenderList = await ctx.service.tender.getList('', null, 1);
  71. const thisMonth = new Date();
  72. const [startMonth, endMonth] = ctx.helper.getStartEndMonth(thisMonth);
  73. for (const t of tenderList) {
  74. const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(t.id);
  75. t.contract_price = tenderInfo.deal_param.contractPrice;
  76. if (t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck) {
  77. const sum = await ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
  78. t.total_price = sum.total_price;
  79. t.deal_tp = sum.deal_tp;
  80. }
  81. t.advance_tp = await ctx.service.advance.getSumAdvance(t.id);
  82. if (t.ledger_status === auditConst.ledger.status.checked) {
  83. t.lastStage = await ctx.service.stage.getLastestStage(t.id, true);
  84. if (t.lastStage && t.lastStage.status === auditConst.stage.status.uncheck &&
  85. t.lastStage.user_id !== ctx.session.sessionUser.accountId) {
  86. t.lastStage = await ctx.service.stage.getLastestStage(t.id);
  87. }
  88. if (t.lastStage) await ctx.service.stage.checkStageGatherData(t.lastStage);
  89. t.completeStage = await ctx.service.stage.getLastestCompleteStage(t.id);
  90. }
  91. t.material_tp = await ctx.service.material.getSumMaterial(t.id);
  92. // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
  93. t.month_stage_num = await this.ctx.service.stageAudit.getNumByMonth(t.id, startMonth, endMonth);
  94. t.month_change_num = await this.ctx.service.changeAudit.getNumByMonth(t.id, startMonth, endMonth);
  95. t.month_revise_num = await this.ctx.service.reviseAudit.getNumByMonth(t.id, startMonth, endMonth);
  96. t.month_material_num = await this.ctx.service.materialAudit.getNumByMonth(t.id, startMonth, endMonth);
  97. }
  98. responseData.data.tenderList = tenderList;
  99. ctx.body = responseData;
  100. } catch (err) {
  101. this.log(err);
  102. ctx.body = { err: 1, msg: err.toString(), data: null };
  103. }
  104. }
  105. }
  106. return DatacollectController;
  107. };