Bläddra i källkod

中间件、工料机单价等同步

chenshilong 5 år sedan
förälder
incheckning
b3cf2766e4

+ 2 - 2
modules/main/controllers/project_controller.js

@@ -39,14 +39,14 @@ module.exports = {
         // Project.getFilterData(data.project_id, ['bills', 'projectGLJ'], function (err, result) {
         //     console.log(result);
         // });
-        //test
+        const isReport = false;
         Project.getData(data.project_id, function (err, message, result) {
             if (!err) {
                 callback(req, res, err, message, result);
             } else {
                 callback(req, res, err, message, null);
             }
-        }, req.session.sessionUser.id);
+        }, isReport, req.session.sessionUser.id);
     },
     markUpdateProject:async function (req,res) {
         let result={

+ 15 - 1
modules/main/models/bills.js

@@ -32,10 +32,24 @@ class billsModel extends baseModel {
         super(bills);
     };
 
-    getData (projectID, callback) {
+    getData (projectID, callback, isReport = false) {
         //已经改成真删除了 {'$or': [{projectID: projectID, deleteInfo: null}, {projectID: projectID, 'deleteInfo.deleted': {$in: [null, false]}}]}
         this.model.find({projectID: projectID}, '-_id', function(err, datas){
             if (!err) {
+                if (isReport){   // 调价中间件机制
+                    for (let i = 0; i < datas.length; i++) {
+                       let fees = datas[i]._doc.fees;
+                       if (fees){
+                           for (let i = 0; i < fees.length; i++) {
+                               let doc = fees[i]._doc;
+                               if (doc){
+                                   if (doc.tenderTotalFee) doc.totalFee = doc.tenderTotalFee;
+                                   if (doc.tenderUnitFee) doc.unitFee = doc.tenderUnitFee;
+                               }
+                           }
+                       }
+                    }
+                };
                 callback(0, projectConsts.BILLS, datas);
             } else {
                 callback(1, projectConsts.BILLS, null);

+ 3 - 3
modules/main/models/project.js

@@ -97,7 +97,7 @@ Project.prototype.save = function(datas, callback){
     me.datas = [];
 };
 
-Project.prototype.getData = function(projectID, callback, userID){
+Project.prototype.getData = function(projectID, callback, isReport, userID){
     var functions = [];
     var itemName;
     let firstTime = +new Date();
@@ -106,7 +106,7 @@ Project.prototype.getData = function(projectID, callback, userID){
             return function (cb) {
                 moduleMap[itemName].getData(projectID, function(err, moduleName, data){
                     cb(err, {moduleName: moduleName, data: data})
-                }, userID)
+                }, isReport, userID)
             }
         })(itemName))
     }
@@ -130,7 +130,7 @@ Project.prototype.getFilterData = function (projectID, filter, callback) {
             if (moduleMap[moduleName]) {
                 moduleMap[moduleName].getData(projectID, function (err, name, data) {
                     cb(err, {'moduleName': name, 'data': data})
-                });
+                }, true);     // 所有报表只显示调价后的数据,这里传入一个标记true,子方法会将调价后的值赋给调价前的字段,这样报表可以不用动。
             } else if (moduleName === projectConsts.PROJECTGLJ) {
                 try {
                     if (isNaN(projectID) || projectID <= 0) {

+ 21 - 1
modules/main/models/ration.js

@@ -17,9 +17,29 @@ class rationModel extends baseModel {
         super(ration);
     }
 
-    getData (projectID, callback) {
+    getData (projectID, callback, isReport = false) {
         ration.find({projectID: projectID}, '-_id', function(err, datas){//{'$or': [{projectID: projectID, deleteInfo: null}, {projectID: projectID, 'deleteInfo.deleted': {$in: [null, false]}}]}
             if (!err) {
+                if (isReport){  // 调价中间件机制
+                    for (let i = 0; i < datas.length; i++) {
+                        let coe = datas[i]._doc.rationQuantityCoe;
+                        if ((!coe) || (coe == '0')) coe = 1;
+                        //如有调价,则需要改动
+                        datas[i]._doc.quantity = parseFloat(datas[i]._doc.quantity) * parseFloat(coe);
+                        datas[i]._doc.contain = parseFloat(datas[i]._doc.contain) * parseFloat(coe);
+
+                        let fees = datas[i]._doc.fees;
+                        if (fees){
+                            for (let i = 0; i < fees.length; i++) {
+                                let doc = fees[i]._doc;
+                                if (doc){
+                                    if (doc.tenderTotalFee) doc.totalFee = doc.tenderTotalFee;
+                                    if (doc.tenderUnitFee) doc.unitFee = doc.tenderUnitFee;
+                                }
+                            }
+                        }
+                    }
+                };
                 callback(0, projectConsts.RATION, datas);
             } else {
                 callback(1, '', null);

+ 169 - 170
modules/pm/controllers/pm_controller.js

@@ -35,14 +35,14 @@ import multiparty from 'multiparty';
 let rp = require('request-promise');
 const commonUtil = require('../../../public/common_util');
 //统一回调函数
-let callback = function(req, res, err, message, data){
-    res.json({error: err, message: message, data: data});
+let callback = function (req, res, err, message, data) {
+    res.json({ error: err, message: message, data: data });
 };
 
 
 module.exports = {
     checkRight: function (req, res) {
-        if(typeof req.body.data === 'object'){
+        if (typeof req.body.data === 'object') {
             req.body.data = JSON.stringify(req.body.data);
         }
         let data = JSON.parse(req.body.data);
@@ -61,7 +61,7 @@ module.exports = {
             let shareInfo = null;
             let isOpenShareProject = false;
             //判断是否是打开分享的项目,分享项目shareInfo不为null
-            if(userId !== result.userID){
+            if (userId !== result.userID) {
                 shareInfo = await pm_facade.getShareInfo(userId, result.ID);
                 isOpenShareProject = true;
             }
@@ -75,7 +75,7 @@ module.exports = {
             callback(false);
         });
     },
-    getProjects: async function(req, res){
+    getProjects: async function (req, res) {
          await ProjectsData.getUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, function(err, message, projects){
             if (projects) {
                 callback(req, res, err, message, projects);
@@ -85,8 +85,8 @@ module.exports = {
         });
     },
     updateProjects: async function (req, res) {
+        let data = JSON.parse(req.body.data);
         try {
-            let data = JSON.parse(req.body.data);
             await ProjectsData.updateUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, req.session.sessionCompilation, data.updateData, function (err, message, data) {
                 if (err === 0) {
                     callback(req, res, err, message, data);
@@ -100,7 +100,7 @@ module.exports = {
         }
     },
     // CSL, 2017-12-14 该方法用于项目属性:提交保存混合型数据,这些数据来自不同的表,包括projects.property、ration、bills、labour_coes.
-    updateMixDatas: async function(req, res){
+    updateMixDatas: async function (req, res) {
         let datas = JSON.parse(req.body.data).mixDataArr;
         let functions = [];
 
@@ -110,7 +110,7 @@ module.exports = {
             }
         };
 
-        function updateLC(){
+        function updateLC() {
             return function (cb) {
                 datas.labourCoes.updateData.projectID = datas.projectID;
                 labourCoe.save(datas.labourCoes.updateData, cb);
@@ -118,84 +118,84 @@ module.exports = {
         };
 
         // 项目属性
-        if (Object.keys(datas.properties).length > 0){
+        if (Object.keys(datas.properties).length > 0) {
             //基本信息特殊处理,更新建设项目
-            if(datas.properties['property.basicInformation']){
+            if (datas.properties['property.basicInformation']) {
                 let constructionProject = await pm_facade.getConstructionProject(datas.projectID);
-                if(constructionProject){
-                    functions.push(updateFunc(projectModel, {ID: constructionProject.ID}, {'property.basicInformation': datas.properties['property.basicInformation']}));
+                if (constructionProject) {
+                    functions.push(updateFunc(projectModel, { ID: constructionProject.ID }, { 'property.basicInformation': datas.properties['property.basicInformation'] }));
                 }
                 delete datas.properties['property.basicInformation'];
             }
-            functions.push(updateFunc(projectModel, {ID: datas.projectID}, datas.properties));
+            functions.push(updateFunc(projectModel, { ID: datas.projectID }, datas.properties));
         };
 
         //选项
-        if(datas.options && datas.options.updateData){
-            functions.push(updateFunc(optionModel, {user_id: req.session.sessionUser.id, compilation_id: req.session.sessionCompilation._id}, {'options.GENERALOPTS': datas.options.updateData}));
+        if (datas.options && datas.options.updateData) {
+            functions.push(updateFunc(optionModel, { user_id: req.session.sessionUser.id, compilation_id: req.session.sessionCompilation._id }, { 'options.GENERALOPTS': datas.options.updateData }));
         }
 
         // 人工系数
-        if (datas.labourCoes&&datas.labourCoes.updateData){
+        if (datas.labourCoes && datas.labourCoes.updateData) {
             functions.push(updateLC());
         };
 
         // 清单:每文档doc只存储一条清单,每条清单都必须定位一次文档,无法合并处理
-        if (datas.bills.length > 0){
-            for (let bill of datas.bills){
-                functions.push(updateFunc(billsModel, {projectID: datas.projectID, ID: bill.ID, deleteInfo: null}, bill));
+        if (datas.bills && datas.bills.length > 0) {
+            for (let bill of datas.bills) {
+                functions.push(updateFunc(billsModel, { projectID: datas.projectID, ID: bill.ID, deleteInfo: null }, bill));
             };
         };
 
         // 定额:每文档doc只存储一条定额,每条定额都必须定位一次文档,无法合并处理
-        if (datas.rations.length > 0){
-            for (let ration of datas.rations){
-                functions.push(updateFunc(rationsModel, {projectID: datas.projectID, ID: ration.ID, deleteInfo: null}, ration));
+        if (datas.rations && datas.rations.length > 0) {
+            for (let ration of datas.rations) {
+                functions.push(updateFunc(rationsModel, { projectID: datas.projectID, ID: ration.ID, deleteInfo: null }, ration));
             };
         };
 
-        asyncTool.parallel(functions, function(err, result){
+        asyncTool.parallel(functions, function (err, result) {
             {
                 if (!err) {
-                    res.json({error: 0, message: err, data: result});
+                    res.json({ error: 0, message: err, data: result });
                 } else {
-                    res.json({error: 1, message: err, data: null});
+                    res.json({ error: 1, message: err, data: null });
                 }
             }
         });
     },
-    updateFiles: async function(req, res){
+    updateFiles: async function (req, res) {
         let data = JSON.parse(req.body.data);
         let updateDatas = data.updateDatas;
         await ProjectsData.udpateUserFiles(req.session.sessionUser.id, updateDatas, function (err, message, data) {
             callback(req, res, err, message, data);
         });
     },
-    defaultSettings: async function(req, res){
-        try{
+    defaultSettings: async function (req, res) {
+        try {
             let data = JSON.parse(req.body.data);
             let projectID = data.projectID;
             let defaultSettingSc = await ProjectsData.defaultSettings(req.session.sessionUser.id, req.session.sessionCompilation, projectID);
-            if(!defaultSettingSc){
+            if (!defaultSettingSc) {
                 throw '恢复失败';
             }
-            res.json({error: 0, message: '恢复成功', data: null});
+            res.json({ error: 0, message: '恢复成功', data: null });
         }
-        catch(error){
+        catch (error) {
             console.log(error);
-            res.json({error: 1, message: error, data: null});
-        }
-    },
- /*   copyProjects: function (req, res) {
-        let data = JSON.parse(req.body.data);
-        ProjectsData.copyUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, data.updateData, function (err, message, data) {
-            if (err === 0) {
-                callback(req, res, err, message, data);
-            } else {
-                callback(req, res, err, message, null);
-            }
-        });
-    },*/
+            res.json({ error: 1, message: error, data: null });
+        }
+    },
+    /*   copyProjects: function (req, res) {
+           let data = JSON.parse(req.body.data);
+           ProjectsData.copyUserProjects(req.session.sessionUser.id, req.session.sessionCompilation._id, data.updateData, function (err, message, data) {
+               if (err === 0) {
+                   callback(req, res, err, message, data);
+               } else {
+                   callback(req, res, err, message, null);
+               }
+           });
+       },*/
     rename: function (req, res) {
         let data = JSON.parse(req.body.data);
         ProjectsData.rename(req.session.sessionUser.id, req.session.sessionCompilation._id, data, function (err, message) {
@@ -203,8 +203,8 @@ module.exports = {
         });
     },
     //project getData接口
-    getData: function(projectID, callback, userID) {
-        projectModel.findOne({$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], ID: projectID}, '-_id').then(async function (project) {
+    getData: function (projectID, callback, isReport, userID) {
+        projectModel.findOne({ $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], ID: projectID }, '-_id').then(async function (project) {
             if (!project) {
                 callback('', consts.projectConst.PROJECT_INFO, {});
             }
@@ -213,10 +213,10 @@ module.exports = {
                 await engineeringLibModel.getEngineering(project.property.engineering_id) : null;
             let projInfo = project._doc;
             if (engineeringInfo !== null) {
-                if(engineeringInfo.billsGuidance_lib){
-                    for(let billsGuidanceLib of engineeringInfo.billsGuidance_lib){
-                        let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ID: billsGuidanceLib.id});
-                        if(stdBillsGuidanceLib){
+                if (engineeringInfo.billsGuidance_lib) {
+                    for (let billsGuidanceLib of engineeringInfo.billsGuidance_lib) {
+                        let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ ID: billsGuidanceLib.id });
+                        if (stdBillsGuidanceLib) {
                             billsGuidanceLib.type = stdBillsGuidanceLib.type ? stdBillsGuidanceLib.type : 1;
                         }
                     }
@@ -245,10 +245,10 @@ module.exports = {
             callback(err, consts.projectConst.PROJECT_INFO, {});
         });
     },
-    getProject: function(req, res){
+    getProject: function (req, res) {
         let data = JSON.parse(req.body.data);
         let projectID = data.proj_id;
-        ProjectsData.getUserProject(req.session.sessionUser.id, data.proj_id, async function(err, message, data){
+        ProjectsData.getUserProject(req.session.sessionUser.id, data.proj_id, async function (err, message, data) {
             if (err === 0) {
                 let engineeringLibModel = new EngineeringLibModel();
                 let engineeringInfo = data !== null && data.property.engineering_id !== undefined ?
@@ -256,10 +256,10 @@ module.exports = {
                 let strData = JSON.stringify(data);
                 let projInfo = JSON.parse(strData);
                 if (engineeringInfo !== null) {
-                    if(engineeringInfo.billsGuidance_lib){
-                        for(let billsGuidanceLib of engineeringInfo.billsGuidance_lib){
-                            let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ID: billsGuidanceLib.id});
-                            if(stdBillsGuidanceLib){
+                    if (engineeringInfo.billsGuidance_lib) {
+                        for (let billsGuidanceLib of engineeringInfo.billsGuidance_lib) {
+                            let stdBillsGuidanceLib = await stdBillsGuidanceLibModel.findOne({ ID: billsGuidanceLib.id });
+                            if (stdBillsGuidanceLib) {
                                 billsGuidanceLib.type = stdBillsGuidanceLib.type ? stdBillsGuidanceLib.type : 1;
                             }
                         }
@@ -293,12 +293,11 @@ module.exports = {
         });
     },
     // 项目管理首页
-    index: async function(request, response) {
-        // 上线后删除,处理旧的分享数据
-        // await pm_facade.prepareShareList();
+    index: async function (request, response) {
+        //await pm_facade.prepareShareList();
         // 获取编办信息
         let sessionCompilation = request.session.sessionCompilation;
-        if (sessionCompilation === undefined ||sessionCompilation ===null) {
+        if (sessionCompilation === undefined || sessionCompilation === null) {
             return response.redirect('/logout');
         }
         let compilationModel = new CompilationModel();
@@ -307,7 +306,6 @@ module.exports = {
         request.session.sessionCompilation = compilationData;
         sessionCompilation = request.session.sessionCompilation;
         //更新用户的使用过的费用定额列表
-        //是否第一次进入该费用定额
         let isFirst = await pm_facade.isFirst(request.session.sessionUser.id, compilationData._id.toString());
         // 清单计价
         let billValuation = sessionCompilation.bill_valuation !== undefined ?
@@ -322,7 +320,7 @@ module.exports = {
             sessionCompilation.ration_valuation : [];
         rationValuation = await engineeringLibModel.getLib(rationValuation);
         let absoluteUrl = compilationData.overWriteUrl ? request.app.locals.rootDir + compilationData.overWriteUrl : request.app.locals.rootDir;
-        let overWriteUrl = fs.existsSync(absoluteUrl) && fs.statSync(absoluteUrl).isFile()? compilationData.overWriteUrl : null;
+        let overWriteUrl = fs.existsSync(absoluteUrl) && fs.statSync(absoluteUrl).isFile() ? compilationData.overWriteUrl : null;
         //欢迎页显示控制
         let [isShow,context,showTime] = await pm_facade.getWelcomeInfo(sessionCompilation._id,request.session.sessionUser,request.session.compilationVersion.includes('免费'));
         const unreadShareList = await pm_facade.getUnreadShareListByCompilation(request.session.sessionUser.id, sessionCompilation._id);
@@ -347,7 +345,7 @@ module.exports = {
         response.render('building_saas/pm/html/project-management.html', renderData);
     },
     //第一次进入该费用定额时准备的初始数据
-    prepareInitialData: async function(request, response) {
+    prepareInitialData: async function (request, response) {
         try {
             const data = {
                 userID: request.session.sessionUser.id,
@@ -356,19 +354,19 @@ module.exports = {
             };
             await redirectToImportServer(data, 'prepareInitialData', request);
             callback(request, response, 0, 'success', null);
-        } catch(err) {
+        } catch (err) {
             console.log(err);
             callback(request, response, 1, err.toString(), null);
         }
     },
     // 获取单价文件列表
-    getUnitFileList: async function(request, response) {
+    getUnitFileList: async function (request, response) {
         let data = request.body.data;
         try {
             data = JSON.parse(data);
             let projectId = data.parentID !== undefined ? data.parentID : 0;
             if (isNaN(projectId) && projectId <= 0) {
-                throw {msg: 'id数据有误!', err: 1};
+                throw { msg: 'id数据有误!', err: 1 };
             }
             /*// 获取对应建设项目下所有的单位工程id
             let idList = await ProjectsData.getTenderByProjectId(projectId);
@@ -380,7 +378,7 @@ module.exports = {
             let unitPriceFileData = await unitPriceFileModel.getDataByRootProject(projectId);
 
             if (unitPriceFileData === null) {
-                throw {msg: '不存在对应单价文件', err: 0};
+                throw { msg: '不存在对应单价文件', err: 0 };
             }
 
             // 整理数据
@@ -400,17 +398,17 @@ module.exports = {
             callback(request, response, error.err, error.msg, responseData);
         }
     },
-    getFeeRateFileList:async function(request, response) {
+    getFeeRateFileList: async function (request, response) {
         let data = request.body.data;
         try {
             data = JSON.parse(data);
             let projectId = data.parentID !== undefined ? data.parentID : 0;
             if (isNaN(projectId) && projectId <= 0) {
-                throw {msg: 'id数据有误!', err: 1};
+                throw { msg: 'id数据有误!', err: 1 };
             }
             // 获取对应建设项目下所有的单位工程id
             let feeRateFileList = await fee_rate_facade.getFeeRatesByProject(projectId);
-            callback(request, response, 0, '',feeRateFileList );
+            callback(request, response, 0, '', feeRateFileList);
         } catch (error) {
             console.log(error);
             let responseData = error.err === 1 ? null : [];
@@ -451,45 +449,45 @@ module.exports = {
         }
     },
 
-    getGCDatas: async function(request, response) {
+    getGCDatas: async function (request, response) {
         let userID = request.session.sessionUser.id;
         let compilatoinId = request.session.sessionCompilation._id;
         let rst = [];
         let _projs = Object.create(null), _engs = Object.create(null), prefix = 'ID_';
-        try{
+        try {
             let gc_unitPriceFiles = await ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
             let gc_feeRateFiles = await ProjectsData.getGCFiles(fileType.feeRateFile, userID);
             let gc_tenderFiles = await ProjectsData.getGCFiles(projType.tender, userID);
-            for(let i = 0, len = gc_unitPriceFiles.length; i < len; i++){
+            for (let i = 0, len = gc_unitPriceFiles.length; i < len; i++) {
                 let gc_uf = gc_unitPriceFiles[i];
                 let theProj = _projs[prefix + gc_uf.root_project_id] || null;
-                if(!theProj){
+                if (!theProj) {
                     let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_uf.root_project_id]);
-                    if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
+                    if (tempProj.length > 0 && tempProj[0].projType !== projType.folder) {
                         theProj = _projs[prefix + gc_uf.root_project_id] = tempProj[0]._doc;
                         buildProj(theProj);
                     }
                 }
-                if(theProj){
+                if (theProj) {
                     theProj.unitPriceFiles.push(gc_uf);
                 }
             }
-            for(let i = 0, len = gc_feeRateFiles.length; i < len; i++){
+            for (let i = 0, len = gc_feeRateFiles.length; i < len; i++) {
                 let gc_ff = gc_feeRateFiles[i];
                 let theProj = _projs[prefix + gc_ff.rootProjectID] || null;
-                if(!theProj){
+                if (!theProj) {
                     let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_ff.rootProjectID]);
-                    if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
+                    if (tempProj.length > 0 && tempProj[0].projType !== projType.folder) {
                         theProj = _projs[prefix + gc_ff.rootProjectID] = tempProj[0]._doc;
                         buildProj(theProj);
                     }
                 }
-                if(theProj) {
+                if (theProj) {
                     theProj.feeRateFiles.push(gc_ff);
                 }
             }
-            if(gc_tenderFiles.length > 0){
-                for(let i = 0, len = gc_tenderFiles.length; i < len; i++){
+            if (gc_tenderFiles.length > 0) {
+                for (let i = 0, len = gc_tenderFiles.length; i < len; i++) {
                     let gc_t = gc_tenderFiles[i];
                     let theProj = _projs[prefix + gc_t.ParentID] || null;
                     if(!theProj){
@@ -504,22 +502,22 @@ module.exports = {
                     }
                 }
             }
-            for(let i in _projs){
+            for (let i in _projs) {
                 rst.push(_projs[i]);
             }
-            function buildProj(proj){
+            function buildProj(proj) {
                 proj.children = [];
                 proj.unitPriceFiles = [];
                 proj.feeRateFiles = [];
             }
             callback(request, response, 0, 'success', rst);
         }
-        catch (error){
+        catch (error) {
             callback(request, response, true, error, null);
         }
     },
 
-    recGC: function(request, response){
+    recGC: function (request, response) {
         let userID = request.session.sessionUser.id,
             compilationId = request.session.sessionCompilation._id;
         let data = JSON.parse(request.body.data);
@@ -527,76 +525,76 @@ module.exports = {
         ProjectsData.recGC(userID, compilationId, nodes, function (err, msg, data) {
             callback(request, response, err, msg, data);
         });
-   },
+    },
 
-    delGC: async function(request, response){
+    delGC: async function (request, response) {
         let data = JSON.parse(request.body.data);
         let delDatas = data.delDatas;
         let bulkProjs = [], bulkUFs = [], bulkFFs = [];
-        try{
-            for(let data of delDatas){
-                if(data.updateType === 'Project'){
-                    bulkProjs.push({updateOne: {filter: {ID: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
+        try {
+            for (let data of delDatas) {
+                if (data.updateType === 'Project') {
+                    bulkProjs.push({ updateOne: { filter: { ID: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
                 }
-                else if(data.updateType === fileType.unitPriceFile){
-                    bulkUFs.push({updateOne: {filter: {id: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
+                else if (data.updateType === fileType.unitPriceFile) {
+                    bulkUFs.push({ updateOne: { filter: { id: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
                 }
-                else{
-                    bulkFFs.push({updateOne: {filter: {ID: data.ID}, update: {'deleteInfo.completeDeleted': true}}});
+                else {
+                    bulkFFs.push({ updateOne: { filter: { ID: data.ID }, update: { 'deleteInfo.completeDeleted': true } } });
                 }
             }
-            if(bulkProjs.length > 0){
+            if (bulkProjs.length > 0) {
                 await projectModel.bulkWrite(bulkProjs);
             }
-            if(bulkUFs.length > 0){
+            if (bulkUFs.length > 0) {
                 await unitPriceFileModel.bulkWrite(bulkUFs);
             }
-            if(bulkFFs.length > 0){
+            if (bulkFFs.length > 0) {
                 await feeRateFileModel.bulkWrite(bulkFFs);
             }
             callback(request, response, 0, 'success', null);
-        } catch(err){
+        } catch (err) {
             callback(request, response, 1, err, null);
         }
     },
-    moveProject:async function(req,res){
-        let result={
-            error:0
+    moveProject: async function (req, res) {
+        let result = {
+            error: 0
         };
         try {
             let data = req.body.data;
-            let rdata= await pm_facade.moveProject(data);
-            result.data= rdata;
-        }catch (err){
+            let rdata = await pm_facade.moveProject(data);
+            result.data = rdata;
+        } catch (err) {
             console.log(err);
-            result.error=1;
+            result.error = 1;
             result.message = err.message;
         }
         res.json(result);
     },
-    copyProjects:async function (req, res) {
-        let result={
-            error:0
+    copyProjects: async function (req, res) {
+        let result = {
+            error: 0
         };
         try {
-            let data = {dataString:req.body.data,userID:req.session.sessionUser.id,compilationID:req.session.sessionCompilation._id};
-            result = await redirectToImportServer(data,"copyProject",req);
-        }catch (err){
+            let data = { dataString: req.body.data, userID: req.session.sessionUser.id, compilationID: req.session.sessionCompilation._id };
+            result = await redirectToImportServer(data, "copyProject", req);
+        } catch (err) {
             console.log(err);
-            result.error=1;
+            result.error = 1;
             result.message = err.message;
         }
         res.json(result);
     },
-    projectShareInfo: async function(req, res){
-        try{
+    projectShareInfo: async function (req, res) {
+        try {
             const data = JSON.parse(req.body.data);
-            const shareList = await pm_facade.getShareList({projectID: data.projectID});
+            const shareList = await pm_facade.getShareList({ projectID: data.projectID });
             const shareInfoMap = await pm_facade.getShareInfoMap(null, shareList);
             const shareInfo = shareInfoMap[data.projectID] || [];
             callback(req, res, 0, 'success', shareInfo);
         }
-        catch (err){
+        catch (err) {
             callback(req, res, 1, err, null);
         }
     },
@@ -703,7 +701,7 @@ module.exports = {
             const rstTask = [
                 pm_facade.getRecentShareList(userID, count),
                 userModelObj.getContacts(userID)
-            ]
+            ];
             // 获取需要广播推送的单位工程
             // shareData数组的形式是以前需求需要,现在的需求下,shareData数组必定只有一个元素
             const emitTenders = await pm_facade.getShareInfoAfterChangePermission(permissionType, shareData[0].userID, projectID);
@@ -719,20 +717,20 @@ module.exports = {
             callback(req, res, 1, String(err), null);
         }
     },
-    receiveProjects: async function(req, res) {
+    receiveProjects: async function (req, res) {
         try {
-            let rst = {grouped: [], ungrouped: [], summaryInfo: null};
+            let rst = { grouped: [], ungrouped: [], summaryInfo: null };
             let userID = req.session.sessionUser.id;
             const shareList = await pm_facade.getShareList({ receiver: userID });
             const receiveProjectIDs = shareList.map(item => item.projectID);
             const compilation = req.session.sessionCompilation._id;
-            const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
-            const receiveProjects = await projectModel.find({ID: {$in: receiveProjectIDs}, compilation, $or: notDeleted}, '-_id').lean();
+            const notDeleted = [{ deleteInfo: null }, { 'deleteInfo.deleted': false }];
+            const receiveProjects = await projectModel.find({ ID: { $in: receiveProjectIDs }, compilation, $or: notDeleted }, '-_id').lean();
             //设置原项目用户信息
             const shareInfoMap = await pm_facade.getShareInfoMap(null, shareList);
-            if(receiveProjects.length > 0){
+            if (receiveProjects.length > 0) {
                 let orgUserIDs = [];
-                for(let proj of receiveProjects){
+                for (let proj of receiveProjects) {
                     orgUserIDs.push(proj.userID);
                     if (proj.projType === projType.tender) {
                         // 设置项目类别
@@ -746,14 +744,14 @@ module.exports = {
                 }
                 orgUserIDs = Array.from(new Set(orgUserIDs));
                 let userObjIDs = [];
-                for(let uID of orgUserIDs){
+                for (let uID of orgUserIDs) {
                     userObjIDs.push(mongoose.Types.ObjectId(uID));
                 }
-                let orgUsersInfo = await userModel.find({_id: {$in : userObjIDs}});
+                let orgUsersInfo = await userModel.find({ _id: { $in: userObjIDs } });
                 //建设项目
                 let consProjIDs = [],
                     ungroupedTenders = [];
-                for(let proj of receiveProjects){
+                for (let proj of receiveProjects) {
                     // 设置分享信息
                     proj.shareInfo = shareInfoMap[proj.ID] || [];
                     if (proj.projType === projType.project) {
@@ -786,9 +784,9 @@ module.exports = {
                     }
                     //设置项目类型为来自别人分享
                     proj.shareType = 'receive';
-                    for(let userData of orgUsersInfo){
-                        if(proj.userID == userData._id.toString()){
-                            let userInfo = {name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email};
+                    for (let userData of orgUsersInfo) {
+                        if (proj.userID == userData._id.toString()) {
+                            let userInfo = { name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email };
                             proj.userInfo = userInfo;
                         }
                     }
@@ -796,17 +794,17 @@ module.exports = {
                 consProjIDs = Array.from(new Set(consProjIDs));
                 let summaryInfo = await pm_facade.getSummaryInfo(consProjIDs);
                 let tendersFeeInfo = await pm_facade.getTendersFeeInfo(ungroupedTenders);
-                rst.summaryInfo = {grouped: summaryInfo, ungrouped: tendersFeeInfo};
+                rst.summaryInfo = { grouped: summaryInfo, ungrouped: tendersFeeInfo };
             }
             callback(req, res, 0, 'success', rst);
         }
-        catch (err){
+        catch (err) {
             console.log(err);
             callback(req, res, 1, err, null);
         }
     },
     getProjectsByQuery: async function (req, res) {
-        try{
+        try {
             let data = JSON.parse(req.body.data);
             let compilation = req.session.sessionCompilation._id;
             let query = data.query;
@@ -815,57 +813,58 @@ module.exports = {
             let projects = await projectModel.find(query, options);
             callback(req, res, 0, 'success', projects);
         }
-        catch (err){
+        catch (err) {
             callback(req, res, 1, err, null);
         }
     },
-    getSummaryInfo: async function(req, res){
-        try{
+    getSummaryInfo: async function (req, res) {
+        try {
             let data = JSON.parse(req.body.data);
             let summaryInfo = await pm_facade.getSummaryInfo(data.projectIDs);
             callback(req, res, 0, 'success', summaryInfo);
         }
-        catch (err){
+        catch (err) {
             callback(req, res, 1, err, null);
         }
     },
-    changeFile:async function(req,res){
-        try{
+    changeFile: async function (req, res) {
+        try {
             let data = JSON.parse(req.body.data);
             console.log(data);
-            await pm_facade.changeFile(data.projects,data.user_id,data.fileID,data.name,data.from,data.type);
+            await pm_facade.changeFile(data.projects, data.user_id, data.fileID, data.name, data.from, data.type);
             callback(req, res, 0, 'success', []);
         }
-        catch (err){
+        catch (err) {
             console.log(err);
             callback(req, res, 1, err, null);
         }
     },
-    exportProject:async function(req,res){
-        let result={
-            error:0
+    exportProject: async function (req, res) {
+        let result = {
+            error: 0
         };
         try {
-            let data = {dataString:req.body.data,userID:req.session.sessionUser.id};
-            result = await redirectToImportServer(data,"exportProject",req);
-        }catch (err){
+            let data = { dataString: req.body.data, userID: req.session.sessionUser.id };
+            result = await redirectToImportServer(data, "exportProject", req);
+        } catch (err) {
             console.log(err);
-            result.error=1;
+            result.error = 1;
             result.message = err.message;
         }
         res.json(result);
+
     },
-    importProject:async function(req,res){
+    importProject: async function (req, res) {
         let data = JSON.parse(req.body.data);
-        let result={
-            error:0
+        let result = {
+            error: 0
         };
         try {
             data.session = req.session;
             result = await redirectToImportServer(data,"importProject",req);
-        }catch (err){
+        } catch (err) {
             console.log(err);
-            result.error=1;
+            result.error = 1;
             result.message = err.message;
         }
         res.json(result);
@@ -885,31 +884,31 @@ module.exports = {
       }
       res.json(result);
     },
-    importProcessChecking:async function (req,res) {
-        let result={
-            error:0
+    importProcessChecking: async function (req, res) {
+        let result = {
+            error: 0
         };
-        try{
+        try {
             let data = JSON.parse(req.body.data);
             data.userID = req.session.sessionUser.id;
             data.compilationID = req.session.sessionCompilation._id;
             result.data = await pm_facade.importProcessChecking(data);
-        } catch (err){
+        } catch (err) {
             console.log(err);
-            result.error=1;
+            result.error = 1;
             result.message = err.message;
         }
         res.json(result);
     },
-    getUploadToken:function (req,res) {
-        let result={
-            error:0
+    getUploadToken: function (req, res) {
+        let result = {
+            error: 0
         };
         try {
-            result =pm_facade.uploadToken();
-        }catch (err){
+            result = pm_facade.uploadToken();
+        } catch (err) {
             console.log(err);
-            result.error=1;
+            result.error = 1;
             result.message = err.message;
         }
         res.json(result);
@@ -917,15 +916,15 @@ module.exports = {
 };
 
 
-async function redirectToImportServer(data,action,req) {
-    let importURL = config.getImportURL(process.env.NODE_ENV,req.headers.origin);
+async function redirectToImportServer(data, action, req) {
+    let importURL = config.getImportURL(process.env.NODE_ENV, req.headers.origin);
     let options = {
         method: 'POST',
         uri: `http://${importURL}/import/${action}`,
         body: data,
-        timeout:220000,
+        timeout: 220000,
         json: true
     };
-    console.log("post import data to:"+options.uri);
+    console.log("post import data to:" + options.uri);
     return await rp.post(options);
 }

+ 61 - 16
modules/ration_glj/facade/ration_glj_facade.js

@@ -100,11 +100,11 @@ async function getQuantityByProjectGLJ(condition) {
         'deleteInfo': null
     };
 
-    /* $and: [
-     {'projectID': condition.projectID},
-     {'ID': {$in: rationList}},
-     {'deleteInfo': null}
-     ]*/
+   /* $and: [
+        {'projectID': condition.projectID},
+        {'ID': {$in: rationList}},
+        {'deleteInfo': null}
+    ]*/
     let rations = await ration.find(rationQuery, ['ID', 'quantity']);
     let rationsTime = +new Date();
     console.log("取定额消耗量时间-----"+(rationsTime - getQuantity));
@@ -150,7 +150,7 @@ function get_lib_glj_info(ration_glj) {
                 ration_glj.repositoryId = glj.repositoryId;
                 ration_glj.adjCoe = glj.adjCoe;
                 getInfoFromProjectGLJ(ration_glj).then(function (info) {
-                    if (info&&info.length>0) {
+                    if (info &&info.length>0) {
                         let tem = {};
                         tem.newRecode = createNewRecord(info[0]);
                         tem.showData = info[0];
@@ -340,13 +340,13 @@ function delete_ration_glj(user_id, datas) {
         deleteByID(datas, callback);
         //callback(new Error("删除子数据失败!"),null)
         //这个方法已经不用,先注释,稳定后再删除
-        /* if (datas.deleteType == "RATION") {
-         deleteByRation(datas, callback);
-         } else if (datas.deleteType == "BILL") {
-         deleteByBill(user_id, datas, callback);
-         } else {
-         deleteByID(datas, callback);
-         }*/
+       /* if (datas.deleteType == "RATION") {
+            deleteByRation(datas, callback);
+        } else if (datas.deleteType == "BILL") {
+            deleteByBill(user_id, datas, callback);
+        } else {
+            deleteByID(datas, callback);
+        }*/
     }
 }
 
@@ -724,8 +724,8 @@ async function addGLJ(rgList,compilation) {
         rationID: rgList[0].rationID
     });
     let result = {
-        projectGLJList:projectGLJList,
         newRecodes: newRecodes,
+        projectGLJList:projectGLJList,
         showData: rgList,
         adjustState: stateResult.adjustState
     };
@@ -736,7 +736,6 @@ async function insertAddTypeGLJ(rgList,compilation,needInsert=true) {
     let newRecodes = [],GLJMap=null;
     let projectGLJList = [];
     let [unitFileId,ext] = await  prepareExtData(rgList[0].projectID,compilation);
-
     for (let g of rgList) {
         let projectGljModel = new GLJListModel();
         let result = await projectGljModel.addList(getGLJSearchInfo(g),unitFileId,ext);
@@ -1176,11 +1175,57 @@ async function testError() {
     throw  new Error('test Error');
 }
 
-function getData(projectID, callback) {
+function getData(projectID, callback, isReport) {
     ration_glj.find({'projectID': projectID}, (err, datas) => {
         if (err) {
             callback(1, '', null);
         } else {
+            if (isReport) {  // 调价中间件机制
+                ration.find({'projectID': projectID}, ['ID', 'code', 'name', 'quantityCoe', 'quantity', 'rationQuantityCoe'],
+                    function cbData(err, rations) {
+                        if (!err) {
+                            for (let i = 0; i < datas.length; i++) {
+                                let glj = datas[i]._doc;
+                                let ration = findRation(rations, glj.rationID);
+                                let coe = 1;
+                                if (ration && ration.quantityCoe){
+                                    if ([gljType.LABOUR].includes(glj.type)){
+                                        if (ration.quantityCoe._doc.labour)
+                                            coe = ration.quantityCoe._doc.labour;
+                                    }
+                                    else if (
+                                        [gljType.GENERAL_MATERIAL,
+                                        gljType.CONCRETE,
+                                        gljType.MORTAR,
+                                        gljType.MIX_RATIO,
+                                        gljType.COMMERCIAL_CONCRETE,
+                                        gljType.COMMERCIAL_MORTAR,
+                                        gljType.OTHER_MATERIAL].includes(glj.type)){
+                                        if (ration.quantityCoe._doc.material)
+                                            coe = ration.quantityCoe._doc.material;
+                                    }
+                                    else if ([gljType.GENERAL_MACHINE,
+                                        gljType.MACHINE_COMPOSITION,
+                                        gljType.MACHINE_LABOUR].includes(glj.type)){
+                                        if (ration.quantityCoe._doc.machine)
+                                            coe = ration.quantityCoe._doc.machine;
+                                    }
+                                    else if ([gljType.MAIN_MATERIAL].includes(glj.type)){
+                                        if (ration.quantityCoe._doc.main)
+                                            coe = ration.quantityCoe._doc.main;
+                                    }
+                                    else if ([gljType.EQUIPMENT].includes(glj.type)){
+                                        if (ration.quantityCoe._doc.equipment)
+                                            coe = ration.quantityCoe._doc.equipment;
+                                    };
+
+                                };
+                                if ((!coe) || (coe == '0')) coe = 1;
+                                glj.quantity = glj.quantity * coe;
+                            }
+                        }
+                    });
+            };
             callback(0, consts.projectConst.RATION_GLJ, datas);
         }
     })

+ 8 - 4
public/gljUtil.js

@@ -31,16 +31,16 @@ function calcProjectGLJQuantity(projectGLJDatas,rationGLJDatas,rationDatas,bills
     gljNodeUtil.calcProjectGLJQuantity(projectGLJDatas,rationGLJDatas,rationDatas,billsDatas,q_decimal,_,scMathUtil);
 }
 
-function getGLJPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio=false) {
-    return gljNodeUtil.getGLJPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
+function getGLJPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio=false,tenderCoe, isReport) {
+    return gljNodeUtil.getGLJPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe, isReport);
 }
 
 function setMaterialCalcRationFee(ration,ration_gljs,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,_,scMathUtil) {
     return gljNodeUtil.setMaterialCalcRationFee(ration,ration_gljs,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,_,scMathUtil);
 }
 
-function getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio=false) {
-    return gljNodeUtil.getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
+function getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio=false,tenderCoe) {
+    return gljNodeUtil.getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
 }
 
 function getBasePrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio=false) {
@@ -84,4 +84,8 @@ function getCCSProjectGLJ(unitFileID,project_id) {
 
 function getBaseCCSMixRatio(unitFileID,consumption,connect_key) {
     return gljNodeUtil.getBaseCCSMixRatio(unitFileID,consumption,connect_key)
+}
+
+function getTenderPriceCoe(glj,tproperty){
+  return gljNodeUtil.getTenderPriceCoe(glj,tproperty);
 }

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

@@ -107,11 +107,11 @@ var gljOprObj = {
     scopeSheet:null,
     scopeDatas:[],
     scopeSelectedIDMap:{},
-    initSheet: function (sheet) {
+    initSheet: function (sheet,name="ration_glj") {
         var me = this;
         me.sheet = sheet;
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);
-        sheet.name('ration_glj');
+        sheet.name(name);
         me.bindSheetEvent(sheet);
         sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
         sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);