| 
					
				 | 
			
			
				@@ -26,6 +26,7 @@ let quantityDetailModel = mongoose.model('quantity_detail'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 let featureLibModel =  mongoose.model("std_project_feature_lib"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 let scMathUtil = require('../../../public/scMathUtil').getUtil(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+let counter = require('../../../public/counter/counter'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import CounterModel from "../../glj/models/counter_model"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import moment from 'moment'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import billsFlags from '../../common/const/bills_fixed'; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -41,6 +42,7 @@ const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 module.exports={ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     moveProject:moveProject, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     copyProject:copyProject, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    copyExample: copyExample, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     getSummaryInfo: getSummaryInfo, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     getSummaryInfoByTender: getSummaryInfoByTender, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     getConstructionProject: getConstructionProject, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -51,9 +53,78 @@ module.exports={ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     isShare: isShare, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//拷贝父级项目 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-async function copyParent(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//拷贝例题项目 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//@param {String}userID {Array}projIDs拷贝的例题项目ID(建设项目、文件夹)@return {Boolean} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+async function copyExample(userID, compilation, projIDs){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let allProjs = [], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        IDMapping = {}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        projMapping = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //例题项目不可为单项工程、单位工程、只能是建设项目、文件夹,否则不自动新建例题项目(这里不报错,让用户没有感觉) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let parentExample = await projectModel.find({ID: {$in: projIDs}, $or: notDeleted}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (parentExample.length === 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    allProjs = allProjs.concat(parentExample); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (let i = 0; i < parentExample.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let data = parentExample[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (data.projType === projectType.tender || data.projType === projectType.engineering) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //设置成顶节点,最后一个节点设置成末节 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.ParentID = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (i === parentExample.length - 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data.NextSiblingID = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //获取所有的子项目 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let posterityProjs = await getPosterityProjects(projIDs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    allProjs = allProjs.concat(posterityProjs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let projCounter = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.project, allProjs.length); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //旧ID与新ID映射 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (let i = 0; i < allProjs.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let data = allProjs[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let newID = projCounter.sequence_value - (allProjs.length - 1) + i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        IDMapping[data.ID] = newID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        projMapping[newID] = data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //设置新的树结构数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let newDate = new Date(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parentBulks = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (let data of allProjs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let orgID = data.ID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.ID = IDMapping[data.ID]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.ParentID = IDMapping[data.ParentID] ? IDMapping[data.ParentID] : -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.NextSiblingID = IDMapping[data.NextSiblingID] ? IDMapping[data.NextSiblingID] : -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.createDateTime = newDate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.userID = userID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.compilation = compilation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.shareInfo = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (data.projType !== projectType.tender) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let newData = _.cloneDeep(data._doc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            delete newData._id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          //  await projectModel.create(newData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            parentBulks.push({insertOne: {document: newData}}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //拷贝单位工程 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let rootProjectID = projMapping[data.ParentID].ParentID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let projectMap = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                copy: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    document: {userID: userID, ID: orgID, NextSiblingID: data.NextSiblingID, ParentID: data.ParentID, name: data.name, shareInfo: [], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                compilation: compilation, fileVer: data.fileVer, projType: data.projType, property: {rootProjectID: rootProjectID}} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await copyProject(userID, compilation, {projectMap}, data.ID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //最末顶层项目(兼容测试时已存在有项目,正常用户第一次进费用定额,该费用定额不存在项目) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let lastProj = await projectModel.findOne({userID: userID, compilation: compilation, ParentID: -1, NextSiblingID: -1, $or: notDeleted}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (lastProj) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parentBulks.push({updateOne: {filter: {ID: lastProj.ID}, update: {$set: {NextSiblingID: parentExample[0].ID}}}}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //拷贝父级文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    await projectModel.bulkWrite(parentBulks); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 async function copyProject(userID, compilationID,data,newProjectID = null) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -733,7 +804,7 @@ async function getProjectFeature(libID,feeStandardName){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//获取文件下所有子项目 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//获取projectIDs文件下所有子项目(不包括projectIDs本身) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 async function getPosterityProjects(projectIDs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let rst = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     async function getProjects(IDs) { 
			 |