瀏覽代碼

导入建设项目批量显示

zhangweicheng 5 年之前
父節點
當前提交
4c972579ee
共有 2 個文件被更改,包括 73 次插入35 次删除
  1. 73 34
      modules/pm/facade/pm_facade.js
  2. 0 1
      modules/unit_price_file/facade/unit_price_facade.js

+ 73 - 34
modules/pm/facade/pm_facade.js

@@ -436,6 +436,7 @@ async function handleCopyProject(key, userID, compilationID, data, newProjectID)
 async function copyProject(userID, compilationID,data,newProjectID = null, delayProjectTask = false) {
     let projectMap = data.projectMap;
     let originalID = projectMap['copy'].document.ID;
+    
     if (!newProjectID) {
         newProjectID = await getCounterID("projects");
     }
@@ -493,6 +494,7 @@ async function copyProject(userID, compilationID,data,newProjectID = null, delay
     ];
     let [billMap,rationMap,projectGLJMap] = await Promise.all(IDtasks);
     //所有复制任务异步处理,提升效率  复制清单,定额,4个文件,项目工料机, 定额工料机,人工系数,工程量明细,定额安装增加费,安装增加费
+
     let copyTasks = [
         copyProjectSetting(originalID,newProjectID),
         copyBills(newProjectID,billMap),
@@ -534,12 +536,12 @@ async function copyProject(userID, compilationID,data,newProjectID = null, delay
 async function createIDsAndReturn(originalID,model) {
     let uuidMaping = {};//做ID映射
     let datas = [];
-    let result = await model.find({"projectID": originalID}, '-_id');
+    let result = await model.find({"projectID": originalID}, '-_id').lean();
     uuidMaping['-1'] = -1;
     //建立uuid-ID映射
     for(let d of result){
         uuidMaping[d.ID] = uuidV1();
-        datas.push(d._doc);
+        datas.push(d);
     }
     return{uuidMaping:uuidMaping,datas:datas};
 }
@@ -547,16 +549,16 @@ async function createIDsAndReturn(originalID,model) {
 async function getProjectGLJIDAndReturn(originalID,newProjectID) {
     let IDMap = {};
     let datas = [];
-    let result = await gljListModel.find({project_id:originalID}, '-_id');
+    let result = await gljListModel.find({project_id:originalID}, '-_id').lean();
     let gljCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.glj_list, result.length);
     for(let i = 0; i < result.length; i++){
         let d = result[i];
         let newID = gljCount.sequence_value - (result.length - 1) + i;
         //let newID = await getCounterID("glj_list");
         IDMap[d.id] = newID;
-        d._doc.project_id = newProjectID;
-        d._doc.id = newID;
-        datas.push(d._doc);
+        d.project_id = newProjectID;
+        d.id = newID;
+        datas.push(d);
     }
     return{IDMap:IDMap,datas:datas};
 }
@@ -689,12 +691,15 @@ async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnit
     }
 
     async function copySubList(srcFID,newFID,model) {
-        let mList = await model.find({unit_price_file_id: srcFID}, '-_id');
+        let mList = await model.find({unit_price_file_id: srcFID}, '-_id').lean();
         let rList = [];
+        let IDcounter = await counter.counterDAO.getIDAfterCountSync(model.modelName, mList.length);
+        let firstID = IDcounter.sequence_value - (mList.length - 1);
         for(let m of mList){
-            m._doc.unit_price_file_id = newFID;
-            m._doc.id = await getCounterID(model.modelName);
-            rList.push(m._doc);
+            m.unit_price_file_id = newFID;
+            m.id = firstID;    
+            firstID+=1
+            rList.push(m);
         }
         await insertMany(rList,model)
     }
@@ -716,26 +721,17 @@ async function copyInstallFee(originalPID,newProjectID) {
 }
 
 async function copyRationSubList(originalPID,newProjectID,billIDMap,rationIDMap,projectGLJIDMap,model) {// 定额工料机,附注条件,工程量明细,定额安装增加费,模板子目
-    let subList = await model.find({projectID:originalPID}, '-_id');
+    let first = +new Date();
+    let subList = await model.find({projectID:originalPID}, '-_id').lean();
     let newList =[];
     for(let s of subList){
-        s._doc = getCopyRationSubData(s._doc,newProjectID,billIDMap,rationIDMap,projectGLJIDMap);
-  /*      s._doc.ID = uuidV1();
-        s._doc.projectID = newProjectID;
-        s._doc.rationID&&rationIDMap[s._doc.rationID]?s._doc.rationID = rationIDMap[s._doc.rationID]:'';
-        s._doc.billID&&billIDMap[s._doc.billID]?s._doc.billID = billIDMap[s._doc.billID]:'';
-        s._doc.billsItemID&&billIDMap[s._doc.billsItemID]?s._doc.billsItemID = billIDMap[s._doc.billsItemID]:'';
-        s._doc.projectGLJID&&projectGLJIDMap[s._doc.projectGLJID]?s._doc.projectGLJID = projectGLJIDMap[s._doc.projectGLJID]:'';
-        if(s._doc.templateList && s._doc.templateList.length > 0 ){
-            for(let t of s._doc.templateList){
-                if(t.billID && billIDMap[t.billID]) t.billID =  billIDMap[t.billID];
-                if(t.fxID && billIDMap[t.fxID]) t.fxID =  billIDMap[t.fxID];
-            }
-        }*/
-        newList.push(s._doc);
+        s = getCopyRationSubData(s,newProjectID,billIDMap,rationIDMap,projectGLJIDMap);
+        newList.push(s);
 
     }
-    await insertMany(newList,model);
+    if(newList.length > 0) await insertMany(newList,model);
+    let last = +new Date();
+    console.log(model.modelName+"-------"+newList.length+"--copyRationSubList - insert时间为-------------------------------"+(last-first));
 }
 
 
@@ -926,10 +922,10 @@ async function getCounterID(collectionName){
 }
 
 async function insertMany(datas,model) {
-    while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入
+    /* while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入  2020-05-28 测试后发现没有限制,暂时先保留代码
         let newList = datas.splice(0,1000);//一次插入1000条
         await model.insertMany(newList);
-    }
+    } */
     await model.insertMany(datas);
 
 }
@@ -2407,6 +2403,7 @@ async function importProjects(data,req,updateData) {
     let result = {error:0};
     let stringArr = data.split("|----|");
     let datas = [];
+    let first = +new Date();
     for(let s of stringArr){
         datas.push(JSON.parse(cipher.aesDecrypt(s)));
     }
@@ -2431,13 +2428,48 @@ async function importProjects(data,req,updateData) {
             let [constructionProjectID,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
             result.constructionProjectID = constructionProjectID;
             if(datas.length > 1 ){
+                let newProjectSettings=[],bills=[],rations=[],installationFees=[],projectGLJs=[],rationGLJs=[],rationCoes=[],quantityDetails=[],rationInstallations=[],rationTemplates=[],evaluateList=[],bidList=[],contractorList=[],newCalcProgramsFiles=[],newLabourCoes=[]
                 for(let i = 1;i<datas.length;i++){
-                    await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
+                  let [tnewProjectSetting,tbills,trations,tinstallationFees,tprojectGLJs,trationGLJs,trationCoes,tquantityDetails,trationInstallations,trationTemplates,tevaluateList,tbidList,tcontractorList,tnewCalcProgramsFile,tnewLabourCoe] = await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
+                  if(tnewProjectSetting) newProjectSettings.push(tnewProjectSetting);
+                  if(tbills.length > 0) bills = bills.concat(tbills);
+                  if(trations.length > 0) rations = rations.concat(trations);
+                  if(tinstallationFees.length > 0) installationFees = installationFees.concat(tinstallationFees);
+                  if(tprojectGLJs.length > 0) projectGLJs = projectGLJs.concat(tprojectGLJs);
+                  if(trationGLJs.length > 0) rationGLJs = rationGLJs.concat(trationGLJs);
+                  if(trationCoes.length > 0) rationCoes = rationCoes.concat(trationCoes);
+                  if(tquantityDetails.length > 0) quantityDetails = quantityDetails.concat(tquantityDetails);
+                  if(trationInstallations.length > 0) rationInstallations = rationInstallations.concat(trationInstallations);
+                  if(trationTemplates.length > 0) rationTemplates = rationTemplates.concat(trationTemplates);
+                  if(tevaluateList.length > 0) evaluateList = evaluateList.concat(tevaluateList);
+                  if(tbidList.length > 0) bidList = bidList.concat(tbidList);
+                  if(tcontractorList.length > 0)  contractorList = contractorList.concat(tcontractorList);
+                  if(tnewCalcProgramsFile) newCalcProgramsFiles.push(tnewCalcProgramsFile);
+                  if(tnewLabourCoe) newLabourCoes.push(tnewLabourCoe); 
                 }
+
+                if(newProjectSettings.length > 0) await insertMany(newProjectSettings,projectSettingModel)
+                if(bills.length > 0) await insertMany(bills,billsModel);
+                if(rations.length > 0) await insertMany(rations,rationModel);
+                if(installationFees.length > 0) await insertMany(installationFees,installationFeeModel);
+                if(projectGLJs.length > 0) await insertMany(projectGLJs,gljListModel);
+                if(rationGLJs.length > 0) await insertMany(rationGLJs,rationGLJModel);
+                if(rationCoes.length > 0) await insertMany(rationCoes,rationCoeModel);
+                if(quantityDetails.length > 0) await insertMany(quantityDetails,quantityDetailModel);
+                if(rationInstallations.length > 0) await insertMany(rationInstallations,rationInstallationModel);
+                if(rationTemplates.length > 0) await insertMany(rationTemplates,rationTemplateModel);
+                if(evaluateList.length > 0) await insertMany(evaluateList,evaluateListModel);
+                if(bidList.length > 0) await insertMany(bidList,bidListModel);
+                if(contractorList.length > 0) await insertMany(contractorList,contractorListModel);
+                if(newCalcProgramsFiles.length > 0) await insertMany(newCalcProgramsFiles,calcProgramsModel);
+                if(newLabourCoes.length > 0) await insertMany(newLabourCoes,labourCoesModel); 
+
             }
 
         }
     }
+    let finish = +new Date();
+    console.log("导入操作总时间为-------------------------------"+(finish-first));
     return result;
 }
 
@@ -2526,7 +2558,9 @@ async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgra
         delete newLabourCoe._id;
     }
 
-    if(newProjectSetting) await projectSettingModel.create(newProjectSetting);
+    return [newProjectSetting,bills,rations,installationFees,projectGLJs,rationGLJs,rationCoes,quantityDetails,rationInstallations,rationTemplates,evaluateList,bidList,contractorList,newCalcProgramsFile,newLabourCoe]
+
+ /*    if(newProjectSetting) await projectSettingModel.create(newProjectSetting);
     if(bills.length > 0) await insertMany(bills,billsModel);
     if(rations.length > 0) await insertMany(rations,rationModel);
     if(installationFees.length > 0) await insertMany(installationFees,installationFeeModel);
@@ -2540,8 +2574,8 @@ async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgra
     if(bidList.length > 0) await insertMany(bidList,bidListModel);
     if(contractorList.length > 0) await insertMany(contractorList,contractorListModel);
     if(newCalcProgramsFile) await calcProgramsModel.create(newCalcProgramsFile);
-    if(newLabourCoe) await labourCoesModel.create(newLabourCoe);
-
+    if(newLabourCoe) await labourCoesModel.create(newLabourCoe); */
+ 
 
 }
 function setMaterialList(datas,newProjectID,projectGLJIDMap){
@@ -2629,6 +2663,8 @@ async function handleMainProjectDatas(mainData,updateData,userID) {
 
 
 async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,userID) {
+    
+  
     if(!mainData.files.unitFiles) return;
     let unitFiles = [],unitPrices =[],mixRatios=[],freights=[],originals=[];
     for(let f of mainData.files.unitFiles){
@@ -2650,11 +2686,14 @@ async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,use
     if(unitPrices.length > 0) await insertMany(unitPrices,unitPriceModel);
     if(mixRatios.length > 0) await insertMany(mixRatios,mixRatioModel);
 
-    async function setSubList(oList,nList,fileID,model,UUID=false) {
+    async function setSubList(oList,nList,fileID,model) {
+      let IDcounter = await counter.counterDAO.getIDAfterCountSync(model.modelName, oList.length);
+      let firstID = IDcounter.sequence_value - (oList.length - 1);
         for(let o of oList){
             delete o._id;
             o.unit_price_file_id = fileID;
-            UUID == true?o.ID = uuidV1():o.id = await getCounterID(model.modelName);
+            o.id = firstID;
+            firstID+=1
             nList.push(o)
         }
     }

+ 0 - 1
modules/unit_price_file/facade/unit_price_facade.js

@@ -26,7 +26,6 @@ async function setIDfromCounter(name,list,map,keyfield){//map,keyfield
         map[key]?map[key].push(a):map[key]=[a]
       }
   }
-
 }
 
 function getProjectGLJNewData(tmp,projectId,ext){