| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author EllisRan
 
-  * @date 2021/9/26
 
-  * @version
 
-  */
 
- const tenderConst = require('../const/tender');
 
- const codeRuleConst = require('../const/code_rule');
 
- const settingConst = require('../const/setting.js');
 
- const tenderMenu = require('../../config/menu').tenderMenu;
 
- const auditConst = require('../const/audit');
 
- const shenpiConst = require('../const/shenpi');
 
- const accountGroup = require('../const/account_group').group;
 
- const accountPermission = require('../const/account_permission');
 
- const measureType = require('../const/tender').measureType;
 
- const billsPosConvert = require('../lib/bills_pos_convert');
 
- const path = require('path');
 
- const sendToWormhole = require('stream-wormhole');
 
- const scheduleConst = require('../const/schedule');
 
- const changeConst = require('../const/change');
 
- const tenderInfoModel = require('../lib/tender_info');
 
- const projectSettingConst = require('../const/project_setting');
 
- const mapConst = require('../const/map');
 
- module.exports = app => {
 
-     class DatacollectController extends app.BaseController {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             ctx.showProject = true;
 
-             ctx.showTitle = true;
 
-         }
 
-         /**
 
-          * 期列表(Get)
 
-          * @param ctx
 
-          * @return {Promise<void>}
 
-          */
 
-         async index(ctx) {
 
-             try {
 
-                 if (!ctx.session.sessionProject.showDataCollect) {
 
-                     throw '该功能已关闭或无法查看';
 
-                 }
 
-                 // 获取标段审批信息
 
-                 const tenderidList = [];
 
-                 const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
 
-                 // 获取分类
 
-                 const categoryData = await this.ctx.service.category.getListByCategoryLevel(ctx.session.sessionProject.id);
 
-                 // 默认坐标,否则则取办事处坐标
 
-                 const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
 
-                 projectData.data_collect_pages = projectData.data_collect_pages ? projectData.data_collect_pages.split(',') : [];
 
-                 let map_json = {
 
-                     province: mapConst.map[0].province,
 
-                     lng: mapConst.map[0].lng,
 
-                     lat: mapConst.map[0].lat,
 
-                     level: 15,
 
-                 };
 
-                 if (projectData.map_json) {
 
-                     map_json = JSON.parse(projectData.map_json);
 
-                 } else {
 
-                     const mapInfo = ctx.helper._.find(mapConst.map, { office: projectData.manager_office });
 
-                     if (mapInfo) {
 
-                         map_json.province = mapInfo.province;
 
-                         map_json.lng = mapInfo.lng;
 
-                         map_json.lat = mapInfo.lat;
 
-                     }
 
-                 }
 
-                 if (ctx.params.index) {
 
-                     ctx.session.sessionProject.dataCollect = parseInt(ctx.params.index);
 
-                 }
 
-                 const is_dz2 = ['P0505', 'P0506', 'P1201', 'P1202', 'GY18Y'].indexOf(ctx.session.sessionProject.code) !== -1
 
-                     && projectData.data_collect_pages.includes('6') && ctx.session.sessionProject.dataCollect === 6;
 
-                 const renderData = {
 
-                     projectData,
 
-                     noticeList,
 
-                     categoryData,
 
-                     map_json,
 
-                     acLedger: auditConst.ledger,
 
-                     acStage: auditConst.stage,
 
-                     acChange: auditConst.flow,
 
-                     acRevise: auditConst.revise,
 
-                     acMaterial: auditConst.material,
 
-                     acAdvance: auditConst.advance,
 
-                     pushType: auditConst.pushType,
 
-                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.datacollect.index),
 
-                 };
 
-                 if (is_dz2) {
 
-                     const commonJson = projectData.common_json ? JSON.parse(projectData.common_json) : null;
 
-                     renderData.daping06Set = commonJson && commonJson.daPing06_set ? commonJson.daPing06_set : ctx.helper._.cloneDeep(projectSettingConst.daPing06Set);
 
-                     const glCategory = categoryData.find(item => item.name === '管理类别');
 
-                     const dpCategory = [];
 
-                     for (const d of renderData.daping06Set.cb_show) {
 
-                         if (glCategory && glCategory.value) dpCategory.push(glCategory.value.find(item => item.id === d));
 
-                     }
 
-                     renderData.dpCategory = dpCategory;
 
-                     await this.layout('datacollect/index4GY18Y.ejs', renderData);
 
-                 } else {
 
-                     await this.layout('datacollect/index.ejs', renderData);
 
-                 }
 
-             } catch (err) {
 
-                 console.log(err);
 
-                 this.log(err);
 
-                 ctx.redirect(this.menu.menu.dashboard.url);
 
-             }
 
-         }
 
