diff --git a/app/Http/Controllers/Admin/ParkingWhitelistController.php b/app/Http/Controllers/Admin/ParkingWhitelistController.php index baa9697..36e03cc 100644 --- a/app/Http/Controllers/Admin/ParkingWhitelistController.php +++ b/app/Http/Controllers/Admin/ParkingWhitelistController.php @@ -272,18 +272,25 @@ class ParkingWhitelistController extends BaseController // 4. 执行导入(使用存储后的绝对路径) // storage_path('app') 获取 storage/app 的绝对路径 + $model = new ParkingWhitelistImport($this->adminUserId); Excel::import( - new ParkingWhitelistImport($this->adminUserId), + $model, storage_path('app/' . $path) ); // 5. (可选)导入完成后删除临时文件 Storage::delete($path); + // 6. 返回错误行 + $error_arr = $model->errorArr(); + if ($error_arr) { + throw new CustomException(implode("
", $error_arr)); + } + return $this->responseService->success( __('controller.import.success') ); - } catch (ValidationException $e) { + } catch (ValidationException|CustomException $e) { throw $e; } catch (Exception $e) { return $this->responseService->systemError( diff --git a/app/Imports/ParkingWhitelistImport.php b/app/Imports/ParkingWhitelistImport.php index 79c6e77..f8f344d 100644 --- a/app/Imports/ParkingWhitelistImport.php +++ b/app/Imports/ParkingWhitelistImport.php @@ -12,8 +12,9 @@ use Maatwebsite\Excel\Concerns\ToModel; use Maatwebsite\Excel\Concerns\WithChunkReading; class ParkingWhitelistImport implements ToModel, WithChunkReading { - protected int $index = 1; + protected int $index = 0; protected int $user_id; + protected array $error = []; public function __construct($admin_user_id) { @@ -22,27 +23,32 @@ class ParkingWhitelistImport implements ToModel, WithChunkReading public function model(array $row) { - if ($this->index == 1) { + if (!$this->index) { $this->index += 1; return; } - $license_plate = $row[1]; + $this->index += 1; + $license_plate = $row[1] ?? ''; if (empty($license_plate)) { + $this->error[] = imports_error($this->index, 'import33'); return; } - $parking_name = $row[2]; + $parking_name = $row[2] ?? ''; if (empty($parking_name)) { + $this->error[] = imports_error($this->index, 'import20'); return; } $parking_id = Parking::getValueId($parking_name); if (empty($parking_id)) { $parking_id = AdminTranslationService::getTypeId(3, $parking_name); if (!$parking_id) { + $this->error[] = imports_error($this->index, 'import24'); return; } } - $channel_name = $row[3]; + $channel_name = $row[3] ?? ''; if (empty($channel_name)) { + $this->error[] = imports_error($this->index, 'import34'); return; } $channel_arr = explode(',', $channel_name); @@ -56,14 +62,16 @@ class ParkingWhitelistImport implements ToModel, WithChunkReading } } if (!$channelIds) { + $this->error[] = imports_error($this->index, 'import35'); return; } } - $reason = $row[4]; + $reason = $row[4] ?? ''; if (empty($reason)) { + $this->error[] = imports_error($this->index, 'import36'); return; } - $type_str = $row[5]; + $type_str = $row[5] ?? ''; $space_type_id = 0; if (!empty($type_str)) { $space_type_id = ParkingSpaceType::getValueId($type_str) ?? 0; @@ -83,11 +91,15 @@ class ParkingWhitelistImport implements ToModel, WithChunkReading $service = new ParkingWhitelistService(new OperationLogService()); $service->createModel($data); - $this->index += 1; } public function chunkSize(): int { return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析 } + + public function errorArr(): array + { + return $this->error; + } } diff --git a/resources/lang/en/exports.php b/resources/lang/en/exports.php index 7c9c65b..64fa6c8 100644 --- a/resources/lang/en/exports.php +++ b/resources/lang/en/exports.php @@ -94,7 +94,7 @@ return [ 'list' => 'White List Import Template', 'export_list' => 'Whitelist Vehicle List', 'parking' => 'Parking Lot', - 'channel' => 'Access Channel', + 'channel' => 'Traffic Lanes', 'reason' => 'Reason For Passage', 'member_type' => 'Identity Type' ], diff --git a/resources/lang/en/imports.php b/resources/lang/en/imports.php index 13ddabb..413900b 100644 --- a/resources/lang/en/imports.php +++ b/resources/lang/en/imports.php @@ -32,5 +32,9 @@ return [ 'import29' => 'The repair start time cannot be empty.', 'import30' => 'Repair start time data error', 'import31' => 'The repair end time cannot be empty.', - 'import32' => 'Repair end time data error' + 'import32' => 'Repair end time data error', + 'import33' => 'License plate number cannot be empty', + 'import34' => 'The lane cannot be empty.', + 'import35' => 'Lane does not exist', + 'import36' => 'The reason for passage cannot be empty.' ]; diff --git a/resources/lang/en/log.php b/resources/lang/en/log.php index 55bd150..60e52f9 100644 --- a/resources/lang/en/log.php +++ b/resources/lang/en/log.php @@ -107,14 +107,14 @@ return [ 'delete' => 'Delete parking lot administrator' ], 'channel_management' => [ - 'create' => 'Create channel', - 'update' => 'Update channel', - 'delete' => 'Delete channel' + 'create' => 'Create lane', + 'update' => 'Update lane', + 'delete' => 'Delete Lane' ], 'guard_booth_management' => [ 'create' => 'Create a booth', - 'update' => 'Update the booth', - 'delete' => 'Delete the booth' + 'update' => 'Update booth', + 'delete' => 'Deleting booth' ], 'departure_management' => [ 'create' => 'Create exit reason', @@ -122,9 +122,9 @@ return [ 'delete' => 'Delete exit reason' ], 'channel_permissions' => [ - 'create' => 'Create channel permissions', - 'update' => 'Update channel permissions', - 'delete' => 'Delete channel permissions' + 'create' => 'Create lane access', + 'update' => 'Update lane access', + 'delete' => 'Delete lane access' ], 'equipment_management' => [ 'create' => 'Create device', diff --git a/resources/lang/en/service.php b/resources/lang/en/service.php index ea95359..6338500 100644 --- a/resources/lang/en/service.php +++ b/resources/lang/en/service.php @@ -111,10 +111,10 @@ return [ 'export' => 'Export', 'on-site' => 'On-site', 'off-site' => 'Off-site', - 'name_exists' => 'The channel name already exists' + 'name_exists' => 'Lane name already exists' ], 'guard_booth_management' => [ - 'name_exists' => 'The booth name already exists' + 'name_exists' => 'The booth name already exists.' ], 'departure_management' => [ 'reason_exists' => 'Reason for departure already exists' diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 4f62bc0..e7652da 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -144,27 +144,27 @@ return [ 'n_max' => 'The maximum length of the region name is 50 characters' ], 'channel_management' => [ - 'n_empty' => 'Channel name cannot be empty', - 't_empty' => 'Channel type cannot be empty', - 'po_empty' => 'The channel position cannot be empty', + 'n_empty' => 'Lane names cannot be empty.', + 't_empty' => 'Lane type cannot be empty', + 'po_empty' => 'Lane positions cannot be empty.', 'pa_empty' => 'The affiliated parking lot cannot be empty', - 'g_empty' => 'The affiliated booth cannot be empty' + 'g_empty' => 'The booth cannot be empty.' ], 'guard_booth_management' => [ - 'n_empty' => 'The booth name cannot be empty', + 'n_empty' => 'Booth name cannot be empty', ], 'departure_management' => [ 'n_empty' => 'Reason for departure cannot be empty', ], 'channel_permissions' => [ 'm_empty' => 'Member type cannot be empty', - 'c_empty' => 'Allow channel not to be empty', - 'c_array' => 'Allow channel data to be an array' + 'c_empty' => 'Lanes cannot be empty.', + 'c_array' => 'Lane data must be an array' ], 'equipment_management' => [ 'n_empty' => 'The device name cannot be empty', 't_empty' => 'The device type cannot be empty', - 'ch_empty' => 'Binding channel cannot be empty', + 'ch_empty' => 'The bound lane cannot be empty.', 'pu_empty' => 'The purpose of the device cannot be empty', 'ip_empty' => 'The device IP cannot be empty', 'ip' => 'Device IP format error', @@ -174,8 +174,8 @@ return [ 'l_empty' => 'The license plate number cannot be empty', 'pa_empty' => 'The parking lot cannot be empty', 'n_empty' => 'The reason for passage cannot be empty', - 'c_empty' => 'The passage cannot be empty', - 'c_array' => 'The passage channel data must be an array', + 'c_empty' => 'The traffic lanes cannot be empty.', + 'c_array' => 'The traffic lane data must be an array.', ], 'parking_repair_list' => [ 'psn_empty' => 'The parking number cannot be empty', @@ -188,7 +188,7 @@ return [ 'gate_control' => [ 'n_empty' => 'Order number or license plate number cannot be empty', 'et_empty' => 'The entry time cannot be empty', - 'channel_id' => 'Channel cannot be empty', + 'channel_id' => 'The lane cannot be empty.', 'lp_empty' => 'The license plate number cannot be empty', 'lt_empty' => 'Departure time cannot be empty' ] diff --git a/resources/lang/zh-CN/exports.php b/resources/lang/zh-CN/exports.php index 31081df..cb6d5bb 100644 --- a/resources/lang/zh-CN/exports.php +++ b/resources/lang/zh-CN/exports.php @@ -94,7 +94,7 @@ return [ 'list' => '白名单导入模板', 'export_list' => '白名单车辆列表', 'parking' => '停车场', - 'channel' => '通行通道', + 'channel' => '通行车道', 'reason' => '通行原因', 'member_type' => '身份类型' ], diff --git a/resources/lang/zh-CN/imports.php b/resources/lang/zh-CN/imports.php index f6af52e..234df86 100644 --- a/resources/lang/zh-CN/imports.php +++ b/resources/lang/zh-CN/imports.php @@ -32,5 +32,9 @@ return [ 'import29' => '维修开始时间不能为空', 'import30' => '维修开始时间数据错误', 'import31' => '维修结束时间不能为空', - 'import32' => '维修结束时间数据错误' + 'import32' => '维修结束时间数据错误', + 'import33' => '车牌号码不能为空', + 'import34' => '车道不能为空', + 'import35' => '车道不存在', + 'import36' => '通行原因不能为空' ]; diff --git a/resources/lang/zh-CN/log.php b/resources/lang/zh-CN/log.php index e9f67af..a967afd 100644 --- a/resources/lang/zh-CN/log.php +++ b/resources/lang/zh-CN/log.php @@ -107,14 +107,14 @@ return [ 'delete' => '删除停车场管理员' ], 'channel_management' => [ - 'create' => '创建通道', - 'update' => '更新通道', - 'delete' => '删除通道' + 'create' => '创建车道', + 'update' => '更新车道', + 'delete' => '删除车道' ], 'guard_booth_management' => [ - 'create' => '创建岗亭', - 'update' => '更新岗亭', - 'delete' => '删除岗亭' + 'create' => '创建展位', + 'update' => '更新展位', + 'delete' => '删除展位' ], 'departure_management' => [ 'create' => '创建离场原因', @@ -122,9 +122,9 @@ return [ 'delete' => '删除离场原因' ], 'channel_permissions' => [ - 'create' => '创建通道权限', - 'update' => '更新通道权限', - 'delete' => '删除通道权限' + 'create' => '创建车道接入', + 'update' => '更新车道接入', + 'delete' => '删除车道接入' ], 'equipment_management' => [ 'create' => '创建设备', diff --git a/resources/lang/zh-CN/service.php b/resources/lang/zh-CN/service.php index bcdcf50..44d4a75 100644 --- a/resources/lang/zh-CN/service.php +++ b/resources/lang/zh-CN/service.php @@ -111,10 +111,10 @@ return [ 'export' => '出口', 'on-site' => '场内', 'off-site' => '场外', - 'name_exists' => '通道名称已存在' + 'name_exists' => '车道名称已存在' ], 'guard_booth_management' => [ - 'name_exists' => '岗亭名称已存在' + 'name_exists' => '展位名称已存在' ], 'departure_management' => [ 'reason_exists' => '离场原因已存在' diff --git a/resources/lang/zh-CN/validation.php b/resources/lang/zh-CN/validation.php index 45532d6..3583fa3 100644 --- a/resources/lang/zh-CN/validation.php +++ b/resources/lang/zh-CN/validation.php @@ -144,27 +144,27 @@ return [ 'n_max' => '区域名称最多50个字符' ], 'channel_management' => [ - 'n_empty' => '通道名称不能为空', - 't_empty' => '通道类型不能为空', - 'po_empty' => '通道位置不能为空', + 'n_empty' => '车道名称不能为空', + 't_empty' => '车道类型不能为空', + 'po_empty' => '车道位置不能为空', 'pa_empty' => '所属车场不能为空', - 'g_empty' => '所属岗亭不能为空' + 'g_empty' => '所属展位不能为空' ], 'guard_booth_management' => [ - 'n_empty' => '岗亭名称不能为空', + 'n_empty' => '展位名称不能为空', ], 'departure_management' => [ 'n_empty' => '离场原因不能为空', ], 'channel_permissions' => [ 'm_empty' => '会员类型不能为空', - 'c_empty' => '允许通道不能为空', - 'c_array' => '允许通道数据必须是数组' + 'c_empty' => '允许车道不能为空', + 'c_array' => '允许车道数据必须是数组' ], 'equipment_management' => [ 'n_empty' => '设备名称不能为空', 't_empty' => '设备类型不能为空', - 'ch_empty' => '绑定通道不能为空', + 'ch_empty' => '绑定车道不能为空', 'pu_empty' => '设备用途不能为空', 'ip_empty' => '设备IP不能为空', 'ip' => '设备IP格式错误', @@ -174,8 +174,8 @@ return [ 'l_empty' => '车牌号码不能为空', 'pa_empty' => '停车场不能为空', 'n_empty' => '通行原因不能为空', - 'c_empty' => '通行通道不能为空', - 'c_array' => '通行通道数据必须是数组', + 'c_empty' => '通行车道不能为空', + 'c_array' => '通行车道数据必须是数组', ], 'parking_repair_list' => [ 'psn_empty' => '车位号码不能为空', @@ -188,7 +188,7 @@ return [ 'gate_control' => [ 'n_empty' => '订单号码或车牌号码不能为空', 'et_empty' => '入场时间不能为空', - 'channel_id' => '通道不能为空', + 'channel_id' => '车道不能为空', 'lp_empty' => '车牌号码不能为空', 'lt_empty' => '离场时间不能为空' ] diff --git a/resources/lang/zh-TW/exports.php b/resources/lang/zh-TW/exports.php index 50366ca..4560f56 100644 --- a/resources/lang/zh-TW/exports.php +++ b/resources/lang/zh-TW/exports.php @@ -94,7 +94,7 @@ return [ 'list' => '白名單導入範本', 'export_list' => '白名單車輛清單', 'parking' => '停車場', - 'channel' => '通行通道', + 'channel' => '通行車道', 'reason' => '通行原因', 'member_type' => '身份類型' ], diff --git a/resources/lang/zh-TW/imports.php b/resources/lang/zh-TW/imports.php index c4791f8..8e0035c 100644 --- a/resources/lang/zh-TW/imports.php +++ b/resources/lang/zh-TW/imports.php @@ -32,5 +32,9 @@ return [ 'import29' => '維修開始時間不能為空', 'import30' => '維修開始時間數據錯誤', 'import31' => '維修結束時間不能為空', - 'import32' => '維修結束時間數據錯誤' + 'import32' => '維修結束時間數據錯誤', + 'import33' => '車牌號碼不能為空', + 'import34' => '車道不能為空', + 'import35' => '車道不存在', + 'import36' => '通行原因不能為空' ]; diff --git a/resources/lang/zh-TW/log.php b/resources/lang/zh-TW/log.php index ca3b84b..d44d171 100644 --- a/resources/lang/zh-TW/log.php +++ b/resources/lang/zh-TW/log.php @@ -107,14 +107,14 @@ return [ 'delete' => '删除停車場管理員' ], 'channel_management' => [ - 'create' => '創建通道', - 'update' => '更新通道', - 'delete' => '删除通道' + 'create' => '創建車道', + 'update' => '更新車道', + 'delete' => '刪除車道' ], 'guard_booth_management' => [ - 'create' => '創建崗亭', - 'update' => '更新崗亭', - 'delete' => '删除崗亭' + 'create' => '創建展位', + 'update' => '更新展位', + 'delete' => '刪除展位' ], 'departure_management' => [ 'create' => '創建離場原因', @@ -122,9 +122,9 @@ return [ 'delete' => '删除離場原因' ], 'channel_permissions' => [ - 'create' => '創建通道許可權', - 'update' => '更新通道許可權', - 'delete' => '删除通道許可權' + 'create' => '創建車道接入', + 'update' => '更新車道接入', + 'delete' => '刪除車道接入' ], 'equipment_management' => [ 'create' => '創建設備', diff --git a/resources/lang/zh-TW/service.php b/resources/lang/zh-TW/service.php index 2b95f0d..bb05cd3 100644 --- a/resources/lang/zh-TW/service.php +++ b/resources/lang/zh-TW/service.php @@ -111,10 +111,10 @@ return [ 'export' => '出口', 'on-site' => '場內', 'off-site' => '場外', - 'name_exists' => '通道名稱已存在' + 'name_exists' => '車道名稱已存在' ], 'guard_booth_management' => [ - 'name_exists' => '崗亭名稱已存在' + 'name_exists' => '展位名稱已存在' ], 'departure_management' => [ 'reason_exists' => '離場原因已存在' diff --git a/resources/lang/zh-TW/validation.php b/resources/lang/zh-TW/validation.php index 39f5442..7cb4dd8 100644 --- a/resources/lang/zh-TW/validation.php +++ b/resources/lang/zh-TW/validation.php @@ -144,27 +144,27 @@ return [ 'n_max' => '區域名稱最多50個字元' ], 'channel_management' => [ - 'n_empty' => '通道名稱不能為空', - 't_empty' => '通道類型不能為空', - 'po_empty' => '通道位置不能為空', + 'n_empty' => '車道名稱不能為空', + 't_empty' => '車道類型不能為空', + 'po_empty' => '車道位置不能為空', 'pa_empty' => '所屬車場不能為空', - 'g_empty' => '所屬崗亭不能為空' + 'g_empty' => '所屬展位不能為空' ], 'guard_booth_management' => [ - 'n_empty' => '崗亭名稱不能為空', + 'n_empty' => '展位名稱不能為空', ], 'departure_management' => [ 'n_empty' => '離場原因不能為空', ], 'channel_permissions' => [ 'm_empty' => '會員類型不能為空', - 'c_empty' => '允許通道不能為空', - 'c_array' => '允許通道數據必須是數組' + 'c_empty' => '允許車道不能為空', + 'c_array' => '允許車道數據必須是數組' ], 'equipment_management' => [ 'n_empty' => '設備名稱不能為空', 't_empty' => '設備類型不能為空', - 'ch_empty' => '綁定通道不能為空', + 'ch_empty' => '綁定車道不能為空', 'pu_empty' => '設備用途不能為空', 'ip_empty' => '設備IP不能為空', 'ip' => '設備IP格式錯誤', @@ -174,8 +174,8 @@ return [ 'l_empty' => '車牌號碼不能為空', 'pa_empty' => '停車場不能為空', 'n_empty' => '通行原因不能為空', - 'c_empty' => '通行通道不能為空', - 'c_array' => '通行通道數據必須是數組', + 'c_empty' => '通行車道不能為空', + 'c_array' => '通行車道數據必須是數組', ], 'parking_repair_list' => [ 'psn_empty' => '車位號碼不能為空', @@ -188,7 +188,7 @@ return [ 'gate_control' => [ 'n_empty' => '訂單號碼或車牌號碼不能為空', 'et_empty' => '入場時間不能為空', - 'channel_id' => '通道不能為空', + 'channel_id' => '車道不能為空', 'lp_empty' => '車牌號碼不能為空', 'lt_empty' => '離場時間不能為空' ]