10 changed files with 220 additions and 14 deletions
@ -0,0 +1,23 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Device; |
||||
|
|
||||
|
use App\Http\Controllers\Controller; |
||||
|
use App\Services\ApiResponseService; |
||||
|
|
||||
|
class BaseController extends Controller |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var ApiResponseService |
||||
|
*/ |
||||
|
protected ApiResponseService $responseService; |
||||
|
|
||||
|
/** |
||||
|
* 构造函数 |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
$this->responseService = new ApiResponseService(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,107 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Device; |
||||
|
|
||||
|
use App\Models\ParkingCamera; |
||||
|
use App\Services\ParkingCameraService; |
||||
|
use Illuminate\Http\JsonResponse; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\Cache; |
||||
|
|
||||
|
class CameraApiController extends BaseController |
||||
|
{ |
||||
|
/** |
||||
|
* @var ParkingCameraService |
||||
|
*/ |
||||
|
protected ParkingCameraService $service; |
||||
|
|
||||
|
/** |
||||
|
* @param ParkingCameraService $service |
||||
|
*/ |
||||
|
public function __construct(ParkingCameraService $service) { |
||||
|
parent::__construct(); |
||||
|
$this->service = $service; |
||||
|
} |
||||
|
|
||||
|
public function getCameraData(): JsonResponse |
||||
|
{ |
||||
|
$data = ParkingCamera::query()->select(['id', 'camera_ip', 'status']) |
||||
|
->get() |
||||
|
->toArray(); |
||||
|
return $this->responseService->success(['list' => $data]); |
||||
|
} |
||||
|
|
||||
|
public function updateCameraStatus(Request $request): JsonResponse |
||||
|
{ |
||||
|
$data = $request->all(); |
||||
|
$list = $data['list']; |
||||
|
foreach ($list as $item) { |
||||
|
$id = $item['id'] ?? 0; |
||||
|
$camera_ip = $item['camera_ip'] ?? ''; |
||||
|
$status = $item['status'] ?? 0; |
||||
|
$this->service->updateStatus($id, $camera_ip, $status); |
||||
|
} |
||||
|
return $this->responseService->success([], 'SUCCESS'); |
||||
|
} |
||||
|
|
||||
|
public function getCameraBody(): JsonResponse |
||||
|
{ |
||||
|
$body = [ |
||||
|
"lampType" => "internal", |
||||
|
"VehicleNumber" => [ |
||||
|
"VehicleChannelNum" => 1, |
||||
|
"VehicleChannelList" => [ |
||||
|
[ |
||||
|
"LampSoure" => "internal", // unrelated |
||||
|
"VehicleNoExist" => [ |
||||
|
"enabled" => true, |
||||
|
"flashEnabled" => false, |
||||
|
"lampColor" => 'green' |
||||
|
], |
||||
|
"VehicleExist" => [ |
||||
|
"enabled" => true, |
||||
|
"flashEnabled" => false, |
||||
|
"lampColor" => 'green' |
||||
|
] |
||||
|
] |
||||
|
] |
||||
|
], |
||||
|
"replaceLampCtrl" => [ |
||||
|
"enabled" => false, |
||||
|
"ipV4Address" => "0.0.0.0", |
||||
|
"portNo" => 80, |
||||
|
"username" => "admin", |
||||
|
"password" => "dddf4589f3430f7b7395bb9d35e05b27" |
||||
|
], |
||||
|
"lampStatusArr" => [ |
||||
|
[ |
||||
|
"name" => "内置灯", |
||||
|
"value" => "相机自控", |
||||
|
"\$\$hashKey" => "062" |
||||
|
], |
||||
|
[ |
||||
|
"name" => "外置灯1", |
||||
|
"value" => "相机自控", |
||||
|
"\$\$hashKey" => "063" |
||||
|
], |
||||
|
[ |
||||
|
"name" => "外置灯2", |
||||
|
"value" => "相机自控", |
||||
|
"\$\$hashKey" => "064" |
||||
|
], |
||||
|
[ |
||||
|
"name" => "外置灯3", |
||||
|
"value" => "相机自控", |
||||
|
"\$\$hashKey" => "065" |
||||
|
] |
||||
|
] |
||||
|
]; |
||||
|
if (!$body) { |
||||
|
return $this->responseService->error('empty'); |
||||
|
} else { |
||||
|
// $bodyArr = json_decode($body); |
||||
|
// Cache::delete('camera_body'); |
||||
|
} |
||||
|
return $this->responseService->success($body, 'SUCCESS'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use Illuminate\Support\Facades\Route; |
||||
|
use App\Http\Controllers\Device\CameraApiController; |
||||
|
|
||||
|
Route::group(['prefix' => 'device'], function () { |
||||
|
|
||||
|
// 获取车位相机设备信息 |
||||
|
Route::get('/camera/getStatus', [CameraApiController::class, 'getCameraData']); |
||||
|
// 更新车位相机设备信息 |
||||
|
Route::put('/camera/getStatus', [CameraApiController::class, 'updateCameraStatus']); |
||||
|
// 获取车位相机设备更新信息 |
||||
|
Route::get('/camera/getBody', [CameraApiController::class, 'getCameraBody']); |
||||
|
|
||||
|
}); |
||||
Loading…
Reference in new issue