102 lines
8.9 KiB
Markdown
102 lines
8.9 KiB
Markdown
## 1. 准备工作
|
||
- [ ] 1.1 阅读并理解 `openspec/changes/refactor-business-logic-layering/proposal.md`。
|
||
- [ ] 1.2 确保本地环境干净,并拉取最新代码。
|
||
|
||
## 2. 统一服务层接口输入输出为 DTO
|
||
|
||
### 2.1 `monitor` 模块
|
||
- [ ] 2.1.1 **修改 `internal/app/service/monitor_service.go` 接口:**
|
||
- [ ] 将所有 `List...` 方法的 `opts repository.ListOptions` 参数替换为服务层自定义的查询 DTO 或一系列基本参数。
|
||
- [ ] 将所有 `List...` 方法的返回值 `[]models.Xxx` 替换为 `[]dto.XxxResponse`。
|
||
- [ ] 2.1.2 **修改 `internal/app/service/impl/monitor_service_impl.go` 实现:**
|
||
- [ ] 调整 `List...` 方法的签名以匹配接口变更。
|
||
- [ ] 在服务层内部将服务层查询 DTO 转换为 `repository.ListOptions`。
|
||
- [ ] 在服务层内部将 `repository` 返回的 `models` 对象转换为 `dto.XxxResponse`。
|
||
- [ ] 2.1.3 **修改 `internal/app/controller/monitor/monitor_controller.go`:**
|
||
- [ ] 移除控制器中构建 `repository.ListOptions` 的逻辑。
|
||
- [ ] 移除控制器中将 `models` 转换为 `dto.NewList...Response` 的逻辑。
|
||
- [ ] 移除控制器中直接使用 `models` 进行枚举类型转换的逻辑,将其下沉到服务层或 DTO 转换逻辑中。
|
||
- [ ] 调整服务层方法的调用,使其接收新的服务层查询 DTO 或基本参数,并直接处理服务层返回的 `dto.XxxResponse`。
|
||
|
||
### 2.2 `device` 模块
|
||
- [ ] 2.2.1 **修改 `internal/app/service/device_service.go` 接口:**
|
||
- [ ] 为 `CreateDevice`, `UpdateDevice`, `CreateAreaController`, `UpdateAreaController`, `CreateDeviceTemplate`, `UpdateDeviceTemplate` 方法定义并接收 DTO 作为输入。
|
||
- [ ] 将 `GetDevice`, `ListDevices`, `GetAreaController`, `ListAreaControllers`, `GetDeviceTemplate`, `ListDeviceTemplates` 方法的返回值 `models.Xxx` 或 `[]models.Xxx` 替换为 `dto.XxxResponse` 或 `[]dto.XxxResponse`。
|
||
- [ ] 调整 `ManualControl` 方法,使其接收 DTO 或基本参数,而不是 `models.Device`。
|
||
- [ ] 2.2.2 **修改 `internal/app/service/impl/device_service_impl.go` 实现:**
|
||
- [ ] 调整方法签名以匹配接口变更。
|
||
- [ ] 在服务层内部将输入 DTO 转换为 `models` 对象。
|
||
- [ ] 在服务层内部将 `repository` 返回的 `models` 对象转换为 `dto.XxxResponse`。
|
||
- [ ] 将 `SelfCheck()` 验证逻辑从控制器移入服务层。
|
||
- [ ] 将 `Properties`, `Commands`, `Values` 的 JSON 序列化逻辑从控制器移入服务层。
|
||
- [ ] 将 `ManualControl` 中的业务逻辑(如动作映射)从控制器移入服务层。
|
||
- [ ] 将控制器中直接调用 `repository` 方法的逻辑移入服务层。
|
||
- [ ] 将控制器中通过检查 `repository` 错误信息处理业务规则的逻辑移入服务层。
|
||
- [ ] 2.2.3 **修改 `internal/app/controller/device/device_controller.go`:**
|
||
- [ ] 移除控制器中直接创建 `models.Device`, `models.AreaController`, `models.DeviceTemplate` 对象的逻辑。
|
||
- [ ] 移除控制器中直接调用 `SelfCheck()` 的逻辑。
|
||
- [ ] 移除控制器中直接调用 `repository` 方法的逻辑。
|
||
- [ ] 移除控制器中通过检查 `repository` 错误信息处理业务规则的逻辑。
|
||
- [ ] 移除控制器中 `Properties`, `Commands`, `Values` 的 JSON 序列化逻辑。
|
||
- [ ] 调整服务层方法的调用,使其接收新的服务层输入 DTO 或基本参数,并直接处理服务层返回的 `dto.XxxResponse`。
|
||
|
||
### 2.3 `pig-farm` 模块
|
||
- [ ] 2.3.1 **修改 `internal/app/service/pig_farm_service.go` 接口:**
|
||
- [ ] 将 `CreatePigHouse`, `GetPigHouseByID`, `ListPigHouses`, `UpdatePigHouse`, `CreatePen`, `GetPenByID`, `ListPens`, `UpdatePen`, `UpdatePenStatus` 方法的返回值 `models.Xxx` 或 `[]models.Xxx` 替换为 `dto.XxxResponse` 或 `[]dto.XxxResponse`。
|
||
- [ ] 2.3.2 **修改 `internal/app/service/impl/pig_farm_service_impl.go` 实现:**
|
||
- [ ] 调整方法签名以匹配接口变更。
|
||
- [ ] 在服务层内部将 `repository` 返回的 `models` 对象转换为 `dto.XxxResponse`。
|
||
- [ ] 将控制器中处理服务层特定业务错误(如 `service.ErrHouseNotFound`)的逻辑移入服务层,服务层应返回更抽象的错误或直接返回 DTO。
|
||
- [ ] 2.3.3 **修改 `internal/app/controller/management/pig_farm_controller.go`:**
|
||
- [ ] 移除控制器中手动将领域实体转换为 DTO 的逻辑。
|
||
- [ ] 移除控制器中直接处理服务层特定业务错误类型的逻辑。
|
||
- [ ] 调整服务层方法的调用,使其直接处理服务层返回的 `dto.XxxResponse`。
|
||
|
||
### 2.4 `plan` 模块
|
||
- [ ] 2.4.1 **修改 `internal/app/service/plan_service.go` 接口:**
|
||
- [ ] 为 `CreatePlan`, `UpdatePlan` 方法定义并接收 DTO 作为输入。
|
||
- [ ] 将 `GetPlanByID`, `ListPlans` 方法的返回值 `models.Plan` 或 `[]models.Plan` 替换为 `dto.PlanResponse` 或 `[]dto.PlanResponse`。
|
||
- [ ] 调整 `ListPlans` 方法的 `opts repository.ListPlansOptions` 参数替换为服务层自定义的查询 DTO 或一系列基本参数。
|
||
- [ ] 调整 `DeletePlan`, `StartPlan`, `StopPlan` 方法,使其接收 DTO 或基本参数,并封装所有业务逻辑。
|
||
- [ ] 2.4.2 **修改 `internal/app/service/impl/plan_service_impl.go` 实现:**
|
||
- [ ] 调整方法签名以匹配接口变更。
|
||
- [ ] 在服务层内部将输入 DTO 转换为 `models` 对象。
|
||
- [ ] 在服务层内部将 `repository` 返回的 `models` 对象转换为 `dto.XxxResponse`。
|
||
- [ ] 将控制器中所有的业务规则判断(计划类型检查、状态检查、执行计数器重置、ContentType 自动判断)移入服务层。
|
||
- [ ] 将控制器中对 `repository` 方法的直接调用移入服务层。
|
||
- [ ] 将控制器中对 `analysisPlanTaskManager` 的协调移入服务层。
|
||
- [ ] 将控制器中处理仓库层特有错误(`gorm.ErrRecordNotFound`)的逻辑移入服务层。
|
||
- [ ] 2.4.3 **修改 `internal/app/controller/plan/plan_controller.go`:**
|
||
- [ ] 移除控制器中直接创建 `models.Plan` 对象和 `repository.ListPlansOptions` 的逻辑。
|
||
- [ ] 移除控制器中所有的业务规则判断。
|
||
- [ ] 移除控制器中直接调用 `repository` 方法的逻辑。
|
||
- [ ] 移除控制器中直接协调 `analysisPlanTaskManager` 的逻辑。
|
||
- [ ] 移除控制器中直接处理仓库层特有错误的逻辑。
|
||
- [ ] 调整服务层方法的调用,使其接收新的服务层输入 DTO 或基本参数,并直接处理服务层返回的 `dto.XxxResponse`。
|
||
|
||
### 2.5 `user` 模块
|
||
- [ ] 2.5.1 **修改 `internal/app/service/user_service.go` 接口:**
|
||
- [ ] 为 `CreateUser`, `Login` 方法定义并接收 DTO 作为输入。
|
||
- [ ] 将 `CreateUser`, `Login` 方法的返回值 `models.User` 替换为 `dto.CreateUserResponse` 或 `dto.LoginResponse`。
|
||
- [ ] 调整 `ListUserHistory` 方法的 `opts repository.UserActionLogListOptions` 参数替换为服务层自定义的查询 DTO 或一系列基本参数,并将其返回值 `[]models.UserActionLog` 替换为 `[]dto.ListUserActionLogResponse`。
|
||
- [ ] 2.5.2 **修改 `internal/app/service/impl/user_service_impl.go` 实现:**
|
||
- [ ] 调整方法签名以匹配接口变更。
|
||
- [ ] 在服务层内部将输入 DTO 转换为 `models` 对象。
|
||
- [ ] 在服务层内部将 `repository` 返回的 `models` 对象转换为 `dto.XxxResponse`。
|
||
- [ ] 将 `CreateUser` 中处理用户名重复的业务逻辑移入服务层。
|
||
- [ ] 将 `Login` 中进行密码验证的业务逻辑和协调 `tokenService` 的逻辑移入服务层。
|
||
- [ ] 将 `ListUserHistory` 中强制覆盖 `UserID`、构建仓库层查询选项、枚举类型转换、以及处理服务层特定错误的逻辑移入服务层。
|
||
- [ ] 将控制器中通过检查底层(仓库层或服务层)的特定错误类型或错误信息来执行业务判断的逻辑移入服务层。
|
||
- [ ] 2.5.3 **修改 `internal/app/controller/user/user_controller.go`:**
|
||
- [ ] 移除控制器中直接创建 `models.User` 对象和 `repository.UserActionLogListOptions` 的逻辑。
|
||
- [ ] 移除控制器中处理用户名重复的业务逻辑。
|
||
- [ ] 移除控制器中进行密码验证的业务逻辑和协调 `tokenService` 的逻辑。
|
||
- [ ] 移除控制器中强制覆盖 `UserID`、构建仓库层查询选项、枚举类型转换、以及处理服务层特定错误的逻辑。
|
||
- [ ] 移除控制器中通过检查底层(仓库层或服务层)的特定错误类型或错误信息来执行业务判断的逻辑。
|
||
- [ ] 调整服务层方法的调用,使其接收新的服务层输入 DTO 或基本参数,并直接处理服务层返回的 `dto.XxxResponse`。
|
||
|
||
## 3. 验证与测试
|
||
- [ ] 3.1 运行所有单元测试和集成测试,确保重构没有引入新的问题。
|
||
- [ ] 3.2 针对受影响的 API 接口进行手动测试,验证功能是否正常。
|
||
- [ ] 3.3 确保日志输出和审计记录仍然准确无误。
|