-         async loadData(ctx) {
 
-             try {
 
-                 const responseData = { err: 0, msg: '', data: {} };
 
-                 // const tenderidList = [];
 
-                 // const noticeList = await ctx.service.noticePush.getNoticeByDataCollect(ctx.session.sessionProject.id, tenderidList);
 
-                 const dcTenders = await ctx.service.datacollectTender.getList(ctx.session.sessionProject.id);
 
-                 const noTids = ctx.app._.map(dcTenders, 'tid');
 
-                 let tenderList = await ctx.service.tender.getList('', null, 1);
 
-                 // let tenderList = await this.ctx.service.tender.getBuildList('', null, 1);
 
-                 tenderList = ctx.app._.filter(tenderList, function(item) {
 
-                     return ctx.app._.indexOf(noTids, item.id) === -1;
 
-                 });
 
-                 const thisMonth = new Date();
 
-                 const [startMonth, endMonth] = ctx.helper.getStartEndMonth(thisMonth);
 
-                 // 统计方法总时长
 
-                 // let sumStageByDataCollectTime = 0;
 
-                 for (const t of tenderList) {
 
-                     // const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(t.id);
 
-                     // t.contract_price = tenderInfo.deal_param.contractPrice;
 
-                     // let bCalcTp = t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck;
 
-                     // t.advance_tp = await ctx.service.advance.getSumAdvance(t.id);
 
-                     //
 
-                     // if (t.ledger_status === auditConst.ledger.status.checked) {
 
-                     //     t.lastStage = await ctx.service.stage.getLastestStage(t.id);
 
-                     //     if (t.lastStage) await ctx.service.stage.checkStageGatherDataByDataCollect(t.lastStage, true);
 
-                     //     t.completeStage = await ctx.service.stage.getLastestCompleteStage(t.id);
 
-                     //     if ((!bCalcTp) && t.measure_type === measureType.gcl.value) {
 
-                     //         bCalcTp = t.lastStage && t.lastStage.status !== auditConst.stage.status.checked && !t.lastStage.readOnly;
 
-                     //     }
 
-                     // }
 
-                     // if (bCalcTp) {
 
-                     //     const sum = await this.ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
 
-                     //     t.total_price = sum.total_price;
 
-                     //     t.deal_tp = sum.deal_tp;
 
-                     // }
 
-                     // 用标段管理的方法获取t数据
 
-                     await this.ctx.service.tenderCache.loadTenderCache(t, '');
 
-                     t.total_price = t.ledger_tp && t.ledger_tp.total_price ? t.ledger_tp.total_price : 0;
 
-                     [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);
 
-                     // t.material_tp = await ctx.service.material.getSumMaterial(t.id);
 
-                     // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
 
-                     t.month_stage_num = await ctx.service.stageAudit.getNumByMonth(t.id, startMonth, endMonth);
 
-                     t.month_change_num = await ctx.service.changeAudit.getNumByMonth(t.id, startMonth, endMonth);
 
-                     t.month_revise_num = await ctx.service.reviseAudit.getNumByMonth(t.id, startMonth, endMonth);
 
-                     t.month_material_num = await ctx.service.materialAudit.getNumByMonth(t.id, startMonth, endMonth);
 
-                     // 获取标段计量月统计及截止月累计计量
 
-                     // 这个慢,统计下面这个方法时长
 
-                     const stageList = await ctx.service.stage.getStageByDataCollect(t.id, t.stage_tp);
 
-                     // const stageList = [];
 
-                     const month_stage = [];
 
-                     for (const s of stageList) {
 
-                         const monthOneStage = ctx.app._.find(month_stage, { yearmonth: s.s_time });
 
-                         if (monthOneStage) {
 
-                             monthOneStage.tp = ctx.helper.add(monthOneStage.tp, s.tp);
 
-                             monthOneStage.end_yf_tp = ctx.helper.add(monthOneStage.end_yf_tp, s.yf_tp);
 
-                             monthOneStage.end_sf_tp = ctx.helper.add(monthOneStage.end_sf_tp, s.sf_tp);
 
-                         } else {
 
-                             const data = {
 
-                                 yearmonth: s.s_time,
 
-                                 tp: s.tp,
 
-                                 end_tp: s.end_tp,
 
-                                 end_yf_tp: s.yf_tp,
 
-                                 end_sf_tp: s.sf_tp,
 
-                             };
 
-                             month_stage.push(data);
 
-                         }
 
-                     }
 
-                     t.month_stage = month_stage;
 
-                 }
 
-                 // const tenderMapList = await ctx.service.tenderMap.getAllDataByCondition({ where: { tid: tender.id } });
 
-                 responseData.data.tenderList = tenderList;
 
-                 ctx.body = responseData;
 
-             } catch (err) {
 
-                 this.log(err);
 
-                 ctx.body = { err: 1, msg: err.toString(), data: null };
 
-             }
 
-         }
 
-     }
 
-     return DatacollectController;
 
- };
 
 
  |