|
@@ -392,14 +392,14 @@ async function accessToCopyProject(userID, compilationID, data, newProjectID) {
|
|
|
create_time: +new Date()
|
|
create_time: +new Date()
|
|
|
};
|
|
};
|
|
|
await importLogsModel.create(logData);
|
|
await importLogsModel.create(logData);
|
|
|
- handleCopyProject(logData.key, userID, compilationID,data,newProjectID);
|
|
|
|
|
|
|
+ handleCopyProject(logData.key, userID, compilationID, data, newProjectID, false);
|
|
|
return 'copying project';
|
|
return 'copying project';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function handleCopyProject(key, userID, compilationID, data, newProjectID) {
|
|
async function handleCopyProject(key, userID, compilationID, data, newProjectID) {
|
|
|
const doc = { status: 'finish' };
|
|
const doc = { status: 'finish' };
|
|
|
try {
|
|
try {
|
|
|
- const projectMap = await copyProject(userID, compilationID, data, newProjectID);
|
|
|
|
|
|
|
+ const projectMap = await copyProject(userID, compilationID, data, newProjectID, false);
|
|
|
doc.projectID = projectMap.copy.document.ID;
|
|
doc.projectID = projectMap.copy.document.ID;
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
doc.status = 'error';
|
|
doc.status = 'error';
|
|
@@ -411,15 +411,22 @@ async function handleCopyProject(key, userID, compilationID, data, newProjectID)
|
|
|
|
|
|
|
|
async function copyProject(userID, compilationID, data, newProjectID = null, delayProjectTask = false) {
|
|
async function copyProject(userID, compilationID, data, newProjectID = null, delayProjectTask = false) {
|
|
|
let projectMap = data.projectMap;
|
|
let projectMap = data.projectMap;
|
|
|
|
|
+ const isSaveAs = isDef(projectMap.isSaveAs) ? projectMap.isSaveAs : false; // 只有另存为的行为为true,这里需要区分是因为,另存为中另存费率单价文件时,若有重名需要直接报错提示,而不是自动加(xxx复制)的后缀
|
|
|
|
|
+ const saveAsFile = isDef(projectMap.saveAsFile) ? projectMap.saveAsFile : true; // 是否另存费率、单价文件,默认是另存的。
|
|
|
|
|
+ const projectParentID = projectMap['copy'].document.ParentID;
|
|
|
|
|
+ const projectName = projectMap['copy'].document.name;
|
|
|
|
|
+ if (isSaveAs) {
|
|
|
|
|
+ const isExist = await isProjectNameExist(projectParentID, projectName);
|
|
|
|
|
+ if (isExist) {
|
|
|
|
|
+ throw `分段文件[${projectName}]已存在。`;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
let originalID = projectMap['copy'].document.ID;
|
|
let originalID = projectMap['copy'].document.ID;
|
|
|
if (!newProjectID) {
|
|
if (!newProjectID) {
|
|
|
newProjectID = await getCounterID("projects");
|
|
newProjectID = await getCounterID("projects");
|
|
|
}
|
|
}
|
|
|
- let newFeeName = null,newUnitName = null;
|
|
|
|
|
let calcProgramFileID = uuidV1();//新的计算程序文件ID
|
|
let calcProgramFileID = uuidV1();//新的计算程序文件ID
|
|
|
let labourCoeFileID = uuidV1();//新的人工调整系数文件ID
|
|
let labourCoeFileID = uuidV1();//新的人工调整系数文件ID
|
|
|
- let feeRateFileID = uuidV1();//新的费率文件ID
|
|
|
|
|
- let unitPriceFileID = await getCounterID("unit_price_file");//新的单价文件ID
|
|
|
|
|
let originalProject = await projectModel.findOne({'ID':originalID});//查找最新的那项目信息,前端缓存的数据有可能不是最新的
|
|
let originalProject = await projectModel.findOne({'ID':originalID});//查找最新的那项目信息,前端缓存的数据有可能不是最新的
|
|
|
if(!originalProject){
|
|
if(!originalProject){
|
|
|
throw new Error('没有找到对应的项目,复制失败!');
|
|
throw new Error('没有找到对应的项目,复制失败!');
|
|
@@ -431,19 +438,6 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
|
|
|
let originalProperty = _.cloneDeep(property);
|
|
let originalProperty = _.cloneDeep(property);
|
|
|
projectMap['copy'].document.property = property;
|
|
projectMap['copy'].document.property = property;
|
|
|
logger.info("复制项目: 旧项目ID: "+originalID+ " ------- 新项目ID: "+newProjectID);
|
|
logger.info("复制项目: 旧项目ID: "+originalID+ " ------- 新项目ID: "+newProjectID);
|
|
|
- //费率文件、单价文件重名检查
|
|
|
|
|
- let feeRate = await feeRateFileModel.findOne({rootProjectID:originalProperty.rootProjectID,name:originalProperty.feeFile.name,deleteInfo:null});
|
|
|
|
|
- if(feeRate){//存在重名的文件
|
|
|
|
|
- newFeeName = originalProperty.feeFile.name + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
|
|
|
|
|
- projectMap['copy'].document.property.feeFile.name = newFeeName;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let unitPriceFile = await unitPriceFileModel.findOne({root_project_id: originalProperty.rootProjectID,name:originalProperty.unitPriceFile.name,deleteInfo: null});
|
|
|
|
|
- if(unitPriceFile){//存在重名的文件
|
|
|
|
|
- newUnitName = originalProperty.unitPriceFile.name + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
|
|
|
|
|
- projectMap['copy'].document.property.unitPriceFile.name = newUnitName;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
//更新项目的属性;
|
|
//更新项目的属性;
|
|
|
projectMap['copy'].document.ID = newProjectID;
|
|
projectMap['copy'].document.ID = newProjectID;
|
|
|
if(projectMap['copy'].document.property.calcProgramFile){
|
|
if(projectMap['copy'].document.property.calcProgramFile){
|
|
@@ -452,12 +446,6 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
|
|
|
if(projectMap['copy'].document.property.labourCoeFile){
|
|
if(projectMap['copy'].document.property.labourCoeFile){
|
|
|
projectMap['copy'].document.property.labourCoeFile.ID = labourCoeFileID;
|
|
projectMap['copy'].document.property.labourCoeFile.ID = labourCoeFileID;
|
|
|
}
|
|
}
|
|
|
- if(projectMap['copy'].document.property.feeFile){
|
|
|
|
|
- projectMap['copy'].document.property.feeFile.id = feeRateFileID;
|
|
|
|
|
- }
|
|
|
|
|
- if(projectMap['copy'].document.property.unitPriceFile){
|
|
|
|
|
- projectMap['copy'].document.property.unitPriceFile.id = unitPriceFileID;
|
|
|
|
|
- }
|
|
|
|
|
projectMap['copy'].document.userID = userID;
|
|
projectMap['copy'].document.userID = userID;
|
|
|
projectMap['copy'].document.compilation = compilationID;
|
|
projectMap['copy'].document.compilation = compilationID;
|
|
|
projectMap['copy'].document.createDateTime = new Date();
|
|
projectMap['copy'].document.createDateTime = new Date();
|
|
@@ -487,11 +475,41 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
|
|
|
if(originalProperty.labourCoeFile){
|
|
if(originalProperty.labourCoeFile){
|
|
|
copyTasks.push(commonCopy(newProjectID,originalProperty.labourCoeFile.ID,labourCoeFileID,labourCoesModel));
|
|
copyTasks.push(commonCopy(newProjectID,originalProperty.labourCoeFile.ID,labourCoeFileID,labourCoesModel));
|
|
|
}
|
|
}
|
|
|
- if(originalProperty.feeFile){
|
|
|
|
|
- copyTasks.push(copyFeeRate(originalProperty.rootProjectID,userID,originalProperty.feeFile.id,feeRateFileID,newFeeName));
|
|
|
|
|
- }
|
|
|
|
|
- if(originalProperty.unitPriceFile){
|
|
|
|
|
- copyTasks.push(copyUnitPriceFile(newProjectID,originalProperty.rootProjectID,userID,originalProperty.unitPriceFile.id,unitPriceFileID,newUnitName));
|
|
|
|
|
|
|
+ // 处理单价、费率文件
|
|
|
|
|
+ if (saveAsFile) {
|
|
|
|
|
+ let feeRateFileName = isSaveAs ? projectName : originalProperty.feeFile.name;
|
|
|
|
|
+ let unitPriceFileName = isSaveAs ? projectName : originalProperty.unitPriceFile.name;
|
|
|
|
|
+ let feeRateFileID = uuidV1();//新的费率文件ID
|
|
|
|
|
+ let unitPriceFileID = await getCounterID("unit_price_file");//新的单价文件ID
|
|
|
|
|
+ //费率文件、单价文件重名检查
|
|
|
|
|
+ let feeRate = await feeRateFileModel.findOne({ rootProjectID: originalProperty.rootProjectID, name: feeRateFileName, deleteInfo: null });
|
|
|
|
|
+ if (feeRate) {//存在重名的文件
|
|
|
|
|
+ if (isSaveAs) {
|
|
|
|
|
+ throw `费率文件[${feeRateFileName}]已存在,请手工检查数据是否正确。`;
|
|
|
|
|
+ }
|
|
|
|
|
+ feeRateFileName = feeRateFileName + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
|
|
|
|
|
+ }
|
|
|
|
|
+ projectMap['copy'].document.property.feeFile.name = feeRateFileName;
|
|
|
|
|
+ let unitPriceFile = await unitPriceFileModel.findOne({ root_project_id: originalProperty.rootProjectID, name: unitPriceFileName, deleteInfo: null });
|
|
|
|
|
+ if (unitPriceFile) {//存在重名的文件
|
|
|
|
|
+ if (isSaveAs) {
|
|
|
|
|
+ throw `单价文件[${unitPriceFileName}]已存在,请手工检查数据是否正确。`;
|
|
|
|
|
+ }
|
|
|
|
|
+ unitPriceFileName = unitPriceFileName + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
|
|
|
|
|
+ }
|
|
|
|
|
+ projectMap['copy'].document.property.unitPriceFile.name = unitPriceFileName;
|
|
|
|
|
+ if(projectMap['copy'].document.property.feeFile){
|
|
|
|
|
+ projectMap['copy'].document.property.feeFile.id = feeRateFileID;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(projectMap['copy'].document.property.unitPriceFile){
|
|
|
|
|
+ projectMap['copy'].document.property.unitPriceFile.id = unitPriceFileID;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(originalProperty.feeFile){
|
|
|
|
|
+ copyTasks.push(copyFeeRate(originalProperty.rootProjectID,userID,originalProperty.feeFile.id,feeRateFileID,feeRateFileName));
|
|
|
|
|
+ }
|
|
|
|
|
+ if(originalProperty.unitPriceFile){
|
|
|
|
|
+ copyTasks.push(copyUnitPriceFile(newProjectID,originalProperty.rootProjectID,userID,originalProperty.unitPriceFile.id,unitPriceFileID,unitPriceFileName));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
await Promise.all(copyTasks);
|
|
await Promise.all(copyTasks);
|
|
|
// 最后再处理项目数据
|
|
// 最后再处理项目数据
|
|
@@ -504,6 +522,13 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 判断项目名称是否存在
|
|
|
|
|
+async function isProjectNameExist(parentID, name) {
|
|
|
|
|
+ const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
|
|
|
|
|
+ const count = await projectModel.count({ ParentID: parentID, name, $or: notDeleted });
|
|
|
|
|
+ return !!count;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async function createIDsAndReturn(originalID,model) {
|
|
async function createIDsAndReturn(originalID,model) {
|
|
|
let uuidMaping = {};//做ID映射
|
|
let uuidMaping = {};//做ID映射
|
|
|
let datas = [];
|
|
let datas = [];
|