- **`internal/app/service/pig_farm_service.go` (`service.PigFarmService`)** - **结构体改造**: - [ ] 移除 `PigFarmService` 结构体中的 `logger *logs.Logger` 成员。 - [ ] 新增 `selfCtx context.Context` 成员。 - [ ] 移除 `PigFarmService` 结构体中的 `repo repository.PigFarmRepository` 成员,改为 `repo repository.PigFarmRepository`。 - **构造函数改造 (`NewPigFarmService`)**: - [ ] 修改函数签名,移除 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`。 - [ ] 在函数内部,为 `PigFarmService` 创建其专属的 `selfCtx`: `selfCtx := logs.AddCompName(ctx, "PigFarmService")`。 - [ ] 将这个 `selfCtx` 赋值给 `PigFarmService` 结构体的 `selfCtx` 成员。 - **公共方法改造 ( 所有方法,例如 `CreatePigHouse`, `GetPigHouseByID`, `ListPigHouses`, `UpdatePigHouse`, `DeletePigHouse`, `CreatePen`, `GetPenByID`, `ListPens`, `UpdatePen`, `DeletePen`, `UpdatePenStatus`)**: - [ ] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。 - [ ] 在方法入口处,使用 `newCtx, logger := logs.Trace(ctx, s.selfCtx, "MethodName")` 获取新的 `context.Context` 和 `logger` 实例。 - [ ] 将所有对 `s.logger.Errorf` 和 `s.logger.Infof` 的调用替换为 `logger.Errorf` 和 `logger.Infof`。 - [ ] 确保所有对 `s.repo` 的调用都将 `newCtx` 作为第一个参数传递。 - **`internal/app/service/pig_batch_service.go` (`service.PigBatchService`)** - **结构体改造**: - [ ] 移除 `PigBatchService` 结构体中的 `logger *logs.Logger` 成员。 - [ ] 新增 `selfCtx context.Context` 成员。 - **构造函数改造 (`NewPigBatchService`)**: - [ ] 修改函数签名,移除 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`。 - [ ] 在函数内部,为 `PigBatchService` 创建其专属的 `selfCtx`: `selfCtx := logs.AddCompName(ctx, "PigBatchService")`。 - [ ] 将这个 `selfCtx` 赋值给 `PigBatchService` 结构体的 `selfCtx` 成员。 - **公共方法改造 ( 所有方法,例如 `CreatePigBatch`, `GetPigBatch`, `UpdatePigBatch`, `DeletePigBatch`, `ListPigBatches`, `AssignEmptyPensToBatch`, `ReclassifyPenToNewBatch`, `RemoveEmptyPenFromBatch`, `MovePigsIntoPen`, `SellPigs`, `BuyPigs`, `RecordSickPigs`, `RecordSickPigRecovery`, `RecordSickPigDeath`, `RecordSickPigCull`, `RecordDeath`, `RecordCull`)**: - [ ] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。 - [ ] 在方法入口处,使用 `newCtx, logger := logs.Trace(ctx, s.selfCtx, "MethodName")` 获取新的 `context.Context` 和 `logger` 实例。 - [ ] 将所有对 `s.logger.Errorf` 和 `s.logger.Infof` 的调用替换为 `logger.Errorf` 和 `logger.Infof`。 - [ ] 确保所有对 `s.pigBatchRepo`, `s.pigBatchLogRepo`, `s.uow`, `s.transferSvc`, `s.tradeSvc`, `s.sickSvc` 等依赖的调用都将 `newCtx` 作为第一个参数传递。 - **`internal/app/service/monitor_service.go` (`service.MonitorService`)** - **结构体改造**: - [ ] 移除 `MonitorService` 结构体中的 `logger *logs.Logger` 成员。 - [ ] 新增 `selfCtx context.Context` 成员。 - **构造函数改造 (`NewMonitorService`)**: - [ ] 修改函数签名,移除 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`。 - [ ] 在函数内部,为 `MonitorService` 创建其专属的 `selfCtx`: `selfCtx := logs.AddCompName(ctx, "MonitorService")`。 - [ ] 将这个 `selfCtx` 赋值给 `MonitorService` 结构体的 `selfCtx` 成员。 - **公共方法改造 ( 所有方法,例如 `ListSensorData`, `ListDeviceCommandLogs`, `ListPlanExecutionLogs`, `ListTaskExecutionLogs`, `ListPendingCollections`, `ListUserActionLogs`, `ListRawMaterialPurchases`, `ListRawMaterialStockLogs`, `ListFeedUsageRecords`, `ListMedicationLogs`, `ListPigBatchLogs`, `ListWeighingBatches`, `ListWeighingRecords`, `ListPigTransferLogs`, `ListPigSickLogs`, `ListPigPurchases`, `ListPigSales`, `ListNotifications`)**: - [ ] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。 - [ ] 在方法入口处,使用 `newCtx, logger := logs.Trace(ctx, s.selfCtx, "MethodName")` 获取新的 `context.Context` 和 `logger` 实例。 - [ ] 将所有对 `s.logger.Errorf` 和 `s.logger.Infof` 的调用替换为 `logger.Errorf` 和 `logger.Infof`。 - [ ] 确保所有对 `s.repo` 的调用都将 `newCtx` 作为第一个参数传递。 - **`internal/app/service/device_service.go` (`service.DeviceService`)** - **结构体改造**: - [ ] 移除 `DeviceService` 结构体中的 `logger *logs.Logger` 成员。 - [ ] 新增 `selfCtx context.Context` 成员。 - **构造函数改造 (`NewDeviceService`)**: - [ ] 修改函数签名,移除 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`。 - [ ] 在函数内部,为 `DeviceService` 创建其专属的 `selfCtx`: `selfCtx := logs.AddCompName(ctx, "DeviceService")`。 - [ ] 将这个 `selfCtx` 赋值给 `DeviceService` 结构体的 `selfCtx` 成员。 - **公共方法改造 ( 所有方法,例如 `CreateDevice`, `GetDevice`, `ListDevices`, `UpdateDevice`, `DeleteDevice`, `ManualControl`, `CreateAreaController`, `GetAreaController`, `ListAreaControllers`, `UpdateAreaController`, `DeleteAreaController`, `CreateDeviceTemplate`, `GetDeviceTemplate`, `ListDeviceTemplates`, `UpdateDeviceTemplate`, `DeleteDeviceTemplate`)**: - [ ] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。 - [ ] 在方法入口处,使用 `newCtx, logger := logs.Trace(ctx, s.selfCtx, "MethodName")` 获取新的 `context.Context` 和 `logger` 实例。 - [ ] 将所有对 `s.logger.Errorf`, `s.logger.Warnf`, `s.logger.Infof` 的调用替换为 `logger.Errorf`, `logger.Warnf`, `logger.Infof`。 - [ ] 确保所有对 `s.repo`, `s.generalDeviceService` 等依赖的调用都将 `newCtx` 作为第一个参数传递。 - **`internal/app/service/plan_service.go` (`service.PlanService`)** - **结构体改造**: - [ ] 移除 `PlanService` 结构体中的 `logger *logs.Logger` 成员。 - [ ] 新增 `selfCtx context.Context` 成员。 - **构造函数改造 (`NewPlanService`)**: - [ ] 修改函数签名,移除 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`。 - [ ] 在函数内部,为 `PlanService` 创建其专属的 `selfCtx`:`selfCtx := logs.AddCompName(ctx, "PlanService")`。 - [ ] 将这个 `selfCtx` 赋值给 `PlanService` 结构体的 `selfCtx` 成员。 - **公共方法改造 ( 所有方法,例如 `CreatePlan`, `GetPlanByID`, `ListPlans`, `UpdatePlan`, `DeletePlan`, `StartPlan`, `StopPlan`)**: - [ ] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。 - [ ] 在方法入口处,使用 `newCtx, logger := logs.Trace(ctx, s.selfCtx, "MethodName")` 获取新的 `context.Context` 和 `logger` 实例。 - [ ] 将所有对 `s.logger.Errorf` 和 `s.logger.Infof` 的调用替换为 `logger.Errorf` 和 `logger.Infof`。 - [ ] 确保所有对 `s.repo`, `s.planExecutionManager`, `s.analysisPlanTaskManager` 等依赖的调用都将 `newCtx` 作为第一个参数传递。 - **`internal/app/service/user_service.go` (`service.UserService`)** - **结构体改造**: - [ ] 移除 `UserService` 结构体中的 `logger *logs.Logger` 成员。 - [ ] 新增 `selfCtx context.Context` 成员。 - **构造函数改造 (`NewUserService`)**: - [ ] 修改函数签名,移除 `logger *logs.Logger` 参数,改为接收 `ctx context.Context`。 - [ ] 在函数内部,为 `UserService` 创建其专属的 `selfCtx`:`selfCtx := logs.AddCompName(ctx, "UserService")`。 - [ ] 将这个 `selfCtx` 赋值给 `UserService` 结构体的 `selfCtx` 成员。 - **公共方法改造 (所有方法,例如 `CreateUser`, `Login`, `SendTestNotification`)**: - [ ] 修改方法签名,添加 `ctx context.Context` 作为第一个参数。 - [ ] 在方法入口处,使用 `newCtx, logger := logs.Trace(ctx, s.selfCtx, "MethodName")` 获取新的 `context.Context` 和 `logger` 实例。 - [ ] 将所有对 `s.logger.Errorf` 和 `s.logger.Infof` 的调用替换为 `logger.Errorf` 和 `logger.Infof`。 - [ ] 确保所有对 `s.repo`, `s.tokenService`, `s.notifier` 等依赖的调用都将 `newCtx` 作为第一个参数传递。