TonyKang 8 سال پیش
والد
کامیت
be097f0941

+ 4 - 2
config/cacheCfg.js

@@ -1,12 +1,14 @@
 /**
  * Created by Tony on 2017/3/24.
  */
-//var rptUtil = require("../modules/reports/util/rpt_util");
+var rptUtil = require("../modules/reports/util/rpt_util");
+var stdTypesUtil = require("../public/cache/std_glj_type_util");
 //rptUtil.setReportDefaultCache();
 
 module.exports = {
     setupDftCache: function() {
-        //rptUtil.setReportDefaultCache();
+        rptUtil.setReportDefaultCache();
+        stdTypesUtil.setStdGljTypeCache();
         //and others...(if any)
     }
 }

+ 5 - 0
modules/reports/controllers/rpt_tpl_controller.js

@@ -10,6 +10,8 @@ let TreeNodeModel = require('../models/tpl_tree_node');
 let rptTplDef = require("../../../public/rpt_tpl_def").getUtil();
 let stringUtil = require("../../../public/stringUtil");
 
+//let test_glj_type_util = require("../../../public/cache/std_glj_type_util");
+
 //统一回调函数
 let callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
@@ -33,6 +35,9 @@ module.exports = {
                 callback(req,res, true,"", null);
             } else callback(req,res,false,"", data);
         });
