Przeglądaj źródła

导入ybp,局部刷新,展开至标段

vian 5 lat temu
rodzic
commit
81cc52c88f

+ 2 - 0
modules/all_models/import_logs.js

@@ -13,6 +13,8 @@ let modelSchema = {
     userID: String,
     userID: String,
     // 关联用户id
     // 关联用户id
     status:String,
     status:String,
+    // 建设项目ID
+    projectID: Number,
     // 创建时间
     // 创建时间
     create_time: Number,
     create_time: Number,
     errorMsg:""
     errorMsg:""

+ 44 - 5
modules/pm/facade/pm_facade.js

@@ -19,6 +19,7 @@ module.exports={
     moveProject:moveProject,
     moveProject:moveProject,
     copyProject:copyProject,
     copyProject:copyProject,
     copyExample: copyExample,
     copyExample: copyExample,
+    setupSummaryFields: setupSummaryFields,
     getSummaryInfo: getSummaryInfo,
     getSummaryInfo: getSummaryInfo,
     getSummaryInfoByTender: getSummaryInfoByTender,
     getSummaryInfoByTender: getSummaryInfoByTender,
     getTendersFeeInfo: getTendersFeeInfo,
     getTendersFeeInfo: getTendersFeeInfo,
@@ -952,6 +953,24 @@ async function getTendersFeeInfo(tenders) {
     }
     }
     return IDMapping;
     return IDMapping;
 }
 }
