- 将 Python 代码移至 analyzer/ 目录(含 venv) - 拆分 Go 服务器代码为模块化结构: - config/: 配置加载 - model/: 请求/响应模型 - service/: 业务逻辑 - handler/: API处理器 - 添加 .gitignore 文件 - 删除旧的独立脚本文件
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
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,
|
|
},
|
|
})
|
|
}
|
|
|