Переглянути джерело

调整report_memory中的私有方法_checkTender和_checkStage,以供调用

MaiXinRong 5 роки тому
батько
коміт
319986ca0e
3 змінених файлів з 68 додано та 67 видалено
  1. 6 67
      app/service/report_memory.js
  2. 55 0
      app/service/stage.js
  3. 7 0
      app/service/tender.js

+ 6 - 67
app/service/report_memory.js

@@ -34,67 +34,6 @@ module.exports = app => {
             this.stageImData = null;
         }
 
-        async _checkTender(tid) {
-            if (this.ctx.tender) return;
-            const tender = await this.ctx.service.tender.getTender(tid);
-            tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tid);
-            this.ctx.tender = tender;
-        }
-
-        async _checkStage(sid) {
-            if (!this.ctx.stage) {
-                const status = audit.stage.status;
-                const stage = await this.ctx.service.stage.getDataById(sid);
-                stage.auditors = await this.ctx.service.stageAudit.getAuditors(stage.id, stage.times);
-                stage.curAuditor = await this.ctx.service.stageAudit.getCurAuditor(stage.id, stage.times);
-
-                const accountId = this.ctx.session.sessionUser.accountId, auditorIds = this._.map(stage.auditors, 'aid'), shareIds = [];
-                if (accountId === stage.user_id) { // 原报
-                    if (stage.curAuditor) {
-                        stage.readOnly = stage.curAuditor.aid !== accountId;
-                    } else {
-                        stage.readOnly = stage.status !== status.uncheck && stage.status !== status.checkNo;
-                    }
-                    stage.curTimes = stage.times;
-                    if (stage.status === status.uncheck || stage.status === status.checkNo) {
-                        stage.curOrder = 0;
-                    } else if (stage.status === status.checked) {
-                        stage.curOrder = this._.max(this._.map(stage.auditors, 'order'));
-                    } else {
-                        stage.curOrder = stage.curAuditor.aid === accountId ? stage.curAuditor.order : stage.curAuditor.order - 1;
-                    }
-                } else if (auditorIds.indexOf(accountId) !== -1) { // 审批人
-                    if (stage.status === status.uncheck) {
-                        throw '您无权查看该数据';
-                    }
-                    stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
-                    if (stage.status === status.checked) {
-                        stage.curOrder = this._.max(this._.map(stage.auditors, 'order'));
-                    } else if (stage.status === status.checkNo) {
-                        const audit = await this.service.stageAudit.getDataByCondition({
-                            sid: stage.id, times: stage.times - 1, status: status.checkNo
-                        });
-                        stage.curOrder = audit.order;
-                    } else {
-                        stage.curOrder = accountId === stage.curAuditor.aid ? stage.curAuditor.order : stage.curAuditor.order - 1;
-                    }
-                } else if (shareIds.indexOf(accountId) !== -1) { // 分享人
-                    if (stage.status === status.uncheck) {
-                        throw '您无权查看该数据';
-                    }
-                    stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
-                    stage.curOrder = stage.status === status.checked ? this._.max(this._.map(stage.auditors, 'order')) : stage.curAuditor.order - 1;
-                }
-
-                this.ctx.stage = stage;
-                let time = this.ctx.stage.readOnly ? this.ctx.stage.cache_time_r : this.ctx.stage.cache_time_l;
-                if (!time) {
-                    time = this.ctx.stage.in_time ? this.ctx.stage.in_time : new Date();
-                }
-                this.ctx.stage.cacheTime = time.getTime();//this.ctx.stage.readOnly ? (this.ctx.stage.cache_time_r).getTime(): (this.ctx.stage.cache_time_l).getTime();
-            }
-        }
-
         // build-time: 162-384ms, redis-cache: 0-41ms, mysql + IO: 116-146ms
         // 一定程度上算是大Value缓存,数据多了以后:
         // 1. 达到redis内存阈值时,数据会swap到磁盘,此时将消耗IO时间
