routes.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package routes
  2. import (
  3. "ems-backend/controllers"
  4. "ems-backend/middleware"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func SetupRoutes(r *gin.Engine) {
  8. // Public Routes
  9. r.POST("/api/v1/login", controllers.Login)
  10. r.POST("/api/v1/login/sso", controllers.SSOLogin)
  11. api := r.Group("/api/v1")
  12. api.Use(middleware.AuthRequired())
  13. {
  14. // Menu & Perms
  15. api.GET("/getRouters", controllers.GetRouters)
  16. api.GET("/system/menu/tree", controllers.GetMenuTree)
  17. api.GET("/system/role/:roleId/menus", controllers.GetRoleMenuIds)
  18. // AI Analysis
  19. ai := api.Group("/ai")
  20. {
  21. ai.GET("/config", controllers.GetAIConfig)
  22. ai.POST("/config", controllers.UpdateAIConfig)
  23. ai.POST("/config/test", controllers.TestAIConnection)
  24. ai.POST("/config/models", controllers.GetRemoteModels)
  25. ai.POST("/generate-report", controllers.GenerateAIReport)
  26. ai.GET("/reports", controllers.GetAIReports)
  27. ai.GET("/reports/:id", controllers.GetAIReportDetail)
  28. }
  29. // Integration Sources
  30. api.GET("/sources", controllers.GetSources)
  31. api.POST("/sources/import/preview", controllers.PreviewSourceImport)
  32. api.POST("/sources/import/execute", controllers.ImportSources)
  33. api.POST("/sources", controllers.CreateSource)
  34. api.PUT("/sources/:id", controllers.UpdateSource)
  35. api.DELETE("/sources/:id", controllers.DeleteSource)
  36. api.POST("/sources/test", controllers.TestSourceConnection) // 测试连接
  37. api.GET("/sources/:id/candidates", controllers.GetSourceCandidates) // 获取候选设备 (Legacy)
  38. api.GET("/sources/:id/devices", controllers.GetSourceDevices) // 获取HA设备列表
  39. api.GET("/sources/:id/devices/:deviceId/entities", controllers.GetSourceDeviceEntities) // 获取HA设备实体
  40. api.POST("/sources/:id/sync", controllers.SyncSource) // 立即同步
  41. api.POST("/sources/:id/service", controllers.CallSourceService) // 调用服务
  42. // Devices
  43. api.GET("/devices", controllers.GetDevices)
  44. api.GET("/devices/:id", controllers.GetDevice)
  45. api.GET("/devices/:id/realtime", controllers.GetDeviceRealtime) // 获取时序库最新数据
  46. api.GET("/devices/history", controllers.GetDeviceHistory)
  47. api.DELETE("/devices/history", controllers.DeleteDeviceHistory)
  48. api.POST("/devices", controllers.CreateDevice)
  49. api.PUT("/devices/:id", controllers.UpdateDevice)
  50. api.DELETE("/devices/:id", controllers.DeleteDevice)
  51. // Locations
  52. api.GET("/locations", controllers.GetLocations)
  53. api.POST("/locations", controllers.CreateLocation)
  54. api.PUT("/locations/:id", controllers.UpdateLocation)
  55. api.DELETE("/locations/:id", controllers.DeleteLocation)
  56. // Cleaning Templates
  57. api.GET("/cleaning-templates", controllers.GetCleaningTemplates)
  58. api.POST("/cleaning-templates", controllers.CreateCleaningTemplate)
  59. api.PUT("/cleaning-templates/:id", controllers.UpdateCleaningTemplate)
  60. api.DELETE("/cleaning-templates/:id", controllers.DeleteCleaningTemplate)
  61. // Dashboard & Control
  62. // api.GET("/dashboard/stats", controllers.GetDashboardStats) // Deprecated
  63. dashboard := api.Group("/dashboard")
  64. {
  65. dashboard.GET("/stats/energy", controllers.GetTodayEnergy)
  66. dashboard.GET("/stats/power", controllers.GetRealtimePower)
  67. dashboard.GET("/stats/overview", controllers.GetDeviceStats)
  68. dashboard.GET("/stats/trend", controllers.GetEnergyTrend)
  69. dashboard.GET("/stats/power-trend", controllers.GetPowerTrend)
  70. dashboard.GET("/stats/activities", controllers.GetRecentActivities)
  71. }
  72. api.POST("/control/:id", controllers.ControlDevice)
  73. // Alarms
  74. api.GET("/alarms", controllers.GetAlarms)
  75. api.POST("/alarms", controllers.CreateAlarm)
  76. api.PUT("/alarms/:id/ack", controllers.AcknowledgeAlarm)
  77. // Alarm Rules
  78. api.GET("/alarm-rules", controllers.GetAlarmRules)
  79. api.POST("/alarm-rules", controllers.CreateAlarmRule)
  80. api.DELETE("/alarm-rules/batch", controllers.BatchDeleteAlarmRules) // Batch Delete
  81. api.PUT("/alarm-rules/:id", controllers.UpdateAlarmRule)
  82. api.DELETE("/alarm-rules/:id", controllers.DeleteAlarmRule)
  83. // Energy Analysis
  84. api.GET("/analysis/energy", controllers.GetEnergyAnalysis)
  85. // Inspections
  86. api.GET("/inspections", controllers.GetInspections)
  87. api.POST("/inspections", controllers.CreateInspection)
  88. // System & Settings
  89. sys := api.Group("/system")
  90. {
  91. // Roles
  92. sys.GET("/roles", controllers.GetRoles)
  93. sys.POST("/roles", controllers.CreateRole)
  94. sys.PUT("/roles/:id", controllers.UpdateRole)
  95. sys.DELETE("/roles/:id", controllers.DeleteRole)
  96. // Users
  97. sys.GET("/users", controllers.GetUsers)
  98. sys.POST("/users", controllers.CreateUser)
  99. sys.PUT("/users/:id", controllers.UpdateUser)
  100. sys.DELETE("/users/:id", controllers.DeleteUser)
  101. // User Profile (Self)
  102. sys.GET("/user/profile", controllers.GetProfile)
  103. sys.PUT("/user/profile/updatePwd", controllers.UpdateProfilePwd)
  104. // Configs
  105. sys.GET("/configs", controllers.GetAllConfigs)
  106. sys.GET("/config/:key", controllers.GetConfig)
  107. sys.POST("/config", controllers.UpdateConfig)
  108. // Debug Log Control
  109. sys.POST("/debug-log", controllers.SetDebugLog)
  110. }
  111. // Backup
  112. backup := api.Group("/backup")
  113. {
  114. bc := new(controllers.BackupController)
  115. backup.GET("/config", bc.GetConfig)
  116. backup.POST("/config", bc.SaveConfig)
  117. backup.POST("/exec", bc.ManualBackup)
  118. backup.GET("/logs", bc.GetLogs)
  119. backup.POST("/test", bc.TestConnection)
  120. backup.GET("/download/:id", bc.Download)
  121. }
  122. // Operations Logs
  123. ops := api.Group("/ops")
  124. {
  125. lc := controllers.NewLogController()
  126. ops.GET("/logs/files", lc.GetLogFiles)
  127. ops.GET("/logs/content", lc.GetLogContent)
  128. }
  129. }
  130. }