From da9f79b32bd64732f3946d7167ba445e0d6c00d9 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Wed, 12 Nov 2025 15:06:45 +0900 Subject: [PATCH] trafficmonitor init...2 --- app/Models/CollectorModel.php | 8 ++++++++ app/Services/CollectorService.php | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Models/CollectorModel.php b/app/Models/CollectorModel.php index d66c29f..ac6fd44 100644 --- a/app/Models/CollectorModel.php +++ b/app/Models/CollectorModel.php @@ -26,4 +26,12 @@ class CollectorModel extends CommonModel { parent::__construct(); } + + public function getLastEntity($uid): CollectorEntity|null + { + return $this + ->where('trafficinfo_uid', $uid) + ->orderBy('created_at', 'DESC') + ->first(); // 첫 번째 레코드(=가장 최신) + } } diff --git a/app/Services/CollectorService.php b/app/Services/CollectorService.php index 91230bd..b6f71e6 100644 --- a/app/Services/CollectorService.php +++ b/app/Services/CollectorService.php @@ -109,11 +109,7 @@ class CollectorService extends CommonService throw new \Exception($message); } // 이전 데이터를 조회하여 Rate 계산에 사용 - $lastEntity = $this->model - ->where('trafficinfo_uid', $trafficEntity->getPK()) - ->orderBy('created_at', 'DESC') - ->first(); - dd($lastEntity); + $lastEntity = $this->model->getLastEntity($trafficEntity->getPK()); $inKbitsSec = 0.0; $outKbitsSec = 0.0; // 이전 데이터가 있어야만 Rate 계산 가능