Compare commits
24 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
7f589b4aa6 | |
|
|
aaa83dba5a | |
|
|
c711fa4451 | |
|
|
90a3afe873 | |
|
|
e9f8def59b | |
|
|
f676e32f9b | |
|
|
de4f83844c | |
|
|
03a1b355e4 | |
|
|
8de29c1802 | |
|
|
13ea196de8 | |
|
|
c4d4f6fc37 | |
|
|
f0f78aa038 | |
|
|
23745ee118 | |
|
|
11da69f2b3 | |
|
|
470c9c25c9 | |
|
|
31e20d139c | |
|
|
dfe788d7ea | |
|
|
5ce52144b3 | |
|
|
67f373ec82 | |
|
|
da004b5674 | |
|
|
547f0796ba | |
|
|
3d403653a5 | |
|
|
650ec1c5eb | |
|
|
c69c8bc5ae |
|
|
@ -54,11 +54,6 @@ class DeviceLogSyncCommand extends Command
|
|||
*/
|
||||
protected function sync(): void
|
||||
{
|
||||
$now = now();
|
||||
|
||||
$this->info('------------------------------------------');
|
||||
$this->info('同步时间: '. $now);
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Collection */
|
||||
$devices = Device::with(['project'])
|
||||
->supplierBy("device-supplier-biang")
|
||||
|
|
@ -79,7 +74,10 @@ class DeviceLogSyncCommand extends Command
|
|||
continue;
|
||||
}
|
||||
|
||||
$now = now();
|
||||
|
||||
$this->info('==========================================');
|
||||
$this->info('同步时间: '. $now);
|
||||
$this->info('设备编号: ' . $device->sn);
|
||||
$this->info('设备名称: ' . $device->name);
|
||||
$this->info('设备类型: ' . match ($device->type) {
|
||||
|
|
@ -157,6 +155,7 @@ class DeviceLogSyncCommand extends Command
|
|||
}
|
||||
|
||||
foreach ($data['imgUrl'] as $item) {
|
||||
try {
|
||||
// 下载图片
|
||||
$name = md5($item['url']);
|
||||
if ($ext = pathinfo($item['url'], PATHINFO_EXTENSION)) {
|
||||
|
|
@ -176,6 +175,9 @@ class DeviceLogSyncCommand extends Command
|
|||
], [
|
||||
'url' => $path,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
$device->update([
|
||||
|
|
@ -202,11 +204,9 @@ class DeviceLogSyncCommand extends Command
|
|||
}
|
||||
|
||||
$this->info('==========================================');
|
||||
}
|
||||
|
||||
$this->info('------------------------------------------');
|
||||
$this->newLine();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 HTTP 客户端
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class WormStatisticsSyncCommand extends Command
|
|||
|
||||
$latestReportedAt = WormReport::where('device_id', $device->id)->latest('reported_at')->value('reported_at');
|
||||
|
||||
$start = $latestReportedAt ? $latestReportedAt->copy() : $today->copy();
|
||||
$start = $latestReportedAt ? $latestReportedAt->copy() : $today->copy()->subDays(179);
|
||||
|
||||
$days = $start->diffInDays($today, false);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
<?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,6 +64,7 @@ class WormReportCommand extends Command
|
|||
$this->info('==================================');
|
||||
$this->info('尝试更新设备状态...');
|
||||
$realTimeData = $client->realTimeData($devices->pluck('sn')->all());
|
||||
|
||||
foreach ($realTimeData as $item) {
|
||||
foreach ($devices as $device) {
|
||||
if ($item['deviceAddr'] != $device->sn) {
|
||||
|
|
@ -71,7 +72,7 @@ class WormReportCommand extends Command
|
|||
}
|
||||
// 更新设备状态
|
||||
$device->update([
|
||||
'state' => $item['status'] === 'online' ? DeviceStatus::Online : DeviceStatus::Offline,
|
||||
'status' => $item['status'] === 'online' ? DeviceStatus::Online : DeviceStatus::Offline,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ class Kernel extends ConsoleKernel
|
|||
->hourlyAt(15)
|
||||
->runInBackground();
|
||||
|
||||
$schedule->command(Commands\Linkos\WaterQualityReportCommand::class)
|
||||
->hourlyAt(30)
|
||||
->runInBackground();
|
||||
|
||||
$schedule->command(Commands\MonitorDeviceHealthCommand::class, ['yidong'])
|
||||
->everyTenMinutes()
|
||||
->runInBackground();
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ class AdminUserController extends Controller
|
|||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = AdminUser::with(['roles'])->filter($request->all())->where('id', '>', 1);
|
||||
$list = $query->paginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||
$list = AdminUser::with(['roles'])
|
||||
->filter($request->all())
|
||||
->when(! $request->user()?->isAdministrator(), fn ($query) => $query->where('id', '!=', 1))
|
||||
->paginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||
|
||||
return $this->json(AdminUserResource::collection($list));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,15 @@ class AuthController extends Controller
|
|||
|
||||
$user = AdminUser::where(['username' => $username])->first();
|
||||
|
||||
$cacheKey = "admin_user_ban:{$username}";
|
||||
|
||||
if ($user?->banned_at) {
|
||||
if ($user->banned_at->addMinutes(5)->gte(now())) {
|
||||
return $this->error('账号已封禁,请联系管理员');
|
||||
}
|
||||
|
||||
$cacheKey = "admin_user_ban:{$username}";
|
||||
$this->cache->forget($cacheKey);
|
||||
}
|
||||
|
||||
if (! Hash::check($request->input('password'), (string) $user?->password)) {
|
||||
$this->cache->add($cacheKey, 0, 86400);
|
||||
|
|
|
|||
|
|
@ -138,6 +138,16 @@ 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);
|
||||
}
|
||||
|
||||
|
|
@ -251,37 +261,40 @@ 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':
|
||||
$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;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -386,27 +399,31 @@ 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') {
|
||||
$y[] = match ($deviceColumn) {
|
||||
'chlorine' => 0.016,
|
||||
'conductivity' => 563,
|
||||
'oxygen' => 0.09,
|
||||
'ph' => rand(750, 770) / 100,
|
||||
'temperature' => rand(900, 1100) / 100,
|
||||
'turbidity' => 0.33,
|
||||
default => null,
|
||||
};
|
||||
} else {
|
||||
}
|
||||
|
||||
// elseif ($device->supplier_key === 'device-supplier-linkos') {
|
||||
// $y[] = match ($deviceColumn) {
|
||||
// 'chlorine' => 0.016,
|
||||
// 'conductivity' => 563,
|
||||
// 'oxygen' => 0.09,
|
||||
// 'ph' => rand(750, 770) / 100,
|
||||
// 'temperature' => rand(900, 1100) / 100,
|
||||
// 'turbidity' => 1028.60,
|
||||
// default => null,
|
||||
// };
|
||||
// }
|
||||
|
||||
else {
|
||||
$y[] = null;
|
||||
}
|
||||
|
||||
|
|
@ -518,6 +535,21 @@ class DeviceController extends Controller
|
|||
'p',
|
||||
'k',
|
||||
];
|
||||
|
||||
switch ($device->supplier_key) {
|
||||
case 'device-supplier-biang':
|
||||
$fields = [
|
||||
'conductivity',
|
||||
'humidity',
|
||||
'temperature',
|
||||
'n',
|
||||
'p',
|
||||
'k',
|
||||
'ph',
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
$monitoringLogs = (
|
||||
$isSameDay
|
||||
|
|
@ -549,7 +581,10 @@ class DeviceController extends Controller
|
|||
case 'device-supplier-biang':
|
||||
$fields = [
|
||||
'oxygen',
|
||||
'ph',
|
||||
'temperature',
|
||||
'turbidity',
|
||||
'nh3n',
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
|
@ -609,31 +644,32 @@ class DeviceController extends Controller
|
|||
$monitoringLog = $monitoringLogs->get($key);
|
||||
|
||||
if (is_null($monitoringLog)) {
|
||||
// 如果是水质设备,则写死假数据
|
||||
if($device->supplier_key === 'device-supplier-linkos' && $device->type == DeviceType::WaterQuality){
|
||||
switch($field){
|
||||
case 'chlorine':
|
||||
$data[$key] = 0.016;
|
||||
break;
|
||||
case 'conductivity':
|
||||
$data[$key] = rand(560, 565);//电导率
|
||||
break;
|
||||
case 'oxygen':
|
||||
$data[$key] = 0.09;//含氧量
|
||||
break;
|
||||
case 'ph':
|
||||
$data[$key] = rand(750, 770) / 100;
|
||||
break;
|
||||
case 'temperature':
|
||||
$data[$key] = rand(950, 1050) / 100;
|
||||
break;
|
||||
case 'turbidity':
|
||||
$data[$key] = 0.33;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$data[$key] = null;
|
||||
}
|
||||
// 如果是水质设备,则写死假数据
|
||||
// if($device->supplier_key === 'device-supplier-linkos' && $device->type == DeviceType::WaterQuality){
|
||||
// switch($field){
|
||||
// case 'chlorine':
|
||||
// $data[$key] = 0.016;
|
||||
// break;
|
||||
// case 'conductivity':
|
||||
// $data[$key] = rand(560, 565);//电导率
|
||||
// break;
|
||||
// case 'oxygen':
|
||||
// $data[$key] = 0.09;//含氧量
|
||||
// break;
|
||||
// case 'ph':
|
||||
// $data[$key] = rand(750, 770) / 100;
|
||||
// break;
|
||||
// case 'temperature':
|
||||
// $data[$key] = rand(950, 1050) / 100;
|
||||
// break;
|
||||
// case 'turbidity':
|
||||
// $data[$key] = 0.33;
|
||||
// break;
|
||||
// }
|
||||
// } else {
|
||||
// $data[$key] = null;
|
||||
// }
|
||||
} else {
|
||||
$data[$key] = $monitoringLog[$field];
|
||||
}
|
||||
|
|
@ -703,7 +739,7 @@ class DeviceController extends Controller
|
|||
// 日期
|
||||
$date = $startTime->toDateString();
|
||||
|
||||
$data[$date] = $wormReports->get($date);
|
||||
$data[$date] = $wormReports->get($date, 0);
|
||||
|
||||
$startTime->addDay();
|
||||
} while ($startTime->lte($endTime));
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class HttpClient
|
|||
public function getLatestWaterDeviceReport(string $deviceId)
|
||||
{
|
||||
$result = $this->get(
|
||||
$this->apiUrl('/api/open-api/open/getWaterDeviceData'),
|
||||
$this->apiUrl('/api/open-api/open/getCurrentWaterData'),
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ class SoilMonitoringDailyLog extends Model
|
|||
'n',
|
||||
'p',
|
||||
'k',
|
||||
'ph',
|
||||
'moisture',
|
||||
'monitored_at',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ class SoilMonitoringLog extends Model
|
|||
'n',
|
||||
'p',
|
||||
'k',
|
||||
'ph',
|
||||
'monitored_at',
|
||||
'moisture',
|
||||
'is_filled',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class WaterQualityMonitoringDailyLog extends Model
|
|||
'ph',
|
||||
'temperature',
|
||||
'turbidity',
|
||||
'nh3n',
|
||||
'monitored_at',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class WaterQualityMonitoringLog extends Model
|
|||
'temperature',
|
||||
'turbidity',
|
||||
'monitored_at',
|
||||
'nh3n',
|
||||
'is_filled',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,9 @@ class BiAngDeviceService
|
|||
'soilAvailablePotassium' => 'k',
|
||||
'soilAvailablePhosphorus' => 'p',
|
||||
'soilConductivity' => 'conductivity',
|
||||
'soilTemperature' => 'temperature',
|
||||
'soilMoisture' => 'humidity',
|
||||
'soilTemperature1' => 'temperature',
|
||||
'soilHumidity1' => 'humidity',
|
||||
'soilPH' => 'ph',
|
||||
default => null,
|
||||
};
|
||||
|
||||
|
|
@ -152,9 +153,11 @@ class BiAngDeviceService
|
|||
if (is_array($data = $log->data)) {
|
||||
foreach ($data as $k => $v) {
|
||||
$attribute = match ($k) {
|
||||
'ec1' => 'conductivity',
|
||||
'waterdo' => 'oxygen',
|
||||
'zd' => 'turbidity',
|
||||
'waterMlss' => 'turbidity',
|
||||
'waterPh' => 'ph',
|
||||
'waterDo' => 'oxygen',
|
||||
'waterTemp' => 'temperature',
|
||||
'waterNh3n' => 'nh3n',
|
||||
default => null,
|
||||
};
|
||||
|
||||
|
|
@ -416,6 +419,7 @@ class BiAngDeviceService
|
|||
'temperature' => ['sum' => 0, 'count' => 0],
|
||||
'humidity' => ['sum' => 0, 'count' => 0],
|
||||
'moisture' => ['sum' => 0, 'count' => 0],
|
||||
'ph' => ['sum' => 0, 'count' => 0],
|
||||
];
|
||||
|
||||
foreach ($soilReports as $soilReport) {
|
||||
|
|
@ -474,6 +478,7 @@ class BiAngDeviceService
|
|||
'ph' => ['sum' => 0, 'count' => 0],
|
||||
'temperature' => ['sum' => 0, 'count' => 0],
|
||||
'turbidity' => ['sum' => 0, 'count' => 0],
|
||||
'nh3n' => ['sum' => 0, 'count' => 0],
|
||||
];
|
||||
|
||||
foreach ($waterQualityReports as $waterQualityReport) {
|
||||
|
|
|
|||
|
|
@ -26,11 +26,14 @@ class LinkosDeviceLogService
|
|||
*/
|
||||
protected $soilMonitoringFields = [
|
||||
'conductivity' => 'conductivity',
|
||||
'humidity' => 'soil_humidity',
|
||||
'temperature' => 'soil_temperature',
|
||||
'n' => 'nitrogen_content',
|
||||
'p' => 'phosphorus_content',
|
||||
'k' => 'potassium_content',
|
||||
'soil_humidity' => 'humidity',
|
||||
'soil_temperature' => 'temperature',
|
||||
'nitrogen_content' => 'n',
|
||||
'phosphorus_content' => 'p',
|
||||
'potassium_content' => 'k',
|
||||
'electroconductibility' => 'conductivity',
|
||||
'temperature' => 'temperature',
|
||||
'moisture_content' => 'moisture',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -134,7 +137,7 @@ class LinkosDeviceLogService
|
|||
*/
|
||||
public function handleSoilMonitoringLog(Device $device, array $data, Carbon $reportedAt): void
|
||||
{
|
||||
if (! Arr::hasAny($data, $this->soilMonitoringFields)) {
|
||||
if (! Arr::hasAny($data, array_keys($this->soilMonitoringFields))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +148,7 @@ class LinkosDeviceLogService
|
|||
'agricultural_base_id' => $device->agricultural_base_id,
|
||||
]);
|
||||
|
||||
foreach ($this->soilMonitoringFields as $attribute => $key) {
|
||||
foreach ($this->soilMonitoringFields as $key => $attribute) {
|
||||
if (! array_key_exists($key, $data)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -181,7 +184,7 @@ class LinkosDeviceLogService
|
|||
$data = [];
|
||||
|
||||
foreach ($logs as $log) {
|
||||
foreach (['conductivity', 'humidity', 'temperature', 'n', 'p', 'k'] as $key) {
|
||||
foreach (['conductivity', 'humidity', 'temperature', 'n', 'p', 'k', 'moisture'] as $key) {
|
||||
if (is_null($v = $log->{$key})) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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,6 +61,12 @@ class SettingTableSeeder extends Seeder
|
|||
"3"=>[["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([
|
||||
"temperature"=>[
|
||||
|
|
@ -99,6 +105,12 @@ class SettingTableSeeder extends Seeder
|
|||
"3"=>[["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 = [
|
||||
['name' => '全市数据-幅员面积', 'slug' => 'city_data_area', 'value' => '{"value":"794.41", "unit":"平方公里"}'],
|
||||
|
|
|
|||
Loading…
Reference in New Issue