rpt_util.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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, cfgs){
  10. if(cfgs.length){
  11. cache.setCache(RPT_CFG_GRP,'admin_cfg',cfgs[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. let user_cfg = cache.getCache(RPT_CFG_GRP,userId + '_cfg');
  28. if (!(user_cfg)) {
  29. Rpt_Cfg_Mdl.find({userId: userId}, '-_id', function(err, cfgs){
  30. if(cfgs.length){
  31. cache.setCache(RPT_CFG_GRP, userId + '_cfg',cfgs[0]);
  32. } else {
  33. me.setReportDefaultCache();
  34. }
  35. })
  36. }
  37. },
  38. getReportCacheByUser: function (userId, cb) {
  39. let me = this,
  40. rst = {ctrls: null, fonts: null, styles: null},
  41. user_cfg = cache.getCache(RPT_CFG_GRP,userId + '_cfg');
  42. ;
  43. if (!(user_cfg)) {
  44. Rpt_Cfg_Mdl.find({userId: userId}, '-_id', function(err, cfgs){
  45. if(cfgs.length){
  46. cache.setCache(RPT_CFG_GRP, userId + '_cfg',cfgs[0]);
  47. user_cfg = cache.getCache(RPT_CFG_GRP,userId + '_cfg');
  48. rst.ctrls = user_cfg.formats;
  49. rst.fonts = user_cfg.fonts;
  50. rst.styles = user_cfg.borders;
  51. user_cfg = null;
  52. cb(rst);
  53. } else {
  54. user_cfg = null;
  55. cb(me.getReportDefaultCache());
  56. }
  57. })
  58. } else {
  59. rst.ctrls = user_cfg.formats;
  60. rst.fonts = user_cfg.fonts;
  61. rst.styles = user_cfg.borders;
  62. user_cfg = null;
  63. cb(rst);
  64. }
  65. }
  66. }