| 
					
				 | 
			
			
				@@ -10,11 +10,48 @@ let rationRepositoryDao = require('./repository_map'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const scMathUtil = require('../../../public/scMathUtil').getUtil(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const rationItemModel = mongoose.model('std_ration_lib_ration_items'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const stdRationLibModel = mongoose.model('std_ration_lib_map'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const stdRationSectionModel = mongoose.model('std_ration_lib_ration_chapter_trees'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const compleRationModel = mongoose.model('complementary_ration_items'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import STDGLJListModel from '../../std_glj_lib/models/gljModel'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import InstallationDao from '../models/installation'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const installationDao = new InstallationDao(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import GljDao from "../../std_glj_lib/models/gljModel"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const stdGljDao = new GljDao(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import stdgljutil  from "../../../public/cache/std_glj_type_util"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 var rationItemDAO = function(){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+rationItemDAO.prototype.prepareInitData = async function (rationRepId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 定额库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const libTask = stdRationLibModel.findOne({ID: rationRepId}, '-_id ID dispName gljLib'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 定额编码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const codesTask = rationItemModel.find({rationRepId}, '-_id code', {lean: true}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 定额章节树 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const sectionTreeTask = stdRationSectionModel.find({rationRepId}, '-_id', {lean: true}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 安装增加费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const installationTask = installationDao.getInstallation(rationRepId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const [libInfo, codesArr, sectionTree, installationList] = await Promise.all([libTask, codesTask, sectionTreeTask, installationTask]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const rationsCodes = codesArr.reduce((acc, cur) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        acc.push(cur.code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return acc; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }, []); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 人材机分类树 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const gljLibId = libInfo.gljLib; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const gljTreeTask = stdGljDao.getGljTreeSync(gljLibId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const gljTask = stdGljDao.getGljItemsSync(gljLibId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const [gljTree, gljList] = await Promise.all([gljTreeTask, gljTask]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const gljDistTypeList = stdgljutil.getStdGljTypeCacheObj().toArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        libInfo, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rationsCodes, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sectionTree, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        installationList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        gljTree, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        gljList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        gljDistTypeList 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 rationItemDAO.prototype.getRationItemsByLib = async function (rationRepId, showHint = null, returnFields = '') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let rationLib = await stdRationLibModel.findOne({ID: rationRepId, deleted: false}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if(!rationLib){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -101,15 +138,49 @@ rationItemDAO.prototype.sortToNumber = function (datas) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-rationItemDAO.prototype.getRationItemsBySection = function(rationRepId, sectionId,callback){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+rationItemDAO.prototype.getRationItemsBySection = async function(rationRepId, sectionId,callback){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let me = this; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    rationItemModel.find({"rationRepId": rationRepId, "sectionId": sectionId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let rations = await rationItemModel.find({rationRepId: rationRepId, sectionId: sectionId}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        me.sortToNumber(rations); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let matchRationIDs = [], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            matchRations = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (let ration of rations) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (ration.rationTemplateList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (let rt of ration.rationTemplateList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (rt.rationID) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        matchRationIDs.push(rt.rationID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (matchRationIDs.length > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            matchRations = await rationItemModel.find({ID: {$in: matchRationIDs}}, '-_id ID code name'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (let mr of matchRations) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (let ration of rations) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (ration.rationTemplateList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    for (let rt of ration.rationTemplateList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (rt.rationID && rt.rationID === mr.ID) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            rt.code = mr.code ? mr.code : ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            rt.name = mr.name ? mr.name : ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        callback(false,"Get items successfully", rations); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } catch (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        console.log(err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        callback(true, "Fail to get items", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /*  rationItemModel.find({"rationRepId": rationRepId, "sectionId": sectionId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(err) callback(true, "Fail to get items", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             me.sortToNumber(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             callback(false,"Get items successfully", data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    })*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 rationItemDAO.prototype.mixUpdateRationItems = function(rationLibId, lastOpr, sectionId, updateItems, addItems, rIds, callback){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     var me = this; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -144,7 +215,16 @@ rationItemDAO.prototype.removeRationItems = function(rationLibId, lastOpr, rIds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 rationRepositoryDao.updateOprArr({ID: rationLibId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     if(!err){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        callback(false, "Remove successfully", docs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        rationItemModel.update({rationRepId: rationLibId}, {$pull: {rationTemplateList: {rationID: {$in: rIds}}}}, function (theErr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (!theErr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                callback(false, "Remove successfully", docs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                callback(true, "Fail to remove", false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        callback(true, "Fail to remove", false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -179,20 +259,9 @@ rationItemDAO.prototype.findRation = function (repId, keyword, callback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-rationItemDAO.prototype.getRationItem = function (repId, code, callback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (callback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        rationItemModel.findOne({rationRepId: repId, code: code, "$or": [{"isDeleted": null}, {"isDeleted": false}]}, '-_id').exec() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            .then(function (result, err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    callback(1, '找不到定额“' + code +'”' , null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    callback(0, '', result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return rationItemModel.findOne({rationRepId: repId, code: code, "$or": [{"isDeleted": null}, {"isDeleted": false}]}, '-_id').exec(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+rationItemDAO.prototype.getRationItem = async function (repId, code) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let ration = await rationItemModel.findOne({rationRepId: repId, code: code}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return ration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 rationItemDAO.prototype.addRationItems = function(rationLibId, lastOpr, sectionId, items,callback){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -228,6 +297,7 @@ rationItemDAO.prototype.addRationItems = function(rationLibId, lastOpr, sectionI 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 rationItemDAO.prototype.updateRationItems = function(rationLibId, lastOpr, sectionId, items,callback){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    console.log('enter============'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     var functions = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (var i=0; i < items.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         functions.push((function(doc) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -268,8 +338,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([ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -346,7 +498,6 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 gljDao.getStdCompleGljItems(compleGljIds, stdGljIds, function (err, allGljs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    const processDecimal = -6; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     if(err){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         cb(err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -367,36 +518,33 @@ 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 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        gljArr.push({gljId: theGlj.ID, basePrice: adjBasePrice, gljParentType: gljParentType, unit: theGlj.unit}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    } 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 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                            gljArr.push({gljId: theGlj.ID, basePrice: parseFloat(theGlj.basePrice), gljParentType: gljParentType}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            gljArr.push({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                gljId: theGlj.ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                basePrice: parseFloat(theGlj.priceProperty.price1), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                gljParentType: gljParentType, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                unit: theGlj.unit}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            gljArr.push({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                gljId: theGlj.ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                basePrice: parseFloat(theGlj.basePrice), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                gljParentType: gljParentType, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                unit: theGlj.unit}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -408,82 +556,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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            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.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 (!overWriteCalc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                updatePrc = calcRation(gljArr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            updatePrc.basePrice = scMathUtil.roundTo( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             let task = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 updateOne: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     filter: { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -632,127 +716,89 @@ rationItemDAO.prototype.updateAnnotation = function (lastOpr, repId, updateArr, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//计算导入数据的价格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-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){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//更新定额下模板关联 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+rationItemDAO.prototype.updateRationTemplate = async function (rationRepId, rationID, templateData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //自动匹配定额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let matachCodes = [], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        matchRations = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //要保存的数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let saveData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (let data of templateData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (data.code) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            matachCodes.push(data.code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    //计算人工费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    matachCodes = Array.from(new Set(matachCodes)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (matachCodes.length > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        matchRations = await rationItemModel.find({rationRepId: rationRepId, code: {$in: matachCodes}}, '-_id ID code name'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    //材料费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if(materialPrc.length > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let sumMtP = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for(let i = 0, len  = materialPrc.length; i < len; i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], processDecimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let validData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //设置展示数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (let data of templateData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let match = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (let ration of matchRations) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (data.code && data.code === ration.code) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                match = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                data.name = ration.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                data.rationID = ration.ID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!match) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data.code = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data.name = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (data.type || data.code || data.name || data.billsLocation) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            validData.push(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (let data of validData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        saveData.push({rationID: data.rationID ? data.rationID : null, type: data.type, billsLocation: data.billsLocation}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    //风险费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if(riskPrc.length > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let sumRkP = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for(let i = 0, len  = riskPrc.length; i < len; i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], processDecimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //更新 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    await rationItemModel.update({ID: rationID}, {$set: {rationTemplateList: saveData}}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return validData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 根据章节列表批量更新定额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+rationItemDAO.prototype.updateRationBySection = async function (rationRepId, sectionList, updateData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    await rationItemModel.updateMany({rationRepId, sectionId: {$in: sectionList}}, updateData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//计算导入数据的价格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+rationItemDAO.prototype.calcForRation = function (stdGljList, ration, overWriteUrl) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let rationGljList = ration.rationGljList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        gljArr = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for(let rationGlj of rationGljList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let glj = stdGljList[rationGlj.gljId]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let gljPType = parseInt(glj.gljType.toString().match(/\d+?/)[0]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let newGlj = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            gljId: glj.ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            consumeAmt: rationGlj.consumeAmt, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            gljParentType: gljPType, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            unit: glj.unit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        newGlj.basePrice = glj.priceProperty && Object.keys(glj.priceProperty).length > 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ? parseFloat(glj.priceProperty.price1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            : parseFloat(glj.basePrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        gljArr.push(newGlj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    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.riskPrice = scMathUtil.roundTo(sumRkP, -2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    //基价 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    updatePrc.basePrice = scMathUtil.roundTo( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    //更新定额数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (!overWriteCalc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        updatePrc = calcRation(gljArr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     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'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if(profit.includes(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return 'profit'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if(risk.includes(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return 'risk' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -806,12 +852,14 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         stdGLJListByID[tmp.ID] = tmp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let lastData = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 定额xx下提示的次数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let lastFailCount = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const rationData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 编码列表,用于查找库中是否有对应数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let rationCodeList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let gljCodeList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 插入失败的工料机列表(用于提示) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    this.failGLJList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let failGLJList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (const tmp of data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (tmp.length <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             continue; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -820,8 +868,12 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (tmp[0] === undefined && Object.keys(lastData).length > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 如果不存在对应的工料机库数据则跳过 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (stdGLJList[tmp[1]] === undefined) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                const failString = '定额' + lastData.code + '下的' + tmp[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                this.failGLJList.push(failString); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (lastFailCount === 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    failGLJList.push('定额' + lastData.code + '下的'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    lastFailCount++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //const failString = '定额' + lastData.code + '下的' + tmp[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                failGLJList.push(tmp[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tmpRationGlj = { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -839,7 +891,7 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (tmp[0] === '定额' && Object.keys(lastData).length > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             rationData.push(lastData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        lastFailCount = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 组装数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         lastData = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             code: tmp[1], 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -897,7 +949,7 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 如果都已经存在,直接返回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (insertData.length <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return failGLJList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //计算价格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for(let ration of insertData){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -915,8 +967,8 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         count++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 插入数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const result = await rationItemModel.create(insertData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return result.length > 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    await rationItemModel.create(insertData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return failGLJList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -929,17 +981,20 @@ rationItemDAO.prototype.exportExcelData = async function(rationRepId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const condition = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         rationRepId: rationRepId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // @todo 限制导出的数量以防内存溢出 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const rationDataList = await this.getRationItemByCondition(condition, ['name', 'code', 'ID', 'sectionId', 'feeType', 'caption', 'basePrice']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const rationDataList = await this.getRationItemByCondition(condition, ['name', 'code', 'ID', 'sectionId', 'feeType', 'caption', 'basePrice', 'jobContent', 'annotation']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 整理数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let rationData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (const tmp of rationDataList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         const sectionId = tmp.sectionId <= 0 || tmp.sectionId === undefined ? null : tmp.sectionId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         const feeType = tmp.feeType === '' || tmp.feeType === undefined ? null : tmp.feeType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        const ration = [sectionId, feeType, tmp.ID, tmp.code, tmp.name, tmp.caption, tmp.basePrice]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        const ration = [sectionId, feeType, tmp.ID, tmp.code, tmp.name, tmp.caption, tmp.basePrice, tmp.jobContent, tmp.annotation]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         rationData.push(ration); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const excelData = [['树ID', '取费专业', '定额ID', '定额编码', '定额名', '定额显示名称', '基价', '工作内容', '附注']]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    excelData.push.apply(excelData, rationData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return excelData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //根据编号排序,优先级:number-number-..., number, Anumber.... 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /*let regConnector = /-/g, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         regLetter = /[a-z,A-Z]/g, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1003,10 +1058,10 @@ rationItemDAO.prototype.exportExcelData = async function(rationRepId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return rst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     });*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const excelData = [['树ID', '取费专业', '定额ID', '定额编码', '定额名', '定额显示名称', '基价']]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /*const excelData = [['树ID', '取费专业', '定额ID', '定额编码', '定额名', '定额显示名称', '基价']]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     excelData.push.apply(excelData, rationData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return excelData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return excelData;*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1020,12 +1075,17 @@ rationItemDAO.prototype.batchUpdateSectionIdFromExcel = async function(data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 批量执行update 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let bulkOprs = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let bulkOprs = [], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sectionIDs = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (const tmp of data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let rationId = parseInt(tmp[2]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         rationId = isNaN(rationId) || rationId <= 0 ? 0 : rationId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let sectionId = parseInt(tmp[0]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sectionId = isNaN(sectionId) || sectionId <= 0 ? 0 : sectionId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (sectionId <= 0 || rationId <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sectionIDs.push(sectionId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 取费专业 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let feeType = tmp[1] ? parseInt(tmp[1]) : null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         feeType = isNaN(feeType) || feeType <= 0 ? null : feeType; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1033,15 +1093,35 @@ rationItemDAO.prototype.batchUpdateSectionIdFromExcel = async function(data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         name = name ? name : ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let caption = tmp[5]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         caption = caption ? caption : ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (sectionId <= 0 || rationId <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        bulkOprs.push({updateOne: {filter: {ID: rationId}, update: {$set: {sectionId: sectionId, feeType: feeType, name: name, caption: caption}}}}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let jobContent = tmp[7] ? tmp[7] : ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let annotation = tmp[8] ? tmp[8] : ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bulkOprs.push({updateOne: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            filter: {ID: rationId}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            update: {$set: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sectionId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                feeType, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                name, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                caption, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                jobContent, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                annotation 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }}} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if(bulkOprs.length <= 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         throw '无有效数据(树ID、定额ID不为空、且为数值)'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     await rationItemModel.bulkWrite(bulkOprs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 更新章节树工作内容、附注节点选项(全设置为ALL) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    sectionIDs = Array.from(new Set(sectionIDs)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (sectionIDs.length) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        await stdRationSectionModel.updateMany( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            {ID: {$in: sectionIDs}}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            {$set: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                jobContentSituation: 'ALL', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                annotationSituation: 'ALL' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 module.exports = new rationItemDAO(); 
			 |