修正方法位置
This commit is contained in:
@@ -131,4 +131,5 @@
|
|||||||
1. 定义告警表和告警历史表
|
1. 定义告警表和告警历史表
|
||||||
2. 重构部分枚举, 让models包不依赖其他项目中的包
|
2. 重构部分枚举, 让models包不依赖其他项目中的包
|
||||||
3. 创建仓库层对象(不包含方法)
|
3. 创建仓库层对象(不包含方法)
|
||||||
4. 实现告警发送任务
|
4. 实现告警发送任务
|
||||||
|
5. 实现告警通知发送计划
|
||||||
@@ -43,7 +43,10 @@ func NewApplication(configPath string) (*Application, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("初始化基础设施失败: %w", err)
|
return nil, fmt.Errorf("初始化基础设施失败: %w", err)
|
||||||
}
|
}
|
||||||
domain := initDomainServices(ctx, cfg, infra)
|
domain, err := initDomainServices(ctx, cfg, infra)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("初始化领域服务失败: %w", err)
|
||||||
|
}
|
||||||
appServices := initAppServices(ctx, infra, domain)
|
appServices := initAppServices(ctx, infra, domain)
|
||||||
|
|
||||||
// 3. 初始化 API 入口点
|
// 3. 初始化 API 入口点
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/transport"
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/transport"
|
||||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/transport/lora"
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/transport/lora"
|
||||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/utils/token"
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/utils/token"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,7 +30,6 @@ type Infrastructure struct {
|
|||||||
storage database.Storage
|
storage database.Storage
|
||||||
repos *Repositories
|
repos *Repositories
|
||||||
lora *LoraComponents
|
lora *LoraComponents
|
||||||
notifyService domain_notify.Service
|
|
||||||
tokenGenerator token.Generator
|
tokenGenerator token.Generator
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,18 +47,12 @@ func initInfrastructure(ctx context.Context, cfg *config.Config) (*Infrastructur
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyService, err := initNotifyService(ctx, cfg.Notify, repos.userRepo, repos.notificationRepo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("初始化通知服务失败: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenGenerator := token.NewTokenGenerator([]byte(cfg.App.JWTSecret))
|
tokenGenerator := token.NewTokenGenerator([]byte(cfg.App.JWTSecret))
|
||||||
|
|
||||||
return &Infrastructure{
|
return &Infrastructure{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
repos: repos,
|
repos: repos,
|
||||||
lora: lora,
|
lora: lora,
|
||||||
notifyService: notifyService,
|
|
||||||
tokenGenerator: tokenGenerator,
|
tokenGenerator: tokenGenerator,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -131,12 +125,18 @@ type DomainServices struct {
|
|||||||
planExecutionManager plan.ExecutionManager
|
planExecutionManager plan.ExecutionManager
|
||||||
analysisPlanTaskManager plan.AnalysisPlanTaskManager
|
analysisPlanTaskManager plan.AnalysisPlanTaskManager
|
||||||
planService plan.Service
|
planService plan.Service
|
||||||
|
notifyService domain_notify.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
// initDomainServices 初始化所有的领域服务。
|
// initDomainServices 初始化所有的领域服务。
|
||||||
func initDomainServices(ctx context.Context, cfg *config.Config, infra *Infrastructure) *DomainServices {
|
func initDomainServices(ctx context.Context, cfg *config.Config, infra *Infrastructure) (*DomainServices, error) {
|
||||||
baseCtx := context.Background()
|
baseCtx := context.Background()
|
||||||
|
|
||||||
|
notifyService, err := initNotifyService(ctx, cfg.Notify, infra.repos.userRepo, infra.repos.notificationRepo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("初始化通知服务失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// 猪群管理相关
|
// 猪群管理相关
|
||||||
pigPenTransferManager := pig.NewPigPenTransferManager(logs.AddCompName(baseCtx, "PigPenTransferManager"), infra.repos.pigPenRepo, infra.repos.pigTransferLogRepo, infra.repos.pigBatchRepo)
|
pigPenTransferManager := pig.NewPigPenTransferManager(logs.AddCompName(baseCtx, "PigPenTransferManager"), infra.repos.pigPenRepo, infra.repos.pigTransferLogRepo, infra.repos.pigBatchRepo)
|
||||||
pigTradeManager := pig.NewPigTradeManager(logs.AddCompName(baseCtx, "PigTradeManager"), infra.repos.pigTradeRepo)
|
pigTradeManager := pig.NewPigTradeManager(logs.AddCompName(baseCtx, "PigTradeManager"), infra.repos.pigTradeRepo)
|
||||||
@@ -165,7 +165,7 @@ func initDomainServices(ctx context.Context, cfg *config.Config, infra *Infrastr
|
|||||||
infra.repos.deviceRepo,
|
infra.repos.deviceRepo,
|
||||||
infra.repos.alarmRepo,
|
infra.repos.alarmRepo,
|
||||||
generalDeviceService,
|
generalDeviceService,
|
||||||
infra.notifyService)
|
notifyService)
|
||||||
|
|
||||||
// 计划任务管理器
|
// 计划任务管理器
|
||||||
analysisPlanTaskManager := plan.NewAnalysisPlanTaskManager(logs.AddCompName(baseCtx, "AnalysisPlanTaskManager"), infra.repos.planRepo, infra.repos.pendingTaskRepo, infra.repos.executionLogRepo)
|
analysisPlanTaskManager := plan.NewAnalysisPlanTaskManager(logs.AddCompName(baseCtx, "AnalysisPlanTaskManager"), infra.repos.planRepo, infra.repos.pendingTaskRepo, infra.repos.executionLogRepo)
|
||||||
@@ -206,7 +206,8 @@ func initDomainServices(ctx context.Context, cfg *config.Config, infra *Infrastr
|
|||||||
taskFactory: taskFactory,
|
taskFactory: taskFactory,
|
||||||
planExecutionManager: planExecutionManager,
|
planExecutionManager: planExecutionManager,
|
||||||
planService: planService,
|
planService: planService,
|
||||||
}
|
notifyService: notifyService,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppServices 聚合了所有的应用服务实例。
|
// AppServices 聚合了所有的应用服务实例。
|
||||||
@@ -251,7 +252,7 @@ func initAppServices(ctx context.Context, infra *Infrastructure, domainServices
|
|||||||
)
|
)
|
||||||
auditService := service.NewAuditService(logs.AddCompName(baseCtx, "AuditService"), infra.repos.userActionLogRepo)
|
auditService := service.NewAuditService(logs.AddCompName(baseCtx, "AuditService"), infra.repos.userActionLogRepo)
|
||||||
planService := service.NewPlanService(logs.AddCompName(baseCtx, "AppPlanService"), domainServices.planService)
|
planService := service.NewPlanService(logs.AddCompName(baseCtx, "AppPlanService"), domainServices.planService)
|
||||||
userService := service.NewUserService(logs.AddCompName(baseCtx, "UserService"), infra.repos.userRepo, infra.tokenGenerator, infra.notifyService)
|
userService := service.NewUserService(logs.AddCompName(baseCtx, "UserService"), infra.repos.userRepo, infra.tokenGenerator, domainServices.notifyService)
|
||||||
|
|
||||||
return &AppServices{
|
return &AppServices{
|
||||||
pigFarmService: pigFarmService,
|
pigFarmService: pigFarmService,
|
||||||
|
|||||||
Reference in New Issue
Block a user