浏览代码

tuning for report configuration merge

TonyKang 8 年之前
父节点
当前提交
c67b153caa

+ 0 - 32
modules/reports/models/cfg_common.js

@@ -1,32 +0,0 @@
-/**
- * Created by Tony on 2017/6/6.
- */
-
-class cfgCommon{
-    constructor(modelObj) {
-        this.modelObj = modelObj;
-    }
-    get(id, callback){
-        this.modelObj.find({ID: id}, '-_id', function(err, templates){
-            if(templates.length){
-                callback(false, templates[0]);
-            }
-            else{
-                callback('no record was found!');
-            }
-        })
-    };
-    getAll(id, callback){
-        this.modelObj.find({}, '-_id', function(err, templates){
-            if(templates.length){
-                callback(false, templates);
-            }
-            else{
-                callback('no record was found!');
-            }
-        })
-    };
-};
-
-//module.exports = new cfgCommon(null);
-module.exports = cfgCommon;

+ 0 - 25
modules/reports/models/cfg_control.js

@@ -1,25 +0,0 @@
-/**
- * Created by Tony on 2016/12/23.
- */
-let mongoose = require('mongoose');
-let dbm = require("../../../config/db/db_manager");
-let smartcostdb = dbm.getCfgConnection("Reports");
-let Schema = mongoose.Schema;
-let CtrlSchema = new Schema({
-    "ID" : String,
-    "Shrink" : String,
-    "ShowZero" : String,
-    "Horizon" : String,
-    "Vertical" : String,
-    "Wrap" : String
-});
-let Control = smartcostdb.model("com_ctrls", CtrlSchema, "com_ctrls");
-let cfgCommonClass = require('./cfg_common');
-
-class CtrlDAO extends cfgCommonClass{
-    constructor(){
-        super(Control);
-    };
-};
-
-module.exports = new CtrlDAO();

+ 0 - 28
modules/reports/models/cfg_font.js

@@ -1,28 +0,0 @@
-/**
- * Created by Tony on 2016/12/23.
- */
-let mongoose = require('mongoose');
-let dbm = require("../../../config/db/db_manager");
-let smartcostdb = dbm.getCfgConnection("Reports");
-let Schema = mongoose.Schema;
-let FontSchema = new Schema({
-    "ID" : String,
-    "Name" : String,
-    "FontHeight" : String,
-    "FontColor" : String,
-    "FontBold" : String,
-    "FontItalic" : String,
-    "FontUnderline" : String,
-    "FontStrikeOut" : String,
-    "FontAngle" : String
-});
-let Font = smartcostdb.model("com_fonts", FontSchema, "com_fonts");
-let cfgCommonClass = require('./cfg_common');
-
-class FontDAO extends cfgCommonClass{
-    constructor(){
-        super(Font);
-    };
-};
-
-module.exports = new FontDAO();

+ 0 - 22
modules/reports/models/cfg_style.js

@@ -1,22 +0,0 @@
-/**
- * Created by Tony on 2016/12/23.
- */
-let mongoose = require('mongoose');
-let dbm = require("../../../config/db/db_manager");
-let smartcostdb = dbm.getCfgConnection("Reports");
-let Schema = mongoose.Schema;
-let StyleSchema = new Schema({
-    "ID" : String,
-    "border_style" : Array
-});
-let Style = smartcostdb.model("com_styles", StyleSchema, "com_styles");
-let cfgCommonClass = require('./cfg_common');
-
-class StyleDAO extends cfgCommonClass{
-    constructor(){
-        super(Style);
-    };
-};
-
-module.exports = new StyleDAO();
-

+ 72 - 0
modules/reports/models/rpt_cfg.js

