datacollect_controller.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. if (!ctx.session.sessionProject.showDataCollect) {
  46. throw '该功能已关闭或无法查看';
  47. }
  48. // 获取标段审批信息
  49. const tenderidList = [];
  50. const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  51. // 获取分类
  52. const categoryData = await this.ctx.service.category.getListByCategoryLevel(ctx.session.sessionProject.id);
  53. // 默认坐标,否则则取办事处坐标
  54. const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
  55. projectData.data_collect_pages = projectData.data_collect_pages ? projectData.data_collect_pages.split(',') : [];
  56. let map_json = {
  57. province: mapConst.map[0].province,
  58. lng: mapConst.map[0].lng,
  59. lat: mapConst.map[0].lat,
  60. level: 15,
  61. };
  62. if (projectData.map_json) {
  63. map_json = JSON.parse(projectData.map_json);
  64. } else {
  65. const mapInfo = ctx.helper._.find(mapConst.map, { office: projectData.manager_office });
  66. if (mapInfo) {
  67. map_json.province = mapInfo.province;
  68. map_json.lng = mapInfo.lng;
  69. map_json.lat = mapInfo.lat;
  70. }
  71. }
  72. const renderData = {
  73. projectData,
  74. noticeList,
  75. categoryData,
  76. map_json,
  77. acLedger: auditConst.ledger,
  78. acStage: auditConst.stage,
  79. acChange: auditConst.flow,
  80. acRevise: auditConst.revise,
  81. acMaterial: auditConst.material,
  82. acAdvance: auditConst.advance,
  83. pushType: auditConst.pushType,
  84. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.datacollect.index),
  85. };
  86. await this.layout('datacollect/index.ejs', renderData);
  87. } catch (err) {
  88. this.log(err);
  89. ctx.redirect(this.menu.menu.dashboard.url);
  90. }
  91. }
  92. async loadData(ctx) {
  93. try {
  94. const responseData = { err: 0, msg: '', data: {} };
  95. // const tenderidList = [];
  96. // const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  97. const dcTenders = await ctx.service.datacollectTender.getList(ctx.session.sessionProject.id);
  98. const noTids = ctx.app._.map(dcTenders, 'tid');
  99. let tenderList = await ctx.service.tender.getList('', null, 1);
  100. tenderList = ctx.app._.filter(tenderList, function(item) {
  101. return ctx.app._.indexOf(noTids, item.id) === -1;
  102. });
  103. const thisMonth = new Date();
  104. const [startMonth, endMonth] = ctx.helper.getStartEndMonth(thisMonth);
  105. for (const t of tenderList) {
  106. const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(t.id);
  107. t.contract_price = tenderInfo.deal_param.contractPrice;
  108. let bCalcTp = t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck;
  109. t.advance_tp = await ctx.service.advance.getSumAdvance(t.id);
  110. if (t.ledger_status === auditConst.ledger.status.checked) {
  111. t.lastStage = await ctx.service.stage.getLastestStage(t.id);
  112. if (t.lastStage) await ctx.service.stage.checkStageGatherData(t.lastStage, true);
  113. t.completeStage = await ctx.service.stage.getLastestCompleteStage(t.id);
  114. if ((!bCalcTp) && t.measure_type === measureType.gcl.value) {
  115. bCalcTp = t.lastStage && t.lastStage.status !== auditConst.stage.status.checked && !t.lastStage.readOnly;
  116. }
  117. }
  118. if (bCalcTp) {
  119. const sum = await this.ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
  120. t.total_price = sum.total_price;
  121. t.deal_tp = sum.deal_tp;
  122. }
  123. [t.change_tp, t.change_p_tp, t.change_n_tp] = await ctx.service.change.getChangeTp(t.id);
  124. // t.material_tp = await ctx.service.material.getSumMaterial(t.id);
  125. // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
  126. t.month_stage_num = await ctx.service.stageAudit.getNumByMonth(t.id, startMonth, endMonth);
  127. t.month_change_num = await ctx.service.changeAudit.getNumByMonth(t.id, startMonth, endMonth);
  128. t.month_revise_num = await ctx.service.reviseAudit.getNumByMonth(t.id, startMonth, endMonth);
  129. t.month_material_num = await ctx.service.materialAudit.getNumByMonth(t.id, startMonth, endMonth);
  130. // 获取标段计量月统计及截止月累计计量
  131. const stageList = await ctx.service.stage.getStageByDataCollect(t.id);
  132. const month_stage = [];
  133. for (const s of stageList) {
  134. const monthOneStage = ctx.app._.find(month_stage, { yearmonth: s.s_time });
  135. if (monthOneStage) {
  136. monthOneStage.tp = ctx.helper.add(monthOneStage.tp, s.tp);
  137. } else {
  138. const data = {
  139. yearmonth: s.s_time,
  140. tp: s.tp,
  141. end_tp: s.end_tp,
  142. };
  143. month_stage.push(data);
  144. }
  145. }
  146. t.month_stage = month_stage;
  147. }
  148. // const tenderMapList = await ctx.service.tenderMap.getAllDataByCondition({ where: { tid: tender.id } });
  149. responseData.data.tenderList = tenderList;
  150. ctx.body = responseData;
  151. } catch (err) {
  152. this.log(err);
  153. ctx.body = { err: 1, msg: err.toString(), data: null };
  154. }
  155. }
  156. }
  157. return DatacollectController;
  158. };