设备日志
parent
f2a1be3adc
commit
0eef056851
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use EloquentFilter\Filterable;
|
use EloquentFilter\Filterable;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class Device extends Model
|
class Device extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -16,6 +17,10 @@ class Device extends Model
|
||||||
public const TYPE_WATER_QUALITY = 3; //水质设备
|
public const TYPE_WATER_QUALITY = 3; //水质设备
|
||||||
public const TYPE_METEOROLOGICAL = 4; //气象设备
|
public const TYPE_METEOROLOGICAL = 4; //气象设备
|
||||||
|
|
||||||
|
public const STATE_DISABLED = 0;
|
||||||
|
public const STATE_ONLINE = 1;
|
||||||
|
public const STATE_OFFLINE = 2;
|
||||||
|
public const STATE_FAULT = 3;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name', 'sn', 'powered_by', 'type', 'model_sn', 'state', 'extends',
|
'name', 'sn', 'powered_by', 'type', 'model_sn', 'state', 'extends',
|
||||||
|
|
@ -26,6 +31,11 @@ class Device extends Model
|
||||||
return $date->format('Y-m-d H:i:s');
|
return $date->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function logs(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(DeviceLog::class);
|
||||||
|
}
|
||||||
|
|
||||||
public static function typeMap()
|
public static function typeMap()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class DeviceLog extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'data' => 'json',
|
||||||
|
'reported_at' => 'datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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('device_logs', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('device_id');
|
||||||
|
$table->json('data')->nullable();
|
||||||
|
$table->timestamp('reported_at');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->index(['device_id', 'reported_at']);
|
||||||
|
$table->index('reported_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('device_logs');
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue