command->warn('统计指标说明.json 文件不存在,跳过数据填充'); return; } $jsonContent = File::get($jsonPath); $data = json_decode($jsonContent, true); if (json_last_error() !== JSON_ERROR_NONE) { $this->command->error('JSON 文件解析失败:' . json_last_error_msg()); return; } if (!is_array($data)) { $this->command->error('JSON 数据格式不正确,应为对象/数组'); return; } // 清空现有数据(可选,根据需要决定是否保留) // StatisticsMetadata::truncate(); // 插入数据 foreach ($data as $key => $item) { StatisticsMetadata::updateOrCreate( ['key' => $key], [ 'name' => $item['name'] ?? '', 'from' => $item['from'] ?? '', 'verify' => $item['verify'] ?? '', ] ); } $this->command->info('统计指标元数据填充完成,共处理 ' . count($data) . ' 条记录'); } }