|
|
@@ -1365,10 +1365,14 @@ async function importFeeRateFiles(mainData,projectIDMap,feeRateFileIDMap,userID)
|
|
|
async function checkFiles(projects) {
|
|
|
// fileID - tenderID 映射
|
|
|
const mapping = {};
|
|
|
+ const tenderItems = [];
|
|
|
const unitFileIDs = [];
|
|
|
const rateFileIDs = [];
|
|
|
+ const task = [];
|
|
|
projects.forEach(project => {
|
|
|
- if (project.projType === projectType.tender) {
|
|
|
+ const isErrorRootProjectTender = project.projType === projectType.tender && project.property.rootProjectID === -1;
|
|
|
+ if (isErrorRootProjectTender) {
|
|
|
+ tenderItems.push({ ID: project.ID, ParentID: project.ParentID });
|
|
|
const priceFileID = project.property.unitPriceFile.id;
|
|
|
const feeFileID = project.property.feeFile.id;
|
|
|
if (!mapping[priceFileID]) {
|
|
|
@@ -1383,8 +1387,7 @@ async function checkFiles(projects) {
|
|
|
});
|
|
|
// 检查是否存在rootProjectID为-1的
|
|
|
const errorUnitFiles = await unitPriceFileModel.find({id: {$in: unitFileIDs}, root_project_id: -1});
|
|
|
- console.log(`errorUnitFiles`);
|
|
|
- console.log(errorUnitFiles);
|
|
|
+ const errorRateFiles = await feeRateFileModel.find({ID: {$in: rateFileIDs}, rootProjectID: -1});
|
|
|
const unitFileTask = errorUnitFiles.map(file => {
|
|
|
const rootProjectID = mapping[file.id].ParentID;
|
|
|
return {
|
|
|
@@ -1395,11 +1398,8 @@ async function checkFiles(projects) {
|
|
|
};
|
|
|
});
|
|
|
if (unitFileTask.length) {
|
|
|
- await unitPriceFileModel.bulkWrite(unitFileTask);
|
|
|
+ task.push(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 {
|
|
|
@@ -1410,6 +1410,18 @@ async function checkFiles(projects) {
|
|
|
};
|
|
|
});
|
|
|
if (rateFileTask.length) {
|
|
|
- await feeRateFileModel.bulkWrite(rateFileTask);
|
|
|
+ task.push(feeRateFileModel.bulkWrite(rateFileTask));
|
|
|
}
|
|
|
-}
|
|
|
+ const tenderTask = tenderItems.map(item => {
|
|
|
+ return {
|
|
|
+ updateOne: {
|
|
|
+ filter: {ID: item.ID},
|
|
|
+ update: {$set: {'property.rootProjectID': item.ParentID}}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (tenderTask.length) {
|
|
|
+ task.push(projectModel.bulkWrite(tenderTask));
|
|
|
+ }
|
|
|
+ await Promise.all(task);
|
|
|
+}
|