123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685 |
- #include "stdafx.h"
- #include "ResultHandler.h"
- #include "basic_struct.h"
- #include "..\ZLibWrapMemLib\MemZipFile.h"
- #include "IdentifyService.h"
- #include "..\ZLibWrapMemLib\UnZipFile.h"
- #include "..\Schema\schema.h"
- #include "OnlineCardIdentifor.h"
- #include <regex>
- #include <thread>
- #include <future>
- #include <set>
- #include "ImgUploadManager.h"
- #include "ServerConfig.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern int g_my_scan_type;
- //督学卡学校id
- extern std::string g_strShoolId;
- extern int g_myindex;
- extern ::string UnicodeToAnsi(const CString& str);
- extern CString AnsiToUnicode(const std::string& str);
- void CResultHandler::SetIdentifor(CIdentifor* identifor)
- {
- m_identifor = identifor;
- }
- CResultHandler::~CResultHandler()
- {
- }
- CResultHandler::CResultHandler()
- {
- m_nOnlineScanType = -1;
- m_bSvePage = false;
- m_bErrorHandle = false;
- m_strQr = "";
- m_bUseQr = false;
- m_hwnd = NULL;
- m_bOnlineCard = false;
- m_bUseQrCode =false;//是否使用二维码
- m_bIdentifyQrCode = false;// 是否识别二维码
- }
- ServiceState CResultHandler::OnRunning(void)
- {
- ServiceState nextState = IService::OnRunning();
- if (nextState == pausing) return nextState;
- if (m_muban_page_count <= 0 && m_identifor->IsMubanLoaded()){
- m_muban_page_count = m_identifor->GetMubanCount();
- m_isMubanLoaded = TRUE;
- }
- if (m_isMubanLoaded == FALSE){
- Sleep(10); return running;
- }
- CIdentifyTask* task = taskManager->getCurrentHandleTask();
- if (task){
- pUnhandledPageInfo = task->getUnhandledPageManager();
- }
- else{
- if (m_bOnlineCard && m_hwnd != NULL && !m_bIdentifyQrCode)
- ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)2, (LPARAM)NULL);
- return stoping;
- }
- UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo;
- int handle_count_limit = (unhandledPageInfo.m_stop&&unhandledPageInfo.unhandled_page_count>0) ? min(m_muban_page_count, unhandledPageInfo.unhandled_page_count) : m_muban_page_count;
- if (unhandledPageInfo.unhandled_page_count >= handle_count_limit){
- if (m_muban_page_count>0){
- SavePaper(handle_count_limit);
- }
- else if (unhandledPageInfo.m_stop){//到停止时 模板还是没有 ,直接清除缓存
- unhandledPageInfo.unhandled_page_count = 0;
- }
- }
- CResultManager * bm = task->getResultBufferManager();
- OMR_RESULT * omr_result = bm->GetResult(TRUE);
- if (!m_handInfo.get()){
- const boost::shared_ptr<const HANDLE_INFO>& handleInfo = identifyService->GetHandleInfo();
- if (handleInfo.get()){
- setHandlInfo(handleInfo);
- }
- }
- if (omr_result == NULL){
- if (unhandledPageInfo.unhandled_page_count <= 0){
- taskManager->doneTask(task);
- }
- else{
- unhandledPageInfo.m_stop = TRUE;
- }
- return running;
- }
- SavePage(omr_result);
- return running;
- }
- ServiceState CResultHandler::OnStarting(void)
- {
- m_bSend = false;
- m_bSvePage = false;
- m_bOnlineCard = false;
- m_bUseQrCode =false;//是否使用二维码
- m_bIdentifyQrCode = false;// 是否识别二维码
- m_muban_page_count = 0;
- scoreCounter.SetDataBase(db_lock, bantch_db);
- scoreCounter.Load();
- loadSchema();
- return running;
- }
- ServiceState CResultHandler::OnStoping(void)
- {
- if (m_bOnlineCard && m_bSvePage){
- OnLineCard::PaperTemplate* pTmp = static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->GetTemplate();
- if (m_hwnd != NULL && !m_bIdentifyQrCode&& !pTmp->useQrCode)
- ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)2, (LPARAM)NULL);
- }
- return IService::OnStoping();
- }
- int CResultHandler::SetHandlerWnd(HWND hwnd)
- {
- m_hwnd = hwnd;
- return 0;
- }
- int CResultHandler::SavePage(OMR_RESULT * omr_result)
- {
- UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo;
- char phy_number[20];
- int len = sprintf_s(phy_number, "%d", omr_result->phy_card_number);
- int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE;
- unhandledPageInfo.unhandled_page_count++;
- UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index];
- unhandled_page.identified = omr_result->identified;
- int page_index = unhandled_page.page_index = omr_result->card_index;
- unhandled_page.omr_result = omr_result;
- unhandled_page.student_code = "";
- if (omr_result->identified){
- if (m_bUseQr){
- if (!m_strQr.empty()){
- std::vector< std::string > _out;
- split(m_strQr, "@", &_out);
- if (_out.size() >= 3){
- unhandled_page.student_code = _out[1];
- unhandled_page.student_id = _out[2];;
- }
- if (!unhandled_page.student_id.empty())return 0;
- }
- }
- bool needRead = true;
- for (int i = 0; needRead&&i < omr_result->qr_result.size(); i++)
- {
- if (omr_result->qr_result[i].qr_str.length()>0){
- unhandled_page.student_code = omr_result->qr_result[i].qr_str;
- needRead = false;
- break;
- }
- }
- const std::vector<TIANTUKAOHAO_RESULT_HANDLE_INFO>& tiantukaohaoHandleInfo = m_handInfoMap[page_index].tiantukaohaoHandleInfo;
- for (int i = 0; needRead&&i<tiantukaohaoHandleInfo.size(); i++)
- {
- std::string student_code;
- bool isRight = true;
- for (int j = 0; j<tiantukaohaoHandleInfo[i].group_index.size(); j++)
- {
- const char * answer = omr_result->group_result[tiantukaohaoHandleInfo[i].group_index[j]].answer.c_str();
- student_code += answer;
- if (answer[0] == '\0')
- {
- break;
- }
- //if (answer[0] == 0){ student_code += "*"; isRight = false; }
- }
- if (student_code.length() < 1)
- {
- student_code += "*"; isRight = false;
- }
- if (student_code.length() > 30)isRight = false;
- if (isRight){
- if (g_my_scan_type == 0)
- {
- unhandled_page.student_code = student_code;
- }
- else
- {
- /*
- if (g_myindex <= 5)
- {
- unhandled_page.student_code = g_strShoolId;
- for (int i = 0; i < student_code.length(); i++)
- {
- unhandled_page.student_code += student_code.at(student_code.length() - 1 - i);
- }
- }
- else
- {
- */
- unhandled_page.student_code = (g_strShoolId + student_code);
- //}
- }
- needRead = false;
- break;
- }
- }
- }
- return 0;
- }
- #include <memory>
- #include <mutex>
- #include <atomic>
- std::mutex mtxTaskNum;
- std::atomic<int> taskNum = 0;
- struct SavePathImgPara{
- std::string path;
- CString pathSave;
- int m;
- SavePathImgPara(std::string path1, CString path2, int n) :path(path1), pathSave(path2), m(n){}
- };
- struct saveImgesPara1{
- vector<CUT_AREA_RESULT*> *area_rst;
- CString path;
- int subjectID;
- bool flag;
- //int ID;
- saveImgesPara1(vector<CUT_AREA_RESULT*> *area_rst1, CString name1, int subjectid, bool flag1) : path(name1), subjectID(subjectid), flag(flag1)
- {
- area_rst = area_rst1;
- //ID = id;
- //printf("name: %s \r\n ", (*area_rst)[0]->area_name.c_str());
- }
- };
- int SavePathImgMy(PVOID para1)
- {
- SavePathImgPara *para = (SavePathImgPara *)para1;
- std::string path = para->path;
- CString question_code;
- question_code.Format(_T("\\image_%d.jpg"), para->m + 1);
- CString oldfile;
- oldfile = CA2T(path.c_str());
- CString savePath = para->pathSave + question_code;
- CopyFile(oldfile, savePath, FALSE);
- /*
- IplImage* pImg = cvLoadImage(path.c_str(), 1);
- CString question_code;
- question_code.Format(_T("\\image_%d.jpg"), para->m + 1);
- CString savePath = para->pathSave + question_code;
- //savePath.Format(_T("%s%s"), para->pathSave.c_str(), question_code);
- //zip.PutNextEntry(question_code);
- vector<uchar> dst;
- vector<int> compression_params_low;
- compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_low.push_back(40);
- vector<int> compression_params_high;
- compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_high.push_back(60);
- cv::Mat _img = cv::cvarrToMat(pImg);
- if (pImg->height > 500){
- imencode(".jpg", _img, dst, compression_params_low);
- }
- else{
- imencode(".jpg", _img, dst, compression_params_high);
- }
- cvReleaseImage(&pImg);
-
- //zip.Write(&dst[0], dst.size());
- CFile file;
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write(dst.data(), dst.size());
- file.Close();
- */
- return 0;
- }
- void saveImgPathMyCallback(PVOID para1/*CString filepath, CString key*/)
- {
- std::lock_guard<std::mutex> _lk(mtxTaskNum);
- taskNum--;
- //delete para1;
- //para1 = NULL;
- }
- int saveImgesMy1(PVOID para1/*CString filepath, CString key*/)
- {
- //printf("saveImgesMy1 %p\r\n", para1);
- saveImgesPara1 *para = (saveImgesPara1 *)para1;
- vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
- CString path = para->path;
- bool flag = para->flag;
- int subjectID = para->subjectID;
- //printf("DST name=%s\n", (*area_results)[0]->area_name.c_str());
- std::string area_name;
- CString savePath;
- CFile file;
- if ((*area_results)[0]->area_name == "")
- {
- area_name = (*area_results)[0]->area_name;
- int idx;
- area_name = ((idx = area_name.find('.')) < 0) ? area_name : area_name.substr(0, idx);
- CString question_code;
- question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str()));
- savePath = path + question_code;
- //printf("flag: %d , subjectID = %d,id: %d \r\n", flag?1:0, subjectID, para->ID);
- }
- else
- {
- area_name = (*area_results)[0]->area_name;
- CString question_code;
- question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str()));
- //printf("flag: %d , subjectID = %d,id: %d \r\n", flag ? 1 : 0, subjectID, para->ID);
- savePath = path + question_code;
- }
- if ((*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){
- int width = 0;
- int height = 0;
- for (int jj = 0; jj < (*area_results).size(); jj++)
- {
- if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width;
- height += (*area_results)[jj]->height;
- }
- cv::Mat img_big(cv::Size(width, height), CV_8UC3, cv::Scalar(255, 255, 255));
- for (int ii = 0, top = 0; ii < (*area_results).size(); ii++)
- {
- Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data());
- Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_COLOR);
- cv::Rect rc_tmp(0, top, temp_img.cols, temp_img.rows);
- Mat cut = img_big(rc_tmp);
- temp_img.copyTo(cut);
- top += temp_img.rows;
- }
- //////////////////////////////////////////////////////////////////////////
- vector<uchar> dst;
- //cv::Mat _img = cv::cvarrToMat(img);
- vector<int> compression_params;
- compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params.push_back(25);
- imencode(".jpg", img_big, dst, compression_params);
- //cvResetImageROI(img);
- //zip.Write(&dst[0], dst.size());
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write(dst.data(), dst.size());
- file.Close();
- if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1)
- {
- CString question_code;
- question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str()));
- savePath = path + question_code;
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write(dst.data(), dst.size());
- file.Close();
- //zip.PutNextEntry(question_code);
- //zip.Write(&dst[0], dst.size());
- }
- }
- else
- {
- if ((*area_results)[0]->is_cut > 0)
- {
- //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size());
- if (file.Open(savePath, CFile::modeCreate | CFile::modeWrite)){
- file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
- file.Close();
- }
- else{
- auto e = GetLastError();
- int n = 0; ++n;
- }
- if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1)
- {
- //zip.PutNextEntry(AnsiToUnicode(area_name + "f.jpg"));
- //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size());
- CString question_code;
- question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str()));
- savePath = path + question_code;
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
- file.Close();
- }
- }
- else
- {
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
- file.Close();
- //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size());
- }
- }
- if (flag && (*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){
- vector<int> compression_params_low;
- compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_low.push_back(40);
- vector<int> compression_params_high;
- compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_high.push_back(60);
- for (int jj = 0; jj < (*area_results).size(); jj++)
- {
- CString question_code;
- question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1);
- //zip.PutNextEntry(question_code);
- savePath = path + question_code;
- /*
- int width = (*area_results)[jj]->width;
- int height = (*area_results)[jj]->height;
- IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
- cvSet(img, cvScalarAll(255));
- Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data());
- Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
- cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
- cvCopy(&IplImage(temp_img), img);
- cvResetImageROI(img);
- char sz_question_code[520] = { 0 };
- WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
- vector<uchar> dst;
- cv::Mat _img = cv::cvarrToMat(img);
- if (img->height > 500){
- imencode(".jpg", _img, dst, compression_params_low);
- }
- else{
- imencode(".jpg", _img, dst, compression_params_high);
- }
- cvReleaseImage(&img);
- */
- //zip.Write(&dst[0], dst.size());
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write((*area_results)[jj]->img_data.data(), (*area_results)[jj]->img_data.size());
- file.Close();
- }
- }
- //printf("path:%s \r\n",CT2A(savePath));
- return 0;
- }
- bool sort_subindex(const CUT_AREA_RESULT * c1, const CUT_AREA_RESULT * c2){
- return c1->area_sub_index < c2->area_sub_index;
- }
- int saveImgesMy2(PVOID para1/*CString filepath, CString key*/)
- {
- saveImgesPara1 *para = (saveImgesPara1 *)para1;
- vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
- CString path = para->path;
- bool flag = para->flag;
- int subjectID = para->subjectID;
- CString question_code;
- question_code.Format(_T("\\%s.jpg"), CString((*area_results)[0]->area_name.c_str()));
- //zip.PutNextEntry(question_code);
- std::sort((*area_results).begin(), (*area_results).end(), sort_subindex);
- CString savePath = path + question_code;
- //postMarkTypeID == 10 判断
- vector<int> compression_params_low;
- compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_low.push_back(40);
- vector<int> compression_params_high;
- compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_high.push_back(60);
- int width = 0;
- int height = 0;
- int centerx = 0, centery = 0;
- for (int jj = 0; jj < (*area_results).size(); jj++)
- {
- if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width;
- height += (*area_results)[jj]->height;
- centerx = (*area_results)[jj]->centerx;
- centery += (*area_results)[jj]->centery;
- }
- IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
- cvSet(img, cvScalarAll(255));
- for (int ii = 0, top = 0; ii < (*area_results).size(); ii++)
- {
- Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data());
- Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
- cvSetImageROI(img, cvRect(0, top, temp_img.cols, temp_img.rows));
- temp_img.copyTo(cv::cvarrToMat(img));
- cvCopy(&IplImage(temp_img), img);
- top += (*area_results)[ii]->height;
- }
- cvResetImageROI(img);
- vector<uchar> dst;
- cv::Mat _img = cv::cvarrToMat(img);
- if (img->height > 500){
- imencode(".jpg", _img, dst, compression_params_low);
- }
- else{
- imencode(".jpg", _img, dst, compression_params_high);
- }
- char sz_question_code[520] = { 0 };
- WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
- cvReleaseImage(&img);
- //zip.Write(&dst[0], dst.size());
- CFile file;
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write(dst.data(), dst.size());
- file.Close();
- //imwrite(savePath.c_str(), img);
- if (flag && (*area_results).size() > 1){
- for (int jj = 0; jj < (*area_results).size(); jj++)
- {
- question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1);
- //zip.PutNextEntry(question_code);
- CString savePath = path + question_code;
- width = (*area_results)[jj]->width;
- height = (*area_results)[jj]->height;
- IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
- cvSet(img, cvScalarAll(255));
- //for (int ii = 0, top = 0; ii < area_results.size(); ii++)
- //{
- Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data());
- Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
- cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
- cvCopy(&IplImage(temp_img), img);
- //top += area_results[ii]->height;
- //}
- cvResetImageROI(img);
- char sz_question_code[520] = { 0 };
- WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
- vector<uchar> dst;
- cv::Mat _img = cv::cvarrToMat(img);
- if (img->height > 500){
- imencode(".jpg", _img, dst, compression_params_low);
- }
- else{
- imencode(".jpg", _img, dst, compression_params_high);
- }
- cvReleaseImage(&img);
- //zip.Write(&dst[0], dst.size());
- CFile file;
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write(dst.data(), dst.size());
- file.Close();
- }
- }
- return 0;
- }
- // 算法组提供的新算法 解决 cvcopy崩溃的问题
- // int saveImgesMy2(PVOID para1/*CString filepath, CString key*/)
- // {
- // saveImgesPara1 *para = (saveImgesPara1 *)para1;
- // vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
- // CString path = para->path;
- // bool flag = para->flag;
- // int subjectID = para->subjectID;
- //
- // CString question_code;
- // question_code.Format(_T("\\%s.jpg"), CString((*area_results)[0]->area_name.c_str()));
- // //zip.PutNextEntry(question_code);
- // std::sort((*area_results).begin(), (*area_results).end(), sort_subindex);
- // CString savePath = path + question_code;
- // //postMarkTypeID == 10 判断
- //
- //
- // vector<int> compression_params_low;
- // compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
- // compression_params_low.push_back(40);
- // vector<int> compression_params_high;
- // compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
- // compression_params_high.push_back(60);
- // int width = 0;
- // int height = 0;
- // int centerx = 0, centery = 0;
- // for (int jj = 0; jj < (*area_results).size(); jj++)
- // {
- // if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width;
- // height += (*area_results)[jj]->height;
- // centerx = (*area_results)[jj]->centerx;
- // centery += (*area_results)[jj]->centery;
- // }
- //
- //
- // cv::Mat _img = cv::Mat(cv::Size(width, height), CV_8U, cv::Scalar(255));
- // for (int ii = 0, top = 0; ii < (*area_results).size(); ii++)
- // {
- // Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data());
- // Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
- // temp_img.copyTo(_img(cv::Rect(0, top, temp_img.cols, temp_img.rows)));
- // top += (*area_results)[ii]->height;
- // }
- //
- // vector<uchar> dst;
- // if (_img.rows > 500) {
- // imencode(".jpg", _img, dst, compression_params_low);
- // }
- // else {
- // imencode(".jpg", _img, dst, compression_params_high);
- // }
- // char sz_question_code[520] = { 0 };
- // WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
- // //zip.Write(&dst[0], dst.size());
- // CFile file;
- // file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- // file.Write(dst.data(), dst.size());
- // file.Close();
- // //imwrite(savePath.c_str(), img);
- //
- // if (flag && (*area_results).size() > 1) {
- // for (int jj = 0; jj < (*area_results).size(); jj++)
- // {
- // question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1);
- // //zip.PutNextEntry(question_code);
- // CString savePath = path + question_code;
- // width = (*area_results)[jj]->width;
- // height = (*area_results)[jj]->height;
- // IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
- // cvSet(img, cvScalarAll(255));
- // //for (int ii = 0, top = 0; ii < area_results.size(); ii++)
- // //{
- // Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data());
- // Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
- // cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
- // cvCopy(&IplImage(temp_img), img);
- // //top += area_results[ii]->height;
- // //}
- // cvResetImageROI(img);
- // char sz_question_code[520] = { 0 };
- // WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
- // vector<uchar> dst;
- // cv::Mat _img = cv::cvarrToMat(img);
- // if (img->height > 500) {
- // imencode(".jpg", _img, dst, compression_params_low);
- // }
- // else {
- // imencode(".jpg", _img, dst, compression_params_high);
- // }
- // cvReleaseImage(&img);
- // //zip.Write(&dst[0], dst.size());
- // CFile file;
- // file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- // file.Write(dst.data(), dst.size());
- // file.Close();
- // }
- // }
- // return 0;
- // }
- void saveImgesMyCallback(PVOID para1/*CString filepath, CString key*/)
- {
- std::lock_guard<std::mutex> _lk(mtxTaskNum);
- taskNum--;
- #ifdef _DEBUG
- LOGFMTI("回调调用-3 taskNum=%d",taskNum.load());
- #endif
- //delete para1;
- //para1 = NULL;
- }
- void CResultHandler::SavePaper(int handle_count_limit)
- {
- //printf("SavePaper \n");
- UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo;
- bool identified;//当前这份试卷是否已识别
- int identified_count = 0;//已识别页数
- int paper_page_count = 0;//当前这份试卷的页数
- int student_paper_id = -1;
- std::string student_id = "-1";
- long class_id = -1;
- int class_total = -1;
- char student_name[20] = { 0 };
- char class_info[20] = { 0 };
- float total_score = 0;
- long exceptions = EX_NOMARL;
- string studentcode;//学生证号
- std::map<int, int> page_counts;
- std::map<std::string, int> vecTwoPic;
- std::map<int, std::vector<CUT_AREA_RESULT*>> mm;
- std::vector<int> _mm_tmp;
- //筛选语文的主观题和选做题
- std::vector<std::string> postMarkTypeIDVec;
- bool b_is_same_exam_id = false;
- /************************************************************************/
- /* 确定试卷页数,并确定试卷ID 和 试卷编号 */
- /************************************************************************/
- for (int i = 0; i<handle_count_limit; i++)
- {
- int index1 = (unhandledPageInfo.first_unhandled_page_index + i) % MAX_UNHANDLED_PAGE;
- if (unhandledPageInfo.bOnlineCard){
- //!unhandledPageInfo.unhandled_pages[index1].omr_result->is_use_qr_code&&
- if (
- unhandledPageInfo.unhandled_pages[index1].omr_result->is_front_page&&
- !unhandledPageInfo.unhandled_pages[index1].omr_result->is_same_exam_id)
- {
- b_is_same_exam_id = true;
- if (!m_bSend){
- m_bSend = true;
- if (m_hwnd != NULL)
- ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)1, (LPARAM)NULL);
- }
- }
- OnLineCard::PaperTemplate* pTmp = static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->GetTemplate();
- if (unhandledPageInfo.unhandled_pages[index1].omr_result->examid_by_qr_code&&!m_bIdentifyQrCode &&
- !pTmp->useQrCode)
- {
- m_bIdentifyQrCode = true;
- }
- }
- BOOL is_next = FALSE;//是否是下一份试卷
- //比较考号是否不一样 依此判断是否是下一份试卷
- if (unhandledPageInfo.unhandled_pages[index1].student_code.length()>0){
- if (studentcode.length()>0){
- if (studentcode != unhandledPageInfo.unhandled_pages[index1].student_code){
- is_next = TRUE;
- }
- }
- else{
- studentcode = unhandledPageInfo.unhandled_pages[index1].student_code;
- }
- }
- if (is_next){
- break;
- }
- page_counts[unhandledPageInfo.unhandled_pages[index1].page_index]++;
- //比较试卷页码是否重复 依此判断是否是下一份试卷
- for (int j = 0; j<i; j++)
- {
- int index2 = (unhandledPageInfo.first_unhandled_page_index + j) % MAX_UNHANDLED_PAGE;
- if (unhandledPageInfo.unhandled_pages[index2].page_index == unhandledPageInfo.unhandled_pages[index1].page_index &&unhandledPageInfo.unhandled_pages[index1].page_index != -1){
- is_next = TRUE;
- break;
- }
- }
- is_next = FALSE;
- if (is_next){
- break;
- }
- paper_page_count++;
- OMR_RESULT* omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- if (omr_result->paper_id > 0){
- student_paper_id = omr_result->paper_id;
- }
- if (m_nOnlineScanType == 0 && omr_result->is_front_page && omr_result->strMagicClassId.length() && omr_result->strMagicStudentId.length())
- {
- CString strPaperCode;
- readPaperId(strPaperCode);
- WriteOnlineCardPaperId(strPaperCode, (wstring)AnsiToUnicode(omr_result->strMagicClassId), (wstring)AnsiToUnicode(omr_result->strMagicStudentId));
- }
- std::string str_stu_id = unhandledPageInfo.unhandled_pages[index1].student_id;
- if (!str_stu_id.empty()){
- student_id = str_stu_id;
- }
- if (unhandledPageInfo.unhandled_pages[index1].identified){
- identified_count++;
- }
- }
- identified = (identified_count == m_muban_page_count&&page_counts.size() == m_muban_page_count);
- if (page_counts.size()<m_muban_page_count) exceptions |= EX_DINGWEIDIAN; // 出现缺页情况统一为定位点异常 exceptions |= EX_SHIJUANQUEYE;
- int isAbsent = 0;
- std::string shijuanleixing = "A";
- for (int m = 0; m<paper_page_count; m++)
- {
- int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
- if (!unhandledPageInfo.bOnlineCard){
- static const std::string Q = "Q";
- if (unhandledPageInfo.unhandled_pages[page_index].omr_result->identified){
- int indx = unhandledPageInfo.unhandled_pages[page_index].omr_result->card_index;
- if (existAbsentFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result) && Q == absentFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result)){
- isAbsent = 1;
- }
- if (existABJuanFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result)){
- shijuanleixing = ABJuanFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result);
- }
- }
- }
- else{
- auto tmp = unhandledPageInfo.unhandled_pages[page_index].omr_result;
- if (tmp&& tmp->identified && isAbsent ==0){
- isAbsent = tmp->quekaoFlag;
- }
- }
- }
- if (isAbsent != 0) exceptions |= EX_SHIJUANQUEKAO;
- /************************************************************************/
- /* 保存切割好的图像 */
- /************************************************************************/
- // printf("切图\n");
- std::map<std::string, std::string> _map_real_name;
- char sz_file_name[520] = { 0 };
- char sz_ori_file_name[520] = { 0 };
- if (identified){//将切割好的图像压缩为zip
- CString filename = m_img_clips_dir + _T("\\") + GetTimeString();
- CreateDirectory(filename, NULL);
- filename += _T("\\img");
- CreateDirectory(filename, NULL);
- CString filename1 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("ori");
- CreateDirectory(filename1, NULL);
- filename1 += _T("\\img");
- CreateDirectory(filename1, NULL);
- WideCharToMultiByte(CP_ACP, 0, filename, -1, sz_file_name, 520, NULL, NULL);
- WideCharToMultiByte(CP_ACP, 0, filename1, -1, sz_ori_file_name, 520, NULL, NULL);;
- //CMemFile file;
- //CMemFile file3;
- //CMemZipFile zip;
- //CMemZipFile zip1;
- //zip.OpenFile(&file);
- //zip1.OpenFile(&file3);
- vector<CUT_AREA_RESULT*> area_results;
- UnhandledPage* unhandledPage[16];
- for (int m = 0; m<paper_page_count; m++)
- {
- int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
- unhandledPage[m] = &unhandledPageInfo.unhandled_pages[page_index];
- }
- for (int m = 0; m<paper_page_count; m++)
- {
- for (int n = m + 1; n<paper_page_count; n++){
- if (unhandledPage[m]->page_index>unhandledPage[n]->page_index){
- UnhandledPage* t_page = unhandledPage[m];
- unhandledPage[m] = unhandledPage[n];
- unhandledPage[n] = t_page;
- }
- }
- }
- int nQuestionNo = 0;
- int nZhuGuanTi = 0, nXuanZuoTi = 0, nZhuGuanTi2 = 0, nXuanZuoTi2 = 0, nCutCount = 0;
- static bool falg = false;
- if (!unhandledPageInfo.bOnlineCard){
- if (!falg && g_my_scan_type != 1)
- {
- loadSchema();
- falg = true;
- }
- else if (g_my_scan_type == 1)
- loadSchema();
- for (int i = 0; i < m_schema.questions.size(); i++)
- {
- if (m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI || m_schema.questions[i].questionType == ZHUGUANTI)
- {
- if (10 == m_schema.questions[i].postMarkTypeID || 4 == m_schema.questions[i].postMarkTypeID )
- postMarkTypeIDVec.push_back(m_schema.questions[i].question_code_new);
- }
- }
- for (int i = 0; i < m_schema.questions.size(); i++)
- {
- if (m_schema.questions[i].questionType == TIANKONGTI || m_schema.questions[i].questionType == ZHUGUANTI)
- {
- nZhuGuanTi++;
- }
- else if (m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI)
- {
- nXuanZuoTi++;
- }
- }
- }
- vector<int> vecQuestionNo;
- map<string, int> mapQuestionNo;
- if (unhandledPageInfo.bOnlineCard){
- OnLineCard::PaperTemplate* pTmp = static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->GetTemplate();
- if (pTmp){
- for (auto it: pTmp->pages){
- for (auto itQ : it.second.vctQuestions){
- if (itQ.marktype == 4 || itQ.marktype == 10)
- {
- postMarkTypeIDVec.push_back(itQ.id);
- }
- vecQuestionNo.push_back(std::stoi(itQ.id));
- }
- }
- }
- }
- else{
- for (std::size_t i = 0; i < m_schema.questions.size(); i++)
- {
- if (m_schema.questions[i].questionType == TIANKONGTI || m_schema.questions[i].questionType == ZHUGUANTI || m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI)
- {
- vecQuestionNo.push_back(atoi(m_schema.questions[i].question_code_new));
- }
- }
- }
- if (vecQuestionNo.size()>1)
- {
- sort(vecQuestionNo.begin(), vecQuestionNo.end(), less_equal<int>());
- }
- std::map<std::string, std::pair<int,std::string>> _map_duoxuanti;
- //std::vector<std::string> _vct_all_questions;
- std::map<std::string, std::vector<std::string>> _map_duoxuantiquanti;
- std::string strtempallxuanzuotiqs = "";
- std::vector<SavePathImgPara *> paraVec1;
- for (int m = 0; m<paper_page_count; m++)
- {
- if (pUnhandledPageInfo->bOnlineCard)
- {
- int index1 = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- for (int i = 0; i < omr_result->zhutuanti_result.size(); i++)
- {
- auto question_code = omr_result->zhutuanti_result[i].question_code;
- if (omr_result->zhutuanti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::XUANZUOTI){
- std::string strAllQuestions = omr_result->zhutuanti_result[i].question_code_all;
- int nSel = -1;
- if (omr_result->zhutuanti_result[i].question_code_all != omr_result->zhutuanti_result[i].question_code_temp && omr_result->zhutuanti_result[i].xuanze == -2)
- {
- //说明是类型4的分组选做题
- bool bfindselect = false;
- //本业查找(一定再这个数据之前)
- for (int j = i -1 ; j >= 0; j--)
- {
- if (omr_result->zhutuanti_result[i].question_code_temp == omr_result->zhutuanti_result[j].question_code_temp && omr_result->zhutuanti_result[j].xuanze != -2)
- {
- nSel = omr_result->zhutuanti_result[j].xuanze;
- omr_result->zhutuanti_result[i].xuanze = nSel;
- bfindselect = true;
- break;
- }
- }
- //没有找到,向前面查找
- if (!bfindselect)
- {
- for (int n = m - 1; n >= 0; n--)
- {
- bfindselect = false;
- int index2 = (unhandledPageInfo.first_unhandled_page_index + n) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index2].omr_result;
- for (int j = omr_result1->zhutuanti_result.size() - 1; j >= 0; j--)
- {
- if (omr_result->zhutuanti_result[i].question_code_temp == omr_result1->zhutuanti_result[j].question_code_temp && omr_result1->zhutuanti_result[j].xuanze != -2)
- {
- nSel = omr_result1->zhutuanti_result[j].xuanze;
- omr_result->zhutuanti_result[i].xuanze = nSel;
- bfindselect = true;
- break;
- }
- }
- if (bfindselect)
- break;
- }
- }
- }
- else
- {
- nSel = omr_result->zhutuanti_result[i].xuanze;
- }
- _map_duoxuanti[question_code] = std::make_pair(nSel, strAllQuestions);
- //if (_vct_all_questions.empty()){
- if (strtempallxuanzuotiqs != strAllQuestions){
- std::vector<std::string> _vct_all_questions;
- split(strAllQuestions, (std::string)",", &_vct_all_questions);
- _map_duoxuantiquanti[strAllQuestions] = _vct_all_questions;
- strtempallxuanzuotiqs = strAllQuestions;
- }
- }
- }
- }
- ThreadPool *threadPool = CImgUploadManager::GetInstance()->getThreadPool();
- int nQueKaoNo = 0, nLengthOfTianTuKaoHao = 0;
- OMR_RESULT* omr_result = unhandledPage[m]->omr_result;
- SavePathImgPara *para = new SavePathImgPara(omr_result->img_path, filename1, m);
- //SavePathImg(omr_result->img_path, zip1, m);
- paraVec1.push_back(para);
- std::lock_guard<std::mutex> _lk(mtxTaskNum);
- taskNum++;
- threadPool->QueueTaskItem(SavePathImgMy, para, saveImgPathMyCallback);
-
- if (unhandledPageInfo.bOnlineCard){
- nQueKaoNo = 1;
- }
- else{
- nQueKaoNo = m_schema.pages[m].quekaobiaoji.size();
- if (m_schema.pages[m].tiantukaohao.size()>0)
- {
- if (m_schema.pages[m].tiantukaohao[m].direction == 1)//Vertical;
- nLengthOfTianTuKaoHao = m_schema.pages[m].tiantukaohao[m].nCols;
- else
- nLengthOfTianTuKaoHao = m_schema.pages[m].tiantukaohao[m].nRows;
- }
- }
- for (int t = 0; t < omr_result->cut_area_result.size(); t++)
- {
- if (mapQuestionNo.size() >= 0)
- {
- map<string, int>::iterator it = mapQuestionNo.find(omr_result->cut_area_result[t].area_name);
- if (it == mapQuestionNo.end())
- mapQuestionNo.insert(map<string, int>::value_type(omr_result->cut_area_result[t].area_name, vecQuestionNo[nCutCount + t]));
- else
- nCutCount = nCutCount - 1;
- }
- }
- nCutCount = mapQuestionNo.size();
- /*if (isAbsent == 0)*/{
- for (int n = 0; n<omr_result->cut_area_result.size(); n++)
- {
- int nKeguanti, nQuestionIndex;
- CString strTimu;
- char cstrTemp[20];
- string strAreaName;
- nZhuGuanTi2++;
- const std::vector<XUANZUOTI_RESULT_HANDLE_INFO>& xuanzuotiHandleInfo = m_handInfoMap[omr_result->card_index].xuanzuotiHandleInfo;
- for (int i = 0; i < xuanzuotiHandleInfo.size(); i++)
- {
- const char * answer = omr_result->group_result[nQueKaoNo + nLengthOfTianTuKaoHao + i].answer.c_str();
- if (omr_result->group_result[nQueKaoNo + nLengthOfTianTuKaoHao + i].answer != "")
- {
- mapQuestionNo[omr_result->cut_area_result[omr_result->cut_area_result.size() - i - 1].area_name] = atoi(answer);
- for (int t = 0; t < xuanzuotiHandleInfo[i].option_question_code[0].size(); t++)
- {
- if (omr_result->cut_area_result[n].area_name == xuanzuotiHandleInfo[i].option_question_code[0][t].at(0))
- {
- omr_result->cut_area_result[n].area_name = answer;
- break;
- }
- }
- }
- }
- nKeguanti = m_schema.questions.size();
- nKeguanti = _wtoi(strTimu.Left(strTimu.Find('&')));
- nQuestionIndex = nKeguanti + atoi(omr_result->cut_area_result[n].area_name.c_str());
- itoa(mapQuestionNo[omr_result->cut_area_result[n].area_name], cstrTemp, 10);
- strAreaName = cstrTemp;
- auto nIndex = omr_result->cut_area_result[n].area_index;
- if (pUnhandledPageInfo->bOnlineCard){
- nIndex = m * 1000 + nIndex;
- }
- mm[nIndex].push_back(&omr_result->cut_area_result[n]);
- _mm_tmp.push_back(nIndex);
- }
- }
- }
- std::map<int, std::vector<CUT_AREA_RESULT*>>::iterator it;
- char strPaperCode[MAX_PATH];
- std::memset(strPaperCode, 0, MAX_PATH);
- CString strPaperId;
- readPaperId(strPaperId);
- for (int i = 0; i<strPaperId.GetLength(); i++)
- {
- strPaperCode[i] = strPaperId.GetAt(i);
- }
- ThreadPool *threadPool = CImgUploadManager::GetInstance()->getThreadPool();
- std::vector<saveImgesPara1 *> paraVec2;
- vector<CUT_AREA_RESULT*> area_rstlist[400];
- int listpos = 0;
- if (pUnhandledPageInfo->bOnlineCard){
- int idx = 0;
- std::vector<std::string> tmp_all_q;
- std::vector<int> _vct_sel;
- std::vector<int> _mm_unsel_tmp;
- std::vector<std::string> _tmp_name;
- std::string area_name_t;
- std::string strtempallxuanzuotiqs = "";
- std::vector<std::string> _vct_all_questions;
- for (auto it = _mm_tmp.begin(); it != _mm_tmp.end(); ++it, ++idx){
- std::vector<CUT_AREA_RESULT*> &area_tmp = mm[*it];
- vector<CUT_AREA_RESULT*> &area_rst = area_rstlist[listpos++];
- area_rst.push_back(area_tmp[0]);
- int area_sub_index = area_tmp[0]->area_sub_index;
- bool is_cut = area_tmp[0]->is_cut;
-
- bool b_duoxuan = false;
- bool b_save = true;
- bool b_sel = false;
- std::string name = area_tmp[0]->area_name;
- auto itFind = _map_duoxuanti.find(area_tmp[0]->area_name);
- if (itFind != _map_duoxuanti.end()){
- if (strtempallxuanzuotiqs != itFind->second.second)
- {
- //肯定可以找到
- _vct_all_questions.clear();
- _vct_sel.clear();
- tmp_all_q.clear();
- _vct_all_questions = _map_duoxuantiquanti.find(itFind->second.second)->second;
- strtempallxuanzuotiqs = itFind->second.second;
- tmp_all_q = _vct_all_questions;
- }
- b_duoxuan = true;
- _tmp_name.push_back(itFind->first);
- std::string area_name;
- int sel = itFind->second.first;
- if (sel >= 0 && sel < _vct_all_questions.size() &&
- std::find(_vct_sel.begin(), _vct_sel.end(), sel) == _vct_sel.end()){
- area_name = _vct_all_questions[sel];
- _vct_sel.push_back(sel);
- tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end());
- _map_real_name[area_tmp[0]->area_name] = area_name;
- area_tmp[0]->area_name = area_name;
- _map_duoxuanti.erase(itFind);
- b_sel = true;
- }
- else{
- _mm_unsel_tmp.push_back(*it);
- std::string area_name = *tmp_all_q.begin();
- tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end());
- _map_real_name[area_rst[0]->area_name] = area_name;
- b_save = false;
- }
- }
- int next_id = idx + 1;
- while (next_id < _mm_tmp.size())
- {
- if (area_sub_index == 1 && is_cut &&
- mm[_mm_tmp[next_id]].size()>0
- && mm[_mm_tmp[next_id]][0]->area_sub_index == 0){
- ++it; ++idx;
- if (b_duoxuan && !b_sel){
- _mm_unsel_tmp.push_back(*it);
- b_save = false;
- }
- area_rst.push_back(mm[*it][0]);
- next_id = idx + 1;
- }
- else{
- break;
- }
- }
- if (b_save){
- BOOL flag = false;
- //if (pUnhandledPageInfo->nSubjectID == 0)
- {
- for (int i = 0; i < postMarkTypeIDVec.size(); i++)
- {
- for (int j = 0; j < area_rst.size(); j++){
- if (postMarkTypeIDVec[i] == area_rst[j]->area_name)
- {
- flag = true;
- break;
- }
- }
- }
- }
- if (flag && area_rst.size() > 1 && area_rst[0]->is_cut){
- vecTwoPic[area_rst[0]->area_name.c_str()] = area_rst.size();
- }
- //printf("SRC name=%s\n", area_rst[0]->area_name.c_str());
- saveImgesPara1 *para = new saveImgesPara1(&area_rst, filename, pUnhandledPageInfo->nSubjectID, flag);
- ///printf("para %p\r\n", para);
- paraVec2.push_back(para);
- std::lock_guard<std::mutex> _lk(mtxTaskNum);
- taskNum++;
- threadPool->QueueTaskItem(saveImgesMy1, para, saveImgesMyCallback);
-
- //SaveImages(area_rst, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic);
- }
- //area_rst.clear();
- area_name_t = "";
- }
- bool bClear = false;
- vector<CUT_AREA_RESULT*> &area_rst = area_rstlist[listpos];
- idx = 0;
- for (auto it = _mm_unsel_tmp.begin(); it != _mm_unsel_tmp.end(); ++it, ++idx){
- std::vector<CUT_AREA_RESULT*> &area_tmp = mm[*it];
- int area_sub_index = area_tmp[0]->area_sub_index;
- int is_cut = area_tmp[0]->is_cut;
- int next_id = idx + 1;
- area_rstlist[listpos].push_back(area_tmp[0]);
- if (area_sub_index == 1 && (is_cut > 0) &&
- next_id < _mm_unsel_tmp.size() && mm[_mm_unsel_tmp[idx + 1]].size()>0
- && mm[_mm_unsel_tmp[idx + 1]][0]->area_sub_index == 0){
- continue;
- }
- //std::string area_name = *tmp_all_q.begin();
- //tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end());
- //_map_real_name[area_rst[0]->area_name] = area_name;
- //area_rst[0]->area_name = area_name;
- area_rstlist[listpos][0]->area_name = _map_real_name[area_rstlist[listpos][0]->area_name];
- //SaveImages(area_rst, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic);
- BOOL flag = false;
- //if (pUnhandledPageInfo->nSubjectID == 0)
- {
- for (int i = 0; i < postMarkTypeIDVec.size(); i++)
- {
- for (int j = 0; j < area_rstlist[listpos].size(); j++){
- if (postMarkTypeIDVec[i] == area_rstlist[listpos][j]->area_name)
- {
- flag = true;
- break;
- }
- }
- }
- }
- if (flag && area_rstlist[listpos].size() > 1 && area_rstlist[listpos][0]->is_cut > 0){
- vecTwoPic[area_rstlist[listpos][0]->area_name.c_str()] = area_rstlist[listpos].size();
- }
- saveImgesPara1 *para = new saveImgesPara1(&area_rstlist[listpos], filename, pUnhandledPageInfo->nSubjectID, flag);
- //printf("para %p\r\n", para);
- paraVec2.push_back(para);
- std::lock_guard<std::mutex> _lk(mtxTaskNum);
- taskNum++;
- threadPool->QueueTaskItem(saveImgesMy1, para, saveImgesMyCallback);
- ++listpos;
- //area_rst = area_rstlist[++listpos];
-
- //area_rst.clear();
- }
- }
- else{
- for (it = mm.begin(); it != mm.end(); ++it){
- BOOL flag = false;
- //if (pUnhandledPageInfo->nSubjectID == 0)
- {
- for (int i = 0; i < postMarkTypeIDVec.size(); i++)
- {
- for (int j = 0; j < it->second.size(); j++){
- if (postMarkTypeIDVec[i] == it->second[j]->area_name)
- {
- vecTwoPic[(it->second[0])->area_name.c_str()] = it->second.size();
- flag = true;
- break;
- }
- }
- }
- }
- saveImgesPara1 *para = new saveImgesPara1(&it->second, filename, pUnhandledPageInfo->nSubjectID, flag);
- ///printf("para %p\r\n", para);
- paraVec2.push_back(para);
- std::lock_guard<std::mutex> _lk(mtxTaskNum);
- taskNum++;
- threadPool->QueueTaskItem(saveImgesMy2, para, saveImgesMyCallback);
-
- //SaveImages(it->second, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic);
- }
- }
- while (true)
- {
- Sleep(10);
- if (taskNum.load() == 0)
- {
- for (std::vector<saveImgesPara1 *>::iterator iter = paraVec2.begin(); iter != paraVec2.end(); ++iter)
- {
- if (*iter != nullptr)
- {
- //(*iter)->area_rst.clear();
- //delete &(*iter)->area_rst;
- delete (*iter);
- (*iter) = nullptr;
- }
- }
- for (std::vector<SavePathImgPara *>::iterator iter = paraVec1.begin(); iter != paraVec1.end(); ++iter)
- {
- if (*iter != nullptr)
- {
- delete (*iter);
- (*iter) = nullptr;
- }
- }
- break;
- }
- }
- for (int i = 0; i < listpos;i++)
- {
- area_rstlist[i].clear();
- }
- //printf("taskNum 结束 \n");
- //zip.Close();
- //zip1.Close();
- //CString filename = m_img_clips_dir + _T("\\") + GetTimeString() + _T(".zip");
- //CString filename1 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("ori.zip");
- //WideCharToMultiByte(CP_ACP, 0, filename, -1, sz_file_name, 520, NULL, NULL);
- //WideCharToMultiByte(CP_ACP, 0, filename1, -1, sz_ori_file_name, 520, NULL, NULL);
- //CFile file2(filename, CFile::OpenFlags::modeWrite | CFile::OpenFlags::modeCreate);
- //CFile file4(filename1, CFile::OpenFlags::modeWrite | CFile::OpenFlags::modeCreate);
- //file.SeekToBegin();
- //file3.SeekToBegin();
- //int len; char buffer[4096];
- //while ((len = file.Read(buffer, 4096))>0){
- // file2.Write(buffer, len);
- //}
- //while ((len = file3.Read(buffer, 4096))>0){
- // file4.Write(buffer, len);
- //}
- //file.Close();
- //file2.Close();
- //file3.Close();
- //file4.Close();
- }
- // printf("切图结束\n");
- /************************************************************************/
- /* 保存试卷页信息和试卷信息 */
- /************************************************************************/
- /************************************************************************/
- /* 匹配学生(先从本地匹配,没有就远程请求) */
- /************************************************************************/
- //std::string::iterator end_pos = std::remove(studentcode.begin(), studentcode.end(), ' ');
- //studentcode.erase(end_pos, studentcode.end());
- // bool bGetStuInfo = true;
- // if (m_bUseQr){
- // std::vector<std::string> split_qr;
- // split(m_strQr, (std::string)",", &split_qr);
- // if (split_qr.size() >= 3){
- // std::vector<std::string> _vct;
- // split(split_qr[2], std::string("@"), &_vct);
- // if (_vct.size() >= 3){
- // bGetStuInfo = false;
- // }
- // }
- // }
- //if (!m_bUseQr || bGetStuInfo)
- {
- if (pUnhandledPageInfo->bOnlineCard){
- if (studentcode.empty() && student_id == "-1"){
- exceptions |= EX_KAOHAOWEISHIBIE;
- }
- else{
- exceptions |= EX_KAOHAODAIPIPEI;
- }
- }
- else{
- // if (!m_bUseQr || m_strQr.empty()){
- const std::tr1::regex pattern("^[a-z0-9A-Z]{1,30}$");
- if( (studentcode.length() > 0 && std::regex_match(studentcode, pattern))){
- exceptions |= EX_KAOHAODAIPIPEI;
- }
- else if (identified || studentcode.length() == 0){
- exceptions |= EX_KAOHAOWEISHIBIE;
- }
- if (existABJuanFlag() && shijuanleixing != "A"&&shijuanleixing != "B"){
- exceptions |= EX_ABJUANWEISHIBIE;
- }
- // }
- }
- }
- bool isupdate = false;
- try{
- EnterCriticalSection(db_lock);
- bantch_db->execDML("begin transaction");
- // 扫描反馈
- //
- if (exceptions&EX_KAOHAOWEISHIBIE && g_my_scan_type != 0 && g_my_scan_type != 2)
- {
- int index1 = (unhandledPageInfo.first_unhandled_page_index + 0) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- char sql1[1024];
- sprintf_s(sql1, "SELECT * from page where img_oldpath = \"%s\"", omr_result->img_oldpath.c_str());
- CppSQLite3Query q = bantch_db->execQuery(sql1);
- if (!q.eof())
- {
- for (int m = 0; m<paper_page_count; m++)
- {
- int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
- unhandledPageInfo.result->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result);
- }
- unhandledPageInfo.first_unhandled_page_index = (unhandledPageInfo.first_unhandled_page_index + paper_page_count) % MAX_UNHANDLED_PAGE;
- unhandledPageInfo.unhandled_page_count -= paper_page_count;
- bantch_db->execDML("rollback transaction");
- LeaveCriticalSection(db_lock);
- return;
- }
- }
- // printf("插入保存试卷:%d\n", student_paper_id);
- //插入保存试卷
- if (student_paper_id>0){
- isupdate = true;
- char sql5[512];
- sprintf_s(sql5, "delete from result where page_id in(select pg.page_id from page pg where pg.student_paper_id =%d )", student_paper_id);
- bantch_db->execDML(sql5);
- sprintf_s(sql5, "delete from exception where student_paper_id =%d", student_paper_id);
- bantch_db->execDML(sql5);
- sprintf_s(sql5, "delete from page where student_paper_id =%d ", student_paper_id);
- bantch_db->execDML(sql5);
- CppSQLite3Statement stmt;
- if (m_bUseQr &&!pUnhandledPageInfo->bOnlineCard ){
- stmt = bantch_db->compileStatement("update student_paper set picFlag=:picFlag,ret_upload=:ret_upload,img_upload=:img_upload,paper_state=:paper_state,student_id=:student_id,file_name=:file_name,ori_img=:ori_img,absent=:absent where student_paper_id =:student_paper_id");
- }
- else{
- stmt = bantch_db->compileStatement("update student_paper set picFlag=:picFlag,ret_upload=:ret_upload,img_upload=:img_upload,student_code=:student_code,paper_state=:paper_state,student_id=:student_id,file_name=:file_name,ori_img=:ori_img,absent=:absent where student_paper_id =:student_paper_id");
- stmt.bind(":student_code", studentcode.c_str());
- }
- stmt.bind(":student_paper_id", student_paper_id);
- stmt.bind(":ret_upload", 0);
- stmt.bind(":img_upload", 0);
- stmt.bind(":file_name", sz_file_name);
- stmt.bind(":ori_img", sz_ori_file_name);
- stmt.bind(":paper_state", 999);
- stmt.bind(":student_id", student_id.c_str());
- stmt.bind(":absent", isAbsent);
- // printf("学生ID:%s isAbsent=%d\n", student_id.c_str(), isAbsent);
- {
- std::map<std::string, int>::iterator it;// = vecTwoPic.end();
- it = vecTwoPic.begin();
- CString strPic;
- while (it != vecTwoPic.end())
- {
- //it->first;
- //it->second;
- std::string str2;
- str2 = it->first;
- //str1 = it->first.c_str();
- int num = it->second;
- //strPic = strPic + _T("_") + std::to_string(num) + _T("#");
- str2 = str2 + "_" + std::to_string(num) + "#";
- CString str1(str2.c_str());
- //str1.Format(_T("%s_%d#"), str1,num);
- strPic += str1;
- it++;
- }
- char cStrPic[1024];
- WideCharToMultiByte(CP_ACP, 0, strPic, -1, cStrPic, 1024, NULL, NULL);
- stmt.bind(":picFlag", cStrPic);
- }
- stmt.execDML();
- }
- else{
- CString strPaperId;
- readPaperId(strPaperId);
- CppSQLite3Statement stmt = bantch_db->compileStatement("insert into student_paper(ret_upload,img_upload,student_code,paper_state,student_id,file_name,ori_img,absent,paper_type,paper_code,location_id,picFlag)values(:ret_upload,:img_upload,:student_code,:paper_state,:student_id,:file_name,:ori_img,:absent,:paper_type,:paper_code,:location_id, :picFlag)");
- stmt.bind(":ret_upload", 0);
- stmt.bind(":img_upload", 0);
- stmt.bind(":file_name", sz_file_name);
- stmt.bind(":ori_img", sz_ori_file_name);
- stmt.bind(":student_code", studentcode.c_str());
- stmt.bind(":paper_state", 999);
- stmt.bind(":student_id", student_id.c_str());
- stmt.bind(":absent", isAbsent);
- stmt.bind(":paper_type", shijuanleixing.c_str());
- // printf("学生ID:%s isAbsent=%d\n", student_id.c_str(), isAbsent);
- char strPaperCode[MAX_PATH];
- memset(strPaperCode, 0, MAX_PATH);
- for (int i = 0; i<strPaperId.GetLength(); i++)
- {
- strPaperCode[i] = strPaperId.GetAt(i);
- }
- stmt.bind(":paper_code", strPaperCode);
- stmt.bind(":location_id", g_myindex);
- std::map<std::string, int>::iterator it;// = vecTwoPic.end();
- it = vecTwoPic.begin();
- CString strPic;
- while (it != vecTwoPic.end())
- {
- //it->first;
- //it->second;
- std::string str2;
- str2 = it->first;
- //str1 = it->first.c_str();
- int num = it->second;
- //strPic = strPic + _T("_") + std::to_string(num) + _T("#");
- str2 = str2 + "_" + std::to_string(num) + "#";
- CString str1(str2.c_str());
- //str1.Format(_T("%s_%d#"), str1,num);
- strPic += str1;
- it++;
- }
- char cStrPic[1024];
- WideCharToMultiByte(CP_ACP, 0, strPic, -1, cStrPic, 1024, NULL, NULL);
- stmt.bind(":picFlag", cStrPic);
- stmt.execDML();
- CppSQLite3Query query = bantch_db->execQuery("select last_insert_rowId() from student_paper");
- student_paper_id = query.getIntField(0);
- }
- char phy_number[20];
- CppSQLite3Statement stmt2 = bantch_db->compileStatement("INSERT INTO result ( page_id, type, answer, score, question_code, score_paper, question_state,student_paper_id ,isright) VALUES ( :page_id, :type, :answer, :score, :question_code, :score_paper, :question_state, :student_paper_id,:isright)");
- CppSQLite3Statement stmt3 = bantch_db->compileStatement("insert into exception (exception_type ,exception_name,page_id,student_paper_id) values(:exception_type ,:exception_name,:page_id,:student_paper_id)");
- if (exceptions&EX_KAOHAOWEISHIBIE){
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":exception_type", SHIFT_KAOHAOWEISHIBIE);
- stmt3.bind(":exception_name", "考号未识别");
- stmt3.execDML();
- }
- if (exceptions&EX_DINGWEIDIAN) {
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":exception_type", SHIFT_DINGWEIDIAN);
- stmt3.bind(":exception_name", "定位点异常");
- stmt3.execDML();
- }
- if (exceptions&EX_KAOHAOBUCUNZAI){
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":exception_type", SHIFT_KAOHAOBUCUNZAI);
- stmt3.bind(":exception_name", "考号不存在");
- stmt3.execDML();
- }
- if (exceptions&EX_KAOHAOCHONGTU){
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
- stmt3.bind(":exception_name", "考号冲突");
- stmt3.execDML();
- }
- if (exceptions&EX_SHIJUANQUEYE){
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":exception_type", SHIFT_SHIJUANQUEYE);
- stmt3.bind(":exception_name", "试卷缺页");
- stmt3.execDML();
- }
- if (exceptions&EX_ABJUANWEISHIBIE){
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":exception_type", SHIFT_ABJUANWEISHIBIE);
- stmt3.bind(":exception_name", "AB卷未识别");
- stmt3.execDML();
- }
- vector<int> page_ids;
- //题号是否被选中(有效选中)
- map<string, bool> question_selected;
- for (std::map<int, const PAGE_RESULT_HANDLE_INFO>::iterator it = m_handInfoMap.begin(); it != m_handInfoMap.end(); it++)
- {
- const std::vector<XUANZUOTI_RESULT_HANDLE_INFO> & xuanzuoti_result_handle_infos = it->second.xuanzuotiHandleInfo;
- for (int idx_xz = 0; idx_xz<xuanzuoti_result_handle_infos.size(); idx_xz++)
- {
- const XUANZUOTI_RESULT_HANDLE_INFO & xuanzuoti_hi = xuanzuoti_result_handle_infos[idx_xz];
- for (int index_group = 0; index_group<xuanzuoti_hi.group_index.size(); index_group++)
- {
- const std::vector<std::string>& mark_unit_question_codes = xuanzuoti_hi.mark_unit_question_code[index_group];
- for (int index_markunit = 0; index_markunit<mark_unit_question_codes.size(); index_markunit++)
- {
- vector<string> markunit_questioncode;
- split(mark_unit_question_codes[index_markunit], ",", &markunit_questioncode);
- for (int index_markunit_q = 0; index_markunit_q<markunit_questioncode.size(); index_markunit_q++)
- {
- question_selected[markunit_questioncode[index_markunit_q]] = false;
- }
- }
- }
- }
- }
- bool bInsertQuekaobiao = false;
-
- Json::Value json_array4(Json::arrayValue);
- Json::Value json4;
- bool flag4 = false;
- for (int p = 0; p < paper_page_count; p++)
- {
- /*
- if (!identified)
- {
- if (pUnhandledPageInfo->bOnlineCard)
- {
- int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- //stmt.bind(":img_path", omr_result->img_path.c_str());
- Json::Value item;
- item["path"] = omr_result->img_path.c_str();
- json_array4.append(item);
- flag4 = true;
- }
- }
- */
- int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- //stmt.bind(":img_path", omr_result->img_path.c_str());
- if (omr_result->card_qrFlag == -1)
- {
- Json::Value item;
- item["path"] = omr_result->img_path.c_str();
- json_array4.append(item);
- flag4 = true;
- }
- }
- if (flag4)
- {
- //发送消息
- MY_DB_INFO fff;
- int len = 1024;
- memset(fff.sUrl, 0, 520);
- //strncpy(fff.sDbBasePath, g_strUpLoadDbPathName.c_str(), g_strUpLoadDbPathName.length() + 1);
- //getupLoadUrl(fff.sUrl, len);
- fff.ntype = 3; //二维码错误情况
- fff.nmode = 1;
- COPYDATASTRUCT cpd; // 给COPYDATASTRUCT结构赋值
- cpd.dwData = 0;
- cpd.cbData = sizeof(MY_DB_INFO);
- cpd.lpData = (&fff);
- json4["imgs"] = json_array4;
-
- char sz_file_name4[520] = { 0 };
- CString filename4 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("_json.txt");
- WideCharToMultiByte(CP_ACP, 0, filename4, -1, sz_file_name4, 520, NULL, NULL);
- CFile file;
- CString fliepath;
-
- file.Open(filename4, CFile::modeCreate | CFile::modeWrite);
- Json::FastWriter writer;
- std::string json_str = writer.write(json4);
- DWORD wide_string_len = MultiByteToWideChar(CP_ACP, 0, json_str.c_str(), -1, NULL, 0);
- WCHAR* wide_string = new WCHAR[wide_string_len];
- wide_string_len = MultiByteToWideChar(CP_ACP, 0, json_str.c_str(), -1, wide_string, wide_string_len);
- DWORD utf8_string_len = WideCharToMultiByte(CP_UTF8, 0, wide_string, -1, NULL, 0, NULL, NULL);
- CHAR* utf8_string = new CHAR[utf8_string_len];
- utf8_string_len = WideCharToMultiByte(CP_UTF8, 0, wide_string, -1, utf8_string, utf8_string_len, NULL, NULL);
- file.Write((void*)utf8_string, utf8_string_len - 1);
- file.Close();
- delete wide_string;
- delete utf8_string;
- //Json::FastWriter writer;
- //std::string json_str = writer.write(json4);
- memset(fff.sDbBasePath, 0, 520);
- std::string str = sz_file_name4;
- strncpy(fff.sDbBasePath, str.c_str(), str.length() + 1);
-
- //std::async(std::launch::async, [cpd](){
- CWnd *pWnd = NULL;
- pWnd = CWnd::FindWindow(NULL, _T("知心慧学学管系统"));
- if (pWnd){
- int ret = pWnd->SendMessage(WM_COPYDATA, NULL, (LPARAM)&cpd); // 发送
- }
- //});
- }
- uint kegunti_orgin_count(0); // 客观题原始题数
- uint kegunti_empty_count(0); // 客观题未作答题数
- {
- for (int p = 0; p < paper_page_count; p++)
- {
- int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
- OMR_RESULT* omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- if (omr_result->identified)
- {
- if (pUnhandledPageInfo->bOnlineCard)
- {
- kegunti_orgin_count += omr_result->group_result.size();
- for (int i = 0; i < omr_result->group_result.size(); i++)
- {
- if (omr_result->group_result[i].answer.length() == 0)
- {
- kegunti_empty_count++;
- }
- }
- }
- else
- {
- const std::vector<KEGUANTI_RESULT_HANDLE_INFO>& keguantiHandleInfo = m_handInfoMap[omr_result->card_index].keguantiHandleInfo;
- for (int m = 0; m < keguantiHandleInfo.size(); m++)
- {
- const std::vector<int> & group_index = keguantiHandleInfo[m].group_index;
- const std::vector<int> & group_question_count = keguantiHandleInfo[m].group_question_count;
- for (int idx_g = 0, idx_q = 0; idx_g < group_index.size(); idx_g++)
- {
- for (int idx_g_i = 0; idx_g_i < group_question_count[idx_g]; idx_g_i++, idx_q++)
- {
- int i = group_index[idx_g];
- kegunti_orgin_count++;
- if (omr_result->group_result[i].answer.length() == 0)
- {
- kegunti_empty_count++;
- }
- }
- }
- }
- }
- }
- }
- }
- std::string strquestioncode = "";
- for (int p = 0; p<paper_page_count; p++)
- {
- int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- int len = sprintf_s(phy_number, "%d", omr_result->phy_card_number);
- CppSQLite3Statement stmt = bantch_db->compileStatement("INSERT INTO page (identified,phy_number,page_index,img_path,img_oldpath,student_paper_id) VALUES (:identified,:phy_number,:page_index,:img_path,:img_oldpath,:student_paper_id)");
- stmt.bind(":identified", omr_result->identified);
- stmt.bind(":phy_number", phy_number);
- stmt.bind(":page_index", omr_result->card_index);
- stmt.bind(":img_path", omr_result->img_path.c_str());
- stmt.bind(":img_oldpath", omr_result->img_oldpath.c_str());
- stmt.bind(":student_paper_id", student_paper_id);
- stmt.execDML();
- CppSQLite3Query query = bantch_db->execQuery("select last_insert_rowId() from page");
- int page_id = query.getIntField(0);
- page_ids.push_back(page_id);
- int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE;
- UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index];
- if (omr_result->identified){
- for (int i = 0; i < omr_result->qr_result.size(); i++)
- {
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":type", RT_CODE);
- stmt2.bind(":answer", omr_result->qr_result[i].qr_str.c_str());
- stmt2.bind(":score", 0);
- stmt2.bind(":score_paper", 0);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- if (pUnhandledPageInfo->bOnlineCard){
- /*******************************保存缺考标记**************************************************/
- if (!bInsertQuekaobiao){
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":type", RT_QUEKAOBIAOJI);
- stmt2.bind(":answer", omr_result->quekaoFlag ? "1" : "0");
- stmt2.bind(":score", 0);
- stmt2.bind(":score_paper", 0);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- bInsertQuekaobiao = true;
- }
- /*******************************保存客观题**************************************************/
- for (int i = 0; i < omr_result->group_result.size(); i++)
- {
- float score = scoreCounter.GetScore(omr_result->group_result[i].question_code, omr_result->group_result[i].answer, 0, 0);
- total_score += score;
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- if (omr_result->group_result[i].omr_question_type == identify::DANXUANTI){
- stmt2.bind(":type", RT_KEGUANTI);
- }
- else{
- stmt2.bind(":type", RT_KEGUANTI_EX);
- }
- q_std answer_std = scoreCounter.get_std(omr_result->group_result[i].question_code); // 取出标准答案题
- if (kegunti_orgin_count > 0 && kegunti_orgin_count == kegunti_empty_count ||
- (answer_std.question_type == DANXUANTI && omr_result->group_result[i].answer == answer_std.answer_all))
- {
- if (!(exceptions & EX_KEGUANTIYICHANG) && g_my_scan_type != 1 && g_my_scan_type != 2)
- {
- exceptions |= EX_KEGUANTIYICHANG;
- }
- }
- stmt2.bind(":answer", omr_result->group_result[i].answer.c_str());
- stmt2.bind(":score", score);
- stmt2.bind(":question_code", omr_result->group_result[i].question_code.c_str());
- stmt2.bind(":score_paper", score);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- }
- else{
- /*******************************保存缺考标记**************************************************/
- const std::vector<QUEKAOBIAOJI_RESULT_HANDLE_INFO>& quekaoHandleInfo = m_handInfoMap[omr_result->card_index].quekaoHandleInfo;
- for (int i = 0; i < quekaoHandleInfo.size(); i++)
- {
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":type", RT_QUEKAOBIAOJI);
- stmt2.bind(":answer", omr_result->group_result[quekaoHandleInfo[i].group_index[0]].answer.c_str());
- stmt2.bind(":score", 0);
- stmt2.bind(":score_paper", 0);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- /*******************************保存AB卷标记**************************************************/
- const std::vector<ABJUAN_RESULT_HANDLE_INFO>& abjuanHandleInfo = m_handInfoMap[omr_result->card_index].abjuanHandleInfo;
- for (int i = 0; i < abjuanHandleInfo.size(); i++)
- {
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":type", RT_ABJUANBIAOJI);
- stmt2.bind(":answer", omr_result->group_result[abjuanHandleInfo[i].group_index[0]].answer.c_str());
- stmt2.bind(":score", 0);
- stmt2.bind(":score_paper", 0);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- /*******************************保存填涂考号**************************************************/
- const std::vector<TIANTUKAOHAO_RESULT_HANDLE_INFO>& tiantukaohaoHandleInfo = m_handInfoMap[omr_result->card_index].tiantukaohaoHandleInfo;
- for (int i = 0; i < tiantukaohaoHandleInfo.size(); i++)
- {
- std::string kaohao;
- if (g_my_scan_type == 1)
- {
- kaohao = g_strShoolId;
- }
- for (int j = 0; j < tiantukaohaoHandleInfo[i].group_index.size(); j++)
- {
- kaohao += omr_result->group_result[tiantukaohaoHandleInfo[i].group_index[j]].answer;
- }
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":type", RT_TIANTUKAOHAO);
- stmt2.bind(":answer", kaohao.c_str());
- stmt2.bind(":score", 0);
- stmt2.bind(":score_paper", 0);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- }
- /*******************************保存填空题**************************************************/
- for (int i = 0; i < omr_result->tiankongti_result.size(); i++)
- {
- float score = 0.0;
- //std::string strscores = "";
- if (strquestioncode == omr_result->tiankongti_result[i].question_code)
- {
- //相同题号,一定是小题号,不用再统计
- continue;
- }
- if (!pUnhandledPageInfo->bOnlineCard ||
- omr_result->tiankongti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::TIANKONGTI){
- if (omr_result->tiankongti_result[i].maxscore > 0)
- {
- //strscores = std::to_string(omr_result->tiankongti_result[i].question_score);
- score += omr_result->tiankongti_result[i].question_score;
- strquestioncode = omr_result->tiankongti_result[i].question_code;
- bool bneedcountiefind = true;
- //同页对比
- for (int j = i + 1; j < omr_result->tiankongti_result.size(); j++)
- {
- if (omr_result->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
- {
- //strscores += ",";
- //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
- score += omr_result->tiankongti_result[j].question_score;
- }
- else
- {
- bneedcountiefind = false;
- }
- }
- if (bneedcountiefind)
- {
- //跨页对比
- bool bstopflag = false;
- for (int q = p + 1; q < paper_page_count; q++)
- {
- if (bstopflag)
- break;
- int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result;
- for (int j = 0; omr_result1->tiankongti_result.size(); j++)
- {
- if (omr_result1->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
- {
- //strscores += ",";
- //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
- score += omr_result1->tiankongti_result[j].question_score;
- }
- else
- {
- bstopflag = true;
- break;
- }
- }
- }
- }
- score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, score);
- }
- else
- {
- score = scoreCounter.GetScore(omr_result->tiankongti_result[i].question_code, "", omr_result->tiankongti_result[i].isright, 0);
- }
- }
- if (pUnhandledPageInfo->bOnlineCard &&
- omr_result->tiankongti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::TIANKONGTI2){
- if (omr_result->tiankongti_result[i].maxscore > 0)
- {
- //strscores = std::to_string(omr_result->tiankongti_result[i].question_score);
- score += omr_result->tiankongti_result[i].question_score;
- strquestioncode = omr_result->tiankongti_result[i].question_code;
- bool bneedcountiefind = true;
- //同页对比
- for (int j = i + 1; j<omr_result->tiankongti_result.size(); j++)
- {
- if (omr_result->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
- {
- //strscores += ",";
- //strscores += std::to_string(omr_result->tiankongti_result[i].question_score);
- score += omr_result->tiankongti_result[j].question_score;
- }
- else
- {
- bneedcountiefind = false;
- }
- }
- if (bneedcountiefind)
- {
- //跨页对比
- bool bstopflag = false;
- for (int q = p + 1; q < paper_page_count; q++)
- {
- if (bstopflag)
- break;
- int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result;
- for (int j = 0; j < omr_result1->tiankongti_result.size(); j++)
- {
- if (omr_result1->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
- {
- //strscores += ",";
- //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
- score += omr_result1->tiankongti_result[j].question_score;
- }
- else
- {
- bstopflag = true;
- break;
- }
- }
- }
- }
- score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, score);
- }
- else
- {
- score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, omr_result->tiankongti_result[i].question_score);
- }
- }
- total_score += score;
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":type", RT_TIANKONGTI);
- stmt2.bind(":answer", "");
- stmt2.bind(":score", score);
- stmt2.bind(":isright", omr_result->tiankongti_result[i].isright);
- stmt2.bind(":question_code", omr_result->tiankongti_result[i].question_code.c_str());
- stmt2.bind(":score_paper", score);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- int loupi_count = 0;
- int wufashibie_count = 0;
- int wupan_count = 0;
- /*******************************保存主观题**************************************************/
- for (int i = 0; i<omr_result->zhutuanti_result.size(); i++)
- {
- if (strquestioncode == omr_result->zhutuanti_result[i].question_code)
- {
- //相同题号,一定是小题号,不用再统计
- continue;
- }
- float score = 0;
- if (omr_result->zhutuanti_result[i].maxscore > 0)
- {
- score += omr_result->zhutuanti_result[i].question_score;
- strquestioncode = omr_result->zhutuanti_result[i].question_code;
- bool bneedcountiefind = true;
- //同页对比
- for (int j = i + 1; j<omr_result->zhutuanti_result.size(); j++)
- {
- if (omr_result->zhutuanti_result[j].question_code == omr_result->zhutuanti_result[i].question_code)
- {
- //strscores += ",";
- //strscores += std::to_string(omr_result->tiankongti_result[i].question_score);
- score += omr_result->zhutuanti_result[j].question_score;
- }
- else
- {
- bneedcountiefind = false;
- }
- }
- if (bneedcountiefind)
- {
- //跨页对比
- bool bstopflag = false;
- for (int q = p + 1; q < paper_page_count; q++)
- {
- if (bstopflag)
- break;
- int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result;
- for (int j = 0; j < omr_result1->zhutuanti_result.size(); j++)
- {
- if (omr_result1->zhutuanti_result[j].question_code == omr_result->zhutuanti_result[i].question_code)
- {
- //strscores += ",";
- //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
- score += omr_result1->zhutuanti_result[j].question_score;
- }
- else
- {
- bstopflag = true;
- break;
- }
- }
- }
- }
- score = scoreCounter.GetScore(omr_result->zhutuanti_result[i].question_code, "", 0, score);
- }
- else
- {
- score = scoreCounter.GetScore(omr_result->zhutuanti_result[i].question_code, "", 0, omr_result->zhutuanti_result[i].question_score);
- }
- total_score += score;
- stmt2.reset();
- if (pUnhandledPageInfo->bOnlineCard &&
- omr_result->zhutuanti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::XUANZUOTI){
- std::string strTotal = std::to_string(omr_result->zhutuanti_result[i].total),
- strRequired = std::to_string(omr_result->zhutuanti_result[i].required),
- strAllQuestions = omr_result->zhutuanti_result[i].question_code_all,
- strXuanz = std::to_string(omr_result->zhutuanti_result[i].xuanze);
- std::string real_name;
- auto it_find = _map_real_name.find(omr_result->zhutuanti_result[i].question_code);
- if (it_find != _map_real_name.end()){
- real_name = it_find->second;
- }
- std::string str_tmp = strAllQuestions + "@" + strXuanz + "@" + strTotal + "@" + strRequired + "@" + real_name;
- stmt2.bind(":answer", str_tmp.c_str());
- stmt2.bind(":type", RT_XUANZUOTI);
- }
- else{
- stmt2.bind(":answer", "");
- stmt2.bind(":type", scoreCounter.get_std(omr_result->zhutuanti_result[i].question_code).question_type == schema::BIZUOTI ? RT_BIZUOTI : RT_ZHUGUANTI);
- }
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":score", score);
- stmt2.bind(":question_code", omr_result->zhutuanti_result[i].question_code.c_str());
- stmt2.bind(":score_paper", omr_result->zhutuanti_result[i].question_score);
- QUESTION_STATE question_state = QUESTION_STATE_NORMAL;
- if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_LOUPI){ loupi_count++; question_state = QUESTION_STATE_LOUPI; }
- if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_WUFASHIBIE){ wufashibie_count++; question_state = QUESTION_STATE_WUFASHIBIE; }
- if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_NORMAL&&omr_result->zhutuanti_result[i].question_score - score>0.1){ wupan_count++; question_state = QUESTION_STATE_WUPAN; }
- stmt2.bind(":question_state", question_state);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- /*******************************保存选做题**************************************************/
- if (!pUnhandledPageInfo->bOnlineCard){
- const std::vector<XUANZUOTI_RESULT_HANDLE_INFO>& xuanzuotiHandleInfo = m_handInfoMap[omr_result->card_index].xuanzuotiHandleInfo;
- for (int i = 0; i < xuanzuotiHandleInfo.size(); i++)
- {
- for (int index_group = 0; index_group < xuanzuotiHandleInfo[i].group_index.size(); index_group++)
- {
- const char * answer = omr_result->group_result[xuanzuotiHandleInfo[i].group_index[index_group]].answer.c_str();
- //if (omr_result->group_result[xuanzuotiHandleInfo[i].group_index[index_group]].answer == "")
- // answer = omr_result->cut_area_result[omr_result->cut_area_result.size() - index_group - 1].area_name.c_str();
- const std::vector<std::string>& mark_units = xuanzuotiHandleInfo[i].mark_unit[index_group];
- const std::vector<std::vector<std::string>>& option_question_code = xuanzuotiHandleInfo[i].option_question_code[index_group];
- int xuantishu = xuanzuotiHandleInfo[i].xuantishu[index_group];
- const std::vector<std::string>& mark_unit_question_codes = xuanzuotiHandleInfo[i].mark_unit_question_code[index_group];
- vector<string> answers;
- split(answer, ",", &answers);
- int selected_count = 0;
- vector<bool> option_selected(option_question_code.size(), false);
- vector<bool> option_selected_valid(option_question_code.size(), false);
- int selected_option_count = 0;
- for (int idx_o = 0; idx_o < option_question_code.size(); idx_o++)
- {
- bool found = false;
- for (int idx_o_q = 0; !found&&idx_o_q < option_question_code[idx_o].size(); idx_o_q++)
- {
- for (int idx_a = 0; !found&&idx_a < answers.size(); idx_a++)
- {
- if (option_question_code[idx_o][idx_o_q] == answers[idx_a]){ found = true; }
- }
- }
- if (found){ option_selected[idx_o] = true; selected_option_count++; }
- }
- bool bIsEmpty = true;
- for (int j = 0; j < option_selected.size(); j++)
- {
- if (option_selected[j] == true)
- bIsEmpty = false;
- }
- if (bIsEmpty)
- option_selected[0] = true;
- for (int idx_o = 0, s_count = 0; s_count < xuantishu&&idx_o < option_selected.size(); idx_o++)
- {
- if (!option_selected[idx_o])continue;
- option_selected_valid[idx_o] = true; s_count++;
- for (int idx_o_q = 0; idx_o_q < option_question_code[idx_o].size(); idx_o_q++)
- {
- question_selected[option_question_code[idx_o][idx_o_q]] = true;
- }
- }
- for (int index_markunit = 0; index_markunit < mark_units.size(); index_markunit++)
- {
- vector<string> markunit_questioncode;
- split(mark_unit_question_codes[index_markunit], ",", &markunit_questioncode);
- std::string question_code_selected;
- for (int index2 = 0; index2 < markunit_questioncode.size(); index2++)
- {
- for (int index_option = 0; index_option < option_question_code.size(); index_option++)
- {
- if (!option_selected_valid[index_option])continue;
- const std::vector<std::string>& option_question = option_question_code[index_option];
- for (int index_option_q = 0; index_option_q < option_question.size(); index_option_q++)
- {
- if (option_question[index_option_q] == markunit_questioncode[index2]){
- if (question_code_selected.length() > 0){
- question_code_selected.append(",");
- }
- question_code_selected.append(option_question[index_option_q]);
- break;
- }
- }
- }
- }
- stmt2.reset();
- stmt2.bind(":page_id", page_id);
- stmt2.bind(":type", RT_XUANZUOTI);
- stmt2.bind(":answer", question_code_selected.c_str());
- stmt2.bind(":score", 0);
- stmt2.bind(":question_code", mark_units[index_markunit].c_str());
- stmt2.bind(":score_paper", 0);
- stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- }
- }
- }
- }
- else{
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":page_id", page_id);
- stmt3.bind(":exception_type", SHIFT_DINGWEIDIAN);
- stmt3.bind(":exception_name", "定位点异常");
- stmt3.execDML();
- exceptions |= EX_DINGWEIDIAN;
- }
- }
- if (!pUnhandledPageInfo->bOnlineCard)
- {
- for (int p = 0; p<paper_page_count; p++)
- {
- int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
- OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
- int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE;
- UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index];
- if (omr_result->identified)
- {
- /*******************************保存客观题**************************************************/
- int loutu_count = 0;
- const std::vector<KEGUANTI_RESULT_HANDLE_INFO>& keguantiHandleInfo = m_handInfoMap[omr_result->card_index].keguantiHandleInfo;
- for (int m = 0; m<keguantiHandleInfo.size(); m++)
- {
- const std::vector<int> & group_index = keguantiHandleInfo[m].group_index;
- const std::vector<int> & group_question_count = keguantiHandleInfo[m].group_question_count;
- const std::vector<std::string> & question_code = keguantiHandleInfo[m].question_code;
- for (int idx_g = 0, idx_q = 0; idx_g<group_index.size(); idx_g++)
- {
- for (int idx_g_i = 0; idx_g_i<group_question_count[idx_g]; idx_g_i++, idx_q++)
- {
- int i = group_index[idx_g];
- float score = scoreCounter.GetScore(question_code[idx_q], omr_result->group_result[i].answer, 0, 0);
- bool isSelected = false;
- bool isLoutu = false;
- if (strcmp("*", omr_result->group_result[i].answer.c_str()) == 0){ loutu_count++; isLoutu = true; }
- if (question_selected.find(question_code[idx_q]) == question_selected.end() || question_selected[question_code[idx_q]]){//不是选做题或者是选中的选做题 加入到总分
- total_score += score;
- isSelected = true;
- }
-
- q_std answer_std = scoreCounter.get_std(question_code[idx_q]); // 取出标准答案题
- if (kegunti_orgin_count > 0 && kegunti_orgin_count == kegunti_empty_count ||
- (answer_std.question_type == DANXUANTI && omr_result->group_result[i].answer == answer_std.answer_all))
- {
- if (!(exceptions & EX_KEGUANTIYICHANG) && g_my_scan_type != 1 && g_my_scan_type != 2)
- {
- exceptions |= EX_KEGUANTIYICHANG;
- }
- }
- stmt2.bind(":page_id", page_ids[p]);
- if (answer_std.question_type == DANXUANTI)
- stmt2.bind(":type", RT_KEGUANTI);
- else
- stmt2.bind(":type", RT_KEGUANTI_EX);
- stmt2.bind(":answer", omr_result->group_result[i].answer.c_str());
- stmt2.bind(":score", score);
- stmt2.bind(":question_code", question_code[idx_q].c_str());
- stmt2.bind(":score_paper", score);
- int question_state = isSelected ? (isLoutu ? QUESTION_STATE_LOUTU : QUESTION_STATE_NORMAL) : (isLoutu ? QUESTION_STATE_UNSELECT_LOUTU : QUESTION_STATE_UNSELECT);
- stmt2.bind(":question_state", question_state);
- stmt2.bind(":student_paper_id", student_paper_id);
- stmt2.execDML();
- }
- /*
- int reuslt_id=bantch_db->execScalar("select last_insert_rowId() from result");
- for(int k=0;k<options.len;k++){
- char feature[1024];
- float* features =options[k].features;;
- sprintf_s(feature,"{%ff,%ff,%ff,%ff,%ff,%ff,%ff,%ff,%ff}",features[0],features[1],features[2],features[3],features[4],features[5],features[6],features[7],features[8]);
- stmt4.bind(":result_id",reuslt_id);
- stmt4.bind(":option_idx",k);
- stmt4.bind(":feature",feature);
- stmt4.execDML();
- }*/
- }
- }
- /*******************************保存异常信息**************************************************/
- if (FALSE&&loutu_count>0){//商讨决定不再抛出该异常
- stmt3.bind(":student_paper_id", student_paper_id);
- stmt3.bind(":page_id", page_ids[p]);
- stmt3.bind(":exception_type", SHIFT_LOUTU);
- stmt3.bind(":exception_name", "考生漏涂");
- stmt3.execDML();
- }
- }
- }
- }
- CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id ,message_type,identified,class_id,class_total,exceptions,class_info,score,student_id,student_name,examnumber) VALUES (:student_paper_id,:message_type,:identified,:class_id,:class_total,:exceptions,:class_info,:score,:student_id,:student_name,:examnumber)");
- stmt4.bind(":student_paper_id", student_paper_id);
- stmt4.bind(":message_type", isupdate ? WM_IDENTIFOR_PAPER_STATE_CHAGED : WM_IDENTIFOR_REPORT);
- stmt4.bind(":identified", identified);
- stmt4.bind(":class_id", class_id);
- stmt4.bind(":class_total", class_total);
- stmt4.bind(":class_info", class_info);
- stmt4.bind(":exceptions", exceptions);
- stmt4.bind(":score", total_score);
- stmt4.bind(":student_id", student_id.c_str());
- stmt4.bind(":student_name", student_name);
- stmt4.bind(":examnumber", studentcode.c_str());
- stmt4.execDML();
- char sql3[512];
- sprintf_s(sql3, "update student_paper set paper_state = %d,score_total= %f where student_paper_id = %d", exceptions, total_score, student_paper_id);
- bantch_db->execDML(sql3);
- bantch_db->execDML("commit transaction");
- LeaveCriticalSection(db_lock);
- }
- catch (...){
- bantch_db->execDML("rollback transaction");
- LeaveCriticalSection(db_lock);
- OutputDebugString(_T("IResultHandler.SavePaper.catch CppSQLite3Exception"));
- }
-
- IDENTIFY_MSG * msg = new IDENTIFY_MSG;
- msg->class_id = class_id;
- msg->class_total = class_total;
- strcpy(msg->class_info, class_info);
- msg->exceptions = exceptions;
- msg->identified = identified;
- msg->paper_id = student_paper_id;
- msg->score = total_score;
- msg->student_id = -1;// student_id;
- msg->locationID = g_myindex;
- strcpy(msg->student_name, student_name);
- strcpy(msg->examnumber, studentcode.c_str());
- if (m_hwnd != NULL)
- {
- if (isupdate)
- {
- if (m_bUseQr){
- if (((exceptions & EX_KAOHAODAIPIPEI) == 0))
- ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)student_paper_id);
- if (!pUnhandledPageInfo->bOnlineCard){
- }
- }
- }
- else
- {
- //printf("WM_IDENTIFOR_REPORT:%d\n",msg->paper_id);
- ::PostMessage(m_hwnd, WM_IDENTIFOR_REPORT, (WPARAM)msg, NULL);
- }
- }
- for (int m = 0; m < paper_page_count; m++)
- {
- int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
- if (pUnhandledPageInfo->bOnlineCard){
- static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result);
- }
- else{
- unhandledPageInfo.result->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result);
- }
- }
- unhandledPageInfo.first_unhandled_page_index = (unhandledPageInfo.first_unhandled_page_index + paper_page_count) % MAX_UNHANDLED_PAGE;
- unhandledPageInfo.unhandled_page_count -= paper_page_count;
- }
- void CResultHandler::SaveImages(vector<CUT_AREA_RESULT*> &area_results, CMemZipFile &zip, int subjectID, BOOL bOnlineCard, char *strPaperCode, const std::vector<std::string> &postMarkTypeIDVec, std::map<std::string, int> &vecTwoPic)
- {
- CString question_code;
- question_code.Format(_T("%s.jpg"), CString(area_results[0]->area_name.c_str()));
- zip.PutNextEntry(question_code);
- std::sort(area_results.begin(), area_results.end(), sort_subindex);
- //postMarkTypeID == 10 判断
- BOOL flag = false;
- for (int i = 0; i < postMarkTypeIDVec.size(); i++)
- {
- for (int j = 0; j < area_results.size(); j++){
- if (postMarkTypeIDVec[i] == area_results[j]->area_name)
- {
- flag = true;
- break;
- }
- }
- }
- vector<int> compression_params_low;
- compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_low.push_back(40);
- vector<int> compression_params_high;
- compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_high.push_back(60);
- int width = 0;
- int height = 0;
- int centerx = 0, centery = 0;
- for (int jj = 0; jj<area_results.size(); jj++)
- {
- if (area_results[jj]->width>width)width = area_results[jj]->width;
- height += area_results[jj]->height;
- centerx = area_results[jj]->centerx;
- centery += area_results[jj]->centery;
- }
- IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
- cvSet(img, cvScalarAll(255));
- for (int ii = 0, top = 0; ii < area_results.size(); ii++)
- {
- Mat ff = Mat(1, area_results[ii]->img_data.size(), CV_8U, area_results[ii]->img_data.data());
- Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
- cvSetImageROI(img, cvRect(0, top, temp_img.cols, temp_img.rows));
- cvCopy(&IplImage(temp_img), img);
- top += area_results[ii]->height;
- }
- cvResetImageROI(img);
- vector<uchar> dst;
- cv::Mat _img = cv::cvarrToMat(img);
- if (img->height > 500){
- imencode(".jpg", _img, dst, compression_params_low);
- }
- else{
- imencode(".jpg", _img, dst, compression_params_high);
- }
- char sz_question_code[520] = { 0 };
- WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
- cvReleaseImage(&img);
- zip.Write(&dst[0], dst.size());
- if (flag && area_results.size() >1){
- for (int jj = 0; jj < area_results.size(); jj++)
- {
- question_code.Format(_T("%s_%d.jpg"), CString(area_results[0]->area_name.c_str()), jj + 1);
- zip.PutNextEntry(question_code);
- width = area_results[jj]->width;
- height = area_results[jj]->height;
- IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
- cvSet(img, cvScalarAll(255));
- //for (int ii = 0, top = 0; ii < area_results.size(); ii++)
- //{
- Mat ff = Mat(1, area_results[jj]->img_data.size(), CV_8U, area_results[jj]->img_data.data());
- Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
- cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
- cvCopy(&IplImage(temp_img), img);
- //top += area_results[ii]->height;
- //}
- cvResetImageROI(img);
- char sz_question_code[520] = { 0 };
- WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
- vector<uchar> dst;
- cv::Mat _img = cv::cvarrToMat(img);
- if (img->height > 500){
- imencode(".jpg", _img, dst, compression_params_low);
- }
- else{
- imencode(".jpg", _img, dst, compression_params_high);
- }
- cvReleaseImage(&img);
- zip.Write(&dst[0], dst.size());
- }
- vecTwoPic[area_results[0]->area_name.c_str()] = area_results.size();
- }
- }
- void CResultHandler::setHandlInfo(const boost::shared_ptr<const HANDLE_INFO>& handInfo)
- {
- m_handInfo = handInfo;
- std::map<int, const PAGE_RESULT_HANDLE_INFO> handInfoMap;
- for (int i = 0; i<m_handInfo->size(); i++)
- {
- const PAGE_RESULT_HANDLE_INFO & p = (*m_handInfo)[i];
- std::map<int, const PAGE_RESULT_HANDLE_INFO>::value_type v(p.page_index, p);
- handInfoMap.insert(v);
- }
- m_handInfoMap = handInfoMap;
- }
- bool CResultHandler::existAbsentFlag(OMR_RESULT * omr_result)
- {
- const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
- return handleInfo.quekaoHandleInfo.size()>0;
- }
- std::string CResultHandler::absentFlag(OMR_RESULT * omr_result)
- {
- const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
- const std::vector<QUEKAOBIAOJI_RESULT_HANDLE_INFO>& quekaoHandleInfo = handleInfo.quekaoHandleInfo;
- if (quekaoHandleInfo.size()>0)return omr_result->group_result[quekaoHandleInfo[0].group_index[0]].answer;
- return "";
- }
- bool CResultHandler::existABJuanFlag(OMR_RESULT * omr_result)
- {
- const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
- return handleInfo.abjuanHandleInfo.size()>0;
- }
- bool CResultHandler::existABJuanFlag()
- {
- for (int i = 0; i<m_handInfo->size(); i++)
- {
- if ((*m_handInfo)[i].abjuanHandleInfo.size()>0)return true;
- }
- return false;
- }
- std::string CResultHandler::ABJuanFlag(OMR_RESULT * omr_result)
- {
- const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
- const std::vector<ABJUAN_RESULT_HANDLE_INFO>& abjuanHandleInfo = handleInfo.abjuanHandleInfo;
- if (abjuanHandleInfo.size()>0)return omr_result->group_result[abjuanHandleInfo[0].group_index[0]].answer;
- return "";
- }
- void CResultHandler::IdentifyTaskManager(CIdentifyTaskManager* taskManager)
- {
- this->taskManager = taskManager;
- }
- BOOL CResultHandler::SupportPause(void)
- {
- return TRUE;
- }
- ServiceState CResultHandler::OnPausing(void)
- {
- return IService::OnPausing();
- }
- void CResultHandler::SetIdentifyService(CIdentifyService* service)
- {
- identifyService = service;
- }
- bool CResultHandler::readPaperId(CString& strPaperId)
- {
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- 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("paperInfo.ini"));
- WCHAR PaperId[512];
- GetPrivateProfileString(_T("paperinfo"), _T("paper_str"), _T(""), PaperId, 512, FilePath);
- strPaperId = PaperId;
- return false;
- }
- void CResultHandler::readOnlineCardPaperId(string strPaperCode, string strStudentId)
- {
- wstring strCode = AnsiToUnicode(strPaperCode);
- wstring strKey = AnsiToUnicode(strStudentId);
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- 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("magic\\"));
- lstrcat(FilePath, strCode.c_str());
- lstrcat(FilePath, _T("magic.ini"));
- WCHAR PaperId[512];
- GetPrivateProfileString(_T("paperinfo"), strKey.c_str(), _T(""), PaperId, 512, FilePath);
- m_strOnlineCardPaperId = UnicodeToAnsi(PaperId);
- }
- void CResultHandler::WriteOnlineCardPaperId(CString strPaperCode, wstring& strSubGroupId, wstring strStudentId)
- {
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- 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("magic\\"));
- lstrcat(FilePath, strPaperCode);
- lstrcat(FilePath, _T("magic.ini"));
- WritePrivateProfileString(_T("paperinfo"), strStudentId.c_str(), strSubGroupId.c_str(), FilePath);
- }
- bool CResultHandler::readTimu(CString& strTimu)
- {
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- 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("paperInfo.ini"));
- WCHAR Timu[512];
- GetPrivateProfileString(_T("paperinfo"), _T("timu_info"), _T(""), Timu, 512, FilePath);
- strTimu = Timu;
- return false;
- }
- bool CResultHandler::loadSchema()
- {
- CString strFileName;
- if (g_my_scan_type == 0)
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- strFileName = FilePath;
- strFileName += _T("\\1111.zip");
- }
- //else
- else if (g_my_scan_type == 1)
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- TCHAR FileName[50];
- _stprintf(FileName, _T("\\mode\\student%d.schema"), g_myindex);
- lstrcat(FilePath, FileName);
- strFileName = FilePath;
- }
- else if (g_my_scan_type == 2)
- {
- TCHAR cfgPath[MAX_PATH];
- GetModuleFileName(NULL, cfgPath, MAX_PATH);
- (_tcsrchr(cfgPath, '\\'))[1] = 0;
- lstrcat(cfgPath, _T("config.ini"));
- TCHAR schoolID[64] = { 0 };
- GetPrivateProfileString(_T("USER"), _T("schoolId"), _T(""), schoolID, sizeof(schoolID) / sizeof(TCHAR), cfgPath);
- TCHAR __version[64] = { 0 };
- GetPrivateProfileString(_T("USER"), _T("tifenbaoversion"), _T(""), __version, sizeof(__version) / sizeof(TCHAR), cfgPath);
- CString version = __version;
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- CString strPath;
- if (CString(schoolID).GetLength() == 4){
- if (version.IsEmpty()){
- strPath += "/mode/tifenbaoZixuanka-9.3.0.schema";
- }
- else{
- strPath += "/mode/tifenbaoZixuanka-9.3.3.schema";
- }
- }
- else{
- if (version.IsEmpty()){
- strPath += "/mode/tifenbaoZixuanka-8.3.0.schema";
- }
- else{
- strPath += "/mode/tifenbaoZixuanka-8.3.3.schema";
- }
- }
- strFileName = CString(FilePath) + strPath;
- }
- CUnZipFile uzip(strFileName);
- std::map<CString, std::vector<unsigned char>> map;
- while (uzip.HasMoreEntry()){
- CString fileNam;
- uzip.GetNextEntry(fileNam);
- char buffer[1024 * 8];
- int len;
- std::vector<unsigned char>& data = map[fileNam];
- data.reserve(1024 * 128);
- while ((len = uzip.Read(buffer, 1024 * 8))>0){
- if (data.capacity()<data.size() + len){
- int c = data.capacity() + 1024 * 128;
- data.reserve(c);
- }
- int oldSize = data.size();
- data.resize(oldSize + len);
- char * dst = (char *)data.data() + oldSize;
- memcpy(dst, buffer, len);
- }
- }
- uzip.Close();
- std::map<CString, std::vector<unsigned char>>::iterator schemabytes = map.find(_T("schema.bytes"));
- if (schemabytes == map.end()){
- return false;
- }
- SCHEMA_VERSION version;
- std::vector<unsigned char>& data = schemabytes->second;
- serializor::SchemJsonSerializor::deserialize(std::string((char *)data.data(), data.size()), m_schema, version);
- if (m_schema.state == 0) return SCH_LOAD_ERR_ZHUANGTAIBUZHENGQUE;
- return true;
- }
- void CResultHandler::SavePathImg(std::string path, CMemZipFile &zip, int i){
- IplImage* pImg = cvLoadImage(path.c_str(), 1);
- CString question_code;
- question_code.Format(_T("image_%d.jpg"), i + 1);
- zip.PutNextEntry(question_code);
- vector<uchar> dst;
- vector<int> compression_params_low;
- compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_low.push_back(40);
- vector<int> compression_params_high;
- compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_high.push_back(60);
- cv::Mat _img = cv::cvarrToMat(pImg);
- if (pImg->height > 500){
- imencode(".jpg", _img, dst, compression_params_low);
- }
- else{
- imencode(".jpg", _img, dst, compression_params_high);
- }
- cvReleaseImage(&pImg);
- zip.Write(&dst[0], dst.size());
- }
- #include <direct.h>
- void ThreadLog4(char* strLogContent, char* fileName)
- {
- char buf[200];
- _getcwd(buf, sizeof(buf));
- strcat_s(buf, "\\ThirdParty\\");
- strcat_s(buf, fileName);
- FILE *file = NULL;
- fopen_s(&file, buf, "at+");
- if (file == NULL)
- {
- // printf("路径错误\n");
- //system("pause");
- return;
- }
- fseek(file, 0, SEEK_END);
- char strLogTemp[5000];
- strcpy_s(strLogTemp, sizeof(strLogTemp), strLogContent);
- fwrite(&strLogTemp, strlen(strLogTemp), 1, file);
- fclose(file);
- }
- void CResultHandler::logForDbg(string strLog)
- {
- char logContent[300];
- char logName[300];
- char sYear[10], sMonth[5], sDay[25];
- SYSTEMTIME st;
- GetLocalTime(&st);
- int j0 = 0;
- int m_nYear = st.wYear; ///年
- int m_nMonth = st.wMonth; ///月
- int m_nDay = st.wDay; ///日
- int m_nHour = st.wHour; ///小时
- int m_nMinute = st.wMinute; ///分钟
- int m_nSecond = st.wSecond; ///秒
- int m_nMillSecond = st.wMilliseconds; ///毫秒
- char strTime[300];
- sprintf(strTime, "----------------------------------%d_%02d_%02d_%d_%02d_%02d", m_nYear, m_nMonth, m_nDay, m_nHour, m_nMinute, m_nSecond);
- strLog += strTime;
- sprintf_s(sYear, sizeof(sYear), "%d", m_nYear);
- sprintf_s(sMonth, sizeof(sMonth), "_%02d", m_nMonth);
- sprintf_s(sDay, sizeof(sDay), "_%02d_log.txt", m_nDay);
- strcpy(logName, sYear);
- strcat(logName, sMonth);
- strcat(logName, sDay);
- char strScore[MAX_PATH] = { 0 };
- for (int i = 0; i < strLog.size(); i++)
- strScore[i] = strLog.at(i);
- sprintf_s(logContent, sizeof(logContent), "%s\n", strScore);
- ThreadLog4(logContent, logName);
- }
- string CResultHandler::GetOnlineCardPaperId(string strPaperCode, string strStudentId)
- {
- //if (m_strOnlineCardPaperId.empty())
- readOnlineCardPaperId(strPaperCode, strStudentId);
- return m_strOnlineCardPaperId;
- }
|