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