Compare commits

...

24 Commits
dev ... main

Author SHA1 Message Date
李静 7f589b4aa6 fix 2025-10-11 22:50:17 +08:00
李静 aaa83dba5a Update 2025-10-11 22:45:56 +08:00
李静 c711fa4451 Update 2025-10-11 21:06:48 +08:00
Jing Li 90a3afe873 Update 2024-12-04 11:59:38 +08:00
Jing Li e9f8def59b Update 2024-12-04 11:55:58 +08:00
Jing Li f676e32f9b Update 2024-06-07 14:50:50 +08:00
Jing Li de4f83844c Update 2024-06-07 14:49:35 +08:00
Jing Li 03a1b355e4 Update 2024-06-07 14:46:04 +08:00
Jing Li 8de29c1802 Update 2024-06-03 21:16:55 +08:00
Jing Li 13ea196de8 Update 2024-06-03 21:14:55 +08:00
Jing Li c4d4f6fc37 Update 2024-06-03 20:09:01 +08:00
Jing Li f0f78aa038 Update 2024-06-03 19:43:23 +08:00
Jing Li 23745ee118 Update 2024-06-03 18:56:04 +08:00
Jing Li 11da69f2b3 Update 2024-06-03 18:47:19 +08:00
Jing Li 470c9c25c9 账号锁定后,5分钟后自动解锁 2024-06-02 20:40:59 +08:00
Jing Li 31e20d139c Update 2024-06-02 13:27:19 +08:00
Jing Li dfe788d7ea 土壤设备增加酸碱度 2024-06-02 13:15:36 +08:00
Jing Li 5ce52144b3 Update 2024-05-28 18:29:06 +08:00
Jing Li 67f373ec82 Update 2024-05-28 18:14:27 +08:00
Jing Li da004b5674 比昂水质设备 2024-05-28 18:12:01 +08:00
Jing Li 547f0796ba Fix 2024-04-10 12:58:16 +08:00
Jing Li 3d403653a5 兼容界市园区土壤设备 2024-04-09 21:30:16 +08:00
Jing Li 650ec1c5eb Update 2024-02-06 10:53:17 +08:00
Jing Li c69c8bc5ae Update 2024-02-06 10:49:06 +08:00
22 changed files with 515 additions and 122 deletions

View File