@@ -0,0 +1,72 @@
+/**
+ * Created by Tony on 2017/6/14.
+ */
+let mongoose = require('mongoose');
+let dbm = require("../../../config/db/db_manager");
+let smartcostdb = dbm.getCfgConnection("Reports");
+let Schema = mongoose.Schema;
+let FormatSchema = new Schema({
+    "ID" : String,
+    "CfgDispName": String,
+    "Shrink" : String,
+    "ShowZero" : String,
+    "Horizon" : String,
+    "Vertical" : String,
+    "Wrap" : String
+});
+let FontSchema = new Schema({
+    "ID" : String,
+    "Name" : String,
+    "CfgDispName": String,
+    "FontHeight" : String,
+    "FontColor" : String,
+    "FontBold" : String,
+    "FontItalic" : String,
+    "FontUnderline" : String,
+    "FontStrikeOut" : String,
+    "FontAngle" : String
+});
+let LineSchema = new Schema({
+    "Position": String,
+    "LineWeight": String,
+    "DashStyle": String,
+    "Color": String
+});
+let StyleSchema = new Schema({
+    "ID" : String,
+    "CfgDispName": String,
+    "border_style" : [LineSchema]
+});
+let RptCfgSchema = new Schema({
+    "userId" : String,
+    "fonts": [FontSchema],
+    "borders" : [StyleSchema],
+    "formats" : [FormatSchema]
+});
+
+let Rpt_Cfg_Mdl = smartcostdb.model("rpt_cfg", RptCfgSchema, "rpt_cfg");
+
+class RptCfgDAO {
+    getByUserId(userId, callback){
+        Rpt_Cfg_Mdl.find({userId: userId}, '-_id', function(err, templates){
+            if(templates.length){
+                callback(false, templates[0]);
+            }
+            else{
+                callback('no record was found!');
+            }
+        })
+    };
+    getAll(id, callback){
+        Rpt_Cfg_Mdl.find({}, '-_id', function(err, templates){
+            if(templates.length){
+                callback(false, templates);
+            }
+            else{
+                callback('no record was found!');
+            }
+        })
+    };
+};
+
+module.exports = new RptCfgDAO();

+ 12 - 21
modules/reports/util/rpt_util.js

@@ -2,35 +2,26 @@
  * Created by Tony on 2017/3/24.
  */
 let cache = require('../../../public/cache/cacheUtil');
-let cmn_ctrl = require('../models/cfg_control');
-let cmn_font = require('../models/cfg_font');
-let cmn_style = require('../models/cfg_style');
+let rpt_cfg = require('../models/rpt_cfg');
 
 const RPT_CFG_GRP = 'rpt_cfg';
 
 module.exports = {
     setReportDefaultCache: function () {
-        cmn_ctrl.getAll(null, function(err, ctrls){
-            if (ctrls) {
-                cache.setCache(RPT_CFG_GRP,'common_ctrls',ctrls);
+        rpt_cfg.getByUserId("Administrator", function (err, cfgs) {
+            if (cfgs) {
+                cache.setCache(RPT_CFG_GRP,'admin_cfg',cfgs);
             }
-        });
-        cmn_font.getAll(null, function(err, fonts){
-            if (fonts) {
-                cache.setCache(RPT_CFG_GRP,'common_fonts',fonts);
-            }
-        });
-        cmn_style.getAll(null, function(err, styles){
-            if (styles) {
-                cache.setCache(RPT_CFG_GRP,'common_styles',styles);
-            }
-        });
+        })
     },
     getReportDefaultCache: function () {
-        let rst = {ctrls: null, fonts: null, styles: null};
-        rst.ctrls = cache.getCache(RPT_CFG_GRP,'common_ctrls');
-        rst.fonts = cache.getCache(RPT_CFG_GRP,'common_fonts');
-        rst.styles = cache.getCache(RPT_CFG_GRP,'common_styles');
+        let rst = {ctrls: null, fonts: null, styles: null},
+            admin_cfg = cache.getCache(RPT_CFG_GRP,'admin_cfg');
+            ;
+        rst.ctrls = admin_cfg.formats;
+        rst.fonts = admin_cfg.fonts;
+        rst.styles = admin_cfg.borders;
+        admin_cfg = null;
         return rst;
     }
 }