All checks were successful
Deploy so-manager (auto) / deploy (push) Successful in 21s
SHJ-13契約台数追加
155 lines
5.4 KiB
PHP
155 lines
5.4 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Log;
|
||
use App\Services\ShjThirteenService;
|
||
|
||
/**
|
||
* SHJ-13 契約台数追加処理コマンド
|
||
*
|
||
* 指定されたパラメータで契約台数をpark_number・zoneテーブルに反映する
|
||
* 主にSHJ-4Bから呼び出されるが、独立実行も可能
|
||
*/
|
||
class ShjThirteenCommand extends Command
|
||
{
|
||
/**
|
||
* コンソールコマンドの名前とシグネチャ
|
||
*
|
||
* 引数:
|
||
* - park_id: 駐輪場ID (必須)
|
||
* - psection_id: 車種区分ID (必須)
|
||
* - ptype_id: 駐輪分類ID (必須)
|
||
* - zone_id: ゾーンID (必須)
|
||
*
|
||
* オプション:
|
||
* - contract_id: 契約ID (任意、ログ用)
|
||
*
|
||
* @var string
|
||
*/
|
||
protected $signature = 'shj:13
|
||
{park_id : 駐輪場ID}
|
||
{psection_id : 車種区分ID}
|
||
{ptype_id : 駐輪分類ID}
|
||
{zone_id : ゾーンID}
|
||
{--contract_id= : 契約ID(ログ用、任意)}';
|
||
|
||
/**
|
||
* コンソールコマンドの説明
|
||
*
|
||
* @var string
|
||
*/
|
||
protected $description = 'SHJ-13 契約台数追加処理 - park_number・zoneテーブルの契約台数を+1更新しログ記録';
|
||
|
||
/**
|
||
* SHJ-13サービスクラス
|
||
*
|
||
* @var ShjThirteenService
|
||
*/
|
||
protected $shjThirteenService;
|
||
|
||
/**
|
||
* コンストラクタ
|
||
*
|
||
* @param ShjThirteenService $shjThirteenService
|
||
*/
|
||
public function __construct(ShjThirteenService $shjThirteenService)
|
||
{
|
||
parent::__construct();
|
||
$this->shjThirteenService = $shjThirteenService;
|
||
}
|
||
|
||
/**
|
||
* コンソールコマンドを実行
|
||
*
|
||
* 処理フロー:
|
||
* 1. 引数取得・検証
|
||
* 2. ShjThirteenService実行
|
||
* 3. 結果表示
|
||
*
|
||
* @return int
|
||
*/
|
||
public function handle()
|
||
{
|
||
try {
|
||
// 開始ログ出力
|
||
$startTime = now();
|
||
$this->info('SHJ-13 契約台数追加処理を開始します。');
|
||
|
||
// 引数取得
|
||
$contractData = [
|
||
'park_id' => (int) $this->argument('park_id'),
|
||
'psection_id' => (int) $this->argument('psection_id'),
|
||
'ptype_id' => (int) $this->argument('ptype_id'),
|
||
'zone_id' => (int) $this->argument('zone_id'),
|
||
'contract_id' => $this->option('contract_id'),
|
||
];
|
||
|
||
Log::info('SHJ-13 契約台数追加処理開始', [
|
||
'start_time' => $startTime,
|
||
'contract_data' => $contractData,
|
||
]);
|
||
|
||
$this->info("駐輪場ID: {$contractData['park_id']}");
|
||
$this->info("車種区分ID: {$contractData['psection_id']}");
|
||
$this->info("駐輪分類ID: {$contractData['ptype_id']}");
|
||
$this->info("ゾーンID: {$contractData['zone_id']}");
|
||
if ($contractData['contract_id']) {
|
||
$this->info("契約ID: {$contractData['contract_id']}");
|
||
}
|
||
|
||
// SHJ-13処理実行
|
||
$this->info('【処理実行】契約台数追加処理を実行しています...');
|
||
$result = $this->shjThirteenService->execute($contractData);
|
||
|
||
// 処理結果確認・表示
|
||
if ($result['result'] === 0) {
|
||
$endTime = now();
|
||
$this->info('SHJ-13 契約台数追加処理が正常に完了しました。');
|
||
$this->info("処理時間: {$startTime->diffInSeconds($endTime)}秒");
|
||
|
||
Log::info('SHJ-13 契約台数追加処理完了', [
|
||
'end_time' => $endTime,
|
||
'duration_seconds' => $startTime->diffInSeconds($endTime),
|
||
'contract_data' => $contractData,
|
||
]);
|
||
|
||
// 成功時の結果出力
|
||
$this->line('処理結果: 0'); // 0 = 正常終了
|
||
$this->line('異常情報: '); // 正常時は空文字
|
||
|
||
return self::SUCCESS;
|
||
} else {
|
||
$this->error('SHJ-13 契約台数追加処理でエラーが発生しました。');
|
||
$this->error("エラーコード: {$result['error_code']}");
|
||
$this->error("エラーメッセージ: {$result['error_message']}");
|
||
|
||
Log::error('SHJ-13 契約台数追加処理エラー', [
|
||
'contract_data' => $contractData,
|
||
'error_result' => $result,
|
||
]);
|
||
|
||
// エラー時の結果出力
|
||
$this->line('処理結果: 1'); // 1 = 異常終了
|
||
$this->line('異常情報: ' . $result['error_message']);
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
} catch (\Exception $e) {
|
||
$this->error('SHJ-13 契約台数追加処理で予期しないエラーが発生しました: ' . $e->getMessage());
|
||
Log::error('SHJ-13 契約台数追加処理例外エラー', [
|
||
'exception' => $e->getMessage(),
|
||
'trace' => $e->getTraceAsString(),
|
||
]);
|
||
|
||
// 例外時の結果出力
|
||
$this->line('処理結果: 1'); // 1 = 異常終了
|
||
$this->line('異常情報: システムエラー: ' . $e->getMessage());
|
||
|
||
return self::FAILURE;
|
||
}
|
||
}
|
||
}
|