rpt_util.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Created by Tony on 2017/3/24.
  3. */
  4. let cache = require('../../../public/cache/cacheUtil');
  5. let Rpt_Cfg_Mdl = require('../models/rpt_cfg');
  6. const RPT_CFG_GRP = 'rpt_cfg';
  7. module.exports = {
  8. setReportDefaultCache: function () {
  9. Rpt_Cfg_Mdl.find({userId: "Administrator"}, '-_id', function(err, templates){
  10. if(templates.length){
  11. cache.setCache(RPT_CFG_GRP,'admin_cfg',templates[0]);
  12. }
  13. })
  14. },
  15. getReportDefaultCache: function () {
  16. let rst = {ctrls: null, fonts: null, styles: null},
  17. admin_cfg = cache.getCache(RPT_CFG_GRP,'admin_cfg');
  18. ;
  19. rst.ctrls = admin_cfg.formats;
  20. rst.fonts = admin_cfg.fonts;
  21. rst.styles = admin_cfg.borders;
  22. admin_cfg = null;
  23. return rst;
  24. },
  25. setReportCacheByUser: function (userId) {
  26. let me = this;
  27. Rpt_Cfg_Mdl.find({userId: userId}, '-_id', function(err, templates){
  28. if(templates.length){
  29. cache.setCache(RPT_CFG_GRP, userId + '_cfg',templates[0]);
  30. } else {
  31. me.setReportDefaultCache();
  32. }
  33. })
  34. },
  35. getReportCacheByUser: function (userId) {
  36. let me = this,
  37. rst = {ctrls: null, fonts: null, styles: null},
  38. user_cfg = cache.getCache(RPT_CFG_GRP,userId + '_cfg');
  39. ;
  40. if (!(user_cfg)) {
  41. rst = null;
  42. rst = me.getReportDefaultCache();
  43. } else {
  44. rst.ctrls = user_cfg.formats;
  45. rst.fonts = user_cfg.fonts;
  46. rst.styles = user_cfg.borders;
  47. user_cfg = null;
  48. }
  49. return rst;
  50. }
  51. }