|
|
@ -248,6 +248,7 @@ class ParkingPatternController extends BaseController |
|
|
* @param Request $request |
|
|
* @param Request $request |
|
|
* @return JsonResponse |
|
|
* @return JsonResponse |
|
|
* @throws ValidationException |
|
|
* @throws ValidationException |
|
|
|
|
|
* @throws CustomException |
|
|
*/ |
|
|
*/ |
|
|
public function batchImport(Request $request): JsonResponse |
|
|
public function batchImport(Request $request): JsonResponse |
|
|
{ |
|
|
{ |
|
|
@ -273,18 +274,25 @@ class ParkingPatternController extends BaseController |
|
|
|
|
|
|
|
|
// 4. 执行导入(使用存储后的绝对路径) |
|
|
// 4. 执行导入(使用存储后的绝对路径) |
|
|
// storage_path('app') 获取 storage/app 的绝对路径 |
|
|
// storage_path('app') 获取 storage/app 的绝对路径 |
|
|
|
|
|
$model = new ParkingPatternSpaceImport($this->adminUserId); |
|
|
Excel::import( |
|
|
Excel::import( |
|
|
new ParkingPatternSpaceImport($this->adminUserId), |
|
|
$model, |
|
|
storage_path('app/' . $path) |
|
|
storage_path('app/' . $path) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// 5. (可选)导入完成后删除临时文件 |
|
|
// 5. (可选)导入完成后删除临时文件 |
|
|
Storage::delete($path); |
|
|
Storage::delete($path); |
|
|
|
|
|
|
|
|
|
|
|
// 6. 返回错误行 |
|
|
|
|
|
$error_arr = $model->errorArr(); |
|
|
|
|
|
if ($error_arr) { |
|
|
|
|
|
throw new CustomException(implode("<br>", $error_arr)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $this->responseService->success( |
|
|
return $this->responseService->success( |
|
|
__('controller.import.success') |
|
|
__('controller.import.success') |
|
|
); |
|
|
); |
|
|
} catch (ValidationException $e) { |
|
|
} catch (ValidationException|CustomException $e) { |
|
|
throw $e; |
|
|
throw $e; |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
return $this->responseService->systemError( |
|
|
return $this->responseService->systemError( |
|
|
@ -299,6 +307,7 @@ class ParkingPatternController extends BaseController |
|
|
* @param Request $request |
|
|
* @param Request $request |
|
|
* @return JsonResponse |
|
|
* @return JsonResponse |
|
|
* @throws ValidationException |
|
|
* @throws ValidationException |
|
|
|
|
|
* @throws CustomException |
|
|
*/ |
|
|
*/ |
|
|
public function import(Request $request): JsonResponse |
|
|
public function import(Request $request): JsonResponse |
|
|
{ |
|
|
{ |
|
|
@ -338,18 +347,25 @@ class ParkingPatternController extends BaseController |
|
|
|
|
|
|
|
|
// 4. 执行导入(使用存储后的绝对路径) |
|
|
// 4. 执行导入(使用存储后的绝对路径) |
|
|
// storage_path('app') 获取 storage/app 的绝对路径 |
|
|
// storage_path('app') 获取 storage/app 的绝对路径 |
|
|
|
|
|
$model = new ParkingPatternImport($model_name, $this->adminUserId, $en_name, $tw_name); |
|
|
Excel::import( |
|
|
Excel::import( |
|
|
new ParkingPatternImport($model_name, $this->adminUserId, $en_name, $tw_name), |
|
|
$model, |
|
|
storage_path('app/' . $path) |
|
|
storage_path('app/' . $path) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// 5. (可选)导入完成后删除临时文件 |
|
|
// 5. (可选)导入完成后删除临时文件 |
|
|
Storage::delete($path); |
|
|
Storage::delete($path); |
|
|
|
|
|
|
|
|
|
|
|
// 6. 返回错误行 |
|
|
|
|
|
$error_arr = $model->errorArr(); |
|
|
|
|
|
if ($error_arr) { |
|
|
|
|
|
throw new CustomException(implode("<br>", $error_arr)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $this->responseService->success( |
|
|
return $this->responseService->success( |
|
|
__('controller.import.success') |
|
|
__('controller.import.success') |
|
|
); |
|
|
); |
|
|
} catch (ValidationException $e) { |
|
|
} catch (ValidationException|CustomException $e) { |
|
|
throw $e; |
|
|
throw $e; |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
return $this->responseService->systemError( |
|
|
return $this->responseService->systemError( |
|
|
|