Update
parent
c733101d1d
commit
71f4247ece
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue