保存喷雾管理
parent
4c9d067325
commit
de53ecbb16
|
|
@ -13,6 +13,7 @@ use App\Models\MeteorologicalReport;
|
|||
use App\Models\MonitorMode;
|
||||
use App\Models\Region;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\MqttService;
|
||||
|
||||
class DeviceController extends AdminController
|
||||
{
|
||||
|
|
@ -279,7 +280,6 @@ class DeviceController extends AdminController
|
|||
amisMake()->Wrapper()->sm(6)->body([
|
||||
amisMake()->Panel()->title('智能开关设置')
|
||||
->labelWidth(100)
|
||||
->className('Panel--success')
|
||||
->body([
|
||||
\amisMake()->Form()->title('')->mode('horizontal')->body([
|
||||
amisMake()->FieldSetControl()->title('智能开启')->body([
|
||||
|
|
@ -325,7 +325,6 @@ class DeviceController extends AdminController
|
|||
]),
|
||||
amisMake()->Wrapper()->sm(6)->body([
|
||||
amisMake()->Panel()->title('开关记录')
|
||||
->className('Panel--success')
|
||||
->body([
|
||||
\amisMake()->Table()->title('')
|
||||
->data([
|
||||
|
|
@ -348,23 +347,79 @@ class DeviceController extends AdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* 喷灌
|
||||
* 喷雾
|
||||
*/
|
||||
public function atomizingDetail(){
|
||||
$regionId = request()->input('region_id', 0);
|
||||
$config = null;
|
||||
$statusStr = '未知';
|
||||
if($regionId){
|
||||
$region = Region::find($regionId);
|
||||
if($region){
|
||||
$monitorMode = $region->monitorModes()->where('type', MonitorMode::TYPE_ATOMIZING)->first();
|
||||
$config = $monitorMode?->pivot->config ?? null;
|
||||
|
||||
if($monitorMode){
|
||||
//判断设备状态是否离线;
|
||||
$device = $monitorMode->devices()->first();
|
||||
if($device->state == Device::STATE_ONLINE){
|
||||
$res = (new MqttService())->getStatus();
|
||||
if($res['error']){
|
||||
switch($res['error']){
|
||||
case 1:
|
||||
$statusStr = '急停';
|
||||
break;
|
||||
case 2:
|
||||
$statusStr = '低水位报警';
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
if($res['is_running']){
|
||||
if($res['yv1']){
|
||||
$statusStr = '区域A运行中,喷雾量:'.$res['speed1'].'%';
|
||||
}elseif(['yv2']){
|
||||
$statusStr = '区域B运行中,喷雾量:'.$res['speed2'].'%';
|
||||
}
|
||||
}else{
|
||||
$statusStr = '未运行';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$statusStr = Device::stateMap()[$device->state];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return amisMake()->Grid()->columns([
|
||||
amisMake()->Wrapper()->sm(6)->body([
|
||||
amisMake()->Panel()->title('智能喷灌设置')
|
||||
->subFormMode('horizontal')
|
||||
->labelWidth(80)
|
||||
->className('Panel--success')
|
||||
->body([
|
||||
\amisMake()->Form()->title('')->mode('horizontal')->body([
|
||||
amisMake()->FieldSetControl()->title('定时喷灌')->body([
|
||||
\amisMake()->Form()->title('')->mode('horizontal')
|
||||
->api([
|
||||
'method'=>'post',
|
||||
'url'=>admin_url('save-region-config').'/'.$regionId,
|
||||
'data'=>[
|
||||
'is_enable' => '${is_enable}',
|
||||
'config' => '${config}'
|
||||
]
|
||||
])
|
||||
->data($config ? json_decode($config) : [])
|
||||
->body([
|
||||
amisMake()->FieldSetControl()->title('当前状态')->body([
|
||||
amisMake()->TextControl('status', '状态')->value($statusStr),
|
||||
])->static(),
|
||||
amisMake()->FieldSetControl()->className('mt-10')->title('定时喷灌')->body([
|
||||
\amisMake()->SwitchControl()->name('is_enable')->label('开关'),
|
||||
\amisMake()->ArrayControl()->name('config')->label('定时')->items([
|
||||
amisMake()->ComboControl()->items([
|
||||
\amisMake()->InputTimeRange(),
|
||||
\amisMake()->TextControl()->name('input')->label('喷灌量')->labelWidth(30),
|
||||
amisMake()->SelectControl('value')->options([
|
||||
'a'=>'区域A','b'=>'区域B'
|
||||
]),
|
||||
\amisMake()->InputTimeRange()->name('time_zone'),
|
||||
Components::make()->decimalControl('input', '喷雾量%')->value(70)->percision(0)->step(1)->max(100)
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
|
|
@ -373,7 +428,6 @@ class DeviceController extends AdminController
|
|||
]),
|
||||
amisMake()->Wrapper()->sm(6)->body([
|
||||
amisMake()->Panel()->title('开关记录')
|
||||
->className('Panel--success')
|
||||
->body([
|
||||
\amisMake()->Table()->title('')
|
||||
->data([
|
||||
|
|
@ -394,4 +448,20 @@ class DeviceController extends AdminController
|
|||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function saveRegionConfig($id, Request $request)
|
||||
{
|
||||
if($id){
|
||||
$region = Region::find($id);
|
||||
if($region){
|
||||
$monitorMode = $region->monitorModes()->where('type', MonitorMode::TYPE_ATOMIZING)->first();
|
||||
$config = $request->input() ?? null;
|
||||
$res = $region->monitorModes()->updateExistingPivot($monitorMode->id, [
|
||||
'config' => $config,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->autoResponse($res, __('admin.save'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ class MonitorModeController extends AdminController
|
|||
amisMake()->PickerControl('picker_devices', '喷雾设备')->visibleOn('data.type == '.MonitorMode::TYPE_ATOMIZING)
|
||||
->valueField('id')
|
||||
->labelField('name')
|
||||
->multiple(true)
|
||||
->multiple(false)//喷雾设备只能选择一个
|
||||
->size('lg')
|
||||
->source([
|
||||
'method' => 'get',
|
||||
|
|
|
|||
|
|
@ -91,6 +91,8 @@ Route::group([
|
|||
|
||||
$router->post('custom-region-atomizing', '\App\Admin\Controllers\DeviceController@atomizingDetail');
|
||||
|
||||
$router->post('save-region-config/{id}', '\App\Admin\Controllers\DeviceController@saveRegionConfig');
|
||||
|
||||
//种植记录
|
||||
$router->resource('crop-plants', \App\Admin\Controllers\CropPlantController::class)->only(['index','store', 'edit', 'update', 'destroy']);
|
||||
$router->resource('crop-harvestes', \App\Admin\Controllers\CropHarvestController::class)->only(['index','store', 'edit', 'update', 'destroy']);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MqttPenwuPlan extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'mqtt:penwu-plan';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'MQTT 喷雾控制';//-todo
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//获取所有喷雾监控点,对应的自动喷雾配置
|
||||
//获取当前时间(时,分)
|
||||
//判断该配置是否开启
|
||||
//判断当前该情况,并判断时间,决定开启,关闭,不作为;
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ class Region extends Model
|
|||
}
|
||||
|
||||
public function monitorModes(){
|
||||
return $this->belongsToMany(MonitorMode::class, RegionMonitor::class, 'region_id', 'monitor_id')->withTimestamps();
|
||||
return $this->belongsToMany(MonitorMode::class, RegionMonitor::class, 'region_id', 'monitor_id')->withTimestamps()->withPivot('config');
|
||||
}
|
||||
|
||||
// 种植记录
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class MqttService
|
||||
{
|
||||
|
||||
public function getStatus()
|
||||
{
|
||||
$res = Http::withHeaders([
|
||||
'Content-Type' => 'application/json;charset=UTF-8',
|
||||
])->get('http://36.133.205.221:92/status');
|
||||
return $res->json();
|
||||
}
|
||||
|
||||
public function mqttDo($parms)
|
||||
{
|
||||
$res = Http::withHeaders([
|
||||
'Content-Type' => 'application/json;charset=UTF-8',
|
||||
])->post('http://36.133.205.221:92/mqtt', $parms);
|
||||
return $res->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启哪个区域,多大量
|
||||
*/
|
||||
public function open($quyu, $liang)
|
||||
{
|
||||
$parms = [
|
||||
'speed1' => 0,
|
||||
'speed2' => 0,
|
||||
'yv1' => 0,
|
||||
'yv2' => 0,
|
||||
];
|
||||
switch($quyu){
|
||||
case 'a':
|
||||
$parms['speed1'] = $liang;
|
||||
$parms['yv1'] = 1;
|
||||
break;
|
||||
case 'b':
|
||||
$parms['speed2'] = $liang;
|
||||
$parms['yv2'] = 1;
|
||||
break;
|
||||
}
|
||||
return $this->mqttDo($parms);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
$parms = [
|
||||
'speed1' => 0,
|
||||
'speed2' => 0,
|
||||
'yv1' => 0,
|
||||
'yv2' => 0,
|
||||
];
|
||||
return $this->mqttDo($parms);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue