Update
parent
71f4247ece
commit
57237a5048
|
|
@ -76,7 +76,9 @@ class SoilMonitoringLogFixCommand extends Command
|
||||||
|
|
||||||
$log->save();
|
$log->save();
|
||||||
|
|
||||||
$linkosDeviceLogService->handleSoilMonitoringDailyLog($device, $time);
|
if ($log->wasChanged()) {
|
||||||
|
$linkosDeviceLogService->handleSoilMonitoringDailyLog($device, $time);
|
||||||
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,6 @@ class WaterQualityMonitoringLogFixCommand extends Command
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($devices as $device) {
|
foreach ($devices as $device) {
|
||||||
if (WaterQualityMonitoringLog::where('device_id', $device->id)->where('monitored_at', $time)->first()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$last = WaterQualityMonitoringLog::where('device_id', $device->id)
|
$last = WaterQualityMonitoringLog::where('device_id', $device->id)
|
||||||
->where('monitored_at', $time->copy()->subHour())
|
->where('monitored_at', $time->copy()->subHour())
|
||||||
->first();
|
->first();
|
||||||
|
|
@ -58,19 +54,31 @@ class WaterQualityMonitoringLogFixCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WaterQualityMonitoringLog::create([
|
$log = WaterQualityMonitoringLog::firstOrCreate([
|
||||||
'device_id' => $device->id,
|
'device_id' => $device->id,
|
||||||
'agricultural_base_id' => $device->agricultural_base_id,
|
|
||||||
'chlorine' => $last->chlorine,
|
|
||||||
'conductivity' => $last->conductivity,
|
|
||||||
'oxygen' => $last->oxygen,
|
|
||||||
'ph' => $last->ph,
|
|
||||||
'temperature' => $last->temperature,
|
|
||||||
'turbidity' => $last->turbidity,
|
|
||||||
'monitored_at' => $time,
|
'monitored_at' => $time,
|
||||||
|
], [
|
||||||
|
'agricultural_base_id' => $device->agricultural_base_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$linkosDeviceLogService->handleWaterQualityMonitoringDailyLog($device, $time);
|
foreach ([
|
||||||
|
'chlorine',
|
||||||
|
'conductivity',
|
||||||
|
'oxygen',
|
||||||
|
'ph',
|
||||||
|
'temperature',
|
||||||
|
'turbidity',
|
||||||
|
] as $key) {
|
||||||
|
if (is_null($log->{$key})) {
|
||||||
|
$log->{$key} = $last->{$key};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
if ($log->wasChanged()) {
|
||||||
|
$linkosDeviceLogService->handleWaterQualityMonitoringDailyLog($device, $time);
|
||||||
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue