فهرست منبع

Merge branch 'master' of http://192.168.1.12:3000/SmartCost/ConstructionCost

TonyKang 8 سال پیش
والد
کامیت
1dabd7e2bb

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

@@ -55,15 +55,6 @@ class billsModel extends baseModel {
         super(bills);
     };
 
-    /**
-     *
-     * @param {Number} projectId
-     * @returns {Promise}
-     */
-    getProjectData (projectId) {
-        return this.getQueryData({"projectID": projectId}, '-_id');
-    };
-
     getData (projectID, callback) {
         this.model.find({'$or': [{projectID: projectID, deleteInfo: null}, {projectID: projectID, 'deleteInfo.deleted': {$in: [null, false]}}]}, '-_id', function(err, datas){
             if (!err) {

+ 36 - 0
modules/main/models/proj_counter.js

@@ -0,0 +1,36 @@
+/**
+ * Created by Mai on 2017/6/13.
+ */
+
+let baseModel = require('./base_model');
+
+class projCounter extends baseModel {
+    constructor (name) {
+        let db = require("../db/project_db");
+        let Schema = require("mongoose").Schema;
+        let projCounterSchema = new Schema({
+            projectID: Number,
+            bills: Number,
+            ration: Number
+        });
+        let projCounterModel = db.model(name, projCounterSchema);
+        super(projCounterModel);
+        this.collectionName = name;
+    };
+
+    getData (projectID, callback) {
+        this.model.findOne({"projectID": projectID}, '-_id', function (err, result) {
+            if (!err) {
+                callback(0, '', result);
+            } else {
+                callback(1, '查询数据失败。', null);
+            }
+        });
+    };
+
+    save (user_id, data, callback) {
+        this.model.update({"projectID": data.projectID}, data, callback);
+    }
+};
+
+module.exports = new projCounter('projCounter');

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

@@ -4,6 +4,7 @@
 var billsData = require('./bills');
 var rationData = require('./ration');
 var GLJData = require('./glj');
+let projCounter = require('./proj_counter');
 var consts = require('./project_consts');
 var projectConsts = consts.projectConst;
 var async = require("async");
@@ -13,6 +14,7 @@ var moduleMap = {};
 moduleMap[projectConsts.BILLS] = billsData;
 moduleMap[projectConsts.RATION] = rationData;
 moduleMap[projectConsts.GLJ] = GLJData;
+moduleMap[projCounter.collectionName] = projCounter;
 
 var Project = function (){};
 

+ 0 - 4
modules/main/models/ration.js

@@ -93,10 +93,6 @@ class rationModel extends baseModel {
             callback(0, '', {lowID: lowID, highID: highID});
         });
     };
-
-    getProjectData (projectID) {
-        return this.getQueryData({"projectID": projectID}, '-_id');
-    };
 };
 
 module.exports = new rationModel();

+ 15 - 9
modules/pm/controllers/copy_proj_controller.js

@@ -4,25 +4,31 @@
 
 let billsData = require('../../main/models/bills');
 let rationData = require('../../main/models/ration');
+let projCounter = require('../../main/models/proj_counter');
 let async = require('async');
 
 module.exports = {
     copyProjectData: function (srcProjID, newProjID, callback) {
         var fun = [];
         var copyData = function (model) {
-            return () => {
-                model.getProjectData(srcProjID).then(function (results) {
-                    let datas = [];
-                    results.forEach(function (result) {
-                        result._doc.projectID = newProjID;
-                        datas.push(result._doc);
-                    });
-                    return model.insertData(datas, callback);
-                }).catch((err) => callback(err));
+            return (cb) => {
+                model.getQueryData({"projectID": srcProjID}, '-_id').then(function (results, err) {
+                    if (results.length > 0) {
+                        let datas = [];
+                        results.forEach(function (result) {
+                            result._doc.projectID = newProjID;
+                            datas.push(result._doc);
+                        });
+                        return model.insertData(datas, cb);
+                    } else {
+                        cb(err);
+                    }
+                }).catch(cb);
             };
         };
         fun.push(copyData(billsData));
         fun.push(copyData(rationData));
+        fun.push(copyData(projCounter));
         async.parallel(fun, (err) => callback(err));
     }
 };

+ 18 - 9
modules/pm/controllers/new_proj_controller.js

@@ -2,18 +2,27 @@
  * Created by Mai on 2017/4/24.
  */
 
-let billsData = require('../../main/models/bills');
 let BillsTemplateData = require('../../templates/models/bills_template');
+let billsData = require('../../main/models/bills');
+let projCounter = require('../../main/models/proj_counter');
+let async = require('async');
 
 module.exports = {
     copyTemplateData: function (tempType, newProjID, callback) {
-        BillsTemplateData.getTemplate(tempType).then(function (templates) {
-            let datas = [];
-            templates.forEach(function (template) {
-                template._doc.projectID = newProjID;
-                datas.push(template._doc);
-            })
-            return billsData.insertData(datas, callback);
-        }).catch((err) => callback(err));
+        async.parallel([
+            function (cb) {
+                BillsTemplateData.getTemplate(tempType).then(function (templates) {
+                    let datas = [];
+                    templates.forEach(function (template) {
+                        template._doc.projectID = newProjID;
+                        datas.push(template._doc);
+                    })
+                    return billsData.insertData(datas, cb);
+                });
+            },
+            function (cb) {
+                projCounter.insertData({"projectID": newProjID}, cb);
+            }
+        ], (err) => callback(err));
     }
 };

+ 5 - 1
package.json

@@ -13,10 +13,14 @@
     "ejs": "~2.5.5",
     "express-session": "^1.15.1",
     "request": "^2.79.0",
-    "tape": "^4.6.3"
+    "tape": "^4.6.3",
+    "nodemon": "^1.11.0"
   },
   "dependencies": {
     "bluebird": "^3.5.0",
     "jszip": "^3.1.3"
+  },
+  "scripts" :{
+    "start": "nodemon server.js"
   }
 }

