diff --git a/internal/app/api/api.go b/internal/app/api/api.go index 2e3b94e..598e1ea 100644 --- a/internal/app/api/api.go +++ b/internal/app/api/api.go @@ -28,8 +28,8 @@ import ( "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/monitor" "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/plan" "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/user" + "git.huangwc.com/pig/pig-farm-controller/internal/app/listener" "git.huangwc.com/pig/pig-farm-controller/internal/app/service" - "git.huangwc.com/pig/pig-farm-controller/internal/app/webhook" domain_plan "git.huangwc.com/pig/pig-farm-controller/internal/domain/plan" "git.huangwc.com/pig/pig-farm-controller/internal/infra/config" "git.huangwc.com/pig/pig-farm-controller/internal/infra/logs" @@ -64,7 +64,7 @@ type API struct { rawMaterialController *feed.RawMaterialController // 原料控制器实例 recipeController *feed.RecipeController // 配方控制器实例 inventoryController *inventory.InventoryController // 库存控制器实例 - listenHandler webhook.ListenHandler // 设备上行事件监听器 + listenHandler listener.ListenHandler // 设备上行事件监听器 analysisTaskManager *domain_plan.AnalysisPlanTaskManager // 计划触发器管理器实例 } @@ -89,7 +89,7 @@ func NewAPI(cfg config.ServerConfig, recipeService service.RecipeService, inventoryService service.InventoryService, tokenGenerator token.Generator, - listenHandler webhook.ListenHandler, + listenHandler listener.ListenHandler, ) *API { // 使用 echo.New() 创建一个 Echo 引擎实例 e := echo.New() diff --git a/internal/app/webhook/chirp_stack.go b/internal/app/listener/chirp_stack/chirp_stack.go similarity index 99% rename from internal/app/webhook/chirp_stack.go rename to internal/app/listener/chirp_stack/chirp_stack.go index c3cf005..1170299 100644 --- a/internal/app/webhook/chirp_stack.go +++ b/internal/app/listener/chirp_stack/chirp_stack.go @@ -1,4 +1,4 @@ -package webhook +package chirp_stack import ( "context" @@ -9,10 +9,12 @@ import ( "net/http" "time" + "git.huangwc.com/pig/pig-farm-controller/internal/app/listener" "git.huangwc.com/pig/pig-farm-controller/internal/infra/logs" "git.huangwc.com/pig/pig-farm-controller/internal/infra/models" "git.huangwc.com/pig/pig-farm-controller/internal/infra/repository" "git.huangwc.com/pig/pig-farm-controller/internal/infra/transport/proto" + gproto "google.golang.org/protobuf/proto" "gorm.io/datatypes" ) @@ -47,7 +49,7 @@ func NewChirpStackListener( areaControllerRepo repository.AreaControllerRepository, deviceCommandLogRepo repository.DeviceCommandLogRepository, pendingCollectionRepo repository.PendingCollectionRepository, -) ListenHandler { +) listener.ListenHandler { return &ChirpStackListener{ ctx: ctx, sensorDataRepo: sensorDataRepo, diff --git a/internal/app/webhook/chirp_stack_types.go b/internal/app/listener/chirp_stack/chirp_stack_types.go similarity index 99% rename from internal/app/webhook/chirp_stack_types.go rename to internal/app/listener/chirp_stack/chirp_stack_types.go index 05247d2..0549843 100644 --- a/internal/app/webhook/chirp_stack_types.go +++ b/internal/app/listener/chirp_stack/chirp_stack_types.go @@ -1,4 +1,4 @@ -package webhook +package chirp_stack import ( "encoding/json" diff --git a/internal/app/webhook/placeholder_listener.go b/internal/app/listener/chirp_stack/placeholder_listener.go similarity index 78% rename from internal/app/webhook/placeholder_listener.go rename to internal/app/listener/chirp_stack/placeholder_listener.go index 2d3979d..1bd24a1 100644 --- a/internal/app/webhook/placeholder_listener.go +++ b/internal/app/listener/chirp_stack/placeholder_listener.go @@ -1,9 +1,10 @@ -package webhook +package chirp_stack import ( "context" "net/http" + "git.huangwc.com/pig/pig-farm-controller/internal/app/listener" "git.huangwc.com/pig/pig-farm-controller/internal/infra/logs" ) @@ -13,8 +14,8 @@ type PlaceholderListener struct { } // NewPlaceholderListener 创建一个新的 PlaceholderListener 实例 -// 它只打印一条日志, 表明 ChirpStack webhook 未被激活 -func NewPlaceholderListener(ctx context.Context) ListenHandler { +// 它只打印一条日志, 表明 ChirpStack listener 未被激活 +func NewPlaceholderListener(ctx context.Context) listener.ListenHandler { return &PlaceholderListener{ ctx: ctx, } diff --git a/internal/app/webhook/transport.go b/internal/app/listener/transport.go similarity index 89% rename from internal/app/webhook/transport.go rename to internal/app/listener/transport.go index 7583c06..5251ebc 100644 --- a/internal/app/webhook/transport.go +++ b/internal/app/listener/transport.go @@ -1,4 +1,4 @@ -package webhook +package listener import "net/http" diff --git a/internal/core/component_initializers.go b/internal/core/component_initializers.go index 02c4f85..8d15d93 100644 --- a/internal/core/component_initializers.go +++ b/internal/core/component_initializers.go @@ -5,8 +5,9 @@ import ( "fmt" "time" + "git.huangwc.com/pig/pig-farm-controller/internal/app/listener" + "git.huangwc.com/pig/pig-farm-controller/internal/app/listener/chirp_stack" "git.huangwc.com/pig/pig-farm-controller/internal/app/service" - "git.huangwc.com/pig/pig-farm-controller/internal/app/webhook" "git.huangwc.com/pig/pig-farm-controller/internal/domain/alarm" "git.huangwc.com/pig/pig-farm-controller/internal/domain/device" "git.huangwc.com/pig/pig-farm-controller/internal/domain/inventory" @@ -361,7 +362,7 @@ func initAppServices(ctx context.Context, infra *Infrastructure, domainServices // LoraComponents 聚合了所有 LoRa 相关组件。 type LoraComponents struct { - listenHandler webhook.ListenHandler + listenHandler listener.ListenHandler comm transport.Communicator loraListener transport.Listener } @@ -372,7 +373,7 @@ func initLora( cfg *config.Config, repos *Repositories, ) (*LoraComponents, error) { - var listenHandler webhook.ListenHandler + var listenHandler listener.ListenHandler var comm transport.Communicator var loraListener transport.Listener baseCtx := context.Background() @@ -380,12 +381,12 @@ func initLora( logger := logs.GetLogger(ctx) if cfg.Lora.Mode == config.LoraMode_LoRaWAN { logger.Info("当前运行模式: lora_wan。初始化 ChirpStack 监听器和传输层。") - listenHandler = webhook.NewChirpStackListener(logs.AddCompName(baseCtx, "ChirpStackListener"), repos.sensorDataRepo, repos.deviceRepo, repos.areaControllerRepo, repos.deviceCommandLogRepo, repos.pendingCollectionRepo) + listenHandler = chirp_stack.NewChirpStackListener(logs.AddCompName(baseCtx, "ChirpStackListener"), repos.sensorDataRepo, repos.deviceRepo, repos.areaControllerRepo, repos.deviceCommandLogRepo, repos.pendingCollectionRepo) comm = lora.NewChirpStackTransport(logs.AddCompName(baseCtx, "ChirpStackTransport"), cfg.ChirpStack) loraListener = lora.NewPlaceholderTransport(logs.AddCompName(baseCtx, "PlaceholderTransport")) } else { logger.Info("当前运行模式: lora_mesh。初始化 LoRa Mesh 传输层和占位符监听器。") - listenHandler = webhook.NewPlaceholderListener(logs.AddCompName(baseCtx, "PlaceholderListener")) + listenHandler = chirp_stack.NewPlaceholderListener(logs.AddCompName(baseCtx, "PlaceholderListener")) tp, err := lora.NewLoRaMeshUartPassthroughTransport(logs.AddCompName(baseCtx, "LoRaMeshTransport"), cfg.LoraMesh, repos.areaControllerRepo, repos.pendingCollectionRepo, repos.deviceRepo, repos.sensorDataRepo) if err != nil { return nil, fmt.Errorf("无法初始化 LoRa Mesh 模块: %w", err) diff --git a/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_create_ifttt_integration_responses.go b/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_create_ifttt_integration_responses.go index 3f9f044..d7e8442 100644 --- a/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_create_ifttt_integration_responses.go +++ b/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_create_ifttt_integration_responses.go @@ -297,7 +297,7 @@ type ApplicationServiceCreateIftttIntegrationParamsBodyIntegration struct { // Event prefix. // If set, the event name will be PREFIX_EVENT. For example if event_prefix // is set to weatherstation, and uplink event will be sent as - // weatherstation_up to the IFTTT webhook. + // weatherstation_up to the IFTTT listener. // Note: Only characters in the A-Z, a-z and 0-9 range are allowed. EventPrefix string `json:"eventPrefix,omitempty"` diff --git a/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_update_ifttt_integration_responses.go b/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_update_ifttt_integration_responses.go index 91caf12..8b92268 100644 --- a/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_update_ifttt_integration_responses.go +++ b/internal/infra/transport/lora/chirp_stack_proto/client/application_service/application_service_update_ifttt_integration_responses.go @@ -297,7 +297,7 @@ type ApplicationServiceUpdateIftttIntegrationParamsBodyIntegration struct { // Event prefix. // If set, the event name will be PREFIX_EVENT. For example if event_prefix // is set to weatherstation, and uplink event will be sent as - // weatherstation_up to the IFTTT webhook. + // weatherstation_up to the IFTTT listener. // Note: Only characters in the A-Z, a-z and 0-9 range are allowed. EventPrefix string `json:"eventPrefix,omitempty"` diff --git a/internal/infra/transport/lora/chirp_stack_proto/models/api_ifttt_integration.go b/internal/infra/transport/lora/chirp_stack_proto/models/api_ifttt_integration.go index 498e866..53eea31 100644 --- a/internal/infra/transport/lora/chirp_stack_proto/models/api_ifttt_integration.go +++ b/internal/infra/transport/lora/chirp_stack_proto/models/api_ifttt_integration.go @@ -28,7 +28,7 @@ type APIIftttIntegration struct { // Event prefix. // If set, the event name will be PREFIX_EVENT. For example if event_prefix // is set to weatherstation, and uplink event will be sent as - // weatherstation_up to the IFTTT webhook. + // weatherstation_up to the IFTTT listener. // Note: Only characters in the A-Z, a-z and 0-9 range are allowed. EventPrefix string `json:"eventPrefix,omitempty"`