|
|
@@ -691,13 +691,24 @@ async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnit
|
|
|
}
|
|
|
|
|
|
async function copySubList(srcFID,newFID,model,UUID=false) {
|
|
|
- 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 = [];
|
|
|
- for(let m of mList){
|
|
|
- m._doc.unit_price_file_id = newFID;
|
|
|
- UUID == true?m._doc.ID = uuidV1():m._doc.id = await getCounterID(model.modelName);
|
|
|
- rList.push(m._doc);
|
|
|
- }
|
|
|
+ if(UUID == true){
|
|
|
+ for(let m of mList){
|
|
|
+ m.unit_price_file_id = newFID;
|
|
|
+ m.ID = uuidV1();
|
|
|
+ rList.push(m);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ let IDcounter = await counter.counterDAO.getIDAfterCountSync(model.modelName, mList.length);
|
|
|
+ let firstID = IDcounter.sequence_value - (mList.length - 1);
|
|
|
+ for(let m of mList){
|
|
|
+ m.unit_price_file_id = newFID;
|
|
|
+ m.id = firstID;
|
|
|
+ firstID+=1
|
|
|
+ rList.push(m);
|
|
|
+ }
|
|
|
+ }
|
|
|
await insertMany(rList,model)
|
|
|
}
|
|
|
}
|
|
|
@@ -910,10 +921,10 @@ async function getCounterID(collectionName){
|
|
|
}
|
|
|
|
|
|
async function insertMany(datas,model) {
|
|
|
- while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入
|
|
|
+ /* while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入
|
|
|
let newList = datas.splice(0,1000);//一次插入1000条
|
|
|
await model.insertMany(newList);
|
|
|
- }
|
|
|
+ } */
|
|
|
await model.insertMany(datas);
|
|
|
|
|
|
}
|
|
|
@@ -1588,10 +1599,34 @@ async function importProject(data,req,updateData) {
|
|
|
}
|
|
|
let [constructionProjectID,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
|
|
|
result.constructionProjectID = constructionProjectID;
|
|
|
- if(datas.length > 1 ){
|
|
|
+ if(datas.length > 1 ){//生成后统一次插入 2020-05-29
|
|
|
+ let newProjectSettings=[],bills=[],rations=[],projectGLJs=[],rationGLJs=[],rationCoes=[],quantityDetails=[],rationInstallations=[],rationTemplates=[],newCalcProgramsFiles=[],newLabourCoes=[];
|
|
|
for(let i = 1;i<datas.length;i++){
|
|
|
- await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
|
|
|
+ let [newProjectSetting,tbills,trations,tprojectGLJs,trationGLJs,trationCoes,tquantityDetails,trationInstallations,trationTemplates,newCalcProgramsFile,newLabourCoe] = await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
|
|
|
+ if(newProjectSetting) newProjectSettings.push(newProjectSetting);
|
|
|
+ if(tbills.length > 0) bills = bills.concat(tbills);
|
|
|
+ if(trations.length > 0) rations = rations.concat(trations);
|
|
|
+ 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(newCalcProgramsFile) newCalcProgramsFiles.push(newCalcProgramsFile);
|
|
|
+ if(newLabourCoe) newLabourCoes.push(newLabourCoe);
|
|
|
}
|
|
|
+
|
|
|
+ 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(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(newCalcProgramsFiles.length > 0) await insertMany(newCalcProgramsFiles,calcProgramsModel);
|
|
|
+ if(newLabourCoes.length>0) await insertMany(newLabourCoes,labourCoesModel);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -1670,19 +1705,7 @@ async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgra
|
|
|
newLabourCoe = data.labourCoes;
|
|
|
delete newLabourCoe._id;
|
|
|
}
|
|
|
-
|
|
|
- if(newProjectSetting) await projectSettingModel.create(newProjectSetting);
|
|
|
- if(bills.length > 0) await insertMany(bills,billsModel);
|
|
|
- if(rations.length > 0) await insertMany(rations,rationModel);
|
|
|
- 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(newCalcProgramsFile) await calcProgramsModel.create(newCalcProgramsFile);
|
|
|
- if(newLabourCoe) await labourCoesModel.create(newLabourCoe);
|
|
|
-
|
|
|
+ return [newProjectSetting,bills,rations,projectGLJs,rationGLJs,rationCoes,quantityDetails,rationInstallations,rationTemplates,newCalcProgramsFile,newLabourCoe]
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -1789,14 +1812,26 @@ async function importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,use
|
|
|
if(freights.length > 0) await insertMany(freights,freightModel);
|
|
|
if(originals.length > 0) await insertMany(originals,originalModel);
|
|
|
if(com_electrovalences.length > 0) await insertMany(com_electrovalences,comElectrovalenceModel);
|
|
|
-
|
|
|
async function setSubList(oList,nList,fileID,model,UUID=false) {
|
|
|
- for(let o of oList){
|
|
|
+ if(UUID == true){
|
|
|
+ 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 = uuidV1();
|
|
|
nList.push(o)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ 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;
|
|
|
+ o.id = firstID;
|
|
|
+ firstID+=1
|
|
|
+ nList.push(o)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|