소스 검색

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

zhongzewei 7 년 전
부모
커밋
a5f1e26f88
5개의 변경된 파일74개의 추가작업 그리고 19개의 파일을 삭제
  1. 13 9
      config/config.js
  2. 1 1
      config/db/db_manager.js
  3. 2 2
      modules/glj/controllers/glj_controller.js
  4. 37 0
      modules/glj/models/mix_ratio_model.js
  5. 21 7
      modules/glj/models/unit_price_model.js

+ 13 - 9
config/config.js

@@ -1,15 +1,19 @@
 module.exports = {
     current: {server: "192.168.1.184", port: "60666",redis:{server:'192.168.1.184',port:'6379',pwd:'smartCost'}},
     local: {server: "localhost", port: "27017"},
-    qa: {server: "192.168.1.184", port: "60666", options:{
-        user:'smartcost',
-        pass:'smartcost3850888',
-        auth: {
-            "authdb": "admin"
-        },
-        connectTimeoutMS: 20000,
-        useMongoClient: true
-    }},
+    qa: {
+        server: "192.168.1.184",
+        port: "60666",
+        options:{
+            user:'smartcost',
+            pass:'smartcost3850888',
+            auth: {
+                "authdb": "admin"
+              },
+            connectTimeoutMS: 20000,
+            useMongoClient: true
+        }
+    },
     test_auth: {
             server: "120.78.150.216",
             port: "27017",

+ 1 - 1
config/db/db_manager.js

@@ -48,7 +48,7 @@ module.exports = {
     },
     connect:function (env="local") {
         var config = require("../config.js");
-        var dbURL = 'mongodb://' + config.current.server + ":" + config.current.port + '/scConstruct';
+        var dbURL = 'mongodb://' + config[env].server + ":" + config[env].port + '/scConstruct';
         if(config[env].options){
             mg.connect(dbURL,config[env].options);
         }else {

+ 2 - 2
modules/glj/controllers/glj_controller.js

@@ -325,7 +325,7 @@ class GLJController extends BaseController {
 
             // 查找对应单价文件的项目工料机数据
             let unitPriceModel = new UnitPriceModel();
-            let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id);
+            let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id,projectId);
             // 复制成功后更改project数据
             if (!copyResult) {
                 throw '复制数据失败';
@@ -385,7 +385,7 @@ class GLJController extends BaseController {
 
             // 查找对应单价文件的项目工料机数据
             let unitPriceModel = new UnitPriceModel();
-            let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, addResult.id);
+            let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, addResult.id,projectId);
             // 复制成功后更改project数据
             if (!copyResult) {
                 throw '复制数据失败';

+ 37 - 0
modules/glj/models/mix_ratio_model.js

@@ -79,6 +79,43 @@ class MixRatioModel extends BaseModel {
         return result.ok !== undefined && result.ok === 1;
     }
 
+    //复制组成物到切换后的组成物映射表
+    async copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap){
+        let currentMap = {},targetMap = {}, insertData = [];
+        //取原单价文件所有的的组成物
+        let currentList = await  this.db.find({'unit_price_file_id':currentUnitPriceId});
+        // 过滤mongoose格式
+        currentList = JSON.stringify(currentList);
+        currentList = JSON.parse(currentList);
+        this.getConnectionMap(currentMap,currentList);
+
+        //切换后的单价文件所有的的组成物
+        let targetList = await this.db.find({'unit_price_file_id':changeUnitPriceId});
+        this.getConnectionMap(targetMap,targetList);
+        for(let ckey in currentMap){
+            if(targetMap[ckey]){//如果切换后的单价文件已经存在,则不用复
+                continue;
+            }
+            if(gljMap[ckey]){//在本项目中有用到
+                for(let ratio of  currentMap[ckey]){
+                    delete ratio._id;  // 删除原有id信息
+                    delete ratio.id;
+                    ratio.unit_price_file_id = changeUnitPriceId;
+                    insertData.push(ratio);
+                }
+            }
+        }
+        return insertData.length > 0 ? this.add(insertData) : true;
+    }
+    getConnectionMap(map,list){
+        for(let l of list){
+            if(map[l.connect_key]){
+                map[l.connect_key].push(l);
+            }else {
+                map[l.connect_key] = [l];
+            }
+        }
+    }
 }
 
 export default MixRatioModel;

+ 21 - 7
modules/glj/models/unit_price_model.js

@@ -14,6 +14,8 @@ import _ from "lodash";
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
 let collectionName = 'unit_price';
 let decimal_facade = require('../../main/facade/decimal_facade');
+let gljListModel = mongoose.model("glj_list");
+
 
 class UnitPriceModel extends BaseModel {
 
@@ -329,7 +331,7 @@ class UnitPriceModel extends BaseModel {
      * @param {Number} changeUnitPriceId
      * @return {Promise}
      */
-    async copyNotExist(currentUnitPriceId, changeUnitPriceId) {
+    async copyNotExist(currentUnitPriceId, changeUnitPriceId,projectId) {
         let result = false;
         // 首先查找原单价文件id下的数据
         let currentUnitList = await this.findDataByCondition({unit_price_file_id: currentUnitPriceId}, null, false);
@@ -340,6 +342,13 @@ class UnitPriceModel extends BaseModel {
         currentUnitList = JSON.stringify(currentUnitList);
         currentUnitList = JSON.parse(currentUnitList);
 
+        let gljList = await gljListModel.find({'project_id':projectId});
+        let gljMap = {};//用来记录glj的映射表,本项目有使用的工料机才需要copy过去
+        for(let g of gljList){
+            let g_index = this.getIndex(g,['code','name','specs','unit','type']);
+            gljMap[g_index] = g;
+        }
+
         let codeList = [];
         let nameList =[];
         for (let tmp of currentUnitList) {
@@ -364,13 +373,18 @@ class UnitPriceModel extends BaseModel {
             if (targetUnitList !== null && targetUnitList[t_index] !== undefined) {
                 continue;
             }
-            // 删除原有id信息
-            delete tmp._id;
-            delete tmp.id;
-            tmp.unit_price_file_id = changeUnitPriceId;
-            insertData.push(tmp);
+            if(gljMap[t_index]){//如果本项目有用到才复制
+                delete tmp._id;  // 删除原有id信息
+                delete tmp.id;
+                tmp.unit_price_file_id = changeUnitPriceId;
+                insertData.push(tmp);
+            }
         }
-        return insertData.length > 0 ? this.add(insertData) : true;
+        let uResult = insertData.length > 0 ? this.add(insertData) : true;
+        let mixRatioModel = new MixRatioModel();
+        let mResult = await mixRatioModel.copyNotExist(currentUnitPriceId, changeUnitPriceId,gljMap);//复制组成物
+        return uResult&&mResult;
+
     }