diff --git a/src/barrier/generic_barrier.cpp b/src/barrier/generic_barrier.cpp index 49c500f..1351b73 100644 --- a/src/barrier/generic_barrier.cpp +++ b/src/barrier/generic_barrier.cpp @@ -53,7 +53,29 @@ namespace zsy std::jthread t([recognizeResult,name,sn] { LOGGER_INFO("正在处理车牌识别结果:{}、{}、{}", recognizeResult->license, name, sn); + { + std::lock_guard lock(tasks_mutex); + if (tasks.contains(sn)) + { + if (auto oldLicense = tasks.at(sn); oldLicense == recognizeResult->license) + { + LOGGER_INFO("重复识别:{}、{}", sn, oldLicense); + } else + { + Application::deviceHolder->getSoundColumn(sn)->play("请等待前车业务完成后重新识别"); + LOGGER_INFO("当前道闸正在处理:{}、{}", sn, oldLicense); + } + return; + } else + { + tasks[sn] = recognizeResult->license; + } + } RecognizeProcessor::process(recognizeResult); + { + std::lock_guard lock(tasks_mutex); + tasks.erase(sn); + } LOGGER_INFO("车牌识别结果处理完成"); }); t.detach(); diff --git a/src/barrier/generic_barrier.h b/src/barrier/generic_barrier.h index be9e26e..5415278 100644 --- a/src/barrier/generic_barrier.h +++ b/src/barrier/generic_barrier.h @@ -144,7 +144,8 @@ namespace zsy class GenericBarrier : public Barrier { BarrierProperties config; - + inline static std::unordered_map tasks; + inline static std::mutex tasks_mutex; public: explicit GenericBarrier(const BarrierProperties &config); diff --git a/src/recognize_processor.cpp b/src/recognize_processor.cpp index 9b4c582..18a85ce 100644 --- a/src/recognize_processor.cpp +++ b/src/recognize_processor.cpp @@ -11,24 +11,6 @@ namespace zsy { const std::string &sn = data->sn; const std::string &license = data->license; - { - std::lock_guard lock(tasks_mutex); - if (tasks.contains(sn)) - { - if (auto oldLicense = tasks.at(sn); oldLicense == license) - { - LOGGER_INFO("重复识别:{}、{}", sn, oldLicense); - } else - { - Application::deviceHolder->getSoundColumn(sn)->play("请等待前车业务完成后重新识别"); - LOGGER_INFO("当前道闸正在处理:{}、{}", sn, oldLicense); - } - return; - } else - { - tasks[sn] = license; - } - } try { std::jthread t; @@ -49,23 +31,11 @@ namespace zsy return; } addition_process(reportPassResult.data.orderNo, data); - { - std::lock_guard lock(tasks_mutex); - tasks.erase(sn); - } } catch (std::exception &e) { - { - std::lock_guard lock(tasks_mutex); - tasks.erase(sn); - } LOGGER_ERROR("车牌识别结果处理失败: {}", e.what()); } catch (...) { - { - std::lock_guard lock(tasks_mutex); - tasks.erase(sn); - } LOGGER_ERROR("未知异常,车牌识别结果处理失败"); } } diff --git a/src/recognize_processor.h b/src/recognize_processor.h index 6ab0077..f322fc6 100644 --- a/src/recognize_processor.h +++ b/src/recognize_processor.h @@ -13,8 +13,6 @@ namespace zsy class RecognizeProcessor { public: - inline static std::unordered_map tasks; - inline static std::mutex tasks_mutex; static void process(std::shared_ptr data);