Browse Source

车位管理资讯修改,维修删除同步修改车位状态

master
wanghongjun 18 hours ago
parent
commit
ba2999f792
  1. 27
      app/Console/Commands/AutoChangeRepair.php
  2. 15
      app/Http/Controllers/Admin/ParkingManagementListController.php
  3. 56
      app/Http/Controllers/Admin/ParkingSpaceController.php
  4. 4
      app/Services/ParkingLicensePlateService.php
  5. 60
      app/Services/ParkingSpaceRepairService.php
  6. 174
      app/Services/ParkingSpaceService.php
  7. 8
      resources/lang/en/service.php
  8. 8
      resources/lang/zh-CN/service.php
  9. 8
      resources/lang/zh-TW/service.php
  10. 1
      routes/admin/api.php

27
app/Console/Commands/AutoChangeRepair.php

@ -55,13 +55,13 @@ class AutoChangeRepair extends Command
['start_at', '<=', $now_time],
['end_at', '>=', $now_time]
];
$space_ids = ParkingSpaceRepair::query()->where($where)->pluck(
$repair_space_ids = ParkingSpaceRepair::query()->where($where)->pluck(
'space_id'
);
if ($space_ids) {
if ($repair_space_ids) {
$update_ids = ParkingSpace::query()->where('status', '<>', 2)
->whereIn('id', $space_ids)->pluck('id');
->whereIn('id', $repair_space_ids)->pluck('id');
// 更新为维修状态
foreach ($update_ids as $id) {
// 修改为类型的维修指定灯光
@ -72,25 +72,16 @@ class AutoChangeRepair extends Command
// 处理在维修的回复正常, 维修已结束的回复正常
$ParkingSpace = ParkingSpace::query();
$ParkingSpace->where('status', 2);
if ($space_ids) {
$ParkingSpace->whereNotIn('id', $space_ids);
if ($repair_space_ids) {
$ParkingSpace->whereNotIn('id', $repair_space_ids);
}
$space_ids = $ParkingSpace->pluck('id');
if ($space_ids) {
// 维修车位已经 超过维修结束时间, 改为空置状态
$update_ids = ParkingSpaceRepair::query()->where(
'end_at',
'<',
$now_time
)->whereIn('space_id', $space_ids)->pluck(
'space_id'
);
if ($update_ids) {
// 更新为空置状态
foreach ($update_ids as $id) {
// 恢复正常类型灯光
$this->service->updateRepairStatus($id, 0);
}
// 更新为空置状态
foreach ($space_ids as $id) {
// 恢复正常类型灯光
$this->service->updateRepairStatus($id, 0);
}
}
DB::commit();

15
app/Http/Controllers/Admin/ParkingManagementListController.php

@ -117,17 +117,10 @@ class ParkingManagementListController
if ($request->has('status')) {
$status = $request->input('status');
if (!empty($status)) {
$where = [['status', '=', 1]];
if ($status == 3) {
$where[] = ['license_plate_id', '=', 0];
$query->where($where);
} elseif ($status == 4) {
$where[] = ['license_plate_id', '>=', 1];
$query->where($where);
} else {
$query->where('status', $status);
}
if (is_numeric($status)) {
$query->where(
$this->service->getStatusWhere($status)
);
}
}

56
app/Http/Controllers/Admin/ParkingSpaceController.php

@ -25,6 +25,7 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Maatwebsite\Excel\Facades\Excel;
use Psr\SimpleCache\InvalidArgumentException;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class ParkingSpaceController extends BaseController
@ -104,8 +105,8 @@ class ParkingSpaceController extends BaseController
if ($request->has('status')) {
$status = $request->input('status');
if (!empty($status)) {
$query->where('status', $status);
if (is_numeric($status)) {
$query->where($this->service->getStatusWhere($status));
}
}
@ -146,8 +147,8 @@ class ParkingSpaceController extends BaseController
'floor_data' => AdminFloor::getData(),
'space_type_data' => ParkingSpaceType::getData(),
'space_attr_data' => ParkingSpaceAttributes::getData(),
'status_data' => get_select_data(
$this->service->getStatusArr()
'status_data' => get_select_child_data(
$this->service->getStatusArr(true)
)
];
return $this->responseService->success($data);
@ -190,7 +191,9 @@ class ParkingSpaceController extends BaseController
null,
__('admin.update_succeeded')
);
} catch (Exception $e) {
} catch (ValidationException|CustomException $e) {
throw $e;
} catch (Exception $e) {
return $this->responseService->systemError(
__('exception.parking_space.update_type_failed') . ':'
. $e->getMessage()
@ -229,7 +232,9 @@ class ParkingSpaceController extends BaseController
null,
__('admin.update_succeeded')
);
} catch (Exception $e) {
} catch (ValidationException|CustomException $e) {
throw $e;
} catch (Exception $e) {
return $this->responseService->systemError(
__('exception.parking_space.update_attr_failed') . ':'
. $e->getMessage()
@ -302,11 +307,9 @@ class ParkingSpaceController extends BaseController
throw new Exception(__('controller.parking_space.not_space'));
}
$statusArr = $this->service->getStatusArr();
$data['parking_space_number'] = $item['number'];
$data['license_plate'] = ParkingLicensePlate::getNumber($item['license_plate_id']);
$data['status'] = $statusArr[$item['status']];
$data['status'] = $this->service->getParkingSpaceStatus($item['status']);
$data['parking_space_type'] = ParkingSpaceType::getName($item['space_type_id']);
$data['berthing_time_str'] = '';
if ($item['berthing_time']) {
@ -350,12 +353,22 @@ class ParkingSpaceController extends BaseController
throw new ValidationException($validator);
}
$parking_space_id = $data['parking_space_id'];
$status = $data['status'] == 1 ? 0 : 1;
$number = $data['license_plate'];
$number = $data['license_plate'] ?? '';
$start_time = $data['start_time'] ?? '';
$end_time = $data['end_time'] ?? '';
$this->validateId($parking_space_id, ParkingSpace::class);
$this->service->updateStatus($parking_space_id, $status, $number);
$this->service->adminUserId = $this->adminUserId;
$this->service->updateStatus(
$parking_space_id,
$data['status'],
$number,
$start_time,
$end_time
);
return $this->responseService->success('', __('admin.save_succeeded'));
} catch (Exception $e) {
} catch (ValidationException|CustomException $e) {
throw $e;
} catch (Exception $e) {
$m_prefix = __('exception.exception_handler.resource');
return $this->responseService->systemError(
$m_prefix . ':' . $e->getMessage()
@ -634,4 +647,21 @@ class ParkingSpaceController extends BaseController
);
}
}
/**
* 停车管理 车位列表权限接口
* @return JsonResponse
* @throws InvalidArgumentException
*/
public function ruleManagement(): JsonResponse
{
try {
$this->menuUri = 'parkingSpaceManagement';
return $this->responseService->success($this->methodShow());
} catch (Exception $e) {
return $this->responseService->systemError(
__('exception.get_data_failed') . ':' . $e->getMessage()
);
}
}
}

4
app/Services/ParkingLicensePlateService.php

@ -68,11 +68,11 @@ class ParkingLicensePlateService
return $model;
}
public function saveNumber($number)
public function saveNumber($number, $space_type_id = 0)
{
$id = ParkingLicensePlate::getValueId($number);
if (!$id) {
$model = $this->createNumber($number);
$model = $this->createNumber($number, $space_type_id);
$id = $model->id;
}
return $id;

60
app/Services/ParkingSpaceRepairService.php

@ -2,6 +2,7 @@
namespace App\Services;
use App\Exceptions\CustomException;
use App\Models\AdminFloor;
use App\Models\AdminUsers;
use App\Models\Parking;
@ -62,18 +63,17 @@ class ParkingSpaceRepairService extends BaseService
$spaceNameArr = explode(',', $data['parking_space_name']);
foreach ($spaceNameArr as $parking_space_name) {
$space_id = ParkingSpace::getValueId($parking_space_name);
$model = ParkingSpaceRepair::query()->create([
'space_id' => $space_id,
'admin_user_id' => $data['admin_user_id'],
'start_at' => $data['start_at'],
'end_at' => $data['end_at'],
'created_at' => get_datetime()
]);
$this->logService->logCreated(
$model,
$this->menuTitle . '.create'
if (!$space_id) {
throw new CustomException(
__service($this->menuTitle . '.space_not_exists')
. ':' . $parking_space_name
);
}
$model = $this->createData(
$space_id,
$data['admin_user_id'],
$data['start_at'],
$data['end_at']
);
}
@ -85,6 +85,23 @@ class ParkingSpaceRepairService extends BaseService
}
}
// 创建维修数据
public function createData($space_id,$admin_user_id, $start_at, $end_at)
{
$model = ParkingSpaceRepair::query()->create([
'space_id' => $space_id,
'admin_user_id' => $admin_user_id,
'start_at' => $start_at,
'end_at' => $end_at,
'created_at' => get_datetime()
]);
$this->logService->logCreated(
$model,
$this->menuTitle . '.create'
);
return $model;
}
/**
* @param array $data
* @param int $id
@ -134,11 +151,21 @@ class ParkingSpaceRepairService extends BaseService
DB::beginTransaction();
$model = ParkingSpaceRepair::query()->findOrFail($id);
$item = $model->toArray();
$this->logService->logDeleted($model, $this->menuTitle . '.delete');
$model->delete();
// 判断 并修改车位状态为空闲
(new ParkingSpaceService(
$this->logService
))->syncUpdateParkingSpaceStatus(
$item['space_id'],
$item['start_at'],
$item['end_at']
);
DB::commit();
return true;
} catch (Exception $e) {
@ -157,13 +184,22 @@ class ParkingSpaceRepairService extends BaseService
try {
DB::beginTransaction();
$ParkingSpaceService = new ParkingSpaceService($this->logService);
foreach ($ids as $id) {
$model = ParkingSpaceRepair::query()->findOrFail($id);
$item = $model->toArray();
$this->logService->logDeleted(
$model,
$this->menuTitle . '.delete'
);
$model->delete();
$ParkingSpaceService->syncUpdateParkingSpaceStatus(
$item['space_id'],
$item['start_at'],
$item['end_at']
);
}
DB::commit();

174
app/Services/ParkingSpaceService.php

@ -2,6 +2,7 @@
namespace App\Services;
use App\Exceptions\CustomException;
use App\Models\AdminFloor;
use App\Models\ParkingLicensePlate;
use App\Models\ParkingSpace;
@ -16,6 +17,8 @@ use Illuminate\Support\Facades\DB;
class ParkingSpaceService extends BaseService
{
public string $adminUserId = '0';
protected int $recognition = 80;
/**
* @var string[]
@ -35,20 +38,6 @@ class ParkingSpaceService extends BaseService
$this->logService->menuTitle = 'cat_list';
}
/**
* 返回翻译后的状态
* @param $status
* @return string
*/
public function getStatusStr($status): string
{
$value = $this->statusArr[$status] ?? '';
if ($value) {
return __('service.parking_space.' . $value);
}
return $value;
}
public function getRecognition($recognition): string
{
if ($recognition) {
@ -67,6 +56,7 @@ class ParkingSpaceService extends BaseService
return '-';
}
// 获取翻译后的状态数据列表
public function getStatusArr($is_child = false): array
{
$arr = [];
@ -84,9 +74,56 @@ class ParkingSpaceService extends BaseService
return $arr;
}
// 获取状态显示值
public function getParkingSpaceStatus($status, $license_plate_id = '')
{
$statusArr = $this->getStatusArr(true);
// 是否有车
$yesStr = '';
$noStr = '';
if ($license_plate_id) {
$yesStr = $statusArr['children'][1][3];
} else {
$noStr = $statusArr['children'][1][4];
}
if ($status == '1') {
// 占用 是否有车
$str = $yesStr ?: $noStr;
return $statusArr[1] . '/' . $str;
} elseif ($status == '2') {
return $statusArr[$status];
} else {
$status_str = $statusArr[$status] ?? '';
if ($status_str) {
// 空闲 是否有车
if ($status < 1) {
return $yesStr ? $status_str . '/' . $yesStr : $status_str;
}
}
return '';
}
}
// 获取查询状态条件
public function getStatusWhere($status)
{
$where = [['status', '=', 1]];
if ($status == 4) {
// 无车牌
$where[] = ['license_plate_id', '=', 0];
} elseif ($status == 3) {
// 有车牌
$where[] = ['license_plate_id', '>=', 1];
} else {
$where = [['status', '=', $status]];
}
return $where;
}
// 获取状态的值
public function getStatusArrKey(): array
{
return array_keys($this->statusArr);
return [0,1,2,3,4];
}
public function optionItems($item)
@ -105,7 +142,7 @@ class ParkingSpaceService extends BaseService
$item['recognition'] = $this->getRecognition(
$item['recognition']
);
$item['status'] = $this->getStatusStr(
$item['status'] = $this->getParkingSpaceStatus(
$item['status']
);
$item['operation_type'] = $this->getOperationType(
@ -124,6 +161,7 @@ class ParkingSpaceService extends BaseService
* @param string $key
* @return Builder
* @throws Exception
* @throws CustomException
*/
public function updateData(
array $data,
@ -137,6 +175,9 @@ class ParkingSpaceService extends BaseService
$model = ParkingSpace::query()->whereIn('id', $ids)->select();
$oldValues = $model->get()->toArray();
if (!$oldValues) {
throw new CustomException(__service('parking_space.space_not'));
}
$updateData = [
$key => $data_id,
@ -256,9 +297,22 @@ class ParkingSpaceService extends BaseService
)->get()->toArray();
}
// 更新状态和车牌
public function updateStatus($id, $status, $license_plate)
{
/**
* 更新状态和车牌
* @param $id // 车位id
* @param $status // 车位状态
* @param $license_plate // 车牌号码
* @param $start_at // 维修开始时间
* @param $end_at // 维修结束时间
* @throws Exception
*/
public function updateStatus(
$id,
$status,
$license_plate,
string $start_at = '',
string $end_at = ''
) {
try {
DB::beginTransaction();
$model = ParkingSpace::query()->findOrFail($id);
@ -267,27 +321,60 @@ class ParkingSpaceService extends BaseService
'status' => $status,
'updated_at' => get_datetime()
];
if (!empty($license_plate) && $status == 1) {
$number_id = ParkingLicensePlate::getValueId($license_plate);
if (!$number_id) {
$licensePlateService = new ParkingLicensePlateService($this->logService);
$create = [
'number' => $license_plate,
'space_type_id' => $oldValues['space_type_id']
];
$licensePlateModel = $licensePlateService->createData($create);
$number_id = $licensePlateModel->id;
}
if (!empty($license_plate) && $status == 3) {
$licensePlateService = new ParkingLicensePlateService(
$this->logService
);
$number_id = $licensePlateService->saveNumber(
$license_plate,
$oldValues['space_type_id']
);
if ($number_id) {
$update['license_plate_id'] = $number_id;
$update['berthing_time'] = get_datetime();
$update['recognition'] = 'high';
$update['recognition'] = '90';
}
$update['status'] = 1;
} else if ($status == 4) {
$update['license_plate_id'] = 0;
$update['berthing_time'] = null;
$update['recognition'] = '';
$update['status'] = 1;
} else if (!$status) {
$update['license_plate_id'] = 0;
$update['berthing_time'] = null;
$update['recognition'] = '';
}
if ($status == 2) {
// 维修
$now_times = time();
$start_times = strtotime($start_at);// 维修开始时间
$end_times = strtotime($end_at);// 维修结束时间
if (!$start_times) {
throw new CustomException(__validation('parking_repair_list.s_empty'));
}
if (!$end_times) {
throw new CustomException(__validation('parking_repair_list.e_empty'));
}
if ($start_times > $end_times) {
throw new CustomException(__validation('parking_repair_list.date_error'));
}
$start_time = get_datetime('datetime', $start_times);
$end_time = get_datetime('datetime', $end_times);
$ParkingSpaceRepair = new ParkingSpaceRepairService(
$this->logService
);
$ParkingSpaceRepair->createData(
$id,
$this->adminUserId,
$start_time,
$end_time
);
if ($start_times <= $now_times && $end_times >= $now_times) {
$this->updateRepairStatus($id, 2);
}
}
$model->update($update);
$this->logService->logUpdated(
$model,
@ -516,4 +603,29 @@ class ParkingSpaceService extends BaseService
$status == 2
);
}
/**
* 删除维修记录,则修改为空闲
* @param $space_id // 车位id
* @param $start_at // 维修开始时间
* @param $end_at // 维修结束时间
* @return void
*/
public function syncUpdateParkingSpaceStatus($space_id, $start_at, $end_at)
{
// 判断是否维修记录在当前时间
$start_at_times = strtotime($start_at);
$end_at_times = strtotime($end_at);
$now_times = time();
$is_now = false;
if ($start_at_times <= $now_times && $end_at_times >= $now_times) {
$is_now = true;
}
// 判断车位状态是否在维修
$item = ParkingSpace::query()->find($space_id);
if ($item['status'] == 2 && $is_now) {
// 删除维修数据这撤销
$this->updateRepairStatus($space_id, 0);
}
}
}

8
resources/lang/en/service.php

@ -71,7 +71,8 @@ return [
'no_cars' => 'Parking space status: no cars, update: cars available',
'yes_cars' => 'Parking status updated with cars available, no cars available',
'number_update' => 'License plate number update',
'number_exists' => 'The parking number already exists'
'number_exists' => 'The parking number already exists',
'space_not' => 'Parking space does not exist'
],
'parking_information' => [
'not_default' => 'Default parking space type not set'
@ -164,8 +165,9 @@ return [
'handler4' => 'Security patrol'
],
'parking_repair_list' => [
'not_synced' => 'Not synced',
'synced' => 'Synchronized'
'not_synced' => 'Not synced',
'synced' => 'Synchronized',
'space_not_exists' => 'The parking number does not exist'
],
'gate_control' => [
'automatic' => 'Automatic entry',

8
resources/lang/zh-CN/service.php

@ -71,7 +71,8 @@ return [
'no_cars' => '车位状态无车更新有车',
'yes_cars' => '车位状态有车更新无车',
'number_update' => '车牌号更新',
'number_exists' => '车位号码已存在'
'number_exists' => '车位号码已存在',
'space_not' => '车位不存在'
],
'parking_information' => [
'not_default' => '未设置默认车位类型'
@ -164,8 +165,9 @@ return [
'handler4' => '安保巡逻'
],
'parking_repair_list' => [
'not_synced' => '未同步',
'synced' => '已同步'
'not_synced' => '未同步',
'synced' => '已同步',
'space_not_exists' => '車位號不存在'
],
'gate_control' => [
'automatic' => '自动入场',

8
resources/lang/zh-TW/service.php

@ -71,7 +71,8 @@ return [
'no_cars' => '車位狀態無車更新有車',
'yes_cars' => '車位狀態有車更新無車',
'number_update' => '車牌號更新',
'number_exists' => '車位號碼已存在'
'number_exists' => '車位號碼已存在',
'space_not' => '車位不存在'
],
'parking_information' => [
'not_default' => '未設定默認車位類型'
@ -164,8 +165,9 @@ return [
'handler4' => '安保巡邏'
],
'parking_repair_list' => [
'not_synced' => '未同步',
'synced' => '已同步'
'not_synced' => '未同步',
'synced' => '已同步',
'space_not_exists' => '车位号不存在'
],
'gate_control' => [
'automatic' => '自動入場',

1
routes/admin/api.php

@ -129,6 +129,7 @@ Route::group(['prefix' => 'admin'], function () {
Route::post('/parkingSpaceManagement/batchDelete', [ParkingSpaceController::class, 'batchDelete']);
Route::post('/parkingSpaceManagement/batchUpdateAttr', [ParkingSpaceController::class, 'updateAttr']);
Route::post('/parkingSpaceManagement/batchImport', [ParkingSpaceController::class, 'import']);
Route::get('/parkingSpaceManagement/rule', [ParkingSpaceController::class, 'ruleManagement']);
//车位类型管理
Route::get('/spaceType', [ParkingSpaceTypeController::class, 'index']);
Route::get('/spaceType/create', [ParkingSpaceTypeController::class, 'create']);

Loading…
Cancel
Save