소스 검색

项目文件

TonyKang 7 년 전
부모
커밋
b9c7df20ef
3개의 변경된 파일270개의 추가작업 그리고 144개의 파일을 삭제
  1. 27 6
      modules/main/facade/prj_properties_facade.js
  2. 23 7
      modules/main/models/prj_properties.js
  3. 220 131
      test/unit/main/prj_properties_test.js

+ 27 - 6
modules/main/facade/prj_properties_facade.js

@@ -3,33 +3,54 @@
  */
 let mongoose = require("mongoose");
 let prj_prop_mdl = mongoose.model("project_property");
+let std_prj_prop_mdl = mongoose.model("cfg_prj_property");
 
 module.exports = {
     createPrjProperties: createPrjProperties,
-    removeProperty : removeProperty,
+    removePrjProperties : removePrjProperties,
     updateWhole: updateWhole,
     updateOneProperty: updateOneProperty,
     addOrChangeProperty: addOrChangeProperty,
     removeOneProperty: removeOneProperty,
+    getPrjProperty: getPrjProperty,
+
+    createStdPrjProperties: createStdPrjProperties,
+    getStdPrjProperties: getStdPrjProperties,
 
     createPrjPropertiesWithCallBack: createPrjPropertiesWithCallBack,
-    removePropertyWithCallBack: removePropertyWithCallBack,
+    removePrjPropertiesWithCallBack: removePrjPropertiesWithCallBack,
     updateWholeWithCallBack: updateWholeWithCallBack,
     updateOnePropertyWithCallBack: updateOnePropertyWithCallBack,
     addOrChangePropertyWithCallBack: addOrChangePropertyWithCallBack,
     removeOnePropertyWithCallBack: removeOnePropertyWithCallBack
 };
 
+async function createStdPrjProperties(rationLibId, items) {
+    let data = {};
+    data.rationLibID = rationLibId;
+    data.properties = items;
+    let rst = await  std_prj_prop_mdl.create(data);
+    return rst;
+}
+
+async function getStdPrjProperties(rationLibId) {
+    let rst = await  std_prj_prop_mdl.findOne({"rationLibID": rationLibId});
+    return rst;
+}
+
+async function getPrjProperty(prjId) {
+    let rst = await  prj_prop_mdl.findOne({"projectID": prjId});
+    return rst;
+}
 async function createPrjProperties(prjId, dftItems) {
     let data = {};
     data.projectID = prjId;
     data.properties = dftItems;
-    let saveObj = new prj_prop_mdl(data);
-    let rst = await  saveObj.save();
+    let rst = await  prj_prop_mdl.create(data);
     return rst;
 };
 
