Parcourir la source

主要模块代码提交

zhangyin il y a 8 ans
Parent
commit
dc6c2e1426

+ 4 - 4
modules/main/controllers/rations_controller.js

@@ -1,7 +1,7 @@
 /**
  * Created by jimiz on 2017/4/9.
  */
-var rationsData = require('../models/rations');
+var rationData = require('../models/ration');
 
 //统一回调函数
 var callback = function(req, res, err, message, data){
@@ -11,7 +11,7 @@ var callback = function(req, res, err, message, data){
 module.exports = {
     getData: function(req, res){
         var data = JSON.parse(req.body.data);
-        rationsData.getData(data.projectId, function(err, message, rationList){
+        rationData.getData(data.projectId, function(err, message, rationList){
             if (err === 0) {
                 callback(req, res, err, message, rationList);
             } else {
@@ -22,7 +22,7 @@ module.exports = {
 
     getItemTemplate: function(req, res){
         //var data = JSON.parse(req.body.data);
-        rationsData.getItemTemplate(function(err, message, rationItem){
+        rationData.getItemTemplate(function(err, message, rationItem){
             if (billsItem) {
                 callback(req, res, err, message, rationItem);
             } else {
@@ -32,7 +32,7 @@ module.exports = {
     },
 
     allocIDs: function(req, res){
-        rationsData.allocIDs(function(err, message, data){
+        rationData.allocIDs(function(err, message, data){
             if (err) {
                 callback(req, res, err, message, data);
             } else {

+ 5 - 5
modules/main/models/GLJ.js

@@ -75,11 +75,11 @@ GLJDAO.prototype.getItemTemplate = function(callback){
 const
     IDStep = 50, IDModule = 'bills';
 
-GLJDAO.prototype.allocIDs = function(callback){
-    var lowID, highID;
-    counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
-    lowID = highID - IDStep + 1;
-    callback(0, '', {lowID: lowID, highID: highID});
+GLJDAO.prototype.allocIDs = function(IDStep, callback){
+    counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, IDStep, function(err, highID){
+        var lowID = highID - IDStep + 1;
+        callback(0, '', {lowID: lowID, highID: highID});
+    });
 };
 
 module.exports = new GLJDAO();

+ 7 - 10
modules/main/models/bills.js

@@ -44,8 +44,8 @@ var bills = db.model("bills", billsSchema);
 
 var billsDAO = function(){};
 
-billsDAO.prototype.getData = function(projectId, callback){
-    bills.find({projectId: projectId}, function(err, datas){
+billsDAO.prototype.getData = function(projectID, callback){
+    bills.find({projectID: projectID}, function(err, datas){
         if (!err) {
             callback(0, '', datas);
         } else {
@@ -89,14 +89,11 @@ billsDAO.prototype.getItemTemplate = function(callback){
     callback(0, '', data);
 };
 
-const
-    IDStep = 50, IDModule = 'bills';
-
-billsDAO.prototype.allocIDs = function(callback){
-    var lowID, highID;
-    counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
-    lowID = highID - IDStep + 1;
-    callback(0, '', {lowID: lowID, highID: highID});
+billsDAO.prototype.allocIDs = function(IDStep, callback){
+    counter.counterDAO.getIDAfterCount(counter.moduleName.bills, IDStep, function(err, highID){
+        var lowID = highID - IDStep + 1;
+        callback(0, '', {lowID: lowID, highID: highID});
+    });
 };
 
 module.exports = new billsDAO();

+ 1 - 1
modules/main/models/billsSubSchemas.js

@@ -16,7 +16,7 @@ var feesSchema = new Schema({
 // 标记字段
 var flagsSchema = new Schema({
     fieldName: String,
-    flag: Boolean
+    flag: Number
 });
 
 module.exports = {feesSchema: feesSchema, flagsSchema: flagsSchema};

+ 1 - 1
modules/main/models/project.js

@@ -2,7 +2,7 @@
  * Created by jimiz on 2017/4/16.
  */
 var billsData = require('./bills');
-var rationData = require('./rations');
+var rationData = require('./ration');
 var GLJData = require('./GLJ');
 var consts = require('./projectConsts');
 

+ 13 - 13
modules/main/models/rations.js

@@ -6,7 +6,7 @@ var db = require("../db/project_db");
 var subSchema = require("./billsSubSchemas");
 var Schema = mongoose.Schema;
 
-var rationsSchema = new Schema({
+var rationSchema = new Schema({
     ID: Number,
     ProjectID: Number,
     billsItemID: Number,
@@ -27,11 +27,11 @@ var rationsSchema = new Schema({
     flags: [subSchema.flagsSchema]
 });
 
-var rations = db.model("rations", rationsSchema);
+var ration = db.model("rations", rationSchema);
 
-var rationsDAO = function(){};
+var rationDAO = function(){};
 
-rationsDAO.prototype.getData = function(projectId, callback){
+rationDAO.prototype.getData = function(projectId, callback){
     rations.find({projectID: projectId}, function(err, datas){
         if (!err) {
             callback(0, '', datas);
@@ -41,7 +41,7 @@ rationsDAO.prototype.getData = function(projectId, callback){
     });
 };
 
-rationsDAO.prototype.save = function(projectId, datas, callback){
+rationDAO.prototype.save = function(projectId, datas, callback){
     var data, errList = [], updateLength = 0;
     var updateFunc = function (err, errData) {
         if (err){
@@ -70,8 +70,8 @@ rationsDAO.prototype.save = function(projectId, datas, callback){
     };
 };
 
-rationsDAO.prototype.getItemTemplate = function(callback){
-    var data = new rations;
+rationDAO.prototype.getItemTemplate = function(callback){
+    var data = new ration;
     /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
     callback(0, '', data);
 };
@@ -79,11 +79,11 @@ rationsDAO.prototype.getItemTemplate = function(callback){
 const
     IDStep = 50, IDModule = 'rations';
 
-rationsDAO.prototype.allocIDs = function(callback){
-    var lowID, highID;
-    counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
-    lowID = highID - IDStep + 1;
-    callback(0, '', {lowID: lowID, highID: highID});
+rationDAO.prototype.allocIDs = function(IDStep, callback){
+    counter.counterDAO.getIDAfterCount(counter.moduleName.ration, IDStep, function(err, highID){
+        var lowID = highID - IDStep + 1;
+        callback(0, '', {lowID: lowID, highID: highID});
+    });
 };
 
-module.exports = new rationsDAO();
+module.exports = new rationDAO();

+ 3 - 3
modules/main/routes/GLJ_route.js

@@ -5,8 +5,8 @@ var express = require('express');
 var GLJRouter = express.Router();
 var GLJController = require('../controllers/GLJ_controller');
 
-GLJRouter.post('/GLJGetData', GLJController.getData);
-GLJRouter.post('/GLJGetItemTemplate', GLJController.getItemTemplate);
-GLJRouter.post('/GLJAllocIDs', GLJController.allocIDs);
+GLJRouter.post('/getData', GLJController.getData);
+GLJRouter.post('/getItemTemplate', GLJController.getItemTemplate);
+GLJRouter.post('/allocIDs', GLJController.allocIDs);
 
 module.exports = GLJRouter;

+ 3 - 3
modules/main/routes/bills_route.js

@@ -5,8 +5,8 @@ var express = require('express');
 var billsRouter = express.Router();
 var billsController = require('../controllers/bills_controller');
 
-billsRouter.post('/billsGetData', billsController.getData);
-billsRouter.post('/billsGetItemTemplate', billsController.getItemTemplate);
-billsRouter.post('/billsAllocIDs', billsController.allocIDs);
+billsRouter.post('/getData', billsController.getData);
+billsRouter.post('/getItemTemplate', billsController.getItemTemplate);
+billsRouter.post('/allocIDs', billsController.allocIDs);
 
 module.exports = billsRouter;

+ 12 - 0
modules/main/routes/ration_route.js

@@ -0,0 +1,12 @@
+/**
+ * Created by jimiz on 2017/4/7.
+ */
+var express = require('express');
+var rationRouter = express.Router();
+var rationController = require('../controllers/ration_controller');
+
+rationRouter.post('/getData', rationController.getData);
+rationRouter.post('/getItemTemplate', rationController.getItemTemplate);
+rationRouter.post('/allocIDs', rationController.allocIDs);
+
+module.exports = rationRouter;

+ 0 - 12
modules/main/routes/rations_route.js

@@ -1,12 +0,0 @@
-/**
- * Created by jimiz on 2017/4/7.
- */
-var express = require('express');
-var rationsRouter = express.Router();
-var rationsController = require('../controllers/rations_controller');
-
-rationsRouter.post('/rationGetData', rationsController.getData);
-rationsRouter.post('/rationGetItemTemplate', rationsController.getItemTemplate);
-rationsRouter.post('/rationAllocIDs', rationsController.allocIDs);
-
-module.exports = rationsRouter;

+ 1 - 0
public/counter/counter.js

@@ -21,6 +21,7 @@ const COUNTER_MODULE_NAME = {
     user: 'users',
     bills: 'bills',
     ration: 'rations',
+    GLJ: 'glj',
     report: 'rptTemplates',
     fee: 'fees',
     template_bills: 'temp_bills'

+ 2 - 2
server.js

@@ -79,11 +79,11 @@ app.get('/main',  function(req, res) {
 
 var project_Router = require('./modules/main/routes/project_route');
 var bills_Router = require('./modules/main/routes/bills_route');
-var rations_Router = require('./modules/main/routes/rations_route');
+var ration_Router = require('./modules/main/routes/ration_route');
 var GLJ_Router = require('./modules/main/routes/GLJ_route');
 app.use('/project', project_Router);
 app.use('/bills', bills_Router);
-app.use('/rations', rations_Router);
+app.use('/ration', ration_Router);
 app.use('/GLJ', GLJ_Router);
 
 var rpt_Router = require("./modules/reports/routes/report_router");

Fichier diff supprimé car celui-ci est trop grand
+ 46 - 0
test/tmp_data/test_project_1.js


+ 3 - 2
web/main/html/main.html

@@ -517,10 +517,11 @@
     <script type="text/javascript" src="lib/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
     <script>GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";</script>
     <!-- Model -->
+    <script type="text/javascript" src="web/main/js/models/mainConsts.js"></script>
     <script type="text/javascript" src="web/main/js/models/project.js"></script>
     <script type="text/javascript" src="web/main/js/models/bills.js"></script>
-    <script type="text/javascript" src="web/main/js/models/rations.js"></script>
-    <script type="text/javascript" src="web/main/js/models/gljs.js"></script>
+    <script type="text/javascript" src="web/main/js/models/ration.js"></script>
+    <script type="text/javascript" src="web/main/js/models/glj.js"></script>
 
     <script type="text/javascript" src="public/web/idTree.js"></script>
     <script type="text/javascript" src="web/main/js/models/cache_tree.js"></script>

+ 25 - 1
web/main/js/models/bills.js

@@ -20,10 +20,29 @@ var Bills = {
             this.datas = null;
             this.tree = idTree.createNew(billsTreeSetting);
 
-            var sourceType = 'bills';
+            var sourceType = ModuleNames.bills;
             this.getSourceType = function () {
                 return sourceType;
             }
+            proj.registerModule(ModuleNames.bills, this);
+        };
+
+        // 从后台获取数据
+        bills.prototype.pullData = function (){
+            this.project.pullData(
+                '/bills/getData',
+                {projectID: this.project.ID},
+                function(result){
+                    if (result.error ===0){
+                        this.loadDatas(result.data);
+                    }
+                    else {
+                        // to do: 错误处理需要细化
+                        alert(result.message);
+                    }
+                },
+                function (){/* to do: 错误处理需要细化*/}
+            )
         };
 
         // prototype用于定义public方法
@@ -44,6 +63,11 @@ var Bills = {
             this.tree.loadDatas(this.datas);
         };
 
+        // 提交数据后的错误处理方法
+        bills.prototype.doAfterUpdate = function(err, data){
+            // to do
+        };
+
         return new bills(project);
     }
 };

+ 49 - 0
web/main/js/models/glj.js

@@ -0,0 +1,49 @@
+/**
+ * Created by Mai on 2017/4/1.
+ */
+var GLJ = {
+    createNew: function (project) {
+        // 用户定义private方法
+        var tools = {};
+
+        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        var glj = function (proj) {
+            this.project = proj;
+            this.datas = null;
+
+            var sourceType = ModuleNames.GLJ;
+            this.getSourceType = function () {
+                return sourceType;
+            }
+            proj.registerModule(ModuleNames.GLJ, this);
+        };
+
+// 从后台获取数据
+        glj.prototype.pullData = function (){
+            this.project.pullData(
+                '/bills/getData',
+                {projectID: this.project.ID},
+                function(result){
+                    if (result.error ===0){
+                        this.loadDatas(result.data);
+                    }
+                    else {
+                        // to do: 错误处理需要细化
+                        alert(result.message);
+                    }
+                },
+                function (){/* to do: 错误处理需要细化*/}
+            )
+        };
+        // prototype用于定义public方法
+        glj.prototype.loadDatas = function (datas) {
+            this.datas = datas;
+        };
+
+        // 提交数据后的错误处理方法
+        glj.prototype.doAfterUpdate = function(err, data){
+            // to do
+        };
+        return new glj(project);
+    }
+};

+ 0 - 27
web/main/js/models/gljs.js

@@ -1,27 +0,0 @@
-/**
- * Created by Mai on 2017/4/1.
- */
-var GLJs = {
-    createNew: function (project) {
-        // 用户定义private方法
-        var tools = {};
-
-        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
-        var gljs = function (proj) {
-            this.project = proj;
-            this.datas = null;
-
-            var sourceType = 'glj';
-            this.getSourceType = function () {
-                return sourceType;
-            }
-        };
-
-        // prototype用于定义public方法
-        gljs.prototype.loadDatas = function (datas) {
-            this.datas = datas;
-        };
-
-        return new gljs(project);
-    }
-};

+ 9 - 0
web/main/js/models/mainConsts.js

@@ -0,0 +1,9 @@
+/**
+ * Created by jimiz on 2017/4/19.
+ */
+const ModuleNames = {
+    bills: 'bills',
+    ration: 'ration',
+    GLJ: 'GLJ',
+    projectGLJ: 'projectGLJ'
+};

+ 56 - 6
web/main/js/models/project.js

@@ -5,11 +5,20 @@ var PROJECT = {
     createNew: function (projectID, userID) {
         // 定义private方法
         var tools = {
-            _projectID: projectID,
+            _ID: projectID,
             _userID: userID,
             updateLock: 0,
             updateData: [],
-            operation: ''
+            operation: '',
+            modules: {},
+
+            doAfterUpdate: function(result){
+                result.forEach(function(item){
+                    if (item.moduleName in this.modules){
+                        this.modules[item.moduleName].doAfterUpdate(item.err, item.data);
+                    }
+                });
+            }
         };
 
         // 所有通过this访问的属性,都不应在此单元外部进行写入操作
@@ -17,8 +26,8 @@ var PROJECT = {
             this.mainTree = cacheTree.createNew(this);
 
             this.Bills = Bills.createNew(this);
-            this.Rations = Rations.createNew(this);
-            this.GLJs = GLJs.createNew(this);
+            this.Ration = Ration.createNew(this);
+            this.GLJ = GLJ.createNew(this);
 
 
             this.masterField = {ration: 'BillsID'};
@@ -29,6 +38,11 @@ var PROJECT = {
             // To Do
         };
 
+        // prototype用于定义public方法
+        project.prototype.ID = function () {
+            return tools._ID;
+        };
+
         project.prototype.loadMainTree = function () {
             var that = this;
             var loadRationNode = function (rations, cacheNode) {
@@ -61,6 +75,33 @@ var PROJECT = {
             this.mainTree.sortTreeItems();
         };
 
+        // 提供给各模块调用的统一从后台获取数据的方法
+        project.prototype.pullData = function (url, data, successCallback, errorCallback) {
+            $.ajax({
+                type:"POST",
+                url: url,
+                data: {'data': JSON.stringify(data)},
+                dataType: 'json',
+                cache: false,
+                timeout: 50000,
+                success: function(result){
+                    successCallback(result);
+                },
+                error: function(jqXHR, textStatus, errorThrown){
+                    alert('error ' + textStatus + " " + errorThrown);
+                    errorCallback();
+                }
+            });
+        };
+
+        // 所有模块在此从后台获取数据
+        project.prototype.loadDatas = function (){
+            this.Bills.pullData();
+            this.Ration.pullData();
+            this.GLJ.pullData();
+
+        };
+
         project.prototype.beginUpdate = function(operation){
             if (tools.updateLock === 0){
                 tools.operation = operation
@@ -78,7 +119,7 @@ var PROJECT = {
                     type: "POST",
                     url: '/project/save',
                     data: {'data': JSON.stringify({
-                        "project_id": tools._projectID,
+                        "project_id": tools._ID,
                         "user_id": tools._userID,
                         "date": new Date,
                         "operation": tools.operation,
@@ -89,7 +130,7 @@ var PROJECT = {
                     timeout: 50000,
                     success: function (result) {
                         if (result.error === 0) {
-                            // to do callback(result.data);
+                            tools.doAfterUpdate(result.data);
                         } else {
                             alert('error: ' + result.message);
                         }
@@ -104,6 +145,9 @@ var PROJECT = {
         };
 
         project.prototype.push = function(moduleName, data){
+            if (tools.updateLock === 0){
+                throw "project can not push data before beginUpdate";
+            };
             var moduleData = {
                 moduleName: moduleName,
                 data: data
@@ -111,6 +155,12 @@ var PROJECT = {
             tools.updateData.push(moduleData);
         };
 
+        project.prototype.registerModule = function(moduleName, obj){
+            if (!tools.modules.hasOwnProperty(moduleName)){
+                tools.modules[moduleName] = obj;
+            }
+        };
+
         return new project();
     }
 };

+ 62 - 0
web/main/js/models/ration.js

@@ -0,0 +1,62 @@
+/**
+ * Created by Mai on 2017/4/1.
+ */
+
+var Ration = {
+    createNew: function (project) {
+        // 用户定义private方法
+        var tools = {};
+
+        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        var ration = function (proj) {
+            this.project = proj;
+            this.datas = null;
+
+            var sourceType = ModuleNames.ration;
+            this.getSourceType = function () {
+                return sourceType;
+            }
+            proj.registerModule(ModuleNames.ration, this);
+        };
+
+        // 从后台获取数据
+        bills.prototype.pullData = function (){
+            this.project.pullData(
+                '/bills/getData',
+                {projectID: this.project.ID},
+                function(result){
+                    if (result.error ===0){
+                        this.loadDatas(result.data);
+                    }
+                    else {
+                        // to do: 错误处理需要细化
+                        alert(result.message);
+                    }
+                },
+                function (){/* to do: 错误处理需要细化*/}
+            )
+        };
+        // prototype用于定义public方法
+        ration.prototype.loadDatas = function (datas) {
+            this.datas = datas;
+            // generate Fees & Flags Index,For View & Calculate
+            this.datas.forEach(function (data) {
+                data.FeesIndex = {};
+                data.fees.forEach(function (fee) {
+                    data.FeesIndex[fee.fieldName] = fee;
+                });
+                data.FlagsIndex = {};
+                data.flags.forEach(function (flag) {
+                    data.FlagsIndex[flag.fieldName] = flag;
+                });
+            });
+        };
+
+        // 提交数据后的错误处理方法
+        ration.prototype.doAfterUpdate = function(err, data){
+            // to do
+        };
+
+        return new ration(project);
+    }
+};

+ 0 - 39
web/main/js/models/rations.js

@@ -1,39 +0,0 @@
-/**
- * Created by Mai on 2017/4/1.
- */
-
-var Rations = {
-    createNew: function (project) {
-        // 用户定义private方法
-        var tools = {};
-
-        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
-        var rations = function (proj) {
-            this.project = proj;
-            this.datas = null;
-
-            var sourceType = 'ration';
-            this.getSourceType = function () {
-                return sourceType;
-            }
-        };
-
-        // prototype用于定义public方法
-        rations.prototype.loadDatas = function (datas) {
-            this.datas = datas;
-            // generate Fees & Flags Index,For View & Calculate
-            this.datas.forEach(function (data) {
-                data.FeesIndex = {};
-                data.fees.forEach(function (fee) {
-                    data.FeesIndex[fee.fieldName] = fee;
-                });
-                data.FlagsIndex = {};
-                data.flags.forEach(function (flag) {
-                    data.FlagsIndex[flag.fieldName] = flag;
-                });
-            });
-        };
-
-        return new rations(project);
-    }
-};