修复问题
parent
62ba7d9a11
commit
6e9047b0ae
|
@ -111,7 +111,7 @@ namespace zsy
|
||||||
LOGGER_INFO("等待...");
|
LOGGER_INFO("等待...");
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(appProperties.delay * 1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(appProperties.delay * 1000));
|
||||||
}
|
}
|
||||||
threadPool = std::make_shared<ThreadPool>(4);
|
threadPool = std::make_shared<ThreadPool>();
|
||||||
|
|
||||||
eventManager = std::make_shared<EventManager>(threadPool);
|
eventManager = std::make_shared<EventManager>(threadPool);
|
||||||
|
|
||||||
|
|
|
@ -5,17 +5,16 @@
|
||||||
|
|
||||||
namespace zsy
|
namespace zsy
|
||||||
{
|
{
|
||||||
|
|
||||||
class Barrier
|
class Barrier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Barrier() = default;
|
virtual ~Barrier() = default;
|
||||||
|
|
||||||
virtual void open() = 0;
|
virtual void open() = 0;
|
||||||
|
|
||||||
virtual void resolveRecognizeResult(const std::string & license,const std::string & imageFile) = 0;
|
virtual bool isFront() = 0;
|
||||||
|
|
||||||
|
// virtual void resolveRecognizeResult(const std::string &license, const std::string &imageFile) = 0;
|
||||||
};
|
};
|
||||||
} // zsy
|
} // zsy
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
#include "generic_barrier.h"
|
#include "generic_barrier.h"
|
||||||
|
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
#include "recognize_processor.h"
|
||||||
|
#include "common/date_util.h"
|
||||||
#include "common/loging.h"
|
#include "common/loging.h"
|
||||||
#include "common/snowflake.h"
|
#include "common/snowflake.h"
|
||||||
#include "common/sys_util.h"
|
#include "common/sys_util.h"
|
||||||
|
|
||||||
namespace zsy
|
namespace zsy
|
||||||
{
|
{
|
||||||
static long long getTime()
|
|
||||||
{
|
|
||||||
const auto now = std::chrono::system_clock::now();
|
|
||||||
const auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
|
|
||||||
const auto epoch = now_ms.time_since_epoch();
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(epoch).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
GenericBarrier::GenericBarrier(const BarrierProperties &config)
|
GenericBarrier::GenericBarrier(const BarrierProperties &config)
|
||||||
: config(config)
|
: config(config)
|
||||||
{
|
{
|
||||||
|
@ -75,15 +69,18 @@ namespace zsy
|
||||||
res.set_content(R"({})", "application/json");
|
res.set_content(R"({})", "application/json");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Application::threadPool->submit([imageFile,license, barrier = Application::deviceHolder->getBarrier(serialno)]
|
auto barrier = Application::deviceHolder->getBarrier(serialno);
|
||||||
|
if (!barrier)
|
||||||
{
|
{
|
||||||
if (!barrier)
|
LOGGER_ERROR("未找到对应的道闸");
|
||||||
{
|
return;
|
||||||
LOGGER_ERROR("未找到对应的道闸");
|
}
|
||||||
return;
|
|
||||||
}
|
std::thread t([front = barrier->isFront(), serialno,license,imageFile]
|
||||||
barrier->resolveRecognizeResult(license, imageFile);
|
{
|
||||||
|
RecognizeProcessor::process(front, serialno, license, imageFile);
|
||||||
});
|
});
|
||||||
|
t.detach();
|
||||||
} catch (std::exception &e)
|
} catch (std::exception &e)
|
||||||
{
|
{
|
||||||
LOGGER_ERROR("车牌识别结果处理失败: {}", e.what());
|
LOGGER_ERROR("车牌识别结果处理失败: {}", e.what());
|
||||||
|
@ -101,7 +98,7 @@ namespace zsy
|
||||||
void GenericBarrier::open()
|
void GenericBarrier::open()
|
||||||
{
|
{
|
||||||
LOGGER_INFO("收到开门请求:{} {}", config.name, config.sn);
|
LOGGER_INFO("收到开门请求:{} {}", config.name, config.sn);
|
||||||
const long timestamp = static_cast<long>(getTime());
|
const long timestamp = static_cast<long>(DateUtil::timestamp() / 1000);
|
||||||
BarrierBcd barrier;
|
BarrierBcd barrier;
|
||||||
barrier.id = "open" + std::to_string(timestamp);
|
barrier.id = "open" + std::to_string(timestamp);
|
||||||
barrier.sn = config.sn;
|
barrier.sn = config.sn;
|
||||||
|
@ -135,6 +132,11 @@ namespace zsy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GenericBarrier::isFront()
|
||||||
|
{
|
||||||
|
return config.name.find("前置") != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
std::tuple<bool, RecognizeResult> GenericBarrier::parseRecognizeResult(const std::string &jsonStr)
|
std::tuple<bool, RecognizeResult> GenericBarrier::parseRecognizeResult(const std::string &jsonStr)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -153,7 +155,7 @@ namespace zsy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericBarrier::resolveRecognizeResult(const std::string &license, const std::string &imageFile)
|
/*void GenericBarrier::resolveRecognizeResult(const std::string &license, const std::string &imageFile)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -224,5 +226,5 @@ namespace zsy
|
||||||
{
|
{
|
||||||
LOGGER_ERROR("未知异常,车牌识别结果处理失败");
|
LOGGER_ERROR("未知异常,车牌识别结果处理失败");
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
} // zsy
|
} // zsy
|
||||||
|
|
|
@ -148,7 +148,9 @@ namespace zsy
|
||||||
|
|
||||||
void open() override;
|
void open() override;
|
||||||
|
|
||||||
void resolveRecognizeResult(const std::string &license, const std::string &imageFile) override;
|
bool isFront() override;
|
||||||
|
|
||||||
|
// void resolveRecognizeResult(const std::string &license, const std::string &imageFile) override;
|
||||||
|
|
||||||
static std::tuple<bool, RecognizeResult> parseRecognizeResult(const std::string &jsonStr);
|
static std::tuple<bool, RecognizeResult> parseRecognizeResult(const std::string &jsonStr);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
#include "daily_and_size_sink.h"
|
#include "daily_and_size_sink.h"
|
||||||
|
#include <ctime>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
#include "date_util.h"
|
||||||
|
|
||||||
namespace zsy
|
namespace zsy
|
||||||
{
|
{
|
||||||
|
@ -12,7 +16,7 @@ namespace zsy
|
||||||
baseFilename = base_path.stem().string();
|
baseFilename = base_path.stem().string();
|
||||||
baseExt = base_path.extension().string();
|
baseExt = base_path.extension().string();
|
||||||
std::filesystem::create_directories(paths);
|
std::filesystem::create_directories(paths);
|
||||||
currentDate = today();
|
currentDate = DateUtil::format(Ymd_);
|
||||||
currentIndex = lastIndex();
|
currentIndex = lastIndex();
|
||||||
currentSize = lastSize();
|
currentSize = lastSize();
|
||||||
fileHelper.open(basePath + "\\" + baseFilename + baseExt, false);
|
fileHelper.open(basePath + "\\" + baseFilename + baseExt, false);
|
||||||
|
@ -21,7 +25,7 @@ namespace zsy
|
||||||
|
|
||||||
void DailyAndSizeSink::rotateFile()
|
void DailyAndSizeSink::rotateFile()
|
||||||
{
|
{
|
||||||
auto current_date = today();
|
auto current_date = DateUtil::format(Ymd_);
|
||||||
|
|
||||||
if (current_date != currentDate)
|
if (current_date != currentDate)
|
||||||
{
|
{
|
||||||
|
@ -100,22 +104,18 @@ namespace zsy
|
||||||
fileHelper.flush();
|
fileHelper.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DailyAndSizeSink::today()
|
/*std::string DailyAndSizeSink::today()
|
||||||
{
|
{
|
||||||
// 获取当前时间点
|
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
time_t current_time = std::chrono::system_clock::to_time_t(now);
|
time_t current_time = std::chrono::system_clock::to_time_t(now);
|
||||||
|
|
||||||
// 转换为本地时间
|
tm local_tm{};
|
||||||
tm local_tm;
|
localtime_s(&local_tm, ¤t_time);
|
||||||
localtime_s(&local_tm, ¤t_time); // 安全版本的 localtime
|
char buffer[11];
|
||||||
|
std::strftime(buffer, sizeof(buffer), "%F", &local_tm);
|
||||||
// 格式化日期为 YYYY-MM-DD 格式
|
|
||||||
char buffer[11]; // 足够存储 "YYYY-MM-DD\0"
|
|
||||||
strftime(buffer, sizeof(buffer), "%F", &local_tm);
|
|
||||||
|
|
||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
uint32_t DailyAndSizeSink::lastIndex()
|
uint32_t DailyAndSizeSink::lastIndex()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,10 +6,8 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ctime>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
namespace zsy
|
namespace zsy
|
||||||
{
|
{
|
||||||
|
@ -30,7 +28,7 @@ namespace zsy
|
||||||
|
|
||||||
void cleanOldFiles();
|
void cleanOldFiles();
|
||||||
|
|
||||||
std::string today();
|
// std::string today();
|
||||||
|
|
||||||
uint32_t lastIndex();
|
uint32_t lastIndex();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "date_util.h"
|
||||||
|
|
||||||
|
namespace zsy
|
||||||
|
{
|
||||||
|
std::string DateUtil::format(const std::string &pattern, const TimePoint dt)
|
||||||
|
{
|
||||||
|
std::time_t t = std::chrono::system_clock::to_time_t(dt);
|
||||||
|
tm local_tm{};
|
||||||
|
localtime_s(&local_tm, &t);
|
||||||
|
char buffer[32];
|
||||||
|
std::strftime(buffer, sizeof(buffer), pattern.c_str(), &local_tm);
|
||||||
|
return std::string(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
long long DateUtil::timestamp()
|
||||||
|
{
|
||||||
|
return std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()+ + std::chrono::hours(8)).time_since_epoch().count();
|
||||||
|
}
|
||||||
|
} // zsy
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef DATE_UTIL_H
|
||||||
|
#define DATE_UTIL_H
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define Ymd_ "%F"
|
||||||
|
#define Ymd "%Y%m%d"
|
||||||
|
#define HMS_ "%T"
|
||||||
|
#define HMS "%H%M%S"
|
||||||
|
#define YmdHMS_ "%F %T"
|
||||||
|
#define YmdHMS "%Y%m%d%H%M%S"
|
||||||
|
|
||||||
|
namespace zsy
|
||||||
|
{
|
||||||
|
class DateUtil
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using TimePoint = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>;
|
||||||
|
|
||||||
|
static std::string format(const std::string &pattern = YmdHMS_, TimePoint dt = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()));
|
||||||
|
|
||||||
|
static long long timestamp();
|
||||||
|
};
|
||||||
|
} // zsy
|
||||||
|
|
||||||
|
#endif //DATE_UTIL_H
|
|
@ -199,20 +199,6 @@ namespace zsy
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*std::wstring SysUtil::str_a_w(const std::string &astr)
|
|
||||||
{
|
|
||||||
if (astr.empty()) return {};
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t> > converter;
|
|
||||||
return converter.from_bytes(astr);
|
|
||||||
}
|
|
||||||
std::string SysUtil::str_w_a(const std::wstring &wstr)
|
|
||||||
{
|
|
||||||
if (wstr.empty()) return {};
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t> > converter;
|
|
||||||
return converter.to_bytes(wstr);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
std::shared_ptr<char[]> SysUtil::ch_vlt(const char *ach)
|
std::shared_ptr<char[]> SysUtil::ch_vlt(const char *ach)
|
||||||
{
|
{
|
||||||
if (ach == nullptr) return nullptr;
|
if (ach == nullptr) return nullptr;
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace zsy
|
||||||
std::shared_mutex status_mtx;
|
std::shared_mutex status_mtx;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ThreadPool(size_t threadCount = std::thread::hardware_concurrency());
|
explicit ThreadPool(size_t threadCount = std::thread::hardware_concurrency() * 2);
|
||||||
|
|
||||||
template<typename Fn>
|
template<typename Fn>
|
||||||
void submit(Fn &&task) noexcept
|
void submit(Fn &&task) noexcept
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include "recognize_processor.h"
|
||||||
|
#include "application.h"
|
||||||
|
#include "common/date_util.h"
|
||||||
|
#include "common/loging.h"
|
||||||
|
#include "common/sys_util.h"
|
||||||
|
#include "common/snowflake.h"
|
||||||
|
|
||||||
|
namespace zsy
|
||||||
|
{
|
||||||
|
void RecognizeProcessor::process(bool front, const std::string &sn, const std::string &license, const std::string &imageFile)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (front)
|
||||||
|
{
|
||||||
|
// 播放语音 1
|
||||||
|
Application::threadPool->submit([sn]
|
||||||
|
{
|
||||||
|
Application::deviceHolder->getSoundColumn(sn)->play("欢迎光临");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 上传车头照
|
||||||
|
auto imageFileDecode = SysUtil::base64_decode(imageFile);
|
||||||
|
const std::shared_ptr<std::istream> imageFileStream = std::make_shared<std::istringstream>(imageFileDecode, std::ios_base::in | std::ios_base::binary);
|
||||||
|
auto photoId = Snowflake::genIdStr();
|
||||||
|
std::string date = DateUtil::format(Ymd);
|
||||||
|
// 上报 1
|
||||||
|
auto reportPassResult = Application::reportSvr->reportPass(license, sn, "");
|
||||||
|
if (!(reportPassResult.code == 0 && (reportPassResult.data.type == 1 || reportPassResult.data.type == 2)))
|
||||||
|
{
|
||||||
|
LOGGER_INFO("不进行后续处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto [carFrontUrlSucc,carFrontUrl] = Application::oss->upload(date + "/" + "front_" + photoId + ".jpg", *imageFileStream);
|
||||||
|
|
||||||
|
// 上报结果 type 不为 0,播放语音 2 并读地磅,拍车斗并上传
|
||||||
|
Application::threadPool->submit([sn]
|
||||||
|
{
|
||||||
|
Application::deviceHolder->getSoundColumn(sn)->play("正在称重,请稍后");
|
||||||
|
});
|
||||||
|
double weight = Application::deviceHolder->getPlatformScale(sn)->reading();
|
||||||
|
auto photographPath = Application::deviceHolder->getVidicon(sn)->photograph();
|
||||||
|
auto [carBodyUrlSucc,carBodyUrl] = Application::oss->upload(date + "/" + "body_" + photoId + ".jpg", photographPath);
|
||||||
|
if (!photographPath.empty())
|
||||||
|
{
|
||||||
|
auto pathPtr = SysUtil::ch_vlt(photographPath.c_str());
|
||||||
|
if (std::remove(pathPtr.get()) != 0)
|
||||||
|
{
|
||||||
|
auto [_,code,msg] = SysUtil::getError();
|
||||||
|
LOGGER_ERROR("临时照片删除失败:{},错误码:{},错误信息:{}", photographPath, code, msg);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("临时照片删除成功:{}", photographPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上报 2
|
||||||
|
Application::reportSvr->report(license, sn, weight, carFrontUrl, carBodyUrl, reportPassResult.data.orderNo);
|
||||||
|
} catch (std::exception &e)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("车牌识别结果处理失败: {}", e.what());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOGGER_ERROR("未知异常,车牌识别结果处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // zsy
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef RECOGNIZE_PROCESSOR_H
|
||||||
|
#define RECOGNIZE_PROCESSOR_H
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
namespace zsy
|
||||||
|
{
|
||||||
|
class RecognizeProcessor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void process(bool front, const std::string& sn, const std::string& license, const std::string& imageFile);
|
||||||
|
};
|
||||||
|
} // zsy
|
||||||
|
|
||||||
|
#endif //RECOGNIZE_PROCESSOR_H
|
|
@ -1,5 +1,6 @@
|
||||||
#include "barrier_vidicon.h"
|
#include "barrier_vidicon.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
#include "common/date_util.h"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
#include "common/sys_util.h"
|
#include "common/sys_util.h"
|
||||||
#include "common/snowflake.h"
|
#include "common/snowflake.h"
|
||||||
|
@ -75,20 +76,12 @@ namespace zsy
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static long long getTime()
|
|
||||||
{
|
|
||||||
const auto now = std::chrono::system_clock::now();
|
|
||||||
const auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
|
|
||||||
const auto epoch = now_ms.time_since_epoch();
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(epoch).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BarrierVidicon::photograph()
|
std::string BarrierVidicon::photograph()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOGGER_INFO("摄像机正在拍照,设备名称:{}", config.name);
|
LOGGER_INFO("摄像机正在拍照,设备名称:{}", config.name);
|
||||||
const long timestamp = static_cast<long>(getTime());
|
const long timestamp = static_cast<long>(DateUtil::timestamp()/1000);
|
||||||
nlohmann::json j{
|
nlohmann::json j{
|
||||||
{"id", "photograph" + std::to_string(timestamp)},
|
{"id", "photograph" + std::to_string(timestamp)},
|
||||||
{"sn", config.ip},
|
{"sn", config.ip},
|
||||||
|
|
Loading…
Reference in New Issue