浏览代码

优化决策大屏加载速度

ellisran 1 年之前
父节点
当前提交
2c236150e0

+ 27 - 19
app/controller/datacollect_controller.js

@@ -102,30 +102,36 @@ module.exports = app => {
                 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;
-                    }
+                    // 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] = await ctx.service.change.getChangeTp(t.id);
                     // t.material_tp = await ctx.service.material.getSumMaterial(t.id);
                     // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
@@ -134,7 +140,9 @@ module.exports = app => {
                     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 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 });

+ 2 - 1
app/service/change_audit.js

@@ -702,7 +702,8 @@ module.exports = app => {
         }
 
         async getNumByMonth(tid, startMonth, endMonth) {
-            const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT b.id FROM (SELECT * FROM ?? WHERE tid = ? AND usite != 0 GROUP BY id ORDER BY usort DESC) as b GROUP BY b.cid) AND status = ? AND sin_time between ? and ?';
+            const sql = 'SELECT COUNT(*) as num FROM ?? t1 JOIN (SELECT MAX(id) as max_id FROM ?? WHERE tid = ? AND usite != 0 GROUP BY id ORDER BY usort DESC) t2 ON t1.id = t2.max_id WHERE t1.status = ? AND t1.sin_time between ? and ?';
+            // const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT b.id FROM (SELECT * FROM ?? WHERE tid = ? AND usite != 0 GROUP BY id ORDER BY usort DESC) as b GROUP BY b.cid) AND status = ? AND sin_time between ? and ?';
             const sqlParam = [this.tableName, this.tableName, tid, auditConst.auditStatus.checked, startMonth, endMonth];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.num : 0;

+ 2 - 1
app/service/material_audit.js

@@ -1016,7 +1016,8 @@ module.exports = app => {
         }
 
         async getNumByMonth(tid, startMonth, endMonth) {
-            const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT MAX(id) FROM ?? WHERE tid = ? GROUP BY mid) AND status = ? AND end_time between ? and ?';
+            const sql = 'SELECT COUNT(*) as num FROM ?? t1 JOIN (SELECT MAX(id) as max_id FROM ?? WHERE tid = ? GROUP BY mid) t2 ON t1.id = t2.max_id WHERE t1.status = ? AND t1.end_time between ? and ?';
+            // const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT MAX(id) FROM ?? WHERE tid = ? GROUP BY mid) AND status = ? AND end_time between ? and ?';
             const sqlParam = [this.tableName, this.tableName, tid, auditConst.status.checked, startMonth, endMonth];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.num : 0;

+ 2 - 1
app/service/revise_audit.js

@@ -858,7 +858,8 @@ module.exports = app => {
         }
 
         async getNumByMonth(tid, startMonth, endMonth) {
-            const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT MAX(id) FROM ?? WHERE tender_id = ? GROUP BY rid) AND status = ? AND end_time between ? and ?';
+            const sql = 'SELECT COUNT(*) as num FROM ?? t1 JOIN (SELECT MAX(id) as max_id FROM ?? WHERE tender_id = ? GROUP BY rid) t2 ON t1.id = t2.max_id WHERE t1.status = ? AND t1.end_time between ? and ?';
+            // const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT MAX(id) FROM ?? WHERE tender_id = ? GROUP BY rid) AND status = ? AND end_time between ? and ?';
             const sqlParam = [this.tableName, this.tableName, tid, auditConst.status.checked, startMonth, endMonth];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.num : 0;

+ 8 - 2
app/service/stage.js

@@ -856,7 +856,7 @@ module.exports = app => {
             return list;
         }
 
