diff --git a/app/Exports/ParkingCameraExport.php b/app/Exports/ParkingCameraExport.php new file mode 100644 index 0000000..d270b35 --- /dev/null +++ b/app/Exports/ParkingCameraExport.php @@ -0,0 +1,58 @@ +each( + function ($item) use (&$data, &$index) { + $oldItem = (new ParkingCameraService( + new OperationLogService() + ))->optionItems($item); + $data[] = [ + 'id' => $index, + 'floor' => $oldItem['floor'], + 'number' => $oldItem['number'], + 'camera_ip' => $oldItem['camera_ip'], + 'parking_space_count' => $oldItem['parking_space_count'], + 'parking_space_numbers' => $oldItem['parking_space_numbers'], + 'is_control_lights' => $oldItem['is_control_lights'], + 'type' => $oldItem['type'], + 'status' => $oldItem['status'], + 'updated_at' => $oldItem['updated_at'] + ]; + $index += 1; + } + ); + return $data; + } + + /** + * @return array + */ + public function headings(): array + { + return [ + __('exports.global.index'), + __('exports.parking_space.floor'), + __('exports.parking_camera.number'), + __('exports.parking_camera.camera_ip'), + __('exports.parking_camera.parking_space_count'), + __('exports.parking_camera.parking_space_numbers'), + __('exports.parking_camera.is_control_lights'), + __('exports.parking_camera.type'), + __('exports.parking_camera.status'), + __('exports.parking_camera.updated_at') + ]; + } +} diff --git a/app/Exports/ParkingSpaceExport.php b/app/Exports/ParkingSpaceExport.php index 9720cf0..58e06d7 100644 --- a/app/Exports/ParkingSpaceExport.php +++ b/app/Exports/ParkingSpaceExport.php @@ -14,8 +14,9 @@ class ParkingSpaceExport implements FromArray, WithHeadings public function array(): array { $data = []; + $index = 1; ParkingSpace::all()->each( - function ($item) use (&$data) { + function ($item) use (&$data, &$index) { $oldItem = (new ParkingSpaceService( new OperationLogService() ))->optionItems($item); @@ -32,6 +33,7 @@ class ParkingSpaceExport implements FromArray, WithHeadings 'operation_type' => $oldItem['operation_type'], 'updated_at' => $oldItem['updated_at'] ]; + $index += 1; } ); return $data; diff --git a/app/Http/Controllers/Admin/ParkingCameraController.php b/app/Http/Controllers/Admin/ParkingCameraController.php index 0b2529a..fa974a5 100644 --- a/app/Http/Controllers/Admin/ParkingCameraController.php +++ b/app/Http/Controllers/Admin/ParkingCameraController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin; use App\Exceptions\CustomException; +use App\Exports\ParkingCameraExport; use App\Models\AdminFloor; use App\Models\ParkingCamera; use App\Models\ParkingSpaceAttributes; @@ -16,7 +17,9 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\ValidationException; use JetBrains\PhpStorm\ArrayShape; +use Maatwebsite\Excel\Facades\Excel; use Psr\SimpleCache\InvalidArgumentException; +use Symfony\Component\HttpFoundation\BinaryFileResponse; class ParkingCameraController extends BaseController { @@ -96,29 +99,13 @@ class ParkingCameraController extends BaseController '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']); - } - ); + )->get()->each(function ($item) { + $item = $this->service->optionItems($item); + unset($item['floor_id']); + }); return $this->responseService->success([ 'items' => $items, @@ -139,8 +126,11 @@ class ParkingCameraController extends BaseController { try { $data = [ - 'floor_list' => $this->getFloorList(), - 'status_list' => get_select_data(ParkingCameraService::getStatus(), true) + 'floor_list' => $this->getFloorList(), + 'status_list' => get_select_data( + ParkingCameraService::getStatus(), + true + ) ]; return $this->responseService->success($data); } catch (Exception $e) { @@ -151,6 +141,21 @@ class ParkingCameraController extends BaseController } } + /** + * @return array + */ + private function getFloorList(): array + { + $floor_column = [ + 'id as floor_id', + 'name as floor_name' + ]; + return AdminFloorService::getSelectList( + 1, + $floor_column + ); + } + public function create(): JsonResponse { try { @@ -173,21 +178,6 @@ class ParkingCameraController extends BaseController ]; } - /** - * @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 @@ -340,4 +330,16 @@ class ParkingCameraController extends BaseController ); } } + + + /** + * @return BinaryFileResponse + */ + public function export(): BinaryFileResponse + { + return Excel::download( + new ParkingCameraExport(), + __('exports.parking_camera.list') . time() . '.xlsx' + ); + } } diff --git a/app/Services/ParkingCameraService.php b/app/Services/ParkingCameraService.php index ff9f8b9..eb86acf 100644 --- a/app/Services/ParkingCameraService.php +++ b/app/Services/ParkingCameraService.php @@ -3,6 +3,7 @@ namespace App\Services; use App\Exceptions\CustomException; +use App\Models\AdminFloor; use App\Models\ParkingCamera; use App\Models\ParkingSpace; use App\Models\ParkingSpaceCamera; @@ -256,4 +257,24 @@ class ParkingCameraService extends BaseService throw $e; } } + + // 处理列表数据 + public function optionItems($item) + { + $item['floor'] = AdminFloor::getName($item['floor_id']); + $item['parking_space_count'] + = ParkingSpaceCamera::getSpaceCount($item['id']); + $item['parking_space_numbers'] + = ParkingSpaceCamera::getParkingSpaceNumber( + $item['id'] + ); + $isArr = ParkingCameraService::getIsControlLights(); + $typeArr = ParkingCameraService::getType(); + $statusArr = ParkingCameraService::getStatus(); + $item['is_control_lights'] + = $isArr[$item['is_control_lights']] ?? ''; + $item['type'] = $typeArr[$item['type']] ?? ''; + $item['status'] = $statusArr[$item['status']] ?? ''; + return $item; + } } diff --git a/resources/lang/zh-CN/exports.php b/resources/lang/zh-CN/exports.php index 7fe4c96..231ae3a 100644 --- a/resources/lang/zh-CN/exports.php +++ b/resources/lang/zh-CN/exports.php @@ -1,18 +1,19 @@ [ + 'vip_list' => [ 'license' => '车牌号码', 'import_template' => 'VIP名单导入模板', 'list' => 'VIP名单' ], - 'global' => [ + 'global' => [ 'index' => '序号', 'admin' => '操作员' ], - 'license_plate' => [ + 'license_plate' => [ 'import_template' => '车牌管理导入模板' ], - 'parking_space' => [ + 'parking_space' => [ 'list' => '车位列表', 'floor' => '楼层', 'number' => '车位号码', @@ -24,5 +25,16 @@ return [ 'space_type' => '车位类型', 'operation_type' => '操作类型', 'updated_at' => '最后更新时间', + ], + 'parking_camera' => [ + 'list' => '车位相机', + 'number' => '设备编号', + 'camera_ip' => 'IP地址', + 'parking_space_count' => '设备管理车位个数', + 'parking_space_numbers' => '关联车位号', + 'is_control_lights' => '是否有外控灯', + 'type' => '相机类型', + 'status' => '通讯状态', + 'updated_at' => '最后更新时间', ] ]; diff --git a/routes/admin/api.php b/routes/admin/api.php index 23d9f79..1f1a274 100644 --- a/routes/admin/api.php +++ b/routes/admin/api.php @@ -157,4 +157,5 @@ Route::group(['prefix' => 'admin'], function () { Route::get('/vipList/export', [VipListController::class, 'export']); Route::get('/licensePlate/import_template', [ParkingLicensePlateController::class, 'importTemplate']); Route::get('/parkingSpace/export', [ParkingSpaceController::class, 'export']); + Route::get('/parkingCamera/export', [ParkingCameraController::class, 'export']); });