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