2026-04-14 13:47:38 +08:00
|
|
|
|
package com.label.controller;
|
2026-04-09 15:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
import com.label.common.result.PageResult;
|
|
|
|
|
|
import com.label.common.result.Result;
|
|
|
|
|
|
import com.label.common.shiro.TokenPrincipal;
|
2026-04-14 13:39:24 +08:00
|
|
|
|
import com.label.entity.TrainingDataset;
|
|
|
|
|
|
import com.label.entity.ExportBatch;
|
2026-04-14 13:45:15 +08:00
|
|
|
|
import com.label.service.ExportService;
|
|
|
|
|
|
import com.label.service.FinetuneService;
|
2026-04-12 00:15:59 +08:00
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2026-04-09 15:43:45 +08:00
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* 训练数据导出与微调接口(5 个端点,全部 ADMIN 权限)。
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Tag(name = "导出管理", description = "训练样本查询、导出批次和微调任务")
|
2026-04-09 15:43:45 +08:00
|
|
|
|
@RestController
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
|
public class ExportController {
|
|
|
|
|
|
|
|
|
|
|
|
private final ExportService exportService;
|
|
|
|
|
|
private final FinetuneService finetuneService;
|
|
|
|
|
|
|
2026-04-14 13:31:50 +08:00
|
|
|
|
/** GET /api/training/samples — 分页查询已审批可导出样本 */
|
|
|
|
|
|
@Operation(summary = "分页查询可导出训练样本")
|
2026-04-09 15:43:45 +08:00
|
|
|
|
@GetMapping("/api/training/samples")
|
|
|
|
|
|
@RequiresRoles("ADMIN")
|
|
|
|
|
|
public Result<PageResult<TrainingDataset>> listSamples(
|
|
|
|
|
|
@RequestParam(defaultValue = "1") int page,
|
|
|
|
|
|
@RequestParam(defaultValue = "20") int pageSize,
|
|
|
|
|
|
@RequestParam(required = false) String sampleType,
|
|
|
|
|
|
@RequestParam(required = false) Boolean exported,
|
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
return Result.success(exportService.listSamples(page, pageSize, sampleType, exported, principal(request)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-14 13:31:50 +08:00
|
|
|
|
/** POST /api/export/batch — 创建导出批次 */
|
|
|
|
|
|
@Operation(summary = "创建导出批次")
|
2026-04-09 15:43:45 +08:00
|
|
|
|
@PostMapping("/api/export/batch")
|
|
|
|
|
|
@RequiresRoles("ADMIN")
|
|
|
|
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
|
|
|
|
public Result<ExportBatch> createBatch(@RequestBody Map<String, Object> body,
|
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
List<Object> rawIds = (List<Object>) body.get("sampleIds");
|
|
|
|
|
|
List<Long> sampleIds = rawIds.stream()
|
|
|
|
|
|
.map(id -> Long.parseLong(id.toString()))
|
|
|
|
|
|
.toList();
|
|
|
|
|
|
return Result.success(exportService.createBatch(sampleIds, principal(request)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-14 13:31:50 +08:00
|
|
|
|
/** POST /api/export/{batchId}/finetune — 提交微调任务 */
|
|
|
|
|
|
@Operation(summary = "提交微调任务")
|
2026-04-09 15:43:45 +08:00
|
|
|
|
@PostMapping("/api/export/{batchId}/finetune")
|
|
|
|
|
|
@RequiresRoles("ADMIN")
|
|
|
|
|
|
public Result<Map<String, Object>> triggerFinetune(@PathVariable Long batchId,
|
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
return Result.success(finetuneService.trigger(batchId, principal(request)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-14 13:31:50 +08:00
|
|
|
|
/** GET /api/export/{batchId}/status — 查询微调状态 */
|
|
|
|
|
|
@Operation(summary = "查询微调状态")
|
2026-04-09 15:43:45 +08:00
|
|
|
|
@GetMapping("/api/export/{batchId}/status")
|
|
|
|
|
|
@RequiresRoles("ADMIN")
|
|
|
|
|
|
public Result<Map<String, Object>> getFinetuneStatus(@PathVariable Long batchId,
|
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
return Result.success(finetuneService.getStatus(batchId, principal(request)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-14 13:31:50 +08:00
|
|
|
|
/** GET /api/export/list — 分页查询导出批次列表 */
|
|
|
|
|
|
@Operation(summary = "分页查询导出批次")
|
2026-04-09 15:43:45 +08:00
|
|
|
|
@GetMapping("/api/export/list")
|
|
|
|
|
|
@RequiresRoles("ADMIN")
|
|
|
|
|
|
public Result<PageResult<ExportBatch>> listBatches(
|
|
|
|
|
|
@RequestParam(defaultValue = "1") int page,
|
|
|
|
|
|
@RequestParam(defaultValue = "20") int pageSize,
|
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
return Result.success(exportService.listBatches(page, pageSize, principal(request)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TokenPrincipal principal(HttpServletRequest request) {
|
|
|
|
|
|
return (TokenPrincipal) request.getAttribute("__token_principal__");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|