调整数据结构
parent
c01420471d
commit
cf8f326515
|
|
@ -95,9 +95,9 @@ class DeviceController extends AdminController
|
|||
$regionId = request()->input('region_id', 0);
|
||||
if($regionId){
|
||||
$region = Region::find($regionId);
|
||||
$query = $region->monitorModes();
|
||||
$query = $region->monitorModes()->where('type', MonitorMode::TYPE_MONITOR)->pluck('name','monitor_id');
|
||||
}else{
|
||||
$query = MonitorMode::query();
|
||||
$query = MonitorMode::where('type', MonitorMode::TYPE_MONITOR)->pluck('name','id');
|
||||
}
|
||||
return CRUDTable::make()
|
||||
->mode('cards')
|
||||
|
|
@ -111,7 +111,7 @@ class DeviceController extends AdminController
|
|||
->footerToolbar(['statistics', 'pagination'])
|
||||
->headerToolbar([])
|
||||
->filter($this->baseFilter()->actions([])->body([
|
||||
amisMake()->SelectControl('monitor_mode', '点位名称')->size('md')->options($query->where('type', MonitorMode::TYPE_MONITOR)->pluck('name','id')->toArray()),
|
||||
amisMake()->SelectControl('monitor_mode', '点位名称')->size('md')->options($query->toArray())->selectFirst(true),
|
||||
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||
Component::make()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ class DeviceFilter extends ModelFilter
|
|||
return $this->where('type', $type);
|
||||
}
|
||||
|
||||
// public function monitorMode($monitorMode){
|
||||
// if($monitorMode){
|
||||
// $monitorMode = MonitorMode::find($monitorMode)?->;
|
||||
// }
|
||||
// return $this->whereIn();
|
||||
// }
|
||||
public function monitorMode($monitorMode){
|
||||
if($monitorMode){
|
||||
$deviceIds = MonitorMode::find($monitorMode)?->devices()->get()->pluck('id')->toArray();
|
||||
}
|
||||
return $this->whereIn('id', $deviceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 类型
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ return new class extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::create('devices', function (Blueprint $table) {
|
||||
$table->engine = 'InnoDB';
|
||||
$table->id();
|
||||
$table->string('name')->comment('设备名称');
|
||||
$table->string('sn')->comment('设备唯一编码');
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ return new class extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::create('regions', function (Blueprint $table) {
|
||||
$table->engine = 'InnoDB';
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('cover')->nullable()->comment('封面图');
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ return new class extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::create('monitor_modes', function (Blueprint $table) {
|
||||
$table->engine = 'InnoDB';
|
||||
$table->id();
|
||||
$table->string('name')->comment('名称');
|
||||
$table->unsignedTinyInteger('type')->comment('类型: 1 视频监控, 2 土壤监测, 3 水质监测, 4 气象监测, 5 通风控制');
|
||||
|
|
|
|||
|
|
@ -14,10 +14,15 @@ return new class extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::create('monitor_devices', function (Blueprint $table) {
|
||||
$table->engine = 'InnoDB';
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('monitor_id');
|
||||
$table->unsignedBigInteger('device_id');
|
||||
$table->text('fields')->nullable()->comment('监测字段');
|
||||
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||
|
||||
$table->foreign('monitor_id')->references('id')->on('monitor_modes')->onDelete('cascade');
|
||||
$table->foreign('device_id')->references('id')->on('devices')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,15 @@ return new class extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::create('region_monitors', function (Blueprint $table) {
|
||||
$table->engine = 'InnoDB';
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('region_id');
|
||||
$table->unsignedBigInteger('monitor_id');
|
||||
$table->text('config')->nullable()->comment('配置信息');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('monitor_id')->references('id')->on('monitor_modes')->onDelete('cascade');
|
||||
$table->foreign('region_id')->references('id')->on('regions')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue