#include "stdafx.h" #include "SmartEvaluationLogicDLL.h" #include "SmartEvaluationService.h" #include #include "ServerConfig.h" #include "IdentifyEngine.h" #include "ImgUploadManager.h" #include "BatchManager.h" #include "Bantch.h" //#include "Log4cplusInitalizer.h" #include "..\Identifier\CrossDetector.h" #include "DnowLoadImg.h" #include "CMyHttpClient.h" #include #include #include #include extern int g_my_scan_type; extern int g_my_continue_scan; //督学卡学校id extern std::string g_strShoolId; extern int g_myindex; extern bool g_isAllSubject;//是否是全学科 /*全局设置相关*/ SMARTEVALUATIONLOGIC_API int SetCookie(std::string path, std::string name, std::string value) { return CIdentifyEngine::GetInstance()->SetCookie(path, name, value); } SMARTEVALUATIONLOGIC_API int SetLocalServerCookie(std::string name, std::string value) { return CIdentifyEngine::GetInstance()->SetLocalServerCookie(name, value); } SMARTEVALUATIONLOGIC_API int SetServerUrl(std::string server_url) { return CIdentifyEngine::GetInstance()->SetServerUrl(server_url); } SMARTEVALUATIONLOGIC_API int InitalizeScan(bool bOnlineCard, int subjectid, int nOnlineScanType) { CBatchManager::Get()->initalize(bOnlineCard, subjectid, nOnlineScanType); return TRUE; } SMARTEVALUATIONLOGIC_API int SetScanConfig(std::string app_data_dir, std::string scan_data_dir) { return CIdentifyEngine::GetInstance()->SetScanConfig(app_data_dir, scan_data_dir); } /*扫描仪相关*/ int GetScannerList(vector & scannerList) { return CSeparateThreadTwainFeeder::Get()->GetScannerList(scannerList); } int GetDefaultScannerInfo(SCANNER_INFO &scannerInfo) { return CSeparateThreadTwainFeeder::Get()->GetDefaultScannerInfo(scannerInfo); } int ConnectScanner(const int nIndex) { return CSeparateThreadTwainFeeder::Get()->ConnectScanner(nIndex); } int ShowScannerSetting(const unsigned int nId) { return CSeparateThreadTwainFeeder::Get()->ShowScannerSetting(nId); } SMARTEVALUATIONLOGIC_API int DisconnectScanner() { return CSeparateThreadTwainFeeder::Get()->DisconnectScanner(); } /*图片上传相关*/ int SetHandlerWndForImg(HWND hwnd){ return CImgUploadManager::GetInstance()->SetHandlerWndForImg(hwnd); } SMARTEVALUATIONLOGIC_API int StartUploadePaperImg() { // Log4cplusInitalizer::initalize(); return CImgUploadManager::GetInstance()->StartUploadePaperImg(); } SMARTEVALUATIONLOGIC_API int QueryUploadePaperImg(vector& tasks) { return CImgUploadManager::GetInstance()->QueryUploadePaperImg(tasks); } SMARTEVALUATIONLOGIC_API int ClearUploadedPaperImg() { return CImgUploadManager::GetInstance()->ClearUploadedPaperImg(); } SMARTEVALUATIONLOGIC_API int GetCurrentUploadTaskInfo(IMG_UPLOAD_TASK& task) { return CImgUploadManager::GetInstance()->GetCurrentUploadTaskInfo(task); } SMARTEVALUATIONLOGIC_API int StopUploadePaperImg() { return CImgUploadManager::GetInstance()->StopUploadePaperImg(); } /*扫描相关*/ SMARTEVALUATIONLOGIC_API int ReadyScanEX(FEEDER_TYPE feederType, const ScanParam & param) { if (g_my_scan_type == 0) setRunFlag(_T("1")); else setRunFlag(_T("0")); if (g_my_scan_type == 0) setRunUploadFlag(_T("1")); else setRunUploadFlag(_T("0")); return CBatchManager::Get()->GetCurrentBatch()->ReadyScanEX(feederType, param); } bool DeleteDirectory(CString sDirName); int Start(){ g_myindex = 1; return CBatchManager::Get()->GetCurrentBatch()->OnBnClickedButtonStartScan(); } int Pause() { return CBatchManager::Get()->GetCurrentBatch()->Pause(); } int Resume() { return CBatchManager::Get()->GetCurrentBatch()->Resume(); } int Stop() { g_myindex = MAX_STRUENTS_NUM; return CBatchManager::Get()->GetCurrentBatch()->Stop(); } int SetHandlerWnd(HWND hwnd) { boost::shared_ptr batch = CBatchManager::Get()->createNewBatch(); return CBatchManager::Get()->GetCurrentBatch()->SetHandlerWnd(hwnd); } static std::string getTimeStamp() { auto tp = std::chrono::time_point_cast(std::chrono::system_clock::now()); auto tmp = std::chrono::duration_cast(tp.time_since_epoch()); std::time_t timestamp = tmp.count(); return std::move(std::to_string(timestamp)); } bool DeleteDirectory(CString sDirName); SMARTEVALUATIONLOGIC_API int ReIdentify(const int paper_id, const std::string& stu_code, std::vector params) { std::string img_path = CServerConfig::app_data_dir_string + "\\ErrorHandleImgTmp\\"; // if (_access(img_path.c_str(), 0) == 0){ // DeleteDirectory(_T("D:\\ErrorHandleImgTmp")); // } if (_access(img_path.c_str(), 0) != 0){ CreateDirectoryA(img_path.c_str(), NULL); } for (auto& it : params){ std::string new_path = img_path + getTimeStamp() + ".jpg"; CopyFileA(it.img_path, new_path.c_str(), false); strcpy(it.img_path, new_path.c_str()); // printf("重新扫描老路径:%s\n", it.img_path); // printf("重新扫描新路径:%s\n", new_path.c_str()); Sleep(300); } return CBatchManager::Get()->GetCurrentBatch()->ReIdentify(paper_id, stu_code, params); } SMARTEVALUATIONLOGIC_API int QueryExceptionPaper(const long exception_type, vector &studengList) { return CBatchManager::Get()->GetCurrentBatch()->QueryExceptionPaper(exception_type, studengList); } SMARTEVALUATIONLOGIC_API int QueryPaperDetail(const int paper_id, PAPER_DETAIL &paper_detail, vector &pageList, vector &questionList) { return CBatchManager::Get()->GetCurrentBatch()->QueryPaperDetail(paper_id, paper_detail, pageList, questionList); } SMARTEVALUATIONLOGIC_API int UpdatePaperStudent(const int paper_id, const std::string examinee_id, const std::string student_code, const std::string studentName, const long schoolId, const std::string stuCode, const std::string stuSchoolCode, const std::string className, const std::string gradeName, bool bReIdentify /*= false*/) { return CBatchManager::Get()->GetCurrentBatch()->UpdatePaperStudent(paper_id, examinee_id, student_code, studentName, schoolId, stuCode, stuSchoolCode, className, gradeName, bReIdentify); } int IgnorePaper(const int paper_id) { return CBatchManager::Get()->GetCurrentBatch()->IgnorePaper(paper_id); } int ReplacePaper(const int paper_id, int &paper_id_ret) { return CBatchManager::Get()->GetCurrentBatch()->ReplacePaper(paper_id, paper_id_ret); } int ReplaceAllKaoHaoChongTu(vector &paper_id_List) { return CBatchManager::Get()->GetCurrentBatch()->ReplaceAllKaoHaoChongTu(paper_id_List); } int IgnoreException(const long exceptions) { return CBatchManager::Get()->GetCurrentBatch()->IgnoreException(exceptions); } SMARTEVALUATIONLOGIC_API int StartUploadPaper(HWND hWnd) { return CBatchManager::Get()->GetCurrentBatch()->StartUploadPaper(hWnd); } SMARTEVALUATIONLOGIC_API int ClearDbTemp() { return CBatchManager::Get()->GetCurrentBatch()->ClearDbTemp(); } SMARTEVALUATIONLOGIC_API int GiveUpCurrentBatch() { return CBatchManager::Get()->GiveUpCurrentBatch(); } SMARTEVALUATIONLOGIC_API int SetFolderScanDir(const std::string img_dir) { return CBatchManager::Get()->GetCurrentBatch()->SetFolderScanDir(img_dir); } SMARTEVALUATIONLOGIC_API int QueryExptionPaperCount(int & exc_count, int & total_count) { return CBatchManager::Get()->GetCurrentBatch()->QueryExptionPaperCount(exc_count,total_count); } SMARTEVALUATIONLOGIC_API int QueryExptionTypeInfo(vector & infos) { return CBatchManager::Get()->GetCurrentBatch()->QueryExptionTypeInfo(infos); } SMARTEVALUATIONLOGIC_API string GetBatchCode() { return CBatchManager::Get()->GetCurrentBatch()->GetBatchCode(); } SMARTEVALUATIONLOGIC_API int LoadSchema(long long examId, std::string examName, long examCourseId, std::string courseName, const std::string schemaPath, std::string rule/* = ""*/) { return CBatchManager::Get()->GetCurrentBatch()->LoadSchema(examId, examName, examCourseId, courseName, schemaPath,rule); } SMARTEVALUATIONLOGIC_API int QueryNormalPaper(vector &studengList) { return CBatchManager::Get()->GetCurrentBatch()->QueryNormalPaper(studengList); } SMARTEVALUATIONLOGIC_API int QueryMubanImgPath(int page_index, std::string& imgPath) { return CBatchManager::Get()->GetCurrentBatch()->QueryMubanImgPath(page_index, imgPath); } SMARTEVALUATIONLOGIC_API int GetServiceSate() { return CBatchManager::Get()->GetCurrentBatch()->GetServiceSate(); } SMARTEVALUATIONLOGIC_API int QueryMubanImgCount(int& page_count) { return CBatchManager::Get()->GetCurrentBatch()->QueryMubanImgCount(page_count); } SMARTEVALUATIONLOGIC_API int DetectCross(const IplImage * img, int detect_x, int detect_y, int detect_w, int detect_h, std::vector& crosss) { IplImage t; cvInitImageHeader(&t, cvSize(img->width, img->height), img->depth, img->nChannels, img->origin, img->align); cvSetData(&t, img->imageData, img->widthStep); IplImage * img_ = &t; int left0 = detect_x; int top0 = detect_y; int right0 = detect_x + detect_w - 1; int bottom0 = detect_y + detect_h - 1; int left = max(left0 - 20, 0); int top = max(top0 - 20, 0); int right = min(right0 + 20, img_->width - 1); int bottom = min(bottom0 + 20, img_->height - 1); CvRect roi = cvRect(left, top, right - left + 1, bottom-top+1); cvSetImageROI(img_, roi); CCrossDetector detector; std::vector cross_; detector.Detect(img_, cross_); for (int i = 0; i < cross_.size();i++) { if (cross_[i].x >= left0&&cross_[i].x <= right0&&cross_[i].y >= top0&&cross_[i].y <= bottom0){ Cross c; c.x = cross_[i].x; c.y = cross_[i].y; c.signal = cross_[i].sign; c.angle = cross_[i].arg; crosss.push_back(c); } } return 0; } SMARTEVALUATIONLOGIC_API int leaveCurrentBatch() { return CBatchManager::Get()->leaveCurrentBatch(); } SMARTEVALUATIONLOGIC_API int AiReadImgPaper(const int subject, int id, std::vector aiVec, const vector imgPath, vector> &retList) { std::vector path; for (int i = 0; i < imgPath.size(); i++) { path.push_back((CString)imgPath[i].c_str()); } return CImgUploadManager::GetInstance()->AiReadImgPaper(subject, id, aiVec, path, retList); } SMARTEVALUATIONLOGIC_API int SetScanInspector(int ntype, std::string strShoolID) { g_my_scan_type = ntype; g_strShoolId = strShoolID; g_myindex = 1; return 0; } SMARTEVALUATIONLOGIC_API int DownLoadImg(HWND hWnd, std::string strExamId, int type) { int flag = 0; CDnowLoadImg::GetInstance()->SetHandlerWnd(hWnd); CDnowLoadImg::GetInstance()->SetExamId(strExamId); CDnowLoadImg::GetInstance()->SetType(type); CDnowLoadImg::GetInstance()->Start(); return flag; } SMARTEVALUATIONLOGIC_API int HttpDownloadTemplate(std::string from, std::string fileName) { int len; int slength = (int)from.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, from.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, from.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; std::vector data; CMyHttpClient::GetInstance()->HttpDownload(r.c_str(), NULL, data); slength = (int)fileName.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, fileName.c_str(), slength, 0, 0); wchar_t* buf2 = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, fileName.c_str(), slength, buf2, len); std::wstring r2(buf2); CFile file; if (file.Open(r2.c_str(), CFile::modeCreate | CFile::modeWrite)) { file.Write(data.data(), data.size()); file.Close(); delete[] buf2; return data.size(); } file.Close(); delete[] buf2; return 0; } SMARTEVALUATIONLOGIC_API int CloseContineScan() { g_my_continue_scan = 0; setRunFlag(_T("0")); setRunUploadFlag(_T("0")); return 0; } SMARTEVALUATIONLOGIC_API int StartContiuneScan() { g_my_continue_scan = 1; return 0; } SMARTEVALUATIONLOGIC_API void getCurScanExam(std::string exam_code, std::vector> &stuInfo) { CBatchManager::Get()->GetCurrentBatch()->getCurScanExam(exam_code, stuInfo); } SMARTEVALUATIONLOGIC_API void getCoverStuInfoByExamCode(std::string examCode, std::vector &stuInfo) { CBatchManager::Get()->GetCurrentBatch()->getCoverStuInfoByExamCode(examCode, stuInfo); } #include "excel/ExcelFormat.h" using namespace ExcelFormat; SMARTEVALUATIONLOGIC_API void writeToexcel(std::string path, std::vector> &stuInfo, std::vector &stuInfo2, bool flag1, bool flag2, bool flag3) { BasicExcel xls; try { xls.New(1); XLSFormatManager fmt_mgr(xls); //CellFormat fmt(fmt_mgr); CellFormat format(fmt_mgr); format.set_format_string(XLS_FORMAT_INTEGER); if (xls.GetTotalWorkSheets() > 0) { int j = 0; BasicExcelWorksheet* sheet = xls.GetWorksheet(j); if (sheet) { if (flag1) { sheet->SetColWidth(2, 5000); sheet->SetColWidth(3, 5000); sheet->Rename(_T("未上传学生名单")); BasicExcelCell* cell = sheet->Cell(0, 0); cell->Set(_T("序号")); cell = sheet->Cell(0, 1); cell->Set(_T("学生姓名")); cell = sheet->Cell(0, 2); cell->Set(_T("系统准考证号")); cell = sheet->Cell(0, 3); cell->Set(_T("学校准考证号")); cell = sheet->Cell(0, 4); cell->Set(_T("班级")); cell = sheet->Cell(0, 5); cell->Set(_T("年级")); cell = sheet->Cell(0, 6); cell->Set(_T("状态")); std::vector info; if (stuInfo.size() > 0) info = stuInfo[0]; for (int i = 0; i < info.size(); i++) { BasicExcelCell* cell = sheet->Cell(i + 1, 0); CString strNO; strNO.Format(_T("%d"), i + 1); cell->Set(strNO); CString stStuName(info[i].stu_name.data()); cell = sheet->Cell(i + 1, 1); cell->Set(stStuName); CString stStuCode1(info[i].stu_code1.data()); cell = sheet->Cell(i + 1, 2); cell->Set(stStuCode1); CString stStuCode2(info[i].stu_code2.data()); cell = sheet->Cell(i + 1, 3); cell->Set(stStuCode2); CString stStuClass(info[i].stu_class.data()); cell = sheet->Cell(i + 1, 4); cell->Set(stStuClass); CString stStuGrade(info[i].stu_grade.data()); cell = sheet->Cell(i + 1, 5); cell->Set(stStuGrade); cell = sheet->Cell(i + 1, 6); cell->Set(_T("未上传")); // cell->SetFormat(format); } //writeTosheetMy(sheet,examID*2,0); j++; } if (flag2) { sheet = xls.AddWorksheet(j); if (sheet) { sheet->SetColWidth(2, 5000); sheet->SetColWidth(3, 5000); sheet->Rename(_T("标记缺考学生名单")); BasicExcelCell* cell = sheet->Cell(0, 0); cell->Set(_T("序号")); cell = sheet->Cell(0, 1); cell->Set(_T("学生姓名")); cell = sheet->Cell(0, 2); cell->Set(_T("系统准考证号")); cell = sheet->Cell(0, 3); cell->Set(_T("学校准考证号")); cell = sheet->Cell(0, 4); cell->Set(_T("班级")); cell = sheet->Cell(0, 5); cell->Set(_T("年级")); cell = sheet->Cell(0, 6); cell->Set(_T("状态")); std::vector info; if (stuInfo.size() > 1) info = stuInfo[1]; for (int i = 0; i < info.size(); i++) { BasicExcelCell* cell = sheet->Cell(i + 1, 0); CString strNO; strNO.Format(_T("%d"), i + 1); cell->Set(strNO); CString stStuName(info[i].stu_name.data()); cell = sheet->Cell(i + 1, 1); cell->Set(stStuName); CString stStuCode1(info[i].stu_code1.data()); cell = sheet->Cell(i + 1, 2); cell->Set(stStuCode1); CString stStuCode2(info[i].stu_code2.data()); cell = sheet->Cell(i + 1, 3); cell->Set(stStuCode2); CString stStuClass(info[i].stu_class.data()); cell = sheet->Cell(i + 1, 4); cell->Set(stStuClass); CString stStuGrade(info[i].stu_grade.data()); cell = sheet->Cell(i + 1, 5); cell->Set(stStuGrade); cell = sheet->Cell(i + 1, 6); cell->Set(_T("缺考")); } //writeTosheetMy(sheet,examID*2,0); j++; } } if (flag3) { sheet = xls.AddWorksheet(j); if (sheet) { sheet->SetColWidth(2, 5000); sheet->SetColWidth(3, 5000); sheet->Rename(_T("覆盖学生名单")); BasicExcelCell* cell = sheet->Cell(0, 0); cell->Set(_T("序号")); cell = sheet->Cell(0, 1); cell->Set(_T("学生姓名")); cell = sheet->Cell(0, 2); cell->Set(_T("系统准考证号")); cell = sheet->Cell(0, 3); cell->Set(_T("学校准考证号")); cell = sheet->Cell(0, 4); cell->Set(_T("班级")); cell = sheet->Cell(0, 5); cell->Set(_T("年级")); cell = sheet->Cell(0, 6); cell->Set(_T("状态")); std::vector info; info = stuInfo2; for (int i = 0; i < info.size(); i++) { BasicExcelCell* cell = sheet->Cell(i + 1, 0); CString strNO; strNO.Format(_T("%d"), i + 1); cell->Set(strNO); CString stStuName(info[i].stu_name.data()); cell = sheet->Cell(i + 1, 1); cell->Set(stStuName); CString stStuCode1(info[i].stu_code1.data()); cell = sheet->Cell(i + 1, 2); cell->Set(stStuCode1); CString stStuCode2(info[i].stu_code2.data()); cell = sheet->Cell(i + 1, 3); cell->Set(stStuCode2); CString stStuClass(info[i].stu_class.data()); cell = sheet->Cell(i + 1, 4); cell->Set(stStuClass); CString stStuGrade(info[i].stu_grade.data()); cell = sheet->Cell(i + 1, 5); cell->Set(stStuGrade); cell = sheet->Cell(i + 1, 6); cell->Set(_T("覆盖")); } //writeTosheetMy(sheet,examID*2,0); j++; } } wstring result; int len = MultiByteToWideChar(CP_ACP, 0, path.c_str(), path.size(), NULL, 0); TCHAR* buffer = new TCHAR[len + 1]; //多字节编码转换成宽字节编码 MultiByteToWideChar(CP_ACP, 0, path.c_str(), path.size(), buffer, len); buffer[len] = '\0'; //添加字符串结尾 result.append(buffer); xls.SaveAs(result.c_str()); delete[] buffer; } } } catch (...) { } } #include "../lib/ucloud/include/api.h" #ifdef _DEBUG #pragma comment(lib,"..\\lib\\ucloud\\debug\\UCloudSDK.lib") #else #pragma comment(lib,"..\\lib\\ucloud\\Release\\UCloudSDK.lib") #endif std::string UnicodeToAnsi(const CString& str) { std::string ret; int nLen = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL); if (nLen == 0){ return ret; } char* pResult = new char[nLen]; WideCharToMultiByte(CP_ACP, 0, str, -1, pResult, nLen, NULL, NULL); ret = pResult; delete[] pResult; return ret; } CString AnsiToUnicode(const std::string& str) { CString strRet; int nLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), -1, NULL, 0); if (nLen == 0){ return strRet; } wchar_t* pResult = new wchar_t[nLen]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), -1, pResult, nLen); strRet = pResult; delete[]pResult; return strRet; } void RecursiveDirectory(CString cstrDir) // 递归创建目录 { if (cstrDir.GetLength() <= 3)//是根目录,无需创建目录 { return; } if (cstrDir[cstrDir.GetLength() - 1] == '\\') // 将路径改为目录 { cstrDir.Delete(cstrDir.GetLength() - 1, 1); } // 修改文件属性 WIN32_FIND_DATA wfd; HANDLE hFind = FindFirstFile(cstrDir, &wfd); // 查找 if (hFind != INVALID_HANDLE_VALUE) { FindClose(hFind); if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) return; } // 创建当前目录的地目录失败 if (CreateDirectory(cstrDir, NULL) == false) {// 退到上一级目录 CString wstrNewDir = cstrDir; int n = wstrNewDir.ReverseFind('\\'); wstrNewDir = cstrDir.Left(n); // 递归进入 RecursiveDirectory(wstrNewDir); // 递归本函数,再创建目录 // 递归退出后创建之前失败的目录 CreateDirectory(cstrDir, NULL); // 递归返回,在存在的目录上再建目录 }// 多级目录创建成功 } bool InitCloud(const char*path) { char FilePath[MAX_PATH] = { 0 }; GetModuleFileNameA(NULL, FilePath, MAX_PATH); strchr(FilePath, '\\')[1] = 0; strcat(FilePath, "config.ini"); char public_key[128] = { 0 }; GetPrivateProfileStringA("UCLOUD", "public_key", "ucloudyunkaopei@outlook.com13615403931104805307", public_key, sizeof(public_key) / sizeof(char), FilePath); char private_key[128] = { 0 }; GetPrivateProfileStringA("UCLOUD", "private_key", "bcfd5bb66ca527c9be9fd7f3e784fbfc90c4bba5", private_key, sizeof(private_key) / sizeof(char), FilePath); char bucket_host[128] = { 0 }; GetPrivateProfileStringA("UCLOUD", "bucket_host", "api.ucloud.cn", bucket_host, sizeof(bucket_host) / sizeof(char), FilePath); char file_host[128] = { 0 }; GetPrivateProfileStringA("UCLOUD", "file_host", "cn-bj.ufileos.com", file_host, sizeof(file_host) / sizeof(char), FilePath); ufile_config cfg; cfg.public_key = public_key; cfg.private_key = private_key; cfg.bucket_host = bucket_host; cfg.file_host = file_host; ufile_error error; error = ufile_sdk_initialize(cfg, 0); if (UFILE_HAS_ERROR(error.code)){ return false; } std::string img_path = CServerConfig::app_data_dir_string + "\\exception_tmp\\"; if (_access(img_path.c_str(), 0) == 0){ DeleteDirectory(CServerConfig::app_data_dir + _T("\\exception_tmp")); } img_path = CServerConfig::app_data_dir_string + "\\temp_ucloud_path\\"; if (_access(img_path.c_str(), 0) == 0){ DeleteDirectory(CServerConfig::app_data_dir + _T("\\temp_ucloud_path")); } CreateDirectory(CServerConfig::app_data_dir + _T("\\temp_ucloud_path\\"), NULL); CreateDirectory(CServerConfig::app_data_dir + _T("\\exception_tmp\\"), NULL); RecursiveDirectory(AnsiToUnicode(path)); return true; } #include "../ZLibWrapLib/ZLibWrapLib.h" #include #include #include #include std::thread thread_get_paper_from_cloud; std::thread thread_error_handle_restore_site; std::mutex _mtx_queue; std::queue > _work_queue; std::atomic _thread_exit; std::condition_variable _cn_thread; int g_nTotal = 0; int g_nCurProcess = 0; void ReportDowndProcess(int nTotal, int nCurProcess); static bool readFile(string & file, string & str) { ifstream in; string line; in.open(file, ifstream::in); if (!in.is_open()) return false; while (getline(in, line)) { str.append(line + "\n"); } in.close(); return true; } ISmartLogicNotify*g_pNotify = NULL; void error_handle_restore_site() { while (!_thread_exit){ std::queue > _que_w; { std::unique_lock _lock(_mtx_queue); _cn_thread.wait(_lock, [](){ return !_work_queue.empty(); }); _que_w = _work_queue; _work_queue = std::queue >(); } if (!_que_w.empty() && !_thread_exit){ while (!_que_w.empty()){ auto it = _que_w.front(); _que_w.pop(); std::string id = std::get<0>(it); std::string type = std::get<1>(it); std::string path = std::get<2>(it); if (!path.empty()) CBatchManager::Get()->GetCurrentBatch()->RestoreErrorHandleSite(id,type,path); g_nCurProcess++; if (g_nCurProcess >= g_nTotal){ if (g_pNotify){ g_pNotify->OnNotify(LOAD_CLOUD_FILE_END, "云端下载结束"); } } else{ if (g_pNotify){ std::string tip_msg = std::string("正在下载: ") + std::to_string(g_nCurProcess) + "/" + std::to_string(g_nTotal); g_pNotify->OnNotify(LOAD_ERROR_LIST_BEGIN, tip_msg.c_str()); } } } } } } void RestoreErrorHandleSite(const std::string& task_id, const std::string&type, const std::string& strPath) { std::lock_guard _lock(_mtx_queue); _work_queue.push(std::make_tuple(task_id, type, strPath)); _cn_thread.notify_all(); } #include "..\EvaluationUtil\HttpClient.h" struct error_info{ std::string task_id; std::string task_type; std::string cloud_key; }; void get_paper_from_cloud(const std::string&strUrl, const std::string&session,const std::string&exam_id, const std::string&destDir, ISmartLogicNotify*pNotify) { RecursiveDirectory(AnsiToUnicode(destDir + "\\Download\\")); // 获取异常列表 std::vector _vctErrorList; if (pNotify){ g_pNotify = pNotify; pNotify->OnNotify(LOAD_ERROR_LIST_BEGIN, "开始获取异常列表"); } std::string response; CString postData; postData.Format(_T("examGroupId=%s"), AnsiToUnicode(exam_id)); CHttpClient httpClient; httpClient.SetSendHeader(AnsiToUnicode(session)); httpClient.HttpPost(AnsiToUnicode(strUrl), postData, response); //printf("get_paper_from_cloud url %s \n", strUrl.c_str()); //printf("get_paper_from_cloud: post_data %s \n",UnicodeToAnsi(postData).c_str()); //printf("get_paper_from_cloud rst= %s \n", response.c_str()); if (!response.empty()){ Json::Features features; Json::Reader re(features); Json::Value root; re.parse(response, root); if (root["success"].asInt() == 1){ Json::Value data = root["data"]; Json::Value name = data["examName"]; if (pNotify){ pNotify->OnNotify(LOAD_ERROR_EXAM_NAME, name.asString().c_str()); } if (data.isObject()){ Json::Value list = data["list"]; g_nTotal = list.size(); for (int i = 0; i < g_nTotal; i++) { Json::Value row = list[i]; error_info info; std::string task_id = row["task_id"].asString(); std::string cloud_key = row["data"].asString(); std::string task_type = row["task_type"].asString(); info.task_id = task_id; info.cloud_key = cloud_key; info.task_type = task_type; _vctErrorList.push_back(info); if (i == 0){ if (pNotify){ pNotify->OnNotify(LOAD_PAPER_TYPE, info.task_type.c_str()); } } } } } else{ if (pNotify){ pNotify->OnNotify(LOAD_ERROR_FAILED, root["message"].asString().c_str()); } } } if (pNotify){ pNotify->OnNotify(LOAD_ERROR_LIST_END, "获取异常列表结束"); } // 从云端下载文件 if (pNotify){ std::string tip_msg = std::string("正在下载: ") + std::to_string(g_nCurProcess) + "/" + std::to_string(g_nTotal); pNotify->OnNotify(LOAD_CLOUD_FILE_BEGIN, tip_msg.c_str()); } int i = 0; if (_vctErrorList.empty()){ if (pNotify){ pNotify->OnNotify(LOAD_CLOUD_FILE_END, "云端异常没有异常"); } } else{ TCHAR exeFullPath[MAX_PATH]; CString strPath; int nSubjectId; GetModuleFileName(NULL, exeFullPath, MAX_PATH); strPath = (CString)exeFullPath; int position = strPath.ReverseFind('\\'); strPath = strPath.Left(position + 1); TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("config.ini")); WCHAR szbucket_name[512]; GetPrivateProfileString(_T("GLOBAL"), _T("bucket_name"), _T("zxhx-test"), szbucket_name, 512, FilePath); std::string bucket_name = UnicodeToAnsi(szbucket_name); for (auto it : _vctErrorList){ std::string cloud_key = it.cloud_key; cloud_key = cloud_key.substr(1, cloud_key.size() - 2); ++i; std::string dst_path = destDir + std::to_string(i) + ".zip"; // 下载文件。 FILE *fpDown = fopen(dst_path.c_str(), "wb"); if (fpDown){ auto error = ufile_download(bucket_name.c_str(), cloud_key.c_str(), fpDown, NULL); if UFILE_HAS_ERROR(error.code){ } else{ fclose(fpDown); std::string ex_path = destDir + "Download\\" + std::to_string(i) + "\\"; ZipExtract(AnsiToUnicode(dst_path), AnsiToUnicode(ex_path)); if (pNotify){ // pNotify->OnNotify(LOAD_CLOUD_FILE, ex_path.c_str()); } RestoreErrorHandleSite(it.task_id, it.task_type, ex_path); } } } } } bool ExitCloud() { ufile_sdk_cleanup(); return true; } class ThreadGuard{ public: void set(std::thread &t){ _t = std::move(t); } ~ThreadGuard(){ if (_t.joinable()) _t.join(); } private: std::thread _t; }; ThreadGuard _t_guard; void exit_thread_error_handle_restore_site() { if (thread_error_handle_restore_site.joinable()){ { _thread_exit = true; std::lock_guard _lock(_mtx_queue); _work_queue.push(std::tuple()); _cn_thread.notify_all(); } thread_error_handle_restore_site.join(); } } void ReportDowndProcess(int nTotal, int nCurProcess) { CWnd *pWnd = CWnd::FindWindow(NULL, _T("知心慧学学管系统")); if (pWnd == NULL){ return; } //发送消息 MY_DB_INFO fff; fff.nmode = 2; fff.total_error = nTotal; fff.cur_process_error = nCurProcess; COPYDATASTRUCT cpd; // 给COPYDATASTRUCT结构赋值 cpd.dwData = 0; cpd.cbData = sizeof(MY_DB_INFO); cpd.lpData = (&fff); int ret = pWnd->SendMessage(WM_COPYDATA, NULL, (LPARAM)&cpd); // 发送 } int PreErrorHandleRestoreSite(bool bcontinue, int scan_type, const ScanParam&scanparam) { CBatchManager::Get()->GetCurrentBatch()->PreErrorHandleRestoreSite(bcontinue,scan_type, FEEDER_TYPE::Folder, scanparam); return 0; } void SetErrorHandle(bool bErrorHandle) { CBatchManager::Get()->GetCurrentBatch()->SetErrorHandle(bErrorHandle); } int ParseErrorPaperFromCloud(const std::string&strUrl, const std::string&session, const std::string&exam_id, const std::string&destDir, ISmartLogicNotify*pNotify /*= NULL*/) { g_nTotal = 0; g_nCurProcess = 0; exit_thread_error_handle_restore_site(); thread_error_handle_restore_site = std::thread(error_handle_restore_site); if (thread_get_paper_from_cloud.joinable()) { thread_get_paper_from_cloud.join(); } thread_get_paper_from_cloud = std::thread(get_paper_from_cloud, strUrl, session, exam_id,destDir, pNotify); _t_guard.set(thread_get_paper_from_cloud); return 0; } #if _DEBUG #pragma comment(lib,"../Win32/Debug/client_interactive_api_d.lib") #else #pragma comment(lib,"../Win32/Release/client_interactive_api.lib") #endif __declspec(dllimport) int api_init(); __declspec(dllimport) void api_free(); SMARTEVALUATIONLOGIC_API int InitIdentiferDllAlgorithm() { int ret = api_init(); LOGFMTI("api_init ret = %d", ret); return ret; } SMARTEVALUATIONLOGIC_API void FreeIdentiferDllAlgorithm() { api_free(); } void InitUploadManager(bool bEanble, bool bCountiue, bool bErrorHanle, bool bOnlineCard, IUploudNotify*pNotify) { CBatchManager::Get()->GetCurrentBatch()->InitUploadManager(bEanble, bCountiue,bErrorHanle, bOnlineCard,pNotify); } void OnScanListFilter(bool bsuccess, int nUploadState) { CBatchManager::Get()->GetCurrentBatch()->OnScanListFilter(bsuccess, nUploadState); } int UploadOnScanCmd(int nCmd, const char*param, void*ret /*= nullptr*/) { if (CBatchManager::Get() && CBatchManager::Get()->GetCurrentBatch()){ return CBatchManager::Get()->GetCurrentBatch()->UploadOnScanCmd(nCmd, param, ret); } return -1; } void QuickHandle(bool bGetPath, char*path_nor, int nor_len, char*path_exc, int exc_len) { CBatchManager::Get()->GetCurrentBatch()->QuickHandle(bGetPath, path_nor, nor_len, path_exc, exc_len); } int BatchServiceCmd(int cmd, void*param, void*ret) { if (cmd == BS_CMD_DEL_REDIFY_TMP_IMG) { std::string img_path = CServerConfig::app_data_dir_string + "\\ErrorHandleImgTmp\\"; if (_access(img_path.c_str(), 0) == 0){ DeleteDirectory(CServerConfig::app_data_dir + _T("\\ErrorHandleImgTmp")); } return 0; } int nRet = -1; if (CBatchManager::Get() && CBatchManager::Get()->GetCurrentBatch()){ nRet = CBatchManager::Get()->GetCurrentBatch()->BatchServiceCmd(cmd, param, ret); } return nRet; } void SetExamName(const wchar_t * name) { TCHAR pathFile[MAX_PATH]; GetModuleFileName(NULL, pathFile, MAX_PATH); (_tcsrchr(pathFile, '\\'))[1] = 0; _tcscat(pathFile, L"config.ini"); WritePrivateProfileString(L"THIRD", L"exam_name", name, pathFile); } SMARTEVALUATIONLOGIC_API vector GetAllConfictPaper(int student_paper_id, string student_id) { return CBatchManager::Get()->GetCurrentBatch()->GetAllConfictPaper(student_paper_id, student_id); } SMARTEVALUATIONLOGIC_API int ExamineThisScan(PAPER_DETAIL& paper_detail) { return CBatchManager::Get()->GetCurrentBatch()->ExamineThisScan(paper_detail); } SMARTEVALUATIONLOGIC_API int SetAbsentExam(PAPER_DETAIL& paper_detail, int absent) { return CBatchManager::Get()->GetCurrentBatch()->SetAbsentExam(paper_detail, absent); } SMARTEVALUATIONLOGIC_API int QueryKeGuanTiYiChang(const int paper_id, std::vector& keguantiList) { return CBatchManager::Get()->GetCurrentBatch()->QueryKeGuanTiYiChang(paper_id, keguantiList); } SMARTEVALUATIONLOGIC_API int UpdateKeGuanTiYiChang(const int paper_id, std::vector& keguantiList) { return CBatchManager::Get()->GetCurrentBatch()->UpdateKeGuanTiYiChang(paper_id, keguantiList); } SMARTEVALUATIONLOGIC_API void SetAllSubject(bool all ) { g_isAllSubject = all; }