#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 imageFileStream = std::make_shared(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