兼容界市园区土壤设备
parent
650ec1c5eb
commit
3d403653a5
|
|
@ -22,6 +22,7 @@ class SoilMonitoringDailyLog extends Model
|
||||||
'n',
|
'n',
|
||||||
'p',
|
'p',
|
||||||
'k',
|
'k',
|
||||||
|
'moisture',
|
||||||
'monitored_at',
|
'monitored_at',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ class SoilMonitoringLog extends Model
|
||||||
'p',
|
'p',
|
||||||
'k',
|
'k',
|
||||||
'monitored_at',
|
'monitored_at',
|
||||||
|
'moisture',
|
||||||
'is_filled',
|
'is_filled',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue