Skip to content

Commit 1686f56

Browse files
authored
fix: 配比任务能够跳转到目标数据集 (#59)
* fix:配比任务需要能够跳转到目标数据集 * feature:增加配比任务详情接口 * fix:删除不存在的配比详情页面
1 parent 30d6fcd commit 1686f56

File tree

5 files changed

+122
-2
lines changed

5 files changed

+122
-2
lines changed

frontend/src/pages/RatioTask/Home/RatioTask.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export default function RatioTasksPage() {
6060
title: "任务名称",
6161
dataIndex: "name",
6262
key: "name",
63+
render: (text: string, record: RatioTaskItem) => (
64+
<a onClick={() => navigate(`/data/synthesis/ratio-task/detail/${record.id}`)}>{text}</a>
65+
),
6366
},
6467
{
6568
title: "状态",
@@ -81,6 +84,9 @@ export default function RatioTasksPage() {
8184
title: "目标数据集",
8285
dataIndex: "target_dataset_name",
8386
key: "target_dataset_name",
87+
render: (text: string, task: RatioTaskItem) => (
88+
<a onClick={() => navigate(`/data/management/detail/${task.target_dataset_id}`)}>{text}</a>
89+
),
8490
},
8591
{
8692
title: "创建时间",
@@ -173,6 +179,17 @@ export default function RatioTasksPage() {
173179
label: "目标数量",
174180
value: (task.totals ?? 0).toLocaleString(),
175181
},
182+
{
183+
label: "目标数据集",
184+
value: task.target_dataset_name ? (
185+
<a onClick={(e) => {
186+
e.stopPropagation();
187+
navigate(`/data/management/detail/${task.target_dataset_id}`);
188+
}}>
189+
{task.target_dataset_name}
190+
</a>
191+
) : '无',
192+
},
176193
{
177194
label: "创建时间",
178195
value: task.created_at || "-",
@@ -182,6 +199,7 @@ export default function RatioTasksPage() {
182199
}))}
183200
pagination={pagination}
184201
operations={operations}
202+
onView={(task) => {navigate(`/data/synthesis/ratio-task/detail/${task.id}`)}}
185203
/>
186204
);
187205

frontend/src/pages/RatioTask/ratio.api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export function queryRatioTasksUsingGet(params?: any) {
55
return get("/api/synthesis/ratio-task", params);
66
}
77

8+
// 查询配比任务详情
9+
export function getRatioTaskByIdUsingGet(id: string) {
10+
return get(`/api/synthesis/ratio-task/${id}`);
11+
}
12+
813
// 创建配比任务
914
export function createRatioTaskUsingPost(data: any) {
1015
return post("/api/synthesis/ratio-task", data);

frontend/src/pages/RatioTask/ratio.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface RatioTaskItem {
7777
ratio_method?: RatioMethod
7878
target_dataset_id?: string
7979
target_dataset_name?: string
80+
config: RatioConfigItem[]
8081
created_at?: string
8182
updated_at?: string
8283
}

runtime/datamate-python/app/module/synthesis/interface/ratio_task.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
PagedRatioTaskResponse,
1919
RatioTaskItem,
2020
TargetDatasetInfo,
21+
RatioTaskDetailResponse,
2122
)
2223
from app.module.synthesis.service.ratio_task import RatioTaskService
23-
from app.db.models.ratio_task import RatioInstance, RatioRelation
24+
from app.db.models.ratio_task import RatioInstance, RatioRelation, RatioRelation as RatioRelationModel
2425

