Browse Source

标段管理页面,优化显示,在其他页面缓存部分数据

MaiXinRong 5 năm trước cách đây
mục cha
commit
cb5ee93c36

+ 18 - 0
app/controller/stage_controller.js

@@ -256,6 +256,7 @@ module.exports = app => {
                     }
                 }
                 await ctx.service.stage.updateCheckDetailFlag(ctx.stage.id, true);
+                await ctx.service.stage.updateCheckCalcFlag(ctx.stage.id, true);
                 ctx.body = responseData;
             } catch (err) {
                 this.log(err);
@@ -303,6 +304,7 @@ module.exports = app => {
                     result = await ctx.service.stageChange.billsChange(data.target.bills, data.change);
                 }
                 await ctx.service.stage.updateCheckDetailFlag(ctx.stage.id, true);
+                await ctx.service.stage.updateCheckCalcFlag(ctx.stage.id, true);
                 ctx.body = {err: 0, msg: '', data: result};
             } catch(err) {
                 this.log(err);
@@ -610,6 +612,12 @@ module.exports = app => {
                         await ctx.service.pay.del(data.id);
                         responseData.data = await ctx.service.stagePay.getStagePays(ctx.stage);
                         await payCalculator.calculate(responseData.data);
+                        await this.ctx.service.stage.update({
+                            id: this.ctx.stage.id, check_calc: false,
+                            contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
+                            yf: payCalculator.yf.tp,
+                        });
+
                         break;
                     case 'changeOrder':
                         responseData.data = await ctx.service.pay.changeOrder(data.id1, data.id2);
@@ -620,6 +628,11 @@ module.exports = app => {
                         if (bReCalc) {
                             responseData.data = await ctx.service.stagePay.getStagePays(ctx.stage);
                             await payCalculator.calculateAll(responseData.data);
+                            await this.ctx.service.stage.update({
+                                id: this.ctx.stage.id, check_calc: false,
+                                contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
+                                yf: payCalculator.yf.tp,
+                            });
                         } else {
                             if (data.updateData instanceof Array) {
                                 responseData.data = await ctx.service.stagePay.getStagePay(ctx.stage, this.app._.map(responseData.data, 'id'));
@@ -632,6 +645,11 @@ module.exports = app => {
                         await ctx.service.stagePay.save(data.updateData);
                         responseData.data = await ctx.service.stagePay.getStagePays(ctx.stage);
                         await payCalculator.calculateAll(responseData.data);
+                        await this.ctx.service.stage.update({
+                            id: this.ctx.stage.id, check_calc: false,
+                            contract_tp: payCalculator.cur.contract_tp, qc_tp: payCalculator.cur.qc_tp,
+                            yf: payCalculator.yf.tp,
+                        });
                         break;
                 }
 

+ 1 - 2
app/controller/tender_controller.js

@@ -38,6 +38,7 @@ module.exports = app => {
                 const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
 
                 const tenderList = await this.ctx.service.tender.getList('', userPermission);
+
                 for (const t of tenderList) {
                     if (t.user_id === this.ctx.session.sessionUser.accountId && (
                         t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck)) {
@@ -67,7 +68,6 @@ module.exports = app => {
                 };
                 await this.layout(view, renderData, modal);
             } catch (err) {
-                console.log(err);
                 this.log(err);
                 this.ctx.redirect('/dashboard');
             }
@@ -152,7 +152,6 @@ module.exports = app => {
                 if (userPermission === null || userPermission.tender === undefined || userPermission.tender.indexOf('1') === -1) {
                     throw '当前用户没有创建标段的权限';
                 }
-                console.log(ctx.request.body.data);
                 const data = JSON.parse(ctx.request.body.data);
                 if (!data.name || data.name === '' || !data.valuation) {
                     throw '标段信息不完整';

+ 34 - 29
app/lib/pay_calc.js

@@ -20,6 +20,12 @@ class PayCalculate {
         this.percentReg = /[0-9]+%/g;
         this.tenderInfo = tenderInfo;
         this.decimal = tenderInfo.decimal.pay ? tenderInfo.decimal.payTp : tenderInfo.decimal.tp;
+        /* 以下变量在调用calculate方法后获得
+        this.add;
+        this.pre;
+        this.cur;
+        this.yf;
+         */
     }
 
     /**
@@ -42,11 +48,11 @@ class PayCalculate {
         }
     }
 
-    calculateTpExpr(pay, addRela) {
+    _calculateTpExpr(pay) {
         let formula = pay.expr;
         for (const b of this.bases) {
             if ((b.code === 'bqwc') && (!pay.pre_used && pay.sprice)) {
-                formula = formula.replace(b.reg, this.ctx.helper.sub(addRela.gather_tp, pay.sprice));
+                formula = formula.replace(b.reg, this.ctx.helper.sub(this.add.gather_tp, pay.sprice));
             } else {
                 formula = formula.replace(b.reg, b.value);
             }
@@ -66,7 +72,7 @@ class PayCalculate {
         }
     }
 
-    calculateExpr(expr) {
+    _calculateExpr(expr) {
         let formula = expr;
         for (const b of this.bases) {
             formula = formula.replace(b.reg, b.value);
@@ -99,12 +105,12 @@ class PayCalculate {
             if (p.csorder === this.stage.order || (p.csorder === 0 || this.stage.order === 1)) {
                 if (p.csaorder === order) {
                     if (!p.sprice && p.sexpr && p.sexpr !== '') {
-                        p.sprice = this.ctx.helper.round(this.calculateExpr(p.sexpr), this.decimal);
+                        p.sprice = this.ctx.helper.round(this._calculateExpr(p.sexpr), this.decimal);
                     } else if (p.sprice && !p.sexpr) {
                         p.sprice = this.ctx.helper.round(p.sprice, this.decimal);
                     }
                     if (!p.rprice && p.rexpr && p.rexpr !== '') {
-                        p.rprice = this.ctx.helper.round(this.calculateExpr(p.rexpr), this.decimal);
+                        p.rprice = this.ctx.helper.round(this._calculateExpr(p.rexpr), this.decimal);
                     } else if (p.rprice && !p.rexpr) {
                         p.rprice = this.ctx.helper.round(p.rprice, this.decimal);
                     }
@@ -116,29 +122,28 @@ class PayCalculate {
     /**
      * 累计 计量等数据
      */
-    async getAddCalcRela() {
+    async _getAddCalcRela() {
         // todo 获取截止上期数据
-        const pre = this.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getSumTotalPrice(this.stage.tid, this.stage.order - 1) : null;
-        const cur = await this.ctx.service.stageBills.getSumTotalPrice(this.stage);
-        const add = {};
-        if (pre) {
-            add.contract_tp = this.ctx.helper.add(pre.contract_tp, cur.contract_tp);
-            add.qc_tp = this.ctx.helper.add(pre.qc_tp, cur.qc_tp);
+        this.pre = this.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getSumTotalPrice(this.stage.tid, this.stage.order - 1) : null;
+        this.cur = await this.ctx.service.stageBills.getSumTotalPrice(this.stage);
+        this.add = {};
+        if (this.pre) {
+            this.add.contract_tp = this.ctx.helper.add(this.pre.contract_tp, this.cur.contract_tp);
+            this.add.qc_tp = this.ctx.helper.add(this.pre.qc_tp, this.cur.qc_tp);
         } else {
-            add.contract_tp = cur.contract_tp;
-            add.qc_tp = cur.qc_tp;
+            this.add.contract_tp = this.cur.contract_tp;
+            this.add.qc_tp = this.cur.qc_tp;
         }
-        add.gather_tp = this.ctx.helper.add(add.contract_tp, add.qc_tp);
-        return add;
+        this.add.gather_tp = this.ctx.helper.add(this.add.contract_tp, this.add.qc_tp);
     }
 
     /**
      * 检查是否到达 计提期限
      * @param pay
      */
-    checkDeadline(pay, addRela) {
+    _checkDeadline(pay) {
         if (pay.dl_type === deadlineType.tp.value) {
-            const deadlineTp = addRela[pay.dl_tp_type + '_tp'];
+            const deadlineTp = this.add[pay.dl_tp_type + '_tp'];
             if (deadlineTp > pay.dl_tp) {
                 return true;
             }
@@ -155,19 +160,19 @@ class PayCalculate {
      */
     async calculate(pays) {
         await this.getCalcBase();
-        const yfPay = pays.find(function (p) {
+        this.yf = pays.find(function (p) {
             return p.ptype === payType.yf;
         });
-        const addRela = await this.getAddCalcRela();
-        if (!yfPay) return false;
-        yfPay.tp = 0;
+        if (!this.yf) return false;
+        await this._getAddCalcRela();
+        this.yf.tp = 0;
         for (const p of pays) {
             if (p.ptype === payType.normal || p.ptype === payType.wc) {
-                if (!p.pause && (!p.sprice || addRela.gather_tp >= p.sprice)) {
+                if (!p.pause && (!p.sprice || this.add.gather_tp >= p.sprice)) {
                     if (p.expr && p.expr !== '') {
-                        const value = this.ctx.helper.round(this.calculateTpExpr(p, addRela), this.decimal);
+                        const value = this.ctx.helper.round(this._calculateTpExpr(p), this.decimal);
                         if (p.rprice) {
-                            if (this.checkDeadline(p, addRela)) {
+                            if (this._checkDeadline(p)) {
                                 p.tp = this.ctx.helper.sub(p.rprice, p.pre_tp);
                             } else {
                                 p.tp = Math.min(this.ctx.helper.sub(p.rprice, p.pre_tp), value);
@@ -177,7 +182,7 @@ class PayCalculate {
                         }
                     } else if (p.tp && !this.ctx.helper.checkZero(p.tp)) {
                         if (p.rprice) {
-                            if (this.checkDeadline(p, addRela)) {
+                            if (this._checkDeadline(p)) {
                                 p.tp = this.ctx.helper.sub(p.rprice, p.pre_tp);
                             } else {
                                 p.tp = Math.min(this.ctx.helper.sub(p.rprice, p.pre_tp), this.ctx.helper.round(p.tp, this.decimal));
@@ -192,15 +197,15 @@ class PayCalculate {
                 // 累加 至 应付
                 if (p.is_yf) {
                     if (p.minus) {
-                        yfPay.tp = this.ctx.helper.sub(yfPay.tp, p.tp);
+                        this.yf.tp = this.ctx.helper.sub(this.yf.tp, p.tp);
                     } else {
-                        yfPay.tp = this.ctx.helper.add(yfPay.tp, p.tp);
+                        this.yf.tp = this.ctx.helper.add(this.yf.tp, p.tp);
                     }
                 }
             }
             p.end_tp = this.ctx.helper.round(this.ctx.helper.add(p.tp, p.pre_tp), this.decimal);
         }
-        yfPay.end_tp = this.ctx.helper.add(yfPay.tp, yfPay.pre_tp);
+        this.yf.end_tp = this.ctx.helper.add(this.yf.tp, this.yf.pre_tp);
     }
 
     async calculateAll(pays) {

+ 2 - 2
app/service/ledger.js

@@ -751,7 +751,7 @@ module.exports = app => {
          * @returns {Promise<void>}
          * @private
          */
-        async _calcNode(node, transaction) {
+        async calcNode(node, transaction) {
             const info = this.ctx.tender.info;
             const precision = this.ctx.helper.findPrecision(info.precision, node.unit);
 
@@ -781,7 +781,7 @@ module.exports = app => {
             if (!node) {
                 throw '数据错误';
             }
-            await this._calcNode(node, transaction);
+            await this.calcNode(node, transaction);
         }
 
         async _importCacheTreeNodes(transaction, nodes) {

+ 7 - 2
app/service/stage.js

@@ -77,7 +77,6 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async getValidStagesShort(tenderId) {
-            // console.log('tenderId: ' + tenderId);
             const sql = 'select * from zh_stage where tid = ? order by zh_stage.order';
             const sqlParam = [tenderId];
             return await this.db.query(sql, sqlParam);
@@ -96,7 +95,7 @@ module.exports = app => {
 
         async checkStageGatherData(stage) {
             // 最新一期计量(未审批完成),当前操作人的期详细数据,应实时计算
-            if (stage.status !== auditConst.status.checked) {
+            if (stage.status !== auditConst.status.checked && stage.check_calc) {
                 const curAuditor = await this.ctx.service.stageAudit.getCurAuditor(stage.id, stage.times);
                 const isActive = curAuditor ? curAuditor.id === this.ctx.session.sessionUser.accountId : stage.user_id === this.ctx.session.sessionUser.accountId;
                 stage.curTimes = stage.status === auditConst.status.checkNo ? stage.times - 1 : stage.times;
@@ -178,6 +177,7 @@ module.exports = app => {
                 status: auditConst.status.uncheck,
                 user_id: this.ctx.session.sessionUser.accountId,
                 check_detail: true,
+                check_calc: false,
             };
             if (preStage) {
                 newStage.im_type = preStage.im_type;
@@ -303,6 +303,11 @@ module.exports = app => {
             return result.affectedRows === 1;
         }
 
+        async updateCheckCalcFlag(sid, check) {
+            const result = await this.db.update(this.tableName, {id: sid, check_calc: check});
+            return result.affectedRows === 1;
+        }
+
         /**
          * 删除计量期
          *

+ 2 - 1
app/service/stage_audit.js

@@ -185,7 +185,7 @@ module.exports = app => {
             try {
                 await transaction.update(this.tableName, {id: audit.id, status: auditConst.status.checking, begin_time: new Date()});
                 // 计算原报最终数据
-                await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
+                const yfPay = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
                 // 复制一份下一审核人数据
                 await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, 1, transaction);
                 // 更新期数据
@@ -194,6 +194,7 @@ module.exports = app => {
                     id: stageId, status: auditConst.status.checking,
                     contract_tp: tpData.contract_tp,
                     qc_tp: tpData.qc_tp,
+                    yf_tp: yfPay.tp,
                 });
 
                 // 添加短信通知-需要审批提醒功能