|
@@ -2,7 +2,7 @@
|
|
|
* @Description: 车位分配算法模块,使用单例模式,接收外部请求并通过调用通信块接口发送反馈
|
|
|
* @Author: yct
|
|
|
* @Date: 2020-07-10 11:02:40
|
|
|
- * @LastEditTime: 2020-07-21 18:15:51
|
|
|
+ * @LastEditTime: 2020-07-22 15:33:48
|
|
|
* @LastEditors: yct
|
|
|
*/
|
|
|
|
|
@@ -32,9 +32,16 @@ Error_manager Parkspace_allocator::parkspace_allocator_init(int threads_size, pa
|
|
|
{
|
|
|
return ec;
|
|
|
}
|
|
|
- m_current_status = eParkspace_allocator_normal;
|
|
|
// 初始化任务处理线程池
|
|
|
m_thread_pool.thread_pool_init(threads_size);
|
|
|
+ // 读数据库车位数据,初始化车位管理
|
|
|
+ message::Parkspace_allocation_status_msg all_parkspace_info;
|
|
|
+ ec = mp_db_manager->get_all_parkspace_info(all_parkspace_info);
|
|
|
+ if(ec != SUCCESS)
|
|
|
+ {
|
|
|
+ return ec;
|
|
|
+ }
|
|
|
+ Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(all_parkspace_info);
|
|
|
m_current_status = eParkspace_allocator_normal;
|
|
|
return Error_code::SUCCESS;
|
|
|
}
|
|
@@ -145,7 +152,7 @@ Error_manager Parkspace_allocator::execute_msg(Communication_message* p_msg)
|
|
|
" message::Parkspace_force_update_request_msg ParseFromString error ");
|
|
|
}
|
|
|
//往线程池添加执行任务, 之后会唤醒一个线程去执行他.
|
|
|
- m_thread_pool.enqueue(&Parkspace_allocator::execute_for_force_update, this, request.confirm_space_info(), request.command_id());
|
|
|
+ m_thread_pool.enqueue(&Parkspace_allocator::execute_for_confirm_alloc, this, request.confirm_space_info(), request.command_id());
|
|
|
return SUCCESS;
|
|
|
}
|
|
|
}
|
|
@@ -195,13 +202,12 @@ void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int t
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
|
|
|
{
|
|
|
// 找到高于车高且空闲车位,则分配
|
|
|
- if (t_current_parkspace_status.parkspace_info(i).height() > car_info.car_height()
|
|
|
+ if (/*t_current_parkspace_status.parkspace_info(i).height() > car_info.car_height()
|
|
|
&& t_current_parkspace_status.parkspace_info(i).width() > car_info.car_width()
|
|
|
- && t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_empty)
|
|
|
+ && */t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_empty)
|
|
|
{
|
|
|
index = i;
|
|
|
break;
|
|
@@ -212,6 +218,7 @@ void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int t
|
|
|
t_error.set_error_code(PARKSPACE_ALLOCATOR_ALLOCATE_FAILED);
|
|
|
t_error.set_error_level(message::Error_level::MAJOR_ERROR);
|
|
|
t_allocated_space.CopyFrom(t_current_parkspace_status.parkspace_info(0));
|
|
|
+ t_allocated_space.mutable_car_info()->CopyFrom(car_info);
|
|
|
LOG(WARNING) << "分配车位失败";
|
|
|
}else{
|
|
|
t_error.set_error_code(SUCCESS);
|
|
@@ -222,18 +229,18 @@ void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int t
|
|
|
t_allocated_space.CopyFrom(t_space_to_lock);
|
|
|
// 分配车位后更新车位状态
|
|
|
Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(index, t_space_to_lock);
|
|
|
- LOG(INFO) << "第"<<index<<"号位占用, id: "<<t_space_to_lock.parkspace_id();
|
|
|
+ LOG(INFO) << "第"<<index<<"号位占用, id: "<<t_space_to_lock.parkspace_id()<<", 号牌: "<<t_space_to_lock.car_info().license();
|
|
|
// 数据库操作,修改车位状态为锁定,车辆状态为停车中
|
|
|
message::Vehicle_status t_vehicle_status = message::Vehicle_status::eVehicle_parking;
|
|
|
Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_space_to_lock);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db车位状态失败";
|
|
|
+ LOG(ERROR) << "更新db车位状态失败: "<< ec.to_string();
|
|
|
}
|
|
|
ec = Parkspace_db_manager::get_instance_references().update_vehicle_status(t_space_to_lock, t_vehicle_status);
|
|
|
if (ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db车辆状态失败";
|
|
|
+ LOG(ERROR) << "更新db车辆状态失败: " <<ec.to_string();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -366,19 +373,19 @@ void Parkspace_allocator::execute_for_release(message::Parkspace_info space_info
|
|
|
Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_space_to_release);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db车位状态失败";
|
|
|
+ LOG(ERROR) << "更新db车位状态失败: "<< ec.to_string();
|
|
|
}
|
|
|
message::Vehicle_status t_vehicle_status = message::Vehicle_status::eVehicle_idle;
|
|
|
ec = Parkspace_db_manager::get_instance_references().update_vehicle_status(t_space_to_release, t_vehicle_status);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db车辆状态失败";
|
|
|
+ LOG(ERROR) << "更新db车辆状态失败: "<< ec.to_string();
|
|
|
}
|
|
|
int t_park_record_id;
|
|
|
ec = Parkspace_db_manager::get_instance_references().query_vehicle(t_space_to_release.car_info().license(), t_vehicle_status, t_park_record_id);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "查询db车辆状态失败";
|
|
|
+ LOG(ERROR) << "查询db车辆状态失败: "<< ec.to_string();
|
|
|
}else if(t_vehicle_status == message::Vehicle_status::eVehicle_in_garage)
|
|
|
{
|
|
|
time_t tt = time(NULL);
|
|
@@ -396,7 +403,7 @@ void Parkspace_allocator::execute_for_release(message::Parkspace_info space_info
|
|
|
ec = Parkspace_db_manager::get_instance_references().update_parking_record(t_space_to_release, t_park_record_id);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db停车记录失败";
|
|
|
+ LOG(ERROR) << "更新db停车记录失败: "<< ec.to_string();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -456,7 +463,7 @@ void Parkspace_allocator::execute_for_force_update(message::Parkspace_info space
|
|
|
Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_update_space);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db车位状态失败";
|
|
|
+ LOG(ERROR) << "更新db车位状态失败: "<< ec.to_string();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -498,8 +505,9 @@ void Parkspace_allocator::execute_for_confirm_alloc(message::Parkspace_info spac
|
|
|
{
|
|
|
for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
|
|
|
{
|
|
|
- // 找到相同车位,且车辆信息匹配
|
|
|
+ // 找到相同车位,车辆信息匹配,且车位为锁定状态
|
|
|
if (t_current_parkspace_status.parkspace_info(i).parkspace_id() == space_info.parkspace_id()
|
|
|
+ && t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_locked
|
|
|
&& t_current_parkspace_status.parkspace_info(i).has_car_info()
|
|
|
&& t_current_parkspace_status.parkspace_info(i).car_info().license() == space_info.car_info().license())
|
|
|
{
|
|
@@ -535,18 +543,18 @@ void Parkspace_allocator::execute_for_confirm_alloc(message::Parkspace_info spac
|
|
|
Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_confirm_space);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db车位状态失败";
|
|
|
+ LOG(ERROR) << "更新db车位状态失败: "<< ec.to_string();
|
|
|
}
|
|
|
ec = Parkspace_db_manager::get_instance_references().insert_parking_record(t_confirm_space);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "插入db停车记录失败";
|
|
|
+ LOG(ERROR) << "插入db停车记录失败: "<< ec.to_string();
|
|
|
}
|
|
|
message::Vehicle_status t_vehicle_status = message::Vehicle_status::eVehicle_in_garage;
|
|
|
ec = Parkspace_db_manager::get_instance_references().update_vehicle_status(t_confirm_space, t_vehicle_status);
|
|
|
if(ec != SUCCESS)
|
|
|
{
|
|
|
- LOG(ERROR) << "更新db车辆状态失败";
|
|
|
+ LOG(ERROR) << "更新db车辆状态失败: "<< ec.to_string();
|
|
|
}
|
|
|
}
|
|
|
}
|