From 333453766340f3b49c43044e887b6539b87c3cd0 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Fri, 31 Oct 2025 15:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=BC=BA=E5=A4=B1=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../refactor-business-logic-layering/design.md | 10 +++++++--- .../refactor-business-logic-layering/proposal.md | 2 ++ .../refactor-business-logic-layering/tasks.md | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/openspec/changes/refactor-business-logic-layering/design.md b/openspec/changes/refactor-business-logic-layering/design.md index eddd012..a10eac0 100644 --- a/openspec/changes/refactor-business-logic-layering/design.md +++ b/openspec/changes/refactor-business-logic-layering/design.md @@ -151,9 +151,13 @@ 1. 移除所有业务逻辑(`json.Marshal`, `SelfCheck`, `repository` 调用, `dto` 转换等)。 2. 每个方法仅保留:参数绑定、调用 `c.deviceService.Method(req)`、错误处理和成功响应。 -3. **更新依赖注入** - - 在 `cmd/server/wire.go` (或项目中的依赖注入配置处) 更新 `DeviceController` 的创建逻辑,为其注入新创建的 - `DeviceService`。 +3. **修改 `internal/core/component_initializers.go`** + - 在 `AppServices` 结构体中增加 `DeviceService service.DeviceService` 字段。 + - 在 `initAppServices` 函数中,调用 `service.NewDeviceService` 创建实例,并将其注入到 `AppServices` 中。 + +4. **修改 `internal/app/api/api.go`** + - 更新 `NewAPI` 函数的参数,使其接收新的 `app/service.DeviceService`。 + - 更新 `device.NewController` 的调用,将多个仓库和领域服务的依赖替换为单一的 `DeviceService` 依赖。 ### Open Questions diff --git a/openspec/changes/refactor-business-logic-layering/proposal.md b/openspec/changes/refactor-business-logic-layering/proposal.md index d02fd85..6359d53 100644 --- a/openspec/changes/refactor-business-logic-layering/proposal.md +++ b/openspec/changes/refactor-business-logic-layering/proposal.md @@ -42,3 +42,5 @@ - `internal/infra/repository/*.go` (可能需要调整接口,以适应服务层接收 DTO 的变化) - `internal/infra/models/*.go` (可能需要添加或修改 DTO 转换方法) - `internal/app/dto/*.go` (可能需要添加新的 DTO 或修改现有 DTO 的构造函数) + - `internal/core/component_initializers.go` + - `internal/app/api/api.go` diff --git a/openspec/changes/refactor-business-logic-layering/tasks.md b/openspec/changes/refactor-business-logic-layering/tasks.md index 6948035..e8b8ddb 100644 --- a/openspec/changes/refactor-business-logic-layering/tasks.md +++ b/openspec/changes/refactor-business-logic-layering/tasks.md @@ -46,12 +46,8 @@ - [x] 移除控制器中通过检查 `repository` 错误信息处理业务规则的逻辑。 - [x] 移除控制器中 `Properties`, `Commands`, `Values` 的 JSON 序列化逻辑。 - [x] 调整服务层方法的调用,使其接收新的服务层输入 DTO 或基本参数,并直接处理服务层返回的 `dto.XxxResponse`。 -- [x] 2.2.3 **保持 `internal/domain/device/device_service.go` 和 `internal/domain/device/general_device_service.go` - 专注于领域逻辑:** - - [x] 确保 `internal/domain/device/device_service.go` 接口方法和 `internal/domain/device/general_device_service.go` - 实现方法不直接接收或返回 DTO。 - - [x] 调整 `internal/domain/device/general_device_service.go` 的方法签名和内部逻辑,以适应其调用方(新的 - `internal/app/service.DeviceService`)的调整,如果需要的话。 +- [x] 2.2.3 **修改 `internal/core/component_initializers.go`**:创建并提供新的 `DeviceService`。 +- [x] 2.2.4 **修改 `internal/app/api/api.go`**:更新 `DeviceController` 的依赖注入。 ### 2.3 `pig-farm` 模块 @@ -93,6 +89,8 @@ - [ ] 移除控制器中直接协调 `analysisPlanTaskManager` 的逻辑。 - [ ] 移除控制器中直接处理仓库层特有错误的逻辑。 - [ ] 调整服务层方法的调用,使其接收新的服务层输入 DTO 或基本参数,并直接处理服务层返回的 `dto.XxxResponse`。 +- [ ] 2.4.3 **修改 `internal/core/component_initializers.go`**:创建并提供新的 `PlanService`。 +- [ ] 2.4.4 **修改 `internal/app/api/api.go`**:更新 `PlanController` 的依赖注入。 ### 2.5 `user` 模块 @@ -119,6 +117,8 @@ - [ ] 移除控制器中强制覆盖 `UserID`、构建仓库层查询选项、枚举类型转换、以及处理服务层特定错误的逻辑。 - [ ] 移除控制器中通过检查底层(仓库层或服务层)的特定错误类型或错误信息来执行业务判断的逻辑。 - [ ] 调整服务层方法的调用,使其接收新的服务层输入 DTO 或基本参数,并直接处理服务层返回的 `dto.XxxResponse`。 +- [ ] 2.5.2 **修改 `internal/core/component_initializers.go`**:创建并提供新的 `UserService`。 +- [ ] 2.5.3 **修改 `internal/app/api/api.go`**:更新 `UserController` 的依赖注入。 ## 3. 验证与测试