', $lastProcessedId) ->orderBy('id') ->limit($this->maxRecords) ->get(); } /** * 获取源表的最大ID * * 重写父类方法,使用模型查询以获得更好的性能 * * @return int */ public function getSourceTableMaxId(): int { return FarmHarvestLog::max('id') ?: 0; } /** * 转换记录为用户日志数据 * * @param FarmHarvestLog $record 农场收获记录 * @return array|null 用户日志数据,null表示跳过 */ protected function convertToUserLog($record): ?array { try { // 跳过收获数量为0的记录 if ($record->output_amount <= 0) { return null; } // 获取作物名称 $cropName = $this->getCropName($record->seed_id); // 构建收获消息 $message = "收获{$record->land_id}号土地的{$cropName},获得{$record->output_amount}个"; return $this->createUserLogData( $record->user_id, $message, $record->id, $record->created_at ); } catch (\Exception $e) { \Illuminate\Support\Facades\Log::error("转换农场收获日志失败", [ 'record_id' => $record->id, 'error' => $e->getMessage() ]); return null; } } /** * 获取作物名称 * * @param int $seedId 种子ID * @return string */ private function getCropName(int $seedId): string { try { // 尝试从配置中获取种子信息 $seedConfig = \App\Module\Farm\Models\FarmSeed::find($seedId); if ($seedConfig) { return $seedConfig->name; } return "作物{$seedId}"; } catch (\Exception $e) { return "作物{$seedId}"; } } }