-        async getStageByDataCollect(tenderId) {
+        async getStageByDataCollect(tenderId, stage_tp) {
             const stages = await this.db.select(this.tableName, {
                 columns: ['id', 'user_id', 'times', 'status', 's_time', 'contract_tp', 'qc_tp', 'pc_tp', 'pre_contract_tp', 'pre_qc_tp', 'tp_history'],
                 where: { tid: tenderId },
@@ -868,7 +868,13 @@ module.exports = app => {
             // 最新一期计量(未审批完成),取上一个人的期详细数据,应实时计算
             const stage = stages[0];
             if (stages.length === 0) return stages;
-            await this.checkStageGatherDataByDataCollect(stage);
+            // await this.checkStageGatherDataByDataCollect(stage);
+            if (stage.status !== auditConst.stage.status.checked) {
+                // 批量把stage_tp的值赋值给stage
+                _.forEach(stage_tp, function(value, key) {
+                    stage[key] = stage_tp[key] ? stage_tp[key] : null;
+                });
+            }
             for (const s of stages) {
                 s.tp = this.ctx.helper.sum([s.contract_tp, s.qc_tp, s.pc_tp]);
                 s.pre_tp = this.ctx.helper.add(s.pre_contract_tp, s.pre_qc_tp);

+ 2 - 1
app/service/stage_audit.js

@@ -1988,7 +1988,8 @@ module.exports = app => {
         }
 
         async getNumByMonth(tid, startMonth, endMonth) {
-            const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT MAX(id) FROM ?? WHERE tid = ? GROUP BY sid) AND status = ? AND end_time between ? and ?';
+            // const sql = 'SELECT COUNT(*) as num FROM ?? WHERE id in (SELECT MAX(id) FROM ?? WHERE tid = ? GROUP BY sid) AND status = ? AND end_time between ? and ?';
+            const sql = 'SELECT COUNT(*) as num FROM ?? t1 JOIN (SELECT MAX(id) as max_id FROM ?? WHERE tid = ? GROUP BY sid) t2 ON t1.id = t2.max_id WHERE t1.status = ? AND t1.end_time between ? and ?';
             const sqlParam = [this.tableName, this.tableName, tid, auditConst.status.checked, startMonth, endMonth];
             const result = await this.db.queryOne(sql, sqlParam);
             return result ? result.num : 0;

+ 8 - 8
app/view/datacollect/index.ejs

@@ -1595,14 +1595,14 @@
         })
 
         function calculateTender(tender) {
-            if (tender.lastStage) {
-                tender.gather_tp = ZhCalc.sum([tender.lastStage.contract_tp, tender.lastStage.qc_tp, tender.lastStage.pc_tp]);
-                tender.end_contract_tp = ZhCalc.sum([tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp, tender.lastStage.contract_pc_tp]);
-                tender.end_qc_tp = ZhCalc.sum([tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp, tender.lastStage.qc_pc_tp]);
+            if (tender.stage_tp) {
+                tender.gather_tp = ZhCalc.sum([tender.stage_tp.contract_tp, tender.stage_tp.qc_tp, tender.stage_tp.pc_tp]);
+                tender.end_contract_tp = ZhCalc.sum([tender.stage_tp.pre_contract_tp, tender.stage_tp.contract_tp, tender.stage_tp.contract_pc_tp]);
+                tender.end_qc_tp = ZhCalc.sum([tender.stage_tp.pre_qc_tp, tender.stage_tp.qc_tp, tender.stage_tp.qc_pc_tp]);
                 tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
-                tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
-                tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
-                tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
+                tender.pre_gather_tp = ZhCalc.add(tender.stage_tp.pre_contract_tp, tender.stage_tp.pre_qc_tp);
+                tender.yf_tp = ZhCalc.add(tender.stage_tp.yf_tp);
+                tender.end_yf_tp = ZhCalc.add(tender.stage_tp.pre_yf_tp, tender.yf_tp);
             }
         }
 
@@ -1663,7 +1663,7 @@
                 month_material_num = ZhCalc.add(month_material_num, t.month_material_num);
                 html += '<tr>\n' +
                     '                                                    <td><span data-toggle="tooltip" data-placement="right" data-original-title="'+ t.name +'">'+ (t.name.length > 15 ? t.name.substring(0, 15) + '...' : t.name) +'</span></td>\n' +
-                    '                                                    <td>'+ (t.lastStage ? '第' + (t.lastStage ? t.lastStage.order : 0) + '期': '台账' ) + '</td>\n' +
+                    '                                                    <td>'+ (t.progress ? t.progress.title : (t.cur_flow ? t.cur_flow.title : '')) + '</td>\n' +
                     '                                                    <td>'+ (t.total_price ? t.total_price : 0) +'</td>\n' +
                     '                                                    <td>'+ (t.gather_tp ? t.gather_tp : 0) +'</td>\n' +
                     '                                                    <td>'+ (t.end_gather_tp ? t.end_gather_tp : 0) +'</td>\n' +