Some checks are pending
Deploy BillAI / Deploy to Production (push) Waiting to run
- 将删除接口从 DELETE /api/bills/:id 改为 POST /api/bills/:id/delete 以兼容 SvelteKit 代理 - 分析页面组件 (TopExpenses/BillRecordsTable/DailyTrendChart) 支持删除并同步更新统计数据 - Review 接口改为直接查询 MongoDB 而非读取文件 - 软删除时记录 updated_at 时间戳 - 添加 .dockerignore 文件优化构建 - 完善 AGENTS.md 文档
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"billai-server/model"
|
|
"billai-server/repository"
|
|
)
|
|
|
|
// Review 获取需要复核的记录
|
|
func Review(c *gin.Context) {
|
|
// 获取数据
|
|
repo := repository.GetRepository()
|
|
if repo == nil {
|
|
c.JSON(http.StatusInternalServerError, model.ReviewResponse{
|
|
Result: false,
|
|
Message: "数据库未连接",
|
|
})
|
|
return
|
|
}
|
|
|
|
// 从MongoDB查询所有需要复核的账单
|
|
bills, err := repo.GetBillsNeedReview()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.ReviewResponse{
|
|
Result: false,
|
|
Message: "查询失败: " + err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// 统计高低优先级数量并转换为 ReviewRecord
|
|
highCount := 0
|
|
lowCount := 0
|
|
records := make([]model.ReviewRecord, 0, len(bills))
|
|
|
|
for _, bill := range bills {
|
|
if bill.ReviewLevel == "HIGH" {
|
|
highCount++
|
|
} else if bill.ReviewLevel == "LOW" {
|
|
lowCount++
|
|
}
|
|
|
|
records = append(records, model.ReviewRecord{
|
|
Time: bill.Time.Time().Format("2006-01-02 15:04:05"),
|
|
Category: bill.Category,
|
|
Merchant: bill.Merchant,
|
|
Description: bill.Description,
|
|
IncomeExpense: bill.IncomeExpense,
|
|
Amount: fmt.Sprintf("%.2f", bill.Amount),
|
|
Remark: bill.Remark,
|
|
ReviewLevel: bill.ReviewLevel,
|
|
})
|
|
}
|
|
|
|
c.JSON(http.StatusOK, model.ReviewResponse{
|
|
Result: true,
|
|
Message: "获取成功",
|
|
Data: &model.ReviewData{
|
|
Total: len(records),
|
|
High: highCount,
|
|
Low: lowCount,
|
|
Records: records,
|
|
},
|
|
})
|
|
}
|