From 4271fd0f6de87fd0ef631db08a8a1ac0d4ec48fa Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:17:36 +0800 Subject: [PATCH] =?UTF-8?q?*=20feat:=20=E6=B7=BB=E5=8A=A0=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E8=AE=B0=E5=BD=95=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=8F=8A=E5=8A=9F=E8=83=BD=20#548?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0008_chat_is_deleted.py | 18 +++++++++++++ apps/application/models/application.py | 1 + .../serializers/chat_serializers.py | 10 ++++++- apps/application/urls.py | 2 ++ apps/application/views/chat_views.py | 19 ++++++++++++++ ui/src/api/log.ts | 15 ++++++++++- ui/src/components/ai-chat/index.vue | 1 - ui/src/stores/modules/log.ts | 12 +++++++++ ui/src/views/chat/embed/index.vue | 25 +++++++++++++++--- ui/src/views/chat/pc/index.vue | 26 ++++++++++++++++--- 10 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 apps/application/migrations/0008_chat_is_deleted.py diff --git a/apps/application/migrations/0008_chat_is_deleted.py b/apps/application/migrations/0008_chat_is_deleted.py new file mode 100644 index 000000000..5291c3f54 --- /dev/null +++ b/apps/application/migrations/0008_chat_is_deleted.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.13 on 2024-06-13 11:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('application', '0007_alter_application_prologue'), + ] + + operations = [ + migrations.AddField( + model_name='chat', + name='is_deleted', + field=models.BooleanField(default=False, verbose_name=''), + ), + ] diff --git a/apps/application/models/application.py b/apps/application/models/application.py index e0fb83e77..073e980c7 100644 --- a/apps/application/models/application.py +++ b/apps/application/models/application.py @@ -75,6 +75,7 @@ class Chat(AppModelMixin): application = models.ForeignKey(Application, on_delete=models.CASCADE) abstract = models.CharField(max_length=1024, verbose_name="摘要") client_id = models.UUIDField(verbose_name="客户端id", default=None, null=True) + is_deleted = models.BooleanField(verbose_name="", default=False) class Meta: db_table = "application_chat" diff --git a/apps/application/serializers/chat_serializers.py b/apps/application/serializers/chat_serializers.py index 3af6b0624..a0d0b7690 100644 --- a/apps/application/serializers/chat_serializers.py +++ b/apps/application/serializers/chat_serializers.py @@ -50,6 +50,13 @@ class ChatSerializers(serializers.Serializer): chat_id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("对话id")) application_id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("应用id")) + def logic_delete(self, with_valid=True): + if with_valid: + self.is_valid(raise_exception=True) + QuerySet(Chat).filter(id=self.data.get('chat_id'), application_id=self.data.get('application_id')).update( + is_deleted=True) + return True + def delete(self, with_valid=True): if with_valid: self.is_valid(raise_exception=True) @@ -64,7 +71,8 @@ class ChatSerializers(serializers.Serializer): if with_valid: self.is_valid(raise_exception=True) queryset = QuerySet(Chat).filter(client_id=self.data.get('client_id'), - application_id=self.data.get('application_id')) + application_id=self.data.get('application_id'), + is_deleted=False) queryset = queryset.order_by('-create_time') return page_search(current_page, page_size, queryset, lambda row: ChatSerializerModel(row).data) diff --git a/apps/application/urls.py b/apps/application/urls.py index 7c3b4ea6c..4fcbbbf0c 100644 --- a/apps/application/urls.py +++ b/apps/application/urls.py @@ -32,6 +32,8 @@ urlpatterns = [ path("application/chat/open", views.ChatView.OpenTemp.as_view()), path("application//chat/client//", views.ChatView.ClientChatHistoryPage.as_view()), + path("application//chat/client/", + views.ChatView.ClientChatHistoryPage.Operate.as_view()), path('application//chat/export', views.ChatView.Export.as_view(), name='export'), path('application//chat', views.ChatView.as_view(), name='chats'), path('application//chat//', views.ChatView.Page.as_view()), diff --git a/apps/application/views/chat_views.py b/apps/application/views/chat_views.py index 3bae2b877..b7f5968f2 100644 --- a/apps/application/views/chat_views.py +++ b/apps/application/views/chat_views.py @@ -160,6 +160,25 @@ class ChatView(APIView): current_page=current_page, page_size=page_size)) + class Operate(APIView): + authentication_classes = [TokenAuth] + + @action(methods=['DELETE'], detail=False) + @swagger_auto_schema(operation_summary="客户端删除对话", + operation_id="客户端删除对话", + tags=["应用/对话日志"]) + @has_permissions(ViewPermission( + [RoleConstants.APPLICATION_ACCESS_TOKEN], + [lambda r, keywords: Permission(group=Group.APPLICATION, operate=Operate.USE, + dynamic_tag=keywords.get('application_id'))], + compare=CompareConstants.AND), + compare=CompareConstants.AND) + def delete(self, request: Request, application_id: str, chat_id: str): + return result.success( + ChatSerializers.Operate( + data={'application_id': application_id, 'user_id': request.user.id, + 'chat_id': chat_id}).logic_delete()) + class Page(APIView): authentication_classes = [TokenAuth] diff --git a/ui/src/api/log.ts b/ui/src/api/log.ts index 67b88ab8f..de4716a3f 100644 --- a/ui/src/api/log.ts +++ b/ui/src/api/log.ts @@ -186,6 +186,18 @@ const getChatLogClient: ( ) } +/** + * 客户端删除日志 + * @param 参数 application_id, chat_id, + */ +const delChatClientLog: ( + application_id: string, + chat_id: string, + loading?: Ref +) => Promise> = (application_id, chat_id, loading) => { + return del(`${prefix}/${application_id}/chat/client/${chat_id}`, undefined, {}, loading) +} + export default { getChatLog, delChatLog, @@ -195,5 +207,6 @@ export default { getRecordDetail, delMarkRecord, exportChatLog, - getChatLogClient + getChatLogClient, + delChatClientLog } diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index 8b1c09f7a..83f4d0107 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -96,7 +96,6 @@ plain size="small" @click="openParagraph(item)" - :disabled="!item.paragraph_list || item.paragraph_list?.length === 0" >引用分段:{{ item.paragraph_list?.length || 0 }} diff --git a/ui/src/stores/modules/log.ts b/ui/src/stores/modules/log.ts index cc08ad303..d7a8d6498 100644 --- a/ui/src/stores/modules/log.ts +++ b/ui/src/stores/modules/log.ts @@ -48,6 +48,18 @@ const useLogStore = defineStore({ reject(error) }) }) + }, + async asyncDelChatClientLog(id: string, chatId: string, loading?: Ref) { + return new Promise((resolve, reject) => { + logApi + .delChatClientLog(id, chatId, loading) + .then((data) => { + resolve(data) + }) + .catch((error) => { + reject(error) + }) + }) } } }) diff --git a/ui/src/views/chat/embed/index.vue b/ui/src/views/chat/embed/index.vue index 59b0559c5..6a2458a5c 100644 --- a/ui/src/views/chat/embed/index.vue +++ b/ui/src/views/chat/embed/index.vue @@ -45,9 +45,16 @@ @click="clickListHandle" >