Browse Source

例题项目管理相关文件没有显示文件

vian 6 years ago
parent
commit
7a844fa21b

+ 33 - 0
modules/pm/controllers/pm_controller.js

@@ -384,6 +384,39 @@ module.exports = {
         }
     },
 
+    getGC: async function(req, res) {
+        const userID = req.session.sessionUser.id;
+        const compilationId = req.session.sessionCompilation._id;
+        try {
+            const rst = [];
+            const priceFilesTask = ProjectsData.getGCFiles(fileType.unitPriceFile, userID);
+            const feeRateFilesTask = ProjectsData.getGCFiles(fileType.feeRateFile, userID);
+            const tendersTask = ProjectsData.getGCFiles(projType.tender, userID);
+            const [priceFiles, rateFiles, tenders] = await Promise.all([priceFilesTask, feeRateFilesTask, tendersTask]);
+            // 建设项目
+            let projectIDs = tenders.reduce((acc, cur) => {
+                acc.push(cur.ParentID);
+                return acc;
+            }, []);
+            projectIDs = [...new Set(projectIDs)];
+            const projects = await ProjectsData.getProjectsByIds(userID, compilationId, projectIDs);
+            projects.forEach(project => {
+                const projectDoc = project._doc;
+                const relTenders = tenders.filter(tender => tender.ParentID === projectDoc.ID);
+                const unitPriceFiles = priceFiles.filter(file => relTenders.find(tender => tender.property.unitPriceFile.id === file.id));
+                const feeRateFiles = rateFiles.filter(file => relTenders.find(tender => tender.property.feeFile.id === file.ID));
+                projectDoc.children = relTenders;
+                projectDoc.unitPriceFiles = unitPriceFiles;
+                projectDoc.feeRateFiles = feeRateFiles;
+                rst.push(projectDoc);
+            });
+            callback(req, res, 0, 'success', rst);
+        } catch (err) {
+            console.log(err);
+            callback(req, res, true, err.message, null);
+        }
+    },
+
     getGCDatas: async function(request, response) {
         let userID = request.session.sessionUser.id;
         let compilatoinId = request.session.sessionCompilation._id;

+ 55 - 1
modules/pm/facade/pm_facade.js

@@ -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);
+    }
 }

+ 1 - 0
modules/pm/models/project_model.js

@@ -67,6 +67,7 @@ ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, cal
                 'deleteInfo': null
             }, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]
         }, '-_id', {lean: true});
+        await pmFacade.checkFiles(projects);
         let projIDs= [];
         for(let project of projects){
             if(project.projType === projectType.project){

+ 1 - 1
modules/pm/routes/pm_route.js

@@ -53,7 +53,7 @@ module.exports = function (app) {
     pmRouter.post('/updateFiles', pmController.updateFiles);
     pmRouter.post('/defaultSettings', pmController.defaultSettings);
     //GC
-    pmRouter.post('/getGCDatas', pmController.getGCDatas);
+    pmRouter.post('/getGCDatas', pmController.getGC);
     pmRouter.post('/recGC', pmController.recGC);
     pmRouter.post('/delGC', pmController.delGC);
     //share