Files
billai/server/router/router.go
clz 02de11caac feat: 新增账单导出 Excel 功能
- 后端新增 /api/bills/export 接口,支持当前筛选条件导出全部记录
- 使用 excelize 库生成 xlsx 格式文件
- 前端账单管理页面添加导出按钮
- 更新 Go 版本到 1.24 以支持 excelize 依赖
2026-03-23 19:16:54 +08:00

82 lines
1.7 KiB
Go

// Package router 路由配置
package router
import (
"net/http"
"github.com/gin-gonic/gin"
"billai-server/handler"
"billai-server/middleware"
)
// Config 路由配置参数
type Config struct {
OutputDir string // 输出目录(用于静态文件服务)
Version string // 应用版本
}
// Setup 设置所有路由
func Setup(r *gin.Engine, cfg Config) {
// 健康检查
r.GET("/health", healthCheck(cfg.Version))
// API 路由组
setupAPIRoutes(r)
// 静态文件下载
r.Static("/download", cfg.OutputDir)
}
// healthCheck 健康检查处理器
func healthCheck(version string) gin.HandlerFunc {
return func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"version": version,
})
}
}
// setupAPIRoutes 设置 API 路由
func setupAPIRoutes(r *gin.Engine) {
api := r.Group("/api")
{
// 认证相关(无需登录)
api.POST("/auth/login", handler.Login)
api.GET("/auth/validate", handler.ValidateToken)
// 需要登录的 API
authed := api.Group("/")
authed.Use(middleware.AuthRequired())
{
// 账单上传
authed.POST("/upload", handler.Upload)
// 复核相关
authed.GET("/review", handler.Review)
// 账单查询
authed.GET("/bills", handler.ListBills)
// 导出账单
authed.GET("/bills/export", handler.ExportBills)
// 编辑账单
authed.POST("/bills/:id", handler.UpdateBill)
// 删除账单(软删除)
authed.POST("/bills/:id/delete", handler.DeleteBill)
// 手动创建账单
authed.POST("/bills/manual", handler.CreateManualBills)
// 月度统计(全部数据)
authed.GET("/monthly-stats", handler.MonthlyStats)
// 待复核数据统计
authed.GET("/review-stats", handler.ReviewStats)
}
}
}