143 lines
4.6 KiB
PHP
143 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\ShjOneService;
|
|
use App\Models\Batch\BatchLog;
|
|
use Illuminate\Console\Command;
|
|
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-8共通処理
|
|
$batchLog = BatchLog::createBatchLog(
|
|
'SHJ-1本人確認自動処理',
|
|
BatchLog::STATUS_START,
|
|
$parameters,
|
|
'SHJ-1処理開始: 利用者ID=' . $userId . ', 駐輪場ID=' . $parkId
|
|
);
|
|
|
|
// SHJ-1 メイン処理を実行
|
|
$result = $this->shjOneService->execute($userId, $parkId);
|
|
|
|
// 処理結果の表示
|
|
$this->displayResult($result);
|
|
|
|
// バッチログ完了 - 実際の処理結果に基づく
|
|
$logStatus = $result['log_status'] ?? ($result['system_success'] ? BatchLog::STATUS_SUCCESS : BatchLog::STATUS_ERROR);
|
|
$batchLog->update([
|
|
'status' => $logStatus,
|
|
'end_time' => now(),
|
|
'message' => $result['message'],
|
|
'success_count' => $result['stats']['success_count'] ?? 0,
|
|
'error_count' => $result['stats']['error_count'] ?? 0,
|
|
'execution_count' => $result['stats']['processed_count'] ?? 1
|
|
]);
|
|
|
|
$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());
|
|
|
|
// エラーログ記録
|
|
if (isset($batchLog)) {
|
|
$batchLog->update([
|
|
'status' => BatchLog::STATUS_ERROR,
|
|
'end_time' => now(),
|
|
'message' => $e->getMessage(),
|
|
'error_details' => $e->getMessage(),
|
|
'error_count' => 1
|
|
]);
|
|
}
|
|
|
|
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}");
|
|
}
|
|
}
|
|
}
|
|
}
|