@ -54,11 +54,6 @@ 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")
@ -79,7 +74,10 @@ 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) {
@ -157,25 +155,29 @@ class DeviceLogSyncCommand extends Command
} }
foreach ($data['imgUrl'] as $item) { foreach ($data['imgUrl'] as $item) {
// 下载图片 try {
$name = md5($item['url']); // 下载图片
if ($ext = pathinfo($item['url'], PATHINFO_EXTENSION)) { $name = md5($item['url']);
$name .= ".{$ext}"; if ($ext = pathinfo($item['url'], PATHINFO_EXTENSION)) {
$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([
@ -202,10 +204,8 @@ class DeviceLogSyncCommand extends Command
} }
$this->info('=========================================='); $this->info('==========================================');
$this->newLine();
} }
$this->info('------------------------------------------');
$this->newLine();
} }
/** /**

View File

@ -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(); $start = $latestReportedAt ? $latestReportedAt->copy() : $today->copy()->subDays(179);
$days = $start->diffInDays($today, false); $days = $start->diffInDays($today, false);

View File

@ -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);
}
}
}

View File

@ -64,6 +64,7 @@ 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) {
@ -71,7 +72,7 @@ class WormReportCommand extends Command
} }
// 更新设备状态 // 更新设备状态
$device->update([ $device->update([
'state' => $item['status'] === 'online' ? DeviceStatus::Online : DeviceStatus::Offline, 'status' => $item['status'] === 'online' ? DeviceStatus::Online : DeviceStatus::Offline,
]); ]);
} }
} }

View File

@ -23,6 +23,10 @@ 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();

View File

@ -17,8 +17,10 @@ class AdminUserController extends Controller
{ {
public function index(Request $request) public function index(Request $request)
{ {
$query = AdminUser::with(['roles'])->filter($request->all())->where('id', '>', 1); $list = AdminUser::with(['roles'])
$list = $query->paginate(Paginator::resolvePerPage('per_page', 20, 50)); ->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)); return $this->json(AdminUserResource::collection($list));
} }

View File

@ -33,12 +33,16 @@ class AuthController extends Controller
$user = AdminUser::where(['username' => $username])->first(); $user = AdminUser::where(['username' => $username])->first();
if ($user?->banned_at) {
return $this->error('账号已封禁,请联系管理员');
}
$cacheKey = "admin_user_ban:{$username}"; $cacheKey = "admin_user_ban:{$username}";
if ($user?->banned_at) {
if ($user->banned_at->addMinutes(5)->gte(now())) {
return $this->error('账号已封禁,请联系管理员');
}
$this->cache->forget($cacheKey);
}
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);

View File

@ -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); return $this->json($data);
} }
@ -251,37 +261,40 @@ 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{//临时写一些假数据
switch($deviceColumn){ $data[$device->monitoring_point][$_key] = $_dataList[$_key][$deviceColumn] ?? null;
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) { 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) {
'chlorine' => 0.016, // elseif ($device->supplier_key === 'device-supplier-linkos') {
'conductivity' => 563, // $y[] = match ($deviceColumn) {
'oxygen' => 0.09, // 'chlorine' => 0.016,
'ph' => rand(750, 770) / 100, // 'conductivity' => 563,
'temperature' => rand(900, 1100) / 100, // 'oxygen' => 0.09,
'turbidity' => 0.33, // 'ph' => rand(750, 770) / 100,
default => null, // 'temperature' => rand(900, 1100) / 100,
}; // 'turbidity' => 1028.60,
} else { // default => null,
// };
// }
else {
$y[] = null; $y[] = null;
} }
@ -518,6 +535,21 @@ 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
@ -549,7 +581,10 @@ class DeviceController extends Controller
case 'device-supplier-biang': case 'device-supplier-biang':
$fields = [ $fields = [
'oxygen', 'oxygen',
'ph',
'temperature',
'turbidity', 'turbidity',
'nh3n',
]; ];
break; break;
} }
@ -609,31 +644,32 @@ 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];
} }
@ -703,7 +739,7 @@ class DeviceController extends Controller
// 日期 // 日期
$date = $startTime->toDateString(); $date = $startTime->toDateString();
$data[$date] = $wormReports->get($date); $data[$date] = $wormReports->get($date, 0);
$startTime->addDay(); $startTime->addDay();
} while ($startTime->lte($endTime)); } while ($startTime->lte($endTime));

View File

@ -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/getWaterDeviceData'), $this->apiUrl('/api/open-api/open/getCurrentWaterData'),
[ [
'deviceId' => $deviceId, 'deviceId' => $deviceId,
] ]

View File

@ -22,6 +22,8 @@ class SoilMonitoringDailyLog extends Model
'n', 'n',
'p', 'p',
'k', 'k',
'ph',
'moisture',
'monitored_at', 'monitored_at',
]; ];
} }

View File

@ -27,7 +27,9 @@ class SoilMonitoringLog extends Model
'n', 'n',
'p', 'p',
'k', 'k',
'ph',
'monitored_at', 'monitored_at',
'moisture',
'is_filled', 'is_filled',
]; ];
} }

View File

@ -22,6 +22,7 @@ class WaterQualityMonitoringDailyLog extends Model
'ph', 'ph',
'temperature', 'temperature',
'turbidity', 'turbidity',
'nh3n',
'monitored_at', 'monitored_at',
]; ];
} }

View File

@ -28,6 +28,7 @@ class WaterQualityMonitoringLog extends Model
'temperature', 'temperature',
'turbidity', 'turbidity',
'monitored_at', 'monitored_at',
'nh3n',
'is_filled', 'is_filled',
]; ];
} }

View File

@ -97,8 +97,9 @@ class BiAngDeviceService
'soilAvailablePotassium' => 'k', 'soilAvailablePotassium' => 'k',
'soilAvailablePhosphorus' => 'p', 'soilAvailablePhosphorus' => 'p',
'soilConductivity' => 'conductivity', 'soilConductivity' => 'conductivity',
'soilTemperature' => 'temperature', 'soilTemperature1' => 'temperature',
'soilMoisture' => 'humidity', 'soilHumidity1' => 'humidity',
'soilPH' => 'ph',
default => null, default => null,
}; };
@ -152,9 +153,11 @@ 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) {
'ec1' => 'conductivity', 'waterMlss' => 'turbidity',
'waterdo' => 'oxygen', 'waterPh' => 'ph',
'zd' => 'turbidity', 'waterDo' => 'oxygen',
'waterTemp' => 'temperature',
'waterNh3n' => 'nh3n',
default => null, default => null,
}; };
@ -416,6 +419,7 @@ 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) {
@ -474,6 +478,7 @@ 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) {

View File

@ -26,11 +26,14 @@ class LinkosDeviceLogService
*/ */
protected $soilMonitoringFields = [ protected $soilMonitoringFields = [
'conductivity' => 'conductivity', 'conductivity' => 'conductivity',
'humidity' => 'soil_humidity', 'soil_humidity' => 'humidity',
'temperature' => 'soil_temperature', 'soil_temperature' => 'temperature',
'n' => 'nitrogen_content', 'nitrogen_content' => 'n',
'p' => 'phosphorus_content', 'phosphorus_content' => 'p',
'k' => 'potassium_content', '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 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; return;
} }
@ -145,7 +148,7 @@ class LinkosDeviceLogService
'agricultural_base_id' => $device->agricultural_base_id, '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)) { if (! array_key_exists($key, $data)) {
continue; continue;
} }
@ -181,7 +184,7 @@ class LinkosDeviceLogService
$data = []; $data = [];
foreach ($logs as $log) { 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})) { if (is_null($v = $log->{$key})) {
continue; continue;
} }

View File

@ -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']);
});
}
};

View File

@ -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']);
});
}
};

View File

@ -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']);
});
}
};

View File

@ -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']);
});
}
};

View File

@ -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']);
});
}
};

View File

@ -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']);
});
}
};

View File

@ -61,6 +61,12 @@ 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"=>[
@ -99,6 +105,12 @@ 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":"平方公里"}'],