Browse Source

维修车位优化导入错误提示

master
wanghongjun 3 weeks ago
parent
commit
1a1ed47d39
  1. 7
      app/Imports/ParkingSpaceRepairImport.php
  2. 23
      app/Services/ParkingSpaceRepairService.php
  3. 8
      app/common.php

7
app/Imports/ParkingSpaceRepairImport.php

@ -76,12 +76,15 @@ class ParkingSpaceRepairImport implements ToModel, WithChunkReading
}
$service = new ParkingSpaceRepairService(new OperationLogService());
$service->createModel([
$errorRes = $service->createModel([
'admin_user_id' => $this->user_id,
'parking_space_name' => $space_number,
'start_at' => date("Y-m-d H:i:s", $start_times),
'end_at' => date("Y-m-d H:i:s", $end_times)
]);
], true);
if ($errorRes) {
$this->error[] = imports_error($this->index, $errorRes, true);
}
}
public function chunkSize(): int

23
app/Services/ParkingSpaceRepairService.php

@ -54,9 +54,11 @@ class ParkingSpaceRepairService extends BaseService
/**
* @param array $data
* @throws Exception
* @param bool $is_import
* @return string
* @throws CustomException
*/
public function createModel(array $data)
public function createModel(array $data, bool $is_import = false): string
{
try {
DB::beginTransaction();
@ -66,6 +68,11 @@ class ParkingSpaceRepairService extends BaseService
$space = ParkingSpace::query()->where('number', $parking_space_name)->first();
$str = $count > 1 ? ':' . $parking_space_name : '';
if (!$space) {
if ($is_import) {
DB::rollBack();
return __service($this->menuTitle . '.space_not_exists')
. $str;
}
throw new CustomException(
__service($this->menuTitle . '.space_not_exists')
. $str
@ -75,12 +82,16 @@ class ParkingSpaceRepairService extends BaseService
$space = $space->toArray();
$space_id = $space['id'];
if ($space['status'] == 2) {
if ($is_import) {
DB::rollBack();
return __service($this->menuTitle . '.space_exists')
. $str;
}
throw new CustomException(
__service($this->menuTitle . '.space_exists')
. $str
__service($this->menuTitle . '.space_exists') . $str
);
}
$model = $this->createData(
$this->createData(
$space_id,
$data['admin_user_id'],
$data['start_at'],
@ -89,7 +100,7 @@ class ParkingSpaceRepairService extends BaseService
}
DB::commit();
return $model;
return '';
} catch (Exception $e) {
DB::rollBack();
throw $e;

8
app/common.php

@ -255,11 +255,15 @@ if (!function_exists('__imports')) {
}
if (!function_exists('imports_error')) {
function imports_error($index, $str): string
function imports_error($index, $str, $is = false): string
{
$str1 = __imports('import1');
$str2 = __imports('import2');
$str3 = __imports($str);
if ($is){
$str3 = $str;
} else {
$str3 = __imports($str);
}
return $str1 . $index . $str2 . ' : ' . $str3;
}
}

Loading…
Cancel
Save