datacollect_controller.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. const mapConst = require('../const/map');
  25. module.exports = app => {
  26. class DatacollectController extends app.BaseController {
  27. /**
  28. * 构造函数
  29. *
  30. * @param {Object} ctx - egg全局变量
  31. * @return {void}
  32. */
  33. constructor(ctx) {
  34. super(ctx);
  35. ctx.showProject = true;
  36. ctx.showTitle = true;
  37. }
  38. /**
  39. * 期列表(Get)
  40. * @param ctx
  41. * @return {Promise<void>}
  42. */
  43. async index(ctx) {
  44. try {
  45. // 获取标段审批信息
  46. const tenderidList = [];
  47. const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  48. // 获取分类
  49. const categoryData = await this.ctx.service.category.getListByCategoryLevel(ctx.session.sessionProject.id);
  50. // 默认坐标,否则则取办事处坐标
  51. const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
  52. let map_json = {
  53. province: mapConst.map[0].province,
  54. lng: mapConst.map[0].lng,
  55. lat: mapConst.map[0].lat,
  56. level: 15,
  57. };
  58. if (projectData.map_json) {
  59. map_json = JSON.parse(projectData.map_json);
  60. } else {
  61. const mapInfo = ctx.helper._.find(mapConst.map, { office: projectData.manager_office });
  62. if (mapInfo) {
  63. map_json.province = mapInfo.province;
  64. map_json.lng = mapInfo.lng;
  65. map_json.lat = mapInfo.lat;
  66. }
  67. }
  68. const renderData = {
  69. noticeList,
  70. categoryData,
  71. map_json,
  72. acLedger: auditConst.ledger,
  73. acStage: auditConst.stage,
  74. acChange: auditConst.flow,
  75. acRevise: auditConst.revise,
  76. acMaterial: auditConst.material,
  77. acAdvance: auditConst.advance,
  78. pushType: auditConst.pushType,
  79. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.datacollect.index),
  80. };
  81. await this.layout('datacollect/index.ejs', renderData);
  82. } catch (err) {
  83. this.log(err);
  84. ctx.redirect(this.menu.menu.dashboard.url);
  85. }
  86. }
  87. async loadData(ctx) {
  88. try {
  89. const responseData = { err: 0, msg: '', data: {} };
  90. // const tenderidList = [];
  91. // const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  92. const tenderList = await ctx.service.tender.getList('', null, 1);
  93. const thisMonth = new Date();
  94. const [startMonth, endMonth] = ctx.helper.getStartEndMonth(thisMonth);
  95. for (const t of tenderList) {
  96. const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(t.id);
  97. t.contract_price = tenderInfo.deal_param.contractPrice;
  98. if (t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck) {
  99. const sum = await ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
  100. t.total_price = sum.total_price;
  101. t.deal_tp = sum.deal_tp;
  102. }
  103. t.advance_tp = await ctx.service.advance.getSumAdvance(t.id);
  104. if (t.ledger_status === auditConst.ledger.status.checked) {
  105. t.lastStage = await ctx.service.stage.getLastestStage(t.id, true);
  106. if (t.lastStage && t.lastStage.status === auditConst.stage.status.uncheck &&
  107. t.lastStage.user_id !== ctx.session.sessionUser.accountId) {
  108. t.lastStage = await ctx.service.stage.getLastestStage(t.id);
  109. }
  110. if (t.lastStage) await ctx.service.stage.checkStageGatherData(t.lastStage);
  111. t.completeStage = await ctx.service.stage.getLastestCompleteStage(t.id);
  112. }
  113. t.material_tp = await ctx.service.material.getSumMaterial(t.id);
  114. // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
  115. t.month_stage_num = await ctx.service.stageAudit.getNumByMonth(t.id, startMonth, endMonth);
  116. t.month_change_num = await ctx.service.changeAudit.getNumByMonth(t.id, startMonth, endMonth);
  117. t.month_revise_num = await ctx.service.reviseAudit.getNumByMonth(t.id, startMonth, endMonth);
  118. t.month_material_num = await ctx.service.materialAudit.getNumByMonth(t.id, startMonth, endMonth);
  119. // 获取标段计量月统计及截止月累计计量
  120. const stageList = await ctx.service.stage.getStageByDataCollect(t.id);
  121. const month_stage = [];
  122. for (const s of stageList) {
  123. const monthOneStage = ctx.app._.find(month_stage, { yearmonth: s.s_time });
  124. if (monthOneStage) {
  125. monthOneStage.tp = ctx.helper.add(monthOneStage.tp, s.tp);
  126. } else {
  127. const data = {
  128. yearmonth: s.s_time,
  129. tp: s.tp,
  130. end_tp: s.end_tp,
  131. };
  132. month_stage.push(data);
  133. }
  134. }
  135. t.month_stage = month_stage;
  136. }
  137. // const tenderMapList = await ctx.service.tenderMap.getAllDataByCondition({ where: { tid: tender.id } });
  138. responseData.data.tenderList = tenderList;
  139. ctx.body = responseData;
  140. } catch (err) {
  141. this.log(err);
  142. ctx.body = { err: 1, msg: err.toString(), data: null };
  143. }
  144. }
  145. }
  146. return DatacollectController;
  147. };