|
@@ -27,7 +27,8 @@ module.exports={
|
|
|
prepareInitialData: prepareInitialData,
|
|
prepareInitialData: prepareInitialData,
|
|
|
changeFile:changeFile,
|
|
changeFile:changeFile,
|
|
|
copyForSectionError: copyForSectionError,
|
|
copyForSectionError: copyForSectionError,
|
|
|
- exportProject:exportProject
|
|
|
|
|
|
|
+ exportProject:exportProject,
|
|
|
|
|
+ importProject:importProject
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@@ -293,35 +294,34 @@ async function copyProjectSetting(originalID,newProjectID) {
|
|
|
async function copyBills(newProjectID,billMap) {
|
|
async function copyBills(newProjectID,billMap) {
|
|
|
let uuidMaping = billMap.uuidMaping;//做ID映射
|
|
let uuidMaping = billMap.uuidMaping;//做ID映射
|
|
|
for(let doc of billMap.datas){
|
|
for(let doc of billMap.datas){
|
|
|
- doc.projectID = newProjectID;
|
|
|
|
|
- doc.ID = uuidMaping[doc.ID] ? uuidMaping[doc.ID] : -1;
|
|
|
|
|
- doc.ParentID = uuidMaping[doc.ParentID] ? uuidMaping[doc.ParentID] : -1;
|
|
|
|
|
- doc.NextSiblingID = uuidMaping[doc.NextSiblingID] ? uuidMaping[doc.NextSiblingID] : -1;
|
|
|
|
|
- //对于有基数计算的节点,需要替换计算基数中引用的ID为新的ID
|
|
|
|
|
- if(doc.calcBase && doc.calcBase != ""){
|
|
|
|
|
- let idArr = scMathUtil.getFIDArr(doc.calcBase);
|
|
|
|
|
- for(let re of idArr){
|
|
|
|
|
- let oID = re.substr(1);//去掉开头的@字符
|
|
|
|
|
- if(!uuidMaping[oID]) continue;
|
|
|
|
|
- doc.calcBase = doc.calcBase.replace(new RegExp(oID, "g"),uuidMaping[oID]);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ doc = getCopyBillDatas(doc,newProjectID,uuidMaping)
|
|
|
}
|
|
}
|
|
|
await insertMany(billMap.datas,billsModel);
|
|
await insertMany(billMap.datas,billsModel);
|
|
|
return billMap.datas;
|
|
return billMap.datas;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+function getCopyBillDatas(doc,newProjectID,uuidMaping) {
|
|
|
|
|
+ doc.projectID = newProjectID;
|
|
|
|
|
+ doc.ID = uuidMaping[doc.ID] ? uuidMaping[doc.ID] : -1;
|
|
|
|
|
+ doc.ParentID = uuidMaping[doc.ParentID] ? uuidMaping[doc.ParentID] : -1;
|
|
|
|
|
+ doc.NextSiblingID = uuidMaping[doc.NextSiblingID] ? uuidMaping[doc.NextSiblingID] : -1;
|
|
|
|
|
+ //对于有基数计算的节点,需要替换计算基数中引用的ID为新的ID
|
|
|
|
|
+ if(doc.calcBase && doc.calcBase != ""){
|
|
|
|
|
+ let idArr = scMathUtil.getFIDArr(doc.calcBase);
|
|
|
|
|
+ for(let re of idArr){
|
|
|
|
|
+ let oID = re.substr(1);//去掉开头的@字符
|
|
|
|
|
+ if(!uuidMaping[oID]) continue;
|
|
|
|
|
+ doc.calcBase = doc.calcBase.replace(new RegExp(oID, "g"),uuidMaping[oID]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return doc;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async function copyRations(newProjectID,billsIDMap,rationMap,projectGLJIDMap) {
|
|
async function copyRations(newProjectID,billsIDMap,rationMap,projectGLJIDMap) {
|
|
|
let uuidMaping = rationMap.uuidMaping;
|
|
let uuidMaping = rationMap.uuidMaping;
|
|
|
for(let doc of rationMap.datas){
|
|
for(let doc of rationMap.datas){
|
|
|
- doc.projectID = newProjectID;
|
|
|
|
|
- doc.ID = uuidMaping[doc.ID] ? uuidMaping[doc.ID] : -1;
|
|
|
|
|
- if(doc.billsItemID){
|
|
|
|
|
- doc.billsItemID = billsIDMap[doc.billsItemID]?billsIDMap[doc.billsItemID]:-1;
|
|
|
|
|
- }
|
|
|
|
|
- if(doc.referenceRationID) doc.referenceRationID = uuidMaping[doc.referenceRationID]?uuidMaping[doc.referenceRationID]:undefined;
|
|
|
|
|
- //绑定定类型的工料机 项目工料机ID
|
|
|
|
|
- doc.type==3&&doc.projectGLJID&&projectGLJIDMap[doc.projectGLJID]?doc.projectGLJID = projectGLJIDMap[doc.projectGLJID]:'';
|
|
|
|
|
|
|
+ doc = getCopyRationData(doc,newProjectID,billsIDMap,uuidMaping,projectGLJIDMap);
|
|
|
}
|
|
}
|
|
|
if(rationMap.datas.length > 0){
|
|
if(rationMap.datas.length > 0){
|
|
|
await insertMany(rationMap.datas,rationModel);
|
|
await insertMany(rationMap.datas,rationModel);
|
|
@@ -329,6 +329,20 @@ async function copyRations(newProjectID,billsIDMap,rationMap,projectGLJIDMap) {
|
|
|
return rationMap.datas;
|
|
return rationMap.datas;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+function getCopyRationData(doc,newProjectID,billsIDMap,uuidMaping,projectGLJIDMap){
|
|
|
|
|
+ doc.projectID = newProjectID;
|
|
|
|
|
+ doc.ID = uuidMaping[doc.ID] ? uuidMaping[doc.ID] : -1;
|
|
|
|
|
+ if(doc.billsItemID){
|
|
|
|
|
+ doc.billsItemID = billsIDMap[doc.billsItemID]?billsIDMap[doc.billsItemID]:-1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(doc.referenceRationID) doc.referenceRationID = uuidMaping[doc.referenceRationID]?uuidMaping[doc.referenceRationID]:undefined;
|
|
|
|
|
+ //绑定定类型的工料机 项目工料机ID
|
|
|
|
|
+ doc.type==3&&doc.projectGLJID&&projectGLJIDMap[doc.projectGLJID]?doc.projectGLJID = projectGLJIDMap[doc.projectGLJID]:'';
|
|
|
|
|
+ return doc;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async function copyProjectGLJ(gljList) {
|
|
async function copyProjectGLJ(gljList) {
|
|
|
await insertMany(gljList,gljListModel);
|
|
await insertMany(gljList,gljListModel);
|
|
|
}
|
|
}
|
|
@@ -416,7 +430,8 @@ async function copyRationSubList(originalPID,newProjectID,billIDMap,rationIDMap,
|
|
|
let subList = await model.find({projectID:originalPID}, '-_id');
|
|
let subList = await model.find({projectID:originalPID}, '-_id');
|
|
|
let newList =[];
|
|
let newList =[];
|
|
|
for(let s of subList){
|
|
for(let s of subList){
|
|
|
- s._doc.ID = uuidV1();
|
|
|
|
|
|
|
+ s._doc = getCopyRationSubData(s._doc,newProjectID,billIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+ /* s._doc.ID = uuidV1();
|
|
|
s._doc.projectID = newProjectID;
|
|
s._doc.projectID = newProjectID;
|
|
|
s._doc.rationID&&rationIDMap[s._doc.rationID]?s._doc.rationID = rationIDMap[s._doc.rationID]:'';
|
|
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.billID&&billIDMap[s._doc.billID]?s._doc.billID = billIDMap[s._doc.billID]:'';
|
|
@@ -427,12 +442,30 @@ async function copyRationSubList(originalPID,newProjectID,billIDMap,rationIDMap,
|
|
|
if(t.billID && billIDMap[t.billID]) t.billID = billIDMap[t.billID];
|
|
if(t.billID && billIDMap[t.billID]) t.billID = billIDMap[t.billID];
|
|
|
if(t.fxID && billIDMap[t.fxID]) t.fxID = billIDMap[t.fxID];
|
|
if(t.fxID && billIDMap[t.fxID]) t.fxID = billIDMap[t.fxID];
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
newList.push(s._doc);
|
|
newList.push(s._doc);
|
|
|
}
|
|
}
|
|
|
await insertMany(newList,model);
|
|
await insertMany(newList,model);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function getCopyRationSubData(doc,newProjectID,billIDMap,rationIDMap,projectGLJIDMap){
|
|
|
|
|
+ doc.ID = uuidV1();
|
|
|
|
|
+ doc.projectID = newProjectID;
|
|
|
|
|
+ doc.rationID&&rationIDMap[doc.rationID]?doc.rationID = rationIDMap[doc.rationID]:'';
|
|
|
|
|
+ doc.billID&&billIDMap[doc.billID]?doc.billID = billIDMap[doc.billID]:'';
|
|
|
|
|
+ doc.billsItemID&&billIDMap[doc.billsItemID]?doc.billsItemID = billIDMap[doc.billsItemID]:'';
|
|
|
|
|
+ doc.projectGLJID&&projectGLJIDMap[doc.projectGLJID]?doc.projectGLJID = projectGLJIDMap[doc.projectGLJID]:'';
|
|
|
|
|
+ if(doc.templateList && doc.templateList.length > 0 ){
|
|
|
|
|
+ for(let t of doc.templateList){
|
|
|
|
|
+ if(t.billID && billIDMap[t.billID]) t.billID = billIDMap[t.billID];
|
|
|
|
|
+ if(t.fxID && billIDMap[t.fxID]) t.fxID = billIDMap[t.fxID];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return doc;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async function moveProject(data) {
|
|
async function moveProject(data) {
|
|
|
data = JSON.parse(data);
|
|
data = JSON.parse(data);
|
|
|
let projectMap = data.projectMap,feeRateMap = data.feeRateMap,unitPriceMap = data.unitPriceMap;
|
|
let projectMap = data.projectMap,feeRateMap = data.feeRateMap,unitPriceMap = data.unitPriceMap;
|
|
@@ -465,7 +498,7 @@ async function moveProject(data) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if(!_.isEmpty(unitPriceMap)&&data.rootProjectID) {//如果单价文件有修改
|
|
if(!_.isEmpty(unitPriceMap)&&data.rootProjectID) {//如果单价文件有修改
|
|
|
- let unitPriceFiles = await unitPriceFileModel.find({root_project_id: data.rootProjectID, deleteInfo: null});
|
|
|
|
|
|
|
+ let unitPriceFiles = await unitPriceFileModel.find({root_project_id: data.rootProjectID, deleteInfo: null});
|
|
|
for(let projectID in unitPriceMap){
|
|
for(let projectID in unitPriceMap){
|
|
|
let checkUn = _.find(unitPriceFiles,{'name':unitPriceMap[projectID].name});
|
|
let checkUn = _.find(unitPriceFiles,{'name':unitPriceMap[projectID].name});
|
|
|
let rename = unitPriceMap[projectID].name;
|
|
let rename = unitPriceMap[projectID].name;
|
|
@@ -979,7 +1012,6 @@ async function changeFile(datas,userID,fileID,name,from,type){//from 费率或
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function exportProject(userID,data){//导出建设项目
|
|
async function exportProject(userID,data){//导出建设项目
|
|
|
- console.log(data);
|
|
|
|
|
if(data.type == 'main'){
|
|
if(data.type == 'main'){
|
|
|
return await exportMainData(userID,data.projectID);
|
|
return await exportMainData(userID,data.projectID);
|
|
|
}else {
|
|
}else {
|
|
@@ -1054,4 +1086,250 @@ async function exportTenderData(data){
|
|
|
result.labourCoes = await labourCoesModel.findOne({projectID:data.projectID});
|
|
result.labourCoes = await labourCoesModel.findOne({projectID:data.projectID});
|
|
|
|
|
|
|
|
return cipher.aesEncrypt(JSON.stringify(result));
|
|
return cipher.aesEncrypt(JSON.stringify(result));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async function importProject(data,req,fields) {
|
|
|
|
|
+ let result = {error:0};
|
|
|
|
|
+ let stringArr = data.split("|----|");
|
|
|
|
|
+ let datas = [];
|
|
|
|
|
+ for(let s of stringArr){
|
|
|
|
|
+ datas.push(JSON.parse(cipher.aesDecrypt(s)));
|
|
|
|
|
+ }
|
|
|
|
|
+ let mainData = datas.length > 0 ?datas[0]:null;
|
|
|
|
|
+ if(mainData){
|
|
|
|
|
+ if(mainData.compilationID != req.session.sessionCompilation._id){
|
|
|
|
|
+ result.error = 1;
|
|
|
|
|
+ result.msg = "编办不同,无法导入,请重新选择!";
|
|
|
|
|
+ }else {
|
|
|
|
|
+ let [projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,JSON.parse(fields.updateData[0]),req.session.sessionUser.id);
|
|
|
|
|
+ if(datas.length > 1 ){
|
|
|
|
|
+ for(let i = 1;i<datas.length;i++){
|
|
|
|
|
+ await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap){
|
|
|
|
|
+ let bills = [],rations = [],projectGLJs = [],rationGLJs=[],rationCoes=[],quantityDetails=[],rationInstallations=[],rationTemplates=[];
|
|
|
|
|
+ let newProjectSetting =null,newCalcProgramsFile = null,newLabourCoe = null;
|
|
|
|
|
+ let billsIDMap = {},projectGLJIDMap={},rationIDMap = {};
|
|
|
|
|
+ let newProjectID = projectIDMap[data.projSetting.projectID];
|
|
|
|
|
+ //生成新的清单;
|
|
|
|
|
+ if(data.bills && data.bills.length > 0){
|
|
|
|
|
+ for(let b of data.bills){
|
|
|
|
|
+ billsIDMap[b.ID] = uuidV1();
|
|
|
|
|
+ }
|
|
|
|
|
+ for(let b of data.bills){
|
|
|
|
|
+ delete b._id;
|
|
|
|
|
+ b = getCopyBillDatas(b,newProjectID,billsIDMap);
|
|
|
|
|
+ bills.push(b);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //生成项目工料机数据
|
|
|
|
|
+ if(data.projectGLJs && data.projectGLJs.length > 0){
|
|
|
|
|
+ let gljCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.glj_list, data.projectGLJs.length);
|
|
|
|
|
+ for(let i = 0; i < data.projectGLJs.length; i++){
|
|
|
|
|
+ let d = data.projectGLJs[i];
|
|
|
|
|
+ delete d._id;
|
|
|
|
|
+ let newID = gljCount.sequence_value - (data.projectGLJs.length - 1) + i;
|
|
|
|
|
+ projectGLJIDMap[d.id] = newID;
|
|
|
|
|
+ d.project_id = newProjectID;
|
|
|
|
|
+ d.id = newID;
|
|
|
|
|
+ projectGLJs.push(d);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //生成新的定额
|
|
|
|
|
+ if(data.rations && data.rations.length > 0){
|
|
|
|
|
+ for(let r of data.rations){
|
|
|
|
|
+ rationIDMap[r.ID] = uuidV1();
|
|
|
|
|
+ }
|
|
|
|
|
+ for(let r of data.rations){
|
|
|
|
|
+ delete r._id;
|
|
|
|
|
+ r = getCopyRationData(r,newProjectID,billsIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+ rations.push(r);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //生成定额下挂的定额工料机等等数据
|
|
|
|
|
+ if(data.rationGLJs && data.rationGLJs.length > 0) rationGLJs = setRationSubList(data.rationGLJs,newProjectID,billsIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+ if(data.rationCoes && data.rationCoes.length > 0) rationCoes = setRationSubList(data.rationCoes,newProjectID,billsIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+ if(data.quantityDetails && data.quantityDetails.length > 0) quantityDetails = setRationSubList(data.quantityDetails,newProjectID,billsIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+ if(data.rationInstallations && data.rationInstallations.length > 0) rationInstallations = setRationSubList(data.rationInstallations,newProjectID,billsIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+ if(data.rationTemplates && data.rationTemplates.length > 0) rationTemplates = setRationSubList(data.rationTemplates,newProjectID,billsIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+
|
|
|
|
|
+ //生成projectSetting 文件
|
|
|
|
|
+ if(data.projSetting){
|
|
|
|
|
+ data.projSetting.projectID =newProjectID;
|
|
|
|
|
+ newProjectSetting = data.projSetting;
|
|
|
|
|
+ delete newProjectSetting._id;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //生成计算程序文件,系数文件
|
|
|
|
|
+ if(data.calcProgramsFile && calcProgramFileIDMap[data.calcProgramsFile.ID]){
|
|
|
|
|
+ data.calcProgramsFile.ID = calcProgramFileIDMap[data.calcProgramsFile.ID];
|
|
|
|
|
+ data.calcProgramsFile.projectID = newProjectID;
|
|
|
|
|
+ newCalcProgramsFile = data.calcProgramsFile;
|
|
|
|
|
+ delete newCalcProgramsFile._id;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ if(data.labourCoes && labourCoeFileIDMap[data.labourCoes.ID]){
|
|
|
|
|
+ data.labourCoes.ID = labourCoeFileIDMap[data.labourCoes.ID];
|
|
|
|
|
+ data.labourCoes.projectID = newProjectID;
|
|
|
|
|
+ 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);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+function setRationSubList(datas,newProjectID,billIDMap,rationIDMap,projectGLJIDMap) {
|
|
|
|
|
+ let arrs = [];
|
|
|
|
|
+ for(let d of datas){
|
|
|
|
|
+ delete d._id;
|
|
|
|
|
+ d = getCopyRationSubData(d,newProjectID,billIDMap,rationIDMap,projectGLJIDMap);
|
|
|
|
|
+ arrs.push(d);
|
|
|
|
|
+ }
|
|
|
|
|
+ return arrs;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function handleMainProjectDatas(mainData,updateData,userID) {
|
|
|
|
|
+ let mainProjectID = -1;
|
|
|
|
|
+ let projectIDMap = {},feeRateFileIDMap={},unitPriceFileIDMap={},labourCoeFileIDMap={},calcProgramFileIDMap={};
|
|
|
|
|
+ let tasks = [];
|
|
|
|
|
+ //生成新的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 == "Tender"){
|
|
|
|
|
+ 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.feeFile) feeRateFileIDMap[p.property.feeFile.id] = uuidV1();//新的费率文件ID
|
|
|
|
|
+ if(p.property.unitPriceFile) unitPriceFileIDMap[p.property.unitPriceFile.id] = await getCounterID("unit_price_file");//新的单价文件ID
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(mainProjectID == -1) throw new Error("文件里面没包含建设项目信息!");
|
|
|
|
|
+
|
|
|
|
|
+ //处理项目信息 ----- 费率文件,单价文件ID信息要重新生成----to do
|
|
|
|
|
+ for(let p of mainData.projects){
|
|
|
|
|
+ delete p._id;
|
|
|
|
|
+ delete p.__v;
|
|
|
|
|
+ p.ID = projectIDMap[p.ID];
|
|
|
|
|
+ if(p.ID == mainProjectID){//对于建设项目,要父和下一节点ID要使用前端传入的位置ID
|
|
|
|
|
+ p.ParentID = updateData.self.ParentID;
|
|
|
|
|
+ p.NextSiblingID = updateData.self.NextSiblingID;
|
|
|
|
|
+ if(updateData.update){//树节构中的上一节点的下一节点设置为本建设项目ID;
|
|
|
|
|
+ tasks.push({updateOne:{filter : updateData.update.query, update : {NextSiblingID:mainProjectID}}});
|
|
|
|
|
+ }
|
|
|
|
|
+ //查看是否重名;
|
|
|
|
|
+ let temp = await projectModel.findOne({userID:userID,ParentID:p.ParentID,name:p.name});
|
|
|
|
|
+ if(temp) p.name = p.name + '(' + moment(Date.now()).format('MM-DD HH:mm:ss') + '导入)';
|
|
|
|
|
+ }else {
|
|
|
|
|
+ p.ParentID = projectIDMap[p.ParentID];
|
|
|
|
|
+ p.NextSiblingID = projectIDMap[p.NextSiblingID];
|
|
|
|
|
+ }
|
|
|
|
|
+ p.userID =userID;
|
|
|
|
|
+ p.shareInfo=[];
|
|
|
|
|
+ if(p.projType == "Tender"){
|
|
|
|
|
+ if(p.property.calcProgramFile) p.property.calcProgramFile.ID = calcProgramFileIDMap[p.property.calcProgramFile.ID];
|
|
|
|
|
+ if(p.property.labourCoeFile) p.property.labourCoeFile.ID = labourCoeFileIDMap[p.property.labourCoeFile.ID];
|
|
|
|
|
+ if(p.property.feeFile) p.property.feeFile.id = feeRateFileIDMap[p.property.feeFile.id];
|
|
|
|
|
+ if(p.property.unitPriceFile) p.property.unitPriceFile.id = unitPriceFileIDMap[p.property.unitPriceFile.id];
|
|
|
|
|
+ p.property.rootProjectID = mainProjectID
|
|
|
|
|
+ }
|
|
|
|
|
+ tasks.push({insertOne: {document: p}})
|
|
|
|
|
+ }
|
|
|
|
|
+ //项目树节构数据生成:
|
|
|
|
|
+ await projectModel.bulkWrite(tasks);
|
|
|
|
|
+
|
|
|
|
|
+ //生成所有的费率文件
|
|
|
|
|
+ await importFeeRateFiles(mainData,projectIDMap,feeRateFileIDMap,userID);
|
|
|
|
|
+
|
|
|
|
|
+ //生成所有的单价文件
|
|
|
|
|
+ await importUnitPriceFiles(mainData,projectIDMap,unitPriceFileIDMap,userID);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return [projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+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){
|
|
|
|
|
+ let file = f.unitFile,prices = f.unitPrices,mixs = f.mixRatios,fres = f.freights,ors = f.originals;
|
|
|
|
|
+ //生成单价文件
|
|
|
|
|
+ delete file._id;
|
|
|
|
|
+ file.id = unitPriceFileIDMap[file.id]?unitPriceFileIDMap[file.id]:await getCounterID("unit_price_file");
|
|
|
|
|
+ file.project_id = projectIDMap[file.project_id];
|
|
|
|
|
+ file.root_project_id = projectIDMap[file.root_project_id];
|
|
|
|
|
+ file.user_id = userID;
|
|
|
|
|
+ unitFiles.push(file);
|
|
|
|
|
+
|
|
|
|
|
+ //生成子数据
|
|
|
|
|
+ if(prices) await setSubList(prices,unitPrices,file.id,unitPriceModel);
|
|
|
|
|
+ if(mixs) await setSubList(mixs,mixRatios,file.id,mixRatioModel);
|
|
|
|
|
+ if(fres) await setSubList(fres,freights,file.id,freightModel,true);
|
|
|
|
|
+ if(ors) await setSubList(ors,originals,file.id,originalModel,true);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(unitFiles.length > 0) await insertMany(unitFiles,unitPriceFileModel);
|
|
|
|
|
+ if(unitPrices.length > 0) await insertMany(unitPrices,unitPriceModel);
|
|
|
|
|
+ if(mixRatios.length > 0) await insertMany(mixRatios,mixRatioModel);
|
|
|
|
|
+ if(freights.length > 0) await insertMany(freights,freightModel);
|
|
|
|
|
+ if(originals.length > 0) await insertMany(originals,originalModel);
|
|
|
|
|
+
|
|
|
|
|
+ async function setSubList(oList,nList,fileID,model,UUID=false) {
|
|
|
|
|
+ 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);
|
|
|
|
|
+ nList.push(o)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async function importFeeRateFiles(mainData,projectIDMap,feeRateFileIDMap,userID) {
|
|
|
|
|
+ let feeRateFiles = [], feeRates = [];
|
|
|
|
|
+ if(!mainData.files.feeRateFiles) return;
|
|
|
|
|
+ for(let f of mainData.files.feeRateFiles){
|
|
|
|
|
+ //生成费率记录
|
|
|
|
|
+ let rate = f.feeRate;
|
|
|
|
|
+ delete rate._id;
|
|
|
|
|
+ rate.ID = uuidV1();
|
|
|
|
|
+ feeRates.push(rate);
|
|
|
|
|
+
|
|
|
|
|
+ //生成费率文件记录
|
|
|
|
|
+ let file = f.feeRateFile;
|
|
|
|
|
+ delete file._id;
|
|
|
|
|
+ file.ID = feeRateFileIDMap[file.ID]?feeRateFileIDMap[file.ID]:uuidV1();
|
|
|
|
|
+ file.userID = userID;
|
|
|
|
|
+ file.rootProjectID = projectIDMap[file.rootProjectID];
|
|
|
|
|
+ file.feeRateID = rate.ID;
|
|
|
|
|
+ feeRateFiles.push(file);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(feeRateFiles.length > 0) await insertMany(feeRateFiles,feeRateFileModel);
|
|
|
|
|
+ if(feeRates.length > 0) await insertMany(feeRates,feeRateModel);
|
|
|
}
|
|
}
|