| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package routes
- import (
- "ems-backend/controllers"
- "ems-backend/middleware"
- "github.com/gin-gonic/gin"
- )
- func SetupRoutes(r *gin.Engine) {
- // Public Routes
- r.POST("/api/v1/login", controllers.Login)
- r.POST("/api/v1/login/sso", controllers.SSOLogin)
- api := r.Group("/api/v1")
- api.Use(middleware.AuthRequired())
- {
- // Menu & Perms
- api.GET("/getRouters", controllers.GetRouters)
- api.GET("/system/menu/tree", controllers.GetMenuTree)
- api.GET("/system/role/:roleId/menus", controllers.GetRoleMenuIds)
- // AI Analysis
- ai := api.Group("/ai")
- {
- ai.GET("/config", controllers.GetAIConfig)
- ai.POST("/config", controllers.UpdateAIConfig)
- ai.POST("/config/test", controllers.TestAIConnection)
- ai.POST("/config/models", controllers.GetRemoteModels)
- ai.POST("/generate-report", controllers.GenerateAIReport)
- ai.GET("/reports", controllers.GetAIReports)
- ai.GET("/reports/:id", controllers.GetAIReportDetail)
- }
- // Integration Sources
- api.GET("/sources", controllers.GetSources)
- api.POST("/sources/import/preview", controllers.PreviewSourceImport)
- api.POST("/sources/import/execute", controllers.ImportSources)
- api.POST("/sources", controllers.CreateSource)
- api.PUT("/sources/:id", controllers.UpdateSource)
- api.DELETE("/sources/:id", controllers.DeleteSource)
- api.POST("/sources/test", controllers.TestSourceConnection) // 测试连接
- api.GET("/sources/:id/candidates", controllers.GetSourceCandidates) // 获取候选设备 (Legacy)
- api.GET("/sources/:id/devices", controllers.GetSourceDevices) // 获取HA设备列表
- api.GET("/sources/:id/devices/:deviceId/entities", controllers.GetSourceDeviceEntities) // 获取HA设备实体
- api.POST("/sources/:id/sync", controllers.SyncSource) // 立即同步
- api.POST("/sources/:id/service", controllers.CallSourceService) // 调用服务
- // Devices
- api.GET("/devices", controllers.GetDevices)
- api.GET("/devices/:id", controllers.GetDevice)
- api.GET("/devices/:id/realtime", controllers.GetDeviceRealtime) // 获取时序库最新数据
- api.GET("/devices/history", controllers.GetDeviceHistory)
- api.DELETE("/devices/history", controllers.DeleteDeviceHistory)
- api.POST("/devices", controllers.CreateDevice)
- api.PUT("/devices/:id", controllers.UpdateDevice)
- api.DELETE("/devices/:id", controllers.DeleteDevice)
- // Locations
- api.GET("/locations", controllers.GetLocations)
- api.POST("/locations", controllers.CreateLocation)
- api.PUT("/locations/:id", controllers.UpdateLocation)
- api.DELETE("/locations/:id", controllers.DeleteLocation)
- // Cleaning Templates
- api.GET("/cleaning-templates", controllers.GetCleaningTemplates)
- api.POST("/cleaning-templates", controllers.CreateCleaningTemplate)
- api.PUT("/cleaning-templates/:id", controllers.UpdateCleaningTemplate)
- api.DELETE("/cleaning-templates/:id", controllers.DeleteCleaningTemplate)
- // Dashboard & Control
- // api.GET("/dashboard/stats", controllers.GetDashboardStats) // Deprecated
- dashboard := api.Group("/dashboard")
- {
- dashboard.GET("/stats/energy", controllers.GetTodayEnergy)
- dashboard.GET("/stats/power", controllers.GetRealtimePower)
- dashboard.GET("/stats/overview", controllers.GetDeviceStats)
- dashboard.GET("/stats/trend", controllers.GetEnergyTrend)
- dashboard.GET("/stats/power-trend", controllers.GetPowerTrend)
- dashboard.GET("/stats/activities", controllers.GetRecentActivities)
- }
- api.POST("/control/:id", controllers.ControlDevice)
- // Alarms
- api.GET("/alarms", controllers.GetAlarms)
- api.POST("/alarms", controllers.CreateAlarm)
- api.PUT("/alarms/:id/ack", controllers.AcknowledgeAlarm)
- // Alarm Rules
- api.GET("/alarm-rules", controllers.GetAlarmRules)
- api.POST("/alarm-rules", controllers.CreateAlarmRule)
- api.DELETE("/alarm-rules/batch", controllers.BatchDeleteAlarmRules) // Batch Delete
- api.PUT("/alarm-rules/:id", controllers.UpdateAlarmRule)
- api.DELETE("/alarm-rules/:id", controllers.DeleteAlarmRule)
- // Energy Analysis
- api.GET("/analysis/energy", controllers.GetEnergyAnalysis)
- // Inspections
- api.GET("/inspections", controllers.GetInspections)
- api.POST("/inspections", controllers.CreateInspection)
- // System & Settings
- sys := api.Group("/system")
- {
- // Roles
- sys.GET("/roles", controllers.GetRoles)
- sys.POST("/roles", controllers.CreateRole)
- sys.PUT("/roles/:id", controllers.UpdateRole)
- sys.DELETE("/roles/:id", controllers.DeleteRole)
- // Users
- sys.GET("/users", controllers.GetUsers)
- sys.POST("/users", controllers.CreateUser)
- sys.PUT("/users/:id", controllers.UpdateUser)
- sys.DELETE("/users/:id", controllers.DeleteUser)
- // User Profile (Self)
- sys.GET("/user/profile", controllers.GetProfile)
- sys.PUT("/user/profile/updatePwd", controllers.UpdateProfilePwd)
- // Configs
- sys.GET("/configs", controllers.GetAllConfigs)
- sys.GET("/config/:key", controllers.GetConfig)
- sys.POST("/config", controllers.UpdateConfig)
-
- // Debug Log Control
- sys.POST("/debug-log", controllers.SetDebugLog)
- }
- // Backup
- backup := api.Group("/backup")
- {
- bc := new(controllers.BackupController)
- backup.GET("/config", bc.GetConfig)
- backup.POST("/config", bc.SaveConfig)
- backup.POST("/exec", bc.ManualBackup)
- backup.GET("/logs", bc.GetLogs)
- backup.POST("/test", bc.TestConnection)
- backup.GET("/download/:id", bc.Download)
- }
- // Operations Logs
- ops := api.Group("/ops")
- {
- lc := controllers.NewLogController()
- ops.GET("/logs/files", lc.GetLogFiles)
- ops.GET("/logs/content", lc.GetLogContent)
- }
- }
- }
|