完善喷雾设置
parent
eab2a29438
commit
de943fda5a
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\AtomizingLogService;
|
||||
|
||||
class AtomizingLogController extends AdminController
|
||||
{
|
||||
protected string $serviceName = AtomizingLogService::class;
|
||||
}
|
||||
|
|
@ -352,6 +352,7 @@ class DeviceController extends AdminController
|
|||
$regionId = request()->input('region_id', 0);
|
||||
$config = null;
|
||||
$statusStr = '未知';
|
||||
$device = null;
|
||||
if($regionId){
|
||||
$region = Region::find($regionId);
|
||||
if($region){
|
||||
|
|
@ -429,21 +430,19 @@ class DeviceController extends AdminController
|
|||
amisMake()->Wrapper()->sm(6)->body([
|
||||
amisMake()->Panel()->title('开关记录')
|
||||
->body([
|
||||
\amisMake()->Table()->title('')
|
||||
->data([
|
||||
'items' => [
|
||||
[
|
||||
'name'=> '定时喷灌',
|
||||
'name1'=> '关闭',
|
||||
'time1'=> '2023-03-21 10:00:00',
|
||||
]
|
||||
]
|
||||
])
|
||||
->columns([
|
||||
amisMake()->TableColumn()->name('name')->label('触发条件'),
|
||||
amisMake()->TableColumn()->name('name1')->label('状态'),
|
||||
amisMake()->TableColumn()->name('time1')->label('执行时间'),
|
||||
])
|
||||
\amisMake()->CRUDTable()
|
||||
->api(admin_url('atomizing-logs').'?_action=getData&device_id='.($device?->id ?? 0))
|
||||
->title('')
|
||||
->columns([
|
||||
amisMake()->TableColumn()->name('type')->type('mapping')->map([
|
||||
"0"=>"<span class='label label-info'>未知</span>",
|
||||
"1"=>"<span class='label label-success'>开启</span>",
|
||||
"2"=>"<span class='label label-danger'>关闭</span>",
|
||||
"*"=> '其他:${type}'
|
||||
])->label('动作'),
|
||||
amisMake()->TableColumn()->name('content')->label('描述内容'),
|
||||
amisMake()->TableColumn()->name('created_at')->type('datetime')->label('操作时间'),
|
||||
])
|
||||
])
|
||||
]),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -100,4 +100,7 @@ Route::group([
|
|||
$router->post('crop-plant-detail', '\App\Admin\Controllers\CropPlantController@plantDetail');
|
||||
|
||||
$router->resource('system/settings', \App\Admin\Controllers\SettingController::class);
|
||||
|
||||
//喷雾自动开启/关闭日志
|
||||
$router->resource('atomizing-logs', \App\Admin\Controllers\AtomizingLogController::class)->only(['index']);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\MonitorMode;
|
||||
use App\Models\RegionMonitor;
|
||||
use App\Models\AtomizingLog;
|
||||
use App\Services\MqttService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ class MqttPenwuPlan extends Command
|
|||
//获取所有喷雾监控点,对应的自动喷雾配置
|
||||
$deviceList = Device::where('type', Device::TYPE_ATOMIZING)->get();
|
||||
$time = now()->format('H:i');//获取当前时间(时,分)
|
||||
// $time = '01:00';
|
||||
$time = '01:00';
|
||||
foreach($deviceList as $device){
|
||||
$_config = $device->extends ?? [];
|
||||
if($_config && $_config['is_enable']){//判断该配置是否开启
|
||||
|
|
@ -53,6 +52,12 @@ class MqttPenwuPlan extends Command
|
|||
||($item['value'] == 'b' && $status['yv2'] == 0)
|
||||
){
|
||||
$service->open($item['value'], $item['input']);
|
||||
//记录触发日志
|
||||
AtomizingLog::create([
|
||||
'device_id' => $device->id,
|
||||
'type' => 1,
|
||||
'content' => '自动开启【区域'.strtoupper($item['value']).'】,喷雾量'.$item['input'].'%',
|
||||
]);
|
||||
}
|
||||
}elseif($time == $end){
|
||||
if($status['is_running']){
|
||||
|
|
@ -61,6 +66,12 @@ class MqttPenwuPlan extends Command
|
|||
||($item['value'] == 'b' && $status['yv2'] == 1)
|
||||
){
|
||||
$service->close();
|
||||
//记录触发日志
|
||||
AtomizingLog::create([
|
||||
'device_id' => $device->id,
|
||||
'type' => 2,
|
||||
'content' => '自动关闭【区域'.strtoupper($item['value']).'】',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filters\Admin;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class AtomizingLogFilter extends ModelFilter
|
||||
{
|
||||
/**
|
||||
* 所属种植计划
|
||||
*/
|
||||
public function device($deviceId)
|
||||
{
|
||||
return $this->where('device_id', $deviceId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use EloquentFilter\Filterable;
|
||||
|
||||
class AtomizingLog extends Model
|
||||
{
|
||||
use Filterable;
|
||||
|
||||
protected $fillable = ['device_id', 'type', 'content', 'created_at', 'updated_at'];
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\AtomizingLog;
|
||||
use App\Filters\Admin\AtomizingLogFilter;
|
||||
|
||||
|
||||
/**
|
||||
* @method AtomizingLog getModel()
|
||||
* @method AtomizingLog|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class AtomizingLogService extends BaseService
|
||||
{
|
||||
protected string $modelName = AtomizingLog::class;
|
||||
|
||||
protected string $modelFilterName = AtomizingLogFilter::class;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('atomizing_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('device_id');
|
||||
$table->unsignedTinyInteger('type')->default(0)->comment('0未知;1开启,2关闭');
|
||||
$table->string('content');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('atomizing_logs');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue