|
|
@@ -26,6 +26,7 @@ module.exports={
|
|
|
getShareInfo: getShareInfo,
|
|
|
prepareInitialData: prepareInitialData,
|
|
|
changeFile:changeFile,
|
|
|
+ checkFiles:checkFiles,
|
|
|
copyForSectionError: copyForSectionError,
|
|
|
exportProject:exportProject,
|
|
|
importProject:importProject
|
|
|
@@ -132,7 +133,7 @@ async function copyExample(userID, compilation, projIDs){
|
|
|
parentBulks.push({insertOne: {document: newData}});
|
|
|
} else {
|
|
|
//拷贝单位工程
|
|
|
- let rootProjectID = projMapping[data.ParentID].ParentID;
|
|
|
+ let rootProjectID = projMapping[data.ParentID];
|
|
|
let projectMap = {
|
|
|
copy: {
|
|
|
document: {userID: userID, ID: orgID, NextSiblingID: data.NextSiblingID, ParentID: data.ParentID, name: data.name, shareInfo: [],
|
|
|
@@ -1355,4 +1356,57 @@ async function importFeeRateFiles(mainData,projectIDMap,feeRateFileIDMap,userID)
|
|
|
}
|
|
|
if(feeRateFiles.length > 0) await insertMany(feeRateFiles,feeRateFileModel);
|
|
|
if(feeRates.length > 0) await insertMany(feeRates,feeRateModel);
|
|
|
+}
|
|
|
+
|
|
|
+// 检查单价、费率文件,处理rootProjectID为-1的旧数据(以前的初始化例题bug造成)
|
|
|
+async function checkFiles(projects) {
|
|
|
+ // fileID - tenderID 映射
|
|
|
+ const mapping = {};
|
|
|
+ const unitFileIDs = [];
|
|
|
+ const rateFileIDs = [];
|
|
|
+ projects.forEach(project => {
|
|
|
+ if (project.projType === projectType.tender) {
|
|
|
+ const priceFileID = project.property.unitPriceFile.id;
|
|
|
+ const feeFileID = project.property.feeFile.id;
|
|
|
+ if (!mapping[priceFileID]) {
|
|
|
+ mapping[priceFileID] = project;
|
|
|
+ unitFileIDs.push(priceFileID);
|
|
|
+ }
|
|
|
+ if (!mapping[feeFileID]) {
|
|
|
+ mapping[feeFileID] = project;
|
|
|
+ rateFileIDs.push(feeFileID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 检查是否存在rootProjectID为-1的
|
|
|
+ const errorUnitFiles = await unitPriceFileModel.find({id: {$in: unitFileIDs}, root_project_id: -1});
|
|
|
+ console.log(`errorUnitFiles`);
|
|
|
+ console.log(errorUnitFiles);
|
|
|
+ const unitFileTask = errorUnitFiles.map(file => {
|
|
|
+ const rootProjectID = mapping[file.id].ParentID;
|
|
|
+ return {
|
|
|
+ updateOne: {
|
|
|
+ filter: {id: file.id},
|
|
|
+ update: {$set: {root_project_id: rootProjectID}}
|
|
|
+ }
|
|
|
+ };
|
|
|
+ });
|
|
|
+ if (unitFileTask.length) {
|
|
|
+ await unitPriceFileModel.bulkWrite(unitFileTask);
|
|
|
+ }
|
|
|
+ const errorRateFiles = await feeRateFileModel.find({ID: {$in: rateFileIDs}, rootProjectID: -1});
|
|
|
+ console.log(`errorRateFiles`);
|
|
|
+ console.log(errorRateFiles);
|
|
|
+ const rateFileTask = errorRateFiles.map(file => {
|
|
|
+ const rootProjectID = mapping[file.ID].ParentID;
|
|
|
+ return {
|
|
|
+ updateOne: {
|
|
|
+ filter: {ID: file.ID},
|
|
|
+ update: {$set: {rootProjectID: rootProjectID}}
|
|
|
+ }
|
|
|
+ };
|
|
|
+ });
|
|
|
+ if (rateFileTask.length) {
|
|
|
+ await feeRateFileModel.bulkWrite(rateFileTask);
|
|
|
+ }
|
|
|
}
|