package handler import ( "net/http" "os" "path/filepath" "strings" "github.com/gin-gonic/gin" "billai-server/config" "billai-server/model" "billai-server/service" ) // Review 获取需要复核的记录 func Review(c *gin.Context) { // 获取文件名参数 fileName := c.Query("file") if fileName == "" { c.JSON(http.StatusBadRequest, model.ReviewResponse{ Result: false, Message: "请提供文件名参数 (file)", }) return } // 构建文件路径 outputDirAbs := config.ResolvePath(config.Global.OutputDir) filePath := filepath.Join(outputDirAbs, fileName) // 检查文件是否存在 if _, err := os.Stat(filePath); os.IsNotExist(err) { c.JSON(http.StatusNotFound, model.ReviewResponse{ Result: false, Message: "文件不存在: " + fileName, }) return } // 判断文件格式 format := "csv" if strings.HasSuffix(fileName, ".json") { format = "json" } // 提取需要复核的记录 records := service.ExtractNeedsReview(filePath, format) // 统计高低优先级数量 highCount := 0 lowCount := 0 for _, r := range records { if r.ReviewLevel == "HIGH" { highCount++ } else if r.ReviewLevel == "LOW" { lowCount++ } } c.JSON(http.StatusOK, model.ReviewResponse{ Result: true, Message: "获取成功", Data: &model.ReviewData{ Total: len(records), High: highCount, Low: lowCount, Records: records, }, }) }