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