|
@@ -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;
|
|
|
}
|
|
|
}
|