+ 1 - 1
test/tmp_data/bills_grid_setting.js

@@ -257,7 +257,7 @@ var BillsGridSetting ={
             "readOnly":false,
             "head":{
                 "titleNames":[
-                    "工程量计规则"
+                    "工程量计规则"
                 ],
                 "spanCols":[
                     1

+ 1 - 1
web/building_saas/main/html/main.html

@@ -198,7 +198,7 @@
                                           <select class="form-control form-control-sm col-6" id="stdBillsLibSelect">
                                           </select>
                                           <div class="input-group col-6" id="stdBillsSearch">
-                                              <input type="text" class="form-control form-control-sm" placeholder="搜索清单" value="1-1-2">
+                                              <input type="text" class="form-control form-control-sm" placeholder="搜索清单">
                                               <span class="input-group-btn">
                                                   <button class="btn btn-secondary btn-sm" type="button"><i class="fa fa-search" aria-hidden="true"></i></button>
                                               </span>

+ 21 - 3
web/building_saas/main/js/models/bills.js

@@ -87,11 +87,25 @@ var Bills = {
             this.tree.loadDatas(this.datas);
         };
 
+        bills.prototype.setMaxID = function (ID) {
+            this.tree.maxNodeID(ID);
+        };
+
         // 提交数据后的错误处理方法
         bills.prototype.doAfterUpdate = function(err, data){
             // to do
         };
 
+        bills.prototype.getCounterData = function (count) {
+            var updateData = {'projectID': this.project.ID()};
+            if (count) {
+                updateData[this.getSourceType()] = this.tree.maxNodeID() + count;
+            } else {
+                updateData[this.getSourceType()] = this.tree.maxNodeID() + 1;
+            }
+            return updateData;
+        };
+
         bills.prototype.insertBills = function (parentId, nextSiblingId) {
             var insertData = this.tree.getInsertData(parentId, nextSiblingId);
             var that = this;
@@ -100,8 +114,10 @@ var Bills = {
                 if (data.type === idTree.updateType.new) {
                     that.datas.push(data.data);
                 }
-            })
-            project.pushNow('insertBills', ModuleNames.bills, tools.coverseTreeUpdateData(insertData));
+            });
+            this.project.pushNow('insertBills', [this.getSourceType(), this.project.projCounter()],
+                [ tools.coverseTreeUpdateData(insertData), this.getCounterData()]);
+            //project.pushNow('insertBills', ModuleNames.bills, tools.coverseTreeUpdateData(insertData));
 
             return this.tree.insert(parentId, nextSiblingId);
         };
