Update
parent
470c9c25c9
commit
11da69f2b3
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Linkos;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\WaterQualityMonitoringDailyLog;
|
||||
use App\Models\WaterQualityMonitoringLog;
|
||||
use App\Services\LinkosDeviceLogService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class WaterQualityReportCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'linkos:water-quality-report';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'linkos 水质设备数据构造';
|
||||
|
||||
/**
|
||||
* @var \App\Services\LinkosDeviceLogService
|
||||
*/
|
||||
protected $linkosDeviceLogService;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(LinkosDeviceLogService $linkosDeviceLogService)
|
||||
{
|
||||
$this->linkosDeviceLogService = $linkosDeviceLogService;
|
||||
|
||||
$startAt = Carbon::createFromFormat('Y-m-d H:00:00', '2024-04-01 00:00:00');
|
||||
|
||||
do {
|
||||
$this->fill($startAt);
|
||||
$startAt->addHour();
|
||||
} while ($startAt->lt('2024-06-03 20:00:00'));
|
||||
}
|
||||
|
||||
protected function fill(Carbon $monitoredAt)
|
||||
{
|
||||
$linkosDeviceLogService = new LinkosDeviceLogService();
|
||||
|
||||
$data = [
|
||||
'conductivity' => rand(560, 565),
|
||||
'oxygen' => rand(1000, 1100) / 100,
|
||||
'chlorine' => rand(8, 10) / 100,
|
||||
'turbidity' => rand(100000, 103000) / 100,
|
||||
'temp' => null,
|
||||
'ph' => rand(750, 760) / 100,
|
||||
'is_filled' => false,
|
||||
];
|
||||
|
||||
$devices = Device::where('sn', '004A7701240041C9')->oldest('id')->get();
|
||||
|
||||
foreach ($devices as $device) {
|
||||
if (! $data['is_filled']) {
|
||||
$lastWaterQualityMonitoringLog = WaterQualityMonitoringLog::where('device_id', $device->id)
|
||||
->whereBetween('monitored_at', [$monitoredAt->copy()->startOfDay(), $monitoredAt])
|
||||
->latest('monitored_at')
|
||||
->first();
|
||||
|
||||
if ($lastWaterQualityMonitoringLog) {
|
||||
$temperature = $lastWaterQualityMonitoringLog->temperature;
|
||||
|
||||
if ($monitoredAt->hour <= 5) {
|
||||
$temperature -= ($monitoredAt->hour - $lastWaterQualityMonitoringLog->monitored_at->hour) * 0.5;
|
||||
} elseif ($monitoredAt->hour <= 11) {
|
||||
if ($lastWaterQualityMonitoringLog->monitored_at->hour <= 5) {
|
||||
$temperature -= (6 - ($lastWaterQualityMonitoringLog->monitored_at->hour + 1)) * 0.5;
|
||||
$temperature += ($monitoredAt->hour + 1 - 6) * 0.5;
|
||||
} else {
|
||||
$temperature += ($monitoredAt->hour - $lastWaterQualityMonitoringLog->monitored_at->hour) * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
$data['temp'] = $temperature;
|
||||
} else {
|
||||
$temperature = null;
|
||||
|
||||
if ($hjzDevice = Device::where('sn', '041508ec545640000730171a')->first()) {
|
||||
$temperature = WaterQualityMonitoringDailyLog::where('device_id', $hjzDevice->id)
|
||||
->where('monitored_at', $monitoredAt->toDateString())
|
||||
->value('temperature');
|
||||
|
||||
if (is_null($temperature)) {
|
||||
$temperature = WaterQualityMonitoringDailyLog::where('device_id', $hjzDevice->id)
|
||||
->latest('monitored_at')
|
||||
->value('temperature');
|
||||
|
||||
if ($temperature) {
|
||||
$temperature = mt_rand($temperature * 100 - 100, $temperature * 100 + 100) / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($temperature)) {
|
||||
$temperature = mt_rand(1800, 2000) / 100;
|
||||
}
|
||||
|
||||
if ($monitoredAt->hour <= 5) {
|
||||
$temperature -= ($monitoredAt->hour + 1) * 0.5;
|
||||
} elseif ($monitoredAt->hour <= 11) {
|
||||
$temperature += ($monitoredAt->hour + 1 - 6) * 0.5;
|
||||
}
|
||||
|
||||
$data['temp'] = $temperature;
|
||||
}
|
||||
|
||||
if ($lastWaterQualityMonitoringLog) {
|
||||
$data = array_merge($data, [
|
||||
'conductivity' => $lastWaterQualityMonitoringLog->conductivity,
|
||||
'oxygen' => $lastWaterQualityMonitoringLog->oxygen,
|
||||
'chlorine' => $lastWaterQualityMonitoringLog->chlorine,
|
||||
'turbidity' => $lastWaterQualityMonitoringLog->turbidity,
|
||||
'ph' => $lastWaterQualityMonitoringLog->ph,
|
||||
]);
|
||||
}
|
||||
|
||||
$data['is_filled'] = true;
|
||||
}
|
||||
|
||||
$linkosDeviceLogService->handleWaterQualityMonitoringLog($device, $data, $monitoredAt);
|
||||
$linkosDeviceLogService->handleWaterQualityMonitoringDailyLog($device, $monitoredAt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,10 @@ class Kernel extends ConsoleKernel
|
|||
->hourlyAt(15)
|
||||
->runInBackground();
|
||||
|
||||
$schedule->command(Commands\Linkos\WaterQualityReportCommand::class)
|
||||
->hourlyAt(50)
|
||||
->runInBackground();
|
||||
|
||||
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['yidong'])
|
||||
->everyTenMinutes()
|
||||
->runInBackground();
|
||||
|
|
|
|||
|
|
@ -251,15 +251,17 @@ class DeviceController extends Controller
|
|||
|
||||
if ($device->supplier_key === 'device-supplier-linkos') {
|
||||
if (isset($_dataList[$_key])) {
|
||||
if($deviceColumn == 'ph'){
|
||||
$data[$device->monitoring_point][$_key] = 7.49;
|
||||
}elseif($deviceColumn == 'temperature'){
|
||||
$data[$device->monitoring_point][$_key] = 10.00;
|
||||
}elseif($deviceColumn == 'turbidity'){
|
||||
$data[$device->monitoring_point][$_key] = 1028.60;
|
||||
}else{
|
||||
// if($deviceColumn == 'ph'){
|
||||
// $data[$device->monitoring_point][$_key] = 7.49;
|
||||
// }elseif($deviceColumn == 'temperature'){
|
||||
// $data[$device->monitoring_point][$_key] = 10.00;
|
||||
// }elseif($deviceColumn == 'turbidity'){
|
||||
// $data[$device->monitoring_point][$_key] = 1028.60;
|
||||
// }else{
|
||||
// $data[$device->monitoring_point][$_key] = $_dataList[$_key][$deviceColumn] ?? null;
|
||||
// }
|
||||
|
||||
$data[$device->monitoring_point][$_key] = $_dataList[$_key][$deviceColumn] ?? null;
|
||||
}
|
||||
}else{//临时写一些假数据
|
||||
switch($deviceColumn){
|
||||
case 'chlorine':
|
||||
|
|
@ -278,7 +280,7 @@ class DeviceController extends Controller
|
|||
$data[$device->monitoring_point][$_key] = rand(950, 1050) / 100;
|
||||
break;
|
||||
case 'turbidity':
|
||||
$data[$device->monitoring_point][$_key] = 0.33;
|
||||
$data[$device->monitoring_point][$_key] = 1028.60;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -386,14 +388,14 @@ class DeviceController extends Controller
|
|||
if ($monitoringLog) {
|
||||
$value = $monitoringLog->{$deviceColumn};
|
||||
|
||||
if (is_null($value) && $device->supplier_key === 'device-supplier-linkos') {
|
||||
$value = match ($deviceColumn) {
|
||||
'ph' => 7.49,
|
||||
'temperature' => 10.00,
|
||||
'turbidity' => 1028.60,
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
// if (is_null($value) && $device->supplier_key === 'device-supplier-linkos') {
|
||||
// $value = match ($deviceColumn) {
|
||||
// 'ph' => 7.49,
|
||||
// 'temperature' => 10.00,
|
||||
// 'turbidity' => 1028.60,
|
||||
// default => $value,
|
||||
// };
|
||||
// }
|
||||
|
||||
$y[] = $value;
|
||||
} elseif ($device->supplier_key === 'device-supplier-linkos') {
|
||||
|
|
@ -403,7 +405,7 @@ class DeviceController extends Controller
|
|||
'oxygen' => 0.09,
|
||||
'ph' => rand(750, 770) / 100,
|
||||
'temperature' => rand(900, 1100) / 100,
|
||||
'turbidity' => 0.33,
|
||||
'turbidity' => 1028.60,
|
||||
default => null,
|
||||
};
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue