调整喷雾设备后台自动设置
parent
de53ecbb16
commit
101bb2c632
|
|
@ -2,15 +2,14 @@
|
||||||
|
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use Slowlyo\OwlAdmin\Renderers\{Button, Form, Page, TableColumn, TextControl, Json, Component, CRUDTable, Card, Video, DateRangeControl, Mapping, SelectControl};
|
use Slowlyo\OwlAdmin\Renderers\{Button, Form, Page, TableColumn, TextControl, Json, Component, CRUDTable, Card, Video, DateRangeControl, Mapping};
|
||||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use App\Services\Admin\DeviceService;
|
use App\Services\Admin\DeviceService;
|
||||||
use App\Admin\Components;
|
use App\Admin\Components;
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\Keyword;
|
use App\Models\Keyword;
|
||||||
use App\Models\MeteorologicalDailyReport;
|
|
||||||
use App\Models\MeteorologicalReport;
|
|
||||||
use App\Models\MonitorMode;
|
use App\Models\MonitorMode;
|
||||||
|
use App\Models\RegionMonitor;
|
||||||
use App\Models\Region;
|
use App\Models\Region;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Services\MqttService;
|
use App\Services\MqttService;
|
||||||
|
|
@ -357,7 +356,8 @@ class DeviceController extends AdminController
|
||||||
$region = Region::find($regionId);
|
$region = Region::find($regionId);
|
||||||
if($region){
|
if($region){
|
||||||
$monitorMode = $region->monitorModes()->where('type', MonitorMode::TYPE_ATOMIZING)->first();
|
$monitorMode = $region->monitorModes()->where('type', MonitorMode::TYPE_ATOMIZING)->first();
|
||||||
$config = $monitorMode?->pivot->config ?? null;
|
$device = $monitorMode->devices()->first();
|
||||||
|
$config = $device?->extends ?? null;
|
||||||
|
|
||||||
if($monitorMode){
|
if($monitorMode){
|
||||||
//判断设备状态是否离线;
|
//判断设备状态是否离线;
|
||||||
|
|
@ -406,7 +406,7 @@ class DeviceController extends AdminController
|
||||||
'config' => '${config}'
|
'config' => '${config}'
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
->data($config ? json_decode($config) : [])
|
->data($config ? $config : [])
|
||||||
->body([
|
->body([
|
||||||
amisMake()->FieldSetControl()->title('当前状态')->body([
|
amisMake()->FieldSetControl()->title('当前状态')->body([
|
||||||
amisMake()->TextControl('status', '状态')->value($statusStr),
|
amisMake()->TextControl('status', '状态')->value($statusStr),
|
||||||
|
|
@ -456,8 +456,9 @@ class DeviceController extends AdminController
|
||||||
if($region){
|
if($region){
|
||||||
$monitorMode = $region->monitorModes()->where('type', MonitorMode::TYPE_ATOMIZING)->first();
|
$monitorMode = $region->monitorModes()->where('type', MonitorMode::TYPE_ATOMIZING)->first();
|
||||||
$config = $request->input() ?? null;
|
$config = $request->input() ?? null;
|
||||||
$res = $region->monitorModes()->updateExistingPivot($monitorMode->id, [
|
|
||||||
'config' => $config,
|
$res = $monitorMode->devices()->update([
|
||||||
|
'extends' => $config,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Device;
|
||||||
|
use App\Models\MonitorMode;
|
||||||
|
use App\Models\RegionMonitor;
|
||||||
|
use App\Services\MqttService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class MqttPenwuPlan extends Command
|
class MqttPenwuPlan extends Command
|
||||||
|
|
@ -18,7 +22,7 @@ class MqttPenwuPlan extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'MQTT 喷雾控制';//-todo
|
protected $description = 'MQTT 喷雾控制';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
|
|
@ -27,10 +31,42 @@ class MqttPenwuPlan extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
//首先获取当前状态
|
||||||
|
$service = new MqttService();
|
||||||
|
$status = $service->getStatus();
|
||||||
|
//判断是否离线,或者状态异常;
|
||||||
|
if($status && $status['error'] == 0 && $status['status'] == 1){
|
||||||
//获取所有喷雾监控点,对应的自动喷雾配置
|
//获取所有喷雾监控点,对应的自动喷雾配置
|
||||||
//获取当前时间(时,分)
|
$deviceList = Device::where('type', Device::TYPE_ATOMIZING)->get();
|
||||||
//判断该配置是否开启
|
$time = now()->format('H:i');//获取当前时间(时,分)
|
||||||
//判断当前该情况,并判断时间,决定开启,关闭,不作为;
|
foreach($deviceList as $device){
|
||||||
|
$_config = $device->extends ?? [];
|
||||||
|
if($_config && $_config['is_enable']){//判断该配置是否开启
|
||||||
|
foreach($_config['config'] as $item){
|
||||||
|
list($start, $end) = explode(',', $item['time_zone']);
|
||||||
|
//决定开启,关闭,
|
||||||
|
if($time == $start){//相等
|
||||||
|
//如果当前对应位置已开启,则不作为
|
||||||
|
if(
|
||||||
|
($item['value'] == 'a' && $status['yv1'] == 0)
|
||||||
|
||($item['value'] == 'b' && $status['yv2'] == 0)
|
||||||
|
){
|
||||||
|
$service->open($item['value'], $item['input']);
|
||||||
|
}
|
||||||
|
}elseif($time == $end){
|
||||||
|
if($status['is_running']){
|
||||||
|
if(
|
||||||
|
($item['value'] == 'a' && $status['yv1'] == 1)
|
||||||
|
||($item['value'] == 'b' && $status['yv2'] == 1)
|
||||||
|
){
|
||||||
|
$service->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')->hourly();
|
// $schedule->command('inspire')->hourly();
|
||||||
|
$schedule->command('mqtt:penwu-plan')->everyMinute();//每分钟执行
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue