dev
Jing Li 2022-11-23 20:49:09 +08:00
parent c733101d1d
commit 71f4247ece
1 changed files with 18 additions and 12 deletions

View File

@ -45,10 +45,6 @@ class SoilMonitoringLogFixCommand extends Command
->get();
foreach ($devices as $device) {
if (SoilMonitoringLog::where('device_id', $device->id)->where('monitored_at', $time)->first()) {
continue;
}
$last = SoilMonitoringLog::where('device_id', $device->id)
->where('monitored_at', $time->copy()->subHour())
->first();
@ -58,18 +54,28 @@ class SoilMonitoringLogFixCommand extends Command
}
try {
SoilMonitoringLog::create([
$log = SoilMonitoringLog::firstOrCreate([
'device_id' => $device->id,
'agricultural_base_id' => $device->agricultural_base_id,
'conductivity' => $last->conductivity,
'humidity' => $last->humidity,
'temperature' => $last->temperature,
'n' => $last->n,
'p' => $last->p,
'k' => $last->k,
'monitored_at' => $time,
], [
'agricultural_base_id' => $device->agricultural_base_id,
]);
foreach ([
'conductivity',
'humidity',
'temperature',
'n',
'p',
'k',
] as $key) {
if (is_null($log->{$key})) {
$log->{$key} = $last->{$key};
}
}
$log->save();
$linkosDeviceLogService->handleSoilMonitoringDailyLog($device, $time);
} catch (Throwable $e) {
report($e);