|
@@ -17,6 +17,8 @@ module.exports={
|
|
|
getShareInfoMap,
|
|
getShareInfoMap,
|
|
|
getRecentShareList,
|
|
getRecentShareList,
|
|
|
getProjectShareList,
|
|
getProjectShareList,
|
|
|
|
|
+ getShareTip,
|
|
|
|
|
+ getShareState,
|
|
|
moveProject:moveProject,
|
|
moveProject:moveProject,
|
|
|
accessToCopyProject,
|
|
accessToCopyProject,
|
|
|
copyProject:copyProject,
|
|
copyProject:copyProject,
|
|
@@ -244,26 +246,65 @@ async function getRecentShareList(userID, count) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取某项目的分享记录
|
|
// 获取某项目的分享记录
|
|
|
-async function getProjectShareList(projectID) {
|
|
|
|
|
- const sharedList = await shareListModel.find({ projectID }).lean();
|
|
|
|
|
|
|
+async function getProjectShareList(projectID, limit = null) {
|
|
|
|
|
+ const sharedList = limit
|
|
|
|
|
+ ? await shareListModel.find({ projectID }).lean().sort({ shareDate: -1 }).limit(limit)
|
|
|
|
|
+ : await shareListModel.find({ projectID }).lean().sort({ shareDate: -1 });
|
|
|
const userIDs = [];
|
|
const userIDs = [];
|
|
|
const userMap = {};
|
|
const userMap = {};
|
|
|
- sharedList.forEach(item => {
|
|
|
|
|
|
|
+ sharedList.forEach((item, index) => {
|
|
|
userIDs.push(item.receiver);
|
|
userIDs.push(item.receiver);
|
|
|
userMap[item.receiver] = item;
|
|
userMap[item.receiver] = item;
|
|
|
|
|
+ userMap[item.receiver].index = index;
|
|
|
});
|
|
});
|
|
|
const userObjectIDs = userIDs.map(userID => mongoose.Types.ObjectId(userID));
|
|
const userObjectIDs = userIDs.map(userID => mongoose.Types.ObjectId(userID));
|
|
|
const users = await userModel.find({_id: {$in: userObjectIDs}}, 'real_name mobile company').lean();
|
|
const users = await userModel.find({_id: {$in: userObjectIDs}}, 'real_name mobile company').lean();
|
|
|
users.forEach(user => {
|
|
users.forEach(user => {
|
|
|
const matched = userMap[user._id];
|
|
const matched = userMap[user._id];
|
|
|
if (matched) {
|
|
if (matched) {
|
|
|
|
|
+ user.index = matched.index;
|
|
|
user.allowCopy = matched.allowCopy;
|
|
user.allowCopy = matched.allowCopy;
|
|
|
user.allowCooperate = matched.allowCooperate;
|
|
user.allowCooperate = matched.allowCooperate;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ users.sort((a, b) => a.index - b.index);
|
|
|
return users;
|
|
return users;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 获取分享的提示(造价书分享按钮tooltip使用)
|
|
|
|
|
+async function getShareTip(projectID, limit) {
|
|
|
|
|
+ const task = [
|
|
|
|
|
+ getProjectShareList(projectID, limit),
|
|
|
|
|
+ shareListModel.count({ projectID })
|
|
|
|
|
+ ];
|
|
|
|
|
+ const [users, count] = await Promise.all(task);
|
|
|
|
|
+ return users.reduce((acc, user, index) => {
|
|
|
|
|
+ if (index === 0) {
|
|
|
|
|
+ acc += '已分享给';
|
|
|
|
|
+ acc += user.real_name;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ acc += ` ${user.real_name}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (index === users.length - 1 && count > limit) {
|
|
|
|
|
+ acc += `等${count}人`;
|
|
|
|
|
+ }
|
|
|
|
|
+ return acc;
|
|
|
|
|
+ }, '');
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 获取项目的分享状态
|
|
|
|
|
+// 分享项目的拷贝和编辑性,需要参考父项
|
|
|
|
|
+// 以项目链上最新更新的分享数据为准
|
|
|
|
|
+async function getShareState(projectID, receiver) {
|
|
|
|
|
+ const projectIDs = await getUpChainIDs(projectID);
|
|
|
|
|
+ const shareList = await shareListModel.find({ projectID: { $in: projectIDs }, receiver }).lean();
|
|
|
|
|
+ shareList.sort((a, b) => Date.parse(b.updateDate) - Date.parse(a.updateDate));
|
|
|
|
|
+ return {
|
|
|
|
|
+ allowCopy: shareList[0] && shareList[0].allowCopy || false,
|
|
|
|
|
+ allowCooperate: shareList[0] && shareList[0].allowCooperate || false
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
//拷贝例题项目
|
|
//拷贝例题项目
|
|
|
//@param {String}userID {Array}projIDs拷贝的例题项目ID(建设项目、文件夹)@return {Boolean}
|
|
//@param {String}userID {Array}projIDs拷贝的例题项目ID(建设项目、文件夹)@return {Boolean}
|
|
|
async function copyExample(userID, compilation, projIDs){
|
|
async function copyExample(userID, compilation, projIDs){
|