1
0
Fork 0
vine_liutk 2023-05-08 17:06:49 +08:00
commit 8dc26a1b30
2 changed files with 7 additions and 3 deletions

View File

@ -68,7 +68,7 @@ class DeviceLogReportCommand extends Command
$lastReportedAt = $lastMonitoringReport?->reported_at; $lastReportedAt = $lastMonitoringReport?->reported_at;
$device->logs() $device->logs()
->when($lastReportedAt, fn ($query, $lastReportedAt) => $query->where('reported_at', '>=', $lastReportedAt->reported_at)) ->when($lastReportedAt, fn ($query, $lastReportedAt) => $query->where('reported_at', '>=', $lastReportedAt))
->oldest('reported_at') ->oldest('reported_at')
->chunkById(500, function ($deviceLogs) use ($device, &$lastMonitoringReport) { ->chunkById(500, function ($deviceLogs) use ($device, &$lastMonitoringReport) {
/** @var \App\Models\DeviceLog */ /** @var \App\Models\DeviceLog */
@ -109,7 +109,7 @@ class DeviceLogReportCommand extends Command
$lastReportedAt = $lastMonitoringReport?->reported_at; $lastReportedAt = $lastMonitoringReport?->reported_at;
$device->logs() $device->logs()
->when($lastReportedAt, fn ($query, $lastReportedAt) => $query->where('reported_at', '>=', $lastReportedAt->reported_at)) ->when($lastReportedAt, fn ($query, $lastReportedAt) => $query->where('reported_at', '>=', $lastReportedAt))
->oldest('reported_at') ->oldest('reported_at')
->chunkById(500, function ($deviceLogs) use ($device, &$lastMonitoringReport) { ->chunkById(500, function ($deviceLogs) use ($device, &$lastMonitoringReport) {
/** @var \App\Models\DeviceLog */ /** @var \App\Models\DeviceLog */
@ -150,7 +150,7 @@ class DeviceLogReportCommand extends Command
$lastReportedAt = $lastMonitoringReport?->reported_at; $lastReportedAt = $lastMonitoringReport?->reported_at;
$device->logs() $device->logs()
->when($lastReportedAt, fn ($query, $lastReportedAt) => $query->where('reported_at', '>=', $lastReportedAt->reported_at)) ->when($lastReportedAt, fn ($query, $lastReportedAt) => $query->where('reported_at', '>=', $lastReportedAt))
->oldest('reported_at') ->oldest('reported_at')
->chunkById(500, function ($deviceLogs) use ($device, &$lastMonitoringReport) { ->chunkById(500, function ($deviceLogs) use ($device, &$lastMonitoringReport) {
/** @var \App\Models\DeviceLog */ /** @var \App\Models\DeviceLog */

View File

@ -45,6 +45,10 @@ class DeviceLogService
} }
foreach ($data['content'] as $item) { foreach ($data['content'] as $item) {
if (! isset($item['data'])) {
continue;
}
$isSoilMonitoring = Arr::hasAny($item['data'], [ $isSoilMonitoring = Arr::hasAny($item['data'], [
'soil_humidity', 'soil_humidity',
'soil_temperature', 'soil_temperature',