Selaa lähdekoodia

提供项目管理-合同树结构数据

MaiXinRong 1 vuosi sitten
vanhempi
commit
1e499b02b7
2 muutettua tiedostoa jossa 39 lisäystä ja 3 poistoa
  1. 4 0
      app/service/report.js
  2. 35 3
      app/service/report_memory.js

+ 4 - 0
app/service/report.js

@@ -393,6 +393,10 @@ module.exports = app => {
                             runnableRst.push(service.reportMemory.getPmDeal());
                             runnableKey.push(filter);
                             break;
+                        case 'mem_pm_deal_pay_tree':
+                            runnableRst.push(service.reportMemory.getPmDealTree());
+                            runnableKey.push(filter);
+                            break;
                         case 'mem_schedule_month':
                             runnableRst.push(service.scheduleMonth.getReportData(params.tender_id));
                             runnableKey.push(filter);

+ 35 - 3
app/service/report_memory.js

@@ -1471,9 +1471,11 @@ module.exports = app => {
             let result = [];
             if (!PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission)) return result;
 
-            const selects = await this.ctx.service.project.getPmDealCache(this.ctx.session.sessionProject.id);
-            const pm = require('../lib/pm');
-            this.pmDeal = await pm.dealData(this.ctx, this.ctx.session.sessionProject.code, selects);
+            if (!this.pmDeal) {
+                const selects = await this.ctx.service.project.getPmDealCache(this.ctx.session.sessionProject.id);
+                const pm = require('../lib/pm');
+                this.pmDeal = await pm.dealData(this.ctx, this.ctx.session.sessionProject.code, selects);
+            }
 
             result = this.pmDeal.contracts ? this.pmDeal.contracts.filter(x => { return x.ContractsType === 2 }) : [];
             const fields = ['Code', 'Name', 'ContractName', 'ContractCode', 'ContractPrice', 'ContractReturned', 'ContractsPaid', 'ContractStatus', 'ContractLocking', 'CreateTime'], self = this;
@@ -1496,6 +1498,36 @@ module.exports = app => {
             });
             return result;
         }
+
+        async getPmDealTree() {
+            const result = [];
+            if (!PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission)) return result;
+
+            if (!this.pmDeal) {
+                const selects = await this.ctx.service.project.getPmDealCache(this.ctx.session.sessionProject.id);
+                const pm = require('../lib/pm');
+                this.pmDeal = await pm.dealData(this.ctx, this.ctx.session.sessionProject.code, selects);
+            }
+
+            for (const tc of this.pmDeal.tree_contracts) {
+                tc.children = this.pmDeal.tree_contracts.filter(x => { return x.ParentId === tc.TreeId})
+            }
+            const root = this.pmDeal.tree_contracts.filter(x => { return x.Depth === 0});
+            root.sort((x, y) => {
+                const type = x.TreeType - y.TreeType;
+                return type ? type : x.Serail - y.Serail;
+            });
+            const sortChildren = function (children, data) {
+                if (!children || children.length === 0) return;
+                for (const c of children) {
+                    data.push(c);
+                    sortChildren(c.children, data);
+                }
+            };
+            sortChildren(root, result);
+            result.forEach(x => { delete x.children });
+            return result;
+        }
     }
 
     return ReportMemory;