2526
router = APIRouter(
2627
prefix="/ratio-task",
@@ -251,3 +252,78 @@ def get_target_dataset_type(source_types: Set[str]) -> str:
251252
# 仅有一种介质类型且无其它类型
252253
target_type = next(iter(media_involved))
253254
return target_type
255+
256+
257+
@router.get("/{task_id}", response_model=StandardResponse[RatioTaskDetailResponse], status_code=200)
258+
async def get_ratio_task(
259+
task_id: str,
260+
db: AsyncSession = Depends(get_db),
261+
):
262+
"""
263+
获取配比任务详情
264+
265+
Path: /api/synthesis/ratio-task/{task_id}
266+
"""
267+
try:
268+
# 查询任务实例
269+
instance_res = await db.execute(
270+
select(RatioInstance).where(RatioInstance.id == task_id)
271+
)
272+
instance = instance_res.scalar_one_or_none()
273+
if not instance:
274+
raise HTTPException(status_code=404, detail="Ratio task not found")
275+
276+
# 查询关联的配比关系
277+
relations_res = await db.execute(
278+
select(RatioRelationModel).where(RatioRelationModel.ratio_instance_id == task_id)
279+
)
280+
relations = list(relations_res.scalars().all())
281+
282+
# 查询目标数据集
283+
target_ds = None
284+
if instance.target_dataset_id:
285+
ds_res = await db.execute(
286+
select(Dataset).where(Dataset.id == instance.target_dataset_id)
287+
)
288+
target_ds = ds_res.scalar_one_or_none()
289+
290+
# 构建响应
291+
config = [
292+
{
293+
"dataset_id": rel.source_dataset_id,
294+
"counts": str(rel.counts) if rel.counts is not None else "0",
295+
"filter_conditions": rel.filter_conditions or "",
296+
}
297+
for rel in relations
298+
]
299+
300+
target_dataset_info = {
301+
"id": str(target_ds.id) if target_ds else None,
302+
"name": target_ds.name if target_ds else None,
303+
"type": target_ds.dataset_type if target_ds else None,
304+
"status": target_ds.status if target_ds else None,
305+
"file_count": target_ds.file_count if target_ds else 0,
306+
"size_bytes": target_ds.size_bytes if target_ds else 0,
307+
}
308+
309+
return StandardResponse(
310+
code=200,
311+
message="success",
312+
data=RatioTaskDetailResponse(
313+
id=instance.id,
314+
name=instance.name or "",
315+
description=instance.description,
316+
status=instance.status or "UNKNOWN",
317+
totals=instance.totals or 0,
318+
ratio_method=instance.ratio_method or "",
319+
config=config,
320+
target_dataset=target_dataset_info,
321+
created_at=instance.created_at,
322+
updated_at=instance.updated_at,
323+
)
324+
)
325+
except HTTPException:
326+
raise
327+
except Exception as e:
328+
logger.error(f"Failed to get ratio task {task_id}: {e}")
329+
raise HTTPException(status_code=500, detail="Internal server error")

runtime/datamate-python/app/module/synthesis/schema/ratio_task.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import List, Optional
1+
from typing import List, Optional, Dict, Any
2+
from datetime import datetime
23
from pydantic import BaseModel, Field, field_validator
34

45
class RatioConfigItem(BaseModel):
@@ -84,3 +85,22 @@ class PagedRatioTaskResponse(BaseModel):
8485
totalPages: int
8586
page: int
8687
size: int
88+
89+
90+
class RatioTaskDetailResponse(BaseModel):
91+
"""Detailed response for a ratio task."""
92+
id: str = Field(..., description="任务ID")
93+
name: str = Field(..., description="任务名称")
94+
description: Optional[str] = Field(None, description="任务描述")
95+
status: str = Field(..., description="任务状态")
96+
totals: int = Field(..., description="目标总数")
97+
ratio_method: str = Field(..., description="配比方式")
98+
config: List[Dict[str, Any]] = Field(..., description="配比配置")
99+
target_dataset: Dict[str, Any] = Field(..., description="目标数据集信息")
100+
created_at: Optional[datetime] = Field(None, description="创建时间")
101+
updated_at: Optional[datetime] = Field(None, description="更新时间")
102+
103+
class Config:
104+
json_encoders = {
105+
datetime: lambda v: v.isoformat() if v else None
106+
}

0 commit comments

Comments
 (0)