Browse Source

主要模块提交

zhangyin 8 years ago
parent
commit
a8b2234b12

+ 47 - 0
modules/main/controllers/GLJ_controller.js

@@ -0,0 +1,47 @@
+/**
+ * Created by jimiz on 2017/4/17.
+ */
+/**
+ * Created by jimiz on 2017/4/7.
+ */
+var GLJData = require('../models/GLJ');
+
+//统一回调函数
+var callback = function(req, res, err, message, data){
+    res.json({error: err, message: message, data: data});
+};
+
+module.exports = {
+    getData: function(req, res){
+        var data = JSON.parse(req.body.data);
+        billsData.getData(data.projectId, function(err, message, billsList){
+            if (err === 0) {
+                callback(req, res, err, message, billsList);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    },
+
+    getItemTemplate: function(req, res){
+        //var data = JSON.parse(req.body.data);
+        billsData.getItemTemplate(function(err, message, billsItem){
+            if (billsItem) {
+                callback(req, res, err, message, billsItem);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    },
+
+    allocIDs: function(req, res){
+        billsData.allocIDs(function(err, message, data){
+            if (err) {
+                callback(req, res, err, message, data);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    }
+
+};

+ 4 - 15
modules/main/controllers/bills_controller.js

@@ -9,9 +9,9 @@ var callback = function(req, res, err, message, data){
 };
 
 module.exports = {
-    getBills: function(req, res){
+    getData: function(req, res){
         var data = JSON.parse(req.body.data);
-        billsData.getBills(data.projectId, function(err, message, billsList){
+        billsData.getData(data.projectId, function(err, message, billsList){
             if (err === 0) {
                 callback(req, res, err, message, billsList);
             } else {
@@ -20,20 +20,9 @@ module.exports = {
         });
     },
 
-    updateBills: function(req, res){
-        var data = JSON.parse(req.body.data);
-        billsData.updateBills(data, function(err, message, errList){
-            if (err) {
-                callback(req, res, err, message, errList);
-            } else {
-                callback(req, res, err, message, null);
-            }
-        });
-    },
-
-    getBillsItemTemplate: function(req, res){
+    getItemTemplate: function(req, res){
         //var data = JSON.parse(req.body.data);
-        billsData.getBillsItemTemplate(function(err, message, billsItem){
+        billsData.getItemTemplate(function(err, message, billsItem){
             if (billsItem) {
                 callback(req, res, err, message, billsItem);
             } else {

+ 22 - 0
modules/main/controllers/project_controller.js

@@ -0,0 +1,22 @@
+/**
+ * Created by jimiz on 2017/4/16.
+ */
+var Project = require('../models/project');
+
+//统一回调函数
+var callback = function(req, res, err, message, data){
+    res.json({error: err, message: message, data: data});
+};
+
+module.exports = {
+    save: function (req, res) {
+        var data = JSON.parse(req.body.data);
+        Project.save(data, function (err, message, result) {
+            if (err) {
+                callback(req, res, err, message, result);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    }
+};

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

@@ -9,9 +9,9 @@ var callback = function(req, res, err, message, data){
 };
 
 module.exports = {
-    getRations: function(req, res){
+    getData: function(req, res){
         var data = JSON.parse(req.body.data);
-        rationsData.getRations(data.projectId, function(err, message, rationList){
+        rationsData.getData(data.projectId, function(err, message, rationList){
             if (err === 0) {
                 callback(req, res, err, message, rationList);
             } else {
@@ -20,20 +20,9 @@ module.exports = {
         });
     },
 
-    updateRations: function(req, res){
-        var data = JSON.parse(req.body.data);
-        rationsData.updateRations(data, function(err, message, errList){
-            if (err) {
-                callback(req, res, err, message, errList);
-            } else {
-                callback(req, res, err, message, null);
-            }
-        });
-    },
-
-    getRationItemTemplate: function(req, res){
+    getItemTemplate: function(req, res){
         //var data = JSON.parse(req.body.data);
-        rationsData.getRationItemTemplate(function(err, message, rationItem){
+        rationsData.getItemTemplate(function(err, message, rationItem){
             if (billsItem) {
                 callback(req, res, err, message, rationItem);
             } else {

+ 85 - 0
modules/main/models/GLJ.js

@@ -0,0 +1,85 @@
+/**
+ * Created by jimiz on 2017/4/1.
+ */
+var mongoose = require("mongoose");
+var db = require("../db/project_db");
+var Schema = mongoose.Schema;
+
+var GLJSchema = new Schema({
+    ID: Number,
+    ProjectID: Number,
+    orgRQuantity: String, //Decimal
+    rQuantity: String, //Decimal
+    customQuantity: String, //Decimal
+    quantity: String, //Decimal
+    rationItemQuantity: String, //Decimal
+    rationPrice: String, //Decimal
+    adjustPrice: String, //Decimal
+    price: String, //Decimal
+    tenderQuantity: String, //Decimal
+    tenderPrice: String, //Decimal
+    type: Number
+    // to do
+
+});
+
+var GLJ = db.model("GLJList", GLJSchema);
+
+var GLJDAO = function(){};
+
+GLJDAO.prototype.getData = function(projectId, callback){
+    GLJ.find({projectId: projectId}, function(err, datas){
+        if (!err) {
+            callback(0, '', datas);
+        } else {
+            callback(1, '', null);
+        };
+    });
+};
+
+GLJDAO.prototype.save = function(datas, callback){
+    var data, errList = [], updateLength = 0;
+    var updateFunc = function (err, errData) {
+        if (err){
+            errList.push(errData);
+        };
+    };
+    if (datas){
+        for (var i = 0; i < datas.length; i++){
+            data = datas[i];
+            if (data.updateType === 'update') {
+                delete data.updateType;
+                data.save(updateFunc);
+            } else if (data.updateType === 'create') {
+                delete data.updateType;
+                data.save(updateFunc);
+            } else if (data.updateType === 'delete') {
+                delete data.updateType;
+                data.remove(updateFunc);
+            };
+        };
+        if (errList.length > 0){
+            callback(1, errList);
+        } else {
+            callback(0, null);
+        };
+    };
+};
+
+GLJDAO.prototype.getItemTemplate = function(callback){
+    var data = new bills;
+    /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
+    callback(0, '', data);
+};
+
+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});
+};
+
+module.exports = new GLJDAO();

+ 6 - 6
modules/main/models/bills.js

@@ -44,8 +44,8 @@ var bills = db.model("bills", billsSchema);
 
 var billsDAO = function(){};
 
-billsDAO.prototype.getBills = function(projectId, callback){
-    Projects.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 {
@@ -54,7 +54,7 @@ billsDAO.prototype.getBills = function(projectId, callback){
     });
 };
 
-billsDAO.prototype.updateBills = function(datas, callback){
+billsDAO.prototype.save = function(datas, callback){
     var data, errList = [], updateLength = 0;
     var updateFunc = function (err, errData) {
         if (err){
@@ -76,14 +76,14 @@ billsDAO.prototype.updateBills = function(datas, callback){
             };
         };
         if (errList.length > 0){
-            callback(1, 'update error.', errList);
+            callback(1, errList);
         } else {
-            callback(0, '', null);
+            callback(0, null);
         };
     };
 };
 
-billsDAO.prototype.getBillsItemTemplate = function(callback){
+billsDAO.prototype.getItemTemplate = function(callback){
     var data = new bills;
     /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
     callback(0, '', data);

+ 0 - 24
modules/main/models/gljs.js

@@ -1,24 +0,0 @@
-/**
- * Created by jimiz on 2017/4/1.
- */
-var mongoose = require("mongoose");
-var db = require("../db/project_db");
-var Schema = mongoose.Schema;
-
-var gljSchema = new Schema({
-    ID: Number,
-    projectID: Number,
-    orgRQuantity: String, //Decimal
-    rQuantity: String, //Decimal
-    customQuantity: String, //Decimal
-    quantity: String, //Decimal
-    rationItemQuantity: String, //Decimal
-    rationPrice: String, //Decimal
-    adjustPrice: String, //Decimal
-    price: String, //Decimal
-    tenderQuantity: String, //Decimal
-    tenderPrice: String, //Decimal
-    type: Number
-    // to do
-
-});

+ 56 - 0
modules/main/models/project.js

@@ -0,0 +1,56 @@
+/**
+ * Created by jimiz on 2017/4/16.
+ */
+var billsData = require('./bills');
+var rationData = require('./rations');
+var GLJData = require('./GLJ');
+var consts = require('./projectConsts');
+
+var moduleMap = {};
+
+moduleMap[consts.BILLS] = billsData;
+moduleMap[consts.RATION] = rationData;
+moduleMap[consts.GLJ] = GLJData;
+
+var Project = function (){};
+
+Project.prototype.datas = [];
+
+Project.prototype.prepare = function(data, callback){
+    data.updateData.forEach(function(item){
+        this.datas.push(item);
+        /*
+        to do
+        moduleMap[item.moduleName].prepare(item.data, jobCallback);
+        */
+    });
+};
+
+Project.prototype.save = function(data, callback){
+    var job, savePoint;
+    var errDatas = [];
+    this.prepare(data, function(job, savePoint){});
+
+    var saveCallback = function(err, moduleName, data){
+        if (err != 0){
+            var errData = {moduleName: moduleName, err: err, data: data};
+            errDatas.push(errData);
+        }
+    };
+
+    this.datas.forEach(function(item){
+        moduleMap[item.moduleName].save(item.data, saveCallback);
+    });
+
+    this.datas = [];
+
+    if (errDatas.length > 0){
+        callback(1, 'error', errDatas)
+    }
+    else{
+        callback(0, '', null)
+    }
+
+};
+
+module.exports = new Project();

+ 12 - 0
modules/main/models/projectConsts.js

@@ -0,0 +1,12 @@
+/**
+ * Created by jimiz on 2017/4/18.
+ */
+var projectConst = {
+    BILLS: 'bills',
+    RATION: 'ration',
+    GLJ: 'GLJ',
+    PROJECTGLJ: 'projectGLJ'
+
+};
+
+module.exports = projectConst;

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

@@ -31,8 +31,8 @@ var rations = db.model("rations", rationsSchema);
 
 var rationsDAO = function(){};
 
-rationsDAO.prototype.getRations = function(projectId, callback){
-    Projects.find({projectID: projectId}, function(err, datas){
+rationsDAO.prototype.getData = function(projectId, callback){
+    rations.find({projectID: projectId}, function(err, datas){
         if (!err) {
             callback(0, '', datas);
         } else {
@@ -41,7 +41,7 @@ rationsDAO.prototype.getRations = function(projectId, callback){
     });
 };
 
-rationsDAO.prototype.updateRations = function(projectId, datas, callback){
+rationsDAO.prototype.save = function(projectId, datas, callback){
     var data, errList = [], updateLength = 0;
     var updateFunc = function (err, errData) {
         if (err){
@@ -70,7 +70,7 @@ rationsDAO.prototype.updateRations = function(projectId, datas, callback){
     };
 };
 
-rationsDAO.prototype.getRationItemTemplate = function(callback){
+rationsDAO.prototype.getItemTemplate = function(callback){
     var data = new rations;
     /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
     callback(0, '', data);

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

@@ -0,0 +1,12 @@
+/**
+ * Created by jimiz on 2017/4/17.
+ */
+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);
+
+module.exports = GLJRouter;

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

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

+ 10 - 0
modules/main/routes/project_route.js

@@ -0,0 +1,10 @@
+/**
+ * Created by jimiz on 2017/4/16.
+ */
+var express = require('express');
+var projectRouter = express.Router();
+var projectController = require('../controllers/project_controller');
+
+projectRouter.post('/save', projectController.save);
+
+module.exports = projectRouter;

+ 3 - 4
modules/main/routes/rations_route.js

@@ -5,9 +5,8 @@ var express = require('express');
 var rationsRouter = express.Router();
 var rationsController = require('../controllers/rations_controller');
 
-rationsRouter.post('/getRations', rationsController.getRations);
-rationsRouter.post('/updateRations', rationsController.updateRations);
-rationsRouter.post('/getRationsItemTemplate', rationsController.getRationItemTemplate);
-rationsRouter.post('/allocIDs', rationsController.allocIDs);
+rationsRouter.post('/rationGetData', rationsController.getData);
+rationsRouter.post('/rationGetItemTemplate', rationsController.getItemTemplate);
+rationsRouter.post('/rationAllocIDs', rationsController.allocIDs);
 
 module.exports = rationsRouter;

+ 4 - 0
server.js

@@ -66,10 +66,14 @@ 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 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('/GLJ', GLJ_Router);
 
 var rpt_Router = require("./modules/reports/routes/report_router");
 app.get('/report',  function(req, res) {

+ 59 - 3
web/main/js/models/project.js

@@ -2,9 +2,15 @@
  * Created by Mai on 2017/4/1.
  */
 var PROJECT = {
-    createNew: function () {
+    createNew: function (projectID, userID) {
         // 定义private方法
-        var tools = {};
+        var tools = {
+            _projectID: projectID,
+            _userID: userID,
+            updateLock: 0,
+            updateData: [],
+            operation: ''
+        };
 
         // 所有通过this访问的属性,都不应在此单元外部进行写入操作
         var project = function () {
@@ -53,7 +59,57 @@ var PROJECT = {
             };
             loadIdTreeNode(this.Bills.tree.roots, null);
             this.mainTree.sortTreeItems();
-        }
+        };
+
+        project.prototype.beginUpdate = function(operation){
+            if (tools.updateLock === 0){
+                tools.operation = operation
+            }
+            tools.updateLock += 1;
+        };
+
+        project.prototype.endUpdate = function(){
+            if (tools.updateLock === 0){
+                throw "project can not endUpdate before beginUpdate";
+            }
+            tools.updateLock -= 1;
+            if (tools.updateLock === 0) {
+                $.ajax({
+                    type: "POST",
+                    url: '/project/save',
+                    data: {'data': JSON.stringify({
+                        "project_id": tools._projectID,
+                        "user_id": tools._userID,
+                        "date": new Date,
+                        "operation": tools.operation,
+                        "update_data": tools.updateData
+                    })},
+                    dataType: 'json',
+                    cache: false,
+                    timeout: 50000,
+                    success: function (result) {
+                        if (result.error === 0) {
+                            // to do callback(result.data);
+                        } else {
+                            alert('error: ' + result.message);
+                        }
+                    },
+                    error: function(jqXHR, textStatus, errorThrown){
+                        alert('error ' + textStatus + " " + errorThrown);
+                    }
+                });
+                tools.updateData = [];
+                tools.operation = "";
+            }
+        };
+
+        project.prototype.push = function(moduleName, data){
+            var moduleData = {
+                moduleName: moduleName,
+                data: data
+            };
+            tools.updateData.push(moduleData);
+        };
 
         return new project();
     }