Browse Source

提交 bills 和 rations 服务器端代码

zhangyin 8 years ago
parent
commit
6d4081b947

+ 55 - 0
modules/main/controllers/bills_controller.js

@@ -0,0 +1,55 @@
+/**
+ * Created by jimiz on 2017/4/7.
+ */
+var billsData = require('../models/bills');
+
+//统一回调函数
+var callback = function(req, res, err, message, data){
+    res.json({error: err, message: message, data: data});
+};
+
+module.exports = {
+    getBills: function(req, res){
+        var data = JSON.parse(req.body.data);
+        billsData.getBills(data.projectId, function(err, message, billsList){
+            if (err === 0) {
+                callback(req, res, err, message, billsList);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    },
+
+    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){
+        //var data = JSON.parse(req.body.data);
+        billsData.getBillsItemTemplate(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);
+            }
+        });
+    }
+
+};

+ 55 - 0
modules/main/controllers/rations_controller.js

@@ -0,0 +1,55 @@
+/**
+ * Created by jimiz on 2017/4/9.
+ */
+var rationsData = require('../models/rations');
+
+//统一回调函数
+var callback = function(req, res, err, message, data){
+    res.json({error: err, message: message, data: data});
+};
+
+module.exports = {
+    getRations: function(req, res){
+        var data = JSON.parse(req.body.data);
+        rationsData.getRations(data.projectId, function(err, message, rationList){
+            if (err === 0) {
+                callback(req, res, err, message, rationList);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    },
+
+    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){
+        //var data = JSON.parse(req.body.data);
+        rationsData.getRationItemTemplate(function(err, message, rationItem){
+            if (billsItem) {
+                callback(req, res, err, message, rationItem);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    },
+
+    allocIDs: function(req, res){
+        rationsData.allocIDs(function(err, message, data){
+            if (err) {
+                callback(req, res, err, message, data);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
+    }
+
+};

+ 8 - 0
modules/main/db/project_db.js

@@ -0,0 +1,8 @@
+/**
+ * Created by jimiz on 2017/4/1.
+ */
+var mongoose = require("mongoose");
+var dbm = require("../../../config/db/db_manager");
+var db = dbm.getCfgConnection("scConstruct");
+
+module.exports = db;

+ 102 - 0
modules/main/models/bills.js

@@ -0,0 +1,102 @@
+/**
+ * Created by jimiz on 2017/4/1.
+ */
+var mongoose = require("mongoose");
+var db = require("../db/project_db");
+var subSchema = require("./billsSubSchemas");
+var Schema = mongoose.Schema;
+var counter = require("../../../public/counter/counter.js");
+
+var billsSchema = new Schema({
+    id: Number,
+    parentId: Number,
+    nextSiblingId: Number,
+    projectId: Number,
+    serialNo: Number,
+    chapterId: Number,
+    code: String,
+    fullCode: String,
+    name: String,
+    unit: String,
+    quantity: String, // Decimal
+    programId: Number,
+    comments: String,
+    // 调价
+    xs_Labour: String, // Decimal
+    xs_Material: String, // Decimal
+    xs_Machine: String, // Decimal
+    xs_FeeRate: String, // Decimal
+    xs_LabourPrice: String, // Decimal
+    xs_MaterialPrice: String, // Decimal
+    xs_MachinePrice: String, // Decimal
+    isTender_Labour: Boolean,
+    isTender_Material: Boolean,
+    isTender_Machine: Boolean,
+    tenderTargetPrice: String, // Decimal
+    tenderTargetUnitPrice: String, // Decimal
+    // 费用字段
+    fees: [subSchema.feesSchema],
+    // 标记字段
+    flags: [subSchema.flagsSchema]
+});
+
+var bills = db.model("bills", billsSchema);
+
+var billsDAO = function(){};
+
+billsDAO.prototype.getBills = function(projectId, callback){
+    Projects.find({projectId: projectId}, function(err, datas){
+        if (!err) {
+            callback(0, '', datas);
+        } else {
+            callback(1, '', null);
+        };
+    });
+};
+
+billsDAO.prototype.updateBills = 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, 'update error.', errList);
+        } else {
+            callback(0, '', null);
+        };
+    };
+};
+
+billsDAO.prototype.getBillsItemTemplate = function(callback){
+    var data = new bills;
+    /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
+    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, highID});
+};
+
+module.exports = new billsDAO();

+ 3 - 0
modules/main/models/billsExprs.js

@@ -0,0 +1,3 @@
+/**
+ * Created by jimiz on 2017/4/10.
+ */

+ 22 - 0
modules/main/models/billsSubSchemas.js

@@ -0,0 +1,22 @@
+/**
+ * Created by jimiz on 2017/4/1.
+ */
+var mongoose = require("mongoose");
+var Schema = mongoose.Schema;
+
+// 费用字段
+var feesSchema = new Schema({
+    fieldName: String,
+    unitFee: String, // Decimal. 单价
+    totalFee: String, // Decimal. 合价
+    tenderUnitFee: String, // Decimal. 调价后单价
+    tenderTotalFee: String // Decimal. 调价后合价
+});
+
+// 标记字段
+var flagsSchema = new Schema({
+    fieldName: String,
+    flag: Boolean
+});
+
+module.exports = {feesSchema, flagsSchema};

+ 3 - 0
modules/main/models/expressions.js

@@ -0,0 +1,3 @@
+/**
+ * Created by jimiz on 2017/4/10.
+ */

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

@@ -0,0 +1,24 @@
+/**
+ * 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
+
+});

+ 21 - 0
modules/main/models/projectGLJ.js

@@ -0,0 +1,21 @@
+/**
+ * Created by jimiz on 2017/4/1.
+ */
+var mongoose = require("mongoose");
+var db = require("../db/project_db");
+var Schema = mongoose.Schema;
+
+var projectGLJSchema = new Schema({
+    id: Number,
+    projectId: Number,
+    code: Number,
+    name: String,
+    specs: String,
+    unit: String,
+    type: String,
+    amount: String, // Decimal
+    rationPrice: String, //Decimal
+    adjustPrice: String, //Decimal
+    price: String //Decimal
+    // to do
+});

+ 25 - 0
modules/main/models/rationPrograms.js

@@ -0,0 +1,25 @@
+/**
+ * Created by jimiz on 2017/4/1.
+ */
+var mongoose = require("mongoose");
+var db = require("../db/project_db");
+var Schema = mongoose.Schema;
+
+var rationProgramSchema = new Schema({
+    id: Number,
+    projectId: Number,
+    name: String,
+    programs: [{
+        id: Number,
+        serialNo: Number,
+        code: String,
+        name: String,
+        expression: String, // 表达式
+        displayExprs: String, // 显示用表达式/基数说明
+        feeRate: String, // Decimal
+        tenderFeeRate: String, // Decimal
+        feeRateID: Number, // 费率细目ID
+        mapField: String, // 对应定额表字段
+        comments: String // 备注
+    }]
+});

+ 89 - 0
modules/main/models/rations.js

@@ -0,0 +1,89 @@
+/**
+ * Created by jimiz on 2017/4/1.
+ */
+var mongoose = require("mongoose");
+var db = require("../db/project_db");
+var subSchema = require("./billsSubSchemas");
+var Schema = mongoose.Schema;
+
+var rationsSchema = new Schema({
+    id: Number,
+    projectId: Number,
+    billsItemId: Number,
+    serialNo: Number,
+    libID: Number,
+    code: String,
+    name: String,
+    maskName: String,
+    unit: String,
+    quantity: String, // Decimal
+    programId: Number,
+    content: String,
+    rationProjName: String,
+    comments: String,
+    // 费用字段
+    fees: [subSchema.feesSchema],
+    // 标记字段
+    flags: [subSchema.flagsSchema]
+});
+
+var rations = db.model("rations", rationsSchema);
+
+var rationsDAO = function(){};
+
+rationsDAO.prototype.getRations = function(projectId, callback){
+    Projects.find({projectID: projectId}, function(err, datas){
+        if (!err) {
+            callback(0, '', datas);
+        } else {
+            callback(1, '', null);
+        }
+    });
+};
+
+rationsDAO.prototype.updateRations = function(projectId, 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, 'update error.', errList);
+        } else {
+            callback(0, '', null);
+        };
+    };
+};
+
+rationsDAO.prototype.getRationItemTemplate = function(callback){
+    var data = new rations;
+    /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
+    callback(0, '', data);
+};
+
+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, highID});
+};
+
+module.exports = new rationsDAO();

+ 13 - 0
modules/main/routes/bills_route.js

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

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

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

+ 5 - 0
server.js

@@ -66,6 +66,11 @@ app.get('/main',  function(req, res) {
     }
 });
 
+var bills_Router = require('./modules/main/routes/bills_route');
+var rations_Router = require('./modules/main/routes/rations_route');
+app.use('/bills', bills_Router);
+app.use('/rations', rations_Router);
+
 var rpt_Router = require("./modules/reports/routes/report_router");
 app.get('/report',  function(req, res) {
     if (!req.session.userAccount) {