#include "stdafx.h" #include "BatchInfo.h" #include "Log.h" //#include "qcloud.h" #include "CrashDumper.h" #include #include "ScanDll.h" #include "_dump.h" #include "../Util/typedef_struct.h" CString GetExePath(); CString AnsiToUnicode(const std::string& str); std::string UnicodeToAnsi(const CString& str); CLog g_log; bool CreateDir(char* path); HWND g_MsgWnd = NULL; string g_SchoolId = ""; string g_ServerUrl = ""; string g_Indexdb=""; void ReadConfig() { CString exe_path = GetExePath(); CString _ini_file = exe_path + _T("\\config.ini"); TCHAR sz_buf1[MAX_PATH] = { 0 }; GetPrivateProfileString(_T("USER"), _T("school_id"), _T(""), sz_buf1, sizeof(sz_buf1) / sizeof(TCHAR), _ini_file); g_SchoolId = UnicodeToAnsi(sz_buf1); memset(sz_buf1, 0, MAX_PATH); GetPrivateProfileString(_T("USER"), _T("server_url"), _T(""), sz_buf1, sizeof(sz_buf1) / sizeof(TCHAR), _ini_file); g_ServerUrl = UnicodeToAnsi(sz_buf1); } batch_info GetBatchInfo(int batch_id); SMARTEVALUATIONLOGIC_API bool InitScanDll(HWND hWnd) { _FCDump::StartDump(); g_MsgWnd = hWnd; ReadConfig(); CString exe_path = GetExePath(); string logDir = UnicodeToAnsi(exe_path + _T("\\log\\")); CreateDir((char*)logDir.c_str()); CString time_string; time_string.Format(_T("%s\\log\\exchandle.log"), exe_path); if (!g_log.Init(UnicodeToAnsi(time_string).c_str(), LogLvlInfo)) { return false; } g_Indexdb = UnicodeToAnsi(exe_path + _T("\\index.db3")); return true; } SMARTEVALUATIONLOGIC_API bool StartScan(HWND wnd, int batch_id) { _FCDump::StartDump(); ReadConfig(); g_MsgWnd = wnd; CString exe_path = GetExePath(); string logDir = UnicodeToAnsi(exe_path + _T("\\log\\")); CreateDir((char*)logDir.c_str()); g_Indexdb = UnicodeToAnsi(exe_path + _T("\\index.db3")); CString time_string; SYSTEMTIME systime; GetLocalTime(&systime); time_string.Format(_T("%s\\log\\批次%d_____%4d-%02d-%02d %02d %02d %02d.log"), exe_path, batch_id, systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond); //g_log.Init(UnicodeToAnsi(time_string).c_str(), LogLvlInfo); g_log.Init((logDir+"scan.log").c_str(), LogLvlInfo); CBatch_Server batch_server; batch_server.StartScan(batch_id); return true; } SMARTEVALUATIONLOGIC_API bool ReScan(int batch_id, int paper_id, char* page0, char* page1,string exam_id) { ReadConfig(); CBatch_Server batch_server; batch_server.ReScan(batch_id, paper_id, page0, page1, exam_id); return true; } SMARTEVALUATIONLOGIC_API bool TestDb() { CppSQLite3DB index_db; try { index_db.open("D:/1cutimg/index.db3"); } catch (CException* e) { g_log.PutMsg(LogLvlFailed, "开启index.db3失败 "); return false; } char sql[1200]; int i = 100; while (true) { sprintf_s(sql, 1200, "update batchs set state = %d",i++); index_db.execDML(sql); Sleep(100); } } SMARTEVALUATIONLOGIC_API vector GetFailedBatch() { vector infos; CppSQLite3DB index_db; try { index_db.open(g_Indexdb.c_str()); } catch (CException* e) { g_log.PutMsg(LogLvlFailed, "开启index.db3失败 "); return infos; } CppSQLite3Query query0; query0 = index_db.execQuery("select * from batchs where state > 0"); if (!query0.eof()) { batch_info info; info.id = query0.getIntField("id"); strcpy_s(info.create_time, query0.getStringField("create_time")); strcpy_s(info.batchdb_path, query0.getStringField("batchdb_path")); strcpy_s(info.work_dir, query0.getStringField("work_dir")); info.total_cnt = query0.getIntField("total_cnt"); info.success_cnt = query0.getIntField("success_cnt"); infos.push_back(info); } query0.finalize(); return infos; } SMARTEVALUATIONLOGIC_API bool ReScan(int batch_id, vector paper_ids, string exam_id) { ReadConfig(); return true; } static bool uploading = false; unsigned _stdcall ReUploadThread(void* param) { CppSQLite3DB index_db; try { index_db.open(g_Indexdb.c_str()); } catch (CException* e) { g_log.PutMsg(LogLvlFailed, "ReUploadThread 开启index.db3失败 "); uploading = false; return false; } CppSQLite3Query query0; char sql[256];//upload_type =0 先扫描 后上传 =1 边扫边上传 sprintf_s(sql, "select * from batchs where state & %d > 0 and state != -1", batch_exc_scan_excption); query0 = index_db.execQuery(sql); vector> batchs; while (!query0.eof()) { int batch_id = query0.getInt64Field("id"); string batch_path = query0.getStringField("batchdb_path"); string work_dir = query0.getStringField("work_dir"); batchs.push_back(std::make_tuple(batch_id, batch_path, work_dir)); query0.nextRow(); } query0.finalize(); index_db.close(); for (auto& it : batchs) { CBatch_Server binfo; binfo.m_batch_id = std::to_string(get<0>(it)); binfo.m_batchDbPath = get<1>(it); binfo.m_work_dir = get<2>(it); binfo.ReUploadAllFailed(); ::PostMessage(g_MsgWnd, UM_ULOAD_SUCCESS, atoi(binfo.m_batch_id.c_str()), NULL); } uploading = false; return true; } SMARTEVALUATIONLOGIC_API bool ReUploadAllFailed() { if (!uploading) { uploading = true; HANDLE h_upload = (HANDLE)_beginthreadex(NULL, 0, ReUploadThread, NULL, NULL, NULL); if (h_upload != NULL) { CloseHandle(h_upload); } else { uploading = false; } } return true; } SMARTEVALUATIONLOGIC_API bool ReBatchScan(int batch_id, string exam_id) // 批量识别 { CBatch_Server batch_server; batch_server.ReBatchScan(batch_id, exam_id); return true; }