소스 검색

1. 权限问题
2. 数据预处理,数据过滤,允许配置'or'

MaiXinRong 5 년 전
부모
커밋
631d1e3efb
4개의 변경된 파일54개의 추가작업 그리고 10개의 파일을 삭제
  1. 26 9
      app/lib/rpt_data_analysis.js
  2. 4 1
      app/middleware/tender_check.js
  3. 9 0
      app/service/stage_audit.js
  4. 15 0
      test/app/lib/rpt_data_analysis.test.js

+ 26 - 9
app/lib/rpt_data_analysis.js

@@ -585,10 +585,11 @@ const filter = {
     defaultSetting: {
         "table": "pay",
         "condition": [
-            {"field": "minus", "type": "bool", "value": "false"},
-            {"field": "ptype", "type": "num", "operate": "=", "value": 1},
-            {"field": "name", "type": "str", "operate": "=", "value": "扣回"}
+            {"field": "minus", "type": "bool", "value": "false", },
+            {"field": "ptype", "type": "num", "operate": "=", "value": 1, "rela": "and"},
+            {"field": "name", "type": "str", "operate": "=", "value": "扣回", "rela": "or"}
         ],
+        "f_type": "or'",
     },
     _typeFun: {
         bool: '_checkBoolean',
@@ -636,7 +637,7 @@ const filter = {
                 return true;
         }
     },
-    fun: function (ctx, data, fields, options) {
+    fun: function (ctx, data, fields, options, print = false) {
         if (!options || !options.table || !options.condition) return;
 
         const fData = data[options.table], self = this;
@@ -645,13 +646,29 @@ const filter = {
             c.fun = this._typeFun[c.type];
         }
 
-        const result = fData.filter(function (d) {
-            for (const c of options.condition) {
-                if (!self[c.fun](ctx, d[c.field], c)) return false;
+        data[options.table] = fData.filter(function (d) {
+            if (print) console.log(d);
+            if (options.condition.length > 0) {
+                let con = options.condition[0];
+                let result = self[con.fun](ctx, d[con.field], con);
+                if (print) console.log(con, result);
+                for (let i = 1, iLen = options.condition.length; i < iLen; i++) {
+                    con = options.condition[i];
+                    result = (con.rela && con.rela === 'or')
+                        ? (result || self[con.fun](ctx, d[con.field], con))
+                        : (result && self[con.fun](ctx, d[con.field], con));
+                    if (print) console.log(con, self[con.fun](ctx, d[con.field], con), result);
+                }
+                return result;
+            } else {
+                return true;
             }
-            return true;
+            // const result;
+            // for (const c of options.condition) {
+            //     if (!self[c.fun](ctx, d[c.field], c)) return false;
+            // }
+            // return true;
         });
-        data[options.table] = result;
     }
 };
 const gatherStagePay = {

+ 4 - 1
app/middleware/tender_check.js

@@ -54,9 +54,12 @@ module.exports = options => {
                     const times = tender.data.ledger_status === auditConst.status.checkNo ? tender.data.ledger_times - 1 : tender.data.ledger_times;
                     const auditors = yield this.service.ledgerAudit.getAuditors(tender.id, times);
                     const auditorsId = this.helper._.map(auditors, 'audit_id');
+                    const stageAuditors = yield this.service.stageAudit.getAllAuditors(tender.id);
+                    const stageAUditorsId = this.helper._.map(stageAuditors, 'aid');
                     const tenderPermission = this.session.sessionUser.permission ? this.session.sessionUser.permission.tender : null;
                     if (auditorsId.indexOf(accountId) === -1 && tender.data.user_id !== accountId &&
-                        (tenderPermission === null || tenderPermission === undefined || tenderPermission.indexOf('2') === -1)) {
+                        (tenderPermission === null || tenderPermission === undefined || tenderPermission.indexOf('2') === -1) &&
+                        stageAUditorsId.indexOf(accountId) === -1) {
                         throw '您无权查看该项目';
                     }
                 }

+ 9 - 0
app/service/stage_audit.js

@@ -64,6 +64,15 @@ module.exports = app => {
             return result;
         }
 
+        async getAllAuditors(tenderId) {
+            const sql = 'SELECT sa.aid, sa.tid FROM ' + this.tableName + ' sa' +
+                '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On sa.tid = t.id' +
+                '  WHERE t.id = ?' +
+                '  GROUP BY  sa.aid';
+            const sqlParam = [tenderId];
+            return this.db.query(sql, sqlParam);
+        }
+
         /**
          * 获取标段审核人最后一位的名称
          *

+ 15 - 0
test/app/lib/rpt_data_analysis.test.js

@@ -395,6 +395,21 @@ describe('test/app/service/report_memory.test.js', () => {
         reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m1);
         result = ctx.helper._.map(data.test, 'order');
         assert(ctx.helper._.isEqual(result, [8]));
+
+        // mix2
+
+        const m2 = {
+            table: 'test',
+            condition: [
+                { field: "c", type: "bool", value: 'true'},
+                { field: "b", type: "num", operate: 'non-zero', rela: "or"},
+                { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd'], rela: "and"},
+            ],
+        };
+        data = JSON.parse(JSON.stringify(orgData));
+        reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m2, true);
+        result = ctx.helper._.map(data.test, 'order');
+        assert(ctx.helper._.isEqual(result, [1, 2, 3, 8]));
     });
     // it('test gatherChapter custom', function* () {
     //     const ctx = app.mockContext(mockData);