Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复文档状态无法过滤 #1800

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions apps/dataset/serializers/document_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
delete_embedding_by_document, update_embedding_dataset_id, delete_embedding_by_paragraph_ids, \
embedding_by_document_list
from smartdoc.conf import PROJECT_DIR
from django.db import models

parse_qa_handle_list = [XlsParseQAHandle(), CsvParseQAHandle(), XlsxParseQAHandle()]
parse_table_handle_list = [CsvSplitHandle(), XlsSplitHandle(), XlsxSplitHandle()]
Expand Down Expand Up @@ -364,6 +363,7 @@ class Query(ApiMixin, serializers.Serializer):
"文档名称"))
hit_handling_method = serializers.CharField(required=False, error_messages=ErrMessage.char("命中处理方式"))
is_active = serializers.BooleanField(required=False, error_messages=ErrMessage.boolean("文档是否可用"))
task_type = serializers.IntegerField(required=False, error_messages=ErrMessage.integer("任务类型"))
status = serializers.CharField(required=False, error_messages=ErrMessage.char("文档状态"))

def get_query_set(self):
Expand All @@ -375,8 +375,22 @@ def get_query_set(self):
query_set = query_set.filter(**{'hit_handling_method': self.data.get('hit_handling_method')})
if 'is_active' in self.data and self.data.get('is_active') is not None:
query_set = query_set.filter(**{'is_active': self.data.get('is_active')})
if 'status' in self.data and self.data.get('status') is not None:
query_set = query_set.filter(**{'status': self.data.get('status')})
if 'status' in self.data and self.data.get(
'status') is not None:
task_type = self.data.get('task_type')
status = self.data.get(
'status')
if task_type is not None:
query_set = query_set.annotate(
reversed_status=Reverse('status'),
task_type_status=Substr('reversed_status', TaskType(task_type).value,
TaskType(task_type).value),
).filter(task_type_status__in=[State(status).value]).values('id')
else:
if status != State.SUCCESS.value:
query_set = query_set.filter(status__icontains=status)
else:
query_set = query_set.filter(status__iregex='^[2n]*$')
query_set = query_set.order_by('-create_time', 'id')
return query_set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该段话没有给出任何代码修改,因此无法判断是否有问题和需要改进的地方。

Expand Down
39 changes: 27 additions & 12 deletions ui/src/views/document/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,43 @@
>全部</el-dropdown-item
>
<el-dropdown-item
:class="filterMethod['status'] === '1' ? 'is-active' : ''"
:class="filterMethod['status'] === State.SUCCESS ? 'is-active' : ''"
class="justify-center"
:command="beforeCommand('status', '1')"
:command="beforeCommand('status', State.SUCCESS)"
>成功</el-dropdown-item
>
<el-dropdown-item
:class="filterMethod['status'] === '2' ? 'is-active' : ''"
:class="filterMethod['status'] === State.FAILURE ? 'is-active' : ''"
class="justify-center"
:command="beforeCommand('status', '2')"
:command="beforeCommand('status', State.FAILURE)"
>失败</el-dropdown-item
>
<el-dropdown-item
:class="filterMethod['status'] === '0' ? 'is-active' : ''"
:class="
filterMethod['status'] === State.STARTED &&
filterMethod['task_type'] == TaskType.EMBEDDING
? 'is-active'
: ''
"
class="justify-center"
:command="beforeCommand('status', '0')"
:command="beforeCommand('status', State.STARTED, TaskType.EMBEDDING)"
>索引中</el-dropdown-item
>
<el-dropdown-item
:class="filterMethod['status'] === '3' ? 'is-active' : ''"
:class="filterMethod['status'] === State.PENDING ? 'is-active' : ''"
class="justify-center"
:command="beforeCommand('status', '3')"
:command="beforeCommand('status', State.PENDING)"
>排队中</el-dropdown-item
>
<el-dropdown-item
:class="filterMethod['status'] === '4' ? 'is-active' : ''"
:class="
filterMethod['status'] === State.STARTED &&
filterMethod['task_type'] === TaskType.GENERATE_PROBLEM
? 'is-active'
: ''
"
class="justify-center"
:command="beforeCommand('status', '4')"
:command="beforeCommand('status', State.STARTED, TaskType.GENERATE_PROBLEM)"
>生成问题中</el-dropdown-item
>
</el-dropdown-menu>
Expand Down Expand Up @@ -481,13 +491,18 @@ function openDatasetDialog(row?: any) {

function dropdownHandle(obj: any) {
filterMethod.value[obj.attr] = obj.command
if (obj.attr == 'status') {
filterMethod.value['task_type'] = obj.task_type
}

getList()
}

function beforeCommand(attr: string, val: any) {
function beforeCommand(attr: string, val: any, task_type?: number) {
return {
attr: attr,
command: val
command: val,
task_type
}
}
const cancelTask = (row: any, task_type: number) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此段代码没有发现明显的错误或不规范的地方。如果需要对代码做一些调整来满足特定的要求,可以根据具体需求进行微调。例如根据任务类型动态计算状态值等。

Expand Down
Loading