17 changed files with 935 additions and 27 deletions
@ -0,0 +1,343 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Admin; |
|||
|
|||
use App\Exceptions\CustomException; |
|||
use App\Models\AdminFloor; |
|||
use App\Models\ParkingCamera; |
|||
use App\Models\ParkingSpaceAttributes; |
|||
use App\Models\ParkingSpaceCamera; |
|||
use App\Services\AdminFloorService; |
|||
use App\Services\ApiResponseService; |
|||
use App\Services\ParkingCameraService; |
|||
use Exception; |
|||
use Illuminate\Http\JsonResponse; |
|||
use Illuminate\Http\Request; |
|||
use Illuminate\Support\Facades\Validator; |
|||
use Illuminate\Validation\ValidationException; |
|||
use JetBrains\PhpStorm\ArrayShape; |
|||
use Psr\SimpleCache\InvalidArgumentException; |
|||
|
|||
class ParkingCameraController extends BaseController |
|||
{ |
|||
protected ParkingCameraService $service; |
|||
|
|||
/** |
|||
* 构造函数 |
|||
* @param ApiResponseService $responseService |
|||
* @param ParkingCameraService $service |
|||
*/ |
|||
public function __construct( |
|||
ApiResponseService $responseService, |
|||
ParkingCameraService $service |
|||
) { |
|||
parent::__construct($responseService); |
|||
$this->service = $service; |
|||
} |
|||
|
|||
public function index(Request $request): JsonResponse |
|||
{ |
|||
try { |
|||
$query = ParkingCamera::query(); |
|||
|
|||
if ($request->has('floor_id')) { |
|||
$floor_id = $request->input('floor_id'); |
|||
if ($floor_id) { |
|||
$query->where('floor_id', $floor_id); |
|||
} |
|||
} |
|||
|
|||
if ($request->has('number')) { |
|||
$number = $request->input('number'); |
|||
if ($number) { |
|||
$query->where('number', 'like', "%{$number}%"); |
|||
} |
|||
} |
|||
|
|||
if ($request->has('parking_space_number')) { |
|||
$parking_space_number = $request->input('parking_space_number'); |
|||
if ($parking_space_number) { |
|||
$cameraIds = ParkingSpaceCamera::getCameraIds( |
|||
$parking_space_number |
|||
); |
|||
if ($cameraIds) { |
|||
$query->whereIn('id', $cameraIds); |
|||
} else { |
|||
$query->where('id', 0); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if ($request->has('camera_ip')) { |
|||
$camera_ip = $request->input('camera_ip'); |
|||
if ($camera_ip) { |
|||
$query->where('camera_ip', $camera_ip); |
|||
} |
|||
} |
|||
|
|||
if ($request->has('status')) { |
|||
$status = $request->input('status'); |
|||
if (is_numeric($status)) { |
|||
$query->where('status', $status); |
|||
} |
|||
} |
|||
|
|||
// 分页 |
|||
$page = $request->input('page', 1); |
|||
$perPage = $request->input('per_page', 10); |
|||
|
|||
$columns = [ |
|||
'id', |
|||
'floor_id', |
|||
'number', |
|||
'camera_ip', |
|||
'is_control_lights', |
|||
'type', |
|||
'status', |
|||
'updated_at' |
|||
]; |
|||
$isArr = ParkingCameraService::getIsControlLights(); |
|||
$typeArr = ParkingCameraService::getType(); |
|||
$statusArr = ParkingCameraService::getStatus(); |
|||
$total = $query->count(); |
|||
$items = $query->latest()->forPage($page, $perPage)->select( |
|||
$columns |
|||
)->get() |
|||
->each( |
|||
function ($item) use ($isArr, $typeArr, $statusArr) { |
|||
$item['floor'] = AdminFloor::getName($item['floor_id']); |
|||
$item['parking_space_count'] |
|||
= ParkingSpaceCamera::getSpaceCount($item['id']); |
|||
$item['parking_space_numbers'] |
|||
= ParkingSpaceCamera::getParkingSpaceNumber( |
|||
$item['id'] |
|||
); |
|||
$item['is_control_lights'] |
|||
= $isArr[$item['is_control_lights']] ?? ''; |
|||
$item['type'] = $typeArr[$item['type']] ?? ''; |
|||
$item['status'] = $statusArr[$item['status']] ?? ''; |
|||
unset($item['floor_id']); |
|||
} |
|||
); |
|||
|
|||
return $this->responseService->success([ |
|||
'items' => $items, |
|||
'total' => $total, |
|||
'page' => $page, |
|||
'per_page' => $perPage, |
|||
'last_page' => ceil($total / $perPage), |
|||
]); |
|||
} catch (Exception $e) { |
|||
$m_prefix = __('exception.exception_handler.resource'); |
|||
return $this->responseService->systemError( |
|||
$m_prefix . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
public function search(): JsonResponse |
|||
{ |
|||
try { |
|||
$data = [ |
|||
'floor_list' => $this->getFloorList(), |
|||
'status_list' => get_select_data(ParkingCameraService::getStatus(), true) |
|||
]; |
|||
return $this->responseService->success($data); |
|||
} catch (Exception $e) { |
|||
$m_prefix = __('exception.exception_handler.resource'); |
|||
return $this->responseService->systemError( |
|||
$m_prefix . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
public function create(): JsonResponse |
|||
{ |
|||
try { |
|||
$data = $this->getViewData(); |
|||
return $this->responseService->success($data); |
|||
} catch (Exception $e) { |
|||
$m_prefix = __('exception.exception_handler.resource'); |
|||
return $this->responseService->systemError( |
|||
$m_prefix . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
#[ArrayShape(['floor_list' => "array", 'attr_list' => "array"])] |
|||
private function getViewData(): array |
|||
{ |
|||
return [ |
|||
'floor_list' => $this->getFloorList(), |
|||
'attr_list' => ParkingSpaceAttributes::getData() |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @return array |
|||
*/ |
|||
private function getFloorList(): array |
|||
{ |
|||
$floor_column = [ |
|||
'id as floor_id', |
|||
'name as floor_name' |
|||
]; |
|||
return AdminFloorService::getSelectList( |
|||
1, |
|||
$floor_column |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* @param Request $request |
|||
* @return JsonResponse |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
public function store(Request $request): JsonResponse |
|||
{ |
|||
try { |
|||
$this->saveValidator($request->all()); |
|||
$this->service->createModel($request->all()); |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.save_succeeded') |
|||
); |
|||
} catch (ValidationException|CustomException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.parking_camera.create_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* @param int $id |
|||
* @return void |
|||
* @throws ValidationException |
|||
*/ |
|||
protected function saveValidator(array $data, int $id = 0): void |
|||
{ |
|||
$rules = [ |
|||
'number' => 'required|max:50', |
|||
'server_ip' => 'required|max:15', |
|||
'camera_ip' => 'required|max:15', |
|||
'floor_id' => 'required|numeric', |
|||
'parking_space_data' => 'array' |
|||
]; |
|||
$messages = [ |
|||
'name.required' => __( |
|||
'validation.parking_camera.n_empty' |
|||
), |
|||
'name.max' => __('validation.parking_camera.n_max'), |
|||
'server_ip.required' => __( |
|||
'validation.parking_camera.s_empty' |
|||
), |
|||
'server_ip.max' => __('validation.parking_camera.s_max'), |
|||
'camera_ip.required' => __( |
|||
'validation.parking_camera.c_empty' |
|||
), |
|||
'camera_ip.max' => __('validation.parking_camera.c_max'), |
|||
'floor_id.required' => __('validation.map.f_empty'), |
|||
'floor_id.numeric' => __('validation.map.f_number'), |
|||
'parking_space_data.array' => __( |
|||
'validation.parking_camera.p_array' |
|||
) |
|||
]; |
|||
if ($id) { |
|||
$this->validateId($id, ParkingCamera::class); |
|||
} |
|||
$validator = Validator::make($data, $rules, $messages); |
|||
|
|||
if ($validator->fails()) { |
|||
throw new ValidationException($validator); |
|||
} |
|||
} |
|||
|
|||
public function edit(string $id): JsonResponse |
|||
{ |
|||
try { |
|||
$this->validateId($id, ParkingCamera::class); |
|||
$data = $this->getViewData(); |
|||
$item = ParkingCamera::query()->findOrFail($id); |
|||
$item['parking_space_data'] = ParkingSpaceCamera::getData($id, 1); |
|||
$data['item'] = $item; |
|||
return $this->responseService->success($data); |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.get_data_failed') . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 更新 |
|||
* @param Request $request |
|||
* @param string $id |
|||
* @return JsonResponse |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
public function update(Request $request, string $id): JsonResponse |
|||
{ |
|||
try { |
|||
$this->saveValidator($request->all(), $id); |
|||
$this->service->updateModel($request->all(), $id); |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.update_succeeded') |
|||
); |
|||
} catch (ValidationException|CustomException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.parking_camera.update_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param string $id |
|||
* @return JsonResponse |
|||
* @throws ValidationException |
|||
*/ |
|||
public function destroy(string $id): JsonResponse |
|||
{ |
|||
try { |
|||
$this->validateId($id, ParkingCamera::class); |
|||
$this->service->deleteModel($id); |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.delete_succeeded') |
|||
); |
|||
} catch (ValidationException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.parking_camera.destroy_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @return JsonResponse |
|||
* @throws InvalidArgumentException |
|||
*/ |
|||
public function rule(): JsonResponse |
|||
{ |
|||
try { |
|||
return $this->responseService->success( |
|||
$this->methodShow('parkingCamera') |
|||
); |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.get_data_failed') . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
|
|||
class ParkingCamera extends Model |
|||
{ |
|||
use HasFactory, SoftDeletes; |
|||
|
|||
protected $table = 'parking_camera'; |
|||
|
|||
protected $fillable = [ |
|||
'number', |
|||
'camera_ip', |
|||
'server_ip', |
|||
'floor_id', |
|||
'floor_region_id', |
|||
'is_control_lights', |
|||
'is_external', |
|||
'built_in_light', |
|||
'off_light', |
|||
'remark', |
|||
'type', |
|||
'status' |
|||
]; |
|||
|
|||
protected $hidden = [ |
|||
'created_at', |
|||
'deleted_at' |
|||
]; |
|||
|
|||
public function getUpdatedAtAttribute($value): string |
|||
{ |
|||
return get_datetime('datetime', strtotime($value)); |
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Support\Collection; |
|||
|
|||
class ParkingSpaceCamera extends Model |
|||
{ |
|||
use HasFactory; |
|||
|
|||
protected $table = 'parking_space_camera'; |
|||
|
|||
protected $fillable |
|||
= [ |
|||
'camera_id', |
|||
'space_index', |
|||
'space_id', |
|||
'control_lights_ip', |
|||
'light_index' |
|||
]; |
|||
|
|||
public static function createModel($data, $camera_id) |
|||
{ |
|||
$createData = []; |
|||
$index = 1; |
|||
foreach ($data as $item) { |
|||
$createData[] = [ |
|||
'camera_id' => $camera_id, |
|||
'space_index' => $index, |
|||
'space_id' => $item['space_id'], |
|||
'control_lights_ip' => $item['control_lights_ip'], |
|||
'light_index' => $item['light_index'] ?? 0 |
|||
]; |
|||
$index += 1; |
|||
} |
|||
return self::insert($createData); |
|||
} |
|||
|
|||
public static function getData($camera_id, $is_space = 0): array |
|||
{ |
|||
$data = self::query()->where('camera_id', $camera_id)->orderBy( |
|||
'space_index' |
|||
)->select()->get()->toArray(); |
|||
if ($is_space) { |
|||
foreach ($data as &$item) { |
|||
$space = ParkingSpace::query()->findOrFail( |
|||
$item['space_id'], |
|||
['number', 'space_attr_id'] |
|||
); |
|||
$item['space_number'] = $space['number']; |
|||
$item['space_attr_id'] = $space['space_attr_id']; |
|||
unset($item['space_id'], $item['id'], $item['camera_id']); |
|||
} |
|||
} |
|||
return $data; |
|||
} |
|||
|
|||
public static function getCameraIds($parking_space_number): Collection|array |
|||
{ |
|||
$space_id = ParkingSpace::getValueId($parking_space_number); |
|||
if ($space_id) { |
|||
return self::query()->where('space_id', $space_id)->pluck( |
|||
'camera_id' |
|||
); |
|||
} |
|||
return []; |
|||
} |
|||
|
|||
public static function getParkingSpaceNumber( |
|||
$camera_id, |
|||
$is_implode = 1 |
|||
): string|array { |
|||
$space_ids = self::query()->where('camera_id', $camera_id)->pluck( |
|||
'space_id' |
|||
); |
|||
$space_number_arr = []; |
|||
foreach ($space_ids as $space_id) { |
|||
$space_number_arr[] = ParkingSpace::getNumber($space_id); |
|||
} |
|||
return $is_implode ? implode(',', $space_number_arr) |
|||
: $space_number_arr; |
|||
} |
|||
|
|||
public static function getSpaceCount($camera_id): int |
|||
{ |
|||
return self::query()->where('camera_id', $camera_id)->count(); |
|||
} |
|||
} |
|||
@ -0,0 +1,259 @@ |
|||
<?php |
|||
|
|||
namespace App\Services; |
|||
|
|||
use App\Exceptions\CustomException; |
|||
use App\Models\ParkingCamera; |
|||
use App\Models\ParkingSpace; |
|||
use App\Models\ParkingSpaceCamera; |
|||
use Exception; |
|||
use Illuminate\Database\Eloquent\Builder; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class ParkingCameraService extends BaseService |
|||
{ |
|||
|
|||
|
|||
private static array $statusArr = ['offline', 'online']; |
|||
private static array $typeArr = [1 => 'flat_garage']; |
|||
private static array $isControlLightsArr = ['no', 'yes']; |
|||
|
|||
public function __construct(OperationLogService $logService) |
|||
{ |
|||
parent::__construct($logService); |
|||
$this->logService->menuTitle = 'camera_management'; |
|||
} |
|||
|
|||
/** |
|||
* @return array|string[] |
|||
*/ |
|||
public static function getStatus(): array |
|||
{ |
|||
$statusArr = self::$statusArr; |
|||
foreach ($statusArr as $key => $value) { |
|||
$statusArr[$key] = __('admin.' . $value); |
|||
} |
|||
return $statusArr; |
|||
} |
|||
|
|||
/** |
|||
* @return array|string[] |
|||
*/ |
|||
public static function getType(): array |
|||
{ |
|||
$typeArr = self::$typeArr; |
|||
foreach ($typeArr as $key => $value) { |
|||
$typeArr[$key] = __('service.parking_camera.' . $value); |
|||
} |
|||
return $typeArr; |
|||
} |
|||
|
|||
/** |
|||
* @return array|string[] |
|||
*/ |
|||
public static function getIsControlLights(): array |
|||
{ |
|||
$arr = self::$isControlLightsArr; |
|||
foreach ($arr as $key => $value) { |
|||
$arr[$key] = __('service.reservation.' . $value); |
|||
} |
|||
return $arr; |
|||
} |
|||
|
|||
/** |
|||
* 创建车位相机 |
|||
* @param array $data |
|||
* @return Builder|Model |
|||
* @throws CustomException |
|||
*/ |
|||
public function createModel(array $data): Builder|Model |
|||
{ |
|||
try { |
|||
DB::beginTransaction(); |
|||
$parking_space_data = $data['parking_space_data']; |
|||
|
|||
if (ParkingCamera::query()->where('number', $data['number']) |
|||
->exists() |
|||
) { |
|||
throw new Exception(__('service.parking_camera.number_exists')); |
|||
} |
|||
|
|||
self::validateSpaceData($parking_space_data); |
|||
|
|||
$model = ParkingCamera::query()->create([ |
|||
'number' => $data['number'], |
|||
'camera_ip' => $data['camera_ip'], |
|||
'server_ip' => $data['server_ip'], |
|||
'floor_id' => $data['floor_id'] ?? 0, |
|||
'floor_region_id' => $data['floor_region_id'] ?? 0, |
|||
'is_control_lights' => $data['is_control_lights'] ?? 1, |
|||
'is_external' => $data['is_external'] ?? 0, |
|||
'built_in_light' => $data['built_in_light'] ?? 0, |
|||
'off_light' => $data['off_light'] ?? 0, |
|||
'remark' => $data['remark'] ?? '', |
|||
'created_at' => get_datetime() |
|||
]); |
|||
|
|||
$this->logService->logCreated($model, 'parking_camera.create'); |
|||
|
|||
$this->addSpaceCamera($model->id, $parking_space_data); |
|||
|
|||
DB::commit(); |
|||
return $model; |
|||
} catch (Exception $e) { |
|||
DB::rollBack(); |
|||
throw $e; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 验证车位控灯相机数据 |
|||
* @param $data |
|||
* @return void |
|||
* @throws CustomException |
|||
*/ |
|||
private function validateSpaceData(&$data): void |
|||
{ |
|||
foreach ($data as &$item) { |
|||
$control_lights_ip = $item['control_lights_ip'] ?? ''; |
|||
$space_attr_id = $item['space_attr_id'] ?? ''; |
|||
if (empty($control_lights_ip)) { |
|||
throw new CustomException( |
|||
__('validation.parking_camera.lights_ip_empty') |
|||
); |
|||
} |
|||
if (strlen($control_lights_ip) > 15) { |
|||
throw new CustomException( |
|||
__('validation.parking_camera.lights_ip_max') |
|||
); |
|||
} |
|||
$space_id = ParkingSpace::getValueId($item['space_number']); |
|||
if (!$space_id && $space_attr_id) { |
|||
// 创建车位 |
|||
$spaceData = [ |
|||
'floor_id' => $data['floor_id'], |
|||
'number' => $item['space_number'], |
|||
'space_attr_id' => $space_attr_id |
|||
]; |
|||
(new ParkingSpaceService($this->logService))->create( |
|||
$spaceData |
|||
); |
|||
$space_id = ParkingSpace::getValueId($item['space_number']); |
|||
} elseif ($space_id && $space_attr_id) { |
|||
// 更新车位属性 |
|||
(new ParkingSpaceService($this->logService))->updateAttr( |
|||
$space_id, |
|||
$space_attr_id |
|||
); |
|||
} |
|||
// 获取车位id |
|||
$item['space_id'] = $space_id; |
|||
} |
|||
} |
|||
|
|||
private function addSpaceCamera($camera_id, $data) |
|||
{ |
|||
ParkingSpaceCamera::createModel($data, $camera_id); |
|||
$AdminRoleMenuData = ParkingSpaceCamera::getData($camera_id); |
|||
$this->logService->logCreatedData( |
|||
new ParkingSpaceCamera(), |
|||
'parking_camera.create_space_camera', |
|||
$AdminRoleMenuData |
|||
); |
|||
} |
|||
|
|||
// 创建车位空灯数据 |
|||
|
|||
/** |
|||
* 更新车位相机 |
|||
* @param array $data |
|||
* @param string $id |
|||
* @return Builder|Model |
|||
* @throws CustomException |
|||
*/ |
|||
public function updateModel(array $data, string $id): Builder|Model |
|||
{ |
|||
try { |
|||
DB::beginTransaction(); |
|||
$parking_space_data = $data['parking_space_data']; |
|||
|
|||
$existsWhere = [ |
|||
['number', '=', $data['number']], |
|||
['id', '<>', $id] |
|||
]; |
|||
if (ParkingCamera::query()->where($existsWhere)->exists()) { |
|||
throw new Exception(__('service.parking_camera.number_exists')); |
|||
} |
|||
self::validateSpaceData($parking_space_data); |
|||
|
|||
// 更新 |
|||
$model = ParkingCamera::query()->findOrFail($id); |
|||
$oldValues = $model->toArray(); |
|||
$model->update([ |
|||
'number' => $data['number'], |
|||
'camera_ip' => $data['camera_ip'], |
|||
'server_ip' => $data['server_ip'], |
|||
'floor_id' => $data['floor_id'] ?? 0, |
|||
'floor_region_id' => $data['floor_region_id'] ?? 0, |
|||
'is_control_lights' => $data['is_control_lights'] ?? 1, |
|||
'is_external' => $data['is_external'] ?? 0, |
|||
'built_in_light' => $data['built_in_light'] ?? 0, |
|||
'off_light' => $data['off_light'] ?? 0, |
|||
'remark' => $data['remark'] ?? '', |
|||
'updated_at' => get_datetime() |
|||
]); |
|||
|
|||
$this->logService->logUpdated( |
|||
$model, |
|||
$oldValues, |
|||
'parking_camera.update' |
|||
); |
|||
|
|||
// 删除再添加 |
|||
$this->delAdminRoleMenu($id); |
|||
$this->addSpaceCamera($id, $parking_space_data); |
|||
|
|||
DB::commit(); |
|||
return $model; |
|||
} catch (Exception $e) { |
|||
DB::rollBack(); |
|||
throw $e; |
|||
} |
|||
} |
|||
|
|||
// 删除车位空灯数据 |
|||
|
|||
private function delAdminRoleMenu(int $camera_id): void |
|||
{ |
|||
$oldAdminRoleMenu = ParkingSpaceCamera::getData($camera_id); |
|||
$this->logService->logDeletedData( |
|||
new ParkingSpaceCamera(), |
|||
'parking_camera.delete_space_camera', |
|||
$oldAdminRoleMenu |
|||
); |
|||
ParkingSpaceCamera::query()->where('camera_id', $camera_id)->delete(); |
|||
} |
|||
|
|||
// 删除 |
|||
public function deleteModel(int $id): bool |
|||
{ |
|||
try { |
|||
DB::beginTransaction(); |
|||
|
|||
$model = ParkingCamera::query()->findOrFail($id); |
|||
|
|||
$this->logService->logDeleted($model, 'parking_camera.delete'); |
|||
|
|||
$model->delete(); |
|||
|
|||
$this->delAdminRoleMenu($id); |
|||
|
|||
DB::commit(); |
|||
return true; |
|||
} catch (Exception $e) { |
|||
DB::rollBack(); |
|||
throw $e; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
return new class extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
*/ |
|||
public function up(): void |
|||
{ |
|||
Schema::create('parking_camera', function (Blueprint $table) { |
|||
$table->id(); |
|||
$table->string('number', 50)->default('')->comment('设备编号'); |
|||
$table->string('camera_ip', 15)->default('')->comment('相机ip地址'); |
|||
$table->string('server_ip', 15)->default('')->comment('服务器ip地址'); |
|||
$table->integer('floor_id')->default(0)->comment('楼层id'); |
|||
$table->integer('floor_region_id')->default(0)->comment('楼层区域id'); |
|||
$table->tinyInteger('is_control_lights')->default(1)->comment('是否控灯'); |
|||
$table->tinyInteger('is_external')->default(0)->comment('是否有外接指示灯'); |
|||
$table->tinyInteger('built_in_light')->default(0)->comment('内置灯映射'); |
|||
$table->tinyInteger('off_light')->default(0)->comment('关闭内置灯'); |
|||
$table->string('remark', 255)->default('')->comment('备注'); |
|||
$table->tinyInteger('type')->default(1)->comment('相机类型'); |
|||
$table->tinyInteger('status')->default(0)->comment('通讯状态 0离线 1在线'); |
|||
$table->index('floor_id'); |
|||
$table->innoDb(); |
|||
$table->comment('车位相机'); |
|||
$table->timestamps(); |
|||
$table->softDeletes(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
*/ |
|||
public function down(): void |
|||
{ |
|||
Schema::dropIfExists('parking_camera'); |
|||
} |
|||
}; |
|||
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
return new class extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
*/ |
|||
public function up(): void |
|||
{ |
|||
Schema::create('parking_space_camera', function (Blueprint $table) { |
|||
$table->id(); |
|||
$table->integer('camera_id')->comment('车位相机id'); |
|||
$table->integer('space_id')->default('')->comment('车位id'); |
|||
$table->integer('space_index')->default(1)->comment('车位信息索引'); |
|||
$table->string('control_lights_ip', 15)->comment('控灯相机IP'); |
|||
$table->tinyInteger('light_index')->default(0)->comment('映射相机指示灯索引'); |
|||
$table->index('camera_id'); |
|||
$table->index('space_id'); |
|||
$table->innoDb(); |
|||
$table->comment('车位相机关联车位'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
*/ |
|||
public function down(): void |
|||
{ |
|||
Schema::dropIfExists('parking_space_camera'); |
|||
} |
|||
}; |
|||
Loading…
Reference in new issue