From 370c3aaaf302c7afb8bd346ff332714f0b15df09 Mon Sep 17 00:00:00 2001 From: Jing Li Date: Wed, 19 Oct 2022 10:16:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=9F=E5=A3=A4=E7=9B=91=E6=B5=8B=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=A8=A1=E5=9E=8B=E5=92=8C=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/SoilMonitoringLog.php | 27 +++++++++++ ...4910_create_soil_monitoring_logs_table.php | 45 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 app/Models/SoilMonitoringLog.php create mode 100644 database/migrations/2022_10_18_164910_create_soil_monitoring_logs_table.php diff --git a/app/Models/SoilMonitoringLog.php b/app/Models/SoilMonitoringLog.php new file mode 100644 index 0000000..711da7f --- /dev/null +++ b/app/Models/SoilMonitoringLog.php @@ -0,0 +1,27 @@ + 'datetime', + ]; + + protected $fillable = [ + 'device_id', + 'agricultural_base_id', + 'conductivity', + 'humidity', + 'temperature', + 'n', + 'p', + 'k', + 'monitored_at', + ]; +} diff --git a/database/migrations/2022_10_18_164910_create_soil_monitoring_logs_table.php b/database/migrations/2022_10_18_164910_create_soil_monitoring_logs_table.php new file mode 100644 index 0000000..78d973e --- /dev/null +++ b/database/migrations/2022_10_18_164910_create_soil_monitoring_logs_table.php @@ -0,0 +1,45 @@ +id(); + $table->unsignedBigInteger('device_id')->comment('设备ID'); + $table->unsignedBigInteger('agricultural_base_id')->comment('农业基地ID'); + $table->decimal('conductivity', 8, 2)->nullable()->comment('电导率 (单位: us/cm)'); + $table->decimal('humidity', 8, 2)->nullable()->comment('湿度 (单位: %RH)'); + $table->decimal('temperature', 8, 2)->nullable()->comment('温度 (单位: ℃)'); + $table->integer('n')->nullable()->comment('氮 (单位: mg/kg)'); + $table->integer('p')->nullable()->comment('磷 (单位: mg/kg)'); + $table->integer('k')->nullable()->comment('钾 (单位: mg/kg)'); + $table->timestamp('monitored_at')->comment('监控时间(小时)'); + $table->timestamps(); + + // 索引 + $table->index('device_id'); + $table->index('agricultural_base_id'); + $table->unique('monitored_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('soil_monitoring_logs'); + } +};