pm_facade.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /**
  2. * Created by zhang on 2018/4/17.
  3. */
  4. let mongoose = require('mongoose');
  5. let _ = require("lodash");
  6. let feeRate_facade = require('../../fee_rates/facade/fee_rates_facade');
  7. let project_facade = require('../../main/facade/project_facade');
  8. let logger = require("../../../logs/log_helper").logger;
  9. const uuidV1 = require('uuid/v1');
  10. let projectModel = mongoose.model('projects');
  11. let projectSettingModel = mongoose.model('proj_setting');
  12. let billsModel = mongoose.model('bills');
  13. let rationModel = mongoose.model('ration');
  14. let gljListModel = mongoose.model("glj_list");
  15. let calcProgramsModel = mongoose.model('calc_programs');
  16. let labourCoesModel = mongoose.model('labour_coes');
  17. let feeRateModel = mongoose.model('fee_rates');
  18. let feeRateFileModel = mongoose.model('fee_rate_file');
  19. let unitPriceFileModel = mongoose.model("unit_price_file");
  20. let mixRatioModel = mongoose.model("mix_ratio");
  21. let unitPriceModel = mongoose.model("unit_price");
  22. let installationFeeModel = mongoose.model("installation_fee");
  23. let rationGLJModel = mongoose.model('ration_glj');
  24. let rationCoeModel = mongoose.model('ration_coe');
  25. let rationInstallationModel = mongoose.model('ration_installation');
  26. let quantityDetailModel = mongoose.model('quantity_detail');
  27. let rationTemplateModel = mongoose.model('ration_template');
  28. let userModel = mongoose.model('user');
  29. let compleGljSectionModel = mongoose.model('complementary_glj_section');
  30. let compleGljSectionTModel = mongoose.model('complementary_glj_section_templates');
  31. let featureLibModel = mongoose.model("std_project_feature_lib");
  32. let scMathUtil = require('../../../public/scMathUtil').getUtil();
  33. let counter = require('../../../public/counter/counter');
  34. import SectionTreeDao from '../../complementary_ration_lib/models/sectionTreeModel';
  35. let sectionTreeDao = new SectionTreeDao();
  36. import CounterModel from "../../glj/models/counter_model";
  37. import moment from 'moment';
  38. import billsFlags from '../../common/const/bills_fixed';
  39. const projectType = {
  40. folder: 'Folder',
  41. tender: 'Tender',
  42. project: 'Project',
  43. engineering: 'Engineering',
  44. };
  45. const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
  46. module.exports={
  47. moveProject:moveProject,
  48. copyProject:copyProject,
  49. copyExample: copyExample,
  50. getSummaryInfo: getSummaryInfo,
  51. getSummaryInfoByTender: getSummaryInfoByTender,
  52. getTendersFeeInfo: getTendersFeeInfo,
  53. getConstructionProject: getConstructionProject,
  54. getFullPath: getFullPath,
  55. getProjectFeature:getProjectFeature,
  56. projectType: projectType,
  57. getPosterityProjects: getPosterityProjects,
  58. isShare: isShare,
  59. getShareInfo: getShareInfo,
  60. prepareInitialData: prepareInitialData,
  61. changeFile:changeFile
  62. };
  63. //拷贝例题项目
  64. //@param {String}userID {Array}projIDs拷贝的例题项目ID(建设项目、文件夹)@return {Boolean}
  65. async function copyExample(userID, compilation, projIDs){
  66. let allProjs = [],
  67. IDMapping = {},
  68. projMapping = {};
  69. //例题项目不可为单项工程、单位工程、只能是建设项目、文件夹,否则不自动新建例题项目(这里不报错,让用户没有感觉)
  70. let parentExample = await projectModel.find({ID: {$in: projIDs}, $or: notDeleted});
  71. if (parentExample.length === 0) {
  72. return false;
  73. }
  74. allProjs = allProjs.concat(parentExample);
  75. for (let i = 0; i < parentExample.length; i++) {
  76. let data = parentExample[i];
  77. if (data.projType === projectType.tender || data.projType === projectType.engineering) {
  78. return false;
  79. }
  80. //设置成顶节点,最后一个节点设置成末节
  81. data.ParentID = -1;
  82. if (i === parentExample.length - 1) {
  83. data.NextSiblingID = -1;
  84. }
  85. }
  86. //获取所有的子项目
  87. let posterityProjs = await getPosterityProjects(projIDs);
  88. allProjs = allProjs.concat(posterityProjs);
  89. let projCounter = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.project, allProjs.length);
  90. //旧ID与新ID映射
  91. for (let i = 0; i < allProjs.length; i++) {
  92. let data = allProjs[i];
  93. let newID = projCounter.sequence_value - (allProjs.length - 1) + i;
  94. IDMapping[data.ID] = newID;
  95. projMapping[newID] = data;
  96. }
  97. //return;
  98. //设置新的树结构数据
  99. let newDate = new Date(),
  100. parentBulks = [];
  101. for (let data of allProjs) {
  102. let orgID = data.ID;
  103. data.ID = IDMapping[data.ID];
  104. data.ParentID = IDMapping[data.ParentID] ? IDMapping[data.ParentID] : -1;
  105. data.NextSiblingID = IDMapping[data.NextSiblingID] ? IDMapping[data.NextSiblingID] : -1;
  106. data.createDateTime = newDate;
  107. data.userID = userID;
  108. data.compilation = compilation;
  109. data.shareInfo = [];
  110. if (data.projType !== projectType.tender) {
  111. let newData = _.cloneDeep(data._doc);
  112. delete newData._id;
  113. // await projectModel.create(newData);
  114. parentBulks.push({insertOne: {document: newData}});
  115. } else {
  116. //拷贝单位工程
  117. let rootProjectID = projMapping[data.ParentID].ParentID;
  118. let projectMap = {
  119. copy: {
  120. document: {userID: userID, ID: orgID, NextSiblingID: data.NextSiblingID, ParentID: data.ParentID, name: data.name, shareInfo: [],
  121. compilation: compilation, fileVer: data.fileVer, projType: data.projType, property: {rootProjectID: rootProjectID}}
  122. }
  123. };
  124. await copyProject(userID, compilation, {projectMap}, data.ID);
  125. }
  126. }
  127. //最末顶层项目(兼容测试时已存在有项目,正常用户第一次进费用定额,该费用定额不存在项目)
  128. let lastProj = await projectModel.findOne({userID: userID, compilation: compilation, ParentID: -1, NextSiblingID: -1, $or: notDeleted});
  129. if (lastProj) {
  130. parentBulks.push({updateOne: {filter: {ID: lastProj.ID}, update: {$set: {NextSiblingID: parentExample[0].ID}}}});
  131. }
  132. //拷贝父级文件
  133. await projectModel.bulkWrite(parentBulks);
  134. return true;
  135. }
  136. async function copyProject(userID, compilationID,data,newProjectID = null) {
  137. let projectMap = data.projectMap;
  138. let originalID = projectMap['copy'].document.ID;
  139. if (!newProjectID) {
  140. newProjectID = await getCounterID("projects");
  141. }
  142. let newFeeName = null,newUnitName = null;
  143. let calcProgramFileID = uuidV1();//新的计算程序文件ID
  144. let labourCoeFileID = uuidV1();//新的人工调整系数文件ID
  145. let feeRateFileID = uuidV1();//新的费率文件ID
  146. let unitPriceFileID = await getCounterID("unit_price_file");//新的单价文件ID
  147. let originalProject = await projectModel.findOne({'ID':originalID});//查找最新的那项目信息,前端缓存的数据有可能不是最新的
  148. if(!originalProject){
  149. throw new Error('没有找到对应的项目,复制失败!');
  150. }
  151. let property = originalProject.property;
  152. if(projectMap['copy'].document.property){//更新项目属性信息
  153. setProperty(property,projectMap['copy'].document.property);
  154. }
  155. let originalProperty = _.cloneDeep(property);
  156. projectMap['copy'].document.property = property;
  157. logger.info("复制项目: 旧项目ID: "+originalID+ " ------- 新项目ID: "+newProjectID);
  158. //费率文件、单价文件重名检查
  159. let feeRate = await feeRateFileModel.findOne({rootProjectID:originalProperty.rootProjectID,name:originalProperty.feeFile.name,deleteInfo:null});
  160. if(feeRate){//存在重名的文件
  161. newFeeName = originalProperty.feeFile.name + '(' + moment(Date.now()).format('MM-DD HH:mm:ss') + '复制)';
  162. projectMap['copy'].document.property.feeFile.name = newFeeName;
  163. }
  164. let unitPriceFile = await unitPriceFileModel.findOne({root_project_id: originalProperty.rootProjectID,name:originalProperty.unitPriceFile.name,deleteInfo: null});
  165. if(unitPriceFile){//存在重名的文件
  166. newUnitName = originalProperty.unitPriceFile.name + '(' + moment(Date.now()).format('MM-DD HH:mm:ss') + '复制)';
  167. projectMap['copy'].document.property.unitPriceFile.name = newUnitName;
  168. }
  169. //更新项目的属性;
  170. projectMap['copy'].document.ID = newProjectID;
  171. if(projectMap['copy'].document.property.calcProgramFile){
  172. projectMap['copy'].document.property.calcProgramFile.ID = calcProgramFileID;
  173. }
  174. if(projectMap['copy'].document.property.labourCoeFile){
  175. projectMap['copy'].document.property.labourCoeFile.ID = labourCoeFileID;
  176. }
  177. if(projectMap['copy'].document.property.feeFile){
  178. projectMap['copy'].document.property.feeFile.id = feeRateFileID;
  179. }
  180. if(projectMap['copy'].document.property.unitPriceFile){
  181. projectMap['copy'].document.property.unitPriceFile.id = unitPriceFileID;
  182. }
  183. projectMap['copy'].document.userID = userID;
  184. projectMap['copy'].document.compilation = compilationID;
  185. projectMap['copy'].document.createDateTime = new Date();
  186. //清单、定额ID生成任务
  187. let IDtasks = [
  188. createIDsAndReturn(originalID,billsModel),
  189. createIDsAndReturn(originalID,rationModel),
  190. getProjectGLJIDAndReturn(originalID,newProjectID)
  191. ];
  192. let [billMap,rationMap,projectGLJMap] = await Promise.all(IDtasks);
  193. //所有复制任务异步处理,提升效率 复制清单,定额,4个文件,项目工料机, 定额工料机,人工系数,工程量明细,定额安装增加费,安装增加费
  194. let copyTasks = [
  195. createProject(projectMap),
  196. copyProjectSetting(originalID,newProjectID),
  197. copyBills(newProjectID,billMap),
  198. copyRations(newProjectID,billMap.uuidMaping,rationMap,projectGLJMap.IDMap),
  199. copyProjectGLJ(projectGLJMap.datas),
  200. copyInstallFee(originalID,newProjectID),
  201. copyRationSubList(originalID,newProjectID,billMap.uuidMaping,rationMap.uuidMaping,projectGLJMap.IDMap,rationGLJModel),
  202. copyRationSubList(originalID,newProjectID,billMap.uuidMaping,rationMap.uuidMaping,projectGLJMap.IDMap,rationCoeModel),
  203. copyRationSubList(originalID,newProjectID,billMap.uuidMaping,rationMap.uuidMaping,projectGLJMap.IDMap,quantityDetailModel),
  204. copyRationSubList(originalID,newProjectID,billMap.uuidMaping,rationMap.uuidMaping,projectGLJMap.IDMap,rationInstallationModel),
  205. copyRationSubList(originalID,newProjectID,billMap.uuidMaping,rationMap.uuidMaping,projectGLJMap.IDMap,rationTemplateModel)
  206. ];
  207. if(originalProperty.calcProgramFile){
  208. copyTasks.push(commonCopy(newProjectID,originalProperty.calcProgramFile.ID,calcProgramFileID,calcProgramsModel));
  209. }
  210. if(originalProperty.labourCoeFile){
  211. copyTasks.push(commonCopy(newProjectID,originalProperty.labourCoeFile.ID,labourCoeFileID,labourCoesModel));
  212. }
  213. if(originalProperty.feeFile){
  214. copyTasks.push(copyFeeRate(originalProperty.rootProjectID,userID,originalProperty.feeFile.id,feeRateFileID,newFeeName));
  215. }
  216. if(originalProperty.unitPriceFile){
  217. copyTasks.push(copyUnitPriceFile(newProjectID,originalProperty.rootProjectID,userID,originalProperty.unitPriceFile.id,unitPriceFileID,newUnitName));
  218. }
  219. let p = await Promise.all(copyTasks);
  220. return p[0];
  221. }
  222. async function createIDsAndReturn(originalID,model) {
  223. let uuidMaping = {};//做ID映射
  224. let datas = [];
  225. let result = await model.find({"projectID": originalID}, '-_id');
  226. uuidMaping['-1'] = -1;
  227. //建立uuid-ID映射
  228. for(let d of result){
  229. uuidMaping[d.ID] = uuidV1();
  230. datas.push(d._doc);
  231. }
  232. return{uuidMaping:uuidMaping,datas:datas};
  233. }
  234. async function getProjectGLJIDAndReturn(originalID,newProjectID) {
  235. let IDMap = {};
  236. let datas = [];
  237. let result = await gljListModel.find({project_id:originalID}, '-_id');
  238. let gljCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.glj_list, result.length);
  239. for(let i = 0; i < result.length; i++){
  240. let d = result[i];
  241. let newID = gljCount.sequence_value - (result.length - 1) + i;
  242. //let newID = await getCounterID("glj_list");
  243. IDMap[d.id] = newID;
  244. d._doc.project_id = newProjectID;
  245. d._doc.id = newID;
  246. datas.push(d._doc);
  247. }
  248. return{IDMap:IDMap,datas:datas};
  249. }
  250. async function createProject(projectMap) {//复制项目
  251. let tasks = [];
  252. if(projectMap['update']){//如果复制后存在前一个节点,则更新其NextSiblingID
  253. tasks.push({updateOne:{filter : projectMap['update'].query, update : {NextSiblingID:projectMap['copy'].document.ID}}});
  254. }
  255. tasks.push({insertOne: {document: projectMap['copy'].document}});//复制任务
  256. await projectModel.bulkWrite(tasks);
  257. return projectMap;
  258. }
  259. async function copyProjectSetting(originalID,newProjectID) {
  260. let result = null;
  261. let setting = await projectSettingModel.findOne({"projectID": originalID}, '-_id');
  262. if(setting){
  263. setting._doc.projectID =newProjectID;
  264. result = await projectSettingModel.create(setting._doc);
  265. }
  266. return result;
  267. }
  268. async function copyBills(newProjectID,billMap) {
  269. let uuidMaping = billMap.uuidMaping;//做ID映射
  270. for(let doc of billMap.datas){
  271. doc.projectID = newProjectID;
  272. doc.ID = uuidMaping[doc.ID] ? uuidMaping[doc.ID] : -1;
  273. doc.ParentID = uuidMaping[doc.ParentID] ? uuidMaping[doc.ParentID] : -1;
  274. doc.NextSiblingID = uuidMaping[doc.NextSiblingID] ? uuidMaping[doc.NextSiblingID] : -1;
  275. }
  276. await insertMany(billMap.datas,billsModel);
  277. return billMap.datas;
  278. }
  279. async function copyRations(newProjectID,billsIDMap,rationMap,projectGLJIDMap) {
  280. let uuidMaping = rationMap.uuidMaping;
  281. for(let doc of rationMap.datas){
  282. doc.projectID = newProjectID;
  283. doc.ID = uuidMaping[doc.ID] ? uuidMaping[doc.ID] : -1;
  284. if(doc.billsItemID){
  285. doc.billsItemID = billsIDMap[doc.billsItemID]?billsIDMap[doc.billsItemID]:-1;
  286. }
  287. if(doc.referenceRationID) doc.referenceRationID = uuidMaping[doc.referenceRationID]?uuidMaping[doc.referenceRationID]:undefined;
  288. //绑定定类型的工料机 项目工料机ID
  289. doc.type==3&&doc.projectGLJID&&projectGLJIDMap[doc.projectGLJID]?doc.projectGLJID = projectGLJIDMap[doc.projectGLJID]:'';
  290. }
  291. if(rationMap.datas.length > 0){
  292. await insertMany(rationMap.datas,rationModel);
  293. }
  294. return rationMap.datas;
  295. }
  296. async function copyProjectGLJ(gljList) {
  297. await insertMany(gljList,gljListModel);
  298. }
  299. async function commonCopy(newProjectID,oldID,newID,model) { //对于只需更新ID和projectID的文件的复制
  300. let result = null;
  301. let file = await model.findOne({"ID": oldID}, '-_id');
  302. if(file){
  303. file._doc.ID = newID;
  304. file._doc.projectID =newProjectID;
  305. result = await model.create(file._doc);
  306. }
  307. return result;
  308. }
  309. async function copyFeeRate(rootProjectID,userID,originalFeeRateFileID,feeRateFileID,newName) {//复制费率和费率文件
  310. let [feeRateFile,feeRate] =await feeRate_facade.getFeeRateByID(originalFeeRateFileID);
  311. let newFeeRateID = uuidV1();
  312. if(feeRate){
  313. feeRate._doc.ID = newFeeRateID;
  314. await feeRateModel.create(feeRate._doc);
  315. }
  316. if(feeRateFile){
  317. feeRateFile._doc.ID = feeRateFileID;
  318. newName?feeRateFile._doc.name = newName:'';
  319. feeRateFile._doc.userID = userID;
  320. feeRateFile._doc.rootProjectID = rootProjectID;
  321. feeRateFile._doc.feeRateID = newFeeRateID;
  322. await feeRateFileModel.create(feeRateFile._doc);
  323. }
  324. }
  325. async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnitPriceFileID,unitPriceFileID,newName) {//复制单价文件、组成物
  326. let taskList = [
  327. copyFile(newProjectID,rootProjectID,userID,originaluUnitPriceFileID,unitPriceFileID,newName),
  328. copySubList(originaluUnitPriceFileID,unitPriceFileID,mixRatioModel),
  329. copySubList(originaluUnitPriceFileID,unitPriceFileID,unitPriceModel)
  330. ];
  331. return await Promise.all(taskList);
  332. async function copyFile(newProjectID,rootProjectID,userID,originaluUnitPriceFileID,unitPriceFileID,newName){
  333. let unitPriceFile = await unitPriceFileModel.findOne({id:originaluUnitPriceFileID}, '-_id');
  334. if(unitPriceFile){
  335. unitPriceFile._doc.id = unitPriceFileID;
  336. newName?unitPriceFile._doc.name = newName:'';
  337. unitPriceFile._doc.project_id = newProjectID;
  338. unitPriceFile._doc.user_id = userID;
  339. unitPriceFile._doc.root_project_id = rootProjectID
  340. }
  341. await unitPriceFileModel.create(unitPriceFile._doc);
  342. }
  343. async function copySubList(srcFID,newFID,model) {
  344. let mList = await model.find({unit_price_file_id: srcFID}, '-_id');
  345. let rList = [];
  346. for(let m of mList){
  347. m._doc.unit_price_file_id = newFID;
  348. m._doc.id = await getCounterID(model.modelName);
  349. rList.push(m._doc);
  350. }
  351. await insertMany(rList,model)
  352. }
  353. }
  354. async function copyInstallFee(originalPID,newProjectID) {
  355. let result = null;
  356. let installationFee = await installationFeeModel.find({projectID:originalPID}, '-_id');
  357. let newList = [];
  358. for(let i of installationFee ){
  359. i._doc.ID = uuidV1();
  360. i._doc.projectID = newProjectID;
  361. newList.push(i._doc);
  362. }
  363. if(newList.length >0){
  364. result = await installationFeeModel.insertMany(newList);
  365. }
  366. return result;
  367. }
  368. async function copyRationSubList(originalPID,newProjectID,billIDMap,rationIDMap,projectGLJIDMap,model) {// 定额工料机,附注条件,工程量明细,定额安装增加费
  369. let subList = await model.find({projectID:originalPID}, '-_id');
  370. let newList =[];
  371. for(let s of subList){
  372. s._doc.ID = uuidV1();
  373. s._doc.projectID = newProjectID;
  374. s._doc.rationID&&rationIDMap[s._doc.rationID]?s._doc.rationID = rationIDMap[s._doc.rationID]:'';
  375. s._doc.billID&&billIDMap[s._doc.billID]?s._doc.billID = billIDMap[s._doc.billID]:'';
  376. s._doc.billsItemID&&billIDMap[s._doc.billsItemID]?s._doc.billsItemID = billIDMap[s._doc.billsItemID]:'';
  377. s._doc.projectGLJID&&projectGLJIDMap[s._doc.projectGLJID]?s._doc.projectGLJID = projectGLJIDMap[s._doc.projectGLJID]:'';
  378. newList.push(s._doc);
  379. }
  380. await insertMany(newList,model);
  381. }
  382. async function moveProject(data) {
  383. data = JSON.parse(data);
  384. let projectMap = data.projectMap,feeRateMap = data.feeRateMap,unitPriceMap = data.unitPriceMap;
  385. let projectTasks = [],feeRateTask=[],feeRateFileTask=[],unitPriceTask=[],unitPriceFileTask=[],mixRatioTask=[];
  386. let feeUniqMap=[],priceUniqMap={};//费率、单价文件唯一映射表当移动多个项目时,任务有可能出现重复的情况
  387. if(!_.isEmpty(feeRateMap)&&data.rootProjectID){//如果费率有修改
  388. let feeRates =await feeRate_facade.getFeeRatesByProject(data.rootProjectID);//取目标建设项目的所有费率文件,重名检查
  389. for(let projectID in feeRateMap){
  390. let rename = feeRateMap[projectID].name;
  391. let feeRateID = feeRateMap[projectID].query.ID;
  392. let checkFee = _.find(feeRates,{'name':rename});
  393. let newID = feeRateID;
  394. if(checkFee){//说明费率名字已存在,需要重命名
  395. rename = feeUniqMap[feeRateID]?feeUniqMap[feeRateID].name:rename + '(' + new Date().Format('MM-dd hh:mm:ss') + '移动)';
  396. projectMap[projectID]['update']['property.feeFile.name'] = rename;
  397. if(feeRateMap[projectID].action == 'move'){
  398. feeRateMap[projectID].update.name = rename;
  399. }
  400. }
  401. if(feeRateMap[projectID].action == 'copy'){
  402. newID = feeUniqMap[feeRateID]?feeUniqMap[feeRateID].ID:uuidV1();
  403. feeRateMap[projectID].name = rename;
  404. feeRateMap[projectID].ID = newID;
  405. projectMap[projectID]['update']['property.feeFile.id'] = newID;
  406. }
  407. if(!feeUniqMap[feeRateID]){
  408. await generateFeeRateTask(feeRateMap[projectID],feeRateTask,feeRateFileTask);
  409. feeUniqMap[feeRateID] = {name:rename,ID:newID};
  410. }
  411. }
  412. }
  413. if(!_.isEmpty(unitPriceMap)&&data.rootProjectID) {//如果单价文件有修改
  414. let unitPriceFiles = await unitPriceFileModel.find({root_project_id: data.rootProjectID, deleteInfo: null});
  415. for(let projectID in unitPriceMap){
  416. let checkUn = _.find(unitPriceFiles,{'name':unitPriceMap[projectID].name});
  417. let rename = unitPriceMap[projectID].name;
  418. let unitPriceID = unitPriceMap[projectID].query.id;
  419. let newID = unitPriceID;
  420. if(checkUn){//重名检查
  421. rename = priceUniqMap[unitPriceID]?priceUniqMap[unitPriceID].name:rename + '(' + new Date().Format('MM-dd hh:mm:ss') + '移动)';
  422. projectMap[projectID]['update']['property.unitPriceFile.name'] = rename;
  423. if(unitPriceMap[projectID].action =='move'){
  424. unitPriceMap[projectID].update.name = rename;
  425. }
  426. }
  427. if(unitPriceMap[projectID].action =='copy'){
  428. newID = priceUniqMap[unitPriceID]?priceUniqMap[unitPriceID].id: await getCounterID("unit_price_file");
  429. unitPriceMap[projectID].name = rename;
  430. unitPriceMap[projectID].id = newID;
  431. projectMap[projectID]['update']['property.unitPriceFile.id'] = newID;
  432. }
  433. if(!priceUniqMap[unitPriceID]){
  434. await generateUnitPriceTask(unitPriceMap[projectID],projectID,data.user_id,unitPriceTask,unitPriceFileTask,mixRatioTask);
  435. priceUniqMap[unitPriceID] = {name:rename,id:newID};
  436. }
  437. }
  438. }
  439. if(!_.isEmpty(projectMap)){
  440. for(let projectID in projectMap){
  441. projectTasks.push({updateOne:{filter : projectMap[projectID].query, update : projectMap[projectID].update}});
  442. }
  443. }
  444. projectTasks.length>0?await projectModel.bulkWrite(projectTasks):'';
  445. feeRateTask.length>0?await feeRateModel.bulkWrite(feeRateTask):'';
  446. feeRateFileTask.length>0?await feeRateFileModel.bulkWrite(feeRateFileTask):'';
  447. unitPriceFileTask.length>0?await unitPriceFileModel.bulkWrite(unitPriceFileTask):'';
  448. unitPriceTask.length>0?await insertMany(unitPriceTask,unitPriceModel):'';
  449. mixRatioTask.length>0?await insertMany(mixRatioTask,mixRatioModel):'';
  450. return projectMap;
  451. }
  452. async function generateFeeRateTask(data,feeRateTask,feeRateFileTask) {
  453. if(data.action == 'move'){
  454. let task = {
  455. updateOne:{
  456. filter : data.query,
  457. update : data.update
  458. }
  459. };
  460. feeRateFileTask.push(task);
  461. }
  462. if(data.action == 'copy'){//copy 费率的时候用insertOne方法
  463. let [feeRateFile,feeRate] =await feeRate_facade.getFeeRateByID(data.query.ID);
  464. let newFeeRateID = uuidV1();
  465. let newFeeRate = {
  466. ID:newFeeRateID,
  467. rates:feeRate.rates
  468. };
  469. let newFeeRateFile = {
  470. ID:data.ID,
  471. rootProjectID:data.rootProjectID,
  472. userID:feeRateFile.userID,
  473. name:data.name,
  474. libID:feeRateFile.libID,
  475. libName:feeRateFile.libName,
  476. feeRateID:newFeeRateID
  477. };
  478. feeRateTask.push({insertOne :{document:newFeeRate}});
  479. feeRateFileTask.push({insertOne :{document:newFeeRateFile}});
  480. }
  481. }
  482. async function generateUnitPriceTask(data,projectID,user_id,unitPriceTask,unitPriceFileTask,mixRatioTask){
  483. if(data.action == 'move'){
  484. let task = {
  485. updateOne:{
  486. filter : data.query,
  487. update : data.update
  488. }
  489. };
  490. unitPriceFileTask.push(task);
  491. }
  492. if(data.action == 'copy'){
  493. let newUnitFile = {
  494. id:data.id,
  495. name: data.name,
  496. project_id:projectID,
  497. user_id:user_id,
  498. root_project_id: data.rootProjectID
  499. };
  500. unitPriceFileTask.push({insertOne :{document:newUnitFile}});
  501. let mixRatios = await mixRatioModel.find({unit_price_file_id: data.query.id});
  502. mixRatios = JSON.stringify(mixRatios);
  503. mixRatios = JSON.parse(mixRatios);
  504. for(let m of mixRatios){
  505. delete m._id; // 删除原有id信息
  506. delete m.id;
  507. m.unit_price_file_id = data.id;
  508. m.id = await getCounterID('mix_ratio');
  509. mixRatioTask.push(m);
  510. }
  511. let unitPrices = await unitPriceModel.find({unit_price_file_id: data.query.id});//unit_price_file_id
  512. unitPrices = JSON.stringify(unitPrices);
  513. unitPrices = JSON.parse(unitPrices);
  514. for(let u of unitPrices){
  515. delete u._id; // 删除原有id信息
  516. delete u.id;
  517. u.unit_price_file_id = data.id;
  518. u.id = await getCounterID('unit_price');
  519. unitPriceTask.push(u);
  520. }
  521. }
  522. }
  523. async function getCounterID(collectionName){
  524. let counterModel = new CounterModel();
  525. return await counterModel.getId(collectionName);
  526. }
  527. async function insertMany(datas,model) {
  528. while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入
  529. let newList = datas.splice(0,1000);//一次插入1000条
  530. await model.insertMany(newList);
  531. }
  532. await model.insertMany(datas);
  533. }
  534. function setProperty(Obj,updateData) {
  535. for(let ukey in updateData){
  536. if(_.isObject(updateData[ukey]) && _.isObject(Obj[ukey])){
  537. setProperty(Obj[ukey],updateData[ukey]);
  538. }else {
  539. Obj[ukey] = updateData[ukey];
  540. }
  541. }
  542. }
  543. function isDef(v){
  544. return typeof v !== 'undefined' && v !== null;
  545. }
  546. function getCommonTotalFee(bills) {
  547. if(!isDef(bills)){
  548. return 0;
  549. }
  550. if(!isDef(bills.fees) || bills.fees.length <= 0){
  551. return 0;
  552. }
  553. for(let fee of bills.fees){
  554. if(isDef(fee.fieldName) && fee.fieldName === 'common'){
  555. return isDef(fee.totalFee) ? fee.totalFee : 0;
  556. }
  557. }
  558. return 0;
  559. }
  560. function summarizeToParent(parent, child) {
  561. const decimal = -2;
  562. parent.engineeringCost = scMathUtil.roundTo(parseFloat(parent.engineeringCost) + parseFloat(child.engineeringCost), decimal);
  563. parent.subEngineering = scMathUtil.roundTo(parseFloat(parent.subEngineering) + parseFloat(child.subEngineering), decimal);
  564. parent.measure = scMathUtil.roundTo(parseFloat(parent.measure) + parseFloat(child.measure), decimal);
  565. parent.safetyConstruction = scMathUtil.roundTo(parseFloat(parent.safetyConstruction) + parseFloat(child.safetyConstruction), decimal);
  566. parent.other = scMathUtil.roundTo(parseFloat(parent.other) + parseFloat(child.other), decimal);
  567. parent.charge = scMathUtil.roundTo(parseFloat(parent.charge) + parseFloat(child.charge), decimal);
  568. parent.tax = scMathUtil.roundTo(parseFloat(parent.tax) + parseFloat(child.tax), decimal);
  569. }
  570. function getBuildingArea(projFeature){
  571. if(!projFeature || projFeature.length === 0){
  572. return null;
  573. }
  574. for(let f of projFeature){
  575. if(f.key === 'buildingArea'){
  576. return f.value;
  577. }
  578. }
  579. return null;
  580. }
  581. //根据单位工程ID获取汇总信息
  582. //@param {Number}tenderID {String}summaryType @return {Object}
  583. async function getSummaryInfoByTender(tenderID, summaryType) {
  584. const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
  585. let tender = await projectModel.findOne({ID: tenderID, $or: notDeleted});
  586. let parentName;
  587. let summaryList = [];
  588. if(!tender){
  589. return null;
  590. }
  591. let engineering = await projectModel.findOne({ID: tender.ParentID, $or: notDeleted});
  592. if(!engineering){
  593. return null;
  594. }
  595. let project = await projectModel.findOne({ID: engineering.ParentID, $or: notDeleted});
  596. if(!project){
  597. return null;
  598. }
  599. let summaryInfo = await getSummaryInfo([project.ID]);
  600. if(summaryType === projectType.engineering){
  601. parentName = engineering.name ? engineering.name : '';
  602. let tenders = await projectModel.find({ParentID: engineering.ID, $or: notDeleted});
  603. for(let t of tenders){
  604. if(summaryInfo[t.ID]){
  605. summaryInfo[t.ID]['name'] = t.name ? t.name : '';
  606. summaryList.push(summaryInfo[t.ID]);
  607. }
  608. }
  609. }
  610. else {
  611. parentName = project.name ? project.name : '';
  612. let engs = await projectModel.find({ParentID: project.ID, $or: notDeleted});
  613. for(let e of engs){
  614. if(summaryInfo[e.ID]){
  615. summaryInfo[e.ID]['name'] = e.name ? e.name : '';
  616. summaryList.push(summaryInfo[e.ID]);
  617. }
  618. }
  619. }
  620. return {parent: {name: parentName}, subList: summaryList};
  621. }
  622. //获取单位工程的各标段费用信息(不进行汇总)
  623. async function getTendersFeeInfo(tenders) {
  624. let IDMapping = {};
  625. //固定清单类别与汇总金额字段映射
  626. let flagFieldMapping = {};
  627. flagFieldMapping[billsFlags.ENGINEERINGCOST] = 'engineeringCost';
  628. flagFieldMapping[billsFlags.SUB_ENGINERRING] = 'subEngineering';
  629. flagFieldMapping[billsFlags.MEASURE] = 'measure';
  630. flagFieldMapping[billsFlags.SAFETY_CONSTRUCTION] = 'safetyConstruction';
  631. flagFieldMapping[billsFlags.OTHER] = 'other';
  632. flagFieldMapping[billsFlags.CHARGE] = 'charge';
  633. flagFieldMapping[billsFlags.TAX] = 'tax';
  634. let tenderIDs = [];
  635. if(tenders.length > 0){
  636. for(let tender of tenders){
  637. tenderIDs.push(tender.ID);
  638. IDMapping[tender.ID] = {engineeringCost: 0, subEngineering: 0, measure: 0, safetyConstruction: 0, other: 0, charge: 0, tax: 0, rate: 0, buildingArea: '', perCost: ''};
  639. IDMapping[tender.ID]['buildingArea'] = '';
  640. }
  641. //需要获取的清单固定类别综合合价:工程造价、分部分项、措施项目、安全文明施工专项、规费、其他项目、税金
  642. let needFlags = [billsFlags.ENGINEERINGCOST, billsFlags.SUB_ENGINERRING, billsFlags.MEASURE,
  643. billsFlags.SAFETY_CONSTRUCTION, billsFlags.CHARGE, billsFlags.OTHER, billsFlags.TAX];
  644. //获取单位工程汇总金额需要用到的所有清单
  645. let allBills = await billsModel.find({projectID: {$in: tenderIDs}, 'flags.flag': {$in: needFlags}, $or: notDeleted},
  646. '-_id projectID fees flags');
  647. //进行单位工程级别的汇总
  648. for(let bills of allBills){
  649. let billsFlag = bills.flags[0]['flag'];
  650. let costField = flagFieldMapping[billsFlag];
  651. IDMapping[bills.projectID][costField] = getCommonTotalFee(bills);
  652. }
  653. //占造价比例、单方造价
  654. for(let tender of tenders){
  655. let tenderInfo = IDMapping[tender.ID];
  656. tenderInfo.rate = '';
  657. //单方造价
  658. tenderInfo.perCost = '';
  659. }
  660. }
  661. return IDMapping;
  662. }
  663. async function getSummaryInfo(projectIDs){
  664. //ID与汇总信息映射
  665. let IDMapping = {};
  666. //固定清单类别与汇总金额字段映射
  667. let flagFieldMapping = {};
  668. flagFieldMapping[billsFlags.ENGINEERINGCOST] = 'engineeringCost';
  669. flagFieldMapping[billsFlags.SUB_ENGINERRING] = 'subEngineering';
  670. flagFieldMapping[billsFlags.MEASURE] = 'measure';
  671. flagFieldMapping[billsFlags.SAFETY_CONSTRUCTION] = 'safetyConstruction';
  672. flagFieldMapping[billsFlags.OTHER] = 'other';
  673. flagFieldMapping[billsFlags.CHARGE] = 'charge';
  674. flagFieldMapping[billsFlags.TAX] = 'tax';
  675. let projects = await projectModel.find({ID: {$in : projectIDs}, projType: projectType.project, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]});
  676. //设置建设项目的总建筑面积
  677. for(let project of projects){
  678. let grossArea = '';
  679. if(project.property && project.property.basicInformation){
  680. for(let basicInfo of project.property.basicInformation){
  681. if(basicInfo.key === 'basicInfo'){
  682. for(let k of basicInfo.items){
  683. if(k.key === 'grossArea'){
  684. grossArea = k.value;
  685. }
  686. }
  687. }
  688. }
  689. }
  690. IDMapping[project.ID] = {engineeringCost: 0, subEngineering: 0, measure: 0, safetyConstruction: 0, other: 0, charge: 0, tax: 0, rate: 0, buildingArea: grossArea, perCost: ''};
  691. }
  692. //单项工程
  693. let engineerings = await projectModel.find({ParentID: {$in : projectIDs}, projType: projectType.engineering, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]});
  694. //单位工程
  695. let tenders = [];
  696. let engIDs = [];
  697. for(let eng of engineerings){
  698. engIDs.push(eng.ID);
  699. IDMapping[eng.ID] = {engineeringCost: 0, subEngineering: 0, measure: 0, safetyConstruction: 0, other: 0, charge: 0, tax: 0, rate: 0, buildingArea: '', perCost: ''};
  700. }
  701. if(engIDs.length > 0){
  702. tenders = await projectModel.find({ParentID: {$in : engIDs}, projType: projectType.tender, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]});
  703. }
  704. let tenderIDs = [];
  705. if(tenders.length > 0){
  706. for(let tender of tenders){
  707. tenderIDs.push(tender.ID);
  708. IDMapping[tender.ID] = {engineeringCost: 0, subEngineering: 0, measure: 0, safetyConstruction: 0, other: 0, charge: 0, tax: 0, rate: 0, buildingArea: '', perCost: '',changeMark:tender.changeMark,property:tender.property};
  709. let buildingArea = getBuildingArea(tender.property.projectFeature);
  710. if(buildingArea){
  711. IDMapping[tender.ID]['buildingArea'] = buildingArea;
  712. }
  713. }
  714. //需要获取的清单固定类别综合合价:工程造价、分部分项、措施项目、安全文明施工专项、规费、其他项目、税金
  715. let needFlags = [billsFlags.ENGINEERINGCOST, billsFlags.SUB_ENGINERRING, billsFlags.MEASURE,
  716. billsFlags.SAFETY_CONSTRUCTION, billsFlags.CHARGE, billsFlags.OTHER, billsFlags.TAX];
  717. //获取单位工程汇总金额需要用到的所有清单
  718. let allBills = await billsModel.find({projectID: {$in: tenderIDs}, 'flags.flag': {$in: needFlags}, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]},
  719. '-_id projectID fees flags');
  720. //进行单位工程级别的汇总
  721. for(let bills of allBills){
  722. let billsFlag = bills.flags[0]['flag'];
  723. let costField = flagFieldMapping[billsFlag];
  724. IDMapping[bills.projectID][costField] = getCommonTotalFee(bills);
  725. }
  726. //进行单项工程级别的汇总
  727. for(let tender of tenders){
  728. summarizeToParent(IDMapping[tender.ParentID], IDMapping[tender.ID]);
  729. }
  730. //进行建设项目级别的汇总
  731. for(let eng of engineerings){
  732. summarizeToParent(IDMapping[eng.ParentID], IDMapping[eng.ID]);
  733. }
  734. //占造价比例、单方造价
  735. const rateDecimal = -2;
  736. const perCostDecimal = -2;
  737. for(let tender of tenders){
  738. let tenderInfo = IDMapping[tender.ID];
  739. let engInfo = IDMapping[tender.ParentID];
  740. tenderInfo.rate = engInfo.engineeringCost == 0 ? 0 : scMathUtil.roundTo(tenderInfo.engineeringCost * 100 / engInfo.engineeringCost, rateDecimal);
  741. //单方造价
  742. tenderInfo.perCost = tenderInfo.buildingArea.toString().trim() === '' || tenderInfo.buildingArea == 0 ?
  743. tenderInfo.buildingArea.toString().trim() : scMathUtil.roundTo(tenderInfo.engineeringCost / tenderInfo.buildingArea, perCostDecimal);
  744. }
  745. for(let eng of engineerings){
  746. let engInfo = IDMapping[eng.ID];
  747. let projInfo = IDMapping[eng.ParentID];
  748. engInfo.rate = !isDef(projInfo) || projInfo.engineeringCost == 0 ? 0 : scMathUtil.roundTo(engInfo.engineeringCost * 100 / projInfo.engineeringCost, rateDecimal);
  749. }
  750. //建设项目占造价比例及单方造价
  751. for(let project of projects){
  752. let projectInfo = IDMapping[project.ID];
  753. projectInfo.rate = 100;
  754. projectInfo.perCost = projectInfo.buildingArea.toString().trim() === '' || projectInfo.buildingArea == 0 ?
  755. projectInfo.buildingArea.toString().trim() : scMathUtil.roundTo(projectInfo.engineeringCost / projectInfo.buildingArea, perCostDecimal);
  756. }
  757. }
  758. return IDMapping;
  759. }
  760. //根据项目ID获取所属建设项目
  761. //@param {Number}projectID @return {Object}
  762. async function getConstructionProject(projectID){
  763. function returnProject(project){
  764. if(!project || project.projType === projectType.folder){
  765. return null;
  766. }
  767. if(project.projType === projectType.project){
  768. return project;
  769. }
  770. }
  771. let project = await projectModel.findOne({ID: projectID, $or: notDeleted});
  772. let returnV = returnProject(project);
  773. if(returnV !== undefined){
  774. return returnV;
  775. }
  776. let parent = await projectModel.findOne({ID: project.ParentID, $or: notDeleted});
  777. returnV = returnProject(parent);
  778. if(returnV !== undefined){
  779. return returnV;
  780. }
  781. let grandParent = await projectModel.findOne({ID: parent.ParentID, $or: notDeleted});
  782. returnV = returnProject(grandParent);
  783. return returnV !== undefined ? returnV : null;
  784. }
  785. //获取单位工程完整目录结构
  786. //@param {Number}projectID @return {Arry}
  787. async function getFullPath(projectID) {
  788. let fullPath = [];
  789. let project = await projectModel.findOne({ID: projectID, $or: notDeleted}, '-_id ParentID name');
  790. if(project){
  791. fullPath.push(project.name);
  792. await getParent(project.ParentID);
  793. }
  794. fullPath = fullPath.reverse();
  795. return fullPath;
  796. async function getParent(ParentID) {
  797. if(ParentID != -1){
  798. let parent = await projectModel.findOne({ID: ParentID, $or: notDeleted}, '-_id ParentID name');
  799. if(parent){
  800. fullPath.push(parent.name);
  801. await getParent(parent.ParentID);
  802. }
  803. }
  804. }
  805. }
  806. async function getProjectFeature(libID,feeStandardName){
  807. let lib = await featureLibModel.findOne({'ID':libID})
  808. if(lib){
  809. let eng = _.find(lib.feature,{'key':'engineering'})
  810. if(eng) eng.value = feeStandardName;
  811. return lib.feature;
  812. }else {
  813. return [];
  814. }
  815. }
  816. //获取projectIDs文件下所有子项目(不包括projectIDs本身)
  817. async function getPosterityProjects(projectIDs) {
  818. let rst = [];
  819. async function getProjects(IDs) {
  820. if (IDs.length > 0) {
  821. let newIDs = [];
  822. let projs = await projectModel.find({ParentID: {$in: IDs}, $or: notDeleted}, '-_id');
  823. for (let proj of projs) {
  824. rst.push(proj);
  825. newIDs.push(proj.ID);
  826. }
  827. await getProjects(newIDs);
  828. }
  829. }
  830. await getProjects(projectIDs);
  831. return rst;
  832. }
  833. //根据项目获得分享信息(分享层级不一定在项目级)(以最新为准)
  834. //@param {String}userId {Object}tender @return {Object} || {null}
  835. async function getShareInfo(userId, project) {
  836. //与该用户相关的分享
  837. let shareList = [];
  838. while (project) {
  839. for(let shareData of project.shareInfo){
  840. if(shareData.userID === userId){
  841. shareList.push(shareData);
  842. break;
  843. }
  844. }
  845. project = await projectModel.findOne({ID: project.ParentID}, '-_id shareInfo ID ParentID');
  846. }
  847. //获取最新分享
  848. shareList.sort(function (a, b) {
  849. let aV = Date.parse(a.shareDate),
  850. bV = Date.parse(b.shareDate);
  851. if (aV > bV) {
  852. return -1;
  853. } else if (aV < bV) {
  854. return 1;
  855. }
  856. return 0;
  857. });
  858. return shareList[0] || null;
  859. }
  860. //打开的单位工程是否是被分享的.
  861. async function isShare(userId, project){
  862. //判断是否是打开分享的项目,属于分享文件的子项也算
  863. while (project) {
  864. for(let shareData of project.shareInfo){
  865. if(shareData.userID === userId){
  866. return true;
  867. }
  868. }
  869. project = await projectModel.findOne({ID: project.ParentID}, '-_id shareInfo ID ParentID');
  870. }
  871. return false;
  872. }
  873. //用户第一次进入费用定额的数据准备
  874. async function prepareInitialData(userId, compilation, example) {
  875. let prepareTask = [
  876. updateUsedList(userId, compilation),
  877. copyCompleRationSection(userId, compilation),
  878. copyCompleGljSection(userId, compilation)
  879. ];
  880. if (example && example.length > 0) {
  881. prepareTask.push(copyExample(userId, compilation, example));
  882. }
  883. await Promise.all(prepareTask);
  884. }
  885. async function updateUsedList(userId, compilation) {
  886. await userModel.update({_id: mongoose.Types.ObjectId(userId)}, {$push: {used_list: {compilationId: compilation}}});
  887. }
  888. //拷贝补充定额章节树
  889. async function copyCompleRationSection(userId, compilationId) {
  890. await sectionTreeDao.copyDataFromTemplate(userId, compilationId);
  891. }
  892. //拷贝补充人材机分类树
  893. async function copyCompleGljSection(userId, compilationId) {
  894. let templateData = await compleGljSectionTModel.find({compilationId: compilationId});
  895. if (templateData.length > 0) {
  896. let insertDatas = [],
  897. uuidMapping = {};
  898. //将ID替换成UUID
  899. for (let temData of templateData) {
  900. uuidMapping[temData.ID] = uuidV1();
  901. }
  902. for(let temData of templateData) {
  903. let insertD = {
  904. userId: userId,
  905. compilationId: compilationId,
  906. Name: temData.Name,
  907. ID: uuidMapping[temData.ID],
  908. ParentID: uuidMapping[temData.ParentID] || -1,
  909. NextSiblingID: uuidMapping[temData.NextSiblingID] || -1,
  910. };
  911. insertDatas.push(insertD);
  912. }
  913. //插入数据
  914. await compleGljSectionModel.insertMany(insertDatas);
  915. }
  916. }
  917. async function changeFile(datas,userID,fileID,name,from,type){//from 费率或单价文件,type从单前建设项目还是从其它建设项目中复制
  918. let projectIDs = [],newFile = {id:fileID,name:name};//计录从其它项目中复制的文件,选中多个的时候只需复制一次
  919. let projectUpdateType = from == "feeRateFile"?"feeRate":"unitFile";
  920. if(from == "feeRateFile"){
  921. for(let d of datas){
  922. let tem_file = await feeRate_facade.changeFeeRateFile(d, newFile,type,userID);
  923. if(type == 1 && tem_file){//从建设项目复制时,只有第一次需要复制,剩下的就相当于使用同个建设项目的情况了
  924. newFile = {id:tem_file.ID,name:tem_file.name};
  925. type = 0;
  926. }
  927. projectIDs.push({ID:d.projectID})
  928. }
  929. }
  930. await project_facade.markProjectsToChange(projectIDs,projectUpdateType)//项目标记为待刷新状态
  931. }