so-manager-dev.com/app/Console/Commands/ShjOneCommand.php
Your Name 10a917b556
All checks were successful
Deploy so-manager (auto) / deploy (push) Successful in 24s
【更新】SHJ関連の修正
2025-10-10 19:55:46 +09:00

125 lines
3.6 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Services\ShjOneService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Exception;
/**
* SHJ-1 本人確認自動処理 Command
*
* 実行コマンド: php artisan shj:one {user_id} {park_id}
*/
class ShjOneCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'shj:one {user_id : 利用者連番} {park_id : 駐輪場ID}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'SHJ-1 本人確認自動処理 - 利用者の本人確認写真と登録情報の照合を行い自動判定する';
protected $shjOneService;
public function __construct(ShjOneService $shjOneService)
{
parent::__construct();
$this->shjOneService = $shjOneService;
}
/**
* Execute the console command.
*/
public function handle()
{
$startTime = now();
$processName = config('shj1.batch_log.process_name');
// 【処理0】パラメーターを取得する
$userId = $this->argument('user_id');
$parkId = $this->argument('park_id');
$parameters = [
'user_id' => $userId,
'park_id' => $parkId
];
$this->info("=== SHJ-1 本人確認自動処理 開始 ===");
$this->info("利用者ID: {$userId}");
$this->info("駐輪場ID: {$parkId}");
try {
// SHJ-1 メイン処理を実行
$result = $this->shjOneService->execute($userId, $parkId);
// 処理結果の表示
$this->displayResult($result);
// バッチログはShjOneServiceが自動的にSHJ-8経由で作成
$this->info("=== SHJ-1 本人確認自動処理 完了 ===");
// システムエラーまたは身元確認失敗の場合は exit code 1
$isSuccess = $result['system_success'] && ($result['identity_result'] ?? '') === 'OK';
return $isSuccess ? 0 : 1;
} catch (Exception $e) {
$this->error("SHJ-1処理中にエラーが発生しました: " . $e->getMessage());
// エラー時もShjOneServiceが自動的にバッチログを作成
Log::error('SHJ-1処理例外エラー', [
'user_id' => $userId,
'park_id' => $parkId,
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
return 1;
}
}
/**
* 処理結果を表示
*/
private function displayResult(array $result): void
{
$this->line('');
$this->info('=== 処理結果 ===');
if ($result['system_success']) {
$this->info("✓ 処理実行成功: " . $result['message']);
if (isset($result['identity_result'])) {
$identityStatus = $result['identity_result'] === 'OK' ? '✓ 本人確認OK' : '✗ 本人確認NG';
$this->line(" 本人確認結果: " . $identityStatus);
}
} else {
$this->error("✗ 処理実行失敗: " . $result['message']);
}
if (isset($result['details'])) {
foreach ($result['details'] as $key => $value) {
$this->line(" {$key}: {$value}");
}
}
if (isset($result['stats'])) {
$this->line('');
$this->info('=== 統計情報 ===');
foreach ($result['stats'] as $key => $value) {
$this->line(" {$key}: {$value}");
}
}
}
}