添加看板设备数据接口
parent
e5b0a286a9
commit
7a892f8c86
|
|
@ -2,12 +2,15 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Enums\DeviceType;
|
||||
use App\Helpers\Paginator;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\SoilMonitoringLog;
|
||||
use App\Http\Requestes\DeviceRequest;
|
||||
use App\Http\Resources\DeviceResource;
|
||||
use App\Models\Device;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\WaterQualityMonitoringLog;
|
||||
use App\Models\MeteorologicalMonitoringLog;
|
||||
|
||||
class DeviceController extends Controller
|
||||
{
|
||||
|
|
@ -64,4 +67,55 @@ class DeviceController extends Controller
|
|||
{
|
||||
return $this->json(DeviceType::types());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备数据
|
||||
*/
|
||||
public function dataStatics(Request $request)
|
||||
{
|
||||
$deviceId = $request->input('device_id');
|
||||
$deviceColumn = $request->input('device_column');//指定字段
|
||||
|
||||
$device = Device::find($deviceId);
|
||||
$data = null;
|
||||
switch ($device->type){
|
||||
case DeviceType::Monitor://监控设备
|
||||
$data = DeviceResource::make($device);
|
||||
break;
|
||||
case DeviceType::Meteorological://气象设备
|
||||
//当天最新一条
|
||||
$log = MeteorologicalMonitoringLog::where('device_id', $deviceId)->orderBy('created_at', 'desc')->first();
|
||||
$data = $log->toArray();
|
||||
break;
|
||||
case DeviceType::Soil://土壤设备
|
||||
//当天
|
||||
$dataList = SoilMonitoringLog::where('device_id', $deviceId)->whereDate('monitored_at', now())->get()->keyBy('monitored_at')->toArray();
|
||||
$data = [];
|
||||
for ($i = 0; $i < 24; $i++){
|
||||
$_key = date('Y-m-d').' '.str_pad($i, 2, '0',STR_PAD_LEFT).':00:00';
|
||||
$data[$_key] = 0;
|
||||
if(isset($dataList[$_key])){
|
||||
$data[$_key] = $dataList[$_key][$deviceColumn] ?? 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DeviceType::WaterQuality://水质设备
|
||||
//当天
|
||||
$dataList = WaterQualityMonitoringLog::where('device_id', $deviceId)->whereDate('monitored_at', now())->get()->keyBy('monitored_at')->toArray();
|
||||
$data = [];
|
||||
for ($i = 0; $i < 24; $i++){
|
||||
$_key = date('Y-m-d').' '.str_pad($i, 2, '0',STR_PAD_LEFT).':00:00';
|
||||
$data[$_key] = 0;
|
||||
if(isset($dataList[$_key])){
|
||||
$data[$_key] = $dataList[$_key][$deviceColumn] ?? 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->json([
|
||||
'list' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,8 @@ class AgriculturalBaseFilter extends ModelFilter
|
|||
{
|
||||
return $this->where('type', $type);
|
||||
}
|
||||
|
||||
public function parentId($parentId){
|
||||
return $this->where('parent_id', $parentId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,4 +20,8 @@ class DeviceFilter extends ModelFilter
|
|||
{
|
||||
return $this->where('type', $type);
|
||||
}
|
||||
|
||||
public function status($status){
|
||||
return $this->where('status', $status);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ Route::group(['middleware' => 'auth:sanctum'], function () {
|
|||
Route::get('crop-yield-total-list', [CropYieldController::class, 'totalStaticsList']);//城镇统计产值
|
||||
Route::get('crop-yield-total-chart', [CropYieldController::class, 'totalStaticsChart']);//城镇统计产值
|
||||
|
||||
Route::get('device-data-statics', [DeviceController::class, 'dataStatics']);
|
||||
|
||||
/** 系统管理 **/
|
||||
Route::apiResource('admin-users', AdminUserController::class)->names('admin_users');
|
||||
Route::put('admin-users/{admin_user}/enable', [AdminUserController::class, 'endable'])->name('admin_users.enable');
|
||||
|
|
|
|||
Loading…
Reference in New Issue