feat: 智能客服系统基础架构完成
✅ 已完成功能: 1. 项目基础设施和Docker开发环境 2. 前端React 18 + TypeScript架构 3. 后端Golang + Gin框架 4. 多租户数据库设计 5. 完整API路由系统 6. 智能客服聊天界面 7. 详细文档和部署指南 🔧 技术栈: - 前端:React 18, TypeScript, Vite, Zustand - 后端:Golang, Gin, GORM, PostgreSQL - 部署:Docker, Docker Compose 🎨 设计规范: - 无渐变色,无紫色 - 简洁专业的中性色系 - 响应式布局 📊 状态: - 前端开发服务器:http://localhost:5173 - 后端API服务:http://localhost:8080 - 数据库:PostgreSQL + Redis - 完整的多租户架构 作者:小弟 (大哥的AI助手) 日期:2026-02-27
This commit is contained in:
102
backend/internal/router/router.go
Normal file
102
backend/internal/router/router.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"time"
|
||||
"smart-customer-service/config"
|
||||
"smart-customer-service/internal/handlers"
|
||||
"smart-customer-service/internal/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
cfg *config.Config
|
||||
handlers *handlers.Handlers
|
||||
}
|
||||
|
||||
func New(cfg *config.Config) *Router {
|
||||
return &Router{
|
||||
cfg: cfg,
|
||||
handlers: handlers.New(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Router) SetupRoutes() *gin.Engine {
|
||||
// 设置Gin模式
|
||||
if r.cfg.Server.Mode == "release" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
router := gin.Default()
|
||||
|
||||
// 全局中间件
|
||||
router.Use(middleware.CORS())
|
||||
router.Use(middleware.Logger())
|
||||
router.Use(middleware.Recovery())
|
||||
|
||||
// API路由组
|
||||
api := router.Group("/api")
|
||||
{
|
||||
// 公共路由(无需认证)
|
||||
public := api.Group("/v1")
|
||||
{
|
||||
public.POST("/auth/login", r.handlers.Auth.Login)
|
||||
public.POST("/auth/register", r.handlers.Auth.Register)
|
||||
public.POST("/auth/refresh", r.handlers.Auth.RefreshToken)
|
||||
|
||||
// 租户相关
|
||||
public.POST("/tenants/register", r.handlers.Tenant.Register)
|
||||
public.GET("/tenants/:id", r.handlers.Tenant.GetTenantInfo)
|
||||
}
|
||||
|
||||
// 需要认证的路由
|
||||
protected := api.Group("/v1")
|
||||
protected.Use(middleware.Auth(r.cfg.JWT.Secret))
|
||||
{
|
||||
// 用户管理
|
||||
protected.GET("/users/profile", r.handlers.User.GetProfile)
|
||||
protected.PUT("/users/profile", r.handlers.User.UpdateProfile)
|
||||
|
||||
// 会话管理
|
||||
protected.GET("/conversations", r.handlers.Conversation.List)
|
||||
protected.POST("/conversations", r.handlers.Conversation.Create)
|
||||
protected.GET("/conversations/:id", r.handlers.Conversation.Get)
|
||||
protected.GET("/conversations/:id/messages", r.handlers.Conversation.GetMessages)
|
||||
|
||||
// 消息管理
|
||||
protected.POST("/messages", r.handlers.Message.Send)
|
||||
|
||||
// 工单管理
|
||||
protected.GET("/tickets", r.handlers.Ticket.List)
|
||||
protected.POST("/tickets", r.handlers.Ticket.Create)
|
||||
protected.GET("/tickets/:id", r.handlers.Ticket.Get)
|
||||
protected.PUT("/tickets/:id", r.handlers.Ticket.Update)
|
||||
|
||||
// 知识库管理
|
||||
protected.GET("/knowledge", r.handlers.Knowledge.List)
|
||||
protected.POST("/knowledge", r.handlers.Knowledge.Create)
|
||||
protected.PUT("/knowledge/:id", r.handlers.Knowledge.Update)
|
||||
protected.DELETE("/knowledge/:id", r.handlers.Knowledge.Delete)
|
||||
}
|
||||
|
||||
// 管理员路由
|
||||
admin := api.Group("/admin")
|
||||
admin.Use(middleware.Auth(r.cfg.JWT.Secret))
|
||||
admin.Use(middleware.AdminOnly())
|
||||
{
|
||||
admin.GET("/tenants", r.handlers.Tenant.ListAll)
|
||||
admin.PUT("/tenants/:id/status", r.handlers.Tenant.UpdateStatus)
|
||||
admin.GET("/stats", r.handlers.Admin.GetStats)
|
||||
}
|
||||
}
|
||||
|
||||
// 健康检查
|
||||
router.GET("/health", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"status": "ok",
|
||||
"time": time.Now().Unix(),
|
||||
})
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
||||
Reference in New Issue
Block a user