浏览代码

从项目管理系统,获取标段列表、合同详情等数据

MaiXinRong 2 年之前
父节点
当前提交
86298b31de
共有 5 个文件被更改,包括 120 次插入1 次删除
  1. 3 1
      app/controller/tender_controller.js
  2. 63 0
      app/lib/pm.js
  3. 4 0
      app/service/report.js
  4. 23 0
      app/service/report_memory.js
  5. 27 0
      test/app/lib/pm.test.js

+ 3 - 1
app/controller/tender_controller.js

@@ -1455,6 +1455,7 @@ module.exports = app => {
                                 orders: [['type', 'asc'], ['create_time', 'desc']],
                             });
                             advance.forEach(x => {
+                                x.orderStr = `第${x.order}期`;
                                 x.statusStr = auditConst.advance.statusString[x.status];
                                 x.typeStr = advanceConst.typeColMap[x.type].text;
                             });
@@ -1464,7 +1465,8 @@ module.exports = app => {
                             if (accountPermission.PermissionCheck.viewPmData(this.ctx.session.sessionUser.permission)) {
                                 const selects = await this.ctx.service.project.getPmDealCache(this.ctx.session.sessionProject.id);
                                 // todo 接入项目管理系统
-                                const tenders = [ {id: 1, name: 'A标'}, {id: 2, name: 'B标'}, {id: 3, name: 'C标'}];
+                                const pm = require('../lib/pm');
+                                const tenders = await pm.dealCatagory(ctx, this.ctx.session.sessionProject.code);
                                 tenders.forEach(x => {
                                     x.selected = selects.indexOf(x.id + '') >= 0;
                                 });

+ 63 - 0
app/lib/pm.js

@@ -0,0 +1,63 @@
+'use strict';
+
+/**
+ * 标准库std 相关接口
+ *
+ * @author Mai
+ * @date 2020/3/15
+ * @version
+ */
+
+// 加密类
+const jwt = require('jsonwebtoken');
+const privateKey = 'jl2pm3850key888sc';
+// todo 修改请求链接
+const dealCatagoryApi = '/api/external/jlbb/folder';
+const dealDataApi = '/api/external/jlbb/folder';
+
+const pmUtils = {
+    getJwt() {
+        // todo jwt加密
+        return jwt.sign({}, privateKey, {expiresIn: '5s', algorithm: 'HS256'});
+    },
+    async postData(ctx, url, data) {
+        const res = await ctx.curl(url, {
+            method: 'GET', //'POST',
+            contentType: 'json',
+            data,
+            dataType: 'json',
+            timeout: [2000, 10000],
+            timing: true,
+        });
+        if (res.status !== 200) throw '请求项目管理数据异常';
+        if (!res.data || res.data.err) throw '项目管理返回数据异常';
+        return res.data.data;
+    },
+};
+
+module.exports = {
+    async dealCatagory(ctx, pCode) {
+        // mock
+        // return [ {id: 1, name: 'A标'}, {id: 2, name: 'B标'}, {id: 3, name: 'C标'}];
+        const url = ctx.app.config.managementProxyPath + dealCatagoryApi;
+        try {
+            const data = { code: pCode, token: pmUtils.getJwt() };
+            return await pmUtils.postData(ctx, url, data);
+        } catch (err) {
+            ctx.log(err);
+            return [];
+        }
+    },
+    async dealData(ctx, pCode, selects) {
+        if (!selects || selects.length === 0) return {};
+
+        const url = ctx.app.config.managementProxyPath + dealDataApi;
+        try {
+            const data = { code: pCode, token: pmUtils.getJwt(), key: ['contracts'], bidsection_id: selects };
+            return await pmUtils.postData(ctx, url, data);
+        } catch (err) {
+            ctx.log(err);
+            return {};
+        }
+    }
+};

+ 4 - 0
app/service/report.js

@@ -292,6 +292,10 @@ module.exports = app => {
                             runnableRst.push(params.budget_id ? budgetSource.budgetFinal(params.budget_id) : budgetSource.tenderFinal(params.tender_id));
                             runnableKey.push(filter);
                             break;
+                        case 'mem_pm_deal':
+                            runnableRst.push(service.reportMemory.getPmDeal());
+                            runnableKey.push(filter);
+                            break;
                         default:
                             break;
                     }

+ 23 - 0
app/service/report_memory.js

@@ -21,6 +21,7 @@ const stageImTz = 'mem_stage_im_tz';
 const stageImTzBills = 'mem_stage_im_tz_bills';
 const stageImZl = 'mem_stage_im_zl';
 const stageImVersion = '1.3';
+const PermissionCheck = require('../const/account_permission').PermissionCheck;
 
 const Ledger = require('../lib/ledger');
 
@@ -1350,6 +1351,28 @@ module.exports = app => {
             }
             return this.changeInfoBills;
         }
+
+        async getPmDeal() {
+            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 = pm.dealData(this.ctx, this.ctx.session.sessionProject.code, selects);
+
+            result = this.pmDeal.contracts.filter(x => { return x.contracts_type === 2 });
+            // 排序:标段-合同类别-创建时间
+            result.sort((x, y) => {
+                const bidSort = selects.indexOf(x.bidsection_id + '') - selects.indexOf(y.bidsection_id + '');
+                if (bidSort) return bidSort;
+
+                const typeSort = x.contracts_type - y.contracts_type;
+                if (typeSort) return typeSort;
+
+                return x.create_time - y.create_time;
+            });
+            return result;
+        }
     }
 
     return ReportMemory;

+ 27 - 0
test/app/lib/pm.test.js

@@ -0,0 +1,27 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const { app, assert } = require('egg-mock/bootstrap');
+const pm = require('../../../app/lib/pm.js');
+
+describe('test/app/lib/pm.test.js', () => {
+    it('test pm', function* () {
+        const ctx = app.mockContext();
+        // 模拟登录
+        const postData = {
+            account: '734406061@qq.com',
+            project: 'T201711273363',
+            project_password: 'mai654321',
+        };
+        const result = yield pm.dealCatagory(ctx, postData.project);
+        assert(!!result);
+    });
+
+});