Browse Source

标段概况,提供章级汇总数据

MaiXinRong 3 years atrás
parent
commit
47cb430660
2 changed files with 111 additions and 2 deletions
  1. 5 2
      app/controller/tender_controller.js
  2. 106 0
      app/lib/tender_info.js

+ 5 - 2
app/controller/tender_controller.js

@@ -21,8 +21,8 @@ const billsPosConvert = require('../lib/bills_pos_convert');
 const path = require('path');
 const sendToWormhole = require('stream-wormhole');
 const scheduleConst = require('../const/schedule');
-const SumLoad = require('../lib/sum_load');
 const changeConst = require('../const/change');
+const tenderInfoModel = require('../lib/tender_info');
 
 module.exports = app => {
 
@@ -442,6 +442,9 @@ module.exports = app => {
                         tender.status_users = status_name ? status_name.name : '';
                     }
                 }
+                const tiModel = new tenderInfoModel(ctx);
+                const gclChapter = await tiModel.gatherChapter();
+
                 const monthProgress = [];
                 for (const s of stages) {
                     if (s.s_time) {
@@ -526,6 +529,7 @@ module.exports = app => {
                     stage_total,
                     hadMap,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.tender.tenderInfo),
+                    gclChapter,
                 };
                 if (ctx.session.sessionUser.is_admin) {
                     renderData.tourists = await ctx.service.tenderTourist.getTourists(tender.id);
@@ -1202,7 +1206,6 @@ module.exports = app => {
                         throw '数据错误';
                 }
             } catch (err) {
-                console.log(err);
                 this.log(err);
                 this.ajaxErrorBody(err, '导入数据失败');
             }

+ 106 - 0
app/lib/tender_info.js

@@ -0,0 +1,106 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const auditConst = require('../const/audit');
+
+class TenderInfo {
+    constructor (ctx) {
+        if (!ctx.tender) throw '汇总标段信息错误';
+        this.ctx = ctx;
+        this.tender = this.ctx.tender;
+    }
+
+    async _getValidStages(tenderId) {
+        const stages = await this.ctx.service.stage.db.select(this.ctx.service.stage.tableName, {
+            where: { tid: tenderId },
+            orders: [['order', 'desc']],
+        });
+        if (stages.length !== 0) {
+            const lastStage = stages[0];
+            if (lastStage.status === auditConst.stage.status.uncheck && lastStage.user_id !== this.ctx.session.sessionUser.accountId) {
+                stages.splice(0, 1);
+            }
+        }
+        return stages;
+    }
+
+    async _checkStage() {
+        if (this.stage) return;
+        this.stages = await this._getValidStages(this.tender.id);
+        this.stage = this.stages[0];
+        await this.ctx.service.stage.doCheckStage(this.stage);
+    }
+
+    async _getStageBillsData () {
+        const billsData = await this.ctx.service.ledger.getData(this.tender.id);
+        if (this.stage) {
+            const curStage = this.stage.readOnly
+                ? await this.ctx.service.stageBills.getAuditorStageData(this.tender.id, this.stage.id, this.stage.curTimes, this.stage.curOrder)
+                : await this.ctx.service.stageBills.getLastestStageData(this.tender.id, this.stage.id);
+
+            const preStage = this.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.tender, this.stage.order - 1) : [];
+            this.ctx.helper.assignRelaData(billsData, [
+                { data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid' },
+                { data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid' },
+            ]);
+        }
+        return billsData;
+    }
+
+    _getGclChapter() {
+        const gclChapter = [];
+        for (const c of this.ctx.tender.info.chapter) {
+            const cc = { code: c.code, name: c.name, cType: 1 };
+            const filter = '^[\\D]*' + c.code.substr(0, c.code.length - 2) + '[0-9]{2}(-|$)';
+            cc.reg = new RegExp(filter);
+            gclChapter.push(cc);
+        }
+        return gclChapter;
+    }
+
+    _findGclChapter(chapters, data, field) {
+        for (const c of chapters) {
+            if (c.reg && c.reg.test(data[field])) {
+                return c;
+            }
+        }
+        return null;
+    }
+
+    async gatherChapter() {
+        await this._checkStage();
+        const billsData = await this._getStageBillsData();
+        const gclChapter = this._getGclChapter();
+        for (const b of billsData) {
+            if (!b.b_code || !b.is_leaf) continue;
+            const chapter = this._findGclChapter(gclChapter, b, 'b_code');
+            if (!chapter) continue;
+            chapter.total_price = this.ctx.helper.add(chapter.total_price, b.total_price);
+            chapter.contract_tp = this.ctx.helper.add(chapter.contract_tp, b.contract_tp);
+            chapter.qc_tp = this.ctx.helper.add(chapter.qc_tp, b.qc_tp);
+            chapter.pre_contract_tp = this.ctx.helper.add(chapter.pre_contract_tp, b.pre_contract_tp);
+            chapter.pre_qc_tp = this.ctx.helper.add(chapter.pre_qc_tp, b.pre_qc_tp);
+        }
+        for (const c of gclChapter) {
+            if (!c.total_price) c.total_price = 0;
+            if (!c.contract_tp) c.contract_tp = 0;
+            if (!c.qc_tp) c.qc_tp = 0;
+            if (!c.pre_contract_tp) c.pre_contract_tp = 0;
+            if (!c.pre_qc_tp) c.pre_qc_tp = 0;
+            c.end_contract_tp = this.ctx.helper.add(c.pre_contract_tp, c.contract_tp);
+            c.end_qc_tp = this.ctx.helper.add(c.pre_qc_tp, c.qc_tp);
+            c.end_gather_tp = this.ctx.helper.add(c.end_qc_tp, c.end_contract_tp);
+            delete c.reg;
+        }
+        return gclChapter;
+    }
+}
+
+module.exports = TenderInfo;