'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 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} */ async index(ctx) { try { // 获取标段审批信息 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); 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; } } const renderData = { 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), }; await this.layout('datacollect/index.ejs', renderData); } catch (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); 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); for (const t of tenderList) { const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(t.id); t.contract_price = tenderInfo.deal_param.contractPrice; if (t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck) { const sum = await ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ }); t.total_price = sum.total_price; t.deal_tp = sum.deal_tp; } 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, true); if (t.lastStage && t.lastStage.status === auditConst.stage.status.uncheck && t.lastStage.user_id !== ctx.session.sessionUser.accountId) { t.lastStage = await ctx.service.stage.getLastestStage(t.id); } if (t.lastStage) await ctx.service.stage.checkStageGatherData(t.lastStage); t.completeStage = await ctx.service.stage.getLastestCompleteStage(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); 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); } else { const data = { yearmonth: s.s_time, tp: s.tp, end_tp: s.end_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; };