+
+// 项目管理界面需要显示的汇总字段
+function setupSummaryFields(summaryInfo, projects, fields = null) {
+    if (!fields) {
+        fields = [
+            'totalCost'
+        ];
+    }
+    for(const proj of projects){
+        const summaryProj = summaryInfo[proj.ID];
+        if(summaryProj){
+            for (const field of fields) {
+                proj[field] = summaryProj[field];
+            }
+        }
+    }
+}
+
 //@param {Array}projectIDs(建设项目ID) @return {Object}
 //@param {Array}projectIDs(建设项目ID) @return {Object}
 async function getSummaryInfo(projectIDs, flagFieldMapping = null){
 async function getSummaryInfo(projectIDs, flagFieldMapping = null){
     //ID与汇总信息映射
     //ID与汇总信息映射
@@ -1080,9 +1099,15 @@ async function getUpChainIDs(projectID) {
     return rst;
     return rst;
 }
 }
 
 
-//获取projectIDs文件下所有子项目(不包括projectIDs本身)
-async function getPosterityProjects(projectIDs) {
+//获取projectIDs文件下所有子项目(默认不包括projectIDs本身)
+async function getPosterityProjects(projectIDs, includeSelf = false) {
     let rst = [];
     let rst = [];
+    if (includeSelf) {
+        const projects = await projectModel.find({ID: {$in: projectIDs}, $or: notDeleted}, '-_id').lean();
+        if (projects) {
+            rst.push(...projects);
+        }
+    }
     async function getProjects(parentIDs) {
     async function getProjects(parentIDs) {
         if (parentIDs.length > 0) {
         if (parentIDs.length > 0) {
             let newIDs = [];
             let newIDs = [];
@@ -1102,6 +1127,7 @@ async function getPosterityProjects(projectIDs) {
     return rst;
     return rst;
 }
 }
 
 
+
 //根据项目获得分享信息(分享层级不一定在项目级)(以最新为准)
 //根据项目获得分享信息(分享层级不一定在项目级)(以最新为准)
 async function getShareInfo(userID, projectID) {
 async function getShareInfo(userID, projectID) {
     // 接受到的分享项目
     // 接受到的分享项目
@@ -1331,6 +1357,7 @@ async function doDownLoadAndImport(privateDownloadUrl,info) {
         try {
         try {
             let data = fs.readFileSync(stream.path,'utf-8');
             let data = fs.readFileSync(stream.path,'utf-8');
             let result = await importProject(data,{session:info.session},info.updateData);
             let result = await importProject(data,{session:info.session},info.updateData);
+            doc.projectID = result.constructionProjectID;
             if(result.error == 1){
             if(result.error == 1){
                 doc.errorMsg = result.msg;
                 doc.errorMsg = result.msg;
                 doc.status = "error";
                 doc.status = "error";
@@ -1353,6 +1380,13 @@ async function importProcessChecking(data){
         if(log.status == "finish"){
         if(log.status == "finish"){
             result.status = "complete";
             result.status = "complete";
             await importLogsModel.remove({key:data.key});
             await importLogsModel.remove({key:data.key});
+            // 获取导入的项目数据
+            if (log.projectID) {
+                const projects = await getPosterityProjects([log.projectID], true);
+                const summaryInfo = await getSummaryInfo([log.projectID]);
+                setupSummaryFields(summaryInfo, projects);
+                result.data = projects;
+            }
         }else if(log.status == "start"){
         }else if(log.status == "start"){
             result.status = "processing";
             result.status = "processing";
         }else if(log.status == "error"){
         }else if(log.status == "error"){
@@ -1394,7 +1428,8 @@ async function importProject(data,req,updateData) {
                 result.error = 1;
                 result.error = 1;
                 result.msg = `您创建的项目个数超限,请联系我们的客服人员,或者导出建设项目保存到本地备份,删除云上数据。`;
                 result.msg = `您创建的项目个数超限,请联系我们的客服人员,或者导出建设项目保存到本地备份,删除云上数据。`;
             }
             }
-            let [projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
+            let [constructionProjectID,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
+            result.constructionProjectID = constructionProjectID;
             if(datas.length > 1 ){
             if(datas.length > 1 ){
                 for(let i = 1;i<datas.length;i++){
                 for(let i = 1;i<datas.length;i++){
                     await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
                     await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
@@ -1509,11 +1544,15 @@ async function handleMainProjectDatas(mainData,updateData,userID) {
     let projectIDMap = {},feeRateFileIDMap={},unitPriceFileIDMap={},labourCoeFileIDMap={},calcProgramFileIDMap={};
     let projectIDMap = {},feeRateFileIDMap={},unitPriceFileIDMap={},labourCoeFileIDMap={},calcProgramFileIDMap={};
     let tasks = [];
     let tasks = [];
     projectIDMap[-1] = -1;//最后一个项目的nextID为-1的情况
     projectIDMap[-1] = -1;//最后一个项目的nextID为-1的情况
+    let constructionProjectID;
     //生成新的projectID
     //生成新的projectID
     for(let p of mainData.projects){
     for(let p of mainData.projects){
         let newProjectID = await getCounterID("projects");
         let newProjectID = await getCounterID("projects");
         projectIDMap[p.ID] = newProjectID;
         projectIDMap[p.ID] = newProjectID;
-        if(p.projType == "Project") mainProjectID =  newProjectID;
+        if(p.projType == "Project") {
+            mainProjectID =  newProjectID;
+            constructionProjectID = newProjectID;
+        }
         if(p.projType == "Tender"){
         if(p.projType == "Tender"){
             if(p.property.calcProgramFile) calcProgramFileIDMap[p.property.calcProgramFile.ID] = uuidV1();//新的计算程序文件ID
             if(p.property.calcProgramFile) calcProgramFileIDMap[p.property.calcProgramFile.ID] = uuidV1();//新的计算程序文件ID
             if(p.property.labourCoeFile) labourCoeFileIDMap[p.property.labourCoeFile.ID] = uuidV1();//新的人工调整系数文件ID
             if(p.property.labourCoeFile) labourCoeFileIDMap[p.property.labourCoeFile.ID] = uuidV1();//新的人工调整系数文件ID
@@ -1562,7 +1601,7 @@ async function handleMainProjectDatas(mainData,updateData,userID) {
     await importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,userID);
     await importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,userID);
 
 
 
 
-    return [projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap]
+    return [constructionProjectID,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap]
 }
 }
 
 
 
 

+ 3 - 2
modules/pm/models/project_model.js

@@ -83,12 +83,13 @@ ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, cal
         });
         });
         //设置汇总字段
         //设置汇总字段
         let summaryInfo = await pmFacade.getSummaryInfo(projIDs);
         let summaryInfo = await pmFacade.getSummaryInfo(projIDs);
-        for(let proj of projects){
+        pmFacade.setupSummaryFields(summaryInfo, projects);
+        /* for(let proj of projects){
             let summaryProj = summaryInfo[proj.ID];
             let summaryProj = summaryInfo[proj.ID];
             if(summaryProj){
             if(summaryProj){
                 proj.totalCost = summaryProj.totalCost;
                 proj.totalCost = summaryProj.totalCost;
             }
             }
-        }
+        } */
         callback(0, '', projects);
         callback(0, '', projects);
     }
     }
     catch (err) {
     catch (err) {

+ 23 - 2
public/common_util.js

@@ -18,13 +18,34 @@
     function isDef(val) {
     function isDef(val) {
         return typeof val !== 'undefined' && val !== null;
         return typeof val !== 'undefined' && val !== null;
     }
     }
-    
+
     function isEmptyVal(val) {
     function isEmptyVal(val) {
         return val === null || val === undefined || val === '';
         return val === null || val === undefined || val === '';
     }
     }
+    // 将树数据排序好
+    function getSortedTreeData(rootID, items) {
+        return sortSameDedth(rootID, items).reverse();
 
 
+        function sortSameDedth(parentID, items) {
+            const sameDepthItems = items.filter(item => item.ParentID === parentID);
+            if (!sameDepthItems.length) {
+                return [];
+            }
+            const NextIDMapping = {};
+            sameDepthItems.forEach(item => NextIDMapping[item.NextSiblingID] = item);
+            let curItem = sameDepthItems.length > 1 ? sameDepthItems.find(item => item.NextSiblingID === -1) : sameDepthItems[0];
+            const sorted = [];
+            while (curItem) {
+                sorted.push(...sortSameDedth(curItem.ID, items));
+                sorted.push(curItem);
+                curItem = NextIDMapping[curItem.ID] || null;
+            }
+            return sorted;
+        }
+    }
     return {
     return {
         isDef,
         isDef,
-        isEmptyVal
+        isEmptyVal,
+        getSortedTreeData
     };
     };
 });
 });

+ 20 - 1
web/building_saas/pm/js/pm_newMain.js

@@ -3954,8 +3954,13 @@ $("#confirm-import").click(function() {
             if(result.status == "processing"){
             if(result.status == "processing"){
                 setTimeout(importProcessChecking,2000);
                 setTimeout(importProcessChecking,2000);
             }else if(result.status == "complete"){
             }else if(result.status == "complete"){
+                if (Array.isArray(result.data)) {
+                    const rootData = result.data.find(item => item.projType === projectType.project);
+                    const sorted = commonUtil.getSortedTreeData(rootData.ParentID, result.data);
+                    doAfterImport(sorted);
+                }
                 $.bootstrapLoading.progressEnd();
                 $.bootstrapLoading.progressEnd();
-                refreshAllPage();
+                //refreshAllPage();
             }
             }
         }
         }
     }
     }
@@ -4135,6 +4140,20 @@ function refreshProjSummary(project, summaryInfo) {
     projTreeObj.refreshNodeData(refreshNodes);
     projTreeObj.refreshNodeData(refreshNodes);
 }
 }
 
 
+//projectDatas在后端已经按照顺序排过了: project eng1 tender1-1 tender1-2 eng2 tender2-1 tender2-2
+function doAfterImport(projectDatas) {
+    //插入节点
+    let lastNode;
+    for (let data of projectDatas) {
+        data.feeStandardName = data.property && data.property.feeStandardName || ''; //工程专业列显示用
+        let parent = projTreeObj.tree.items.find(node => node.data.ID === data.ParentID),
+            next = projTreeObj.tree.items.find(node => node.data.ID === data.NextSiblingID);
+        lastNode = projTreeObj.insert(data, parent, next);
+    }
+    if (lastNode) {
+        projTreeObj.workBook.getSheet(0).showRow(lastNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
+    }
+}
 
 
 $(function () {
 $(function () {
    if(isShow)  $('#welcomePage').modal('show');//是否显示欢迎页
    if(isShow)  $('#welcomePage').modal('show');//是否显示欢迎页