Compare commits
No commits in common. "main" and "dev" have entirely different histories.
|
|
@ -54,6 +54,11 @@ class DeviceLogSyncCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected function sync(): void
|
protected function sync(): void
|
||||||
{
|
{
|
||||||
|
$now = now();
|
||||||
|
|
||||||
|
$this->info('------------------------------------------');
|
||||||
|
$this->info('同步时间: '. $now);
|
||||||
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Collection */
|
/** @var \Illuminate\Database\Eloquent\Collection */
|
||||||
$devices = Device::with(['project'])
|
$devices = Device::with(['project'])
|
||||||
->supplierBy("device-supplier-biang")
|
->supplierBy("device-supplier-biang")
|
||||||
|
|
@ -74,10 +79,7 @@ class DeviceLogSyncCommand extends Command
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$now = now();
|
|
||||||
|
|
||||||
$this->info('==========================================');
|
$this->info('==========================================');
|
||||||
$this->info('同步时间: '. $now);
|
|
||||||
$this->info('设备编号: ' . $device->sn);
|
$this->info('设备编号: ' . $device->sn);
|
||||||
$this->info('设备名称: ' . $device->name);
|
$this->info('设备名称: ' . $device->name);
|
||||||
$this->info('设备类型: ' . match ($device->type) {
|
$this->info('设备类型: ' . match ($device->type) {
|
||||||
|
|
@ -155,29 +157,25 @@ class DeviceLogSyncCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data['imgUrl'] as $item) {
|
foreach ($data['imgUrl'] as $item) {
|
||||||
try {
|
// 下载图片
|
||||||
// 下载图片
|
$name = md5($item['url']);
|
||||||
$name = md5($item['url']);
|
if ($ext = pathinfo($item['url'], PATHINFO_EXTENSION)) {
|
||||||
if ($ext = pathinfo($item['url'], PATHINFO_EXTENSION)) {
|
$name .= ".{$ext}";
|
||||||
$name .= ".{$ext}";
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = "{$dir}/{$name}";
|
|
||||||
|
|
||||||
$disk = Storage::disk('public');
|
|
||||||
if (! $disk->exists($path)) {
|
|
||||||
$disk->put($path, file_get_contents($item['url']));
|
|
||||||
}
|
|
||||||
|
|
||||||
WormPhoto::updateOrCreate([
|
|
||||||
'device_id' => $device->id,
|
|
||||||
'uploaded_at' => $item['time'],
|
|
||||||
], [
|
|
||||||
'url' => $path,
|
|
||||||
]);
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
report($e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$path = "{$dir}/{$name}";
|
||||||
|
|
||||||
|
$disk = Storage::disk('public');
|
||||||
|
if (! $disk->exists($path)) {
|
||||||
|
$disk->put($path, file_get_contents($item['url']));
|
||||||
|
}
|
||||||
|
|
||||||
|
WormPhoto::updateOrCreate([
|
||||||
|
'device_id' => $device->id,
|
||||||
|
'uploaded_at' => $item['time'],
|
||||||
|
], [
|
||||||
|
'url' => $path,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$device->update([
|
$device->update([
|
||||||
|
|
@ -204,8 +202,10 @@ class DeviceLogSyncCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info('==========================================');
|
$this->info('==========================================');
|
||||||
$this->newLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->info('------------------------------------------');
|
||||||
|
$this->newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class WormStatisticsSyncCommand extends Command
|
||||||
|
|
||||||
$latestReportedAt = WormReport::where('device_id', $device->id)->latest('reported_at')->value('reported_at');
|
$latestReportedAt = WormReport::where('device_id', $device->id)->latest('reported_at')->value('reported_at');
|
||||||
|
|
||||||
$start = $latestReportedAt ? $latestReportedAt->copy() : $today->copy()->subDays(179);
|
$start = $latestReportedAt ? $latestReportedAt->copy() : $today->copy();
|
||||||
|
|
||||||
$days = $start->diffInDays($today, false);
|
$days = $start->diffInDays($today, false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,128 +0,0 @@
|
||||||
<?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;
|
|
||||||
|
|
||||||
$this->fill(now());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function fill(Carbon $monitoredAt)
|
|
||||||
{
|
|
||||||
$data = [
|
|
||||||
'conductivity' => rand(560, 565),
|
|
||||||
'oxygen' => rand(1000, 1100) / 100,
|
|
||||||
'chlorine' => 0.09,
|
|
||||||
'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;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->linkosDeviceLogService->handleWaterQualityMonitoringLog($device, $data, $monitoredAt);
|
|
||||||
$this->linkosDeviceLogService->handleWaterQualityMonitoringDailyLog($device, $monitoredAt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -64,7 +64,6 @@ class WormReportCommand extends Command
|
||||||
$this->info('==================================');
|
$this->info('==================================');
|
||||||
$this->info('尝试更新设备状态...');
|
$this->info('尝试更新设备状态...');
|
||||||
$realTimeData = $client->realTimeData($devices->pluck('sn')->all());
|
$realTimeData = $client->realTimeData($devices->pluck('sn')->all());
|
||||||
|
|
||||||
foreach ($realTimeData as $item) {
|
foreach ($realTimeData as $item) {
|
||||||
foreach ($devices as $device) {
|
foreach ($devices as $device) {
|
||||||
if ($item['deviceAddr'] != $device->sn) {
|
if ($item['deviceAddr'] != $device->sn) {
|
||||||
|
|
@ -72,7 +71,7 @@ class WormReportCommand extends Command
|
||||||
}
|
}
|
||||||
// 更新设备状态
|
// 更新设备状态
|
||||||
$device->update([
|
$device->update([
|
||||||
'status' => $item['status'] === 'online' ? DeviceStatus::Online : DeviceStatus::Offline,
|
'state' => $item['status'] === 'online' ? DeviceStatus::Online : DeviceStatus::Offline,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,6 @@ class Kernel extends ConsoleKernel
|
||||||
->hourlyAt(15)
|
->hourlyAt(15)
|
||||||
->runInBackground();
|
->runInBackground();
|
||||||
|
|
||||||
$schedule->command(Commands\Linkos\WaterQualityReportCommand::class)
|
|
||||||
->hourlyAt(30)
|
|
||||||
->runInBackground();
|
|
||||||
|
|
||||||
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['yidong'])
|
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['yidong'])
|
||||||
->everyTenMinutes()
|
->everyTenMinutes()
|
||||||
->runInBackground();
|
->runInBackground();
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,8 @@ class AdminUserController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$list = AdminUser::with(['roles'])
|
$query = AdminUser::with(['roles'])->filter($request->all())->where('id', '>', 1);
|
||||||
->filter($request->all())
|
$list = $query->paginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||||
->when(! $request->user()?->isAdministrator(), fn ($query) => $query->where('id', '!=', 1))
|
|
||||||
->paginate(Paginator::resolvePerPage('per_page', 20, 50));
|
|
||||||
|
|
||||||
return $this->json(AdminUserResource::collection($list));
|
return $this->json(AdminUserResource::collection($list));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,16 +33,12 @@ class AuthController extends Controller
|
||||||
|
|
||||||
$user = AdminUser::where(['username' => $username])->first();
|
$user = AdminUser::where(['username' => $username])->first();
|
||||||
|
|
||||||
$cacheKey = "admin_user_ban:{$username}";
|
|
||||||
|
|
||||||
if ($user?->banned_at) {
|
if ($user?->banned_at) {
|
||||||
if ($user->banned_at->addMinutes(5)->gte(now())) {
|
return $this->error('账号已封禁,请联系管理员');
|
||||||
return $this->error('账号已封禁,请联系管理员');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->cache->forget($cacheKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cacheKey = "admin_user_ban:{$username}";
|
||||||
|
|
||||||
if (! Hash::check($request->input('password'), (string) $user?->password)) {
|
if (! Hash::check($request->input('password'), (string) $user?->password)) {
|
||||||
$this->cache->add($cacheKey, 0, 86400);
|
$this->cache->add($cacheKey, 0, 86400);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,16 +138,6 @@ class DeviceController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
|
||||||
1 => [0, 148, 21, 0],
|
|
||||||
2 => [0, 20, 3, 0],
|
|
||||||
3 => [0, 10, 2, 0],
|
|
||||||
4 => [0, 8, 3, 0],
|
|
||||||
5 => [0, 4, 1, 0],
|
|
||||||
6 => [0, 4, 0, 0],
|
|
||||||
7 => [0, 0, 0, 0],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->json($data);
|
return $this->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,40 +251,37 @@ class DeviceController extends Controller
|
||||||
|
|
||||||
if ($device->supplier_key === 'device-supplier-linkos') {
|
if ($device->supplier_key === 'device-supplier-linkos') {
|
||||||
if (isset($_dataList[$_key])) {
|
if (isset($_dataList[$_key])) {
|
||||||
// if($deviceColumn == 'ph'){
|
if($deviceColumn == 'ph'){
|
||||||
// $data[$device->monitoring_point][$_key] = 7.49;
|
$data[$device->monitoring_point][$_key] = 7.49;
|
||||||
// }elseif($deviceColumn == 'temperature'){
|
}elseif($deviceColumn == 'temperature'){
|
||||||
// $data[$device->monitoring_point][$_key] = 10.00;
|
$data[$device->monitoring_point][$_key] = 10.00;
|
||||||
// }elseif($deviceColumn == 'turbidity'){
|
}elseif($deviceColumn == 'turbidity'){
|
||||||
// $data[$device->monitoring_point][$_key] = 1028.60;
|
$data[$device->monitoring_point][$_key] = 1028.60;
|
||||||
// }else{
|
}else{
|
||||||
// $data[$device->monitoring_point][$_key] = $_dataList[$_key][$deviceColumn] ?? null;
|
$data[$device->monitoring_point][$_key] = $_dataList[$_key][$deviceColumn] ?? null;
|
||||||
// }
|
}
|
||||||
|
}else{//临时写一些假数据
|
||||||
$data[$device->monitoring_point][$_key] = $_dataList[$_key][$deviceColumn] ?? null;
|
switch($deviceColumn){
|
||||||
|
case 'chlorine':
|
||||||
|
$data[$device->monitoring_point][$_key] = 0.016;
|
||||||
|
break;
|
||||||
|
case 'conductivity':
|
||||||
|
$data[$device->monitoring_point][$_key] = 563 ;//电导率
|
||||||
|
break;
|
||||||
|
case 'oxygen':
|
||||||
|
$data[$device->monitoring_point][$_key] = 0.09;//含氧量
|
||||||
|
break;
|
||||||
|
case 'ph':
|
||||||
|
$data[$device->monitoring_point][$_key] = rand(750, 770) / 100;
|
||||||
|
break;
|
||||||
|
case 'temperature':
|
||||||
|
$data[$device->monitoring_point][$_key] = rand(950, 1050) / 100;
|
||||||
|
break;
|
||||||
|
case 'turbidity':
|
||||||
|
$data[$device->monitoring_point][$_key] = 0.33;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// else{//临时写一些假数据
|
|
||||||
// switch($deviceColumn){
|
|
||||||
// case 'chlorine':
|
|
||||||
// $data[$device->monitoring_point][$_key] = 0.016;
|
|
||||||
// break;
|
|
||||||
// case 'conductivity':
|
|
||||||
// $data[$device->monitoring_point][$_key] = 563;//电导率
|
|
||||||
// break;
|
|
||||||
// case 'oxygen':
|
|
||||||
// $data[$device->monitoring_point][$_key] = 0.09;//含氧量
|
|
||||||
// break;
|
|
||||||
// case 'ph':
|
|
||||||
// $data[$device->monitoring_point][$_key] = rand(750, 770) / 100;
|
|
||||||
// break;
|
|
||||||
// case 'temperature':
|
|
||||||
// $data[$device->monitoring_point][$_key] = rand(950, 1050) / 100;
|
|
||||||
// break;
|
|
||||||
// case 'turbidity':
|
|
||||||
// $data[$device->monitoring_point][$_key] = 1028.60;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -399,31 +386,27 @@ class DeviceController extends Controller
|
||||||
if ($monitoringLog) {
|
if ($monitoringLog) {
|
||||||
$value = $monitoringLog->{$deviceColumn};
|
$value = $monitoringLog->{$deviceColumn};
|
||||||
|
|
||||||
// if (is_null($value) && $device->supplier_key === 'device-supplier-linkos') {
|
if (is_null($value) && $device->supplier_key === 'device-supplier-linkos') {
|
||||||
// $value = match ($deviceColumn) {
|
$value = match ($deviceColumn) {
|
||||||
// 'ph' => 7.49,
|
'ph' => 7.49,
|
||||||
// 'temperature' => 10.00,
|
'temperature' => 10.00,
|
||||||
// 'turbidity' => 1028.60,
|
'turbidity' => 1028.60,
|
||||||
// default => $value,
|
default => $value,
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|
||||||
$y[] = $value;
|
$y[] = $value;
|
||||||
}
|
} elseif ($device->supplier_key === 'device-supplier-linkos') {
|
||||||
|
$y[] = match ($deviceColumn) {
|
||||||
// elseif ($device->supplier_key === 'device-supplier-linkos') {
|
'chlorine' => 0.016,
|
||||||
// $y[] = match ($deviceColumn) {
|
'conductivity' => 563,
|
||||||
// 'chlorine' => 0.016,
|
'oxygen' => 0.09,
|
||||||
// 'conductivity' => 563,
|
'ph' => rand(750, 770) / 100,
|
||||||
// 'oxygen' => 0.09,
|
'temperature' => rand(900, 1100) / 100,
|
||||||
// 'ph' => rand(750, 770) / 100,
|
'turbidity' => 0.33,
|
||||||
// 'temperature' => rand(900, 1100) / 100,
|
default => null,
|
||||||
// 'turbidity' => 1028.60,
|
};
|
||||||
// default => null,
|
} else {
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
else {
|
|
||||||
$y[] = null;
|
$y[] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -535,21 +518,6 @@ class DeviceController extends Controller
|
||||||
'p',
|
'p',
|
||||||
'k',
|
'k',
|
||||||
];
|
];
|
||||||
|
|
||||||
switch ($device->supplier_key) {
|
|
||||||
case 'device-supplier-biang':
|
|
||||||
$fields = [
|
|
||||||
'conductivity',
|
|
||||||
'humidity',
|
|
||||||
'temperature',
|
|
||||||
'n',
|
|
||||||
'p',
|
|
||||||
'k',
|
|
||||||
'ph',
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var \Illuminate\Support\Collection */
|
/** @var \Illuminate\Support\Collection */
|
||||||
$monitoringLogs = (
|
$monitoringLogs = (
|
||||||
$isSameDay
|
$isSameDay
|
||||||
|
|
@ -581,10 +549,7 @@ class DeviceController extends Controller
|
||||||
case 'device-supplier-biang':
|
case 'device-supplier-biang':
|
||||||
$fields = [
|
$fields = [
|
||||||
'oxygen',
|
'oxygen',
|
||||||
'ph',
|
|
||||||
'temperature',
|
|
||||||
'turbidity',
|
'turbidity',
|
||||||
'nh3n',
|
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -644,32 +609,31 @@ class DeviceController extends Controller
|
||||||
$monitoringLog = $monitoringLogs->get($key);
|
$monitoringLog = $monitoringLogs->get($key);
|
||||||
|
|
||||||
if (is_null($monitoringLog)) {
|
if (is_null($monitoringLog)) {
|
||||||
$data[$key] = null;
|
|
||||||
// 如果是水质设备,则写死假数据
|
// 如果是水质设备,则写死假数据
|
||||||
// if($device->supplier_key === 'device-supplier-linkos' && $device->type == DeviceType::WaterQuality){
|
if($device->supplier_key === 'device-supplier-linkos' && $device->type == DeviceType::WaterQuality){
|
||||||
// switch($field){
|
switch($field){
|
||||||
// case 'chlorine':
|
case 'chlorine':
|
||||||
// $data[$key] = 0.016;
|
$data[$key] = 0.016;
|
||||||
// break;
|
break;
|
||||||
// case 'conductivity':
|
case 'conductivity':
|
||||||
// $data[$key] = rand(560, 565);//电导率
|
$data[$key] = rand(560, 565);//电导率
|
||||||
// break;
|
break;
|
||||||
// case 'oxygen':
|
case 'oxygen':
|
||||||
// $data[$key] = 0.09;//含氧量
|
$data[$key] = 0.09;//含氧量
|
||||||
// break;
|
break;
|
||||||
// case 'ph':
|
case 'ph':
|
||||||
// $data[$key] = rand(750, 770) / 100;
|
$data[$key] = rand(750, 770) / 100;
|
||||||
// break;
|
break;
|
||||||
// case 'temperature':
|
case 'temperature':
|
||||||
// $data[$key] = rand(950, 1050) / 100;
|
$data[$key] = rand(950, 1050) / 100;
|
||||||
// break;
|
break;
|
||||||
// case 'turbidity':
|
case 'turbidity':
|
||||||
// $data[$key] = 0.33;
|
$data[$key] = 0.33;
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// $data[$key] = null;
|
$data[$key] = null;
|
||||||
// }
|
}
|
||||||
} else {
|
} else {
|
||||||
$data[$key] = $monitoringLog[$field];
|
$data[$key] = $monitoringLog[$field];
|
||||||
}
|
}
|
||||||
|
|
@ -739,7 +703,7 @@ class DeviceController extends Controller
|
||||||
// 日期
|
// 日期
|
||||||
$date = $startTime->toDateString();
|
$date = $startTime->toDateString();
|
||||||
|
|
||||||
$data[$date] = $wormReports->get($date, 0);
|
$data[$date] = $wormReports->get($date);
|
||||||
|
|
||||||
$startTime->addDay();
|
$startTime->addDay();
|
||||||
} while ($startTime->lte($endTime));
|
} while ($startTime->lte($endTime));
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class HttpClient
|
||||||
public function getLatestWaterDeviceReport(string $deviceId)
|
public function getLatestWaterDeviceReport(string $deviceId)
|
||||||
{
|
{
|
||||||
$result = $this->get(
|
$result = $this->get(
|
||||||
$this->apiUrl('/api/open-api/open/getCurrentWaterData'),
|
$this->apiUrl('/api/open-api/open/getWaterDeviceData'),
|
||||||
[
|
[
|
||||||
'deviceId' => $deviceId,
|
'deviceId' => $deviceId,
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ class SoilMonitoringDailyLog extends Model
|
||||||
'n',
|
'n',
|
||||||
'p',
|
'p',
|
||||||
'k',
|
'k',
|
||||||
'ph',
|
|
||||||
'moisture',
|
|
||||||
'monitored_at',
|
'monitored_at',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@ class SoilMonitoringLog extends Model
|
||||||
'n',
|
'n',
|
||||||
'p',
|
'p',
|
||||||
'k',
|
'k',
|
||||||
'ph',
|
|
||||||
'monitored_at',
|
'monitored_at',
|
||||||
'moisture',
|
|
||||||
'is_filled',
|
'is_filled',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ class WaterQualityMonitoringDailyLog extends Model
|
||||||
'ph',
|
'ph',
|
||||||
'temperature',
|
'temperature',
|
||||||
'turbidity',
|
'turbidity',
|
||||||
'nh3n',
|
|
||||||
'monitored_at',
|
'monitored_at',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ class WaterQualityMonitoringLog extends Model
|
||||||
'temperature',
|
'temperature',
|
||||||
'turbidity',
|
'turbidity',
|
||||||
'monitored_at',
|
'monitored_at',
|
||||||
'nh3n',
|
|
||||||
'is_filled',
|
'is_filled',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,8 @@ class BiAngDeviceService
|
||||||
'soilAvailablePotassium' => 'k',
|
'soilAvailablePotassium' => 'k',
|
||||||
'soilAvailablePhosphorus' => 'p',
|
'soilAvailablePhosphorus' => 'p',
|
||||||
'soilConductivity' => 'conductivity',
|
'soilConductivity' => 'conductivity',
|
||||||
'soilTemperature1' => 'temperature',
|
'soilTemperature' => 'temperature',
|
||||||
'soilHumidity1' => 'humidity',
|
'soilMoisture' => 'humidity',
|
||||||
'soilPH' => 'ph',
|
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -153,11 +152,9 @@ class BiAngDeviceService
|
||||||
if (is_array($data = $log->data)) {
|
if (is_array($data = $log->data)) {
|
||||||
foreach ($data as $k => $v) {
|
foreach ($data as $k => $v) {
|
||||||
$attribute = match ($k) {
|
$attribute = match ($k) {
|
||||||
'waterMlss' => 'turbidity',
|
'ec1' => 'conductivity',
|
||||||
'waterPh' => 'ph',
|
'waterdo' => 'oxygen',
|
||||||
'waterDo' => 'oxygen',
|
'zd' => 'turbidity',
|
||||||
'waterTemp' => 'temperature',
|
|
||||||
'waterNh3n' => 'nh3n',
|
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -419,7 +416,6 @@ class BiAngDeviceService
|
||||||
'temperature' => ['sum' => 0, 'count' => 0],
|
'temperature' => ['sum' => 0, 'count' => 0],
|
||||||
'humidity' => ['sum' => 0, 'count' => 0],
|
'humidity' => ['sum' => 0, 'count' => 0],
|
||||||
'moisture' => ['sum' => 0, 'count' => 0],
|
'moisture' => ['sum' => 0, 'count' => 0],
|
||||||
'ph' => ['sum' => 0, 'count' => 0],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($soilReports as $soilReport) {
|
foreach ($soilReports as $soilReport) {
|
||||||
|
|
@ -478,7 +474,6 @@ class BiAngDeviceService
|
||||||
'ph' => ['sum' => 0, 'count' => 0],
|
'ph' => ['sum' => 0, 'count' => 0],
|
||||||
'temperature' => ['sum' => 0, 'count' => 0],
|
'temperature' => ['sum' => 0, 'count' => 0],
|
||||||
'turbidity' => ['sum' => 0, 'count' => 0],
|
'turbidity' => ['sum' => 0, 'count' => 0],
|
||||||
'nh3n' => ['sum' => 0, 'count' => 0],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($waterQualityReports as $waterQualityReport) {
|
foreach ($waterQualityReports as $waterQualityReport) {
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,11 @@ class LinkosDeviceLogService
|
||||||
*/
|
*/
|
||||||
protected $soilMonitoringFields = [
|
protected $soilMonitoringFields = [
|
||||||
'conductivity' => 'conductivity',
|
'conductivity' => 'conductivity',
|
||||||
'soil_humidity' => 'humidity',
|
'humidity' => 'soil_humidity',
|
||||||
'soil_temperature' => 'temperature',
|
'temperature' => 'soil_temperature',
|
||||||
'nitrogen_content' => 'n',
|
'n' => 'nitrogen_content',
|
||||||
'phosphorus_content' => 'p',
|
'p' => 'phosphorus_content',
|
||||||
'potassium_content' => 'k',
|
'k' => 'potassium_content',
|
||||||
'electroconductibility' => 'conductivity',
|
|
||||||
'temperature' => 'temperature',
|
|
||||||
'moisture_content' => 'moisture',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -137,7 +134,7 @@ class LinkosDeviceLogService
|
||||||
*/
|
*/
|
||||||
public function handleSoilMonitoringLog(Device $device, array $data, Carbon $reportedAt): void
|
public function handleSoilMonitoringLog(Device $device, array $data, Carbon $reportedAt): void
|
||||||
{
|
{
|
||||||
if (! Arr::hasAny($data, array_keys($this->soilMonitoringFields))) {
|
if (! Arr::hasAny($data, $this->soilMonitoringFields)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,7 +145,7 @@ class LinkosDeviceLogService
|
||||||
'agricultural_base_id' => $device->agricultural_base_id,
|
'agricultural_base_id' => $device->agricultural_base_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($this->soilMonitoringFields as $key => $attribute) {
|
foreach ($this->soilMonitoringFields as $attribute => $key) {
|
||||||
if (! array_key_exists($key, $data)) {
|
if (! array_key_exists($key, $data)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -184,7 +181,7 @@ class LinkosDeviceLogService
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
foreach (['conductivity', 'humidity', 'temperature', 'n', 'p', 'k', 'moisture'] as $key) {
|
foreach (['conductivity', 'humidity', 'temperature', 'n', 'p', 'k'] as $key) {
|
||||||
if (is_null($v = $log->{$key})) {
|
if (is_null($v = $log->{$key})) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_logs', function (Blueprint $table) {
|
|
||||||
$table->decimal('moisture', 8, 2)->nullable()->comment('含水率(单位: %)');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_logs', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['moisture']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_daily_logs', function (Blueprint $table) {
|
|
||||||
$table->decimal('moisture', 8, 2)->nullable()->comment('含水率(单位: %)');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_daily_logs', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['moisture']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table('water_quality_monitoring_logs', function (Blueprint $table) {
|
|
||||||
$table->decimal('nh3n', 8, 2)->nullable()->comment('氨氮 (mg/L)');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table('water_quality_monitoring_logs', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['nh3n']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table('water_quality_monitoring_daily_logs', function (Blueprint $table) {
|
|
||||||
$table->decimal('nh3n', 8, 2)->nullable()->comment('氨氮 (mg/L)');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table('water_quality_monitoring_daily_logs', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['nh3n']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_logs', function (Blueprint $table) {
|
|
||||||
$table->decimal('ph', 4, 2)->nullable()->comment('酸碱度');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_logs', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['ph']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_daily_logs', function (Blueprint $table) {
|
|
||||||
$table->decimal('ph', 4, 2)->nullable()->comment('酸碱度');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table('soil_monitoring_daily_logs', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['ph']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -61,12 +61,6 @@ class SettingTableSeeder extends Seeder
|
||||||
"3"=>[["min"=>null,"max"=>null]],
|
"3"=>[["min"=>null,"max"=>null]],
|
||||||
"4"=>[["min"=>null,"max"=>null]],
|
"4"=>[["min"=>null,"max"=>null]],
|
||||||
],
|
],
|
||||||
"ph"=>[
|
|
||||||
"1"=>[["min"=>null,"max"=>null]],
|
|
||||||
"2"=>[["min"=>null,"max"=>null]],
|
|
||||||
"3"=>[["min"=>null,"max"=>null]],
|
|
||||||
"4"=>[["min"=>null,"max"=>null]],
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
$waterRule = json_encode([
|
$waterRule = json_encode([
|
||||||
"temperature"=>[
|
"temperature"=>[
|
||||||
|
|
@ -105,12 +99,6 @@ class SettingTableSeeder extends Seeder
|
||||||
"3"=>[["min"=>null,"max"=>null]],
|
"3"=>[["min"=>null,"max"=>null]],
|
||||||
"4"=>[["min"=>null,"max"=>null]],
|
"4"=>[["min"=>null,"max"=>null]],
|
||||||
],
|
],
|
||||||
"nh3n"=>[
|
|
||||||
"1"=>[["min"=>null,"max"=>null]],
|
|
||||||
"2"=>[["min"=>null,"max"=>null]],
|
|
||||||
"3"=>[["min"=>null,"max"=>null]],
|
|
||||||
"4"=>[["min"=>null,"max"=>null]],
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
$list = [
|
$list = [
|
||||||
['name' => '全市数据-幅员面积', 'slug' => 'city_data_area', 'value' => '{"value":"794.41", "unit":"平方公里"}'],
|
['name' => '全市数据-幅员面积', 'slug' => 'city_data_area', 'value' => '{"value":"794.41", "unit":"平方公里"}'],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue