datacollect_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 projectSettingConst = require('../const/project_setting');
  25. const mapConst = require('../const/map');
  26. module.exports = app => {
  27. class DatacollectController extends app.BaseController {
  28. /**
  29. * 构造函数
  30. *
  31. * @param {Object} ctx - egg全局变量
  32. * @return {void}
  33. */
  34. constructor(ctx) {
  35. super(ctx);
  36. ctx.showProject = true;
  37. ctx.showTitle = true;
  38. }
  39. /**
  40. * 期列表(Get)
  41. * @param ctx
  42. * @return {Promise<void>}
  43. */
  44. async index(ctx) {
  45. try {
  46. if (!ctx.subProject.showDataCollect) {
  47. throw '该功能已关闭或无法查看';
  48. }
  49. // 获取标段审批信息
  50. const tenderidList = [];
  51. const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  52. // 获取分类
  53. const categoryData = await this.ctx.service.category.getListByCategoryLevel(ctx.subProject.id);
  54. // 默认坐标,否则则取办事处坐标
  55. const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
  56. ctx.subProject.data_collect_pages = ctx.subProject.data_collect_pages ? ctx.subProject.data_collect_pages.split(',') : [];
  57. // let map_json = {
  58. // province: mapConst.map[0].province,
  59. // lng: mapConst.map[0].lng,
  60. // lat: mapConst.map[0].lat,
  61. // level: 15,
  62. // };
  63. // if (projectData.map_json) {
  64. // map_json = JSON.parse(projectData.map_json);
  65. // } else {
  66. // const mapInfo = ctx.helper._.find(mapConst.map, { office: projectData.manager_office });
  67. // if (mapInfo) {
  68. // map_json.province = mapInfo.province;
  69. // map_json.lng = mapInfo.lng;
  70. // map_json.lat = mapInfo.lat;
  71. // }
  72. // }
  73. if (ctx.params.index) {
  74. ctx.subProject.dataCollect = parseInt(ctx.params.index);
  75. }
  76. const is_dz2 = ['P0505', 'P0506', 'P1201', 'P1202', 'GY18Y', 'GYJJ1', 'P1103'].indexOf(ctx.session.sessionProject.code) !== -1
  77. && ctx.subProject.data_collect_pages.includes('6') && ctx.subProject.dataCollect === 6;
  78. const renderData = {
  79. projectData,
  80. noticeList,
  81. categoryData,
  82. // map_json,
  83. acLedger: auditConst.ledger,
  84. acStage: auditConst.stage,
  85. acChange: auditConst.flow,
  86. acRevise: auditConst.revise,
  87. acMaterial: auditConst.material,
  88. acAdvance: auditConst.advance,
  89. pushType: auditConst.pushType,
  90. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.datacollect.index),
  91. };
  92. if (is_dz2) {
  93. const commonJson = projectData.common_json ? JSON.parse(projectData.common_json) : null;
  94. renderData.daping06Set = commonJson && commonJson.daPing06_set ? commonJson.daPing06_set : ctx.helper._.cloneDeep(projectSettingConst.daPing06Set);
  95. const glCategory = categoryData.find(item => item.name === '管理类别');
  96. const dpCategory = [];
  97. for (const d of renderData.daping06Set.cb_show) {
  98. if (glCategory && glCategory.value) dpCategory.push(glCategory.value.find(item => item.id === d));
  99. }
  100. renderData.dpCategory = dpCategory;
  101. await this.layout('datacollect/index4GY18Y.ejs', renderData);
  102. } else {
  103. await this.layout('datacollect/index.ejs', renderData);
  104. }
  105. } catch (err) {
  106. console.log(err);
  107. this.log(err);
  108. ctx.redirect(this.menu.menu.dashboard.url);
  109. }
  110. }
  111. async loadData(ctx) {
  112. try {
  113. const responseData = { err: 0, msg: '', data: {} };
  114. // const tenderidList = [];
  115. // const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
  116. const dcTenders = await ctx.service.datacollectTender.getList(ctx.session.sessionProject.id, ctx.subProject.id);
  117. const noTids = ctx.app._.map(dcTenders, 'tid');
  118. let tenderList = await ctx.service.tender.getList('', null, 1);
  119. // let tenderList = await this.ctx.service.tender.getBuildList('', null, 1);
  120. tenderList = ctx.app._.filter(tenderList, function(item) {
  121. return ctx.app._.indexOf(noTids, item.id) === -1;
  122. });
  123. const thisMonth = new Date();
  124. const [startMonth, endMonth] = ctx.helper.getStartEndMonth(thisMonth);
  125. // 统计方法总时长
  126. // let sumStageByDataCollectTime = 0;
  127. for (const t of tenderList) {
  128. // const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(t.id);
  129. // t.contract_price = tenderInfo.deal_param.contractPrice;
  130. // let bCalcTp = t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck;
  131. // t.advance_tp = await ctx.service.advance.getSumAdvance(t.id);
  132. //
  133. // if (t.ledger_status === auditConst.ledger.status.checked) {
  134. // t.lastStage = await ctx.service.stage.getLastestStage(t.id);
  135. // if (t.lastStage) await ctx.service.stage.checkStageGatherDataByDataCollect(t.lastStage, true);
  136. // t.completeStage = await ctx.service.stage.getLastestCompleteStage(t.id);
  137. // if ((!bCalcTp) && t.measure_type === measureType.gcl.value) {
  138. // bCalcTp = t.lastStage && t.lastStage.status !== auditConst.stage.status.checked && !t.lastStage.readOnly;
  139. // }
  140. // }
  141. // if (bCalcTp) {
  142. // const sum = await this.ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
  143. // t.total_price = sum.total_price;
  144. // t.deal_tp = sum.deal_tp;
  145. // }
  146. // 用标段管理的方法获取t数据
  147. await this.ctx.service.tenderCache.loadTenderCache(t, '');
  148. t.total_price = t.ledger_tp && t.ledger_tp.total_price ? t.ledger_tp.total_price : 0;
  149. [t.change_tp, t.change_p_tp, t.change_n_tp, t.change_valuation_tp, t.change_unvaluation_tp] = await ctx.service.change.getChangeTp(t.id);
  150. // t.material_tp = await ctx.service.material.getSumMaterial(t.id);
  151. // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
  152. t.month_stage_num = await ctx.service.stageAudit.getNumByMonth(t.id, startMonth, endMonth);
  153. t.month_change_num = await ctx.service.changeAudit.getNumByMonth(t.id, startMonth, endMonth);
  154. t.month_revise_num = await ctx.service.reviseAudit.getNumByMonth(t.id, startMonth, endMonth);
  155. t.month_material_num = await ctx.service.materialAudit.getNumByMonth(t.id, startMonth, endMonth);
  156. // 获取标段计量月统计及截止月累计计量
  157. // 这个慢,统计下面这个方法时长
  158. const stageList = await ctx.service.stage.getStageByDataCollect(t.id, t.stage_tp);
  159. // const stageList = [];
  160. const month_stage = [];
  161. for (const s of stageList) {
  162. const monthOneStage = ctx.app._.find(month_stage, { yearmonth: s.s_time });
  163. if (monthOneStage) {
  164. monthOneStage.tp = ctx.helper.add(monthOneStage.tp, s.tp);
  165. monthOneStage.end_yf_tp = ctx.helper.add(monthOneStage.end_yf_tp, s.yf_tp);
  166. monthOneStage.end_sf_tp = ctx.helper.add(monthOneStage.end_sf_tp, s.sf_tp);
  167. } else {
  168. const data = {
  169. yearmonth: s.s_time,
  170. tp: s.tp,
  171. end_tp: s.end_tp,
  172. end_yf_tp: s.yf_tp,
  173. end_sf_tp: s.sf_tp,
  174. };
  175. month_stage.push(data);
  176. }
  177. }
  178. t.month_stage = month_stage;
  179. }
  180. // const tenderMapList = await ctx.service.tenderMap.getAllDataByCondition({ where: { tid: tender.id } });
  181. responseData.data.tenderList = tenderList;
  182. ctx.body = responseData;
  183. } catch (err) {
  184. this.log(err);
  185. ctx.body = { err: 1, msg: err.toString(), data: null };
  186. }
  187. }
  188. }
  189. return DatacollectController;
  190. };