Browse Source

1. project, getFilterData, 提供项目工料机数据
2. Number.prototype.toDecimal 调用张博士提供的四舍五入方法

MaiXinRong 7 years ago
parent
commit
5ae327afab

+ 4 - 0
modules/main/controllers/project_controller.js

@@ -22,6 +22,10 @@ module.exports = {
     },
     getData: function (req, res) {
         var data = JSON.parse(req.body.data);
+        // 注释代码用于测试getFilterData
+        // Project.getFilterData(data.project_id, ['bills', 'projectGLJ'], function (err, result) {
+        //     console.log(result);
+        // });
         Project.getData(data.project_id, function (err, message, result) {
             if (!err) {
                 callback(req, res, err, message, result);

+ 28 - 5
modules/main/models/project.js

@@ -14,9 +14,13 @@ let projSetting = require('./proj_setting_model');
 let volumePriceData = require('../../volume_price/models/volume_price_model');
 var labour_coe_facade = require('../facade/labour_coe_facade');
 var calc_program_facade = require('../facade/calc_program_facade');
+
+const ProjectModel = require('../../pm/models/project_model').project;
+import GLJListModel from "../../glj/models/glj_list_model";
+
 var consts = require('./project_consts');
 var projectConsts = consts.projectConst;
-var async = require("async");
+var asyncTool = require("async");
 
 var moduleMap = {};
 
@@ -73,7 +77,7 @@ Project.prototype.save = function(datas, callback){
         functions.push(saveModule(item));
     }
 
-    async.parallel(functions, function(err, results) {
+    asyncTool.parallel(functions, function(err, results) {
         if (!err){
             callback(null, '', results)
         }
@@ -98,7 +102,7 @@ Project.prototype.getData = function(projectID, callback){
         })(itemName))
     }
 
-    async.parallel(functions, function(err, results) {
+    asyncTool.parallel(functions, function(err, results) {
         if (!err){
             callback(null, '', results)
         }
@@ -111,11 +115,29 @@ Project.prototype.getData = function(projectID, callback){
 Project.prototype.getFilterData = function (projectID, filter, callback) {
     let functions = [];
     let getModuleData = function (moduleName) {
-        return function (cb) {
+        return async function (cb) {
             if (moduleMap[moduleName]) {
                 moduleMap[moduleName].getData(projectID, function (err, name, data) {
                     cb(err, {'moduleName': name, 'data': data})
                 });
+            } else if (moduleName === projectConsts.PROJECTGLJ) {
+                try {
+                    if (isNaN(projectID) || projectID <= 0) {
+                        throw '标段id有误';
+                    }
+                    // 获取标段对应的单价文件id
+                    let unitPriceFileId = await ProjectModel.getUnitPriceFileId(projectID);
+                    if (unitPriceFileId <= 0) {
+                        throw '没有对应的单价文件';
+                    }
+                    // 先获取对应标段的项目工料机数据
+                    let gljListModel = new GLJListModel();
+                    let [gljList, mixRatioConnectData] = await gljListModel.getListByProjectId(projectID, unitPriceFileId);
+
+                    cb(null, {'moduleName': moduleName, 'data': gljList});
+                } catch (error) {
+                    cb(error, null);
+                }
             } else {
                 throw '要查询的项目模块不存在';
             }
@@ -124,7 +146,8 @@ Project.prototype.getFilterData = function (projectID, filter, callback) {
     for (let itemName of filter) {
         functions.push(getModuleData(itemName));
     }
-    async.parallel(functions, function (err, results) {
+    asyncTool.parallel(functions, function (err, results) {
+        console.log(results);
         if (err) {
             throw '获取项目数据出错';
         } else {

+ 3 - 3
public/web/number_util.js

@@ -2,9 +2,9 @@
  * Created by chen on 2017/7/5.
  */
 
-Number.prototype.toDecimal = function (ADigit) {
-    return parseFloat(this.toFixed(ADigit));
-};
+// Number.prototype.toDecimal = function (ADigit) {
+//     return parseFloat(this.toFixed(ADigit));
+// };
 
 var  number_util = {
     isNumber : function (obj) {

+ 9 - 0
public/web/scMathUtil.js

@@ -78,4 +78,13 @@ let scMathUtil = {
         let me = this;
         return me.innerRoundTo(me.binToFloat(me.incMantissa(me.floatToBin(num))), digit);
     }
+};
+
+Number.prototype.toDecimal = function (ADigit) {
+    //return parseFloat(this.toFixed(ADigit));
+    digit = (ADigit && typeof(ADigit) === 'Number' && Number.isInteger(ADigit) && ADigit >= 0) ? -ADigit : -2;
+    // var s = scMathUtil.roundTo(this, digit);
+    // console.log('Number: ' + this + '   Digit: ' + digit + '    Result: ' + s);
+    // return parseFloat(s);
+    return parseFloat(scMathUtil.roundTo(this, digit));
 };