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

30 KiB
Raw Blame History

  • internal/infra/repository/unit_of_work.go (repository.UnitOfWork - gormUnitOfWork 实现)

    • 接口改造 (UnitOfWork):
      • 修改 UnitOfWork 接口中的 ExecuteInTransaction 方法签名,使其接收 ctx context.Context 作为第一个参数: ExecuteInTransaction(ctx context.Context, fn func(tx *gorm.DB) error) error
    • 结构体改造 (gormUnitOfWork):
      • 移除 gormUnitOfWork 结构体中的 logger *logs.Logger 成员。
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormUnitOfWork):
      • 修改函数签名,移除 logger *logs.Logger 参数,改为接收 ctx context.Context
      • 在函数内部,为 gormUnitOfWork 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "GormUnitOfWork")
      • 将这个 selfCtx 赋值给 gormUnitOfWork 结构体的 selfCtx 成员。
    • 方法改造 (ExecuteInTransaction):
      • 修改方法签名,使其接收 ctx context.Context 作为第一个参数: (u *gormUnitOfWork) ExecuteInTransaction(ctx context.Context, fn func(tx *gorm.DB) error) error
      • 在方法入口处,使用 newCtx, logger := logs.Trace(ctx, u.selfCtx, "ExecuteInTransaction") 获取新的 context.Contextlogger 实例。
      • 将所有对 u.logger.Errorf 的调用替换为 logger.Errorf
      • 在开启事务时,使用 tx := u.db.WithContext(newCtx).Begin(),确保事务 tx 携带了正确的上下文。
  • internal/infra/repository/plan_repository.go (repository.PlanRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPlanRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPlanRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PlanRepository")
      • 将这个 selfCtx 赋值给 gormPlanRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/user_repository.go (repository.UserRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormUserRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormUserRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "UserRepository")
      • 将这个 selfCtx 赋值给 gormUserRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/device_repository.go (repository.DeviceRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormDeviceRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormDeviceRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "DeviceRepository")
      • 将这个 selfCtx 赋值给 gormDeviceRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_pen_repository.go (repository.PigPenRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigPenRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigPenRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigPenRepository")
      • 将这个 selfCtx 赋值给 gormPigPenRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_farm_repository.go (repository.PigFarmRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigFarmRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigFarmRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigFarmRepository")
      • 将这个 selfCtx 赋值给 gormPigFarmRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_sick_repository.go (repository.PigSickLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigSickLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigSickLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigSickLogRepository")
      • 将这个 selfCtx 赋值给 gormPigSickLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_batch_repository.go (repository.PigBatchRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigBatchRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigBatchRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigBatchRepository")
      • 将这个 selfCtx 赋值给 gormPigBatchRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_trade_repository.go (repository.PigTradeRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigTradeRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigTradeRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigTradeRepository")
      • 将这个 selfCtx 赋值给 gormPigTradeRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/sensor_data_repository.go (repository.SensorDataRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormSensorDataRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormSensorDataRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "SensorDataRepository")
      • 将这个 selfCtx 赋值给 gormSensorDataRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/notification_repository.go (repository.NotificationRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormNotificationRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormNotificationRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "NotificationRepository")
      • 将这个 selfCtx 赋值给 gormNotificationRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pending_task_repository.go (repository.PendingTaskRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPendingTaskRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPendingTaskRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PendingTaskRepository")
      • 将这个 selfCtx 赋值给 gormPendingTaskRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/raw_material_repository.go (repository.RawMaterialRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormRawMaterialRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormRawMaterialRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "RawMaterialRepository")
      • 将这个 selfCtx 赋值给 gormRawMaterialRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/execution_log_repository.go (repository.ExecutionLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormExecutionLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormExecutionLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "ExecutionLogRepository")
      • 将这个 selfCtx 赋值给 gormExecutionLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_batch_log_repository.go (repository.PigBatchLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigBatchLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigBatchLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigBatchLogRepository")
      • 将这个 selfCtx 赋值给 gormPigBatchLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/medication_log_repository.go (repository.MedicationLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormMedicationLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormMedicationLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "MedicationLogRepository")
      • 将这个 selfCtx 赋值给 gormMedicationLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/area_controller_repository.go (repository.AreaControllerRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormAreaControllerRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormAreaControllerRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "AreaControllerRepository")
      • 将这个 selfCtx 赋值给 gormAreaControllerRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/device_template_repository.go (repository.DeviceTemplateRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormDeviceTemplateRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormDeviceTemplateRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "DeviceTemplateRepository")
      • 将这个 selfCtx 赋值给 gormDeviceTemplateRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/user_action_log_repository.go (repository.UserActionLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormUserActionLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormUserActionLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "UserActionLogRepository")
      • 将这个 selfCtx 赋值给 gormUserActionLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_transfer_log_repository.go (repository.PigTransferLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigTransferLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigTransferLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigTransferLogRepository")
      • 将这个 selfCtx 赋值给 gormPigTransferLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/device_command_log_repository.go (repository.DeviceCommandLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormDeviceCommandLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormDeviceCommandLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "DeviceCommandLogRepository")
      • 将这个 selfCtx 赋值给 gormDeviceCommandLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pending_collection_repository.go (repository.PendingCollectionRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPendingCollectionRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPendingCollectionRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PendingCollectionRepository")
      • 将这个 selfCtx 赋值给 gormPendingCollectionRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/raw_material_repository.go (repository.RawMaterialRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormRawMaterialRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormRawMaterialRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "RawMaterialRepository")
      • 将这个 selfCtx 赋值给 gormRawMaterialRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/execution_log_repository.go (repository.ExecutionLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormExecutionLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormExecutionLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "ExecutionLogRepository")
      • 将这个 selfCtx 赋值给 gormExecutionLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_batch_log_repository.go (repository.PigBatchLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigBatchLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigBatchLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigBatchLogRepository")
      • 将这个 selfCtx 赋值给 gormPigBatchLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/medication_log_repository.go (repository.MedicationLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormMedicationLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormMedicationLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "MedicationLogRepository")
      • 将这个 selfCtx 赋值给 gormMedicationLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/area_controller_repository.go (repository.AreaControllerRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormAreaControllerRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormAreaControllerRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "AreaControllerRepository")
      • 将这个 selfCtx 赋值给 gormAreaControllerRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/device_template_repository.go (repository.DeviceTemplateRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormDeviceTemplateRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormDeviceTemplateRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "DeviceTemplateRepository")
      • 将这个 selfCtx 赋值给 gormDeviceTemplateRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/user_action_log_repository.go (repository.UserActionLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormUserActionLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormUserActionLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "UserActionLogRepository")
      • 将这个 selfCtx 赋值给 gormUserActionLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx)tx.WithContext(newCtx)
  • internal/infra/repository/pig_transfer_log_repository.go (repository.PigTransferLogRepository)

    • 结构体改造:
      • 新增 selfCtx context.Context 成员。
    • 构造函数改造 (NewGormPigTransferLogRepository):
      • 修改函数签名,添加 ctx context.Context 作为第一个参数。
      • 在函数内部,为 gormPigTransferLogRepository 创建其专属的 selfCtx selfCtx := logs.AddCompName(ctx, "PigTransferLogRepository")
      • 将这个 selfCtx 赋值给 gormPigTransferLogRepository 结构体的 selfCtx 成员。
    • 公共方法改造 (所有公共方法):
      • 修改方法签名,添加 ctx context.Context 作为第一个参数。
      • 在方法入口处,使用 newCtx := logs.AddFuncName(ctx, r.selfCtx, "MethodName")
      • 确保所有对 r.dbtx 的调用都使用 r.db.WithContext(newCtx) 或 `tx.WithContext(new