|
@@ -2,7 +2,7 @@
|
|
|
* @Description: 车位分配算法模块,使用单例模式,接收外部请求并通过调用通信块接口发送反馈
|
|
|
* @Author: yct
|
|
|
* @Date: 2020-07-10 11:02:40
|
|
|
- * @LastEditTime: 2020-08-05 17:10:58
|
|
|
+ * @LastEditTime: 2020-08-06 10:32:28
|
|
|
* @LastEditors: yct
|
|
|
*/
|
|
|
|
|
@@ -177,6 +177,23 @@ Parkspace_allocator::parkspace_allocator_status Parkspace_allocator::get_parkspa
|
|
|
return m_current_status;
|
|
|
}
|
|
|
|
|
|
+// 检查车辆是否已存在,通常分配前调用
|
|
|
+bool Parkspace_allocator::check_car_existence(std::string license, message::Parkspace_allocation_status_msg status_msg)
|
|
|
+{
|
|
|
+ for (size_t i = 0; i < status_msg.parkspace_info_size(); i++)
|
|
|
+ {
|
|
|
+ // 找到相同号牌,且车位状态锁定或占用
|
|
|
+ if(status_msg.parkspace_info(i).has_car_info()
|
|
|
+ && status_msg.parkspace_info(i).car_info().license() == license
|
|
|
+ && (status_msg.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_locked ||
|
|
|
+ status_msg.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_occupied))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
//分配车位线程函数
|
|
|
void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int terminal_id, message::Command_info command_info)
|
|
|
{
|
|
@@ -200,8 +217,14 @@ void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int t
|
|
|
t_error.set_error_level(message::Error_level::MAJOR_ERROR);
|
|
|
LOG(ERROR) << "无车位";
|
|
|
}
|
|
|
- else
|
|
|
+ else if(check_car_existence(car_info.license(), t_current_parkspace_status))
|
|
|
{
|
|
|
+ t_error.set_error_code(PARKSPACE_ALLOCATOR_CAR_ALREADY_EXIST);
|
|
|
+ t_error.set_error_level(message::Error_level::MAJOR_ERROR);
|
|
|
+ LOG(ERROR) << "车辆已存在";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
|
|
|
{
|
|
|
// 找到高于车高且空闲车位,则分配
|
|
@@ -246,7 +269,7 @@ void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int t
|
|
|
}
|
|
|
}
|
|
|
response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
- response_msg.CopyFrom(command_info);
|
|
|
+ response_msg.mutable_command_info()->CopyFrom(command_info);
|
|
|
response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
response_msg.mutable_allocated_space_info()->CopyFrom(t_allocated_space);
|
|
|
Communication_message response=Communication_message();
|
|
@@ -306,7 +329,7 @@ void Parkspace_allocator::execute_for_search(message::Car_info car_info, message
|
|
|
}
|
|
|
}
|
|
|
response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
- response_msg.CopyFrom(command_info);
|
|
|
+ response_msg.mutable_command_info()->CopyFrom(command_info);
|
|
|
response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
response_msg.mutable_car_position()->CopyFrom(t_car_position);
|
|
|
Communication_message response=Communication_message();
|
|
@@ -415,7 +438,7 @@ void Parkspace_allocator::execute_for_release(message::Parkspace_info space_info
|
|
|
}
|
|
|
}
|
|
|
response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
- response_msg.CopyFrom(command_info);
|
|
|
+ response_msg.mutable_command_info()->CopyFrom(command_info);
|
|
|
response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
response_msg.mutable_release_space_info()->CopyFrom(t_release_space);
|
|
|
Communication_message response=Communication_message();
|
|
@@ -479,7 +502,7 @@ void Parkspace_allocator::execute_for_force_update(message::Parkspace_info space
|
|
|
}
|
|
|
}
|
|
|
response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
- response_msg.CopyFrom(command_info);
|
|
|
+ response_msg.mutable_command_info()->CopyFrom(command_info);
|
|
|
response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
response_msg.mutable_update_space_info()->CopyFrom(t_update_space);
|
|
|
Communication_message response=Communication_message();
|
|
@@ -575,7 +598,7 @@ void Parkspace_allocator::execute_for_confirm_alloc(message::Parkspace_info spac
|
|
|
}
|
|
|
}
|
|
|
response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
- response_msg.CopyFrom(command_info);
|
|
|
+ response_msg.mutable_command_info()->CopyFrom(command_info);
|
|
|
response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
response_msg.mutable_confirm_alloc_space_info()->CopyFrom(t_confirm_space);
|
|
|
Communication_message response=Communication_message();
|