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.
58 lines
1.6 KiB
58 lines
1.6 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\Redis;
|
|
|
|
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 = Redis::get('camera_body');
|
|
if (!$body) {
|
|
return $this->responseService->error('empty');
|
|
} else {
|
|
$bodyArr = json_decode($body);
|
|
Redis::delete('camera_body');
|
|
}
|
|
return $this->responseService->success($bodyArr, 'SUCCESS');
|
|
}
|
|
}
|
|
|