TonyKang пре 8 година
родитељ
комит
295c34f73d
3 измењених фајлова са 77 додато и 14 уклоњено
  1. 43 0
      modules/reports/util/rpt_data_util.js
  2. 19 6
      public/cache/std_glj_type_util.js
  3. 15 8
      test/public/testStdGljTypes.js

+ 43 - 0
modules/reports/util/rpt_data_util.js

@@ -0,0 +1,43 @@
+/**
+ * Created by Tony on 2017/7/14.
+ * 报表数据提取class,是协助报表模板里指标字段自主提取数据的工具类
+ */
+class Rpt_Common{
+    initialize(Projects) {
+        this.Projects = Projects;
+    };
+};
+
+class Rpt_Data_Extractor {
+    initialize(Projects) {
+        this.Projects = Projects;
+        //Projects对象从前端传送过来,无需在后端重复查询及构建
+        /* 结构:
+         {
+            currentPrjId: int,
+            topPrj: [
+                //单项工程
+                {
+                    subPrjName: String,
+                    subPrjId: int,
+                    detailPrj: [
+                        //单位工程
+                        {
+                            detailPrjName: String,
+                            subPrjId: int,
+                        }
+                        ...
+                    ]
+                }
+                ...
+            ]
+         }
+         */
+    };
+
+    prepare($CURRENT_RPT) {
+        //在报表提取数据前的准备工作,主要有:
+        //1. 确认指标数据的类型,
+    };
+
+}

+ 19 - 6
public/cache/std_glj_type_util.js

@@ -1,13 +1,13 @@
 /**
  * Created by Tony on 2017/7/6.
  */
-let cache = require('./cacheUtil');
+let cacheUtil = require('./cacheUtil');
 let std_glj_type_mdl = require('../models/std_glj_types');
 
 const STD_GLJ_GRP = 'std_glj_grp';
 
 function getStdGljTypeCache() {
-    let rst = cache.getCache(STD_GLJ_GRP,'default');
+    let rst = cacheUtil.getCache(STD_GLJ_GRP,'default');
     return rst;
 };
 
@@ -20,21 +20,23 @@ class StdGljTypeClass{
     build(cache){
         let me = this, rst = {};
         rst.items = [];
-        let private_combine_glj_type = function (item) {
+        let private_combine_glj_type = function (item, topParentId, parentId) {
             let tmpItem = {};
             tmpItem.ID = item.ID;
+            tmpItem.TopParentID = topParentId;
+            tmpItem.ParentID = parentId;
             tmpItem.fullName = item.fullName;
             tmpItem.shortName = item.shortName;
             rst["typeId" + item.ID] = tmpItem;
             rst.items.push(tmpItem);
             if (item.items) {
                 for (let subItem of item.items) {
-                    private_combine_glj_type(subItem);
+                    private_combine_glj_type(subItem, topParentId, item.ID);
                 }
             }
         }
         for (let item of cache.typesDefine) {
-            private_combine_glj_type(item);
+            private_combine_glj_type(item, item.ID, -1);
         }
         me.innerGljTypeObj = rst;
     };
@@ -47,6 +49,17 @@ class StdGljTypeClass{
         return rst;
     };
 
+    getTopParentIdByItemId(itemId) {
+        let me = this, rst = itemId;
+        if (me.innerGljTypeObj) {
+            let item = me.innerGljTypeObj["typeId" + itemId];
+            if (item) {
+                rst = item.TopParentID;
+            }
+        }
+        return rst;
+    };
+
     toArray(){
         let me = this, rst = null;
         return me.innerGljTypeObj.items;
@@ -58,7 +71,7 @@ module.exports = {
     setStdGljTypeCache: function () {
         std_glj_type_mdl.find({typeName: "默认"}, '-_id', function(err, typeObj){
             if(typeObj.length){
-                cache.setCache(STD_GLJ_GRP,'default',typeObj[0]);
+                cacheUtil.setCache(STD_GLJ_GRP,'default',typeObj[0]);
             }
         })
     },

+ 15 - 8
test/public/testStdGljTypes.js

@@ -3,6 +3,8 @@
  */
 
 let test = require('tape');
+let mongoose = require('mongoose');
+
 let stdgljutil = require("../../public/cache/std_glj_type_util");
 
 test('std glj types test1', function(t){
@@ -11,13 +13,18 @@ test('std glj types test1', function(t){
 })
 
 test('std glj types test2', function(t){
-    //stdgljutil.setStdGljTypeCache();
-    let cacheObj = stdgljutil.getStdGljTypeCacheObj();
-    t.equal(cacheObj != null, true);
-    let rgItem = cacheObj.getItemById(1);
-    t.equal(rgItem != null, true);
-    let arr = cacheObj.toArray();
-    t.equal(arr.length, 11);
-    t.end();
+    setTimeout(function(){
+        let cacheObj = stdgljutil.getStdGljTypeCacheObj();
+        t.equal(cacheObj != null, true);
+        let rgItem = cacheObj.getItemById(301);
+        t.equal(rgItem != null, true);
+        let tPId = cacheObj.getTopParentIdByItemId(301);
+        t.equal(tPId, 3);
+        let arr = cacheObj.toArray();
+        t.equal(arr.length, 13);
+        mongoose.disconnect();
+        t.pass('closing db connection');
+        t.end();
+    }, 500);
 })