api.so-manager-dev.com/app/Console/Commands/ShjNineCommand.php
unhi.go e1073e2577
All checks were successful
Deploy api / deploy (push) Successful in 24s
SH-6 SHJ-9 実装
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 20:16:47 +08:00

111 lines
3.3 KiB
PHP
Raw 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\ShjNineService;
/**
* SHJ-9 売上集計処理コマンド
*
* 駐輪場の売上データを日次で集計する処理を実行する
* バックグラウンドで実行される定期バッチ処理
*/
class ShjNineCommand extends Command
{
/**
* コンソールコマンドの名前とシグネチャ
*
* 引数:
* - target_date: 集計対象日 (オプション、YYYY-MM-DD形式)
*
* @var string
*/
protected $signature = 'shj:9 {target_date? : 集計対象日(YYYY-MM-DD)}';
/**
* コンソールコマンドの説明
*
* @var string
*/
protected $description = 'SHJ-9 売上集計処理 - 日次売上データ集計を実行';
/**
* SHJ-9サービスクラス
*
* @var ShjNineService
*/
protected $shjNineService;
/**
* コンストラクタ
*
* @param ShjNineService $shjNineService
*/
public function __construct(ShjNineService $shjNineService)
{
parent::__construct();
$this->shjNineService = $shjNineService;
}
/**
* コンソールコマンドを実行
*
* 処理フロー:
* 1. 集計対象日設定JOB1
* 2. 売上集計処理実行JOB2JOB4
* 3. バッチログ作成JOB5
*
* 日付バリデーション・バッチログ作成はService側で実施
* ステータスは常にsuccess式様書準拠
*
* @return int
*/
public function handle()
{
// 開始ログ出力
$startTime = now();
$this->info('SHJ-9 売上集計処理を開始します。');
// 集計種別は日次固定SHJ-9は日次のみ
$type = 'daily';
// 集計対象日設定JOB1
$targetDate = $this->argument('target_date');
// パラメータ指定がない場合は昨日本日の1日前
$aggregationDate = $targetDate ?? now()->subDay()->format('Y-m-d');
Log::info('SHJ-9 売上集計処理開始', [
'start_time' => $startTime,
'type' => $type,
'target_date' => $aggregationDate
]);
$this->info("集計種別: {$type}");
$this->info("集計対象日: {$aggregationDate}");
// SHJ-9処理実行日付バリデーション・バッチログ作成含む
$result = $this->shjNineService->executeEarningsAggregation($type, $aggregationDate);
$endTime = now();
$this->info("処理時間: {$startTime->diffInSeconds($endTime)}");
if ($result['success']) {
$this->info('SHJ-9 売上集計処理が正常に完了しました。');
$this->info("処理結果: 駐輪場数 {$result['processed_parks']}, 集計レコード数 {$result['summary_records']}");
} else {
$this->info('SHJ-9 売上集計処理が完了しました(エラーあり): ' . $result['message']);
}
Log::info('SHJ-9 売上集計処理完了', [
'end_time' => $endTime,
'duration_seconds' => $startTime->diffInSeconds($endTime),
'result' => $result
]);
// 式様書準拠: ステータスは常にsuccess
return self::SUCCESS;
}
}