Skip to content

Commit a7f7189

Browse files
committed
fix: 修复文档状态无法过滤 (#1800)
(cherry picked from commit aa94f66)
1 parent 87f3c88 commit a7f7189

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

apps/dataset/serializers/document_serializers.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
delete_embedding_by_document, update_embedding_dataset_id, delete_embedding_by_paragraph_ids, \
5757
embedding_by_document_list
5858
from smartdoc.conf import PROJECT_DIR
59-
from django.db import models
6059

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

369369
def get_query_set(self):
@@ -375,8 +375,22 @@ def get_query_set(self):
375375
query_set = query_set.filter(**{'hit_handling_method': self.data.get('hit_handling_method')})
376376
if 'is_active' in self.data and self.data.get('is_active') is not None:
377377
query_set = query_set.filter(**{'is_active': self.data.get('is_active')})
378-
if 'status' in self.data and self.data.get('status') is not None:
379-
query_set = query_set.filter(**{'status': self.data.get('status')})
378+
if 'status' in self.data and self.data.get(
379+
'status') is not None:
380+
task_type = self.data.get('task_type')
381+
status = self.data.get(
382+
'status')
383+
if task_type is not None:
384+
query_set = query_set.annotate(
385+
reversed_status=Reverse('status'),
386+
task_type_status=Substr('reversed_status', TaskType(task_type).value,
387+
TaskType(task_type).value),
388+
).filter(task_type_status__in=[State(status).value]).values('id')
389+
else:
390+
if status != State.SUCCESS.value:
391+
query_set = query_set.filter(status__icontains=status)
392+
else:
393+
query_set = query_set.filter(status__iregex='^[2n]*$')
380394
query_set = query_set.order_by('-create_time', 'id')
381395
return query_set
382396

ui/src/views/document/index.vue

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,33 +99,43 @@
9999
>全部</el-dropdown-item
100100
>
101101
<el-dropdown-item
102-
:class="filterMethod['status'] === '1' ? 'is-active' : ''"
102+
:class="filterMethod['status'] === State.SUCCESS ? 'is-active' : ''"
103103
class="justify-center"
104-
:command="beforeCommand('status', '1')"
104+
:command="beforeCommand('status', State.SUCCESS)"
105105
>成功</el-dropdown-item
106106
>
107107
<el-dropdown-item
108-
:class="filterMethod['status'] === '2' ? 'is-active' : ''"
108+
:class="filterMethod['status'] === State.FAILURE ? 'is-active' : ''"
109109
class="justify-center"
110-
:command="beforeCommand('status', '2')"
110+
:command="beforeCommand('status', State.FAILURE)"
111111
>失败</el-dropdown-item
112112
>
113113
<el-dropdown-item
114-
:class="filterMethod['status'] === '0' ? 'is-active' : ''"
114+
:class="
115+
filterMethod['status'] === State.STARTED &&
116+
filterMethod['task_type'] == TaskType.EMBEDDING
117+
? 'is-active'
118+
: ''
119+
"
115120
class="justify-center"
116-
:command="beforeCommand('status', '0')"
121+
:command="beforeCommand('status', State.STARTED, TaskType.EMBEDDING)"
117122
>索引中</el-dropdown-item
118123
>
119124
<el-dropdown-item
120-
:class="filterMethod['status'] === '3' ? 'is-active' : ''"
125+
:class="filterMethod['status'] === State.PENDING ? 'is-active' : ''"
121126
class="justify-center"
122-
:command="beforeCommand('status', '3')"
127+
:command="beforeCommand('status', State.PENDING)"
123128
>排队中</el-dropdown-item
124129
>
125130
<el-dropdown-item
126-
:class="filterMethod['status'] === '4' ? 'is-active' : ''"
131+
:class="
132+
filterMethod['status'] === State.STARTED &&
133+
filterMethod['task_type'] === TaskType.GENERATE_PROBLEM
134+
? 'is-active'
135+
: ''
136+
"
127137
class="justify-center"
128-
:command="beforeCommand('status', '4')"
138+
:command="beforeCommand('status', State.STARTED, TaskType.GENERATE_PROBLEM)"
129139
>生成问题中</el-dropdown-item
130140
>
131141
</el-dropdown-menu>
@@ -481,13 +491,18 @@ function openDatasetDialog(row?: any) {
481491
482492
function dropdownHandle(obj: any) {
483493
filterMethod.value[obj.attr] = obj.command
494+
if (obj.attr == 'status') {
495+
filterMethod.value['task_type'] = obj.task_type
496+
}
497+
484498
getList()
485499
}
486500
487-
function beforeCommand(attr: string, val: any) {
501+
function beforeCommand(attr: string, val: any, task_type?: number) {
488502
return {
489503
attr: attr,
490-
command: val
504+
command: val,
505+
task_type
491506
}
492507
}
493508
const cancelTask = (row: any, task_type: number) => {

0 commit comments

Comments
 (0)