zhongzewei 6 лет назад
Родитель
Сommit
0e76aea065

+ 1 - 1
modules/all_models/stdRation_lib.js

@@ -8,7 +8,7 @@ const oprSchema = require('../all_schemas/opr_schema');
 const RepositoryMapSchema = new Schema({
     "ID": Number,
     "dispName" : String,
-    "libCode": String, //定额编号
+    "libCode": String, //定额库编码
     "appType" : String, //如:"建筑" / "公路"
     "localeType": String, //如 各个省份 / 部颁
     "descr" : String,

+ 2 - 0
modules/basic_info_lib/controllers/basic_info_controller.js

@@ -4,6 +4,7 @@
 import BaseController from "../../common/base/base_controller";
 import basicInfoFacade from "../facade/basic_info_facade";
 let config = require("../../../config/config.js");
+let logger = require('../../../logs/log_helper').logger;
 
 class BasicInfoController extends BaseController{
     async main(request, response) {
@@ -59,6 +60,7 @@ class BasicInfoController extends BaseController{
         response.json(result);
     }
     async deleteLibByID(request,response){
+        logger.info(`delete basicInfoLib ${request.ip}`);
         let result={
             error:0
         };

+ 3 - 1
modules/bills_lib/controllers/bills_lib_controllers.js

@@ -5,7 +5,8 @@
 let billsLibDao = require("./../models/bills_lib_interfaces");
 let callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
-}
+};
+let logger = require('../../../logs/log_helper').logger;
 
 module.exports = {
     getMaxNumber: function(req, res){
@@ -33,6 +34,7 @@ module.exports = {
     },
     deleteStdBillsLib: function(req, res){
         let data = JSON.parse(req.body.data);
+        logger.info(`deleteBillsLib ${req.ip}`);
         billsLibDao.deleteStdBillsLib(data, function(err, message){
             callback(req, res, err, message, null);
         });

+ 2 - 0
modules/bills_template_lib/controllers/bills_template_controller.js

@@ -11,6 +11,7 @@ import {default as BillsFixedFlagConst, List as BillsFixedFlagList} from "../../
 import {default as BillsTypeFlagConst, List as BillsTypeFlagList} from "../../common/const/bills_type.js";
 import CompilationModel from '../../users/models/compilation_model';
 let config = require("../../../config/config.js");
+let logger = require('../../../logs/log_helper').logger;
 
 class BillsTemplateController extends BaseController {
 
@@ -93,6 +94,7 @@ class BillsTemplateController extends BaseController {
     }
 
     async deleteLibByID(request,response){
+        logger.info(`delete billsTemplateLib ${request.ip}`);
         let result={
             error:0
         };

+ 2 - 0
modules/calc_program_lib/controllers/calc_program_controller.js

@@ -3,6 +3,7 @@
  */
 import BaseController from "../../common/base/base_controller";
 let config = require("../../../config/config.js");
+let logger = require('../../../logs/log_helper').logger;
 import calcProgramFacade from "../facade/calc_program_facade";
 import CompilationModel from '../../users/models/compilation_model';
 
@@ -71,6 +72,7 @@ class CalcProgramController extends BaseController {
         response.json(result);
     }
     async deleteLibByID(request,response){
+        logger.info(`delete calcProgramLib ${request.ip}`);
         let result={
             error:0
         };

+ 2 - 0
modules/fee_rate_lib/controllers/fee_rate_controller.js

@@ -3,6 +3,7 @@
  */
 import BaseController from "../../common/base/base_controller";
 let config = require("../../../config/config.js");
+let logger = require('../../../logs/log_helper').logger;
 import feeRateFacade from "../facade/fee_rate_facade";
 import CompilationModel from '../../users/models/compilation_model';
 
@@ -71,6 +72,7 @@ class FeeRateController extends BaseController{
         response.json(result);
     }
     async deleteLibByID(request,response){
+        logger.info(`delete feeRateLib ${request.ip}`);
         let result={
             error:0
         };

+ 2 - 0
modules/main_col_lib/controllers/main_col_controller.js

@@ -9,6 +9,7 @@
 import BaseController from "../../common/base/base_controller";
 import mainColFacade from "../facade/main_col_facade";
 let config = require("../../../config/config.js");
+let logger = require('../../../logs/log_helper').logger;
 
 class MainColController extends BaseController {
 
@@ -36,6 +37,7 @@ class MainColController extends BaseController {
     }
 
     async deleteLibByID(request,response){
+        logger.info(`delete colSettingLib ${request.ip}`);
         let result={
             error:0
         };

+ 2 - 0
modules/material_replace_lib/controllers/material_replace_controller.js

@@ -4,6 +4,7 @@
 import BaseController from "../../common/base/base_controller";
 import materialFacade from "../facade/material_replace_facade";
 let config = require("../../../config/config.js");
+let logger = require('../../../logs/log_helper').logger;
 
 class ReplaceController extends BaseController{
     /**
@@ -100,6 +101,7 @@ class ReplaceController extends BaseController{
         response.json(result);
     }
     async deleteLibByID(request,response){
+        logger.info(`delete materialLib ${request.ip}`);
         let result={
             error:0
         };

+ 2 - 0
modules/project_feature_lib/controllers/project_feature_controller.js

@@ -4,6 +4,7 @@
 import BaseController from "../../common/base/base_controller";
 import featureFacade from "../facade/project_feature_facade";
 let config = require("../../../config/config.js");
+let logger = require('../../../logs/log_helper').logger;
 
 class FeatureController extends BaseController{
     async main(request, response) {
@@ -59,6 +60,7 @@ class FeatureController extends BaseController{
         response.json(result);
     }
     async deleteLibByID(request,response){
+        logger.info(`delete projectFeatureLib ${request.ip}`);
         let result={
             error:0
         };

+ 7 - 1
modules/ration_repository/controllers/ration_repository_controller.js

@@ -6,6 +6,7 @@ var rationRepository = require("../models/repository_map");
 import baseController from "../../common/base/base_controller";
 import CompilationModel from "../../users/models/compilation_model";
 const gljMapModel = mongoose.model('std_glj_lib_map');
+const compilationModel = mongoose.model('compilation');
 import async from "async";
 var callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
@@ -19,6 +20,7 @@ const rationItem = require("../models/ration_item");
 const rationLibModel = mongoose.model('std_ration_lib_map');
 const rationItemModel = mongoose.model('std_ration_lib_ration_items');
 import STDGLJListModel from '../../std_glj_lib/models/gljModel';
+let logger = require('../../../logs/log_helper').logger;
 
 class RationRepositoryController extends baseController {
     async getRationLibsByCompilation(req, res){
@@ -134,6 +136,7 @@ class RationRepositoryController extends baseController {
     }
 
     deleteRationLib(req, res) {
+        logger.info(`deleteRationLib ${req.ip}`);
         let oprtor = req.body.oprtor,
             libId = req.body.libId;
         rationRepository.deleteRationLib(oprtor, libId, function (err, message) {
@@ -274,8 +277,11 @@ class RationRepositoryController extends baseController {
             }
             //获取所有的定额
             let allRations = await rationItemModel.find({rationRepId: rationRepId, $or: [{isDeleted: false}, {isDeleted: null}]});
+            let compilation = await compilationModel.findOne({_id: mongoose.Types.ObjectId(rationLib.compilationId)});
+            let tempUrl = compilation.overWriteUrl ? req.app.locals.rootDir + compilation.overWriteUrl : req.app.locals.rootDir;
+            let absoluteUrl = fs.existsSync(tempUrl) && fs.statSync(tempUrl).isFile()? tempUrl : null;
             for(let ration of allRations){
-                rationItem.calcForRation(stdGLJListByID, ration);
+                rationItem.calcForRation(stdGLJListByID, ration, absoluteUrl);
                 task.push({
                     updateOne: {
                         filter: {ID: ration.ID},

+ 2 - 1
modules/ration_repository/controllers/repository_views_controller.js

@@ -54,7 +54,8 @@ class ViewsController extends BaseController{
                 redirectCoe: redirectCoe,
                 redirectInstallation: redirectInstallation,
                 LicenseKey:config.getLicenseKey(process.env.NODE_ENV),
-                priceProperties: JSON.stringify(priceProperties)
+                priceProperties: JSON.stringify(priceProperties),
+                overWriteUrl: overWriteUrl
             });
     }
     async redirectGlj(req, res){

+ 128 - 207
modules/ration_repository/models/ration_item.js

@@ -301,8 +301,90 @@ function round(v,e){
     return Math.round(v*t)/t;
 }
 
+function calcRation(gljArr) {
+    let labourPrc = [],
+        materialPrc = [],
+        machinePrc = [],
+        managePrc = [],
+        profitPrc = [],
+        riskPrc = [],
+        singlePrc,
+        updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0, basePrice: 0};
+    gljArr.forEach(function (gljItem) {
+        if(gljItem.gljParentType !== -1){
+            singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
+            if(gljItem.gljParentType === 1){
+                labourPrc.push(singlePrc);
+            }
+            else if(gljItem.gljParentType ===2){
+                materialPrc.push(singlePrc);
+            }
+            else if(gljItem.gljParentType === 3){
+                machinePrc.push(singlePrc);
+            }
+            else if(gljItem.gljParentType === 6){
+                managePrc.push(singlePrc);
+            }
+            else if(gljItem.gljParentType === 7){
+                profitPrc.push(singlePrc);
+            }
+            else if(gljItem.gljParentType === 8){
+                riskPrc.push(singlePrc);
+            }
+        }
+    });
+    if(labourPrc.length > 0){
+        let sumLaP = 0;
+        for(let i=0; i<labourPrc.length; i++){
+            sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], -6);
+        }
+        updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
+        updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.labourPrice, -2);
+    }
+    if(materialPrc.length > 0){
+        let sumMtP = 0;
+        for(let i= 0; i<materialPrc.length; i++){
+            sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], -6);
+        }
+        updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
+        updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.materialPrice, -2);
+    }
+    if(machinePrc.length > 0){
+        let sumMaP = 0;
+        for(let i =0; i< machinePrc.length; i++){
+            sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], -6);
+        }
+        updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
+        updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.machinePrice, -2);
+    }
+    if(managePrc.length > 0){
+        let sumMgP = 0;
+        for(let i =0; i< managePrc.length; i++){
+            sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], -6);
+        }
+        updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
+        updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.managePrice, -2);
+    }
+    if(profitPrc.length > 0){
+        let sumPfP = 0;
+        for(let i =0; i< profitPrc.length; i++){
+            sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], -6);
+        }
+        updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
+        updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.profitPrice, -2);
+    }
+    if(riskPrc.length > 0){
+        let sumRkP = 0;
+        for(let i =0; i< riskPrc.length; i++){
+            sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], -6);
+        }
+        updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
+        updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.riskPrice, -2);
+    }
+    return updatePrc;
+}
 
-rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
+rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, overWriteUrl, callback) {
     async.each(basePrcArr, function (basePrcObj, finalCb) {
         let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
         async.waterfall([
@@ -379,7 +461,6 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                     }
                 }
                 gljDao.getStdCompleGljItems(compleGljIds, stdGljIds, function (err, allGljs) {
-                    const processDecimal = -6;
                     if(err){
                         cb(err);
                     }
@@ -400,35 +481,25 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                     }
                                     if(theGlj.gljType <= 3){
                                         gljParentType = theGlj.gljType;
-                                    }
-                                    if(theGlj.gljType > 200 && theGlj.gljType < 300){
+                                    } else if(theGlj.gljType > 200 && theGlj.gljType < 300){
                                         gljParentType = 2;
-                                    }
-                                    if(theGlj.gljType > 300 && theGlj.gljType < 400){
+                                    } else if(theGlj.gljType > 300 && theGlj.gljType < 400){
                                         gljParentType = 3;
-                                    }
-                                    //管理费
-                                    if(theGlj.gljType === 6){
+                                    } else if(theGlj.gljType === 6){   //管理费
                                         gljParentType = 6;
-                                    }
-                                    //利润
-                                    if(theGlj.gljType === 7){
+                                    } else if(theGlj.gljType === 7){    //利润
                                         gljParentType = 7;
-                                    }
-                                    //风险费
-                                    if(theGlj.gljType === 8){
+                                    } else if(theGlj.gljType === 8){    //风险费
                                         gljParentType = 8;
                                     }
                                     if(theGlj)
                                     if(theGlj.ID === adjGljId){
                                         gljArr.push({gljId: theGlj.ID, basePrice: adjBasePrice, gljParentType: gljParentType});
-                                    }
-                                    else {
+                                    } else {
                                         if(theGlj.priceProperty && Object.keys(theGlj.priceProperty).length > 0){
                                             let priceKeys = Object.keys(theGlj.priceProperty);
                                             gljArr.push({gljId: theGlj.ID, basePrice: parseFloat(theGlj.priceProperty[priceKeys[0]]), gljParentType: gljParentType});
-                                        }
-                                        else {
+                                        } else {
                                             gljArr.push({gljId: theGlj.ID, basePrice: parseFloat(theGlj.basePrice), gljParentType: gljParentType});
                                         }
                                     }
@@ -441,82 +512,18 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                     }
                                 })
                             });
-                            //recalculate the price of ration
-                            let labourPrc = [],
-                                materialPrc = [],
-                                machinePrc = [],
-                                managePrc = [],
-                                profitPrc = [],
-                                riskPrc = [],
-                                singlePrc,
-                                updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0, basePrice: 0};
-                            gljArr.forEach(function (gljItem) {
-                                if(gljItem.gljParentType !== -1){
-                                    singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
-                                    if(gljItem.gljParentType === 1){
-                                        labourPrc.push(singlePrc);
-                                    }
-                                    else if(gljItem.gljParentType ===2){
-                                        materialPrc.push(singlePrc);
-                                    }
-                                    else if(gljItem.gljParentType === 3){
-                                        machinePrc.push(singlePrc);
-                                    }
-                                    else if(gljItem.gljParentType === 6){
-                                        managePrc.push(singlePrc);
-                                    }
-                                    else if(gljItem.gljParentType === 7){
-                                        profitPrc.push(singlePrc);
-                                    }
-                                    else if(gljItem.gljParentType === 8){
-                                        riskPrc.push(singlePrc);
-                                    }
-                                }
-                            });
-                            if(labourPrc.length > 0){
-                                let sumLaP = 0;
-                                for(let i=0; i<labourPrc.length; i++){
-                                    sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], processDecimal);
+                            let updatePrc = null;
+                            let overWriteCalc = false;  //需要重写算法
+                            if (overWriteUrl) {
+                                let overWriteExports = require(overWriteUrl);
+                                if (typeof overWriteExports.calcRation !== 'undefined') {
+                                    overWriteCalc = true;
+                                    updatePrc = overWriteExports.calcRation(gljArr, scMathUtil);
                                 }
-                                updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
                             }
-                            if(materialPrc.length > 0){
-                                let sumMtP = 0;
-                                for(let i= 0; i<materialPrc.length; i++){
-                                    sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], processDecimal);
-                                }
-                                updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
-                            }
-                            if(machinePrc.length > 0){
-                                let sumMaP = 0;
-                                for(let i =0; i< machinePrc.length; i++){
-                                    sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], processDecimal);
-                                }
-                                updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
-                            }
-                            if(managePrc.length > 0){
-                                let sumMgP = 0;
-                                for(let i =0; i< managePrc.length; i++){
-                                    sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], processDecimal);
-                                }
-                                updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
-                            }
-                            if(profitPrc.length > 0){
-                                let sumPfP = 0;
-                                for(let i =0; i< profitPrc.length; i++){
-                                    sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], processDecimal);
-                                }
-                                updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
-                            }
-                            if(riskPrc.length > 0){
-                                let sumRkP = 0;
-                                for(let i =0; i< riskPrc.length; i++){
-                                    sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], processDecimal);
-                                }
-                                updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
+                            if (!overWriteCalc) {
+                                updatePrc = calcRation(gljArr);
                             }
-                            updatePrc.basePrice = scMathUtil.roundTo(
-                                updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2);
                             let task = {
                                 updateOne: {
                                     filter: {
@@ -710,126 +717,40 @@ rationItemDAO.prototype.updateRationTemplate = async function (rationRepId, rati
 };
 
 //计算导入数据的价格
-rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
-    const processDecimal = -6;
-    //根据工料机类型划分价格
-    const labour = [1],
-        material = [201, 202, 203, 204, 205, 206, 207],
-        machine = [301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312],
-        manage = [6],
-        profit = [7],
-        risk = [8];
-    let labourPrc = [], materialPrc = [], machinePrc = [], managePrc = [], profitPrc = [], riskPrc = [],
-        singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0};
-    let rationGljList = ration.rationGljList;
-    for(let rationGlj of rationGljList){
+rationItemDAO.prototype.calcForRation = function (stdGljList, ration, overWriteUrl) {
+    let rationGljList = ration.rationGljList,
+        gljArr = [];
+    for(let rationGlj of rationGljList) {
         let glj = stdGljList[rationGlj.gljId];
-        let prcType = isDef(glj) ? getParentType(glj.gljType) : null;
-        if(isDef(prcType)){
-            singlePrc = scMathUtil.roundTo(parseFloat(glj.basePrice) * parseFloat(rationGlj.consumeAmt), -3);
-            if(prcType === 'labour'){
-                labourPrc.push(singlePrc);
-            }
-            else if(prcType === 'material'){
-                materialPrc.push(singlePrc);
-            }
-            else if(prcType === 'machine'){
-                machinePrc.push(singlePrc);
-            }
-            else if(prcType === 'manage'){
-                managePrc.push(singlePrc);
-            }
-            else if(prcType === 'profit'){
-                profitPrc.push(singlePrc);
-            }
-            else if(prcType === 'risk'){
-                riskPrc.push(singlePrc);
-            }
-        }
-    }
-    //计算人工费
-    if(labourPrc.length > 0){
-        let sumLaP = 0;
-        for(let i = 0, len  = labourPrc.length; i < len; i++){
-            sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], processDecimal);
-        }
-        updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
-    }
-    //材料费
-    if(materialPrc.length > 0){
-        let sumMtP = 0;
-        for(let i = 0, len  = materialPrc.length; i < len; i++){
-            sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], processDecimal);
-        }
-        updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
-    }
-    //机械费
-    if(machinePrc.length > 0){
-        let sumMaP = 0;
-        for(let i = 0, len  = machinePrc.length; i < len; i++){
-            sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], processDecimal);
-        }
-        updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
-    }
-    //管理费
-    if(managePrc.length > 0){
-        let sumMgP = 0;
-        for(let i = 0, len  = managePrc.length; i < len; i++){
-            sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], processDecimal);
-        }
-        updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
-    }
-    //利润
-    if(profitPrc.length > 0){
-        let sumPfP = 0;
-        for(let i = 0, len  = profitPrc.length; i < len; i++){
-            sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], processDecimal);
-        }
-        updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
-    }
-    //风险费
-    if(riskPrc.length > 0){
-        let sumRkP = 0;
-        for(let i = 0, len  = riskPrc.length; i < len; i++){
-            sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], processDecimal);
-        }
-        updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
-    }
-    //基价
-    updatePrc.basePrice = scMathUtil.roundTo(
-        updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2);
-    //更新定额数据
-    ration.labourPrice = updatePrc.labourPrice.toString();
-    ration.materialPrice = updatePrc.materialPrice.toString();
-    ration.machinePrice = updatePrc.machinePrice.toString();
-    ration.basePrice = updatePrc.basePrice.toString();
-
-    function isDef(v){
-        return v !== undefined && v !== null;
-    }
-    //是否属于人工、材料、机械类型
-    function getParentType(type){
-        if(labour.includes(type)){
-            return 'labour';
-        }
-        if(material.includes(type)){
-            return 'material';
-        }
-        if(machine.includes(type)){
-            return 'machine';
-        }
-        if(manage.includes(type)){
-            return 'manage';
+        let gljPType = parseInt(glj.gljType.toString().match(/\d+?/)[0]);
+        if (glj.priceProperty && Object.keys(glj.priceProperty).length > 0) {
+            let priceKeys = Object.keys(glj.priceProperty);
+            gljArr.push({
+                gljId: glj.ID,
+                basePrice: parseFloat(glj.priceProperty[priceKeys[0]]),
+                consumeAmt: rationGlj.consumeAmt,
+                gljParentType: gljPType
+            });
+        } else {
+            gljArr.push({gljId: glj.ID, basePrice: parseFloat(glj.basePrice), consumeAmt: rationGlj.consumeAmt, gljParentType: gljPType});
         }
-        if(profit.includes(type)){
-            return 'profit';
+        let updatePrc = null;
+        let overWriteCalc = false;  //需要重写算法
+        if (overWriteUrl) {
+            let overWriteExports = require(overWriteUrl);
+            if (typeof overWriteExports.calcRation !== 'undefined') {
+                overWriteCalc = true;
+                updatePrc = overWriteExports.calcRation(gljArr, scMathUtil);
+            }
         }
-        if(risk.includes(type)){
-            return 'risk'
+        if (!overWriteCalc) {
+            updatePrc = calcRation(gljArr);
         }
-        return null;
+        ration.labourPrice = updatePrc.labourPrice.toString();
+        ration.materialPrice = updatePrc.materialPrice.toString();
+        ration.machinePrice = updatePrc.machinePrice.toString();
+        ration.basePrice = updatePrc.basePrice.toString();
     }
-
 };
 
 /**

+ 4 - 0
modules/std_billsGuidance_lib/controllers/libController.js

@@ -10,6 +10,7 @@
 import BaseController from '../../common/base/base_controller';
 import moment from 'moment';
 const billsGuidanceFacade = require('../facade/facades');
+let logger = require('../../../logs/log_helper').logger;
 let callback = function (req, res, err, msg, data) {
     res.json({error: err, message: msg, data: data});
 };
@@ -45,6 +46,9 @@ class BillsGuideLibController extends BaseController{
                 await billsGuidanceFacade.initBillsGuideLib(data.updateData);
             }
             else{
+                if (data.updateType === 'delete') {
+                    logger.info(`delete billsGuidanceLib ${req.ip}`);
+                }
                 await billsGuidanceFacade.updateBillsGuideLib(data);
             }
             callback(req, res, 0, '', data.updateData);

+ 13 - 2
modules/std_glj_lib/controllers/gljController.js

@@ -13,6 +13,9 @@ const gljModel = mongoose.model('std_glj_lib_gljList');
 const stdRationModel = mongoose.model('std_ration_lib_ration_items');
 const cplRationModel = mongoose.model('complementary_ration_items');
 const fs = require('fs');
+const compilationModel = mongoose.model('compilation');
+const gljLibModel = mongoose.model('std_glj_lib_map');
+
 let gljDao = new GljDao();
 let callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
@@ -34,9 +37,17 @@ class GljController extends BaseController{
             callback(req,res,err, 'Get Tree', data)
         });
     }
-    updateRationBasePrc(req, res){
+    async updateRationBasePrc(req, res){
         let basePrcArr = JSON.parse(req.body.basePrcArr);
-        rationItemDao.updateRationBasePrc(basePrcArr, function (err, message) {
+        let repId = req.body.repId;
+        let absoluteUrl = null;
+        let stdGljLib = await gljLibModel.findOne({ID: repId});
+        if(stdGljLib){
+            let compilation = await compilationModel.findOne({_id: mongoose.Types.ObjectId(stdGljLib.compilationId)});
+            let tempUrl = compilation.overWriteUrl ? req.app.locals.rootDir + compilation.overWriteUrl : req.app.locals.rootDir;
+            absoluteUrl = fs.existsSync(tempUrl) && fs.statSync(tempUrl).isFile()? tempUrl : null;
+        }
+        rationItemDao.updateRationBasePrc(basePrcArr, absoluteUrl, function (err, message) {
             if(err){
                 callback(req, res, err, message, null);
             }

+ 2 - 0
modules/std_glj_lib/controllers/gljMapController.js

@@ -6,6 +6,7 @@ import BaseController from "../../common/base/base_controller";
 import {GljMapDao} from "../models/gljMapModel";
 import CompilationModel from "../../users/models/compilation_model";
 let gljMapDao = new GljMapDao();
+let logger = require('../../../logs/log_helper').logger;
 
 let callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
@@ -74,6 +75,7 @@ class GljMapController extends BaseController{
         })
     }
     removeGljLib(req, res){
+        logger.info(`deleteGljLib ${req.ip}`);
         let oprtor = req.body.oprtor,
             libId = req.body.libId;
         gljMapDao.removeGljLib(oprtor, libId, function (err, message) {

+ 3 - 0
web/maintain/ration_repository/dinge.html

@@ -675,6 +675,9 @@
         <script type="text/javascript" src="/public/web/QueryParam.js"></script>
         <script type="text/javascript" src="/public/web/storageUtil.js"></script>
         <script type="text/javascript" src="/web/maintain/ration_repository/js/coe.js"></script>
+        <% if(overWriteUrl){ %>
+        <script type="text/javascript" src="<%= overWriteUrl %>"></script>
+        <% } %>
         <script src="/lib/codemirror/codemirror.js"></script>
         <script src="/lib/codemirror/xml.js"></script>
         <script src="/web/common/js/uploadImg.js"></script>

+ 2 - 2
web/maintain/ration_repository/js/main.js

@@ -22,7 +22,7 @@ $(function () {
             alert('名称不可为空!');
             $('#libNameTxt').val('')
         } else if (!libCode) {
-            alert('定额编号不可为空');
+            alert('定额库编码不可为空');
             $('#libCode').val('');
         } else if(allNames.indexOf(libName) !== -1){
             alert('此定额库已存在!');
@@ -64,7 +64,7 @@ $(function () {
             alert("名称不可为空!");
             $("#renameText").val('');
         } else if (!newLibCode) {
-            alert('定额编号不可为空!');
+            alert('定额库编码不可为空!');
             $('#renameCode').val('');
         } else if(filterName.length > 0 && newName !== orgName){
             alert("该定额库已存在!");

+ 6 - 5
web/maintain/ration_repository/main.html

@@ -49,7 +49,7 @@
                   <div class="col-md-8">
                     <div class="warp-p2 mt-3">
                       <table class="table table-hover table-bordered">
-                        <thead><tr><th>定额库名称</th><th>定额编号</th><th width="160">费用定额</th><th width="160">添加时间</th><th width="90">操作</th><th width="90">原始数据</th><th width="150">内部数据</th><th width="90">补充模板</th></tr></thead>
+                        <thead><tr><th>定额库名称</th><th>定额库编码</th><th width="160">费用定额</th><th width="160">添加时间</th><th width="90">操作</th><th width="90">原始数据</th><th width="150">内部数据</th><th width="90">补充模板</th></tr></thead>
                         <tbody id="showArea">
                         <% for(let lib of rationLibs){ %>
                         <tr id="<%= lib.ID %>">
@@ -60,6 +60,7 @@
                             <td>
                                 <a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a>
                                 <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a>
+                                <a href="javascript:void(0);" data-toggle="modal" data-target="#reCalcAll" title="全部计算"><i class="fa fa-calculator"></i></a>
                             </td>
                             <td>
                                 <a class="btn btn-secondary btn-sm import-source" href="javacript:void(0);" data-id="<%= lib.ID %>" title="导入原始数据"><i class="fa fa-sign-in fa-rotate-90"></i>导入</a>
@@ -122,8 +123,8 @@
                             <input id="libNameTxt" class="form-control" placeholder="输入定额库名称" type="text">
                         </div>
                         <div class="form-group">
-                            <label>定额编号</label>
-                            <input id="libCode" class="form-control" placeholder="输入定额编号" type="text">
+                            <label>定额库编码</label>
+                            <input id="libCode" class="form-control" placeholder="输入定额库编码" type="text">
                         </div>
                         <div class="form-group">
                             <label>费用定额名称</label>
@@ -159,8 +160,8 @@
                       <input class="form-control" id="renameText" placeholder="输入定额库名称" type="text" value="">
                     </div>
                       <div class="form-group">
-                          <label>定额编号</label>
-                          <input class="form-control" id="renameCode" placeholder="输入定额编号" type="text" value="">
+                          <label>定额库编码</label>
+                          <input class="form-control" id="renameCode" placeholder="输入定额库编码" type="text" value="">
                       </div>
                   </form>
                 </div>

+ 6 - 4
web/maintain/std_glj_lib/js/glj.js

@@ -246,7 +246,7 @@ let repositoryGljObj = {
     //工料机价格是否相同
     priceIsEqual: function (gljA, gljB) {
         if(!priceProperties || priceProperties.length === 0){
-            return gljA.basePrice === gljB.basePrice;
+            return gljA.basePrice == gljB.basePrice;
         }
         return _.isEqual(gljA.priceProperty, gljB.priceProperty);
     },
@@ -745,6 +745,7 @@ let repositoryGljObj = {
         return objA[me.colMapping.colToField[col]] !== objB[[me.colMapping.colToField[col]]];
     },
     onCellEditEnd: function(sender, args) {
+        debugger;
         let me = repositoryGljObj, that = gljComponentOprObj,
             updateArr = [], addArr = [], updateBasePrcArr = [];
         let deESCFields = ['code', 'name', 'specs'];//消除转义字符
@@ -859,7 +860,6 @@ let repositoryGljObj = {
                 }
             }
             if(!me.priceIsEqual(rObj, me.currentEditingGlj)){
-                console.log('df');
                 //update basePrice of ration when editting basePrice of glj
                 let gljType = -1;
                 let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
@@ -1503,15 +1503,17 @@ let repositoryGljObj = {
     updateRationBasePrcRq: function (basePrcArr, workBook, callback) {
         let me = this;
         me.prevent = true;
+        me.calcRation = true;
         if (!$.bootstrapLoading.isLoading()) {
             $.bootstrapLoading.start();
         }
         $.ajax({
             type: 'post',
             url: 'api/updateRationBasePrc',
-            data:{basePrcArr: JSON.stringify(basePrcArr)},
+            data:{basePrcArr: JSON.stringify(basePrcArr), repId: pageOprObj.gljLibId},
             dataType: 'json',
             success: function (result) {
+                me.calcRation = false;
                 if(result.error){
                     alert("计算定额基价失败");
                 }
@@ -1566,7 +1568,7 @@ let repositoryGljObj = {
                     sheetCommonObj.cleanData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, -1);
                     sheetsOprObj.showData(gljComponentOprObj, gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, me.currentComponent);
                 }
-                if ($.bootstrapLoading.isLoading()) {
+                if (!me.calcRation && $.bootstrapLoading.isLoading()) {
                     $.bootstrapLoading.end();
                 }
             },

+ 154 - 0
web/over_write/js/neimenggu_2017.js

@@ -0,0 +1,154 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Zhong
+ * @date 2019/4/17
+ * @version
+ */
+
+//允许使用的工料机类型:人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆、机械台班、机械组成物、机上人工、主材、设备、企业管理费、利润
+if(typeof allowGljType !== 'undefined'){
+    allowGljType = [1, 201, 202, 203, 204, 205, 206, 301, 302, 303, 4, 5, 6, 7];
+}
+if(typeof allowComponent !== 'undefined'){
+    //允许含有组成物的工料机类型:混凝土、砂浆、配合比、机械台班、主材
+    allowComponent = [202, 203, 204, 301, 4];
+}
+if(typeof componentType !== 'undefined'){
+    //可以作为组成物的工料机类型:普通材料、机械组成物、机上人工、主材
+    componentType = [201, 302, 303, 4];
+}
+if(typeof machineAllowComponent !== 'undefined'){
+    //允许含有组成物的机械工料机类型:机械台班
+    machineAllowComponent = [301];
+}
+if(typeof machineComponent !== 'undefined'){
+    //可以作为机械工料机组成物的工料机类型:机械组成物、机上人工
+    machineComponent = [302, 303];
+}
+if(typeof materialAllowComponent !== 'undefined'){
+    //允许含有组成物的材料工料机类型:混凝土、砂浆、配合比
+    materialAllowComponent = [202, 203, 204];
+}
+if(typeof materialComponent !== 'undefined'){
+    //可以作为材料工料机组成物的工料机类型:普通材料
+    materialComponent = [201];
+}
+//覆盖前端基价计算
+//基价=人工费+材料费+机械费+管理费利润
+//管理费利润=Round(人工费*(管理费消耗量+利润消耗量)%,2) 注:书中管理费、利润的单位都是“%”
+if (typeof rationGLJOprObj !== 'undefined' && typeof rationGLJOprObj.rationCal !== 'undefined') {
+    rationGLJOprObj.rationCal = function () {
+        let me = rationGLJOprObj;
+        let price = {gljType1: [], gljType2: [], gljType3: []},
+            rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0},
+            rationBasePrc = 0;
+        let manageProfitConsume = 0;   //管理费、利润消耗量
+        if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
+            let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
+            cacheArr.forEach(function (gljData) {
+                if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
+                    let parent = me.distTypeTree.distTypes[me.distTypeTree.prefix + gljData.gljType].parent;
+                    if(parent && parent.data.ID <= 3){
+                        price['gljType' + parent.data.ID].push(scMathUtil.roundTo(gljData.basePrice * gljData.consumeAmt, -3));//取三位
+                    }
+                    if(!parent && gljData.gljType <= 3){
+                        price['gljType' + gljData.gljType].push(scMathUtil.roundTo(gljData.basePrice * gljData.consumeAmt, -3));//取三位
+                    }
+                    if([6, 7].includes(gljData.gljType)){
+                        manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljData.consumeAmt, -6);
+                    }
+                }
+            });
+            if(price.gljType1.length > 0){
+                let labourPrice = 0;
+                price.gljType1.forEach(function (singlePrc) {
+                    labourPrice = scMathUtil.roundTo(labourPrice + singlePrc, me.processDecimal);
+                });
+                let roundPrice = scMathUtil.roundTo(labourPrice, -2);
+                rst.labourPrice = roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
+                //管理费利润
+                let manageProfitPrc = scMathUtil.roundTo(roundPrice * manageProfitConsume * 0.01, -2);
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + manageProfitPrc, -2);
+            }
+            if(price.gljType2.length > 0){
+                let materialPrice = 0;
+                price.gljType2.forEach(function (singlePrc) {
+                    materialPrice = scMathUtil.roundTo(materialPrice + singlePrc, me.processDecimal);
+                });
+                let roundPrice = scMathUtil.roundTo(materialPrice, -2);
+                rst.materialPrice = roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
+            }
+            if(price.gljType3.length > 0){
+                let machinePrice = 0;
+                price.gljType3.forEach(function (singlePrc) {
+                    machinePrice = scMathUtil.roundTo(machinePrice + singlePrc, me.processDecimal);
+                });
+                let roundPrice = scMathUtil.roundTo(machinePrice, -2);
+                rst.machinePrice = roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
+            }
+            rst.rationBasePrc = rationBasePrc;
+        }
+        return rst;
+    }
+}
+
+if (typeof module !== 'undefined') {
+    module.exports = {
+        calcRation: function (gljArr, scMathUtil) {
+            let labourPrc = [],
+                materialPrc = [],
+                machinePrc = [],
+                manageProfitConsume = 0,
+                singlePrc,
+                updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, manageProfitPrice: 0, basePrice: 0};
+            gljArr.forEach(function (gljItem) {
+                if(gljItem.gljParentType !== -1){
+                    singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
+                    if(gljItem.gljParentType === 1){
+                        labourPrc.push(singlePrc);
+                    } else if(gljItem.gljParentType ===2){
+                        materialPrc.push(singlePrc);
+                    } else if(gljItem.gljParentType === 3){
+                        machinePrc.push(singlePrc);
+                    } else if(gljItem.gljParentType === 6){
+                        manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, -6);
+                    } else if(gljItem.gljParentType === 7){
+                        manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, -6);
+                    }
+                }
+            });
+            if(labourPrc.length > 0){
+                let sumLaP = 0;
+                for(let i=0; i<labourPrc.length; i++){
+                    sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], -6);
+                }
+                updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
+                updatePrc.manageProfitPrice = scMathUtil.roundTo(updatePrc.labourPrice * manageProfitConsume * 0.01, -2);
+                updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.manageProfitPrice, -2);
+            }
+            if(materialPrc.length > 0){
+                let sumMtP = 0;
+                for(let i= 0; i<materialPrc.length; i++){
+                    sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], -6);
+                }
+                updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
+                updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.materialPrice, -2);
+            }
+            if(machinePrc.length > 0){
+                let sumMaP = 0;
+                for(let i =0; i< machinePrc.length; i++){
+                    sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], -6);
+                }
+                updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
+                updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.machinePrice, -2);
+            }
+            return updatePrc;
+        }
+    };
+}