|
|
@@ -27,6 +27,7 @@ module.exports={
|
|
|
prepareInitialData: prepareInitialData,
|
|
|
changeFile:changeFile,
|
|
|
copyForSectionError: copyForSectionError,
|
|
|
+ exportProject:exportProject
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -49,6 +50,8 @@ let feeRateModel = mongoose.model('fee_rates');
|
|
|
let feeRateFileModel = mongoose.model('fee_rate_file');
|
|
|
let unitPriceFileModel = mongoose.model("unit_price_file");
|
|
|
let mixRatioModel = mongoose.model("mix_ratio");
|
|
|
+let freightModel = mongoose.model("freight_calc");
|
|
|
+let originalModel = mongoose.model("original_calc");
|
|
|
let unitPriceModel = mongoose.model("unit_price");
|
|
|
let installationFeeModel = mongoose.model("installation_fee");
|
|
|
let rationGLJModel = mongoose.model('ration_glj');
|
|
|
@@ -70,6 +73,7 @@ import CounterModel from "../../glj/models/counter_model";
|
|
|
import moment from 'moment';
|
|
|
import billsFlags from '../../common/const/bills_fixed';
|
|
|
const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
|
|
|
+let cipher = require('../../../public/cipher');
|
|
|
|
|
|
|
|
|
|
|
|
@@ -362,6 +366,8 @@ async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnit
|
|
|
let taskList = [
|
|
|
copyFile(newProjectID,rootProjectID,userID,originaluUnitPriceFileID,unitPriceFileID,newName),
|
|
|
copySubList(originaluUnitPriceFileID,unitPriceFileID,mixRatioModel),
|
|
|
+ copySubList(originaluUnitPriceFileID,unitPriceFileID,freightModel,true),
|
|
|
+ copySubList(originaluUnitPriceFileID,unitPriceFileID,originalModel,true),
|
|
|
copySubList(originaluUnitPriceFileID,unitPriceFileID,unitPriceModel)
|
|
|
];
|
|
|
|
|
|
@@ -379,12 +385,12 @@ async function copyUnitPriceFile(newProjectID,rootProjectID,userID,originaluUnit
|
|
|
await unitPriceFileModel.create(unitPriceFile._doc);
|
|
|
}
|
|
|
|
|
|
- async function copySubList(srcFID,newFID,model) {
|
|
|
+ async function copySubList(srcFID,newFID,model,UUID=false) {
|
|
|
let mList = await model.find({unit_price_file_id: srcFID}, '-_id');
|
|
|
let rList = [];
|
|
|
for(let m of mList){
|
|
|
m._doc.unit_price_file_id = newFID;
|
|
|
- m._doc.id = await getCounterID(model.modelName);
|
|
|
+ UUID == true?m._doc.ID = uuidV1():m._doc.id = await getCounterID(model.modelName);
|
|
|
rList.push(m._doc);
|
|
|
}
|
|
|
await insertMany(rList,model)
|
|
|
@@ -970,4 +976,82 @@ async function changeFile(datas,userID,fileID,name,from,type){//from 费率或
|
|
|
}
|
|
|
await project_facade.markProjectsToChange(projectIDs,projectUpdateType)//项目标记为待刷新状态
|
|
|
|
|
|
+}
|
|
|
+
|
|
|
+async function exportProject(userID,data){//导出建设项目
|
|
|
+ console.log(data);
|
|
|
+ if(data.type == 'main'){
|
|
|
+ return await exportMainData(userID,data.projectID);
|
|
|
+ }else {
|
|
|
+ return await exportTenderData(data);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function exportMainData(userID,projectID) {
|
|
|
+ let result = {userID:userID,projects:[],type:'Project'};//type 备用属性,表示导出的类型,目前导出的都是整个建设项目
|
|
|
+ let tenderIDs = [];
|
|
|
+ let project = await projectModel.findOne({ID:projectID});
|
|
|
+ if(!project) throw new Error("没有找到该建设项目:"+projectID);
|
|
|
+ result['compilationID'] = project.compilation;
|
|
|
+ result.projects.push(project);
|
|
|
+ let subProjects = await projectModel.find({"$or": [{'ParentID':projectID}, {"property.rootProjectID": projectID}]});
|
|
|
+ for(let s of subProjects){
|
|
|
+ if(!s.deleteInfo || !s.deleteInfo.deleted){
|
|
|
+ result.projects.push(s);
|
|
|
+ if(s.projType =="Tender") tenderIDs.push(s.ID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let files = {unitFiles:await exportUnitFiles(projectID),feeRateFiles:await exportFeeRateFiles(projectID)};
|
|
|
+ result.files = files;
|
|
|
+ result = cipher.aesEncrypt(JSON.stringify(result));
|
|
|
+ result +="|----|" +JSON.stringify(tenderIDs);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+async function exportUnitFiles(rootProjectID){
|
|
|
+ let unitFiles = [];
|
|
|
+ let files = await unitPriceFileModel.find({root_project_id:rootProjectID});
|
|
|
+ for(let f of files){
|
|
|
+ if(f.deleteInfo && f.deleteInfo.deleted == true) continue;
|
|
|
+ let tem = {unitFile:f};
|
|
|
+ tem.unitPrices = await unitPriceModel.find({unit_price_file_id:f.id});
|
|
|
+ tem.mixRatios = await mixRatioModel.find({unit_price_file_id:f.id});
|
|
|
+ tem.freights = await freightModel.find({unit_price_file_id:f.id});
|
|
|
+ tem.originals = await originalModel.find({unit_price_file_id:f.id});
|
|
|
+ unitFiles.push(tem);
|
|
|
+ }
|
|
|
+ return unitFiles;
|
|
|
+}
|
|
|
+
|
|
|
+async function exportFeeRateFiles(rootProjectID) {
|
|
|
+ let feeRateFiles = [];
|
|
|
+ let files = await feeRateFileModel.find({rootProjectID:rootProjectID});
|
|
|
+ for(let f of files){
|
|
|
+ if(f.deleteInfo && f.deleteInfo.deleted == true) continue;
|
|
|
+ let tem = {feeRateFile:f};
|
|
|
+ tem.feeRate = await feeRateModel.findOne({ID:f.feeRateID});
|
|
|
+ feeRateFiles.push(tem);
|
|
|
+ }
|
|
|
+ return feeRateFiles;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+async function exportTenderData(data){
|
|
|
+ let result = {};
|
|
|
+ let projectSetting = await projectSettingModel.findOne({"projectID": data.projectID}, '-_id');
|
|
|
+ if(projectSetting) result['projSetting'] = projectSetting;
|
|
|
+ result.bills = await billsModel.find({"projectID": data.projectID});
|
|
|
+ result.rations = await rationModel.find({'$or': [{projectID: data.projectID, deleteInfo: null}, {projectID: data.projectID, 'deleteInfo.deleted': {$in: [null, false]}}]});
|
|
|
+ result.projectGLJs = await gljListModel.find({'project_id':data.projectID});
|
|
|
+ result.installationFees = await installationFeeModel.find({projectID:data.projectID});
|
|
|
+ result.rationGLJs = await rationGLJModel.find({projectID:data.projectID});
|
|
|
+ result.rationCoes = await rationCoeModel.find({projectID:data.projectID});
|
|
|
+ result.quantityDetails = await quantityDetailModel.find({projectID:data.projectID});
|
|
|
+ result.rationInstallations = await rationInstallationModel.find({projectID:data.projectID});
|
|
|
+ result.rationTemplates = await rationTemplateModel.find({projectID:data.projectID});
|
|
|
+ result.calcProgramsFile = await calcProgramsModel.findOne({projectID:data.projectID});
|
|
|
+ result.labourCoes = await labourCoesModel.findOne({projectID:data.projectID});
|
|
|
+
|
|
|
+ return cipher.aesEncrypt(JSON.stringify(result));
|
|
|
}
|