更新
This commit is contained in:
@@ -10,6 +10,7 @@ use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\console\input\Option;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
|
||||
final class EsignSetup extends Command
|
||||
{
|
||||
@@ -17,7 +18,8 @@ final class EsignSetup extends Command
|
||||
{
|
||||
$this->setName('esign:setup')->setDescription('检查 e签宝配置、初始化内网 SDK 或恢复已归档签署结果')
|
||||
->addOption('initialize', null, Option::VALUE_NONE, '初始化已部署的 SDK;不创建医生、认证或处方签署')
|
||||
->addOption('recover', null, Option::VALUE_REQUIRED, '重新验签已归档的处方 ID;不会再次签署');
|
||||
->addOption('recover', null, Option::VALUE_REQUIRED, '重新验签已归档的处方 ID;不会再次签署')
|
||||
->addOption('backfill-signature-times', null, Option::VALUE_NONE, '从当前签署环境及应用的已验签原件补录签署时间');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output): int
|
||||
@@ -34,6 +36,9 @@ final class EsignSetup extends Command
|
||||
}
|
||||
PrescriptionEsignService::recover($id);
|
||||
$output->writeln('原件验签及状态恢复完成;未发送新的签署请求');
|
||||
} elseif ($input->getOption('backfill-signature-times')) {
|
||||
(new EsignClient())->assertConfigured();
|
||||
return $this->backfillSignatureTimes($config, $output);
|
||||
} elseif ($input->getOption('initialize')) {
|
||||
// Deployment may initialize before enabling the new clinical workflow.
|
||||
$client = new EsignClient(array_merge($config, ['enabled' => true]));
|
||||
@@ -49,4 +54,28 @@ final class EsignSetup extends Command
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function backfillSignatureTimes(array $config, Output $output): int
|
||||
{
|
||||
$filled = 0;
|
||||
$failed = 0;
|
||||
Db::name('prescription_esign')
|
||||
->where('environment', $config['environment'])->where('app_id', $config['app_id'])
|
||||
->where('signed_at', '>', 0)->where('signature_time', 0)->field('prescription_id')
|
||||
->chunk(100, static function ($rows) use ($output, &$filled, &$failed): void {
|
||||
foreach ($rows as $row) {
|
||||
$id = (int) $row['prescription_id'];
|
||||
try {
|
||||
PrescriptionEsignService::recover($id);
|
||||
$filled++;
|
||||
} catch (\Throwable $error) {
|
||||
$failed++;
|
||||
$message = $error instanceof \DomainException ? $error->getMessage() : '暂时无法验签,请检查 SDK 服务';
|
||||
$output->writeln("处方 {$id} 的签署时间待核实({$message})");
|
||||
}
|
||||
}
|
||||
}, 'prescription_id');
|
||||
$output->writeln("签署时间补录完成 {$filled} 张,待核实 {$failed} 张");
|
||||
return $failed === 0 ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user