@@ -186,8 +125,8 @@ module.exports = app => {
         }
 
         async getStageImTzData(tid, sid) {
-            await this._checkTender(tid);
-            await this._checkStage(sid);
+            await this.ctx.service.tender.checkTender(tid);
+            await this.ctx.service.stage.checkStage(sid);
             const cache = await this._getReportMemoryCache('mem_stage_im_tz', tid, sid, this.ctx.stage.cacheTime);
             if (cache) {
                 // console.log('cache');
@@ -211,8 +150,8 @@ module.exports = app => {
         }
 
         async getStageImTzBillsData(tid, sid) {
-            await this._checkTender(tid);
-            await this._checkStage(sid);
+            await this.ctx.service.tender.checkTender(tid);
+            await this.ctx.service.stage.checkStage(sid);
             const cache = await this._getReportMemoryCache('mem_stage_im_tz_bills', tid, sid, this.ctx.stage.cacheTime);
             if (cache) return cache;
 
@@ -232,8 +171,8 @@ module.exports = app => {
         }
 
         async getStageImZlData(tid, sid) {
-            await this._checkTender(tid);
-            await this._checkStage(sid);
+            await this.ctx.service.tender.checkTender(tid);
+            await this.ctx.service.stage.checkStage(sid);
             const cache = await this._getReportMemoryCache('mem_stage_im_zl', tid, sid, this.ctx.stage.cacheTime);
             if (cache) return cache;
 

+ 55 - 0
app/service/stage.js

@@ -27,6 +27,61 @@ module.exports = app => {
             this.tableName = 'stage';
         }
 
+
+        async checkStage(sid) {
+            if (!this.ctx.stage) {
+                const status = auditConst.status;
+                const stage = await this.ctx.service.stage.getDataById(sid);
+                stage.auditors = await this.ctx.service.stageAudit.getAuditors(stage.id, stage.times);
+                stage.curAuditor = await this.ctx.service.stageAudit.getCurAuditor(stage.id, stage.times);
+
+                const accountId = this.ctx.session.sessionUser.accountId, auditorIds = this._.map(stage.auditors, 'aid'), shareIds = [];
+                if (accountId === stage.user_id) { // 原报
+                    if (stage.curAuditor) {
+                        stage.readOnly = stage.curAuditor.aid !== accountId;
+                    } else {
+                        stage.readOnly = stage.status !== status.uncheck && stage.status !== status.checkNo;
+                    }
+                    stage.curTimes = stage.times;
+                    if (stage.status === status.uncheck || stage.status === status.checkNo) {
+                        stage.curOrder = 0;
+                    } else if (stage.status === status.checked) {
+                        stage.curOrder = this._.max(this._.map(stage.auditors, 'order'));
+                    } else {
+                        stage.curOrder = stage.curAuditor.aid === accountId ? stage.curAuditor.order : stage.curAuditor.order - 1;
+                    }
+                } else if (auditorIds.indexOf(accountId) !== -1) { // 审批人
+                    if (stage.status === status.uncheck) {
+                        throw '您无权查看该数据';
+                    }
+                    stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
+                    if (stage.status === status.checked) {
+                        stage.curOrder = this._.max(this._.map(stage.auditors, 'order'));
+                    } else if (stage.status === status.checkNo) {
+                        const audit = await this.service.stageAudit.getDataByCondition({
+                            sid: stage.id, times: stage.times - 1, status: status.checkNo
+                        });
+                        stage.curOrder = audit.order;
+                    } else {
+                        stage.curOrder = accountId === stage.curAuditor.aid ? stage.curAuditor.order : stage.curAuditor.order - 1;
+                    }
+                } else if (shareIds.indexOf(accountId) !== -1) { // 分享人
+                    if (stage.status === status.uncheck) {
+                        throw '您无权查看该数据';
+                    }
+                    stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
+                    stage.curOrder = stage.status === status.checked ? this._.max(this._.map(stage.auditors, 'order')) : stage.curAuditor.order - 1;
+                }
+
+                this.ctx.stage = stage;
+                let time = this.ctx.stage.readOnly ? this.ctx.stage.cache_time_r : this.ctx.stage.cache_time_l;
+                if (!time) {
+                    time = this.ctx.stage.in_time ? this.ctx.stage.in_time : new Date();
+                }
+                this.ctx.stage.cacheTime = time.getTime();//this.ctx.stage.readOnly ? (this.ctx.stage.cache_time_r).getTime(): (this.ctx.stage.cache_time_l).getTime();
+            }
+        }
+
         /**
          * 获取 最新一期 期计量
          * @param tenderId

+ 7 - 0
app/service/tender.js

@@ -334,6 +334,13 @@ module.exports = app => {
             return result;
         }
 
+        async checkTender(tid) {
+            if (this.ctx.tender) return;
+            const tender = await this.ctx.service.tender.getTender(tid);
+            tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tid);
+            this.ctx.tender = tender;
+        }
+
     }
 
     return Tender;