气象监测日志模型和数据库迁移
parent
370c3aaaf3
commit
dd2b56a0d2
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum WindDirection: int
|
||||
{
|
||||
case North = 0; // 北风
|
||||
case Northeast = 1; // 东北风;
|
||||
case East = 2; // 东风
|
||||
case Southeast = 3; // 东南风
|
||||
case South = 4; // 南方
|
||||
case Southwest = 5; // 西南风
|
||||
case West = 6; // 西风
|
||||
case Northwest = 7; // 西北风
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\WindDirection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MeteorologicalMonitoringLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'wind_direction' => WindDirection::class,
|
||||
'monitored_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'device_id',
|
||||
'agricultural_base_id',
|
||||
'wind_speed',
|
||||
'wind_power',
|
||||
'wind_direction',
|
||||
'wind_degree',
|
||||
'air_humidity',
|
||||
'air_temperature',
|
||||
'air_pressure',
|
||||
'co2',
|
||||
'noise',
|
||||
'illumination',
|
||||
'accumulated_rainfall',
|
||||
'current_rainfall',
|
||||
'moment_rainfall',
|
||||
'day_rainfall',
|
||||
'pm25',
|
||||
'pm10',
|
||||
'monitored_at',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?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::create('meteorological_monitoring_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('device_id')->comment('设备ID');
|
||||
$table->unsignedBigInteger('agricultural_base_id')->comment('农业基地ID');
|
||||
$table->decimal('wind_speed', 8, 2)->nullable()->comment('风速 (单位: m/s)');
|
||||
$table->integer('wind_power')->nullable()->comment('风力');
|
||||
$table->tinyInteger('wind_direction')->nullable()->comment('风向: 0 北风, 1 东北风, 2 东风, 3 东南风, 4 南风, 5 西南风, 6 西风, 7 西北风');
|
||||
$table->integer('wind_degree')->nullable()->comment('风向度数');
|
||||
$table->decimal('air_humidity', 8, 2)->nullable()->comment('空气湿度 (单位: db)');
|
||||
$table->decimal('air_temperature', 8, 2)->nullable()->comment('气温 (单位: db)');
|
||||
$table->decimal('air_pressure', 8, 2)->nullable()->comment('气压 (单位: Kpa)');
|
||||
$table->decimal('co2', 8, 2)->nullable()->comment('二氧化碳浓度 (单位: ppm)');
|
||||
$table->decimal('noise', 8, 2)->nullable()->comment('噪声 (单位: db)');
|
||||
$table->integer('illumination')->nullable()->comment('光照度 (单位: Lux)');
|
||||
$table->decimal('accumulated_rainfall', 8, 2)->nullable()->comment('积雨量 (单位: mm)');
|
||||
$table->decimal('current_rainfall', 8, 2)->nullable()->comment('当前雨量 (单位: mm)');
|
||||
$table->decimal('moment_rainfall', 8, 2)->nullable()->comment('瞬时雨量 (单位: mm)');
|
||||
$table->decimal('day_rainfall', 8, 2)->nullable()->comment('日雨量 (单位: mm)');
|
||||
$table->integer('pm25')->nullable()->comment('PM2.5浓度 (单位: ug/m3)');
|
||||
$table->integer('pm10')->nullable()->comment('PM10浓度 (单位: ug/m3)');
|
||||
$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('meteorological_monitoring_logs');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue