You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.5 KiB
109 lines
3.5 KiB
<?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
|
|
{
|
|
$body = [
|
|
"lampType" => "internal",
|
|
"VehicleNumber" => [
|
|
"VehicleChannelNum" => 1,
|
|
"VehicleChannelList" => [
|
|
[
|
|
"LampSoure" => "internal", // unrelated
|
|
"VehicleNoExist" => [
|
|
"enabled" => true,
|
|
"flashEnabled" => false,
|
|
"lampColor" => 'red'
|
|
],
|
|
"VehicleExist" => [
|
|
"enabled" => true,
|
|
"flashEnabled" => false,
|
|
"lampColor" => 'red'
|
|
]
|
|
]
|
|
]
|
|
],
|
|
"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"
|
|
]
|
|
]
|
|
];
|
|
Cache::put('camera_body', json_encode($body), 300);
|
|
$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 = Cache::get('camera_body');
|
|
if (!$body) {
|
|
return $this->responseService->error('empty');
|
|
} else {
|
|
$bodyArr = json_decode($body);
|
|
Cache::delete('camera_body');
|
|
}
|
|
return $this->responseService->success($body, 'SUCCESS');
|
|
}
|
|
}
|
|
|