Commit 3a911c51 by heheer Committed by GitHub

fix chat log list api (#4700)

parent 433e7ed9
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"back_to_text": "Text input", "back_to_text": "Text input",
"chat.quote.No Data": "The file cannot be found", "chat.quote.No Data": "The file cannot be found",
"chat.quote.deleted": "This data has been deleted ~", "chat.quote.deleted": "This data has been deleted ~",
"chat.waiting_for_response": "Please wait for the conversation to complete",
"chat_history": "Conversation History", "chat_history": "Conversation History",
"chat_input_guide_lexicon_is_empty": "Lexicon not configured yet", "chat_input_guide_lexicon_is_empty": "Lexicon not configured yet",
"chat_test_app": "Debug-{{name}}", "chat_test_app": "Debug-{{name}}",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"back_to_text": "返回输入", "back_to_text": "返回输入",
"chat.quote.No Data": "找不到该文件", "chat.quote.No Data": "找不到该文件",
"chat.quote.deleted": "该数据已被删除~", "chat.quote.deleted": "该数据已被删除~",
"chat.waiting_for_response": "请等待对话完成",
"chat_history": "聊天记录", "chat_history": "聊天记录",
"chat_input_guide_lexicon_is_empty": "还没有配置词库", "chat_input_guide_lexicon_is_empty": "还没有配置词库",
"chat_test_app": "调试-{{name}}", "chat_test_app": "调试-{{name}}",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"back_to_text": "返回輸入", "back_to_text": "返回輸入",
"chat.quote.No Data": "找不到該文件", "chat.quote.No Data": "找不到該文件",
"chat.quote.deleted": "該資料已被刪除~", "chat.quote.deleted": "該資料已被刪除~",
"chat.waiting_for_response": "請等待對話完成",
"chat_history": "對話紀錄", "chat_history": "對話紀錄",
"chat_input_guide_lexicon_is_empty": "尚未設定詞彙庫", "chat_input_guide_lexicon_is_empty": "尚未設定詞彙庫",
"chat_test_app": "除錯-{{name}}", "chat_test_app": "除錯-{{name}}",
......
...@@ -28,6 +28,7 @@ import dayjs from 'dayjs'; ...@@ -28,6 +28,7 @@ import dayjs from 'dayjs';
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext'; import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
import { eventBus, EventNameEnum } from '@/web/common/utils/eventbus'; import { eventBus, EventNameEnum } from '@/web/common/utils/eventbus';
import { addStatisticalDataToHistoryItem } from '@/global/core/chat/utils'; import { addStatisticalDataToHistoryItem } from '@/global/core/chat/utils';
import { useToast } from '@fastgpt/web/hooks/useToast';
const colorMap = { const colorMap = {
[ChatStatusEnum.loading]: { [ChatStatusEnum.loading]: {
...@@ -117,6 +118,7 @@ const ChatItem = (props: Props) => { ...@@ -117,6 +118,7 @@ const ChatItem = (props: Props) => {
const { type, avatar, statusBoxData, children, isLastChild, questionGuides = [], chat } = props; const { type, avatar, statusBoxData, children, isLastChild, questionGuides = [], chat } = props;
const { isPc } = useSystem(); const { isPc } = useSystem();
const { toast } = useToast();
const styleMap: BoxProps = { const styleMap: BoxProps = {
...(type === ChatRoleEnum.Human ...(type === ChatRoleEnum.Human
...@@ -237,6 +239,11 @@ const ChatItem = (props: Props) => { ...@@ -237,6 +239,11 @@ const ChatItem = (props: Props) => {
quoteId?: string; quoteId?: string;
}) => { }) => {
if (!setQuoteData) return; if (!setQuoteData) return;
if (isChatting)
return toast({
title: t('chat:chat.waiting_for_response'),
status: 'info'
});
const collectionIdList = collectionId const collectionIdList = collectionId
? [collectionId] ? [collectionId]
...@@ -269,7 +276,18 @@ const ChatItem = (props: Props) => { ...@@ -269,7 +276,18 @@ const ChatItem = (props: Props) => {
} }
}); });
}, },
[setQuoteData, quoteList, isShowReadRawSource, appId, chatId, chat.dataId, outLinkAuthData] [
setQuoteData,
isChatting,
toast,
t,
quoteList,
isShowReadRawSource,
appId,
chatId,
chat.dataId,
outLinkAuthData
]
); );
useEffect(() => { useEffect(() => {
......
...@@ -57,9 +57,6 @@ async function handler( ...@@ -57,9 +57,6 @@ async function handler(
{ $match: where }, { $match: where },
{ {
$sort: { $sort: {
userBadFeedbackCount: -1,
userGoodFeedbackCount: -1,
customFeedbacksCount: -1,
updateTime: -1 updateTime: -1
} }
}, },
...@@ -68,68 +65,117 @@ async function handler( ...@@ -68,68 +65,117 @@ async function handler(
{ {
$lookup: { $lookup: {
from: ChatItemCollectionName, from: ChatItemCollectionName,
let: { chatId: '$chatId' }, let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
pipeline: [ pipeline: [
{ {
$match: { $match: {
$expr: { $expr: {
$and: [ $and: [{ $eq: ['$appId', '$$appId'] }, { $eq: ['$chatId', '$$chatId'] }]
{ $eq: ['$appId', new Types.ObjectId(appId)] },
{ $eq: ['$chatId', '$$chatId'] }
]
} }
} }
}, },
{ $count: 'messageCount' }
],
as: 'messageCountData'
}
},
{ {
$project: { $lookup: {
userGoodFeedback: 1, from: ChatItemCollectionName,
userBadFeedback: 1, let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
customFeedbacks: 1, pipeline: [
adminFeedback: 1 {
$match: {
$expr: {
$and: [
{ $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] },
{ $eq: ['$userGoodFeedback', true] }
]
} }
} }
},
{ $count: 'count' }
], ],
as: 'chatitems' as: 'userGoodFeedbackData'
} }
}, },
{ {
$addFields: { $lookup: {
userGoodFeedbackCount: { from: ChatItemCollectionName,
$size: { let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
$filter: { pipeline: [
input: '$chatitems', {
as: 'item', $match: {
cond: { $ifNull: ['$$item.userGoodFeedback', false] } $expr: {
$and: [
{ $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] },
{ $eq: ['$userBadFeedback', true] }
]
} }
} }
}, },
userBadFeedbackCount: { { $count: 'count' }
$size: { ],
$filter: { as: 'userBadFeedbackData'
input: '$chatitems',
as: 'item',
cond: { $ifNull: ['$$item.userBadFeedback', false] }
}
} }
}, },
customFeedbacksCount: { {
$size: { $lookup: {
$filter: { from: ChatItemCollectionName,
input: '$chatitems', let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
as: 'item', pipeline: [
cond: { $gt: [{ $size: { $ifNull: ['$$item.customFeedbacks', []] } }, 0] } {
$match: {
$expr: {
$and: [
{ $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] },
{ $gt: [{ $size: { $ifNull: ['$customFeedbacks', []] } }, 0] }
]
} }
} }
}, },
markCount: { { $count: 'count' }
$size: { ],
$filter: { as: 'customFeedbacksData'
input: '$chatitems', }
as: 'item', },
cond: { $ifNull: ['$$item.adminFeedback', false] } {
$lookup: {
from: ChatItemCollectionName,
let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] },
{ $eq: ['$adminFeedback', true] }
]
} }
} }
},
{ $count: 'count' }
],
as: 'markData'
} }
},
{
$addFields: {
userGoodFeedbackCount: {
$ifNull: [{ $arrayElemAt: ['$userGoodFeedbackData.count', 0] }, 0]
},
userBadFeedbackCount: {
$ifNull: [{ $arrayElemAt: ['$userBadFeedbackData.count', 0] }, 0]
},
customFeedbacksCount: {
$ifNull: [{ $arrayElemAt: ['$customFeedbacksData.count', 0] }, 0]
},
markCount: { $ifNull: [{ $arrayElemAt: ['$markData.count', 0] }, 0] },
messageCount: { $ifNull: [{ $arrayElemAt: ['$messageCountData.messageCount', 0] }, 0] }
} }
}, },
{ {
...@@ -141,7 +187,7 @@ async function handler( ...@@ -141,7 +187,7 @@ async function handler(
source: 1, source: 1,
sourceName: 1, sourceName: 1,
time: '$updateTime', time: '$updateTime',
messageCount: { $size: '$chatitems' }, messageCount: 1,
userGoodFeedbackCount: 1, userGoodFeedbackCount: 1,
userBadFeedbackCount: 1, userBadFeedbackCount: 1,
customFeedbacksCount: 1, customFeedbacksCount: 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment