Files
pig-farm-controller/design/provide-logger-with-mothed/task-repository.md
2025-11-05 23:57:09 +08:00

396 lines
30 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

- **`internal/infra/repository/unit_of_work.go` (`repository.UnitOfWork` - `gormUnitOfWork` 实现)**
- **接口改造 (`UnitOfWork`)**:
- [x] 修改 `UnitOfWork` 接口中的 `ExecuteInTransaction` 方法签名,使其接收 `ctx context.Context` 作为第一个参数:
`ExecuteInTransaction(ctx context.Context, fn func(tx *gorm.DB) error) error`
- **结构体改造 (`gormUnitOfWork`)**:
- [x] 移除 `gormUnitOfWork` 结构体中的 `logger *logs.Logger` 成员。
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormUnitOfWork`)**:
- [x] 修改函数签名,移除 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`
- [x] 在函数内部,为 `gormUnitOfWork` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "GormUnitOfWork")`
- [x] 将这个 `selfCtx` 赋值给 `gormUnitOfWork` 结构体的 `selfCtx` 成员。
- **方法改造 (`ExecuteInTransaction`)**:
- [x] 修改方法签名,使其接收 `ctx context.Context` 作为第一个参数:
`(u *gormUnitOfWork) ExecuteInTransaction(ctx context.Context, fn func(tx *gorm.DB) error) error`
- [x] 在方法入口处,使用 `newCtx, logger := logs.Trace(ctx, u.selfCtx, "ExecuteInTransaction")` 获取新的
`context.Context``logger` 实例。
- [x] 将所有对 `u.logger.Errorf` 的调用替换为 `logger.Errorf`
- [x] 在开启事务时,使用 `tx := u.db.WithContext(newCtx).Begin()`,确保事务 `tx` 携带了正确的上下文。
- **`internal/infra/repository/plan_repository.go` (`repository.PlanRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPlanRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPlanRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PlanRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPlanRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/user_repository.go` (`repository.UserRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormUserRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormUserRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "UserRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormUserRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/device_repository.go` (`repository.DeviceRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormDeviceRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormDeviceRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "DeviceRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormDeviceRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_pen_repository.go` (`repository.PigPenRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigPenRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigPenRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigPenRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigPenRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_farm_repository.go` (`repository.PigFarmRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigFarmRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigFarmRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigFarmRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigFarmRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_sick_repository.go` (`repository.PigSickLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigSickLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigSickLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigSickLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigSickLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_batch_repository.go` (`repository.PigBatchRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigBatchRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigBatchRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigBatchRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigBatchRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_trade_repository.go` (`repository.PigTradeRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigTradeRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigTradeRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigTradeRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigTradeRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/sensor_data_repository.go` (`repository.SensorDataRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormSensorDataRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormSensorDataRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "SensorDataRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormSensorDataRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/notification_repository.go` (`repository.NotificationRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormNotificationRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormNotificationRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "NotificationRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormNotificationRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pending_task_repository.go` (`repository.PendingTaskRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPendingTaskRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPendingTaskRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PendingTaskRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPendingTaskRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/raw_material_repository.go` (`repository.RawMaterialRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormRawMaterialRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormRawMaterialRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "RawMaterialRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormRawMaterialRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/execution_log_repository.go` (`repository.ExecutionLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormExecutionLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormExecutionLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "ExecutionLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormExecutionLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_batch_log_repository.go` (`repository.PigBatchLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigBatchLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigBatchLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigBatchLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigBatchLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/medication_log_repository.go` (`repository.MedicationLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormMedicationLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormMedicationLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "MedicationLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormMedicationLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/area_controller_repository.go` (`repository.AreaControllerRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormAreaControllerRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormAreaControllerRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "AreaControllerRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormAreaControllerRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/device_template_repository.go` (`repository.DeviceTemplateRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormDeviceTemplateRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormDeviceTemplateRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "DeviceTemplateRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormDeviceTemplateRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/user_action_log_repository.go` (`repository.UserActionLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormUserActionLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormUserActionLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "UserActionLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormUserActionLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_transfer_log_repository.go` (`repository.PigTransferLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigTransferLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigTransferLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigTransferLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigTransferLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/device_command_log_repository.go` (`repository.DeviceCommandLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormDeviceCommandLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormDeviceCommandLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "DeviceCommandLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormDeviceCommandLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pending_collection_repository.go` (`repository.PendingCollectionRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPendingCollectionRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPendingCollectionRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PendingCollectionRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPendingCollectionRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/raw_material_repository.go` (`repository.RawMaterialRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormRawMaterialRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormRawMaterialRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "RawMaterialRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormRawMaterialRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/execution_log_repository.go` (`repository.ExecutionLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormExecutionLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormExecutionLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "ExecutionLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormExecutionLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_batch_log_repository.go` (`repository.PigBatchLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigBatchLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigBatchLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigBatchLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigBatchLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/medication_log_repository.go` (`repository.MedicationLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormMedicationLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormMedicationLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "MedicationLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormMedicationLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/area_controller_repository.go` (`repository.AreaControllerRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormAreaControllerRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormAreaControllerRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "AreaControllerRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormAreaControllerRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/device_template_repository.go` (`repository.DeviceTemplateRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormDeviceTemplateRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormDeviceTemplateRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "DeviceTemplateRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormDeviceTemplateRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/user_action_log_repository.go` (`repository.UserActionLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormUserActionLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormUserActionLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "UserActionLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormUserActionLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)``tx.WithContext(newCtx)`
- **`internal/infra/repository/pig_transfer_log_repository.go` (`repository.PigTransferLogRepository`)**
- **结构体改造**:
- [x] 新增 `selfCtx context.Context` 成员。
- **构造函数改造 (`NewGormPigTransferLogRepository`)**:
- [x] 修改函数签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在函数内部,为 `gormPigTransferLogRepository` 创建其专属的 `selfCtx`
`selfCtx := logs.AddCompName(ctx, "PigTransferLogRepository")`
- [x] 将这个 `selfCtx` 赋值给 `gormPigTransferLogRepository` 结构体的 `selfCtx` 成员。
- **公共方法改造 (所有公共方法)**:
- [x] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。
- [x] 在方法入口处,使用 `newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")`
- [x] 确保所有对 `r.db``tx` 的调用都使用 `r.db.WithContext(newCtx)` 或 `tx.WithContext(new