+        // let obj = test_glj_type_util.getStdGljTypeCacheObj();
+        // console.log(obj.toArray());
+        // console.log(obj.getItemById(1));
     },
     updateTreeNodes: function(req, res) {
         let params = JSON.parse(req.body.params),

+ 3 - 0
modules/reports/routes/rpt_tpl_router.js

@@ -1,6 +1,7 @@
 let express = require("express");
 let rptTplRouter = express.Router();
 let reportTplController = require('./../controllers/rpt_tpl_controller');
+let reportCfgController = require('./../controllers/rpt_cfg_controller');
 
 rptTplRouter.post('/createTplTreeNode', reportTplController.createTplTreeNode);
 rptTplRouter.post('/getRptTplTree', reportTplController.getRptTplTree);
@@ -9,4 +10,6 @@ rptTplRouter.post('/deleteRptTplNodes', reportTplController.deleteRptTplNodes);
 rptTplRouter.post('/createDftRptTpl', reportTplController.createDftRptTpl);
 rptTplRouter.post('/getRefRptTpl', reportTplController.getRefRptTpl);
 
+rptTplRouter.post('/getUserRptCfg', reportCfgController.getReportUserCfg);
+
 module.exports = rptTplRouter;

+ 29 - 14
modules/reports/util/rpt_util.js

@@ -8,9 +8,9 @@ const RPT_CFG_GRP = 'rpt_cfg';
 
 module.exports = {
     setReportDefaultCache: function () {
-        Rpt_Cfg_Mdl.find({userId: "Administrator"}, '-_id', function(err, templates){
-            if(templates.length){
-                cache.setCache(RPT_CFG_GRP,'admin_cfg',templates[0]);
+        Rpt_Cfg_Mdl.find({userId: "Administrator"}, '-_id', function(err, cfgs){
+            if(cfgs.length){
+                cache.setCache(RPT_CFG_GRP,'admin_cfg',cfgs[0]);
             }
         })
     },
@@ -26,28 +26,43 @@ module.exports = {
     },
     setReportCacheByUser: function (userId) {
         let me = this;
-        Rpt_Cfg_Mdl.find({userId: userId}, '-_id', function(err, templates){
-            if(templates.length){
-                cache.setCache(RPT_CFG_GRP, userId + '_cfg',templates[0]);
-            } else {
-                me.setReportDefaultCache();
-            }
-        })
+        let user_cfg = cache.getCache(RPT_CFG_GRP,userId + '_cfg');
+        if (!(user_cfg)) {
+            Rpt_Cfg_Mdl.find({userId: userId}, '-_id', function(err, cfgs){
+                if(cfgs.length){
+                    cache.setCache(RPT_CFG_GRP, userId + '_cfg',cfgs[0]);
+                } else {
+                    me.setReportDefaultCache();
+                }
+            })
+        }
     },
-    getReportCacheByUser: function (userId) {
+    getReportCacheByUser: function (userId, cb) {
         let me = this,
             rst = {ctrls: null, fonts: null, styles: null},
             user_cfg = cache.getCache(RPT_CFG_GRP,userId + '_cfg');
         ;
         if (!(user_cfg)) {
-            rst = null;
-            rst = me.getReportDefaultCache();
+            Rpt_Cfg_Mdl.find({userId: userId}, '-_id', function(err, cfgs){
+                if(cfgs.length){
+                    cache.setCache(RPT_CFG_GRP, userId + '_cfg',cfgs[0]);
+                    user_cfg = cache.getCache(RPT_CFG_GRP,userId + '_cfg');
+                    rst.ctrls = user_cfg.formats;
+                    rst.fonts = user_cfg.fonts;
+                    rst.styles = user_cfg.borders;
+                    user_cfg = null;
+                    cb(rst);
+                } else {
+                    user_cfg = null;
+                    cb(me.getReportDefaultCache());
+                }
+            })
         } else {
             rst.ctrls = user_cfg.formats;
             rst.fonts = user_cfg.fonts;
             rst.styles = user_cfg.borders;
             user_cfg = null;
+            cb(rst);
         }
-        return rst;
     }
 }

+ 78 - 0
public/cache/std_glj_type_util.js

@@ -0,0 +1,78 @@
+/**
+ * Created by Tony on 2017/7/6.
+ */
+let cache = 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');
+    return rst;
+};
+
+class StdGljTypeClass{
+    //根据id获取临时数据
+    constructor() {
+        this.innerGljTypeObj = null;
+    };
+
+    build(cache){
+        let me = this, rst = {};
+        rst.items = [];
+        let private_combine_glj_type = function (item) {
+            let tmpItem = {};
+            tmpItem.ID = item.ID;
+            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);
+                }
+            }
+        }
+        for (let item of cache.typesDefine) {
+            private_combine_glj_type(item);
+        }
+        me.innerGljTypeObj = rst;
+    };
+
+    getItemById(Id) {
+        let me = this, rst = null;
+        if (me.innerGljTypeObj) {
+            rst = me.innerGljTypeObj["typeId" + Id];
+        }
+        return rst;
+    };
+
+    toArray(){
+        let me = this, rst = null;
+        return me.innerGljTypeObj.items;
+    }
+};
+
+module.exports = {
+    stdGljTypeObj: null,
+    setStdGljTypeCache: function () {
+        std_glj_type_mdl.find({typeName: "默认"}, '-_id', function(err, typeObj){
+            if(typeObj.length){
+                cache.setCache(STD_GLJ_GRP,'default',typeObj[0]);
+            }
+        })
+    },
+    getStdGljTypeCacheObj: function () {
+        let me = this,
+            rst = null,
+            cache = getStdGljTypeCache();
+        if (me.stdGljTypeObj) {
+            rst = me.stdGljTypeObj;
+        } else if (cache) {
+            rst = new StdGljTypeClass();
+            rst.build(cache);
+            me.stdGljTypeObj = rst;
+        }
+        return rst;
+    }
+}

+ 25 - 0
public/models/std_glj_types.js

@@ -0,0 +1,25 @@
+/**
+ * Created by Tony on 2017/7/6.
+ */
+let mongoose = require('mongoose');
+let dbm = require("../../config/db/db_manager");
+let smartcostdb = dbm.getCfgConnection("scConstruct");
+let Schema = mongoose.Schema;
+
+let RptCfgSchema = new Schema({
+    "typeName" : String,
+    "typesDefine": [{
+        "ID": Number,
+        "fullName": String,
+        "shortName": String,
+        "items": [{
+            "ID": Number,
+            "fullName": String,
+            "shortName": String
+        }]
+    }],
+});
+
+let std_glj_type_mdl = smartcostdb.model("std_glj_type", RptCfgSchema, "std_glj_type");
+
+module.exports = std_glj_type_mdl;

+ 27 - 0
public/web/string_util_light.js

@@ -0,0 +1,27 @@
+/**
+ * Created by Tony on 2017/7/5.
+ * 字符串工具类简化版本
+ */
+
+let stringUtil = {
+    isEmptyString: function(str) {
+        var rst = false;
+        if (str == null || str == undefined) {
+            rst = true;
+        } else if (typeof str) {
+            var reg = /^\s*$/;
+            rst = reg.test(str);
+        }
+        return rst;
+    },
+    convertStrToBoolean: function(str) {
+        var rst = false, me = this;
+        if (!me.isEmptyString(str)) {
+            var upperStr = str.toUpperCase();
+            if (upperStr == 'T' || upperStr == 'Y' || upperStr == 'YES' || upperStr == 'TRUE') {
+                rst = true;
+            }
+        }
+        return rst;
+    }
+}