so-manager-dev.com/app/Console/Commands/ShjBatchLogCommand.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

164 lines
5.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use App\Services\ShjEightService;
/**
* SHJ-8 バッチ処理ログ登録コマンド
*
* bat_job_logテーブルにバッチ処理の実行ログを登録する
* ShjEightServiceを使用して実装
*/
class ShjBatchLogCommand extends Command
{
/**
* ShjEightService インスタンス
*
* @var ShjEightService
*/
protected $shjEightService;
/**
* コンソールコマンドの名前とシグネチャ
*
* 修正版7項目status_comment追加
* - device_id: デバイスID (必須)
* - status: ステータス (必須)
* - status_comment: ステータスコメント (必須)
* - created_date: 登録日時 (必須、yyyy/mm/dd形式)
* - updated_date: 更新日時 (必須、yyyy/mm/dd形式)
* - process_name: プロセス名 (オプション)
* - job_name: ジョブ名 (オプション)
*
* @var string
*/
protected $signature = 'shj:batch-log
{device_id : デバイスID}
{status : ステータス}
{status_comment : ステータスコメント}
{created_date : 登録日時}
{updated_date : 更新日時}
{process_name? : プロセス名}
{job_name? : ジョブ名}';
/**
* コンソールコマンドの説明
*
* @var string
*/
protected $description = 'SHJ-8 バッチ処理ログ登録 - bat_job_logテーブルにバッチ処理の実行ログを登録';
/**
* コンストラクタ
*
* @param ShjEightService $shjEightService
*/
public function __construct(ShjEightService $shjEightService)
{
parent::__construct();
$this->shjEightService = $shjEightService;
}
/**
* コンソールコマンドを実行
*
* 処理フロー:
* 1. ShjEightServiceを呼び出して処理を実行
* 2. 処理結果を返却する
*
* @return int
*/
public function handle()
{
try {
// 開始ログ出力
$startTime = now();
$this->info('SHJ-8 バッチ処理ログ登録を開始します。');
// 引数取得
$deviceId = (int) $this->argument('device_id');
$processName = $this->argument('process_name');
$jobName = $this->argument('job_name');
$status = $this->argument('status');
$statusComment = $this->argument('status_comment');
$createdDate = $this->argument('created_date');
$updatedDate = $this->argument('updated_date');
Log::info('SHJ-8 バッチ処理ログ登録開始', [
'start_time' => $startTime,
'device_id' => $deviceId,
'process_name' => $processName,
'job_name' => $jobName,
'status' => $status,
'status_comment' => $statusComment,
'created_date' => $createdDate,
'updated_date' => $updatedDate
]);
// ShjEightServiceを呼び出して処理を実行
$result = $this->shjEightService->execute(
$deviceId,
$processName,
$jobName,
$status,
$statusComment,
$createdDate,
$updatedDate
);
$endTime = now();
// 処理結果に応じた出力
if ($result['result'] === 0) {
// 正常終了
$this->info('SHJ-8 バッチ処理ログ登録が正常に完了しました。');
$this->info("処理時間: {$startTime->diffInSeconds($endTime)}");
// 標準出力形式 (SHJ-8仕様書準拠)
$this->line('処理結果: 0');
$this->line('異常情報: ');
Log::info('SHJ-8 バッチ処理ログ登録完了', [
'end_time' => $endTime,
'duration_seconds' => $startTime->diffInSeconds($endTime)
]);
return self::SUCCESS;
} else {
// 異常終了
$errorMessage = $result['error_message'] ?? '不明なエラー';
$this->error('SHJ-8 バッチ処理ログ登録エラー: ' . $errorMessage);
// 標準出力形式 (SHJ-8仕様書準拠)
$this->line('処理結果: 1');
$this->line('異常情報: ' . $errorMessage);
Log::error('SHJ-8 バッチ処理ログ登録エラー', [
'error_message' => $errorMessage,
'error_code' => $result['error_code'] ?? null
]);
return self::FAILURE;
}
} catch (\Exception $e) {
$this->error('SHJ-8 バッチ処理ログ登録で予期しないエラーが発生しました: ' . $e->getMessage());
// 標準出力形式 (SHJ-8仕様書準拠 - 例外時)
$this->line('処理結果: 1');
$this->line('異常情報: ' . $e->getMessage());
Log::error('SHJ-8 バッチ処理ログ登録例外エラー', [
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
return self::FAILURE;
}
}
}