Explorar el Código

report / cache

TonyKang hace 8 años
padre
commit
3f6caf9ca1

+ 6 - 7
modules/reports/controllers/rpt_controller.js

@@ -6,7 +6,7 @@ var JV = require('../rpt_component/Jpc_ValueDefine');
 var Template = require('../models/rpt_template');
 var TemplateData = require('../models/rpt_temp_data');
 var JpcEx = require('../rpt_component/JpcEx');
-var cacheController = require('./cacheController');
+var cache = require('../../../public/cache/cacheUtil');
 
 //统一回调函数
 var callback = function(req, res, err, data){
@@ -18,7 +18,7 @@ var callback = function(req, res, err, data){
         //res.send({success: true, data: data});
         res.json({success:true, data: data});
     }
-}
+};
 
 module.exports = {
     getReportAllPages: function(req, res){
@@ -31,9 +31,9 @@ module.exports = {
                     if (tplData) {
                         var printCom = JpcEx.createNew();
                         rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
-                        var dftControls = cacheController.getCache("common_ctrls");
-                        var dftFonts = cacheController.getCache("common_fonts");
-                        var dftStyles = cacheController.getCache("common_styles");
+                        var dftControls = cache.getCache("common_ctrls");
+                        var dftFonts = cache.getCache("common_fonts");
+                        var dftStyles = cache.getCache("common_styles");
                         var defProperties = {ctrls: dftControls, fonts: dftFonts, styles: dftStyles};
                         printCom.initialize(rptTpl);
                         printCom.analyzeData(rptTpl, tplData, defProperties);
@@ -56,5 +56,4 @@ module.exports = {
     },
     remove: function(req, res){
     }
-
-}
+};

+ 48 - 0
modules/reports/controllers/rtp_cfg_controller.js

@@ -0,0 +1,48 @@
+/**
+ * Created by Tony on 2017/3/17.
+ */
+var cmn_ctrl = require('../models/rpt_control');
+var cmn_font = require('../models/rpt_font');
+var cmn_style = require('../models/rpt_style');
+
+var callback = function(req, res, err, data){
+    if(err){
+        //res.send({success: false, error: err});
+        res.json({success: false, error: err});
+    }
+    else{
+        //res.send({success: true, data: data});
+        res.json({success:true, data: data});
+    }
+}
+
+module.exports = {
+    setReportDefaultCache: function (req, res) {
+        var err = "", defProperties = {ctrls: null, fonts: null, styles: null};
+        cmn_ctrl.getAll(null, function(err, ctrls){
+            if (ctrls) {
+                cache.common_ctrls = ctrls;
+                defProperties.ctrls = ctrls;
+            } else {
+                err += 'No default controls! ';
+            }
+        });
+        cmn_font.getAll(null, function(err, fonts){
+            if (fonts) {
+                cache.common_fonts = fonts;
+                defProperties.fonts = fonts;
+            } else {
+                err += 'No default fonts! ';
+            }
+        });
+        cmn_style.getAll(null, function(err, styles){
+            if (styles) {
+                cache.common_styles = styles;
+                defProperties.styles = styles;
+            } else {
+                err += 'No default styles!';
+            }
+        });
+        callback(req, res, err, defProperties);
+    }
+}

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

@@ -0,0 +1,44 @@
+/**
+ * Created by Tony on 2016/12/23.
+ */
+var mongoose = require('mongoose');
+var dbm = require("../../../config/db/db_manager");
+var smartcostdb = dbm.getCfgConnection("Reports");
+var Schema = mongoose.Schema;
+var CtrlSchema = new Schema({
+    "ID" : String,
+    "Shrink" : String,
+    "ShowZero" : String,
+    "Horizon" : String,
+    "Vertical" : String,
+    "Wrap" : String
+});
+
+var Control = smartcostdb.model("com_ctrls", CtrlSchema);
+
+var CtrlDAO = function(){};
+
+//根据id
+CtrlDAO.prototype.get = function(id, callback){
+    Control.find({ID: id}, function(err, templates){
+        if(templates.length){
+            callback(false, templates[0]);
+        }
+        else{
+            callback('查找不到报表模板!');
+        }
+    })
+}
+
+CtrlDAO.prototype.getAll = function(id, callback){
+    Control.find({}, function(err, templates){
+        if(templates.length){
+            callback(false, templates);
+        }
+        else{
+            callback('查找不到报表模板!');
+        }
+    })
+}
+
+module.exports = new CtrlDAO();

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

@@ -0,0 +1,47 @@
+/**
+ * Created by Tony on 2016/12/23.
+ */
+var mongoose = require('mongoose');
+var dbm = require("../../../config/db/db_manager");
+var smartcostdb = dbm.getCfgConnection("Reports");
+var Schema = mongoose.Schema;
+var FontSchema = new Schema({
+    "ID" : String,
+    "Name" : String,
+    "FontHeight" : String,
+    "FontColor" : String,
+    "FontBold" : String,
+    "FontItalic" : String,
+    "FontUnderline" : String,
+    "FontStrikeOut" : String,
+    "FontAngle" : String
+});
+
+var Font = smartcostdb.model("com_fonts", FontSchema);
+
+var FontDAO = function(){};
+
+//根据id
+FontDAO.prototype.get = function(id, callback){
+    Font.find({ID: id}, function(err, templates){
+        if(templates.length){
+            callback(false, templates[0]);
+        }
+        else{
+            callback('查找不到报表模板!');
+        }
+    })
+}
+
+FontDAO.prototype.getAll = function(id, callback){
+    Font.find({}, function(err, templates){
+        if(templates.length){
+            callback(false, templates);
+        }
+        else{
+            callback('查找不到报表模板!');
+        }
+    })
+}
+
+module.exports = new FontDAO();

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

@@ -0,0 +1,40 @@
+/**
+ * Created by Tony on 2016/12/23.
+ */
+var mongoose = require('mongoose');
+var dbm = require("../../../config/db/db_manager");
+var smartcostdb = dbm.getCfgConnection("Reports");
+var Schema = mongoose.Schema;
+var StyleSchema = new Schema({
+    "ID" : String,
+    "border_style" : Array
+});
+
+var Style = smartcostdb.model("com_styles", StyleSchema);
+
+var StyleDAO = function(){};
+
+//根据id
+StyleDAO.prototype.get = function(id, callback){
+    Style.find({ID: id}, function(err, templates){
+        if(templates.length){
+            callback(false, templates[0]);
+        }
+        else{
+            callback('查找不到报表模板!');
+        }
+    })
+}
+
+StyleDAO.prototype.getAll = function(id, callback){
+    Style.find({}, function(err, templates){
+        if(templates.length){
+            callback(false, templates);
+        }
+        else{
+            callback('查找不到报表模板!');
+        }
+    })
+}
+
+module.exports = new StyleDAO();

+ 3 - 4
modules/reports/models/rpt_temp_data.js

@@ -2,8 +2,8 @@
  * Created by Tony on 2016/12/28.
  */
 var mongoose = require('mongoose');
-var smartcostdb = require('./../db/smartcostdb');
-//var Schema = smartcostdb.mongoose.Schema;
+var dbm = require("../../../config/db/db_manager");
+var smartcostdb = dbm.getCfgConnection("Reports");
 var Schema = mongoose.Schema;
 var RptTemplateDataSchema = new Schema({
     "Data_Key": String,
@@ -12,8 +12,7 @@ var RptTemplateDataSchema = new Schema({
     "detail_data": Array
 });
 
-var TemplateData = smartcostdb.mongoose.model("temp_tpl_datas", RptTemplateDataSchema);
-//var TemplateData = smartcostdb.model("temp_tpl_datas", RptTemplateDataSchema);
+var TemplateData = smartcostdb.model("temp_tpl_datas", RptTemplateDataSchema);
 
 var RplTplDataDAO = function(){};
 

+ 3 - 4
modules/reports/models/rpt_template.js

@@ -2,8 +2,8 @@
  * Created by Tony on 2016/12/23.
  */
 var mongoose = require('mongoose');
-var smartcostdb = require('./../db/smartcostdb');
-//var Schema = smartcostdb.mongoose.Schema;
+var dbm = require("../../../config/db/db_manager");
+var smartcostdb = dbm.getCfgConnection("Reports");
 var Schema = mongoose.Schema;
 var RptTemplateSchema = new Schema({
     "GROUP_KEY": String,
@@ -18,8 +18,7 @@ var RptTemplateSchema = new Schema({
     "计算式_集合": Array
 });
 
-var Template = smartcostdb.mongoose.model("rpt_templates", RptTemplateSchema);
-//var Template = smartcostdb.model("rpt_templates", RptTemplateSchema);
+var Template = smartcostdb.model("rpt_templates", RptTemplateSchema);
 
 var RplTplDAO = function(){};
 

+ 5 - 15
modules/reports/routes/report_router.js

@@ -4,21 +4,11 @@
 
 var express = require('express');
 var rptRouter = express.Router();
-var pmController = require('./../controllers/pm_controller');
+var reportController = require('./../controllers/rpt_controller');
+//apiRouter.post('/getReport', reportController.getReportAllPages);
 
-rptRouter.get('/pm', function(req, res){
-    if(!req.session.userAccount){
-        res.redirect('/login');
-    }
-    else{
-        res.render('pm/html/project-management.html',
-            {userAccount: req.session.userAccount,
-                userID: req.session.userID});
-    }
-});
-
-rptRouter.post('/getProjects', pmController.getProjects);
-rptRouter.post('/updateProjects', pmController.updateProjects);
-rptRouter.post('/renameProject', pmController.rename);
+rptRouter.post('/getReport', reportController.getReportAllPages);
+//rptRouter.post('/getPreview', pmController.updateProjects);
+//rptRouter.post('/getExcel', pmController.rename);
 
 module.exports = rptRouter;

+ 14 - 0
public/cache/cacheUtil.js

@@ -0,0 +1,14 @@
+/**
+ * Created by Tony on 2016/12/28.
+ */
+var cache = {};
+
+module.exports = {
+    setCache: function(cacheKey, cacheValue) {
+        cache[cacheKey] = cacheValue;
+        return true;
+    },
+    getCache: function(cacheKey) {
+        return cache[cacheKey];
+    }
+}

+ 3 - 0
server.js

@@ -64,6 +64,9 @@ app.get('/main',  function(req, res) {
     }
 });
 
+var rpt_Router = require("./modules/reports/routes/report_router");
+app.use("/report", rpt_Router);
+
 //zhangenping add 2017.0.13-----------------------------------------begin
 app.use(express.static(_rootDir+"/web"));
 app.use(express.static(_rootDir+"/lib"));

+ 1 - 1
test/demo/demo.js

@@ -7,6 +7,6 @@ var test = require('tape');
 test('basic arithmetic', function (t) {
     t.plan(2);
 
-    t.equal(2 + 3, 5);
+    t.equal(2 + 3, 6);
     t.equal(7 * 8 + 9, 65);
 });

+ 0 - 0
test/globalTestSuit.js


+ 0 - 33
test/testRouter.js

@@ -1,33 +0,0 @@
-/**
- * Created by Tony on 2017/3/7.
- */
-var express = require('express');
-var app = express();
-
-var _rootDir = __dirname;
-
-app.use(express.static(_rootDir));
-
-var bodyParser = require('body-parser');
-app.use(bodyParser.urlencoded({extended: false}));
-app.use(bodyParser.json());
-
-//注册路由
-app.get('/', function(req, res){
-    //res.sendFile(_rootDir+'/web/.../project-management.html');
-});
-
-
-var apiRouter = express.Router();
-
-app.use('/api', apiRouter);
-
-app.use(function(req, res, next) {
-    res.status(404).sendFile(_rootDir+'/src/404.html');
-});
-app.use(function(err, req, res, next) {
-    console.error(err.stack);
-    res.status(500).send('500 Error');
-});
-
-app.listen(6060);

+ 11 - 0
test/unit/reports/testRpt.js

@@ -0,0 +1,11 @@
+/**
+ * Created by Tony on 2017/3/17.
+ */
+var test = require('tape');
+
+test('test get report pages function: ', function (t) {
+    t.plan(2);
+
+    t.equal(2 + 3, 6);
+    t.equal(7 * 8 + 9, 65);
+});