完善监测点位设置设备
parent
d07a31741a
commit
073f509618
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Slowlyo\OwlAdmin\Renderers\{Button, Form, Page, TableColumn, TextControl, Json, Component, CRUDTable, Card, Video, DateRangeControl, Mapping};
|
||||
use Slowlyo\OwlAdmin\Renderers\{Button, Form, Page, TableColumn, TextControl, Json, Component, CRUDTable, Card, Video, DateRangeControl, Mapping, SelectControl};
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\DeviceService;
|
||||
use App\Models\Device;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\MonitorMode;
|
||||
use App\Models\Region;
|
||||
|
||||
class DeviceController extends AdminController
|
||||
{
|
||||
|
|
@ -90,6 +92,13 @@ class DeviceController extends AdminController
|
|||
if ($this->actionOfGetData()) {
|
||||
return $this->response()->success($this->service->list());
|
||||
}
|
||||
$regionId = request()->input('region_id', 0);
|
||||
if($regionId){
|
||||
$region = Region::find($regionId);
|
||||
$query = $region->monitorModes();
|
||||
}else{
|
||||
$query = MonitorMode::query();
|
||||
}
|
||||
return CRUDTable::make()
|
||||
->mode('cards')
|
||||
->hideCheckToggler()
|
||||
|
|
@ -102,7 +111,7 @@ class DeviceController extends AdminController
|
|||
->footerToolbar(['statistics', 'pagination'])
|
||||
->headerToolbar([])
|
||||
->filter($this->baseFilter()->actions([])->body([
|
||||
TextControl::make()->name('name')->label('点位名称')->size('md'),
|
||||
amisMake()->SelectControl('monitor_mode', '点位名称')->size('md')->options($query->where('type', MonitorMode::TYPE_MONITOR)->pluck('name','id')->toArray()),
|
||||
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||
Component::make()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
|
|
|
|||
|
|
@ -68,16 +68,16 @@ class MonitorModeController extends AdminController
|
|||
amisMake()->Drawer()->title('设置监测设备')->resizable(true)->closeOnOutside(true)->closeOnEsc(true)->body([
|
||||
amisMake()
|
||||
->Form()
|
||||
->api(admin_url(''))//--todo
|
||||
->api(admin_url('monitor-mode-save-devices'))
|
||||
->initApi($this->getEditGetDataPath())
|
||||
->mode('normal')
|
||||
->data(['id' => '${id}'])
|
||||
->body([
|
||||
amisMake()->RadiosControl()->name('type')->label('类型')->options(MonitorMode::typeMap())->disabled(true),
|
||||
amisMake()->PickerControl('monitor_devices', '监控设备')->visibleOn('data.type == '.MonitorMode::TYPE_MONITOR)
|
||||
amisMake()->PickerControl('picker_devices', '监控设备')->visibleOn('data.type == '.MonitorMode::TYPE_MONITOR)
|
||||
->valueField('id')
|
||||
->labelField('name')
|
||||
->multiple(true)
|
||||
->multiple(true)->joinValues(false)->extractValue(true)
|
||||
->size('lg')
|
||||
->source([
|
||||
'method' => 'get',
|
||||
|
|
@ -109,28 +109,28 @@ class MonitorModeController extends AdminController
|
|||
]
|
||||
]
|
||||
),
|
||||
amisMake()->ArrayControl('soil_devices', '土壤监测')->visibleOn('data.type == '.MonitorMode::TYPE_SOIL)
|
||||
amisMake()->ArrayControl('array_devices', '土壤监测')->visibleOn('data.type == '.MonitorMode::TYPE_SOIL)
|
||||
->items(
|
||||
amisMake()->ComboControl()->items([
|
||||
\amisMake()->CheckboxesControl('device_fields', '监测字段')->checkAll(true)->options(MonitorMode::fieldMap(MonitorMode::TYPE_SOIL)),
|
||||
\amisMake()->SelectControl('device_id', '监测设备'),
|
||||
\amisMake()->SelectControl('device_id', '监测设备')->options(Device::where('type', Device::TYPE_SOIL)->get()->pluck('name', 'id')),
|
||||
]),
|
||||
),
|
||||
amisMake()->ArrayControl('water_devices', '水质监测')->visibleOn('data.type == '.MonitorMode::TYPE_WATER_QUALITY)
|
||||
amisMake()->ArrayControl('array_devices', '水质监测')->visibleOn('data.type == '.MonitorMode::TYPE_WATER_QUALITY)
|
||||
->items(
|
||||
amisMake()->ComboControl()->items([
|
||||
\amisMake()->CheckboxesControl('device_fields', '监测字段')->checkAll(true)->options(MonitorMode::fieldMap(MonitorMode::TYPE_WATER_QUALITY)),
|
||||
\amisMake()->SelectControl('device_id', '监测设备'),
|
||||
]),
|
||||
),
|
||||
amisMake()->ArrayControl('meteorological_devices', '气象监测')->visibleOn('data.type == '.MonitorMode::TYPE_METEOROLOGICAL)
|
||||
amisMake()->ArrayControl('array_devices', '气象监测')->visibleOn('data.type == '.MonitorMode::TYPE_METEOROLOGICAL)
|
||||
->items(
|
||||
amisMake()->ComboControl()->items([
|
||||
\amisMake()->CheckboxesControl('device_fields', '监测字段')->checkAll(true)->options(MonitorMode::fieldMap(MonitorMode::TYPE_METEOROLOGICAL)),
|
||||
\amisMake()->SelectControl('device_id', '监测设备'),
|
||||
]),
|
||||
),
|
||||
amisMake()->PickerControl('air_devices', '通风设备')->visibleOn('data.type == '.MonitorMode::TYPE_AIR)
|
||||
amisMake()->PickerControl('picker_devices', '通风设备')->visibleOn('data.type == '.MonitorMode::TYPE_AIR)
|
||||
->valueField('id')
|
||||
->labelField('name')
|
||||
->multiple(true)
|
||||
|
|
@ -165,7 +165,7 @@ class MonitorModeController extends AdminController
|
|||
]
|
||||
]
|
||||
),
|
||||
amisMake()->PickerControl('atomizing_devices', '喷雾设备')->visibleOn('data.type == '.MonitorMode::TYPE_ATOMIZING)
|
||||
amisMake()->PickerControl('picker_devices', '喷雾设备')->visibleOn('data.type == '.MonitorMode::TYPE_ATOMIZING)
|
||||
->valueField('id')
|
||||
->labelField('name')
|
||||
->multiple(true)
|
||||
|
|
@ -206,4 +206,11 @@ class MonitorModeController extends AdminController
|
|||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function saveDevices()
|
||||
{
|
||||
$result = $this->service->saveDevices(request('id'), request());
|
||||
|
||||
return $this->autoResponse($result, __('admin.save'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ Route::group([
|
|||
|
||||
//监测点位
|
||||
$router->resource('monitor-modes', \App\Admin\Controllers\MonitorModeController::class);
|
||||
$router->post('quick-edit/monitor-modes/{monitor_mode}',[\App\Admin\Controllers\MonitorModeController::class, 'update']);
|
||||
$router->post('monitor-mode-save-devices', '\App\Admin\Controllers\MonitorModeController@saveDevices');
|
||||
|
||||
//区域分类
|
||||
$router->resource('region-categories', \App\Admin\Controllers\RegionCategoryController::class);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Filters\Admin;
|
|||
|
||||
use EloquentFilter\ModelFilter;
|
||||
use App\Models\Device;
|
||||
use App\Models\MonitorMode;
|
||||
|
||||
class DeviceFilter extends ModelFilter
|
||||
{
|
||||
|
|
@ -28,6 +29,13 @@ class DeviceFilter extends ModelFilter
|
|||
return $this->where('type', $type);
|
||||
}
|
||||
|
||||
// public function monitorMode($monitorMode){
|
||||
// if($monitorMode){
|
||||
// $monitorMode = MonitorMode::find($monitorMode)?->;
|
||||
// }
|
||||
// return $this->whereIn();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filters\Admin;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
use App\Models\Device;
|
||||
|
||||
class MonitorModeFilter extends ModelFilter
|
||||
{
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
public function name($name){
|
||||
return $this->where('name', 'like', '%'.$name.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
public function type($type){
|
||||
return $this->where('type', $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
public function typeName($typeName){
|
||||
$type = 0;
|
||||
foreach(Device::typeMap() as $key => $item){
|
||||
if($item == $typeName){
|
||||
$type = $key;
|
||||
break;
|
||||
}
|
||||
};
|
||||
return $this->where('type', $type);
|
||||
}
|
||||
/**
|
||||
* 分组
|
||||
*/
|
||||
public function groupTags($groupTags){
|
||||
return $this->whereRaw("FIND_IN_SET(group_tags,'$groupTags')");
|
||||
}
|
||||
}
|
||||
|
|
@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||
class MonitorDevice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,4 +85,8 @@ class MonitorMode extends Model
|
|||
get: fn($value) => $this->group_tags ? explode(',', $this->group_tags) : [],
|
||||
);
|
||||
}
|
||||
|
||||
public function devices(){
|
||||
return $this->belongsToMany(Device::class, MonitorDevice::class, 'monitor_id', 'device_id')->withPivot('fields');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class Region extends Model
|
|||
$tabs[] = [//有监控设备才有
|
||||
'title' => '监控视频',
|
||||
'value' => 'monitor',
|
||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-monitor?id='.$region->id)),
|
||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-monitor?region_id='.$region->id)),
|
||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||
'sort' => 1,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\MonitorMode;
|
||||
use App\Filters\Admin\MonitorModeFilter;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* @method MonitorMode getModel()
|
||||
|
|
@ -11,4 +14,65 @@ use App\Models\MonitorMode;
|
|||
class MonitorModeService extends BaseService
|
||||
{
|
||||
protected string $modelName = MonitorMode::class;
|
||||
|
||||
protected string $modelFilterName = MonitorModeFilter::class;
|
||||
|
||||
public function getEditData($id): Model|\Illuminate\Database\Eloquent\Collection|Builder|array|null
|
||||
{
|
||||
$region = parent::getEditData($id);
|
||||
//处理详情数据;
|
||||
$region->load('devices');
|
||||
|
||||
switch($region->type) {
|
||||
case MonitorMode::TYPE_MONITOR:
|
||||
case MonitorMode::TYPE_AIR:
|
||||
case MonitorMode::TYPE_ATOMIZING:
|
||||
$region->offsetSet('picker_devices', $region->devices->pluck('id')->toArray());
|
||||
break;
|
||||
case MonitorMode::TYPE_SOIL:
|
||||
case MonitorMode::TYPE_WATER_QUALITY:
|
||||
case MonitorMode::TYPE_METEOROLOGICAL:
|
||||
$region->offsetSet('array_devices', $region->devices->map(function($item, $key){
|
||||
return [
|
||||
'device_id' => $item->id,
|
||||
'device_fields' => explode(',', $item->pivot->fields ?? ''),
|
||||
];
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
return $region;
|
||||
}
|
||||
|
||||
public function saveDevices($primaryKey, $params){
|
||||
$model = $this->query()->whereKey($primaryKey)->first();
|
||||
$type = $params['type'] ?? null;
|
||||
$syncData = [];
|
||||
switch($type){
|
||||
case MonitorMode::TYPE_MONITOR:
|
||||
case MonitorMode::TYPE_AIR:
|
||||
case MonitorMode::TYPE_ATOMIZING:
|
||||
$syncData = $params['picker_devices'] ?? [];
|
||||
break;
|
||||
case MonitorMode::TYPE_SOIL:
|
||||
case MonitorMode::TYPE_WATER_QUALITY:
|
||||
case MonitorMode::TYPE_METEOROLOGICAL:
|
||||
$arrayDevices = $params['array_devices'] ?? [];
|
||||
if($arrayDevices){
|
||||
foreach($arrayDevices as $arrayDevice){
|
||||
//过滤重复设备
|
||||
if(isset($syncData[$arrayDevice['device_id']])){
|
||||
return $this->setError('请勿重复选择监测设备');
|
||||
}
|
||||
$syncData[$arrayDevice['device_id']] = [
|
||||
'fields' => $arrayDevice['device_fields']
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $model->devices()->sync($syncData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue