setName('prescription-ai:backfill')->setDescription('预览或分批补登记手工处方AI任务,不调用模型') ->addOption('from', null, Option::VALUE_REQUIRED, '开始日期 YYYY-MM-DD') ->addOption('to', null, Option::VALUE_REQUIRED, '结束日期 YYYY-MM-DD') ->addOption('after-id', null, Option::VALUE_REQUIRED, '上次返回的游标', '0') ->addOption('limit', null, Option::VALUE_REQUIRED, '每批最多200', '50') ->addOption('apply', null, Option::VALUE_NONE, '确认将本批登记为后台任务'); } protected function execute(Input $input, Output $output): int { foreach (['from', 'to'] as $key) { $value = (string) $input->getOption($key); if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) || date('Y-m-d', strtotime($value)) !== $value) { $output->writeln('Explicit valid from/to dates are required'); return 1; } } if ($input->getOption('apply') && !PrescriptionAiStore::enabled()) { $output->writeln('Enable prescription_analysis before enqueueing'); return 1; } $from = strtotime((string) $input->getOption('from')); $to = strtotime((string) $input->getOption('to') . ' 23:59:59'); if ($from > $to) { $output->writeln('Invalid date range'); return 1; } $result = (new PrescriptionAiWorker())->reconcile((int) $input->getOption('after-id'), (int) $input->getOption('limit'), $from, $to, (bool) $input->getOption('apply')); $output->writeln(json_encode(['dry_run' => !$input->getOption('apply')] + $result)); return 0; } }