update: stat command

This commit is contained in:
v2board 2023-06-05 13:56:45 +08:00
parent 228355a520
commit b39299be23

View File

@ -61,6 +61,7 @@ class V2boardStatistics extends Command
$statService->setStartAt($recordAt);
$statService->setServerStats();
$stats = $statService->getStatServer();
try {
DB::beginTransaction();
foreach ($stats as $stat) {
if (!StatServer::insert([
@ -73,12 +74,15 @@ class V2boardStatistics extends Command
'record_type' => 'd',
'record_at' => $recordAt
])) {
DB::rollback();
throw new \Exception('stat server fail');
}
}
DB::commit();
$statService->clearStatServer();
} catch (\Exception $e) {
DB::rollback();
$this->error($e->getMessage());
}
}
private function statUser()
@ -89,6 +93,7 @@ class V2boardStatistics extends Command
$statService->setStartAt($recordAt);
$statService->setUserStats();
$stats = $statService->getStatUser();
try {
DB::beginTransaction();
foreach ($stats as $stat) {
if (!StatUser::insert([
@ -101,12 +106,15 @@ class V2boardStatistics extends Command
'record_type' => 'd',
'record_at' => $recordAt
])) {
DB::rollback();
throw new \Exception('stat user fail');
}
}
DB::commit();
$statService->clearStatUser();
} catch (\Exception $e) {
DB::rollback();
$this->error($e->getMessage());
}
}
private function stat()