GenerateQuestionsAndSummary godoc @Summary 生成问题和简介 @Description 为指定文件生成相关问题和简介,使用 GenerateQuestionsAndSummaryPipeline 流水线处理 @Tags 文件管理 @Accept json @Produce json @Security BearerAuth @Param file_id path int true "文件ID" @Success 200 {object} model.CommonResponse{data=model.RagJob} "任务创建成功,返回任务信息" @Fa
(c *gin.Context)
| 2262 | // @Failure 500 {object} model.CommonResponse "服务器内部错误" |
| 2263 | // @Router /api/files/{file_id}/generate-questions-and-summary [post] |
| 2264 | func GenerateQuestionsAndSummary(c *gin.Context) { |
| 2265 | eid := config.GetEID(c) |
| 2266 | userID := config.GetUserId(c) |
| 2267 | |
| 2268 | // 获取文件ID |
| 2269 | fileIDStr := c.Param("file_id") |
| 2270 | if fileIDStr == "" { |
| 2271 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("文件ID不能为空"))) |
| 2272 | return |
| 2273 | } |
| 2274 | |
| 2275 | fileID, err := strconv.ParseInt(fileIDStr, 10, 64) |
| 2276 | if err != nil { |
| 2277 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("无效的文件ID"))) |
| 2278 | return |
| 2279 | } |
| 2280 | |
| 2281 | // 验证文件是否存在 |
| 2282 | file, err := model.GetFileByID(eid, fileID) |
| 2283 | if err != nil { |
| 2284 | c.JSON(http.StatusNotFound, model.NotFound.ToResponse(errors.New("文件不存在"))) |
| 2285 | return |
| 2286 | } |
| 2287 | |
| 2288 | // 检查用户是否有权限访问该文件 |
| 2289 | permission, err := service.GetUserPermission(eid, model.RESOURCE_TYPE_FILE, fileID, userID) |
| 2290 | if err != nil || permission < model.PERMISSION_VIEW_ONLY { |
| 2291 | c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(errors.New("没有权限访问该文件"))) |
| 2292 | return |
| 2293 | } |
| 2294 | |
| 2295 | // 1. 幂等检查:已有任务或已有结果则直接返回 |
| 2296 | jobTypes := []string{"summary_generation", "generate_questions_and_summary"} |
| 2297 | var existingJob model.RagJob |
| 2298 | if err := model.DB.Where("eid = ? AND related_id = ? AND type IN ?", |
| 2299 | eid, fileID, jobTypes).Order("job_id DESC").First(&existingJob).Error; err == nil { |
| 2300 | if existingJob.Status == model.RagJobStatusPending || existingJob.Status == model.RagJobStatusProcessing { |
| 2301 | c.JSON(http.StatusOK, model.Success.ToResponse(existingJob)) |
| 2302 | return |
| 2303 | } |
| 2304 | if existingJob.Status == model.RagJobStatusSuccess { |
| 2305 | c.JSON(http.StatusOK, model.Success.ToResponse(existingJob)) |
| 2306 | return |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | // 文件已生成成功,直接返回(避免重复创建任务) |
| 2311 | if file.AIGenerateSQStatus == model.AIGenerateSQStatusNormal && |
| 2312 | (strings.TrimSpace(file.Summary) != "" || strings.TrimSpace(file.Questions) != "" || strings.TrimSpace(file.KnowledgeMap) != "") { |
| 2313 | c.JSON(http.StatusOK, model.Success.ToResponse(model.RagJob{ |
| 2314 | Eid: eid, |
| 2315 | Type: "summary_generation", |
| 2316 | Status: model.RagJobStatusSuccess, |
| 2317 | RelatedId: fileID, |
| 2318 | })) |
| 2319 | return |
| 2320 | } |
| 2321 |
nothing calls this directly
no test coverage detected