Browse Source

Merge branch 'master' of http://192.168.1.41:3000/SmartCost/ConstructionCost

chenshilong 5 years ago
parent
commit
46a01e034e

+ 2 - 0
modules/all_models/import_logs.js

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

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

@@ -19,6 +19,7 @@ module.exports={
     moveProject:moveProject,
     copyProject:copyProject,
     copyExample: copyExample,
+    setupSummaryFields: setupSummaryFields,
     getSummaryInfo: getSummaryInfo,
     getSummaryInfoByTender: getSummaryInfoByTender,
     getIndexReportData: getIndexReportData,
@@ -1052,6 +1053,32 @@ const defaultSummaryField = {
     }
 };
 
+// 项目管理界面需要显示的汇总字段
+function setupSummaryFields(summaryInfo, projects, fields = null) {
+    if (!fields) {
+        fields = [
+            'engineeringCost',
+            'subEngineering',
+            'measure',
+            'safetyConstruction',
+            'other',
+            'charge',
+            'tax',
+            'rate',
+            'buildingArea',
+            'perCost'
+        ];
+    }
+    for(const proj of projects){
+        const summaryProj = summaryInfo[proj.ID];
+        if(summaryProj){
+            for (const field of fields) {
+                proj[field] = summaryProj[field];
+            }
+        }
+    }
+}
+
 async function getSummaryInfo(projectIDs, summaryField = defaultSummaryField){
     function initFees(target, summaryField) {
         for (const flag in summaryField) {
@@ -1351,9 +1378,15 @@ async function getUpChainIDs(projectID) {
     return rst;
 }
 
-//获取projectIDs文件下所有子项目(不包括projectIDs本身)
-async function getPosterityProjects(projectIDs) {
+//获取projectIDs文件下所有子项目(默认不包括projectIDs本身)
+async function getPosterityProjects(projectIDs, includeSelf = false) {
     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) {
         if (parentIDs.length > 0) {
             let newIDs = [];
@@ -2084,6 +2117,7 @@ async function doDownLoadAndImport(privateDownloadUrl,info) {
         try {
             let data = fs.readFileSync(stream.path,'utf-8');
             let result = await importProjects(data,{session:info.session},info.updateData);
+            doc.projectID = result.constructionProjectID;
             if(result.error == 1){
                 doc.errorMsg = result.msg;
                 doc.status = "error";
@@ -2106,6 +2140,13 @@ async function importProcessChecking(data){
         if(log.status == "finish"){
             result.status = "complete";
             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"){
             result.status = "processing";
         }else if(log.status == "error"){
@@ -2200,7 +2241,8 @@ async function importProjects(data,req,updateData) {
                 result.error = 1;
                 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 ){
                 for(let i = 1;i<datas.length;i++){
                     await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
@@ -2328,11 +2370,15 @@ async function handleMainProjectDatas(mainData,updateData,userID) {
     let projectIDMap = {},feeRateFileIDMap={},unitPriceFileIDMap={},labourCoeFileIDMap={},calcProgramFileIDMap={};
     let tasks = [];
     projectIDMap[-1] = -1;//最后一个项目的nextID为-1的情况
+    let constructionProjectID;
     //生成新的projectID
     for(let p of mainData.projects){
         let newProjectID = await getCounterID("projects");
         projectIDMap[p.ID] = newProjectID;
-        if(p.projType == "Project") mainProjectID =  newProjectID;
+        if(p.projType == "Project") {
+            mainProjectID =  newProjectID;
+            constructionProjectID = newProjectID;
+        }
         if(p.projType == "Tender"){
             if(p.property.calcProgramFile) calcProgramFileIDMap[p.property.calcProgramFile.ID] = uuidV1();//新的计算程序文件ID
             if(p.property.labourCoeFile) labourCoeFileIDMap[p.property.labourCoeFile.ID] = uuidV1();//新的人工调整系数文件ID
@@ -2381,7 +2427,7 @@ async function handleMainProjectDatas(mainData,updateData,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,7 +83,8 @@ ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, cal
         });
         // 设置汇总字段
         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];
             if(summaryProj){
                 proj.engineeringCost = summaryProj.engineeringCost;
@@ -97,7 +98,7 @@ ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, cal
                 proj.buildingArea = summaryProj.buildingArea;
                 proj.perCost = summaryProj.perCost;
             }
-        }
+        } */
         callback(0, '', projects);
     }
     catch (err) {

+ 22 - 0
public/common_util.js

@@ -63,6 +63,27 @@ function deleteEmptyObject(arr) {
         }
         return rst;
     }
+    // 将树数据排序好
+    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 {
         isDef,
@@ -70,5 +91,6 @@ function deleteEmptyObject(arr) {
         isNumber,
         similarEqual,
         getRequired,
+        getSortedTreeData,
     };
 });

+ 1 - 1
web/building_saas/pm/js/pm_import.js

@@ -512,5 +512,5 @@ const importView = (() => {
             projTreeObj.workBook.getSheet(0).showRow(lastNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
         }
     }
-    return { eventListen };
+    return { eventListen, doAfterImport };
 })();

+ 12 - 2
web/building_saas/pm/js/pm_newMain.js

@@ -1301,8 +1301,13 @@ const projTreeObj = {
     getFileListWithPath:function (list) {
         for(let n of list){
             let node = projTreeObj.tree.findNode(n.ID);
-            if(node) n.name = getPathName(node);
+            if(node) {
+                n.name = getPathName(node);
+            }
+            n.serialNo = node && node.serialNo() || 1;
         }
+        // 按照正确的树结构排序
+        list.sort((a, b) => a.serialNo - b.serialNo);
 
         function getPathName(node) {
             if(node.parent && node.parent.data){
@@ -5080,8 +5085,13 @@ async function importProcessChecking(key) {
             if(result.status == "processing"){
                 setTimeout(checking,2000);
             }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);
+                    importView.doAfterImport(sorted);
+                }
                 $.bootstrapLoading.progressEnd();
-                refreshAllPage();
+                //refreshAllPage();
             }
         }
     }