ソースを参照

rpt_data_analysis.js调整

MaiXinRong 5 年 前
コミット
8d48f2d7a7
2 ファイル変更40 行追加7 行削除
  1. 24 4
      app/lib/rpt_data_analysis.js
  2. 16 3
      test/app/lib/rpt_data_analysis.test.js

+ 24 - 4
app/lib/rpt_data_analysis.js

@@ -10,14 +10,15 @@
 
 const changeSort = {
     name: '变更令排序',
-    hint: '默认的变更令排序,同时对变更令,变更清单进行排序',
+    hint: '默认的变更令排序,同时对变更令,变更清单进行排序\n' +
+        '变更令排序勿需勾选任何预定义处理指标,但是在指标映射中,要添加"变更令(change)"和"变更清单(chang_audit_list)"下的指标',
     /**
      *
      * @param ctx - context常量
      * @param data - 全部数据源{Array}
      * @param fieldsKey - 计算字段
      */
-    fun: function (ctx, data, fieldsKey) {
+    fun: function(ctx, data, fieldsKey) {
         if (!data.change || !data.change_audit_list) return;
         // 变更令排序
         data.change.sort(function (a, b) {
@@ -143,8 +144,27 @@ const sortGcl = {
     }
 };
 
-module.exports = {
+const analysisObj = {
     changeSort,
     gatherGcl,
-    sortGcl,
+    sortGcl
+};
+const analysisDefine = (function (obj) {
+    const result = [];
+    for (const o in obj) {
+        const analysis = obj[o];
+        if (analysis.name && analysis.hint && analysis.fun) {
+            result.push({
+                name: analysis.name,
+                key: o,
+                hint: analysis.hint,
+            })
+        }
+    }
+    return result;
+})(analysisObj);
+
+module.exports = {
+    analysisObj,
+    analysisDefine
 };

+ 16 - 3
test/app/lib/rpt_data_analysis.test.js

@@ -46,7 +46,7 @@ describe('test/app/service/report_memory.test.js', () => {
         };
         const filters = ['change', 'change_audit_list'];
         const data = yield ctx.service.report.getReportData(params, filters);
-        reportDataAnalysis.changeSort.fun(ctx, data);
+        reportDataAnalysis.analysisObj.changeSort.fun(ctx, data);
         assert(data.change[0].code === 'test7-BG-001');
         assert(data.change[2].code === 'test7-BG-003');
         const changeCid = ctx.helper._.map(data.change, 'cid');
@@ -83,7 +83,7 @@ describe('test/app/service/report_memory.test.js', () => {
             ]
         });
         assert(data.mem_stage_bills.length === 216);
-        reportDataAnalysis.gatherGcl.fun(ctx, data, [
+        reportDataAnalysis.analysisObj.gatherGcl.fun(ctx, data, [
             {field: 'b_code', table: 'mem_stage_bills'},
             {field: 'name', table: 'mem_stage_bills'},
             {field: 'unit', table: 'mem_stage_bills'},
@@ -91,7 +91,7 @@ describe('test/app/service/report_memory.test.js', () => {
             {field: 'is_leaf', table: 'mem_stage_bills'},
         ]);
         assert(data.mem_stage_bills.length === 43);
-        reportDataAnalysis.sortGcl.fun(ctx, data, [
+        reportDataAnalysis.analysisObj.sortGcl.fun(ctx, data, [
             {field: 'b_code', table: 'mem_stage_bills'},
         ]);
         const codeIndex = ctx.helper._.map(data.mem_stage_bills, 'b_code');
@@ -110,4 +110,17 @@ describe('test/app/service/report_memory.test.js', () => {
             assert(a === codeResult[i]);
         });
     });
+    it('test analysisDefine', function() {
+        const define = reportDataAnalysis.analysisDefine;
+        assert(define.length === 3);
+        assert(define[0].key === 'changeSort');
+        assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name);
+        assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint);
+        assert(define[1].key === 'gatherGcl');
+        assert(define[1].name === reportDataAnalysis.analysisObj.gatherGcl.name);
+        assert(define[1].hint === reportDataAnalysis.analysisObj.gatherGcl.hint);
+        assert(define[2].key === 'sortGcl');
+        assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name);
+        assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint);
+    });
 });