|
@@ -53,18 +53,20 @@ export class ChatService extends BaseService<modelType> {
|
|
const query = { doctor };
|
|
const query = { doctor };
|
|
pipes.push({ $match: query });
|
|
pipes.push({ $match: query });
|
|
pipes.push({ $sort: { 'meta.createdAt': -1 } });
|
|
pipes.push({ $sort: { 'meta.createdAt': -1 } });
|
|
|
|
+ // 如果speaker等于patient,说明这是患者讲的话,是否未读的状态是算医护上的;如果不是患者讲的,那就不算了
|
|
|
|
+ pipes.push({
|
|
|
|
+ $addFields: { countDot: { $cond: { if: { $eq: ['$speaker', '$patient'] }, then: '$not_read', else: 0 } } },
|
|
|
|
+ });
|
|
pipes.push({
|
|
pipes.push({
|
|
$group: {
|
|
$group: {
|
|
_id: '$patient',
|
|
_id: '$patient',
|
|
l: { $first: '$$ROOT' },
|
|
l: { $first: '$$ROOT' },
|
|
- notRead: { $sum: '$$ROOT.not_read' },
|
|
|
|
|
|
+ notRead: { $sum: '$countDot' },
|
|
},
|
|
},
|
|
});
|
|
});
|
|
// 将notRead结果放到l里,之后替换根变量
|
|
// 将notRead结果放到l里,之后替换根变量
|
|
pipes.push({ $addFields: { 'l.gid': { $toObjectId: '$l.group' }, 'l.pid': { $toObjectId: '$l.patient' }, 'l.did': { $toObjectId: '$l.doctor' }, 'l.notRead': '$notRead' } });
|
|
pipes.push({ $addFields: { 'l.gid': { $toObjectId: '$l.group' }, 'l.pid': { $toObjectId: '$l.patient' }, 'l.did': { $toObjectId: '$l.doctor' }, 'l.notRead': '$notRead' } });
|
|
pipes.push({ $replaceRoot: { newRoot: '$l' } });
|
|
pipes.push({ $replaceRoot: { newRoot: '$l' } });
|
|
- // 查询总数
|
|
|
|
-
|
|
|
|
pipes.push({
|
|
pipes.push({
|
|
$lookup: {
|
|
$lookup: {
|
|
from: 'group',
|
|
from: 'group',
|
|
@@ -96,10 +98,12 @@ export class ChatService extends BaseService<modelType> {
|
|
pipes.push({ $match: { 'pInfo.name': new RegExp(name) } });
|
|
pipes.push({ $match: { 'pInfo.name': new RegExp(name) } });
|
|
}
|
|
}
|
|
pipes.push({ $project: this.lastChatRecordListItem });
|
|
pipes.push({ $project: this.lastChatRecordListItem });
|
|
|
|
+ // 查询总数
|
|
const totalResult = await this.model.aggregate([...pipes, { $count: 'total' }]);
|
|
const totalResult = await this.model.aggregate([...pipes, { $count: 'total' }]);
|
|
if (skip && skip >= 0) pipes.push({ $skip: skip });
|
|
if (skip && skip >= 0) pipes.push({ $skip: skip });
|
|
if (limit && limit > 0) pipes.push({ $limit: limit });
|
|
if (limit && limit > 0) pipes.push({ $limit: limit });
|
|
const result = await this.model.aggregate(pipes);
|
|
const result = await this.model.aggregate(pipes);
|
|
- return { data: result, total: get(head(totalResult), 'total') };
|
|
|
|
|
|
+ // return { data: result, total: get(head(totalResult), 'total') };
|
|
|
|
+ return { data: result, total: 0 };
|
|
}
|
|
}
|
|
}
|
|
}
|