-async function removeProperty(prjId) {
+async function removePrjProperties(prjId) {
     let rst = await  prj_prop_mdl.remove({'projectID': prjId});
     return rst;
 };
@@ -75,7 +96,7 @@ function createPrjPropertiesWithCallBack(prjId, dftItems, cb) {
     saveObj.save(cb);
 };
 
-function removePropertyWithCallBack(prjId, cb) {
+function removePrjPropertiesWithCallBack(prjId, cb) {
     prj_prop_mdl.remove({'projectID': prjId}, cb);
 }
 

+ 23 - 7
modules/main/models/prj_properties.js

@@ -63,17 +63,33 @@
 // module.exports = new projectPropertiesDAO();
 
 let mongoose = require('mongoose');
-// let propertyDetailSchema = new mongoose.Schema({
-//     key: String,
-//     dispName: String,
-//     value: String
-// });
+let propertyDetailSchema = new mongoose.Schema({
+    key: String,
+    dispName: String,
+    value: String
+});
 
 let prj_property = new mongoose.Schema({
     projectID: Number,
-    properties: Array
+    properties: Array  //原则上是应该设置好对象的属性,但在实际应用中发现mongoose保存的时候会自动增加objectId(_id)字段,无语。。。
+    // properties: [{
+    //     key: String,
+    //     dispName: String,
+    //     value: String
+    // }]
+}, {versionKey: false});
+
+//预储存的项目属性,在项目创建的时候copy一份到项目中
+let cfg_property = new mongoose.Schema({
+    rationLibID: Number,      //这个对应标准定额库ID
+    descr: String,      //描述
+    properties: [propertyDetailSchema]
 }, {versionKey: false});
 
 let prj_prop_mdl = mongoose.model('project_property', prj_property, 'prj_properties');
+let std_prj_prop_mdl = mongoose.model('cfg_prj_property', cfg_property, 'std_cfg_prj_properties');
 
-module.exports = prj_prop_mdl;
+module.exports = {
+    prj_prop_mdl: prj_prop_mdl,
+    std_prj_prop_mdl: std_prj_prop_mdl
+};

+ 220 - 131
test/unit/main/prj_properties_test.js

@@ -7,139 +7,228 @@ let dbm = require("../../../config/db/db_manager");
 require('../../../modules/main/models/prj_properties');
 let ppFacade = require('../../../modules/main/facade/prj_properties_facade');
 
-//let randomPrjId = Math.round(Math.random() * 100);
-let randomPrjId = 35;
+let rationLibId = 3;
+let randomPrjId = Math.round(Math.random() * 100);
+//let randomPrjId = 35;
 dbm.connect();
 
-// test('测试 - 创建dummy项目属性: ', function (t) {
-//     let items = [];
-//     items.push({key: "contractNum", dispName: "合同号", value: "天字第一号"});
-//     items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
-//     items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
-//     items.push({key: "startDate", dispName: "建设日期", value: "2017-07-31"});
-//     items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
-//     items.push({key: "designer", dispName: "设计单位", value: "珠海设计局"});
-//     items.push({key: "builder", dispName: "施工单位", value: "中建十局"});
-//
-//     let results = ppFacade.createPrjProperties(randomPrjId, items);
-//     results.then(function(rst) {
-//         console.log('rst.projectID: ' + rst.projectID);
-//         for (let prop of rst.properties) {
-//             console.log('property ' + prop.dispName + ': ' + prop.value);
-//         }
-//         t.pass('just pass!');
-//         t.end();
-//     });
-// });
-
-// test('测试 - 整个更新项目属性: ', function (t) {
-//     let items = [];
-//     items.push({key: "contractNum", dispName: "合同号", value: "人字第三号"});
-//     items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
-//     items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
-//     items.push({key: "startDate", dispName: "建设日期", value: "2017-08-01"});
-//     items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
-//     items.push({key: "designer", dispName: "设计单位", value: "珠海设计局"});
-//     items.push({key: "builder", dispName: "施工单位", value: "中建十局"});
-//
-//     let udtObj = {"projectID": 35, "properties": items};
-//
-//     let rst = ppFacade.updateWhole(udtObj);
-//     if (rst) {
-//         rst.then(function(results){
-//             for (let prop in results) {
-//                 console.log(prop + ': ' + results[prop]);
-//             }
-//             t.pass('just pass!');
-//             t.end();
-//         });
-//     } else {
-//         console.log('update failed!');
-//         t.pass('just pass!');
-//         t.end();
-//     }
-// });
-
-// test('测试 - 新增项目属性: ', function (t) {
-//     let newItem = {key: "auditor", dispName: "监理单位", value: "珠海德信"};
-//     let results = ppFacade.addOrChangeProperty(35, newItem);
-//     if (results instanceof Promise) {
-//         results.then(function (rst) {
-//             for (let prop in rst) {
-//                 console.log("property " + prop + ' : ' + rst[prop]);
-//             }
-//         })
-//     } else {
-//         for (let prop in results) {
-//             console.log("property " + prop + ' : ' + results[prop]);
-//         }
-//     }
-//
-//     t.pass('just pass!');
-//     t.end();
-//
-// });
-
-// test('测试 - 删除全体项目属性: ', function (t) {
-//     let rst = ppFacade.removeProperty(35);
-//     if (rst) {
-//         if (rst instanceof Promise) {
-//             rst.then(function(results){
-//                 for (let prop in results) {
-//                     console.log(prop + ': ' + results[prop]);
-//                 }
-//                 t.pass('just pass with remove1!');
-//                 t.end();
-//             });
-//         } else {
-//             for (let prop in results) {
-//                 console.log(prop + ': ' + results[prop]);
-//             }
-//             t.pass('just pass with remove2!');
-//             t.end();
-//         }
-//     } else {
-//         t.pass('just pass but not remove!');
-//         t.end();
-//     }
-// });
-
-// test('测试 - 更新项目属性: ', function (t) {
-//     let rst = ppFacade.updateOneProperty(35, "builder", "中建十一局");
-//     if (rst) {
-//         rst.then(function(results){
-//             for (let prop in results) {
-//                 console.log(prop + ': ' + results[prop]);
-//             }
-//             t.pass('just pass with update!');
-//             t.end();
-//         });
-//     } else {
-//         t.pass('just pass but not update!');
-//         t.end();
-//     }
-// });
-
-// test('测试 - 移除一项属性: ', function (t) {
-//     let rst = ppFacade.removeOneProperty(35, "auditor");
-//     if (rst) {
-//         rst.then(function(results){
-//             for (let prop in results) {
-//                 console.log(prop + ': ' + results[prop]);
-//             }
-//             t.pass('just pass with remove!');
-//             t.end();
-//         });
-//     } else {
-//         t.pass('just pass but not remove!');
-//         t.end();
-//     }
-// });
+/*
+test('测试 - 创建dummy项目属性: ', function (t) {
+    let items = [];
+    items.push({key: "contractNum", dispName: "合同号", value: "天字第一号"});
+    items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
+    items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
+    items.push({key: "startDate", dispName: "开工日期", value: "2017-07-31"});
+    items.push({key: "completeDate", dispName: "竣工日期", value: "2018-07-31"});
+    items.push({key: "location", dispName: "工程地点", value: "珠海新香洲人民西路666号"});
+    items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
+    items.push({key: "designCompany", dispName: "设计单位", value: "珠海设计局"});
+    items.push({key: "buildingCompany", dispName: "施工单位", value: "中建十局"});
+    items.push({key: "superviseCompany", dispName: "监理单位", value: "珠海监理"});
+    items.push({key: "auditCompany", dispName: "审核单位", value: "创新审核"});
+    items.push({key: "author", dispName: "编制人", value: "张三"});
+    items.push({key: "auditor", dispName: "审核人", value: "李四"});
 
-test('close the connection', function (t) {
-    setTimeout(function () {
-        mongoose.disconnect();
-        t.pass('closing db connection');
+    let results = ppFacade.createPrjProperties(randomPrjId, items);
+    results.then(function(rst) {
+        console.log('rst.projectID: ' + rst.projectID);
+        for (let prop of rst.properties) {
+            console.log('property ' + prop.dispName + ': ' + prop.value);
+        }
+        t.pass('just pass!');
+        t.end();
+    });
+});
+//*/
+
+/*
+test('测试 - 创建dummy标准项目属性: ', function (t) {
+    let items = [];
+    items.push({key: "contractNum", dispName: "合同号", value: "天字第一号"});
+    items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
+    items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
+    items.push({key: "startDate", dispName: "开工日期", value: "2017-07-31"});
+    items.push({key: "completeDate", dispName: "竣工日期", value: "2018-07-31"});
+    items.push({key: "location", dispName: "工程地点", value: "珠海新香洲人民西路666号"});
+    items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
+    items.push({key: "designCompany", dispName: "设计单位", value: "珠海设计局"});
+    items.push({key: "buildingCompany", dispName: "施工单位", value: "中建十局"});
+    items.push({key: "superviseCompany", dispName: "监理单位", value: "珠海监理"});
+    items.push({key: "auditCompany", dispName: "审核单位", value: "创新审核"});
+    items.push({key: "author", dispName: "编制人", value: "张三"});
+    items.push({key: "auditor", dispName: "审核人", value: "李四"});
+
+    let results = ppFacade.createStdPrjProperties(rationLibId, items);
+    results.then(function(rst) {
+        console.log('rst.projectID: ' + rst.projectID);
+        for (let prop of rst.properties) {
+            console.log('property ' + prop.dispName + ': ' + prop.value);
+        }
+        t.pass('just pass!');
+        t.end();
+    });
+});
+//*/
+
+/*
+test('测试 - 整个更新项目属性: ', function (t) {
+    let items = [];
+    items.push({key: "contractNum", dispName: "合同号", value: "人字第三号"});
+    items.push({key: "appType", dispName: "工程专业", value: "建筑工程"});
+    items.push({key: "constructType", dispName: "工程类别", value: "住宅"});
+    items.push({key: "startDate", dispName: "建设日期", value: "2017-08-01"});
+    items.push({key: "owner", dispName: "建设单位", value: "珠海纵横创新"});
+    items.push({key: "designCompany", dispName: "设计单位", value: "珠海设计局"});
+    items.push({key: "buildingCompany", dispName: "施工单位", value: "中建十局"});
+
+    let udtObj = {"projectID": 35, "properties": items};
+
+    let rst = ppFacade.updateWhole(udtObj);
+    if (rst) {
+        rst.then(function(results){
+            for (let prop in results) {
+                console.log(prop + ': ' + results[prop]);
+            }
+            t.pass('just pass!');
+            t.end();
+        });
+    } else {
+        console.log('update failed!');
+        t.pass('just pass!');
         t.end();
-    }, 1500);
+    }
+});
+//*/
+
+/*
+test('测试 - 新增项目属性: ', function (t) {
+    let newItem = {key: "superviseCompany", dispName: "监理单位", value: "珠海德信"};
+    let results = ppFacade.addOrChangeProperty(35, newItem);
+    if (results instanceof Promise) {
+        results.then(function (rst) {
+            for (let prop in rst) {
+                console.log("property " + prop + ' : ' + rst[prop]);
+            }
+        })
+    } else {
+        for (let prop in results) {
+            console.log("property " + prop + ' : ' + results[prop]);
+        }
+    }
+
+    t.pass('just pass!');
+    t.end();
+
+});
+//*/
+
+/*
+test('测试 - 删除全体项目属性: ', function (t) {
+    let rst = ppFacade.removePrjProperties(35);
+    if (rst) {
+        if (rst instanceof Promise) {
+            rst.then(function(results){
+                for (let prop in results) {
+                    console.log(prop + ': ' + results[prop]);
+                }
+                t.pass('just pass with remove1!');
+                t.end();
+            });
+        } else {
+            for (let prop in results) {
+                console.log(prop + ': ' + results[prop]);
+            }
+            t.pass('just pass with remove2!');
+            t.end();
+        }
+    } else {
+        t.pass('just pass but not remove!');
+        t.end();
+    }
+});
+//*/
+
+/*
+test('测试 - 更新项目属性: ', function (t) {
+    let rst = ppFacade.updateOneProperty(35, "buildingCompany", "中建十一局");
+    if (rst) {
+        rst.then(function(results){
+            for (let prop in results) {
+                console.log(prop + ': ' + results[prop]);
+            }
+            t.pass('just pass with update!');
+            t.end();
+        });
+    } else {
+        t.pass('just pass but not update!');
+        t.end();
+    }
+});
+//*/
+
+/*
+test('测试 - 获取项目属性: ', function (t) {
+    let rst = ppFacade.getPrjProperty(35);
+    if (rst) {
+        rst.then(function(results){
+            console.log(results.projectID);
+            console.log(results.properties);
+            t.pass('just pass with update!');
+            t.end();
+        });
+    } else {
+        t.pass('just pass but not update!');
+        t.end();
+    }
+});
+//*/
+
+/*
+test('测试 - 获取标准项目属性: ', function (t) {
+    let rst = ppFacade.getStdPrjProperties(rationLibId);
+    if (rst) {
+        rst.then(function(results){
+            // console.log(results.rationLibID);
+            // console.log(results.properties);
+            let rt = ppFacade.createPrjProperties(randomPrjId, results.properties);
+            rt.then(function (rt1) {
+                console.log('创建后ID: '+ rt1.projectID);
+            })
+            t.pass('just pass with update!');
+            t.end();
+        });
+    } else {
+        t.pass('just pass but not update!');
+        t.end();
+    }
+});
+//*/
+
+/*
+test('测试 - 移除一项属性: ', function (t) {
+    let rst = ppFacade.removeOneProperty(35, "superviseCompany");
+    if (rst) {
+        rst.then(function(results){
+            for (let prop in results) {
+                console.log(prop + ': ' + results[prop]);
+            }
+            t.pass('just pass with remove!');
+            t.end();
+        });
+    } else {
+        t.pass('just pass but not remove!');
+        t.end();
+    }
+});
+//*/
+
+test('close the connection', function (t) {
+    // setTimeout(function () {
+    //     mongoose.disconnect();
+    //     t.pass('closing db connection');
+    //     t.end();
+    // }, 100);
+    mongoose.disconnect();
+    t.pass('closing db connection');
+    t.end();
 })