This commit is contained in:
Your Name
2026-11-17 17:06:05 +08:00
parent 08892f4270
commit 378bf32069
51 changed files with 4656 additions and 103 deletions
+52
View File
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace app\command;
use app\common\service\esign\EsignClient;
use app\common\service\esign\PrescriptionEsignService;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Option;
use think\facade\Config;
final class EsignSetup extends Command
{
protected function configure(): void
{
$this->setName('esign:setup')->setDescription('检查 e签宝配置、初始化内网 SDK 或恢复已归档签署结果')
->addOption('initialize', null, Option::VALUE_NONE, '初始化已部署的 SDK;不创建医生、认证或处方签署')
->addOption('recover', null, Option::VALUE_REQUIRED, '重新验签已归档的处方 ID;不会再次签署');
}
protected function execute(Input $input, Output $output): int
{
$config = (array) Config::get('esign', []);
$output->writeln('environment=' . ($config['environment'] ?? 'sandbox'));
$output->writeln('enabled=' . (PrescriptionEsignService::enabled() ? 'true' : 'false'));
$output->writeln('credentials=' . (!empty($config['app_id']) && !empty($config['app_secret']) ? 'configured' : 'missing'));
try {
if ($input->getOption('recover') !== null) {
$id = filter_var($input->getOption('recover'), FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if (!$id) {
throw new \DomainException('recover 必须为正整数处方ID');
}
PrescriptionEsignService::recover($id);
$output->writeln('原件验签及状态恢复完成;未发送新的签署请求');
} elseif ($input->getOption('initialize')) {
// Deployment may initialize before enabling the new clinical workflow.
$client = new EsignClient(array_merge($config, ['enabled' => true]));
$client->assertConfigured();
$client->initialize();
$output->writeln('SDK 初始化成功;尚未执行医生核身或处方签署');
} else {
$output->writeln('配置检查完成;部署 SDK 后使用 --initialize,完成数据库迁移后再启用签署');
}
return 0;
} catch (\Throwable $e) {
$output->writeln('<error>' . ($e instanceof \DomainException ? $e->getMessage() : 'SDK 操作失败,请检查内网服务、应用环境和 e签宝 IP 白名单') . '</error>');
return 1;
}
}
}