From a5ba159e5b83188cab92c61a5b6228a61f2ab44c Mon Sep 17 00:00:00 2001 From: Jing Li Date: Fri, 14 Oct 2022 16:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/DeviceStatus.php | 11 +++++ app/Enums/DeviceType.php | 11 +++++ app/Models/Device.php | 46 +++++++++++++++++++ ...2022_10_14_095443_create_devices_table.php | 41 +++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 app/Enums/DeviceStatus.php create mode 100644 app/Enums/DeviceType.php create mode 100644 app/Models/Device.php create mode 100644 database/migrations/2022_10_14_095443_create_devices_table.php diff --git a/app/Enums/DeviceStatus.php b/app/Enums/DeviceStatus.php new file mode 100644 index 0000000..218cb7f --- /dev/null +++ b/app/Enums/DeviceStatus.php @@ -0,0 +1,11 @@ + 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'); + } +} diff --git a/database/migrations/2022_10_14_095443_create_devices_table.php b/database/migrations/2022_10_14_095443_create_devices_table.php new file mode 100644 index 0000000..bb775e1 --- /dev/null +++ b/database/migrations/2022_10_14_095443_create_devices_table.php @@ -0,0 +1,41 @@ +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'); + } +};