datacollect_controller.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  47. // 获取分类
  48. const categoryData = await this.ctx.service.category.getListByCategoryLevel(ctx.session.sessionProject.id);
  49. const renderData = {
  50. noticeList,
  51. categoryData,
  52. acLedger: auditConst.ledger,
  53. acStage: auditConst.stage,
  54. acChange: auditConst.flow,
  55. acRevise: auditConst.revise,
  56. acMaterial: auditConst.material,
  57. acAdvance: auditConst.advance,
  58. pushType: auditConst.pushType,
  59. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.datacollect.index),
  60. };
  61. await this.layout('datacollect/index.ejs', renderData);
  62. } catch (err) {
  63. this.log(err);
  64. ctx.redirect(this.menu.menu.dashboard.url);
  65. }
  66. }
  67. async loadData(ctx) {
  68. try {
  69. const responseData = { err: 0, msg: '', data: {} };
  70. // const tenderidList = [];
  71. // const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  72. const tenderList = await ctx.service.tender.getList('', null, 1);
  73. const thisMonth = new Date();
  74. const [startMonth, endMonth] = ctx.helper.getStartEndMonth(thisMonth);
  75. for (const t of tenderList) {
  76. const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(t.id);
  77. t.contract_price = tenderInfo.deal_param.contractPrice;
  78. if (t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck) {
  79. const sum = await ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
  80. t.total_price = sum.total_price;
  81. t.deal_tp = sum.deal_tp;
  82. }
  83. t.advance_tp = await ctx.service.advance.getSumAdvance(t.id);
  84. if (t.ledger_status === auditConst.ledger.status.checked) {
  85. t.lastStage = await ctx.service.stage.getLastestStage(t.id, true);
  86. if (t.lastStage && t.lastStage.status === auditConst.stage.status.uncheck &&
  87. t.lastStage.user_id !== ctx.session.sessionUser.accountId) {
  88. t.lastStage = await ctx.service.stage.getLastestStage(t.id);
  89. }
  90. if (t.lastStage) await ctx.service.stage.checkStageGatherData(t.lastStage);
  91. t.completeStage = await ctx.service.stage.getLastestCompleteStage(t.id);
  92. }
  93. t.material_tp = await ctx.service.material.getSumMaterial(t.id);
  94. // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
  95. t.month_stage_num = await ctx.service.stageAudit.getNumByMonth(t.id, startMonth, endMonth);
  96. t.month_change_num = await ctx.service.changeAudit.getNumByMonth(t.id, startMonth, endMonth);
  97. t.month_revise_num = await ctx.service.reviseAudit.getNumByMonth(t.id, startMonth, endMonth);
  98. t.month_material_num = await ctx.service.materialAudit.getNumByMonth(t.id, startMonth, endMonth);
  99. // 获取标段计量月统计及截止月累计计量
  100. const stageList = await ctx.service.stage.getStageByDataCollect(t.id);
  101. const month_stage = [];
  102. for (const s of stageList) {
  103. const monthOneStage = ctx.app._.find(month_stage, { yearmonth: s.s_time });
  104. if (monthOneStage) {
  105. monthOneStage.tp = ctx.helper.add(monthOneStage.tp, s.tp);
  106. } else {
  107. const data = {
  108. yearmonth: s.s_time,
  109. tp: s.tp,
  110. end_tp: s.end_tp,
  111. };
  112. month_stage.push(data);
  113. }
  114. }
  115. t.month_stage = month_stage;
  116. }
  117. responseData.data.tenderList = tenderList;
  118. ctx.body = responseData;
  119. } catch (err) {
  120. this.log(err);
  121. ctx.body = { err: 1, msg: err.toString(), data: null };
  122. }
  123. }
  124. }
  125. return DatacollectController;
  126. };