Browse Source

报表,新增数据

MaiXinRong 3 years ago
parent
commit
e26c4740b1
2 changed files with 80 additions and 13 deletions
  1. 12 8
      app/service/report.js
  2. 68 5
      app/service/report_memory.js

+ 12 - 8
app/service/report.js

@@ -246,14 +246,6 @@ module.exports = app => {
                             runnableRst.push(service.stageRelaImBills.getAllDataByCondition({ where: { tid: params.tender_id, sid: params.stage_id } }));
                             runnableKey.push(filter);
                             break;
-                        case 'mem_change_apply':
-                            runnableRst.push(service.reportMemory.getChangeApplyData(params.tender_id));
-                            runnableKey.push(filter);
-                            break;
-                        case 'mem_change_project':
-                            runnableRst.push(service.reportMemory.getChangeProjectData(params.tender_id));
-                            runnableKey.push(filter);
-                            break;
                         default:
                             break;
                     }
@@ -286,6 +278,18 @@ module.exports = app => {
                     case 'mem_change_audit':
                         rst[filter] = await service.reportMemory.getChangeAuditData(params.tender_id, params.stage_id, memFieldKeys[filter]);
                         break;
+                    case 'mem_change_apply':
+                        rst[filter] = await service.reportMemory.getChangeApplyData(params.tender_id);
+                        break;
+                    case 'mem_change_apply_audit':
+                        rst[filter] = await service.reportMemory.getChangeApplyAuditData(params.tender_id);
+                        break;
+                    case 'mem_change_project':
+                        rst[filter] = await service.reportMemory.getChangeProjectData(params.tender_id);
+                        break;
+                    case 'mem_change_project_audit':
+                        rst[filter] = await service.reportMemory.getChangeProjectAuditData(params.tender_id);
+                        break;
                     case 'mem_jh_im_change':
                         const jhHelper1 = new rptCustomData.jhHelper(this.ctx);
                         rst[filter] = await jhHelper1.convert(params.tender_id, params.stage_id, memFieldKeys[filter], customDefine.option);

+ 68 - 5
app/service/report_memory.js

@@ -81,6 +81,8 @@ module.exports = app => {
             // 需要缓存的数据
             this.stageImData = null;
             this.changeData = null;
+            this.changeApplyData = null;
+            this.changeProjectData = null;
             this.stageValidRole = [];
         }
 
@@ -790,7 +792,6 @@ module.exports = app => {
                 throw err;
                 this.changeData = {change: [], bills: []};
             }
-
         }
 
         async _generateChangeAudit() {
@@ -837,16 +838,78 @@ module.exports = app => {
             }
         }
 
-        async getChangeApplyData(tid, sid, fields) {
+        async _generateChangeApply(tid) {
+            if (!!this.changeApplyData) return;
             const where = { tid };
             if (this.ctx.session.sessionProject.page_show.isOnlyChecked) where.status = audit.changeApply.status.checked;
-            return await this.ctx.service.changeApply.getAllDataByCondition({ where });
+            this.changeApplyData.data = await this.ctx.service.changeApply.getAllDataByCondition({ where });
         }
 
-        async getChangeProjectData(tid, sid, fields) {
+        async _generateChangeApplyAudit() {
+            if (!!this.changeApplyData.audit) return;
+
+            this.changeApplyData.audit = [];
+            for (const c of this.changeApplyData.data) {
+                const changeAudit = await this.ctx.service.changeApplyAudit.getAllDataByCondition({ where: { caid: c.id, times: c.times }});
+                const changeAuditFilter = this.ctx.helper.filterLastestData(changeAudit, ['aid']);
+                this.changeData.audit.push(...changeAuditFilter);
+            }
+        }
+
+        async getChangeApplyData(tid, sid, fields) {
+            try {
+                await this._generateChangeApply(tid);
+                return this.changeApplyData.data;
+            } catch (err) {
+                return [];
+            }
+        }
+
+        async _generateChangeProject(tid) {
+            if (!!this.changeProjectData) return;
             const where = { tid };
             if (this.ctx.session.sessionProject.page_show.isOnlyChecked) where.status = audit.changeProject.status.checked;
-            return await this.ctx.service.changeProject.getAllDataByCondition({ where });
+            this.changeProjectData.data = await this.ctx.service.changeProject.getAllDataByCondition({ where });
+        }
+
+        async getChangeApplyAuditData(tid, sid, fields) {
+            try {
+                await this._generateChangeApply(tid);
+                await this._generateChangeApplyAudit();
+                return this.changeApplyData.audit;
+            } catch (err) {
+                return [];
+            }
+        }
+
+        async _generateChangeProjectAudit() {
+            if (!!this.changeProjectData.audit) return;
+
+            this.changeProjectData.audit = [];
+            for (const c of this.changeProjectData.data) {
+                const changeAudit = await this.ctx.service.changeProjectAudit.getAllDataByCondition({ where: { cpid: c.id, times: c.times }});
+                const changeAuditFilter = this.ctx.helper.filterLastestData(changeAudit, ['aid']);
+                this.changeData.audit.push(...changeAuditFilter);
+            }
+        }
+
+        async getChangeProjectData(tid, sid, fields) {
+            try {
+                await this._generateChangeProject(tid);
+                return this.changeProjectData.data;
+            } catch (err) {
+                return [];
+            }
+        }
+
+        async getChangeProjectAuditData(tid, sid, fields) {
+            try {
+                await this._generateChangeProject(tid);
+                await this._generateChangeProjectAudit();
+                return this.changeProjectData.audit;
+            } catch (err) {
+                return [];
+            }
         }
 
         async getStageJgcl(tid, sid, fields) {