@@ -119,7 +135,9 @@ var Bills = {
                     newData = data.data;
                 }
             });
-            project.pushNow('insertStdBills', ModuleNames.bills, tools.coverseTreeUpdateData(insertData));
+            this.project.pushNow('insertStdBills', [this.getSourceType(), this.project.projCounter()],
+                [ tools.coverseTreeUpdateData(insertData), this.getCounterData()]);
+            //project.pushNow('insertStdBills', ModuleNames.bills, tools.coverseTreeUpdateData(insertData));
 
             return this.tree.insertByData(newData, parentId, nextSiblingId);
         }

+ 14 - 1
web/building_saas/main/js/models/project.js

@@ -11,7 +11,8 @@ var PROJECT = {
             updateLock: 0,
             updateData: [],
             operation: '',
-            modules: {}
+            modules: {},
+            projCounter: 'projCounter'
         };
 
         var me = tools;
@@ -24,11 +25,19 @@ var PROJECT = {
             });
         };
         tools.doAfterLoad = function(result, callback){
+            var counter;
             result.forEach(function(item){
                 if (me.modules[item.moduleName]){
                     me.modules[item.moduleName].loadData(item.data);
+                } else if (item.moduleName === me.projCounter) {
+                    counter = item.data;
                 }
             });
+            for (module in counter) {
+                if (me.modules[module]) {
+                    me.modules[module].setMaxID(counter[module]);
+                }
+            }
             me._project.loadMainTree();
             //me.test(result[0].data[0]);
             callback(0);
@@ -63,6 +72,10 @@ var PROJECT = {
             return tools._ID;
         };
 
+        project.prototype.projCounter = function () {
+            return tools.projCounter;
+        }
+
         project.prototype.loadMainTree = function () {
             var that = this;
             var loadRationNode = function (rations, cacheNode) {

+ 7 - 3
web/building_saas/main/js/models/ration.js

@@ -50,6 +50,10 @@ var Ration = {
             });
         };
 
+        ration.prototype.setMaxID = function (ID) {
+            this.maxRationID(ID);
+        }
+
         // 提交数据后的错误处理方法
         ration.prototype.doAfterUpdate = function(err, data){
             // to do
@@ -98,9 +102,9 @@ var Ration = {
 
         ration.prototype.insertRation = function (billsID, preRation) {
             var br = this.getBillsSortRation(billsID);
-            /*this.project.pushNow('insertRation', [this.getSourceType(), 'proj_counter'],
-                [this.getInsertRationData(billsID, preRation), this.getCounterData()]);*/
-            this.project.pushNow('insertRation', [this.getSourceType()], [this.getInsertRationData(billsID, preRation)]);
+            this.project.pushNow('insertRation', [this.getSourceType(), this.project.projCounter()],
+                [this.getInsertRationData(billsID, preRation), this.getCounterData()]);
+            //this.project.pushNow('insertRation', [this.getSourceType()], [this.getInsertRationData(billsID, preRation)]);
 
             var newRation = null;
             if (preRation) {

+ 2 - 2
web/building_saas/main/js/views/std_bills_lib.js

@@ -304,7 +304,7 @@ var LoadStdBills = (function () {
                 "width":200,
                 "readOnly":true,
                 "head":{
-                    "titleNames":["工内容"],
+                    "titleNames":["工内容"],
                     "spanCols":[1],
                     "spanRows":[1],
                     "vAlign":[1],
@@ -410,7 +410,7 @@ var LoadStdBills = (function () {
             return codeIs || nameIs;
         });
         result.sort(function (x, y) {
-            return x.serialNo - y.serialNo;
+            return x.serialNo() - y.serialNo();
         });
         if (result.length !== 0) {
             var sel = stdBillsSpread.getActiveSheet().getSelections();