Просмотр исходного кода

Merge branch '1.0.0_online' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost into 1.0.0_online

zhongzewei 7 лет назад
Родитель
Сommit
dabfe05956

+ 23 - 16
modules/glj/controllers/glj_controller.js

@@ -14,6 +14,7 @@ import UnitPriceFileModel from "../models/unit_price_file_model";
 let logger = require("../../../logs/log_helper").logger;
 let consts = require('../../main/models/project_consts');
 let glj_type_util = require('../../../public/cache/std_glj_type_util');
+let ration_glj_facade = require('../../ration_glj/facade/ration_glj_facade');
 let mongoose = require('mongoose');
 let ration = mongoose.model('ration');
 let projectModel = mongoose.model('projects');
@@ -244,23 +245,29 @@ class GLJController extends BaseController {
             let gljList = data.gljList, parentInfo = data.parentInfo,mixRatios = [];
             let projectGljModel = new GLJListModel();
             let mixRatioModel = new MixRatioModel();
-            for(let g of gljList){
-                let newProjectGLJ = await projectGljModel.addList(g,parentInfo.unit_price_file_id);
-                let mixRatio = {
-                    glj_id:newProjectGLJ.glj_id,
-                    consumption:0,
-                    unit_price_file_id:parentInfo.unit_price_file_id,
-                    connect_key:parentInfo.connect_key,
-                    type: newProjectGLJ.type,
-                    code: newProjectGLJ.code,
-                    specs:newProjectGLJ.specs,
-                    name:newProjectGLJ.name,
-                    unit:newProjectGLJ.unit,
-                    model:newProjectGLJ.model
-                };
-                newProjectGLJ.ratio_data = await mixRatioModel.add(mixRatio);
-                mixRatios.push(newProjectGLJ);
+            if(gljList.length > 0){
+                let [unitFileId,ext] = await ration_glj_facade.prepareExtData(gljList[0].project_id,request.session.sessionCompilation);
+                console.log(ext);
+                for(let g of gljList){
+                    let newProjectGLJ = await projectGljModel.addList(g,unitFileId,ext);
+                    let mixRatio = {
+                        glj_id:newProjectGLJ.glj_id,
+                        consumption:0,
+                        unit_price_file_id:unitFileId,
+                        connect_key:parentInfo.connect_key,
+                        type: newProjectGLJ.type,
+                        code: newProjectGLJ.code,
+                        specs:newProjectGLJ.specs,
+                        name:newProjectGLJ.name,
+                        unit:newProjectGLJ.unit,
+                        model:newProjectGLJ.model
+                    };
+                    newProjectGLJ.ratio_data = await mixRatioModel.add(mixRatio);
+                    mixRatios.push(newProjectGLJ);
+                }
+
             }
+
             result.data = mixRatios;
         }catch (err){
             logger.err(err);

+ 1 - 1
modules/main/controllers/bills_controller.js

@@ -183,7 +183,7 @@ module.exports = {
         try {
             let data = req.body.data;
             data = JSON.parse(data);
-            let pasteResult = await bill_facade.pasteBlock(data);
+            let pasteResult = await bill_facade.pasteBlock(data,req.session.sessionCompilation);
             result.data = pasteResult;
         }catch (err){
             logger.err(err);

+ 13 - 10
modules/main/facade/bill_facade.js

@@ -72,9 +72,9 @@ module.exports={
         }
        return result;
     },
-    pasteBlock : async function(data){
+    pasteBlock : async function(data,compilation){
         let pasteTasks = [
-            pasteRationsAndRationGLJ(data.rations,data.ration_gljs),//这一步会花费比较多时间
+            pasteRationsAndRationGLJ(data.rations,data.ration_gljs,compilation),//这一步会花费比较多时间
             pasteOtherData(data)
         ];
         let [rationsAndRationGLJ,resultMap] = await Promise.all(pasteTasks);
@@ -148,19 +148,22 @@ async function pasteOtherData(data) {
     return {bills:bills,quantity_details:quantity_details,ration_coes:ration_coes,ration_installations:ration_installations,ration_templates:ration_templates,updateData:updateData}
 }
 
-async function pasteRationsAndRationGLJ (rations,ration_gljs) {
+async function pasteRationsAndRationGLJ (rations,ration_gljs,compilation) {
     let projectGljModel = new GLJListModel();
-    let gljMap = {};
-    let new_ration_gljs=[];
+    let gljMap = {}, new_ration_gljs=[],projectID=null;
+    if(rations.length > 0) projectID = rations[0].projectID;
+    if(projectID==null && ration_gljs.length > 0) projectID = ration_gljs[0].projectID;
+    if(projectID == null) return {rations:rations,new_ration_gljs:new_ration_gljs};
+    let [unitFileId,ext] = await ration_glj_facade.prepareExtData(projectID,compilation);
     //先根据定额类型的工料机,插入到项目工料机中
     for(let r of rations){
         if(r.type == rationType.gljRation){
-            await getProjectGLJ(r,rationKeyArray,gljMap);
+            await getProjectGLJ(r,rationKeyArray,gljMap,unitFileId,ext);
         }
     }
 
     for(let rg of ration_gljs){
-        await getProjectGLJ(rg,gljKeyArray,gljMap);
+        await getProjectGLJ(rg,gljKeyArray,gljMap,unitFileId,ext);
         let temRecord = ration_glj_facade.createNewRecord(rg);
         rg.rcode?temRecord.rcode = rg.rcode:'';
         rg.hasOwnProperty("customQuantity")?temRecord.customQuantity = rg.customQuantity:'';
@@ -170,16 +173,16 @@ async function pasteRationsAndRationGLJ (rations,ration_gljs) {
     rations.length>0?await insertMany(rations,ration_Model):'';
     new_ration_gljs.length>0?await insertMany(new_ration_gljs,ration_glj_Model):'';
 
-    return{rations:rations,new_ration_gljs:new_ration_gljs};
+    return {rations:rations,new_ration_gljs:new_ration_gljs};
 
-    async function getProjectGLJ (glj,keyArray,gljMap) {
+    async function getProjectGLJ (glj,keyArray,gljMap,unitFileId,ext) {
         let keyIndex = projectGljModel.getIndex(glj,keyArray);
         let pgljResult = null;
         if(gljMap[keyIndex]){
             pgljResult = gljMap[keyIndex]
         }else {
             let p_glj = ration_glj_facade.getGLJSearchInfo(glj);
-            pgljResult = await projectGljModel.addList(p_glj);//逐条添加到项目工料机
+            pgljResult = await projectGljModel.addList(p_glj,unitFileId,ext);//逐条添加到项目工料机
             gljMap[keyIndex] = pgljResult;
         }
         setResult(glj,pgljResult);

+ 2 - 1
modules/ration_glj/facade/ration_glj_facade.js

@@ -51,7 +51,8 @@ module.exports = {
     createNewRecord:createNewRecord,
     getGLJSearchInfo:getGLJSearchInfo,
     updateRationGLJFromDoc:updateRationGLJFromDoc,
-    getGLJLibByEngineerID:getGLJLibByEngineerID
+    getGLJLibByEngineerID:getGLJLibByEngineerID,
+    prepareExtData:prepareExtData
 }
 
 let operationMap = {

+ 6 - 0
public/web/gljUtil.js

@@ -302,6 +302,12 @@ let gljUtil = {
                 gljType.MACHINE_COMPOSITION,gljType.MACHINE_LABOUR,gljType.FUEL_POWER_FEE,gljType.DEPRECIATION_FEE,gljType.INSPECTION_FEE,gljType.MAINTENANCE,
                 gljType.DISMANTLING_FREIGHT_FEE,gljType.VERIFICATION_FEE,gljType.OTHER_FEE,gljType.EQUIPMENT,gljType.MANAGEMENT_FEE,gljType.PROFIT,gljType.GENERAL_RISK_FEE]
     },
+    sortRationGLJ:function (list) {
+        list = _.sortByAll(list, [function (item) {
+            return _.indexOf(gljTypeSeq,item.type)
+        }, "code"])
+        return list;
+    },
     fixedFlag : {
         // 分部分项工程
         SUB_ENGINERRING: 1,

+ 2 - 2
web/building_saas/main/js/models/ration_glj.js

@@ -200,7 +200,7 @@ let ration_glj = {
         };
 
         ration_glj.prototype.addToMainTree = function (datas) {
-            datas = sortRationGLJ(datas);
+            datas = gljUtil.sortRationGLJ(datas);
             for (let data of datas) {
                 if (this.needShowToTree(data)) {
                     gljOprObj.setGLJPrice(data);
@@ -874,7 +874,7 @@ let ration_glj = {
             let gljList = _.filter(this.datas, function (n) {
                 return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
             });
-            gljList = sortRationGLJ(gljList);
+            gljList = gljUtil.sortRationGLJ(gljList);
             return gljOprObj.combineWithProjectGlj(gljList);
         };
         ration_glj.prototype.transferToNodeData = function (data) {

+ 3 - 10
web/building_saas/main/js/views/glj_view.js

@@ -558,7 +558,7 @@ var gljOprObj = {
         }
         this.sheetData = gljList;
         this.sheet.setRowCount(0);
-        this.sheetData = sortRationGLJ(this.sheetData);
+        this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
         this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
         sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
         //初始选择
@@ -587,7 +587,7 @@ var gljOprObj = {
         let selected = this.sheet.getSelections();
         this.combineWithProjectGlj(this.sheetData);
         this.sheet.setRowCount(0);
-        this.sheetData = sortRationGLJ(this.sheetData);
+        this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
         this.sumQuantity();//计算总消耗量
         this.addMixRatioToShow();//显示组成物信息
         this.initRationTree(init,this.getUnitPriceCodeMap());
@@ -827,7 +827,7 @@ var gljOprObj = {
             }
             temRationGLJs.push(tem);
         }
-        temRationGLJs = _.sortBy(temRationGLJs, 'code');
+        temRationGLJs = gljUtil.sortRationGLJ(temRationGLJs);
         return temRationGLJs;
     },
     showQuantityDetailData: function (node) {
@@ -1644,13 +1644,6 @@ function getDecimal(fieldID, node) {
 }
 
 
-function sortRationGLJ(list) {
-    list = _.sortByAll(list, [function (item) {
-        return _.indexOf(gljTypeSeq,item.type)
-    }, "code"])
-    return list;
-}
-
 function compareRationGLJ(a, b) {
     if ((a.type + "") < (b.type + "")) {
         return true

+ 1 - 1
web/building_saas/main/js/views/main_tree_col.js

@@ -442,7 +442,7 @@ let MainTreeCol = {
         let tips="";
         let ration_glj = projectObj.project.ration_glj;
         let gljList = gljOprObj.filterGljByRation(node.data, ration_glj.datas);
-        gljList = sortRationGLJ(gljList);
+        gljList = gljUtil.sortRationGLJ(gljList);
         for(let glj of gljList){
             tips += `${glj.code} ${glj.name}${glj.specs ? '&nbsp;&nbsp;&nbsp;' + glj.specs : ''}&nbsp;&nbsp&nbsp;${glj.unit}&nbsp;&nbsp;&nbsp;${glj.quantity}<br>`;
         }

+ 4 - 3
web/building_saas/main/js/views/project_glj_view.js

@@ -194,11 +194,12 @@ projectGljObject={
             if(gljId !== projectObj.project.projectGLJ.getRatioId){//两个id不一致说明不是最新的请求,不用往下执行。
                 return;
             }
-            let rationList =[];
+            let ratioList =[];
             for(let glj of data){
-                rationList.push(me.getMixRatioSheetData(glj)) ;
+                ratioList.push(me.getMixRatioSheetData(glj)) ;
             }
-            me.mixRatioData = rationList;
+            ratioList = gljUtil.sortRationGLJ(ratioList);
+            me.mixRatioData = ratioList;
             me.mixRatioSheet.setRowCount(0);
             sheetCommonObj.showData(me.mixRatioSheet, me.mixRatioSetting,me.mixRatioData);
             me.mixRatioSheet.setRowCount(me.mixRatioData.length);