| 
					
				 | 
			
			
				@@ -9,6 +9,7 @@ let gljDao = require('./glj_repository'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 let rationRepositoryDao = require('./repository_map'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const scMathUtil = require('../../../public/scMathUtil').getUtil(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import {rationItemModel} from './schemas'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import STDGLJListModel from '../../std_glj_lib/models/gljModel'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 var rationItemDAO = function(){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -494,6 +495,19 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (data.length <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 获取定额库相关数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const rationRepository = await rationRepositoryDao.getRepositoryById(rationRepId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (rationRepository.length !== 1 || rationRepository[0].gljLib === undefined) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 获取标准工料机库数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const stdBillsLibListsModel = new STDGLJListModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const stdGLJData = await stdBillsLibListsModel.getGljItemsByRep(rationRepository[0].gljLib); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 整理标准工料机库数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let stdGLJList = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (const tmp of stdGLJData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        stdGLJList[tmp.code.toString()] = tmp.ID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let lastData = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const rationData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 编码列表,用于查找库中是否有对应数据 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -505,8 +519,12 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 如果第一个字段为null则是工料机数据,放入上一个数据的工料机字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (tmp[0] === undefined && Object.keys(lastData).length > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 如果不存在对应的工料机库数据则跳过 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (stdGLJList[tmp[1]] === undefined) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tmpRationGlj = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                gljId: 1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                gljId: stdGLJList[tmp[1]], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 consumeAmt: tmp[4], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 proportion: 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -528,6 +546,7 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             unit: tmp[3], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             caption: tmp[2], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             rationRepId: rationRepId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sectionId: 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             rationGljList: [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 防止重复加入 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -556,7 +575,6 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (insertData.length <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 组织id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const counterInfo = await counter.counterDAO.getIDAfterCount(counter.moduleName.rations, insertData.length); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let maxId = counterInfo.value.sequence_value; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -583,18 +601,45 @@ rationItemDAO.prototype.exportExcelData = async function(rationRepId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         rationRepId: rationRepId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // @todo 限制导出的数量以防内存溢出 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const rationDataList = await this.getRationItemByCondition(condition, ['name', 'code']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const rationDataList = await this.getRationItemByCondition(condition, ['name', 'code', 'ID']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 整理数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let rationData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (const tmp of rationDataList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        const ration = [null, tmp.code, tmp.name]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        const ration = [null, tmp.ID, tmp.code, tmp.name]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         rationData.push(ration); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const excelData = [['树ID', '定额名', '定额编码']]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const excelData = [['树ID', '定额ID', '定额编码', '定额名']]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     excelData.push.apply(excelData, rationData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return excelData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 批量更改章节id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @param {Object} data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @return {bool} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+rationItemDAO.prototype.batchUpdateSectionIdFromExcel = async function(data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (data.length <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 批量执行update 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const bulk = rationItemModel.collection.initializeOrderedBulkOp(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (const tmp of data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let rationId = parseInt(tmp[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bulk.find({"ID": rationId}).update({$set: { sectionId: sectionId }}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const result = await bulk.execute(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return result.isOk(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 module.exports = new rationItemDAO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |