设备模型
parent
b1d17622ff
commit
a5ba159e5b
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum DeviceStatus: int
|
||||
{
|
||||
case Disabled = 0; // 禁用
|
||||
case Online = 1; // 在线
|
||||
case Offline = 2; // 离线
|
||||
case Broken = 3; // 故障
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum DeviceType: int
|
||||
{
|
||||
case Monitor = 1; // 监控设备
|
||||
case Soil = 2; // 土壤设备
|
||||
case WaterQuality = 3; // 水质设备
|
||||
case Meteorological = 4; // 气象设备
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\DeviceStatus;
|
||||
use App\Enums\DeviceType;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Device extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $attributes = [
|
||||
'status' => DeviceStatus::Offline,
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'type' => DeviceType::class,
|
||||
'status' => DeviceStatus::class,
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'agricultural_base_id',
|
||||
'sn',
|
||||
'name',
|
||||
'model',
|
||||
'monitoring_point',
|
||||
'type',
|
||||
'status',
|
||||
'extends',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(AdminUser::class, 'created_by');
|
||||
}
|
||||
|
||||
public function updatedBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(AdminUser::class, 'updated_by');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?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('devices', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('agricultural_base_id')->comment('农业基地ID');
|
||||
$table->string('sn')->comment('序列号');
|
||||
$table->string('name')->comment('名称');
|
||||
$table->string('model')->comment('型号');
|
||||
$table->string('monitoring_point')->nullable()->comment('监控点');
|
||||
$table->tinyInteger('type')->comment('类型: 1 监控设备, 2 土壤设备, 3 水质设备, 4 气象设备');
|
||||
$table->tinyInteger('status')->default(2)->comment('状态: 0 禁用, 1 在线, 2 离线, 3 故障');
|
||||
$table->json('extends')->nullable()->comment('扩展信息');
|
||||
$table->unsignedBigInteger('created_by')->comment('创建人ID');
|
||||
$table->unsignedBigInteger('updated_by')->comment('修改人ID');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('devices');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue