- SystemSetting: 系统设置模型,支持配置管理 - Terminal: 终端模型,支持终端管理 - TerminalKnowledgeBase: 终端知识库关联模型 - TerminalPrompt: 终端提示词模型 - TerminalSyncLog: 终端同步日志模型 - SopTemplate: SOP模板模型 - SopStep: SOP步骤模型 - SopInteractiveTask: SOP交互任务模型 - SopTemplateVersion: SOP模板版本模型 所有模型集成 LogsActivity trait 用于操作日志记录
91 lines
2.1 KiB
PHP
91 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
use Spatie\Activitylog\LogOptions;
|
|
|
|
class Terminal extends Model
|
|
{
|
|
use HasFactory, SoftDeletes, LogsActivity;
|
|
|
|
/**
|
|
* 可批量赋值的属性
|
|
*
|
|
* @var array<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'code',
|
|
'ip_address',
|
|
'station_id',
|
|
'diagram_url',
|
|
'display_config',
|
|
'is_online',
|
|
'last_online_at',
|
|
];
|
|
|
|
/**
|
|
* 属性类型转换
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'display_config' => 'array',
|
|
'is_online' => 'boolean',
|
|
'last_online_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取终端关联的知识库
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function knowledgeBases()
|
|
{
|
|
return $this->belongsToMany(KnowledgeBase::class, 'terminal_knowledge_bases')
|
|
->withPivot('priority')
|
|
->withTimestamps()
|
|
->orderBy('priority');
|
|
}
|
|
|
|
/**
|
|
* 获取终端的提示词配置
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function prompt()
|
|
{
|
|
return $this->hasOne(TerminalPrompt::class);
|
|
}
|
|
|
|
/**
|
|
* 获取终端的同步日志
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function syncLogs()
|
|
{
|
|
return $this->hasMany(TerminalSyncLog::class);
|
|
}
|
|
|
|
/**
|
|
* 配置活动日志选项
|
|
*
|
|
* @return \Spatie\Activitylog\LogOptions
|
|
*/
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['name', 'code', 'station_id', 'diagram_url', 'display_config'])
|
|
->logOnlyDirty()
|
|
->setDescriptionForEvent(fn(string $eventName) => "终端已{$eventName}");
|
|
}
|
|
}
|