BatchService - 副本.cpp 174 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563
  1. #include "StdAfx.h"
  2. #include "BatchService.h"
  3. #include "scan_common.h"
  4. #include "..\EvaluationUtil\HttpClient.h"
  5. #include "..\Schema\schema_struct.h"
  6. #include "SchemaLoader.h"
  7. #include "basic_struct_result.h"
  8. #include "..\Identifier\schema_struct.h"
  9. #include "ServerConfig.h"
  10. //#include "Log4cplusInitalizer.h"
  11. #include "TemplateManager.h"
  12. #include "resource.h"
  13. #include "IdentifyService.h"
  14. #include "ResultUploader.h"
  15. #include <direct.h>
  16. #include <time.h>
  17. #include "OnlineCardIdentifyService.h"
  18. #include <fstream>
  19. #include "../Identifier/OnLineCardSchemaStruct.h"
  20. #include "..\ZLibWrapMemLib\UnZipFile.h"
  21. #include "..\ZLibWrapMemLib\MemZipFile.h"
  22. #include "..\ZLibWrapLib\ZLibWrapLib.h"
  23. #include "OnlineCardStudentMatcher.h"
  24. #include "ResultUploader.h"
  25. #include <future>
  26. using namespace schema;
  27. using namespace OnLineCard;
  28. CString GetExePath()
  29. {
  30. HMODULE module = GetModuleHandle(0);
  31. TCHAR pFileName[MAX_PATH + 2] = { 0 };
  32. GetModuleFileName(module, pFileName, MAX_PATH);
  33. CString csFullPath(pFileName);
  34. int nPos = csFullPath.ReverseFind(_T('\\'));
  35. if (nPos < 0)
  36. return CString("");
  37. else
  38. return csFullPath.Left(nPos);
  39. }
  40. CString AnsiToUnicode(const std::string& str);
  41. std::string UnicodeToAnsi(const CString& str);
  42. int g_my_scan_type;//0答题卡 1督学卡
  43. int g_my_continue_scan = 0;
  44. //督学卡学校id
  45. std::string g_strShoolId;
  46. std::string g_strUpLoadDbPathName;
  47. int g_myindex = 1;
  48. extern int g_flagid;
  49. void ThreadLog2(char* ThreadName, char* fileName)
  50. {
  51. char buf[200];
  52. _getcwd(buf, sizeof(buf));
  53. strcat_s(buf, "\\ThirdParty\\");
  54. strcat_s(buf, fileName);
  55. FILE *file = NULL;
  56. fopen_s(&file, buf, "at+");
  57. if (file == NULL)
  58. {
  59. // printf("路径错误\n");
  60. //system("pause");
  61. return;
  62. }
  63. fseek(file, 0, SEEK_END);
  64. char bufThread[200];
  65. strcpy_s(bufThread, sizeof(bufThread), ThreadName);
  66. fwrite(&bufThread, strlen(bufThread), 1, file);
  67. fclose(file);
  68. }
  69. CBatchService::CBatchService(bool bOnlineCard, int nSubjectID, int nOnlineScanType)
  70. :m_bantch_state(DATABASE_STATE_CREATE),
  71. m_result_uploader(new CResultUploader()),
  72. m_bOnlineCard(bOnlineCard),
  73. m_nSubjectID(nSubjectID),
  74. m_nOnlineScanType(nOnlineScanType)
  75. {
  76. m_eventZXHXCreateDB = CreateEvent(NULL, false, false, NULL);
  77. m_result_uploader->EnableOnLineCard(m_bOnlineCard, m_nSubjectID, nOnlineScanType);
  78. m_upload_manager.m_pBatchService = this;
  79. m_onlineCardTemplate = new OnLineCard::PaperTemplate;
  80. InitializeCriticalSection(&bantch_db_lock);
  81. m_bErrorHandle = false;
  82. NetOperator::SetClientNotifyPtr(this);
  83. if (getRunFlag() == _T("1")){
  84. CString _ini_file = GetExePath() + _T("\\..\\config.ini");
  85. TCHAR sz_b_code[100] = { 0 };
  86. GetPrivateProfileString(_T("THRID"), _T("cur_bantch_code"), _T(""), sz_b_code, sizeof(sz_b_code) / sizeof(TCHAR), _ini_file);
  87. auto bantch_code = UnicodeToAnsi(sz_b_code);
  88. m_upload_manager.SetBatchCode(bantch_code);
  89. }
  90. LOGI("连接知心慧学");
  91. int nRet = NetOperator::InitClient("127.0.0.1", 99995, this);
  92. if (nRet==-1){
  93. LOGI("连接知心慧学已存在,无需再次连接");
  94. }
  95. else if (nRet<0){
  96. LOGE("连接知心慧学-ERROR");
  97. }
  98. else{
  99. LOGI("连接知心慧学-SUCCESS");
  100. }
  101. }
  102. CBatchService::~CBatchService(void)
  103. {
  104. if (m_coverd_all_kaohaochongtu.valid()){
  105. LOGI("等待覆盖所有考号冲突线程退出");
  106. m_coverd_all_kaohaochongtu.wait();
  107. LOGI("覆盖所有考号冲突线程退出");
  108. }
  109. if (m_onlineCardTemplate)
  110. delete m_onlineCardTemplate;
  111. m_onlineCardTemplate = nullptr;
  112. DeleteCriticalSection(&bantch_db_lock);
  113. CloseHandle(m_eventZXHXCreateDB);
  114. NetOperator::SetClientNotifyPtr(NULL);
  115. }
  116. //开始扫描处理函数
  117. ServiceState CBatchService::OnStarting(void)
  118. {
  119. char sql[512];
  120. sprintf_s(sql, "update database set database_state =%d where database_id =%d", DATABASE_STATE_SCANNING, m_database_id);
  121. EnterCriticalSection(database_db_lock);
  122. database_db->execDML("begin transaction");
  123. database_db->execDML(sql);
  124. database_db->execDML("commit transaction");
  125. LeaveCriticalSection(database_db_lock);
  126. mainService->SetHandlerWnd(m_hwnd);
  127. mainService->Start();
  128. while (mainService->GetServiceSate()== starting)
  129. {
  130. Sleep(10);
  131. }
  132. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_STARTED, 0, 0);
  133. return running;
  134. }
  135. ServiceState CBatchService::OnRunning(void)
  136. {
  137. ServiceState nextState = IService::OnRunning();
  138. if (nextState == pausing) return nextState;
  139. if (nextState == stoping) return nextState;
  140. if (mainService->GetServiceSate()==stoped){
  141. return stoping;
  142. }else{
  143. Sleep(10);
  144. }
  145. return running;
  146. }
  147. static void resetQueScore(std::vector<schema::SCHEMA_QUESTION> &questions, std::string rule)
  148. {
  149. Json::Value qesScores;
  150. if (rule.empty())
  151. return;
  152. Json::Features features;
  153. Json::Reader re(features);
  154. Json::Value root;
  155. re.parse(rule, root);
  156. qesScores = root["questions"];
  157. if (qesScores.isNull())
  158. return;
  159. int array_size = 0;
  160. array_size = qesScores.size();
  161. for (int i = 0; i < array_size; i++)
  162. {
  163. Json::Value row = qesScores[i];
  164. int qesid = row["questionNum"].asInt();
  165. int qestype = row["questionTypeId"].asInt();
  166. float score = atof(row["fullScore"].asString().c_str());
  167. string answer = "";
  168. if (!row["answer"].isNull())
  169. {
  170. answer = row["answer"].asString();
  171. }
  172. for (auto& it : questions)
  173. {
  174. char str[25];
  175. itoa(qesid, str, 10);
  176. if (strcmp(it.question_code_new, str) == 0)
  177. {
  178. it.score = score;
  179. if (answer.length())
  180. {
  181. it.answerA = answer;
  182. }
  183. break;
  184. }
  185. }
  186. }
  187. }
  188. int CBatchService::LoadSchema(long long examId, std::string examName, long examCourseId, std::string courseName, std::string schemaPath, std::string rule/*=""*/)
  189. {
  190. if (m_upload_manager.IsEanble()){
  191. // 边扫描边上传模式
  192. ScanParamInfo obj;
  193. obj.subject_id = std::to_string(m_examCourseId);
  194. obj.course_name = m_courseName;
  195. obj.exam_id = std::to_string(m_examId);
  196. CString _ini_file = GetExePath() + _T("\\..\\config.ini");
  197. if (m_upload_manager.IsContinue()){
  198. TCHAR sz_b_code[100] = { 0 };
  199. GetPrivateProfileString(_T("THRID"), _T("cur_bantch_code"), _T(""), sz_b_code, sizeof(sz_b_code) / sizeof(TCHAR), _ini_file);
  200. obj.bantch_code = UnicodeToAnsi(sz_b_code);
  201. }
  202. else{
  203. obj.bantch_code = UnicodeToAnsi(m_bantch_code);
  204. WritePrivateProfileString(_T("THRID"), _T("cur_bantch_code"), m_bantch_code, _ini_file);
  205. }
  206. m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_START_SCAN, (const char*)&obj, m_nOnlineScanType);
  207. m_result_uploader->SetBatchCode(AnsiToUnicode(obj.bantch_code));
  208. if (WaitForSingleObject(m_eventZXHXCreateDB, INFINITE) != WAIT_OBJECT_0){
  209. LOGI("等待知心慧学创建数据库超时");
  210. ::PostMessage(m_hwnd, WM_IDENTIFOR_STOPED, 0, 0);
  211. return IDF_LOAD_FAILURE;
  212. }
  213. else{
  214. if (!m_upload_manager.IsZXHXCreateUploadDBSuccess()){
  215. LOGI("知心慧学创建数据库错误,无法扫描OR扫描后无法上传");
  216. ::PostMessage(m_hwnd, WM_IDENTIFOR_STOPED, 0, 0);
  217. return IDF_LOAD_FAILURE;
  218. }
  219. }
  220. }
  221. m_examId = examId;
  222. m_examCourseId = examCourseId;
  223. CSchemaLoader schemaLoader;
  224. if (!m_bOnlineCard){
  225. int ret = schemaLoader.Load(schemaPath, m_muban_img_dir, m_schema0, m_schema, m_handleInfo);
  226. if (ret == SCH_LOAD_SUCCESS)
  227. {
  228. resetQueScore(m_schema0.questions, rule);
  229. saveQuestionStd(examId, examName, examCourseId, courseName, m_schema0.questions, rule);
  230. recordBarcodeFlag(0);
  231. for (int i = 0; i < m_schema0.pages.size(); i++)
  232. {
  233. if (m_schema0.pages[i].codes.size()>0)
  234. recordBarcodeFlag(1);
  235. }
  236. g_myindex = 1;
  237. mainService->SetFolderPageNumber(m_schema0.pages.size());
  238. return IDF_LOAD_SUCCESS;
  239. }
  240. else
  241. {
  242. return IDF_LOAD_CLASS_SCHEMA | ret;
  243. }
  244. }
  245. else
  246. {
  247. if (m_onlineCardTemplate)
  248. {
  249. if (ParseTemplateFromJson(schemaPath))
  250. {
  251. Online_saveQuestionStd(examId, examName, examCourseId, courseName, rule);
  252. mainService->SetFolderPageNumber(m_onlineCardTemplate->pages.size());
  253. return IDF_LOAD_SUCCESS;
  254. }
  255. else
  256. {
  257. return IDF_LOAD_FAILURE;
  258. }
  259. }
  260. else
  261. return IDF_LOAD_FAILURE;
  262. }
  263. return IDF_LOAD_FAILURE;
  264. }
  265. #include "pugixml/pugixml.hpp"
  266. // void ParseTemplateOffset(const std::string&file_name, OnLineCard::PaperTemplate* m_onlineCard)
  267. // {
  268. // if (m_onlineCard->pages.size() <= 0)return;
  269. // if (!m_onlineCard) return;
  270. // pugi::xml_document doc;
  271. // auto result = doc.load_file(file_name.c_str());
  272. // if (result.status != pugi::status_ok)
  273. // return;
  274. // for (auto child = doc.child("item_info").first_child(); child; child = child.next_sibling())
  275. // {
  276. // std::string child_name = child.name();
  277. // if (child_name == "dingweidian_w_max_rate"){
  278. // std::string value = child.attribute("value").value();
  279. // if (!value.empty())
  280. // m_onlineCard->dingweidian_w_max_rate = std::stof(value);
  281. // }
  282. // else if (child_name == "dingweidian_w_min_rate"){
  283. // std::string value = child.attribute("value").value();
  284. // if (!value.empty())
  285. // m_onlineCard->dingweidian_w_min_rate = std::stof(value);
  286. // }
  287. // else if (child_name == "dingweidian_h_max_rate"){
  288. // std::string value = child.attribute("value").value();
  289. // if (!value.empty())
  290. // m_onlineCard->dingweidian_h_max_rate = std::stof(value);
  291. // }
  292. // else if (child_name == "dingweidian_h_min_rate"){
  293. // std::string value = child.attribute("value").value();
  294. // if (!value.empty())
  295. // m_onlineCard->dingweidian_h_min_rate = std::stof(value);
  296. // }
  297. // else if (child_name == "dingweidian_range_top"){
  298. // std::string value = child.attribute("value").value();
  299. // if (!value.empty())
  300. // m_onlineCard->dingweidian_range_top = std::stoi(value);
  301. // }
  302. // else if (child_name == "dingweidian_rang_buttom"){
  303. // std::string value = child.attribute("value").value();
  304. // if (!value.empty())
  305. // m_onlineCard->dingweidian_rang_buttom = std::stoi(value);
  306. // }
  307. // else if (child_name == "open_save_debug_img"){
  308. // std::string value = child.attribute("value").value();
  309. // if (!value.empty())
  310. // m_onlineCard->open_save_debug_img = (std::stoi(value) == 1);
  311. // }
  312. // else{
  313. // Item_Pos_offset_Info info;
  314. // for (pugi::xml_attribute attr = child.first_attribute(); attr; attr = attr.next_attribute()){
  315. // std::string attr_name = attr.name();
  316. // if (attr_name == "type"){
  317. // std::string value = attr.value();
  318. // if (!value.empty())
  319. // info.type = (item_type)std::stoi(value);
  320. // }
  321. // else if (attr_name == "x_offset"){
  322. // std::string value = attr.value();
  323. // if (!value.empty())
  324. // info.x_offset = (item_type)std::stoi(value);
  325. // }
  326. // else if (attr_name == "y_offset"){
  327. // std::string value = attr.value();
  328. // if (!value.empty())
  329. // info.y_offset = (item_type)std::stoi(value);
  330. // }
  331. // else if (attr_name == "w_offset"){
  332. // std::string value = attr.value();
  333. // if (!value.empty())
  334. // info.w_offset = (item_type)std::stoi(value);
  335. // }
  336. // else if (attr_name == "h_offset"){
  337. // std::string value = attr.value();
  338. // if (!value.empty())
  339. // info.h_offset = (item_type)std::stoi(value);
  340. // }
  341. // else if (attr_name == "score_x_offset"){
  342. // std::string value = attr.value();
  343. // if (!value.empty())
  344. // info.x_offset_score = (item_type)std::stoi(value);
  345. // }
  346. // else if (attr_name == "score_y_offset"){
  347. // std::string value = attr.value();
  348. // if (!value.empty())
  349. // info.y_offset_score = (item_type)std::stoi(value);
  350. // }
  351. // else if (attr_name == "score_w_offset"){
  352. // std::string value = attr.value();
  353. // if (!value.empty())
  354. // info.w_offset_score = (item_type)std::stoi(value);
  355. // }
  356. // else if (attr_name == "score_h_offset"){
  357. // std::string value = attr.value();
  358. // if (!value.empty())
  359. // info.h_offset_score = (item_type)std::stoi(value);
  360. // }
  361. // else if (attr_name == "id"){
  362. // info.question_id = attr.value();
  363. // }
  364. // else if (attr_name == "opt_x_offset"){
  365. // std::string value = attr.value();
  366. // if (!value.empty())
  367. // info.x_offset_opt = (item_type)std::stoi(value);
  368. // }
  369. // else if (attr_name == "opt_y_offset"){
  370. // std::string value = attr.value();
  371. // if (!value.empty())
  372. // info.y_offset_opt = (item_type)std::stoi(value);
  373. // }
  374. // else if (attr_name == "opt_w_offset"){
  375. // std::string value = attr.value();
  376. // if (!value.empty())
  377. // info.w_offset_opt = (item_type)std::stoi(value);
  378. // }
  379. // else if (attr_name == "opt_h_offset"){
  380. // std::string value = attr.value();
  381. // if (!value.empty())
  382. // info.h_offset_opt = (item_type)std::stoi(value);
  383. // }
  384. // }
  385. // std::string key = info.question_id;
  386. // if (info.type == item_type::type_absent || //缺考标记
  387. // info.type == item_type::type_qrbar || // 二维码
  388. // info.type == item_type::type_tiaoxingma){ // 条形码
  389. // Pos*pos = &m_onlineCard->pages[1].absent;
  390. // if (info.type == item_type::type_qrbar)pos = &m_onlineCard->pages[1].QrCode;
  391. // else if (info.type == item_type::type_tiaoxingma)pos = &m_onlineCard->pages[1].studentcode_bar;
  392. // pos->x += info.x_offset;
  393. // pos->y += info.y_offset;
  394. // pos->w += info.w_offset;
  395. // pos->h += info.h_offset;
  396. // continue;
  397. // }
  398. // else if (info.type == item_type::type_tiantukaohao){
  399. // key = "tiantukaohao";
  400. // }
  401. // else if (info.type == item_type::type_question_keguan){
  402. // key = "question_keguan";
  403. // }
  404. // else if (info.type == item_type::type_question_keguan_d){
  405. // key = "question_keguan_d";
  406. // }
  407. // else if (info.type == item_type::type_question_keguan_b){
  408. // key = "question_keguan_b";
  409. // }
  410. // m_onlineCard->_map_offset_info[key] = info;
  411. // }
  412. // }
  413. //
  414. // // 更新
  415. // // 填涂考号
  416. // auto it_find = m_onlineCard->_map_offset_info.find("tiantukaohao");
  417. // if (it_find != m_onlineCard->_map_offset_info.end()){
  418. // int nIndex = 0;
  419. // for (std::size_t row = 0; row < m_onlineCard->pages[1].studentcode_fill.size(); row++)
  420. // {
  421. // for (std::size_t col = 0; col < m_onlineCard->pages[1].studentcode_fill[row].size(); col++, nIndex++)
  422. // {
  423. // m_onlineCard->pages[1].studentcode_fill[row][col].pos.x += it_find->second.x_offset;
  424. // m_onlineCard->pages[1].studentcode_fill[row][col].pos.y += it_find->second.y_offset;
  425. // m_onlineCard->pages[1].studentcode_fill[row][col].pos.w += it_find->second.w_offset;
  426. // m_onlineCard->pages[1].studentcode_fill[row][col].pos.h += it_find->second.h_offset;
  427. // }
  428. // }
  429. // }
  430. // auto &it_keguanti = m_onlineCard->_map_offset_info.find("question_keguan");
  431. // auto &it_keguanti_d = m_onlineCard->_map_offset_info.find("question_keguan_d");
  432. // auto &it_keguanti_b = m_onlineCard->_map_offset_info.find("question_keguan_b");
  433. // for (std::size_t n = 0; n < m_onlineCard->pages.size(); ++n)
  434. // {
  435. // for (std::size_t i = 0; i < m_onlineCard->pages[n + 1].vctQuestions.size(); ++i)
  436. // {
  437. // std::string id = m_onlineCard->pages[n + 1].vctQuestions[i].id;
  438. // auto it_find = m_onlineCard->_map_offset_info.find(id);
  439. // if (it_find != m_onlineCard->_map_offset_info.end()){
  440. // // 主观题
  441. // if ( m_onlineCard->pages[n + 1].vctQuestions[i].type == 1 ||
  442. // m_onlineCard->pages[n + 1].vctQuestions[i].type == 3 ||
  443. // m_onlineCard->pages[n + 1].vctQuestions[i].type == 2){
  444. // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.x += it_find->second.x_offset;
  445. // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.y += it_find->second.y_offset;
  446. // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.w += it_find->second.w_offset;
  447. // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.h += it_find->second.h_offset;
  448. //
  449. // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.x += it_find->second.x_offset_score;
  450. // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.y += it_find->second.y_offset_score;
  451. // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.w += it_find->second.w_offset_score;
  452. // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.h += it_find->second.h_offset_score;
  453. // if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 2){
  454. // // 选做题
  455. // for (std::size_t j = 0; j <m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
  456. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_find->second.x_offset_opt;
  457. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_find->second.y_offset_opt;
  458. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_find->second.w_offset_opt;
  459. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_find->second.h_offset_opt;
  460. // }
  461. // }
  462. // }
  463. // }
  464. // // 单选题
  465. // else if (m_onlineCard->pages[n + 1].vctQuestions[i].type==0 && it_keguanti != m_onlineCard->_map_offset_info.end()){
  466. // for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
  467. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_keguanti->second.x_offset;
  468. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_keguanti->second.y_offset;
  469. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_keguanti->second.w_offset;
  470. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_keguanti->second.h_offset;
  471. // }
  472. // }
  473. // // 多选题
  474. // else if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 8 && it_keguanti_d != m_onlineCard->_map_offset_info.end()){
  475. // for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
  476. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_keguanti_d->second.x_offset;
  477. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_keguanti_d->second.y_offset;
  478. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_keguanti_d->second.w_offset;
  479. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_keguanti_d->second.h_offset;
  480. // }
  481. // }
  482. // // 不定项选择题
  483. // else if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 5 && it_keguanti_b != m_onlineCard->_map_offset_info.end()){
  484. // for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
  485. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_keguanti_b->second.x_offset;
  486. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_keguanti_b->second.y_offset;
  487. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_keguanti_b->second.w_offset;
  488. // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_keguanti_b->second.h_offset;
  489. // }
  490. // }
  491. // }
  492. // }
  493. // }
  494. void ParseTemplateOffset(const std::string&file_name, OnLineCard::PaperTemplate* m_onlineCard)
  495. {
  496. if (m_onlineCard->pages.size() <= 0)return;
  497. if (!m_onlineCard) return;
  498. pugi::xml_document doc;
  499. auto result = doc.load_file(file_name.c_str());
  500. if (result.status != pugi::status_ok)
  501. return;
  502. for (auto child = doc.child("item_info").first_child(); child; child = child.next_sibling())
  503. {
  504. std::string child_name = child.name();
  505. if (child_name == "dingweidian_w_max_rate"){
  506. std::string value = child.attribute("value").value();
  507. if (!value.empty())
  508. m_onlineCard->dingweidian_w_max_rate = std::stof(value);
  509. }
  510. else if (child_name == "dingweidian_w_min_rate"){
  511. std::string value = child.attribute("value").value();
  512. if (!value.empty())
  513. m_onlineCard->dingweidian_w_min_rate = std::stof(value);
  514. }
  515. else if (child_name == "dingweidian_h_max_rate"){
  516. std::string value = child.attribute("value").value();
  517. if (!value.empty())
  518. m_onlineCard->dingweidian_h_max_rate = std::stof(value);
  519. }
  520. else if (child_name == "dingweidian_h_min_rate"){
  521. std::string value = child.attribute("value").value();
  522. if (!value.empty())
  523. m_onlineCard->dingweidian_h_min_rate = std::stof(value);
  524. }
  525. else if (child_name == "dingweidian_range_top"){
  526. std::string value = child.attribute("value").value();
  527. if (!value.empty())
  528. m_onlineCard->dingweidian_range_top = std::stoi(value);
  529. }
  530. else if (child_name == "dingweidian_rang_buttom"){
  531. std::string value = child.attribute("value").value();
  532. if (!value.empty())
  533. m_onlineCard->dingweidian_rang_buttom = std::stoi(value);
  534. }
  535. else if (child_name == "open_save_debug_img"){
  536. std::string value = child.attribute("value").value();
  537. if (!value.empty())
  538. m_onlineCard->open_save_debug_img = (std::stoi(value) == 1);
  539. }
  540. else{
  541. Item_Pos_offset_Info info;
  542. for (pugi::xml_attribute attr = child.first_attribute(); attr; attr = attr.next_attribute()){
  543. std::string attr_name = attr.name();
  544. if (attr_name == "type"){
  545. std::string value = attr.value();
  546. if (!value.empty())
  547. info.type = (item_type)std::stoi(value);
  548. }
  549. else if (attr_name == "x_offset"){
  550. std::string value = attr.value();
  551. if (!value.empty())
  552. info.x_offset = (item_type)std::stoi(value);
  553. }
  554. else if (attr_name == "y_offset"){
  555. std::string value = attr.value();
  556. if (!value.empty())
  557. info.y_offset = (item_type)std::stoi(value);
  558. }
  559. else if (attr_name == "w_offset"){
  560. std::string value = attr.value();
  561. if (!value.empty())
  562. info.w_offset = (item_type)std::stoi(value);
  563. }
  564. else if (attr_name == "h_offset"){
  565. std::string value = attr.value();
  566. if (!value.empty())
  567. info.h_offset = (item_type)std::stoi(value);
  568. }
  569. else if (attr_name == "score_x_offset"){
  570. std::string value = attr.value();
  571. if (!value.empty())
  572. info.x_offset_score = (item_type)std::stoi(value);
  573. }
  574. else if (attr_name == "score_y_offset"){
  575. std::string value = attr.value();
  576. if (!value.empty())
  577. info.y_offset_score = (item_type)std::stoi(value);
  578. }
  579. else if (attr_name == "score_w_offset"){
  580. std::string value = attr.value();
  581. if (!value.empty())
  582. info.w_offset_score = (item_type)std::stoi(value);
  583. }
  584. else if (attr_name == "score_h_offset"){
  585. std::string value = attr.value();
  586. if (!value.empty())
  587. info.h_offset_score = (item_type)std::stoi(value);
  588. }
  589. else if (attr_name == "id"){
  590. info.question_id = attr.value();
  591. }
  592. else if (attr_name == "opt_x_offset"){
  593. std::string value = attr.value();
  594. if (!value.empty())
  595. info.x_offset_opt = (item_type)std::stoi(value);
  596. }
  597. else if (attr_name == "opt_y_offset"){
  598. std::string value = attr.value();
  599. if (!value.empty())
  600. info.y_offset_opt = (item_type)std::stoi(value);
  601. }
  602. else if (attr_name == "opt_w_offset"){
  603. std::string value = attr.value();
  604. if (!value.empty())
  605. info.w_offset_opt = (item_type)std::stoi(value);
  606. }
  607. else if (attr_name == "opt_h_offset"){
  608. std::string value = attr.value();
  609. if (!value.empty())
  610. info.h_offset_opt = (item_type)std::stoi(value);
  611. }
  612. else if (attr_name == "link_param"){
  613. std::string value = attr.value();
  614. if (!value.empty())
  615. info.link_param = (item_type)std::stoi(value);
  616. }
  617. }
  618. for (pugi::xml_node opt_info = child.first_child(); opt_info; opt_info = opt_info.next_sibling()){
  619. Item_Pos_offset_Info _opt_info;
  620. for (pugi::xml_attribute attr = opt_info.first_attribute(); attr; attr = attr.next_attribute()){
  621. std::string attr_name = attr.name();
  622. if (attr_name == "index"){
  623. // 选项序号 从0开始
  624. _opt_info.question_id = attr.value();
  625. }
  626. else if (attr_name == "x_offset"){
  627. std::string value = attr.value();
  628. if (!value.empty())
  629. _opt_info.x_offset = (item_type)std::stoi(value);
  630. }
  631. else if (attr_name == "y_offset"){
  632. std::string value = attr.value();
  633. if (!value.empty())
  634. _opt_info.y_offset = (item_type)std::stoi(value);
  635. }
  636. else if (attr_name == "w_offset"){
  637. std::string value = attr.value();
  638. if (!value.empty())
  639. _opt_info.w_offset = (item_type)std::stoi(value);
  640. }
  641. else if (attr_name == "h_offset"){
  642. std::string value = attr.value();
  643. if (!value.empty())
  644. _opt_info.h_offset = (item_type)std::stoi(value);
  645. }
  646. }
  647. info._child_info[std::stoi(_opt_info.question_id)] = _opt_info;
  648. }
  649. std::string key = info.question_id;
  650. if (info.type == item_type::type_absent || //缺考标记
  651. info.type == item_type::type_qrbar || // 二维码
  652. info.type == item_type::type_tiaoxingma){ // 条形码
  653. Pos*pos = &m_onlineCard->pages[1].absent;
  654. if (info.type == item_type::type_qrbar)pos = &m_onlineCard->pages[1].QrCode;
  655. else if (info.type == item_type::type_tiaoxingma)pos = &m_onlineCard->pages[1].studentcode_bar;
  656. pos->x += info.x_offset;
  657. pos->y += info.y_offset;
  658. pos->w += info.w_offset;
  659. pos->h += info.h_offset;
  660. continue;
  661. }
  662. else if (info.type == item_type::type_tiantukaohao){
  663. info.question_id = "tiantukaohao";
  664. }
  665. if (info.link_param>1)
  666. {
  667. info.question_id += "_";
  668. info.question_id += std::to_string(info.link_param);
  669. }
  670. m_onlineCard->_map_offset_info[info.question_id] = info;
  671. }
  672. }
  673. // 更新
  674. // 填涂考号
  675. auto it_find = m_onlineCard->_map_offset_info.find("tiantukaohao");
  676. if (it_find != m_onlineCard->_map_offset_info.end()){
  677. int nIndex = 0;
  678. for (std::size_t row = 0; row < m_onlineCard->pages[1].studentcode_fill.size(); row++)
  679. {
  680. for (std::size_t col = 0; col < m_onlineCard->pages[1].studentcode_fill[row].size(); col++, nIndex++)
  681. {
  682. m_onlineCard->pages[1].studentcode_fill[row][col].pos.x += it_find->second.x_offset;
  683. m_onlineCard->pages[1].studentcode_fill[row][col].pos.y += it_find->second.y_offset;
  684. m_onlineCard->pages[1].studentcode_fill[row][col].pos.w += it_find->second.w_offset;
  685. m_onlineCard->pages[1].studentcode_fill[row][col].pos.h += it_find->second.h_offset;
  686. auto it_opt_find = it_find->second._child_info.find(nIndex);
  687. if (it_opt_find != it_find->second._child_info.end()){
  688. m_onlineCard->pages[1].studentcode_fill[row][col].pos.x += it_opt_find->second.x_offset;
  689. m_onlineCard->pages[1].studentcode_fill[row][col].pos.y += it_opt_find->second.y_offset;
  690. m_onlineCard->pages[1].studentcode_fill[row][col].pos.w += it_opt_find->second.w_offset;
  691. m_onlineCard->pages[1].studentcode_fill[row][col].pos.h += it_opt_find->second.h_offset;
  692. }
  693. }
  694. }
  695. }
  696. for (std::size_t n = 0; n < m_onlineCard->pages.size(); ++n)
  697. {
  698. for (std::size_t i = 0; i < m_onlineCard->pages[n + 1].vctQuestions.size(); ++i)
  699. {
  700. std::string id = m_onlineCard->pages[n + 1].vctQuestions[i].id;
  701. if ((m_onlineCard->pages[n + 1].vctQuestions[i].type == 1||
  702. m_onlineCard->pages[n + 1].vctQuestions[i].type == 2) && m_onlineCard->pages[n + 1].vctQuestions[i].cut.linkparm>1){
  703. id += "_";
  704. id += std::to_string(m_onlineCard->pages[n + 1].vctQuestions[i].cut.linkparm);
  705. }
  706. auto it_find = m_onlineCard->_map_offset_info.find(id);
  707. if (it_find != m_onlineCard->_map_offset_info.end()){
  708. // 主观题
  709. if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 1|| // 主观题
  710. m_onlineCard->pages[n + 1].vctQuestions[i].type == 3|| // 填空题
  711. m_onlineCard->pages[n + 1].vctQuestions[i].type == 2) // 选做题
  712. {
  713. m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.x += it_find->second.x_offset;
  714. m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.y += it_find->second.y_offset;
  715. m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.w += it_find->second.w_offset;
  716. m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.h += it_find->second.h_offset;
  717. m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.x += it_find->second.x_offset_score;
  718. m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.y += it_find->second.y_offset_score;
  719. m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.w += it_find->second.w_offset_score;
  720. m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.h += it_find->second.h_offset_score;
  721. if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 2){
  722. // 选做题
  723. for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j)
  724. {
  725. auto it_opt_find = it_find->second._child_info.find(j);
  726. if (it_opt_find != it_find->second._child_info.end()){
  727. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_opt_find->second.x_offset;
  728. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_opt_find->second.y_offset;
  729. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_opt_find->second.w_offset;
  730. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_opt_find->second.h_offset;
  731. }
  732. }
  733. }
  734. }
  735. else
  736. {
  737. // 选择题 多选题 不定项选择题
  738. for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
  739. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_find->second.x_offset;
  740. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_find->second.y_offset;
  741. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_find->second.w_offset;
  742. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_find->second.h_offset;
  743. auto it_opt_find = it_find->second._child_info.find(j);
  744. if (it_opt_find != it_find->second._child_info.end()){
  745. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_opt_find->second.x_offset;
  746. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_opt_find->second.y_offset;
  747. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_opt_find->second.w_offset;
  748. m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_opt_find->second.h_offset;
  749. }
  750. }
  751. }
  752. }
  753. }
  754. }
  755. }
  756. bool CBatchService::ParseTemplateFromJsonAll(const std::string&fileName)//全学科在线答题卡
  757. {
  758. //1 单选 2 小题单选 3 多选 4 小题多选 5 单空 6 多空 7 小题多空 8 解答 9 小题解答 10 英语作文 11 语文作文 12 判断题
  759. //0选择 1解答 2选作 3填空 4编组 5不定项 8不定项
  760. map<string, int> type_map;//新旧题型对应
  761. type_map["1"] = 0; type_map["2"] = 0; type_map["3"] = 5; type_map["4"] = 5; type_map["5"] = 3; type_map["6"] = 3;
  762. type_map["7"] = 3; type_map["8"] = 1; type_map["9"] = 1; /*type_map["10"] = 1; type_map["11"] = 1; type_map["12"] = 1;*/
  763. CUnZipFile uzip(CString(fileName.c_str()));
  764. std::map<CString, std::vector<unsigned char>> map1;
  765. while (uzip.HasMoreEntry()){
  766. CString fileNam;
  767. uzip.GetNextEntry(fileNam);
  768. char buffer[1024 * 8];
  769. int len;
  770. std::vector<unsigned char>& data = map1[fileNam];
  771. data.reserve(1024 * 128);
  772. while ((len = uzip.Read(buffer, 1024 * 8)) > 0){
  773. if (data.capacity() < data.size() + len){
  774. int c = data.capacity() + 1024 * 128;
  775. data.reserve(c);
  776. }
  777. int oldSize = data.size();
  778. data.resize(oldSize + len);
  779. char * dst = (char *)data.data() + oldSize;
  780. memcpy(dst, buffer, len);
  781. }
  782. }
  783. uzip.Close();
  784. auto schemabytes = map1.find(_T("json.txt"));
  785. if (schemabytes == map1.end()){
  786. return SCH_LOAD_ERR_MISSINGFORMAT;
  787. }
  788. std::vector<unsigned char>& data = schemabytes->second;
  789. auto strJson = std::string((char *)data.data(), data.size());
  790. if (!m_onlineCardTemplate) return false;
  791. m_onlineCardTemplate->pages.clear();
  792. auto pfGetPos = [](const rapidjson::Value&value)->std::tuple<bool, Pos>{
  793. bool bRet = false;
  794. double x = 0.0, y = 0.0, w = 0.0, h = 0.0;
  795. auto itX = value.FindMember("x");
  796. if (itX != value.MemberEnd() && (itX->value.IsInt() || itX->value.IsDouble())){
  797. x = itX->value.GetDouble();
  798. }
  799. auto itY = value.FindMember("y");
  800. if (itY != value.MemberEnd() && (itY->value.IsInt() || itY->value.IsDouble())){
  801. y = itY->value.GetDouble();
  802. }
  803. auto itW = value.FindMember("width");
  804. if (itW != value.MemberEnd() && (itW->value.IsInt() || itW->value.IsDouble())){
  805. w = itW->value.GetDouble();
  806. }
  807. auto itH = value.FindMember("height");
  808. if (itH != value.MemberEnd() && (itH->value.IsInt() || itH->value.IsDouble())){
  809. h = itH->value.GetDouble();
  810. bRet = true;
  811. }
  812. return std::tie(bRet, Pos{ x, y, w, h });
  813. };
  814. rapidjson::Document doc;
  815. doc.Parse(strJson.c_str());
  816. if (doc.HasParseError()) return false;
  817. m_onlineCardTemplate->subject_id = m_nSubjectID;
  818. m_onlineCardTemplate->_version = "old";
  819. // 检测版本号
  820. auto it_version = doc.FindMember("online_card_version");
  821. if (it_version != doc.MemberEnd() && it_version->value.IsString()){
  822. m_onlineCardTemplate->_version = it_version->value.GetString();
  823. }
  824. LOGFMTI("在线答题卡版本号:%s", m_onlineCardTemplate->_version.c_str());
  825. {
  826. // 总页数
  827. auto itTotalPage = doc.FindMember("totalPage");
  828. if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
  829. m_onlineCardTemplate->totalPage = itTotalPage->value.GetInt();
  830. }
  831. // 是否使用二维码
  832. auto itUseQrCode = doc.FindMember("useQrCode");
  833. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
  834. m_onlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
  835. }
  836. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
  837. m_onlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
  838. }
  839. // 学校状态
  840. auto itSchoolStatus = doc.FindMember("school_card_status");
  841. if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
  842. m_onlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
  843. }
  844. int n_duo_xuanti_index = 0;
  845. std::string temp_all_id = "";
  846. // 页
  847. auto itPages = doc.FindMember("pages");
  848. if (itPages != doc.MemberEnd() && itPages->value.IsArray()/* && itPages->value.Size() == m_onlineCardTemplate->totalPage*/){
  849. for (auto itPage = itPages->value.Begin(); itPage != itPages->value.End(); ++itPage){
  850. if (!itPage->IsObject()) return false;
  851. PageTemplate page;
  852. // 页号
  853. auto itPageNo = itPage->FindMember("pageNo");
  854. if (itPageNo != itPage->MemberEnd() && itPageNo->value.IsInt()){
  855. page.pageNo = itPageNo->value.GetInt();
  856. }
  857. else {
  858. return false;
  859. }
  860. // 定位点
  861. auto itLocations = itPage->FindMember("location");
  862. if (itLocations != itPage->MemberEnd() && itLocations->value.IsArray()){
  863. for (auto it = itLocations->value.Begin(); it != itLocations->value.End(); ++it){
  864. Location lc;
  865. auto itType = it->FindMember("type");
  866. if (itType != it->MemberEnd() && itType->value.IsInt()){
  867. lc.type = itType->value.GetInt();
  868. }
  869. auto tm = pfGetPos(*it);
  870. if (std::get<0>(tm)){
  871. lc.pos = std::get<1>(tm);
  872. }
  873. page.location.push_back(lc);
  874. }
  875. }
  876. if (page.pageNo == 1){
  877. if (!m_onlineCardTemplate->useQrCode){
  878. // 条形码
  879. auto itBar = itPage->FindMember("studentcode_bar");
  880. if (itBar != itPage->MemberEnd() && itBar->value.IsObject()){
  881. auto itObj = itBar->value.FindMember("object");
  882. if (itObj != itBar->value.MemberEnd() && itObj->value.IsObject()){
  883. auto t = pfGetPos(itObj->value);
  884. page.studentcode_bar = std::get<1>(t);
  885. }
  886. }
  887. // 填涂考号
  888. auto itFill = itPage->FindMember("studentcode_fill");
  889. if (itFill != itPage->MemberEnd() && itFill->value.IsObject()){
  890. auto itObj = itFill->value.FindMember("object");
  891. if (itObj != itFill->value.MemberEnd() && itObj->value.IsArray()){
  892. for (auto itRow = itObj->value.Begin(); itRow != itObj->value.End(); ++itRow){
  893. auto itGroup = itRow->FindMember("group");
  894. if (itGroup != itRow->MemberEnd() && itGroup->value.IsArray()){
  895. std::vector<Opt> _vctOpt;
  896. for (auto itCol = itGroup->value.Begin(); itCol != itGroup->value.End(); ++itCol){
  897. Opt opt;
  898. auto itOptName = itCol->FindMember("optName");
  899. if (itOptName != itCol->MemberEnd() && itOptName->value.IsInt())
  900. opt.optName = std::to_string(itOptName->value.GetInt());
  901. auto t = pfGetPos(*itCol);
  902. if (std::get<0>(t))
  903. opt.pos = std::get<1>(t);
  904. _vctOpt.push_back(opt);
  905. }
  906. page.studentcode_fill.push_back(_vctOpt);
  907. }
  908. }
  909. }
  910. }
  911. }
  912. // 缺考标记
  913. auto itAbsent = itPage->FindMember("absent");
  914. if (itAbsent != itPage->MemberEnd() && itAbsent->value.IsObject()){
  915. auto t = pfGetPos(itAbsent->value);
  916. if (std::get<0>(t)){
  917. page.absent = std::get<1>(t);
  918. }
  919. }
  920. // 二维码
  921. auto itQrCode = itPage->FindMember("QrCode");
  922. if (itQrCode != itPage->MemberEnd() && itQrCode->value.IsObject()){
  923. auto t = pfGetPos(itQrCode->value);
  924. if (std::get<0>(t)){
  925. page.QrCode = std::get<1>(t);
  926. }
  927. }
  928. } // end if page.pageNo == 0
  929. // 长宽
  930. auto itImge = itPage->FindMember("imge");
  931. if (itImge != itPage->MemberEnd()){
  932. auto t = std::get<1>(pfGetPos(itImge->value));
  933. page.w = t.w;
  934. page.h = t.h;
  935. }
  936. else{
  937. return false;
  938. }
  939. // 题目
  940. auto itQuestion = itPage->FindMember("questions");
  941. if (itQuestion != itPage->MemberEnd() && itQuestion->value.IsArray())
  942. {
  943. for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it)
  944. {
  945. question q;
  946. // 题目类型
  947. auto itType = it->FindMember("type");
  948. string qType = "1";
  949. if (itType != it->MemberEnd() && itType->value.IsString())
  950. {
  951. qType = itType->value.GetString();
  952. q.type = atoi(qType.c_str());
  953. }
  954. else
  955. {
  956. return false;
  957. }
  958. q.marktype = 0;
  959. // 题目类型
  960. auto itMarktype = it->FindMember("marktype");
  961. if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
  962. q.marktype = itMarktype->value.GetInt();
  963. }
  964. // 分数
  965. auto itScore = it->FindMember("score");
  966. if (itScore != it->MemberEnd() && itScore->value.IsObject()){
  967. auto itFull = itScore->value.FindMember("full");
  968. if (itFull != itScore->value.MemberEnd() && (itFull->value.IsDouble() || itFull->value.IsInt()))
  969. q.score = itFull->value.GetDouble();
  970. }
  971. // 题目编号 2选做题
  972. auto itId = it->FindMember((q.type == 2 || q.type == 4) ? "editorId" : "id");
  973. if (itId != it->MemberEnd() && itId->value.IsString()){
  974. q.id = itId->value.GetString();
  975. }
  976. if (itId != it->MemberEnd() && itId->value.IsInt()){
  977. q.id = std::to_string(itId->value.GetInt());
  978. }
  979. if (q.type == 2 || q.type == 4){
  980. auto itAllID = it->FindMember("id");
  981. if (itAllID != it->MemberEnd() && itAllID->value.IsString()){
  982. q.all_id = itAllID->value.GetString();
  983. }
  984. }
  985. auto itSmallQtNo = it->FindMember("smallQtNo");
  986. if (itSmallQtNo != it->MemberEnd() && !(itSmallQtNo->value.IsNull()))
  987. {
  988. q.smallQtNo = itSmallQtNo->value.GetInt();
  989. }
  990. else
  991. {
  992. q.smallQtNo = -1;
  993. }
  994. auto itNickID = it->FindMember("name");
  995. if (itNickID != it->MemberEnd() && !(itNickID->value.IsNull()) && itNickID->value.IsInt())
  996. {
  997. m_mapKeguantiNickName[q.id] = std::to_string(itNickID->value.GetInt());
  998. }
  999. // 打分区域
  1000. auto itScoreBox = it->FindMember("scorebox");
  1001. if (itScoreBox != it->MemberEnd() && itScoreBox->value.IsObject()){
  1002. // 打分框类型
  1003. auto itType = itScoreBox->value.FindMember("type");
  1004. if (itType != itScoreBox->value.MemberEnd() && itType->value.IsString()){
  1005. q.scoreBox.type = std::stoi(itType->value.GetString());
  1006. }
  1007. else if (itType != itScoreBox->value.MemberEnd() && itType->value.IsInt()){
  1008. q.scoreBox.type = itType->value.GetInt();
  1009. }
  1010. else{
  1011. return false;
  1012. }
  1013. if (q.smallQtNo != -1)
  1014. {
  1015. // 小问最大分值
  1016. auto itmaxScore = itScoreBox->value.FindMember("maxscore");
  1017. if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsString()){
  1018. q.scoreBox.maxsorce = std::stod(itmaxScore->value.GetString());
  1019. }
  1020. else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsDouble()){
  1021. q.scoreBox.maxsorce = itScoreBox->value.GetDouble();
  1022. }
  1023. else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsInt()){
  1024. q.scoreBox.maxsorce = itmaxScore->value.GetInt();
  1025. }
  1026. else{
  1027. q.scoreBox.maxsorce = 0.0;
  1028. }
  1029. }
  1030. else
  1031. {
  1032. q.scoreBox.maxsorce = 0.0;
  1033. }
  1034. // 分数上限
  1035. auto itLimit = itScoreBox->value.FindMember("limit");
  1036. if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsString())
  1037. q.scoreBox.limit = std::stoi(itLimit->value.GetString());
  1038. if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsInt())
  1039. q.scoreBox.limit = itLimit->value.GetInt();
  1040. // 最后一个格子是否为小数 1是 2否
  1041. auto itPoint = itScoreBox->value.FindMember("point");
  1042. if (itPoint != itScoreBox->value.MemberEnd()){
  1043. if (itPoint->value.IsInt()){
  1044. q.scoreBox.bPoint = (itPoint->value.GetInt() == 1);
  1045. }
  1046. else if (itPoint->value.IsString()){
  1047. std::string str = itPoint->value.GetString();
  1048. q.scoreBox.bPoint = (str == "1");
  1049. }
  1050. }
  1051. // 填空题带打分
  1052. if (q.scoreBox.type == 3){
  1053. auto itScore = itScoreBox->value.FindMember("Score");
  1054. if (itScore != itScoreBox->value.MemberEnd() && itScore->value.IsArray()){
  1055. for (auto it = itScore->value.Begin(); it != itScore->value.End(); ++it){
  1056. if (it->IsString()){
  1057. std::string str = it->GetString();
  1058. if (!str.empty())
  1059. q.scoreBox.vctScore.push_back(std::stoi(str));
  1060. }
  1061. }
  1062. }
  1063. }
  1064. // 打分位置
  1065. auto t = pfGetPos(itScoreBox->value);
  1066. if (std::get<0>(t))
  1067. q.scoreBox.pos = std::get<1>(t);
  1068. }
  1069. // 几选几
  1070. if (q.type == 2 || q.type == 4){ // 选做题
  1071. rapidjson::Value::ConstMemberIterator itSel = it->FindMember("select");
  1072. if (itSel != it->MemberEnd() && itSel->value.IsInt()){
  1073. q.selItem = itSel->value.GetInt();
  1074. }
  1075. rapidjson::Value::ConstMemberIterator itTotal = it->FindMember("total");
  1076. if (itTotal != it->MemberEnd() && itTotal->value.IsInt()){
  1077. q.selTotal = itTotal->value.GetInt();
  1078. }
  1079. }
  1080. // 剪裁区域
  1081. if (q.type == 1 || q.type == 3 || q.type == 2 || q.type == 4){ // 1 解答题 2 选做题 3 填空题
  1082. auto itCut = it->FindMember("cut");
  1083. if (itCut != it->MemberEnd() && itCut->value.IsObject()){
  1084. auto itLink = itCut->value.FindMember("linkparm");
  1085. if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
  1086. q.cut.linkparm = itLink->value.GetInt();
  1087. if (itLink != itCut->value.MemberEnd() && itLink->value.IsString())
  1088. q.cut.linkparm = std::stoi(itLink->value.GetString());
  1089. auto t = pfGetPos(itCut->value);
  1090. if (std::get<0>(t))
  1091. q.cut.pos = std::get<1>(t);
  1092. if (q.type == 3 && m_onlineCardTemplate->subject_id == 8)
  1093. {
  1094. TCHAR FilePath[MAX_PATH];
  1095. GetModuleFileName(NULL, FilePath, MAX_PATH);
  1096. (_tcsrchr(FilePath, '\\'))[1] = 0;
  1097. lstrcat(FilePath, _T("config.ini"));
  1098. int english = GetPrivateProfileInt(_T("USER"), _T("english_height"), 30, FilePath);//英语填空题高度加大比例
  1099. if (english > 0 && english <= 30)
  1100. {
  1101. q.cut.pos.h = q.cut.pos.h* (1.0 + english / 100.0);
  1102. }
  1103. }
  1104. }
  1105. if (q.type == 2){
  1106. if (temp_all_id != q.all_id)
  1107. {
  1108. temp_all_id = q.all_id;
  1109. n_duo_xuanti_index = 0;
  1110. }
  1111. if (q.cut.linkparm < 2){
  1112. std::vector<std::string> split_qr;
  1113. split(q.all_id, (std::string)",", &split_qr);
  1114. if (n_duo_xuanti_index < split_qr.size())
  1115. q.id = split_qr[n_duo_xuanti_index++];
  1116. }
  1117. else
  1118. {
  1119. std::vector<std::string> split_qr;
  1120. split(q.all_id, (std::string)",", &split_qr);
  1121. if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
  1122. q.id = split_qr[n_duo_xuanti_index - 1];
  1123. }
  1124. }
  1125. else if (q.type == 4)
  1126. {
  1127. if (temp_all_id != q.all_id)
  1128. {
  1129. temp_all_id = q.all_id;
  1130. n_duo_xuanti_index = 0;
  1131. }
  1132. if (q.cut.linkparm < 1){
  1133. std::vector<std::string> split_qr;
  1134. split(q.all_id, (std::string)",", &split_qr);
  1135. if (n_duo_xuanti_index < split_qr.size())
  1136. q.id = split_qr[n_duo_xuanti_index++];
  1137. }
  1138. else
  1139. {
  1140. std::vector<std::string> split_qr;
  1141. split(q.all_id, (std::string)",", &split_qr);
  1142. if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
  1143. q.id = split_qr[n_duo_xuanti_index - 1];
  1144. }
  1145. }
  1146. }
  1147. // 选项 单选题 多选题
  1148. if (q.type == 0 || q.type == 8 || q.type == 5){
  1149. auto itOpts = it->FindMember("opt");
  1150. if (itOpts != it->MemberEnd() && itOpts->value.IsArray()){
  1151. for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt){
  1152. Opt opt;
  1153. auto t = pfGetPos(*itOpt);
  1154. if (std::get<0>(t))
  1155. opt.pos = std::get<1>(t);
  1156. auto itOptName = itOpt->FindMember("optName");
  1157. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  1158. opt.optName = itOptName->value.GetString();
  1159. q.opt.push_back(opt);
  1160. }
  1161. }
  1162. }
  1163. else if (q.type == 2 || q.type == 4){ // 选作
  1164. auto itSelectqts = it->FindMember("selectqts");
  1165. if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
  1166. for (auto itOpt = itSelectqts->value.Begin(); itOpt != itSelectqts->value.End(); ++itOpt){
  1167. Opt opt;
  1168. auto t = pfGetPos(*itOpt);
  1169. if (std::get<0>(t))
  1170. opt.pos = std::get<1>(t);
  1171. auto itOptName = itOpt->FindMember("optName");
  1172. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  1173. opt.optName = itOptName->value.GetString();
  1174. q.opt.push_back(opt);
  1175. }
  1176. }
  1177. }
  1178. page.vctQuestions.push_back(q);
  1179. }
  1180. }
  1181. m_onlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
  1182. }
  1183. }
  1184. else{
  1185. return false;
  1186. }
  1187. }
  1188. m_onlineCardTemplate->open_save_debug_img = false;
  1189. m_onlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
  1190. m_onlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
  1191. m_onlineCardTemplate->dingweidian_w_max_rate = 1.0;
  1192. m_onlineCardTemplate->dingweidian_h_max_rate = 1.0;
  1193. m_onlineCardTemplate->dingweidian_w_min_rate = 0.7;
  1194. m_onlineCardTemplate->dingweidian_h_min_rate = 0.7;
  1195. CString _ini_file = GetExePath() + _T("\\config.ini");
  1196. TCHAR sz_offset_file_name[MAX_PATH] = { 0 };
  1197. GetPrivateProfileString(_T("USER"), _T("offset_file"), _T(""), sz_offset_file_name, sizeof(sz_offset_file_name) / sizeof(TCHAR), _ini_file);
  1198. ParseTemplateOffset(UnicodeToAnsi(GetExePath() + _T("\\") + sz_offset_file_name), m_onlineCardTemplate);
  1199. return true;
  1200. }
  1201. bool CBatchService::ParseTemplateFromJson(const std::string&fileName)
  1202. {
  1203. CUnZipFile uzip(CString(fileName.c_str()));
  1204. std::map<CString, std::vector<unsigned char>> map;
  1205. while (uzip.HasMoreEntry()){
  1206. CString fileNam;
  1207. uzip.GetNextEntry(fileNam);
  1208. char buffer[1024 * 8];
  1209. int len;
  1210. std::vector<unsigned char>& data = map[fileNam];
  1211. data.reserve(1024 * 128);
  1212. while ((len = uzip.Read(buffer, 1024 * 8)) > 0){
  1213. if (data.capacity() < data.size() + len){
  1214. int c = data.capacity() + 1024 * 128;
  1215. data.reserve(c);
  1216. }
  1217. int oldSize = data.size();
  1218. data.resize(oldSize + len);
  1219. char * dst = (char *)data.data() + oldSize;
  1220. memcpy(dst, buffer, len);
  1221. }
  1222. }
  1223. uzip.Close();
  1224. auto schemabytes = map.find(_T("json.txt"));
  1225. if (schemabytes == map.end()){
  1226. return SCH_LOAD_ERR_MISSINGFORMAT;
  1227. }
  1228. std::vector<unsigned char>& data = schemabytes->second;
  1229. auto strJson = std::string((char *)data.data(), data.size());
  1230. if (!m_onlineCardTemplate) return false;
  1231. m_onlineCardTemplate->pages.clear();
  1232. auto pfGetPos = [](const rapidjson::Value&value)->std::tuple<bool, Pos>{
  1233. bool bRet = false;
  1234. double x = 0.0, y = 0.0, w = 0.0, h = 0.0;
  1235. auto itX = value.FindMember("x");
  1236. if (itX != value.MemberEnd() && (itX->value.IsInt() || itX->value.IsDouble())){
  1237. x = itX->value.GetDouble();
  1238. }
  1239. auto itY = value.FindMember("y");
  1240. if (itY != value.MemberEnd() && (itY->value.IsInt() || itY->value.IsDouble())){
  1241. y = itY->value.GetDouble();
  1242. }
  1243. auto itW = value.FindMember("width");
  1244. if (itW != value.MemberEnd() && (itW->value.IsInt() || itW->value.IsDouble())){
  1245. w = itW->value.GetDouble();
  1246. }
  1247. auto itH = value.FindMember("height");
  1248. if (itH != value.MemberEnd() && (itH->value.IsInt() || itH->value.IsDouble())){
  1249. h = itH->value.GetDouble();
  1250. bRet = true;
  1251. }
  1252. return std::tie(bRet, Pos{ x, y, w, h });
  1253. };
  1254. rapidjson::Document doc;
  1255. doc.Parse(strJson.c_str());
  1256. if (doc.HasParseError()) return false;
  1257. m_onlineCardTemplate->subject_id = m_nSubjectID;
  1258. m_onlineCardTemplate->_version = "old";
  1259. auto isAllSubjectCard = doc.FindMember("isAllSubjectCard");
  1260. if (isAllSubjectCard != doc.MemberEnd() && isAllSubjectCard->value.IsInt()){
  1261. int nisAllSubjectCard = isAllSubjectCard->value.GetInt();
  1262. if (nisAllSubjectCard == 1)
  1263. {
  1264. return ParseTemplateFromJsonAll(fileName);
  1265. }
  1266. }
  1267. // 检测版本号
  1268. auto it_version = doc.FindMember("online_card_version");
  1269. if (it_version!= doc.MemberEnd() && it_version->value.IsString()){
  1270. m_onlineCardTemplate->_version = it_version->value.GetString();
  1271. }
  1272. LOGFMTI("在线答题卡版本号:%s",m_onlineCardTemplate->_version.c_str());
  1273. if (m_onlineCardTemplate->_version=="old"){
  1274. // 总页数
  1275. auto itTotalPage = doc.FindMember("totalPage");
  1276. if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
  1277. m_onlineCardTemplate->totalPage = itTotalPage->value.GetInt();
  1278. }
  1279. // 是否使用二维码
  1280. auto itUseQrCode = doc.FindMember("useQrCode");
  1281. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
  1282. m_onlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
  1283. }
  1284. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
  1285. m_onlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
  1286. }
  1287. // 学校状态
  1288. auto itSchoolStatus = doc.FindMember("school_card_status");
  1289. if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
  1290. m_onlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
  1291. }
  1292. int n_duo_xuanti_index = 0;
  1293. // 页
  1294. auto itPages = doc.FindMember("pages");
  1295. if (itPages != doc.MemberEnd() && itPages->value.IsArray() && itPages->value.Size() == m_onlineCardTemplate->totalPage){
  1296. for (auto itPage = itPages->value.Begin(); itPage != itPages->value.End(); ++itPage){
  1297. if (!itPage->IsObject()) return false;
  1298. PageTemplate page;
  1299. // 页号
  1300. auto itPageNo = itPage->FindMember("pageNo");
  1301. if (itPageNo != itPage->MemberEnd() && itPageNo->value.IsInt()){
  1302. page.pageNo = itPageNo->value.GetInt();
  1303. }
  1304. else {
  1305. return false;
  1306. }
  1307. // 定位点
  1308. auto itLocations = itPage->FindMember("location");
  1309. if (itLocations != itPage->MemberEnd() && itLocations->value.IsArray()){
  1310. for (auto it = itLocations->value.Begin(); it != itLocations->value.End(); ++it){
  1311. Location lc;
  1312. auto itType = it->FindMember("type");
  1313. if (itType != it->MemberEnd() && itType->value.IsInt()){
  1314. lc.type = itType->value.GetInt();
  1315. }
  1316. auto tm = pfGetPos(*it);
  1317. if (std::get<0>(tm)){
  1318. lc.pos = std::get<1>(tm);
  1319. }
  1320. page.location.push_back(lc);
  1321. }
  1322. }
  1323. if (page.pageNo == 1){
  1324. if (!m_onlineCardTemplate->useQrCode){
  1325. // 条形码
  1326. auto itBar = itPage->FindMember("studentcode_bar");
  1327. if (itBar != itPage->MemberEnd() && itBar->value.IsObject()){
  1328. auto itObj = itBar->value.FindMember("object");
  1329. if (itObj != itBar->value.MemberEnd() && itObj->value.IsObject()){
  1330. auto t = pfGetPos(itObj->value);
  1331. page.studentcode_bar = std::get<1>(t);
  1332. }
  1333. }
  1334. // 填涂考号
  1335. auto itFill = itPage->FindMember("studentcode_fill");
  1336. if (itFill != itPage->MemberEnd() && itFill->value.IsObject()){
  1337. auto itObj = itFill->value.FindMember("object");
  1338. if (itObj != itFill->value.MemberEnd() && itObj->value.IsArray()){
  1339. for (auto itRow = itObj->value.Begin(); itRow != itObj->value.End(); ++itRow){
  1340. auto itGroup = itRow->FindMember("group");
  1341. if (itGroup != itRow->MemberEnd() && itGroup->value.IsArray()){
  1342. std::vector<Opt> _vctOpt;
  1343. for (auto itCol = itGroup->value.Begin(); itCol != itGroup->value.End(); ++itCol){
  1344. Opt opt;
  1345. auto itOptName = itCol->FindMember("optName");
  1346. if (itOptName != itCol->MemberEnd() && itOptName->value.IsInt())
  1347. opt.optName = std::to_string(itOptName->value.GetInt());
  1348. auto t = pfGetPos(*itCol);
  1349. if (std::get<0>(t))
  1350. opt.pos = std::get<1>(t);
  1351. _vctOpt.push_back(opt);
  1352. }
  1353. page.studentcode_fill.push_back(_vctOpt);
  1354. }
  1355. }
  1356. }
  1357. }
  1358. }
  1359. // 缺考标记
  1360. auto itAbsent = itPage->FindMember("absent");
  1361. if (itAbsent != itPage->MemberEnd() && itAbsent->value.IsObject()){
  1362. auto t = pfGetPos(itAbsent->value);
  1363. if (std::get<0>(t)){
  1364. page.absent = std::get<1>(t);
  1365. }
  1366. }
  1367. // 二维码
  1368. auto itQrCode = itPage->FindMember("QrCode");
  1369. if (itQrCode != itPage->MemberEnd() && itQrCode->value.IsObject()){
  1370. auto t = pfGetPos(itQrCode->value);
  1371. if (std::get<0>(t)){
  1372. page.QrCode = std::get<1>(t);
  1373. }
  1374. }
  1375. } // end if page.pageNo == 0
  1376. // 长宽
  1377. auto itImge = itPage->FindMember("imge");
  1378. if (itImge != itPage->MemberEnd()){
  1379. auto t = std::get<1>(pfGetPos(itImge->value));
  1380. page.w = t.w;
  1381. page.h = t.h;
  1382. }
  1383. else{
  1384. return false;
  1385. }
  1386. // 题目
  1387. auto itQuestion = itPage->FindMember("questions");
  1388. if (itQuestion != itPage->MemberEnd() && itQuestion->value.IsArray()){
  1389. for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
  1390. question q;
  1391. // 题目类型
  1392. auto itType = it->FindMember("type");
  1393. if (itType != it->MemberEnd() && itType->value.IsInt()){
  1394. q.type = itType->value.GetInt();
  1395. }
  1396. else{
  1397. return false;
  1398. }
  1399. q.marktype = 0;
  1400. // 题目类型
  1401. auto itMarktype = it->FindMember("marktype");
  1402. if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
  1403. q.marktype = itMarktype->value.GetInt();
  1404. }
  1405. // 分数
  1406. auto itScore = it->FindMember("score");
  1407. if (itScore != it->MemberEnd() && itScore->value.IsObject()){
  1408. auto itFull = itScore->value.FindMember("full");
  1409. if (itFull != itScore->value.MemberEnd() && (itFull->value.IsDouble() || itFull->value.IsInt()))
  1410. q.score = itFull->value.GetDouble();
  1411. }
  1412. // 题目编号 2选做题
  1413. auto itId = it->FindMember(q.type == 2 ? "editorId" : "id");
  1414. if (itId != it->MemberEnd() && itId->value.IsString()){
  1415. q.id = itId->value.GetString();
  1416. }
  1417. if (q.type == 2){
  1418. auto itAllID = it->FindMember("id");
  1419. if (itAllID != it->MemberEnd() && itAllID->value.IsString()){
  1420. q.all_id = itAllID->value.GetString();
  1421. }
  1422. }
  1423. // 目前应该只有填空题有这个参数
  1424. auto itSmallQtNo = it->FindMember("smallQtNo");
  1425. if (itSmallQtNo != it->MemberEnd() && !(itSmallQtNo->value.IsNull()))
  1426. {
  1427. q.smallQtNo = itSmallQtNo->value.GetInt();
  1428. }
  1429. else
  1430. {
  1431. q.smallQtNo = -1;
  1432. }
  1433. // 打分区域
  1434. auto itScoreBox = it->FindMember("scorebox");
  1435. if (itScoreBox != it->MemberEnd() && itScoreBox->value.IsObject()){
  1436. // 打分框类型
  1437. auto itType = itScoreBox->value.FindMember("type");
  1438. if (itType != itScoreBox->value.MemberEnd() && itType->value.IsString()){
  1439. q.scoreBox.type = std::stoi(itType->value.GetString());
  1440. }
  1441. else if (itType != itScoreBox->value.MemberEnd() && itType->value.IsInt()){
  1442. q.scoreBox.type = itType->value.GetInt();
  1443. }
  1444. else{
  1445. return false;
  1446. }
  1447. // 分数上限
  1448. auto itLimit = itScoreBox->value.FindMember("limit");
  1449. if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsString())
  1450. q.scoreBox.limit = std::stoi(itLimit->value.GetString());
  1451. // 最后一个格子是否为小数 1是 2否
  1452. auto itPoint = itScoreBox->value.FindMember("point");
  1453. if (itPoint != itScoreBox->value.MemberEnd()){
  1454. if (itPoint->value.IsInt()){
  1455. if (itPoint->value.GetInt() == 1 || itPoint->value.GetInt() == 2)
  1456. q.scoreBox.bPoint = (itPoint->value.GetInt() == 1);
  1457. }
  1458. else if (itPoint->value.IsString()){
  1459. std::string str = itPoint->value.GetString();
  1460. if (str == "1" || str == "2")
  1461. q.scoreBox.bPoint = (str == "1");
  1462. }
  1463. }
  1464. // 填空题带打分
  1465. if (q.scoreBox.type == 3){
  1466. auto itScore = itScoreBox->value.FindMember("Score");
  1467. if (itScore != itScoreBox->value.MemberEnd() && itScore->value.IsArray()){
  1468. for (auto it = itScore->value.Begin(); it != itScore->value.End(); ++it){
  1469. if (it->IsString()){
  1470. std::string str = it->GetString();
  1471. if (!str.empty())
  1472. q.scoreBox.vctScore.push_back(std::stoi(str));
  1473. }
  1474. }
  1475. }
  1476. }
  1477. // 打分位置
  1478. auto t = pfGetPos(itScoreBox->value);
  1479. if (std::get<0>(t))
  1480. q.scoreBox.pos = std::get<1>(t);
  1481. }
  1482. // 剪裁区域
  1483. if (q.type == 1 || q.type == 3){
  1484. auto itCut = it->FindMember("cut");
  1485. if (itCut != it->MemberEnd() && itCut->value.IsObject()){
  1486. auto itLink = itCut->value.FindMember("linkparm");
  1487. if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
  1488. q.cut.linkparm = itLink->value.GetInt();
  1489. auto t = pfGetPos(itCut->value);
  1490. if (std::get<0>(t))
  1491. q.cut.pos = std::get<1>(t);
  1492. if (q.type == 3 && m_onlineCardTemplate->subject_id == 8)
  1493. {
  1494. TCHAR FilePath[MAX_PATH];
  1495. GetModuleFileName(NULL, FilePath, MAX_PATH);
  1496. (_tcsrchr(FilePath, '\\'))[1] = 0;
  1497. lstrcat(FilePath, _T("config.ini"));
  1498. int english = GetPrivateProfileInt(_T("USER"), _T("english_height"), 30, FilePath);//英语填空题高度加大比例
  1499. if (english > 0 && english <= 30)
  1500. {
  1501. q.cut.pos.h = q.cut.pos.h* (1.0 + english / 100.0);
  1502. }
  1503. }
  1504. }
  1505. }
  1506. else if (q.type == 2){ // 选做题
  1507. rapidjson::Value::ConstMemberIterator itSel = it->FindMember("select");
  1508. if (itSel != it->MemberEnd() && itSel->value.IsInt()){
  1509. q.selItem = itSel->value.GetInt();
  1510. }
  1511. rapidjson::Value::ConstMemberIterator itTotal = it->FindMember("total");
  1512. if (itTotal != it->MemberEnd() && itTotal->value.IsInt()){
  1513. q.selTotal = itTotal->value.GetInt();
  1514. }
  1515. auto itSelectqts = it->FindMember("selectqts");
  1516. if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
  1517. rapidjson::Value::ConstMemberIterator itCut = itSelectqts->value.Begin()->FindMember("cut");
  1518. if (itCut != itSelectqts->value.Begin()->MemberEnd() && itCut->value.IsObject()){
  1519. rapidjson::Value::ConstMemberIterator itLink = itCut->value.FindMember("linkparm");
  1520. if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
  1521. q.cut.linkparm = itLink->value.GetInt();
  1522. auto t = pfGetPos(itCut->value);
  1523. if (std::get<0>(t))
  1524. q.cut.pos = std::get<1>(t);
  1525. }
  1526. }
  1527. if (q.cut.linkparm < 2){
  1528. std::vector<std::string> split_qr;
  1529. split(q.all_id, (std::string)",", &split_qr);
  1530. if (n_duo_xuanti_index < split_qr.size())
  1531. q.id = split_qr[n_duo_xuanti_index++];
  1532. }
  1533. else
  1534. {
  1535. std::vector<std::string> split_qr;
  1536. split(q.all_id, (std::string)",", &split_qr);
  1537. if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
  1538. q.id = split_qr[n_duo_xuanti_index - 1];
  1539. }
  1540. }
  1541. // 选项 单选题 多选题
  1542. if (q.type == 0 || q.type == 8 || q.type == 5){
  1543. auto itOpts = it->FindMember("opt");
  1544. if (itOpts != it->MemberEnd() && itOpts->value.IsArray()){
  1545. int i = 0;
  1546. for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt,++i){
  1547. Opt opt;
  1548. auto t = pfGetPos(*itOpt);
  1549. if (std::get<0>(t))
  1550. opt.pos = std::get<1>(t);
  1551. auto itOptName = itOpt->FindMember("optName");
  1552. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  1553. opt.optName = itOptName->value.GetString();
  1554. q.opt.push_back(opt);
  1555. }
  1556. }
  1557. }
  1558. else if (q.type == 2){ // 多选题
  1559. auto itSelectqts = it->FindMember("selectqts");
  1560. if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
  1561. auto itOpts = itSelectqts->value.Begin()->FindMember("opt");
  1562. if (itOpts != itSelectqts->value.Begin()->MemberEnd() && itOpts->value.IsArray()){
  1563. q.selTotal = itOpts->value.Size();
  1564. for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt){
  1565. Opt opt;
  1566. auto t = pfGetPos(*itOpt);
  1567. if (std::get<0>(t))
  1568. opt.pos = std::get<1>(t);
  1569. auto itOptName = itOpt->FindMember("optName");
  1570. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  1571. opt.optName = itOptName->value.GetString();
  1572. q.opt.push_back(opt);
  1573. }
  1574. }
  1575. }
  1576. }
  1577. page.vctQuestions.push_back(q);
  1578. }
  1579. }
  1580. m_onlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
  1581. }
  1582. }
  1583. else{
  1584. return false;
  1585. }
  1586. }
  1587. else{
  1588. // 总页数
  1589. auto itTotalPage = doc.FindMember("totalPage");
  1590. if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
  1591. m_onlineCardTemplate->totalPage = itTotalPage->value.GetInt();
  1592. }
  1593. // 是否使用二维码
  1594. auto itUseQrCode = doc.FindMember("useQrCode");
  1595. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
  1596. m_onlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
  1597. }
  1598. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
  1599. m_onlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
  1600. }
  1601. // 学校状态
  1602. auto itSchoolStatus = doc.FindMember("school_card_status");
  1603. if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
  1604. m_onlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
  1605. }
  1606. int n_duo_xuanti_index = 0;
  1607. std::string temp_all_id = "";
  1608. // 页
  1609. auto itPages = doc.FindMember("pages");
  1610. if (itPages != doc.MemberEnd() && itPages->value.IsArray()/* && itPages->value.Size() == m_onlineCardTemplate->totalPage*/){
  1611. for (auto itPage = itPages->value.Begin(); itPage != itPages->value.End(); ++itPage){
  1612. if (!itPage->IsObject()) return false;
  1613. PageTemplate page;
  1614. // 页号
  1615. auto itPageNo = itPage->FindMember("pageNo");
  1616. if (itPageNo != itPage->MemberEnd() && itPageNo->value.IsInt()){
  1617. page.pageNo = itPageNo->value.GetInt();
  1618. }
  1619. else {
  1620. return false;
  1621. }
  1622. // 定位点
  1623. auto itLocations = itPage->FindMember("location");
  1624. if (itLocations != itPage->MemberEnd() && itLocations->value.IsArray()){
  1625. for (auto it = itLocations->value.Begin(); it != itLocations->value.End(); ++it){
  1626. Location lc;
  1627. auto itType = it->FindMember("type");
  1628. if (itType != it->MemberEnd() && itType->value.IsInt()){
  1629. lc.type = itType->value.GetInt();
  1630. }
  1631. auto tm = pfGetPos(*it);
  1632. if (std::get<0>(tm)){
  1633. lc.pos = std::get<1>(tm);
  1634. }
  1635. page.location.push_back(lc);
  1636. }
  1637. }
  1638. if (page.pageNo == 1){
  1639. if (!m_onlineCardTemplate->useQrCode){
  1640. // 条形码
  1641. auto itBar = itPage->FindMember("studentcode_bar");
  1642. if (itBar != itPage->MemberEnd() && itBar->value.IsObject()){
  1643. auto itObj = itBar->value.FindMember("object");
  1644. if (itObj != itBar->value.MemberEnd() && itObj->value.IsObject()){
  1645. auto t = pfGetPos(itObj->value);
  1646. page.studentcode_bar = std::get<1>(t);
  1647. }
  1648. }
  1649. // 填涂考号
  1650. auto itFill = itPage->FindMember("studentcode_fill");
  1651. if (itFill != itPage->MemberEnd() && itFill->value.IsObject()){
  1652. auto itObj = itFill->value.FindMember("object");
  1653. if (itObj != itFill->value.MemberEnd() && itObj->value.IsArray()){
  1654. for (auto itRow = itObj->value.Begin(); itRow != itObj->value.End(); ++itRow){
  1655. auto itGroup = itRow->FindMember("group");
  1656. if (itGroup != itRow->MemberEnd() && itGroup->value.IsArray()){
  1657. std::vector<Opt> _vctOpt;
  1658. for (auto itCol = itGroup->value.Begin(); itCol != itGroup->value.End(); ++itCol){
  1659. Opt opt;
  1660. auto itOptName = itCol->FindMember("optName");
  1661. if (itOptName != itCol->MemberEnd() && itOptName->value.IsInt())
  1662. opt.optName = std::to_string(itOptName->value.GetInt());
  1663. auto t = pfGetPos(*itCol);
  1664. if (std::get<0>(t))
  1665. opt.pos = std::get<1>(t);
  1666. _vctOpt.push_back(opt);
  1667. }
  1668. page.studentcode_fill.push_back(_vctOpt);
  1669. }
  1670. }
  1671. }
  1672. }
  1673. }
  1674. // 缺考标记
  1675. auto itAbsent = itPage->FindMember("absent");
  1676. if (itAbsent != itPage->MemberEnd() && itAbsent->value.IsObject()){
  1677. auto t = pfGetPos(itAbsent->value);
  1678. if (std::get<0>(t)){
  1679. page.absent = std::get<1>(t);
  1680. }
  1681. }
  1682. // 二维码
  1683. auto itQrCode = itPage->FindMember("QrCode");
  1684. if (itQrCode != itPage->MemberEnd() && itQrCode->value.IsObject()){
  1685. auto t = pfGetPos(itQrCode->value);
  1686. if (std::get<0>(t)){
  1687. page.QrCode = std::get<1>(t);
  1688. }
  1689. }
  1690. } // end if page.pageNo == 0
  1691. // 长宽
  1692. auto itImge = itPage->FindMember("imge");
  1693. if (itImge != itPage->MemberEnd()){
  1694. auto t = std::get<1>(pfGetPos(itImge->value));
  1695. page.w = t.w;
  1696. page.h = t.h;
  1697. }
  1698. else{
  1699. return false;
  1700. }
  1701. // 题目
  1702. auto itQuestion = itPage->FindMember("questions");
  1703. if (itQuestion != itPage->MemberEnd() && itQuestion->value.IsArray()){
  1704. for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
  1705. question q;
  1706. // 题目类型
  1707. auto itType = it->FindMember("type");
  1708. if (itType != it->MemberEnd() && itType->value.IsInt()){
  1709. q.type = itType->value.GetInt();
  1710. }
  1711. else{
  1712. return false;
  1713. }
  1714. q.marktype = 0;
  1715. // 题目类型
  1716. auto itMarktype = it->FindMember("marktype");
  1717. if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
  1718. q.marktype = itMarktype->value.GetInt();
  1719. }
  1720. // 分数
  1721. auto itScore = it->FindMember("score");
  1722. if (itScore != it->MemberEnd() && itScore->value.IsObject()){
  1723. auto itFull = itScore->value.FindMember("full");
  1724. if (itFull != itScore->value.MemberEnd() && (itFull->value.IsDouble() || itFull->value.IsInt()))
  1725. q.score = itFull->value.GetDouble();
  1726. }
  1727. // 题目编号 2选做题
  1728. auto itId = it->FindMember((q.type == 2 || q.type == 4 )? "editorId" : "id");
  1729. if (itId != it->MemberEnd() && itId->value.IsString()){
  1730. q.id = itId->value.GetString();
  1731. }
  1732. if (itId != it->MemberEnd() && itId->value.IsInt()){
  1733. q.id = std::to_string(itId->value.GetInt());
  1734. }
  1735. if (q.type == 2 || q.type == 4){
  1736. auto itAllID = it->FindMember("id");
  1737. if (itAllID != it->MemberEnd() && itAllID->value.IsString()){
  1738. q.all_id = itAllID->value.GetString();
  1739. }
  1740. }
  1741. auto itSmallQtNo = it->FindMember("smallQtNo");
  1742. if (itSmallQtNo != it->MemberEnd() && !(itSmallQtNo->value.IsNull()))
  1743. {
  1744. q.smallQtNo = itSmallQtNo->value.GetInt();
  1745. }
  1746. else
  1747. {
  1748. q.smallQtNo = -1;
  1749. }
  1750. auto itNickID = it->FindMember("name");
  1751. if (itNickID != it->MemberEnd() && !(itNickID->value.IsNull()) && itNickID->value.IsInt())
  1752. {
  1753. m_mapKeguantiNickName[q.id] = std::to_string(itNickID->value.GetInt());
  1754. }
  1755. // 打分区域
  1756. auto itScoreBox = it->FindMember("scorebox");
  1757. if (itScoreBox != it->MemberEnd() && itScoreBox->value.IsObject()){
  1758. // 打分框类型
  1759. auto itType = itScoreBox->value.FindMember("type");
  1760. if (itType != itScoreBox->value.MemberEnd() && itType->value.IsString()){
  1761. q.scoreBox.type = std::stoi(itType->value.GetString());
  1762. }
  1763. else if (itType != itScoreBox->value.MemberEnd() && itType->value.IsInt()){
  1764. q.scoreBox.type = itType->value.GetInt();
  1765. }
  1766. else{
  1767. return false;
  1768. }
  1769. if (q.smallQtNo != -1)
  1770. {
  1771. // 小问最大分值
  1772. auto itmaxScore = itScoreBox->value.FindMember("maxscore");
  1773. if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsString()){
  1774. q.scoreBox.maxsorce = std::stod(itmaxScore->value.GetString());
  1775. }
  1776. else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsDouble()){
  1777. q.scoreBox.maxsorce = itScoreBox->value.GetDouble();
  1778. }
  1779. else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsInt()){
  1780. q.scoreBox.maxsorce = itmaxScore->value.GetInt();
  1781. }
  1782. else{
  1783. q.scoreBox.maxsorce = 0.0;
  1784. }
  1785. }
  1786. else
  1787. {
  1788. q.scoreBox.maxsorce = 0.0;
  1789. }
  1790. // 分数上限
  1791. auto itLimit = itScoreBox->value.FindMember("limit");
  1792. if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsString())
  1793. q.scoreBox.limit = std::stoi(itLimit->value.GetString());
  1794. if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsInt())
  1795. q.scoreBox.limit = itLimit->value.GetInt();
  1796. // 最后一个格子是否为小数 1是 2否
  1797. auto itPoint = itScoreBox->value.FindMember("point");
  1798. if (itPoint != itScoreBox->value.MemberEnd()){
  1799. if (itPoint->value.IsInt()){
  1800. q.scoreBox.bPoint = (itPoint->value.GetInt() == 1);
  1801. }
  1802. else if (itPoint->value.IsString()){
  1803. std::string str = itPoint->value.GetString();
  1804. q.scoreBox.bPoint = (str == "1");
  1805. }
  1806. }
  1807. // 填空题带打分
  1808. if (q.scoreBox.type == 3){
  1809. auto itScore = itScoreBox->value.FindMember("Score");
  1810. if (itScore != itScoreBox->value.MemberEnd() && itScore->value.IsArray()){
  1811. for (auto it = itScore->value.Begin(); it != itScore->value.End(); ++it){
  1812. if (it->IsString()){
  1813. std::string str = it->GetString();
  1814. if (!str.empty())
  1815. q.scoreBox.vctScore.push_back(std::stoi(str));
  1816. }
  1817. }
  1818. }
  1819. }
  1820. // 打分位置
  1821. auto t = pfGetPos(itScoreBox->value);
  1822. if (std::get<0>(t))
  1823. q.scoreBox.pos = std::get<1>(t);
  1824. }
  1825. // 几选几
  1826. if (q.type == 2 || q.type == 4){ // 选做题
  1827. rapidjson::Value::ConstMemberIterator itSel = it->FindMember("select");
  1828. if (itSel != it->MemberEnd() && itSel->value.IsInt()){
  1829. q.selItem = itSel->value.GetInt();
  1830. }
  1831. rapidjson::Value::ConstMemberIterator itTotal = it->FindMember("total");
  1832. if (itTotal != it->MemberEnd() && itTotal->value.IsInt()){
  1833. q.selTotal = itTotal->value.GetInt();
  1834. }
  1835. }
  1836. // 剪裁区域
  1837. if (q.type == 1 || q.type == 3 || q.type == 2 || q.type == 4){ // 1 解答题 2 选做题 3 填空题
  1838. auto itCut = it->FindMember("cut");
  1839. if (itCut != it->MemberEnd() && itCut->value.IsObject()){
  1840. auto itLink = itCut->value.FindMember("linkparm");
  1841. if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
  1842. q.cut.linkparm = itLink->value.GetInt();
  1843. if (itLink != itCut->value.MemberEnd() && itLink->value.IsString())
  1844. q.cut.linkparm = std::stoi(itLink->value.GetString());
  1845. auto t = pfGetPos(itCut->value);
  1846. if (std::get<0>(t))
  1847. q.cut.pos = std::get<1>(t);
  1848. if (q.type == 3 && m_onlineCardTemplate->subject_id==8)
  1849. {
  1850. TCHAR FilePath[MAX_PATH];
  1851. GetModuleFileName(NULL, FilePath, MAX_PATH);
  1852. (_tcsrchr(FilePath, '\\'))[1] = 0;
  1853. lstrcat(FilePath, _T("config.ini"));
  1854. int english = GetPrivateProfileInt(_T("USER"), _T("english_height"), 30, FilePath);//英语填空题高度加大比例
  1855. if (english > 0 && english <= 30)
  1856. {
  1857. q.cut.pos.h = q.cut.pos.h* (1.0 + english / 100.0);
  1858. }
  1859. }
  1860. }
  1861. if (q.type == 2){
  1862. if (temp_all_id != q.all_id)
  1863. {
  1864. temp_all_id = q.all_id;
  1865. n_duo_xuanti_index = 0;
  1866. }
  1867. if (q.cut.linkparm < 2){
  1868. std::vector<std::string> split_qr;
  1869. split(q.all_id, (std::string)",", &split_qr);
  1870. if (n_duo_xuanti_index < split_qr.size())
  1871. q.id = split_qr[n_duo_xuanti_index++];
  1872. }
  1873. else
  1874. {
  1875. std::vector<std::string> split_qr;
  1876. split(q.all_id, (std::string)",", &split_qr);
  1877. if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
  1878. q.id = split_qr[n_duo_xuanti_index - 1];
  1879. }
  1880. }
  1881. else if (q.type == 4)
  1882. {
  1883. if (temp_all_id != q.all_id)
  1884. {
  1885. temp_all_id = q.all_id;
  1886. n_duo_xuanti_index = 0;
  1887. }
  1888. if (q.cut.linkparm < 1){
  1889. std::vector<std::string> split_qr;
  1890. split(q.all_id, (std::string)",", &split_qr);
  1891. if (n_duo_xuanti_index < split_qr.size())
  1892. q.id = split_qr[n_duo_xuanti_index++];
  1893. }
  1894. else
  1895. {
  1896. std::vector<std::string> split_qr;
  1897. split(q.all_id, (std::string)",", &split_qr);
  1898. if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
  1899. q.id = split_qr[n_duo_xuanti_index - 1];
  1900. }
  1901. }
  1902. }
  1903. // 选项 单选题 多选题
  1904. if (q.type == 0 || q.type == 8 || q.type == 5){
  1905. auto itOpts = it->FindMember("opt");
  1906. if (itOpts != it->MemberEnd() && itOpts->value.IsArray()){
  1907. for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt){
  1908. Opt opt;
  1909. auto t = pfGetPos(*itOpt);
  1910. if (std::get<0>(t))
  1911. opt.pos = std::get<1>(t);
  1912. auto itOptName = itOpt->FindMember("optName");
  1913. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  1914. opt.optName = itOptName->value.GetString();
  1915. q.opt.push_back(opt);
  1916. }
  1917. }
  1918. }
  1919. else if (q.type == 2 || q.type == 4){ // 多选题
  1920. auto itSelectqts = it->FindMember("selectqts");
  1921. if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
  1922. for (auto itOpt = itSelectqts->value.Begin(); itOpt != itSelectqts->value.End(); ++itOpt){
  1923. Opt opt;
  1924. auto t = pfGetPos(*itOpt);
  1925. if (std::get<0>(t))
  1926. opt.pos = std::get<1>(t);
  1927. auto itOptName = itOpt->FindMember("optName");
  1928. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  1929. opt.optName = itOptName->value.GetString();
  1930. q.opt.push_back(opt);
  1931. }
  1932. }
  1933. }
  1934. page.vctQuestions.push_back(q);
  1935. }
  1936. }
  1937. m_onlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
  1938. }
  1939. }
  1940. else{
  1941. return false;
  1942. }
  1943. }
  1944. m_onlineCardTemplate->open_save_debug_img = false;
  1945. m_onlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
  1946. m_onlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
  1947. m_onlineCardTemplate->dingweidian_w_max_rate = 1.0;
  1948. m_onlineCardTemplate->dingweidian_h_max_rate = 1.0;
  1949. m_onlineCardTemplate->dingweidian_w_min_rate = 0.7;
  1950. m_onlineCardTemplate->dingweidian_h_min_rate = 0.7;
  1951. CString _ini_file = GetExePath() + _T("\\config.ini");
  1952. TCHAR sz_offset_file_name[MAX_PATH] = { 0 };
  1953. GetPrivateProfileString(_T("USER"), _T("offset_file"), _T(""), sz_offset_file_name, sizeof(sz_offset_file_name) / sizeof(TCHAR), _ini_file);
  1954. ParseTemplateOffset(UnicodeToAnsi(GetExePath() + _T("\\") + sz_offset_file_name), m_onlineCardTemplate);
  1955. return true;
  1956. }
  1957. int CBatchService::loadDuXueFirstMode()
  1958. {
  1959. TCHAR FilePath[MAX_PATH];
  1960. GetModuleFileName(NULL, FilePath, MAX_PATH);
  1961. (_tcsrchr(FilePath, '\\'))[1] = 0;
  1962. TCHAR FileName[50];
  1963. _stprintf(FileName, _T("\\mode\\student1.schema"));
  1964. lstrcat(FilePath, FileName);
  1965. CT2CA pszConvertedAnsiString(FilePath);
  1966. std::string schemaPath(pszConvertedAnsiString);
  1967. CSchemaLoader schemaLoader;
  1968. int ret = schemaLoader.Load(schemaPath, m_muban_img_dir, m_schema0, m_schema, m_handleInfo);
  1969. return ret;
  1970. }
  1971. //停止扫描处理函数
  1972. ServiceState CBatchService::OnStoping(void)
  1973. {
  1974. mainService->Stop();
  1975. while (mainService->GetServiceSate()!=stoped)
  1976. {
  1977. Sleep(10);
  1978. }
  1979. if (g_my_scan_type == 1&&g_myindex < MAX_STRUENTS_NUM)
  1980. {
  1981. TCHAR FilePath[MAX_PATH];
  1982. GetModuleFileName(NULL, FilePath, MAX_PATH);
  1983. (_tcsrchr(FilePath, '\\'))[1] = 0;
  1984. TCHAR FileName[50];
  1985. _stprintf(FileName, _T("\\mode\\student%d.schema"), g_myindex+1);
  1986. lstrcat(FilePath, FileName);
  1987. CT2CA pszConvertedAnsiString(FilePath);
  1988. std::string schemaPath(pszConvertedAnsiString);
  1989. CSchemaLoader schemaLoader;
  1990. int ret = schemaLoader.Load(schemaPath, m_muban_img_dir, m_schema0, m_schema, m_handleInfo);
  1991. g_myindex++;
  1992. ServiceState nextState = OnStarting();
  1993. return nextState;
  1994. }
  1995. char sql[128];
  1996. sprintf_s(sql, "update database set database_state =%d where database_id =%d", DATABASE_STATE_SCAN_OVER, m_database_id);
  1997. EnterCriticalSection(database_db_lock);
  1998. database_db->execDML("begin transaction");
  1999. database_db->execDML(sql);
  2000. database_db->execDML("commit transaction");
  2001. LeaveCriticalSection(database_db_lock);
  2002. if (m_hwnd != NULL&&m_abnormal_stop == FALSE)
  2003. {
  2004. ::PostMessage(m_hwnd, WM_IDENTIFOR_COMPLETE, 0, 0);
  2005. }
  2006. ServiceState nextState = IService::OnStoping();
  2007. if (nextState == stoped&&m_hwnd != NULL)
  2008. {
  2009. ::PostMessage(m_hwnd, WM_IDENTIFOR_STOPED, 0, 0);
  2010. }
  2011. return nextState;
  2012. }
  2013. #include <io.h>
  2014. #include <stdio.h>
  2015. #include <stdlib.h>
  2016. //设置消息接收窗口
  2017. int CBatchService::SetHandlerWnd(HWND hwnd)
  2018. {
  2019. m_hwnd = hwnd;
  2020. if (mainService.get()){
  2021. mainService->SetHandlerWnd(hwnd);
  2022. }
  2023. return TRUE;
  2024. }
  2025. //检测服务是是否可以访问
  2026. bool testServerAvaiable2(const CString& serverAdd){
  2027. std::string response;
  2028. CHttpClient httpClient;
  2029. CString url;
  2030. url.Format(_T("%s/course/findAllCourse"), serverAdd);
  2031. httpClient.HttpGet(url, NULL, response);
  2032. Json::Value root;
  2033. Json::Reader(Json::Features()).parse(response, root);
  2034. if (root["success"].isInt() && root["success"].asInt() == 1){
  2035. return true;
  2036. }
  2037. return false;
  2038. }
  2039. /*
  2040. 准备扫描
  2041. 1、检测本地服务器状态
  2042. 2、创建当前批次目录
  2043. 3、创建当前批次数据库
  2044. 4、创建主要服务
  2045. */
  2046. int CBatchService::ReadyScan(FEEDER_TYPE feederType, const ScanParam & param)
  2047. {
  2048. m_examId = param.examId;
  2049. m_examCourseId = param.examCourseId;
  2050. m_examName = param.examName;
  2051. m_courseName = param.courseName;
  2052. // Log4cplusInitalizer::initalize();
  2053. std::string response;
  2054. CHttpClient httpClient;
  2055. CString url;
  2056. url.Format(_T("%s/exam/getServerUrl?examId=%I64d"), CServerConfig::server_url, param.examId);
  2057. // AfxMessageBox(url);
  2058. #if 0
  2059. httpClient.HttpGet(url, NULL, response);
  2060. AfxMessageBox(L"CBatchService::HttpGet after!");
  2061. Json::Value root;
  2062. AfxMessageBox(L"CBatchService::ReadyScan");
  2063. Json::Reader(Json::Features()).parse(response, root);
  2064. AfxMessageBox(L"CBatchService::Json::Reader");
  2065. if (root["success"].isInt() && root["success"].asInt() == 1){
  2066. CServerConfig::server_address_type = SAT_REMOTE;
  2067. Json::Value object = root["object"];
  2068. //标记本地服务器是否是不可用状态
  2069. bool isLocalServerUnavailable = false;
  2070. if (object["url"].isString() && object["url"].asCString() != (string)""){
  2071. CServerConfig::server_url_local_in = object["url"].asCString();
  2072. if (!testServerAvaiable2(CServerConfig::server_url_local_in)){
  2073. isLocalServerUnavailable = true;
  2074. }
  2075. CServerConfig::server_address_type = SAT_LOCAL_IN;
  2076. }
  2077. if (isLocalServerUnavailable&&object["outurl"].isString() && object["outurl"].asCString() != (string)""){
  2078. CServerConfig::server_url_local_out = object["outurl"].asCString();
  2079. if (testServerAvaiable2(CServerConfig::server_url_local_out)){
  2080. isLocalServerUnavailable = false;
  2081. }
  2082. else {
  2083. isLocalServerUnavailable = true;
  2084. }
  2085. CServerConfig::server_address_type = SAT_LOCAL_OUT;
  2086. }
  2087. //本地服务器不可用,返回错误
  2088. if (isLocalServerUnavailable)return 2;
  2089. }
  2090. #endif
  2091. m_feeder_type = feederType;
  2092. CString moule_dir =CServerConfig::scan_data_dir;
  2093. m_bantch_code = GetTimeString();
  2094. CString tempExamId;
  2095. tempExamId.Format(_T("%llu"), param.examId);
  2096. if (g_my_scan_type == 1)
  2097. {
  2098. m_bantch_dir = moule_dir + _T("\\duxueka") + tempExamId;
  2099. }
  2100. else
  2101. {
  2102. m_bantch_dir = moule_dir + _T("\\datika") + tempExamId;
  2103. }
  2104. m_norimg_dir = m_bantch_dir + _T("\\nor_imgs");
  2105. m_excimg_dir = m_bantch_dir + _T("\\") + m_bantch_code + _T("\\exc_imgs");
  2106. m_img_down_load_dir = m_bantch_dir + _T("\\img_down_load");
  2107. m_muban_img_dir = CT2A(m_bantch_dir + _T("\\muban_imgs"));
  2108. m_img_clips_dir = m_bantch_dir + _T("\\clips");
  2109. m_img_alynasis_dir = m_bantch_dir + _T("\\alynasis");
  2110. m_img_alynasis_result_dir = m_bantch_dir + _T("\\alynasis_result");
  2111. CreateDirectory(m_bantch_dir, NULL);
  2112. CreateDirectory(m_norimg_dir, NULL);
  2113. CreateDirectory(m_bantch_dir + _T("\\") + m_bantch_code, NULL);
  2114. CreateDirectory(m_excimg_dir, NULL);
  2115. CreateDirectory(m_img_clips_dir, NULL);
  2116. CreateDirectory(CA2T(m_muban_img_dir.c_str()), NULL);
  2117. CreateDirectory(m_img_down_load_dir, NULL);
  2118. CreateDirectory(m_img_alynasis_dir, NULL);
  2119. CreateDirectory(m_img_alynasis_result_dir, NULL);
  2120. CString path = m_bantch_dir + _T("\\result.db3");
  2121. CString uploadPath = m_excimg_dir + _T("\\upload.db3");
  2122. char db_file_name[520];
  2123. char db_file_name1[520];
  2124. char db_upload_file_name[520];
  2125. char db_upload_file_name1[520];
  2126. WideCharToMultiByte(CP_UTF8, 0, path, -1, db_file_name, 520, NULL, NULL);
  2127. WideCharToMultiByte(CP_ACP, 0, path, -1, db_file_name1, 520, NULL, NULL);
  2128. WideCharToMultiByte(CP_UTF8, 0, uploadPath, -1, db_upload_file_name, 520, NULL, NULL);
  2129. WideCharToMultiByte(CP_ACP, 0, uploadPath, -1, db_upload_file_name1, 520, NULL, NULL);
  2130. g_strUpLoadDbPathName = db_upload_file_name;
  2131. if (_access(db_file_name1, 0) == -1)
  2132. {
  2133. // 不存在首次拷贝
  2134. CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_RESULT, path);
  2135. }
  2136. if (_access(db_upload_file_name1, 0) == -1)
  2137. {
  2138. CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_UPLOAD, uploadPath);
  2139. }
  2140. EnterCriticalSection(database_db_lock);
  2141. database_db->execDML("begin transaction");
  2142. char * sql = "INSERT INTO DATABASE ( database_state, create_time, db_file_name, bantch_code, bantch_dir, exam_id, exam_name, exam_course_id, course_name, total_upload_count, scan_type, exam_course_id_from, batch_code_from, examinne_id_from, server_address ) VALUES ( :database_state, :create_time, :db_file_name, :bantch_code ,:bantch_dir ,:exam_id ,:exam_name ,:exam_course_id ,:course_name ,:total_upload_count, :scan_type, :exam_course_id_from, :batch_code_from, :examinne_id_from, :server_address )";
  2143. CppSQLite3Statement stmt = database_db->compileStatement(sql);
  2144. CT2A szbantch_code(m_bantch_code);
  2145. CT2A szbantch_dir(m_bantch_dir);
  2146. CT2A server_address(CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
  2147. stmt.bind(":database_state", DATABASE_STATE_CREATE);
  2148. stmt.bind(":create_time", szbantch_code);
  2149. stmt.bind(":db_file_name", db_file_name);
  2150. stmt.bind(":bantch_code", szbantch_code);
  2151. stmt.bind(":bantch_dir", szbantch_dir);
  2152. stmt.bind(":server_address", server_address);
  2153. switch (feederType&FEEDER_TYPE_MASK){
  2154. case Folder:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
  2155. case Scanner:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
  2156. case AdjustBatch:
  2157. stmt.bind(":exam_id", param.examId);
  2158. stmt.bind(":exam_course_id", param.examCourseId);
  2159. stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_BATCH);
  2160. stmt.bind(":exam_course_id_from", param.examCourseIdOld);
  2161. stmt.bind(":batch_code_from", param.batch.c_str());
  2162. break;
  2163. case AdjustExaminne:
  2164. stmt.bind(":exam_id", param.examId);
  2165. stmt.bind(":exam_course_id", param.examCourseId);
  2166. stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_EXAMINNE);
  2167. stmt.bind(":exam_course_id_from", param.examCourseIdOld);
  2168. stmt.bind(":batch_code_from", param.batch.c_str());
  2169. stmt.bind(":examinne_id_from", param.examinneid.c_str());
  2170. break;
  2171. }
  2172. stmt.bind(":exam_name", param.examName.c_str());
  2173. stmt.bind(":course_name", param.courseName.c_str());
  2174. stmt.execDML();
  2175. CppSQLite3Query query = database_db->execQuery("select last_insert_rowId() from DATABASE");
  2176. m_database_id = query.getIntField(0);
  2177. database_db->execDML("commit transaction");
  2178. LeaveCriticalSection(database_db_lock);
  2179. strncpy(m_db_file_name, db_file_name, 520);
  2180. bantch_db.open(db_file_name);
  2181. bantch_db.execDML("pragma journal_mode = MEMORY");
  2182. if (g_my_continue_scan != 1)
  2183. {
  2184. //情况没有上传的
  2185. vector<int> listpaper_id;
  2186. char sql1[512];
  2187. sprintf_s(sql1, "select student_paper_id from student_paper where ret_upload = 0 OR paper_state !=0 OR Is_Covered=1");
  2188. EnterCriticalSection(&bantch_db_lock);
  2189. CppSQLite3Query q = bantch_db.execQuery(sql1);
  2190. std::string _param;
  2191. while (!q.eof()){
  2192. int student_paper_id = q.getIntField("student_paper_id");
  2193. _param += std::to_string(student_paper_id) + ",";
  2194. listpaper_id.push_back(q.getIntField("student_paper_id"));
  2195. q.nextRow();
  2196. }
  2197. if (!_param.empty()){
  2198. _param = std::string(_param, 0, _param.size() - 1);
  2199. if (m_upload_manager.IsEanble())
  2200. m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, _param.c_str());
  2201. std::string str1 = std::string("") + "delete from exception where student_paper_id in(" + _param + ")";
  2202. std::string str2 = std::string("") + "delete from result where page_id in (select pg.page_id from page pg where pg.student_paper_id in(" + _param + "))";
  2203. std::string str3 = std::string("") + "delete from page where student_paper_id in(" + _param + ")";
  2204. std::string str4 = std::string("") + "delete from student_paper where student_paper_id in(" + _param + ")";
  2205. bantch_db.execDML(str1.c_str());
  2206. bantch_db.execDML(str2.c_str());
  2207. bantch_db.execDML(str3.c_str());
  2208. bantch_db.execDML(str4.c_str());
  2209. bantch_db.execDML("delete from message");
  2210. }
  2211. // while (!q.eof()){
  2212. // int student_paper_id = q.getIntField("student_paper_id");
  2213. // listpaper_id.push_back(q.getIntField("student_paper_id"));
  2214. // q.nextRow();
  2215. // }
  2216. // for (int i = 0; i < listpaper_id.size(); i++)
  2217. // {
  2218. // char sql1[512];
  2219. // char sql2[512];
  2220. // char sql3[512];
  2221. // char sql4[512];
  2222. // sprintf_s(sql1, "delete from exception where student_paper_id =%d ", listpaper_id[i]);
  2223. // sprintf_s(sql2, "delete from result where page_id in (select pg.page_id from page pg where pg.student_paper_id =%d)", listpaper_id[i]);
  2224. // sprintf_s(sql3, "delete from page where student_paper_id =%d", listpaper_id[i]);
  2225. // sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", listpaper_id[i]);
  2226. // bantch_db.execDML(sql1);
  2227. // bantch_db.execDML(sql2);
  2228. // bantch_db.execDML(sql3);
  2229. // bantch_db.execDML(sql4);
  2230. // bantch_db.execDML("delete from message");
  2231. // m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, std::to_string(listpaper_id[i]).c_str());
  2232. // }
  2233. LeaveCriticalSection(&bantch_db_lock);
  2234. }
  2235. m_result_uploader->EnableOnLineCard(m_bOnlineCard, m_nSubjectID, m_nOnlineScanType);
  2236. if (m_bOnlineCard){
  2237. mainService.reset(new OnLineCard::COnlineCardIdentifyService(this));
  2238. mainService->m_nOnlineScanType = m_nOnlineScanType;
  2239. }else{
  2240. mainService.reset(new CIdentifyService(this));
  2241. }
  2242. mainService->InitService();
  2243. mainService->SetBianShiBieBianShangChuan(m_upload_manager.IsEanble());
  2244. if (m_bOnlineCard){
  2245. static_cast<OnLineCard::COnlineCardIdentifyService*>(mainService.get())->SetQr(-1,false, std::to_string(m_examId));
  2246. static_cast<OnLineCard::COnlineCardIdentifyService*>(mainService.get())->SetTemplate(m_onlineCardTemplate);
  2247. }
  2248. mainService->SerErrorHandle(m_bErrorHandle);
  2249. mainService->setMainService(true);
  2250. mainService->SetDirs(m_bantch_dir, m_norimg_dir, m_excimg_dir, m_img_clips_dir, m_img_alynasis_dir, m_img_alynasis_result_dir, m_img_down_load_dir, m_muban_img_dir);
  2251. mainService->SetDataBase(&bantch_db_lock, &bantch_db);
  2252. mainService->ReadScan(feederType, param);
  2253. m_scoreCounter.SetDataBase(&bantch_db_lock, &bantch_db);
  2254. if (m_hwnd != NULL) ::PostMessage(m_hwnd, WM_IDENTIFOR_READY, 0, 0);
  2255. return TRUE;
  2256. }
  2257. void DeleteDirectory(CString source);
  2258. int CBatchService::PreErrorHandleRestoreSite(bool bcontinue, int scan_type, FEEDER_TYPE feederType, const ScanParam & param)
  2259. {
  2260. g_my_scan_type = scan_type;
  2261. m_examId = param.examId;
  2262. m_examCourseId = 0;
  2263. m_examName = "";
  2264. m_courseName = "";
  2265. std::string response;
  2266. CString moule_dir = CServerConfig::scan_data_dir;
  2267. m_bantch_code = GetTimeString();
  2268. CString tempExamId;
  2269. tempExamId.Format(_T("%llu"), m_examId);
  2270. if (g_my_scan_type == 1)
  2271. {
  2272. m_bantch_dir = moule_dir + _T("\\duxueka_errorhandle") + m_bantch_code + tempExamId;
  2273. }
  2274. else
  2275. {
  2276. m_bantch_dir = moule_dir + _T("\\datika_errorhandle") + m_bantch_code + tempExamId;
  2277. }
  2278. m_norimg_dir = m_bantch_dir + _T("\\nor_imgs");
  2279. m_excimg_dir = m_bantch_dir + _T("\\") + m_bantch_code + _T("\\exc_imgs");
  2280. m_img_down_load_dir = m_bantch_dir + _T("\\img_down_load");
  2281. m_muban_img_dir = CT2A(m_bantch_dir + _T("\\muban_imgs"));
  2282. m_img_clips_dir = m_bantch_dir + _T("\\clips");
  2283. m_img_alynasis_dir = m_bantch_dir + _T("\\alynasis");
  2284. m_img_alynasis_result_dir = m_bantch_dir + _T("\\alynasis_result");
  2285. //DeleteDirectory(m_bantch_dir);
  2286. CreateDirectory(m_bantch_dir, NULL);
  2287. CreateDirectory(m_norimg_dir, NULL);
  2288. CreateDirectory(m_bantch_dir + _T("\\") + m_bantch_code, NULL);
  2289. CreateDirectory(m_excimg_dir, NULL);
  2290. CreateDirectory(m_img_clips_dir, NULL);
  2291. CreateDirectory(CA2T(m_muban_img_dir.c_str()), NULL);
  2292. CreateDirectory(m_img_down_load_dir, NULL);
  2293. CreateDirectory(m_img_alynasis_dir, NULL);
  2294. CreateDirectory(m_img_alynasis_result_dir, NULL);
  2295. CString path = m_bantch_dir + _T("\\result.db3");
  2296. CString uploadPath = m_excimg_dir + _T("\\upload.db3");
  2297. char db_file_name[520];
  2298. char db_file_name1[520];
  2299. char db_upload_file_name[520];
  2300. char db_upload_file_name1[520];
  2301. WideCharToMultiByte(CP_UTF8, 0, path, -1, db_file_name, 520, NULL, NULL);
  2302. WideCharToMultiByte(CP_ACP, 0, path, -1, db_file_name1, 520, NULL, NULL);
  2303. WideCharToMultiByte(CP_UTF8, 0, uploadPath, -1, db_upload_file_name, 520, NULL, NULL);
  2304. WideCharToMultiByte(CP_ACP, 0, uploadPath, -1, db_upload_file_name1, 520, NULL, NULL);
  2305. g_strUpLoadDbPathName = db_upload_file_name;
  2306. if (_access(db_file_name1, 0) == -1)
  2307. {
  2308. // 不存在首次拷贝
  2309. CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_RESULT, path);
  2310. }
  2311. if (_access(db_upload_file_name1, 0) == -1)
  2312. {
  2313. CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_UPLOAD, uploadPath);
  2314. }
  2315. EnterCriticalSection(database_db_lock);
  2316. database_db->execDML("begin transaction");
  2317. char * sql = "INSERT INTO DATABASE ( database_state, create_time, db_file_name, bantch_code, bantch_dir, exam_id, exam_name, exam_course_id, course_name, total_upload_count, scan_type, exam_course_id_from, batch_code_from, examinne_id_from, server_address ) VALUES ( :database_state, :create_time, :db_file_name, :bantch_code ,:bantch_dir ,:exam_id ,:exam_name ,:exam_course_id ,:course_name ,:total_upload_count, :scan_type, :exam_course_id_from, :batch_code_from, :examinne_id_from, :server_address )";
  2318. CppSQLite3Statement stmt = database_db->compileStatement(sql);
  2319. CT2A szbantch_code(m_bantch_code);
  2320. CT2A szbantch_dir(m_bantch_dir);
  2321. CT2A server_address(CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
  2322. stmt.bind(":database_state", DATABASE_STATE_CREATE);
  2323. stmt.bind(":create_time", szbantch_code);
  2324. stmt.bind(":db_file_name", db_file_name);
  2325. stmt.bind(":bantch_code", szbantch_code);
  2326. stmt.bind(":bantch_dir", szbantch_dir);
  2327. stmt.bind(":server_address", server_address);
  2328. switch (feederType&FEEDER_TYPE_MASK){
  2329. case Folder:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
  2330. case Scanner:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
  2331. case AdjustBatch:
  2332. stmt.bind(":exam_id", param.examId);
  2333. stmt.bind(":exam_course_id", param.examCourseId);
  2334. stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_BATCH);
  2335. stmt.bind(":exam_course_id_from", param.examCourseIdOld);
  2336. stmt.bind(":batch_code_from", param.batch.c_str());
  2337. break;
  2338. case AdjustExaminne:
  2339. stmt.bind(":exam_id", param.examId);
  2340. stmt.bind(":exam_course_id", param.examCourseId);
  2341. stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_EXAMINNE);
  2342. stmt.bind(":exam_course_id_from", param.examCourseIdOld);
  2343. stmt.bind(":batch_code_from", param.batch.c_str());
  2344. stmt.bind(":examinne_id_from", param.examinneid.c_str());
  2345. break;
  2346. }
  2347. stmt.bind(":exam_name", param.examName.c_str());
  2348. stmt.bind(":course_name", param.courseName.c_str());
  2349. stmt.execDML();
  2350. CppSQLite3Query query = database_db->execQuery("select last_insert_rowId() from DATABASE");
  2351. m_database_id = query.getIntField(0);
  2352. database_db->execDML("commit transaction");
  2353. LeaveCriticalSection(database_db_lock);
  2354. strncpy(m_db_file_name, db_file_name, 520);
  2355. bantch_db.open(db_file_name);
  2356. bantch_db.execDML("pragma journal_mode = MEMORY");
  2357. return 0;
  2358. }
  2359. //查询异常试卷
  2360. int CBatchService::QueryExceptionPaper(const long exception_type, vector<STUDENT_INFO>& studentList)
  2361. {
  2362. EnterCriticalSection(&bantch_db_lock);
  2363. char sql[512];
  2364. sprintf_s(sql, "select s.student_id,s.student_code,s.class_name,s.grade_name,s.student_name,s.class_id,pp.score_total,pp.student_paper_id,pp.location_id from student_paper pp left join student s on s.student_id=pp.student_id where not (pp.paper_state&%d) =0", exception_type);
  2365. CppSQLite3Query q = bantch_db.execQuery(sql);
  2366. while (!q.eof()){
  2367. STUDENT_INFO si;
  2368. char class_name[64];
  2369. sprintf_s(class_name, "%s(%s)班", q.getStringField("grade_name"), q.getStringField("class_name"));
  2370. si.class_name = class_name;
  2371. si.student_id = q.getInt64Field("student_id");
  2372. si.student_name = q.getStringField("student_name");
  2373. si.student_code = q.getStringField("student_code");
  2374. si.class_id = q.getInt64Field("class_id");
  2375. si.score = (float)q.getFloatField("score_total", -1);
  2376. si.paper_id = q.getIntField("student_paper_id", -1);
  2377. si.location_id = q.getIntField("location_id", -1);
  2378. studentList.push_back(si);
  2379. q.nextRow();
  2380. }
  2381. LeaveCriticalSection(&bantch_db_lock);
  2382. return TRUE;
  2383. }
  2384. //查询试卷详情,包括异常信息,试卷图像信息,试卷题目信息
  2385. int CBatchService::QueryPaperDetail(const int paper_id, PAPER_DETAIL &paper_detail, vector<PAGE_DETAIL> &pageList, vector<GROUP_QUESTION> &questionList)
  2386. {
  2387. EnterCriticalSection(&bantch_db_lock);
  2388. char sql[512];
  2389. sprintf_s(sql, "SELECT sp.student_paper_id,sp.Is_Covered, sp.ret_upload, img_upload, sp.paper_code, sp.student_code, sp.paper_state, sp.student_id, sp.file_name, sp.score_total,sp.location_id,s.schoolStudentCard, s.student_name,s.class_name,e.full_score,e.full_score_objective FROM student_paper sp LEFT JOIN student s ON s.student_id = sp.student_id left join exam e on 1=1 WHERE sp.student_paper_id = %d", paper_id);
  2390. CppSQLite3Query q = bantch_db.execQuery(sql);
  2391. if (!q.eof())
  2392. {
  2393. if (m_onlineCardTemplate->useQrCode && m_onlineCardTemplate->schoolCardStatus == 1)//使用二维码 且使用学校准考证
  2394. {
  2395. strcpy_s(paper_detail.examnumber, q.getStringField("schoolStudentCard"));
  2396. }
  2397. else
  2398. {
  2399. strcpy_s(paper_detail.examnumber, q.getStringField("student_code"));
  2400. }
  2401. paper_detail.exceptionsFlag = q.getInt64Field("paper_state");
  2402. strcpy_s(paper_detail.student_name, q.getStringField("student_name"));
  2403. paper_detail.score = q.getFloatField("score_total");
  2404. strcpy_s(paper_detail.student_id, q.getStringField("student_id"));
  2405. strcpy_s(paper_detail.class_name, q.getStringField("class_name"));
  2406. paper_detail.fullScore = q.getFloatField("full_score");
  2407. paper_detail.fullScoreObjective = q.getFloatField("full_score_objective");
  2408. paper_detail.location_id = q.getInt64Field("location_id");
  2409. paper_detail.has_covered = (BatchServiceCmd(BATCH_SRV_CMD::BS_CMD_IS_HAS_COVERD, (void*)&paper_id, NULL)>0);
  2410. }
  2411. else{
  2412. strcpy_s(paper_detail.examnumber, "");
  2413. paper_detail.exceptionsFlag = 0;
  2414. strcpy_s(paper_detail.student_name, "");
  2415. paper_detail.score = 0;
  2416. strcpy_s(paper_detail.student_id, "");
  2417. paper_detail.fullScore = 0;
  2418. paper_detail.fullScoreObjective = 0;
  2419. paper_detail.location_id = 0;
  2420. LeaveCriticalSection(&bantch_db_lock);
  2421. return FALSE;
  2422. }
  2423. std::map<int, PAGE_DETAIL> mm;
  2424. //页码信息
  2425. sprintf_s(sql, "select pg.* from student_paper pp left join page pg on pg.student_paper_id =pp.student_paper_id where pp.student_paper_id =%d", paper_id);
  2426. q = bantch_db.execQuery(sql);
  2427. while (!q.eof()){
  2428. PAGE_DETAIL pd;
  2429. pd.page_id = q.getIntField("page_id");
  2430. pd.page_index = q.getIntField("page_index");
  2431. pd.img_path = q.getStringField("img_path");
  2432. pd.img_oldpath=q.getStringField("img_oldpath");
  2433. pd.phy_number = atoi(q.getStringField("phy_number"));
  2434. pd.exceptions.clear();
  2435. mm[pd.page_id] = pd;
  2436. q.nextRow();
  2437. }
  2438. std::map<std::string, QUESTION_INFO> mm2;
  2439. std::vector<QUESTION_INFO*> quesitons;
  2440. // 题目标准
  2441. sprintf_s(sql, "SELECT question_code, question_type, multi_answer, answer_all, answer_std, score_full, score_half, option_count FROM question_std ORDER BY question_code + 0");
  2442. q = bantch_db.execQuery(sql);
  2443. while (!q.eof()){
  2444. QUESTION_INFO qi;
  2445. qi.answer_std = q.getStringField("answer_std");
  2446. qi.answer_stu = "";
  2447. qi.is_mutil = q.getIntField("multi_answer");
  2448. qi.option_count = q.getIntField("option_count");
  2449. qi.question_code = q.getStringField("question_code");
  2450. //qi.question_id =-1;
  2451. qi.question_type = (QUESTION_TYPE)q.getIntField("question_type");
  2452. qi.score_full = q.getFloatField("score_full");
  2453. qi.score_half = q.getFloatField("score_half");
  2454. qi.score_stu = 0;
  2455. mm2[qi.question_code] = qi;
  2456. quesitons.push_back(&mm2[qi.question_code]);
  2457. q.nextRow();
  2458. }
  2459. sprintf_s(sql, "SELECT count(0) FROM student_paper pp where pp.student_paper_id =%d and not (pp.paper_state&%d)=0", paper_id, MEX_BUKECHAXUNFENSHU);
  2460. if (bantch_db.execScalar(sql) <= 0){//不存在定位点异常时,查询分数
  2461. // 题目得分信息
  2462. sprintf_s(sql, "SELECT r.* FROM student_paper pp LEFT JOIN page pg ON pg.student_paper_id = pp.student_paper_id LEFT JOIN result r ON r.page_id = pg.page_id WHERE pp.student_paper_id = %d AND r.type>0", paper_id, paper_id);
  2463. q = bantch_db.execQuery(sql);
  2464. while (!q.eof()){
  2465. string question_code = q.getStringField("question_code");
  2466. mm2[question_code].question_state = (QUESTION_STATE)q.getIntField("question_state");
  2467. mm2[question_code].score_stu = (mm2[question_code].question_state == QUESTION_STATE_NORMAL) ? q.getFloatField("score") : q.getFloatField("score_paper");
  2468. mm2[question_code].answer_stu = q.getStringField("answer");
  2469. q.nextRow();
  2470. }
  2471. }
  2472. //页面异常信息
  2473. sprintf_s(sql, "SELECT ex.exception_id, ex.exception_type, ex.exception_name, ex.page_id,pg.page_id FROM exception ex LEFT JOIN page pg ON pg.page_id = ex.page_id where ex.page_id is not null and ex.student_paper_id =%d", paper_id);
  2474. q = bantch_db.execQuery(sql);
  2475. while (!q.eof()){
  2476. int page_id = q.getIntField("page_id");
  2477. EXCEPTION_INFO ei;
  2478. ei.exception_id = q.getIntField("exception_id");
  2479. ei.type = (EXCEPTION_TYPE)q.getInt64Field("exception_type");
  2480. ei.x = 0;
  2481. ei.y = 0;
  2482. ei.w = 0;
  2483. ei.h = 0;
  2484. mm[page_id].exceptions.push_back(ei);
  2485. q.nextRow();
  2486. }
  2487. //试卷异常信息
  2488. paper_detail.paper_id = paper_id;
  2489. paper_detail.exceptions.clear();
  2490. sprintf_s(sql, "SELECT ex.exception_id, ex.exception_type, ex.exception_name, ex.page_id FROM exception ex where ex.page_id is null and ex.student_paper_id =%d", paper_id);
  2491. q = bantch_db.execQuery(sql);
  2492. while (!q.eof()){
  2493. EXCEPTION_INFO ei;
  2494. ei.exception_id = q.getIntField("exception_id");
  2495. ei.type = (EXCEPTION_TYPE)q.getInt64Field("exception_type");
  2496. ei.x = 0;
  2497. ei.y = 0;
  2498. ei.w = 0;
  2499. ei.h = 0;
  2500. paper_detail.exceptions.push_back(ei);
  2501. q.nextRow();
  2502. }
  2503. for (map<int, PAGE_DETAIL>::iterator it = mm.begin(); it != mm.end(); it++)
  2504. {
  2505. pageList.push_back(it->second);
  2506. }
  2507. LeaveCriticalSection(&bantch_db_lock);
  2508. memset(paper_detail.sz_upload_error_msg, 0, sizeof(paper_detail.sz_upload_error_msg));
  2509. if (m_upload_manager.IsEanble()){
  2510. paper_detail.paper_upload_state = m_upload_manager.GetPaperUploadState(paper_detail.paper_id,paper_detail.sz_upload_error_msg,512);
  2511. bool isexception = 0 != (paper_detail.exceptionsFlag&(~EX_KAOHAODAIPIPEI));
  2512. if (isexception && paper_detail.paper_upload_state==0){
  2513. paper_detail.paper_upload_state = 4;
  2514. }
  2515. }
  2516. return TRUE;
  2517. }
  2518. //重新识别
  2519. int CBatchService::ReIdentify(const int paper_id, const std::string& student_code, const std::vector<img_param>& params)
  2520. {
  2521. CppSQLite3Statement statm = bantch_db.compileStatement("update student_paper set paper_state =:paper_state where student_paper_id=:student_paper_id");
  2522. statm.bind(":paper_state", EX_SHIJUANCHONGXINSHIBIEZHONG);
  2523. statm.bind(":student_paper_id", paper_id);
  2524. statm.execDML();
  2525. m_result_uploader->EnableOnLineCard(m_bOnlineCard, m_nSubjectID, m_nOnlineScanType);
  2526. boost::shared_ptr<CIdentifyService> subService_;
  2527. if (m_bOnlineCard){
  2528. subService_ = boost::make_shared<OnLineCard::COnlineCardIdentifyService>(this);
  2529. }
  2530. else{
  2531. subService_ = boost::make_shared<CIdentifyService>(this);
  2532. }
  2533. subService_->m_nOnlineScanType = m_nOnlineScanType;
  2534. subService_->InitService();
  2535. subService_->SerErrorHandle(m_bErrorHandle);
  2536. subService_->SetBianShiBieBianShangChuan(m_upload_manager.IsEanble());
  2537. std::string qr;
  2538. if (m_bOnlineCard){
  2539. static_cast<OnLineCard::COnlineCardIdentifyService*>(subService_.get())->SetTemplate(m_onlineCardTemplate);
  2540. qr = std::to_string(m_examId) + "," + std::to_string(paper_id) + (student_code.empty() ? "" : ("," + student_code));
  2541. }
  2542. else{
  2543. qr = student_code;
  2544. }
  2545. subService_->SetQr(paper_id,true, qr);
  2546. CString newdbFile = CServerConfig::app_data_dir + _T("\\result_1111.db3");
  2547. CopyFile(m_bantch_dir + _T("\\result.db3"), newdbFile, FALSE);
  2548. CopyFile(m_bantch_dir + _T("\\result.db3"), _T("D:\\result_1111.db3"),FALSE);
  2549. subService_->SetDirs(m_bantch_dir, m_norimg_dir, m_excimg_dir, m_img_clips_dir, m_img_alynasis_dir, m_img_alynasis_result_dir, m_img_down_load_dir, m_muban_img_dir);
  2550. subService_->SetHandlerWnd(m_hwnd);
  2551. subService_->SetDataBase(&bantch_db_lock, &bantch_db);
  2552. subService_->ReIdentify(paper_id, params);
  2553. subService.push_back(subService_);
  2554. subService_->Start();
  2555. //if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_STARTED, 0, 0);
  2556. return 1;
  2557. }
  2558. //更新试卷对应考试
  2559. int CBatchService::UpdatePaperStudent(const int paper_id, const std::string examinee_id, const std::string student_code, const std::string studentName, const long schoolId, const std::string stuCode, const std::string stuSchoolCode, const std::string className, const std::string gradeName, bool bReIdentify/* = false*/)
  2560. {
  2561. EnterCriticalSection(&bantch_db_lock);
  2562. // 添加学生
  2563. char * sql3 = "INSERT INTO student ( student_id, student_code, class_name, school_id, grade_name, student_name, class_id, score_total,studentCard,schoolStudentCard ) SELECT t.student_id, t.student_code, t.class_name, t.school_id, t.grade_name, t.student_name, t.class_id, t.score_total,t.studentCard,t.schoolStudentCard FROM ( SELECT :student_id student_id, :student_code student_code, :class_name class_name, :school_id school_id, :grade_name grade_name, :student_name student_name, :class_id class_id, :score_total score_total , :studentCard studentCard,:schoolStudentCard schoolStudentCard ) t LEFT JOIN student s ON s.student_id = t.student_id WHERE s.student_id IS NULL";
  2564. CppSQLite3Statement statement = bantch_db.compileStatement(sql3);
  2565. statement.bind(":student_id", examinee_id.c_str());
  2566. statement.bind(":student_code", student_code.c_str());
  2567. statement.bind(":school_id", schoolId);
  2568. statement.bind(":student_name", studentName.c_str());
  2569. statement.bind(":studentCard", stuCode.c_str());
  2570. statement.bind(":schoolStudentCard", stuSchoolCode.c_str());
  2571. statement.bind(":class_name", className.c_str());
  2572. statement.bind(":grade_name", gradeName.c_str());
  2573. statement.execDML();
  2574. char sql[512];
  2575. char sqlTemp[512];
  2576. long exceptions = MEX_KAOHAOYICHANG;
  2577. sprintf_s(sql, "select sp.student_paper_id,sp.paper_state,sp.student_id from student_paper sp where sp.student_paper_id = %d", paper_id);
  2578. CppSQLite3Query query_student_paper = bantch_db.execQuery(sql);
  2579. if (query_student_paper.eof()){ LeaveCriticalSection(&bantch_db_lock); return FALSE; }
  2580. const std::string student_id_old = query_student_paper.getStringField("student_id");
  2581. long paper_state = query_student_paper.getInt64Field("paper_state");
  2582. bantch_db.execDML("begin transaction");
  2583. if (paper_state&EX_KAOHAOCHONGTU){
  2584. sprintf_s(sql, "select sp.student_paper_id,sp.paper_state,sp.student_id from student_paper sp where sp.student_id = '%s' and not sp.student_paper_id = %d", student_id_old, paper_id);
  2585. CppSQLite3Query q2 = bantch_db.execQuery(sql);
  2586. vector<int> resolved_ids;
  2587. int same_code_count = 0;
  2588. while (!q2.eof()){
  2589. long paper_state_t = q2.getInt64Field("paper_state");
  2590. if (paper_state_t&EX_KAOHAOCHONGTU)
  2591. resolved_ids.push_back(q2.getIntField("student_paper_id"));
  2592. same_code_count++;
  2593. q2.nextRow();
  2594. }
  2595. if (same_code_count == 1 && resolved_ids.size() == 1){//解决了考号冲突
  2596. sprintf_s(sql, "update student_paper set paper_state =paper_state-(paper_state&%d),ret_upload = 0 where student_paper_id=%d", EX_KAOHAOCHONGTU, resolved_ids[0]);
  2597. bantch_db.execDML(sql);
  2598. sprintf_s(sql, "delete from exception where student_paper_id = %d and exception_type in(%d)", resolved_ids[0], SHIFT_KAOHAOCHONGTU);
  2599. bantch_db.execDML(sql);
  2600. }
  2601. }
  2602. sprintf_s(sql, "update student_paper set student_id ='%s',ret_upload = 0,student_code=(select student_code from student where student_id='%s'),paper_state =paper_state-(paper_state&%d) where student_paper_id=%d", examinee_id.c_str(), examinee_id.c_str(), exceptions, paper_id);
  2603. bantch_db.execDML(sql);
  2604. //更新这次修改消息
  2605. sprintf_s(sql, "update message set identified =1 , examnumber=\"%s\",exceptions=16 where student_paper_id=%d", student_code.c_str(), paper_id);
  2606. bantch_db.execDML(sql);
  2607. //删除
  2608. sprintf_s(sql, "delete from message where student_paper_id =%d and message_type = %d", paper_id, WM_IDENTIFOR_PAPER_STATE_CHAGED);
  2609. bantch_db.execDML(sql);
  2610. //添加
  2611. CppSQLite3Statement stmt4 = bantch_db.compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  2612. stmt4.bind(":student_paper_id", paper_id);
  2613. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  2614. stmt4.execDML();
  2615. sprintf_s(sql, "delete from exception where student_paper_id = %d and exception_type in(%d,%d,%d)", paper_id, SHIFT_KAOHAOBUCUNZAI, SHIFT_KAOHAOCHONGTU, SHIFT_KAOHAOWEISHIBIE);
  2616. bantch_db.execDML(sql);
  2617. sprintf_s(sql, "update result set answer ='%s' where student_paper_id=%d and type =3", student_code.c_str(), paper_id);
  2618. logForDbg(sql);
  2619. bantch_db.execDML(sql);
  2620. sprintf_s(sql, "update result set answer ='%s' where student_paper_id=%d and type =0", student_code.c_str(), paper_id);
  2621. logForDbg(sql);
  2622. bantch_db.execDML(sql);
  2623. //updatefile(&bantch_db, paper_id, (string)CT2A(m_norimg_dir), (string)CT2A(m_excimg_dir));
  2624. vector<int> conflict_ids;
  2625. {//更新考号后导致其他试卷考号冲突情况
  2626. sprintf_s(sql, "select sp.student_paper_id,sp.paper_state,sp.student_id from student_paper sp where sp.student_id = '%s' ", examinee_id.c_str());
  2627. CppSQLite3Query q2 = bantch_db.execQuery(sql);
  2628. while (!q2.eof()){
  2629. long paper_state_t = q2.getInt64Field("paper_state");
  2630. if (!(paper_state_t&EX_KAOHAOCHONGTU))
  2631. conflict_ids.push_back(q2.getIntField("student_paper_id"));
  2632. q2.nextRow();
  2633. }
  2634. if (conflict_ids.size()>1){
  2635. for (int m = 0; m < conflict_ids.size(); m++)
  2636. {
  2637. sprintf_s(sql, "update student_paper set paper_state =paper_state|%d ,ret_upload = 0,Is_Covered=0 where student_paper_id=%d", EX_KAOHAOCHONGTU, conflict_ids[m]);
  2638. bantch_db.execDML(sql);
  2639. 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)");
  2640. stmt3.bind(":student_paper_id", conflict_ids[m]);
  2641. stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
  2642. stmt3.bind(":exception_name", "考号冲突");
  2643. stmt3.execDML();
  2644. {
  2645. //删除
  2646. sprintf_s(sql, "delete from message where student_paper_id =%d and message_type = %d", conflict_ids[m], WM_IDENTIFOR_PAPER_STATE_CHAGED);
  2647. bantch_db.execDML(sql);
  2648. //添加
  2649. CppSQLite3Statement stmt4 = bantch_db.compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  2650. stmt4.bind(":student_paper_id", conflict_ids[m]);
  2651. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  2652. stmt4.execDML();
  2653. }
  2654. }
  2655. }
  2656. }
  2657. for (int m = 0; m < conflict_ids.size(); m++)
  2658. {
  2659. if (paper_id != conflict_ids[m]){
  2660. bantch_db.execDML(sql);
  2661. if (m_upload_manager.IsEanble()){
  2662. m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, std::to_string(conflict_ids[m]).c_str());
  2663. }
  2664. }
  2665. }
  2666. bantch_db.execDML("commit transaction");
  2667. LeaveCriticalSection(&bantch_db_lock);
  2668. for (int m = 0; m < conflict_ids.size(); m++)
  2669. {
  2670. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)conflict_ids[m]);
  2671. }
  2672. return TRUE;
  2673. }
  2674. int CBatchService::ClearDbTemp()
  2675. {
  2676. //情况没有上传的
  2677. vector<int> listpaper_id;
  2678. char sql1[512];
  2679. sprintf_s(sql1, "select student_paper_id from student_paper where ret_upload = 0");
  2680. EnterCriticalSection(&bantch_db_lock);
  2681. CppSQLite3Query q = bantch_db.execQuery(sql1);
  2682. while (!q.eof()){
  2683. listpaper_id.push_back(q.getIntField("student_paper_id"));
  2684. q.nextRow();
  2685. }
  2686. for (int i = 0; i < listpaper_id.size(); i++)
  2687. {
  2688. char sql1[512];
  2689. char sql2[512];
  2690. char sql3[512];
  2691. char sql4[512];
  2692. sprintf_s(sql1, "delete from exception where student_paper_id =%d ", listpaper_id[i]);
  2693. sprintf_s(sql2, "delete from result where page_id in (select pg.page_id from page pg where pg.student_paper_id =%d)", listpaper_id[i]);
  2694. sprintf_s(sql3, "delete from page where student_paper_id =%d", listpaper_id[i]);
  2695. sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", listpaper_id[i]);
  2696. bantch_db.execDML(sql1);
  2697. bantch_db.execDML(sql2);
  2698. bantch_db.execDML(sql3);
  2699. bantch_db.execDML(sql4);
  2700. }
  2701. LeaveCriticalSection(&bantch_db_lock);
  2702. return TRUE;
  2703. }
  2704. //忽略试卷
  2705. int CBatchService::IgnorePaper(const int paper_id)
  2706. {
  2707. char sql1[512];
  2708. char sql2[512];
  2709. char sql3[512];
  2710. char sql4[512];
  2711. char sql5[512];
  2712. sprintf_s(sql1, "delete from exception where student_paper_id =%d ", paper_id);
  2713. sprintf_s(sql2, "delete from result where page_id in (select pg.page_id from page pg where pg.student_paper_id =%d)", paper_id);
  2714. sprintf_s(sql3, "delete from page where student_paper_id =%d", paper_id);
  2715. sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", paper_id);
  2716. sprintf_s(sql5, "delete from message where student_paper_id =%d", paper_id);
  2717. EnterCriticalSection(&bantch_db_lock);
  2718. bantch_db.execDML(sql1);
  2719. bantch_db.execDML(sql2);
  2720. bantch_db.execDML(sql3);
  2721. bantch_db.execDML(sql4);
  2722. bantch_db.execDML(sql5);
  2723. LeaveCriticalSection(&bantch_db_lock);
  2724. return TRUE;
  2725. }
  2726. //忽略某类型的异常
  2727. int CBatchService::IgnoreException(const long exceptions)
  2728. {
  2729. char number_string[10];
  2730. //忽略必须处理的异常将删除试卷
  2731. EnterCriticalSection(&bantch_db_lock);
  2732. if (exceptions&MEX_BIXUCHULIYICHANG){
  2733. char sql0[512];
  2734. sprintf_s(sql0, "update student_paper set paper_state=(paper_state|%d) where paper_state&%d=0 and paper_state&%d>0", EX_SHIJUANSHANCHU, EX_SHIJUANSHANCHU, MEX_BIXUCHULIYICHANG);
  2735. bantch_db.execDML(sql0);
  2736. }
  2737. //忽略非必须处理异常,只删除异常
  2738. const long non_must_handle_exceptions[3] = { EX_LOUTU, EX_LOUPI, EX_WUPAN };
  2739. const long non_must_handle_exception_shifts[3] = { SHIFT_LOUTU, SHIFT_LOUPI, SHIFT_WUPAN };
  2740. if (exceptions&MEX_FEIBIXUCHULIYICHANG){
  2741. char sql0[512];
  2742. sprintf_s(sql0, "update student_paper set paper_state=paper_state-(paper_state&%d) where paper_state&%d=0 and paper_state&%d>0", MEX_FEIBIXUCHULIYICHANG, EX_SHIJUANSHANCHU, MEX_FEIBIXUCHULIYICHANG);
  2743. bantch_db.execDML(sql0);
  2744. }
  2745. LeaveCriticalSection(&bantch_db_lock);
  2746. return TRUE;
  2747. }
  2748. vector<int> CBatchService::GetAllConfictPaper(int student_paper_id, string student_id)//获取冲突试卷
  2749. {
  2750. char sql5[1024] = { 0 };
  2751. sprintf_s(sql5, "select sp.student_paper_id,sp.paper_state,sp.student_id from student_paper sp where sp.student_id = '%s' and not sp.student_paper_id = %d", student_id.c_str(), student_paper_id);
  2752. CppSQLite3Query q2 = bantch_db.execQuery(sql5);
  2753. vector<int> all_conflict_ids;
  2754. vector<int> conflict_ids;
  2755. while (!q2.eof()){
  2756. long paper_state_t = q2.getInt64Field("paper_state");
  2757. all_conflict_ids.push_back(q2.getIntField("student_paper_id"));
  2758. if (!(paper_state_t&EX_KAOHAOCHONGTU))
  2759. conflict_ids.push_back(q2.getIntField("student_paper_id"));
  2760. q2.nextRow();
  2761. }
  2762. return all_conflict_ids;
  2763. }
  2764. int CBatchService::BatchServiceCmd(int cmd, void*param, void*ret)
  2765. {
  2766. switch (cmd){
  2767. // 获取被覆盖的试卷
  2768. case BATCH_SRV_CMD::BS_CMD_GET_BE_COVERD_PAPERS:
  2769. {
  2770. if (param && ret){
  2771. std::vector<int>& vctRetStuInfo = *static_cast<std::vector<int>*>(ret);
  2772. vctRetStuInfo.clear();
  2773. int student_paper_id = *(int*)param;
  2774. std::string sql_fmt = "select student_paper_id from student_paper where student_id in(select student_id from student_paper where student_paper_id=%d) and student_paper_id!=%d and Is_Covered=1";
  2775. char sz_sql[512] = { 0 };
  2776. sprintf_s(sz_sql, sql_fmt.c_str(), student_paper_id, student_paper_id);;
  2777. EnterCriticalSection(&bantch_db_lock);
  2778. if (bantch_db.is_open()){
  2779. CppSQLite3Query q = bantch_db.execQuery(sz_sql);
  2780. while (!q.eof()){
  2781. vctRetStuInfo.push_back(q.getIntField("student_paper_id"));
  2782. q.nextRow();
  2783. }
  2784. }
  2785. LeaveCriticalSection(&bantch_db_lock);
  2786. }
  2787. }
  2788. break;
  2789. // 判断是否有被覆盖的
  2790. case BATCH_SRV_CMD::BS_CMD_IS_HAS_COVERD:
  2791. {
  2792. int nRet = 0;
  2793. if (param){
  2794. int student_paper_id = *(int*)param;
  2795. EnterCriticalSection(&bantch_db_lock);
  2796. if (bantch_db.is_open()){
  2797. std::string sql_fmt = "select count(*) from student_paper where student_id in(select student_id from student_paper where student_paper_id=%d) and student_paper_id!=%d and Is_Covered=1";
  2798. char sz_sql[512] = { 0 };
  2799. sprintf_s(sz_sql, sql_fmt.c_str(), student_paper_id, student_paper_id);
  2800. nRet = bantch_db.execScalar(sz_sql);
  2801. }
  2802. LeaveCriticalSection(&bantch_db_lock);
  2803. }
  2804. return nRet;
  2805. }
  2806. break;
  2807. // 判断是否有考号冲突
  2808. case BATCH_SRV_CMD::BS_CMD_IS_HAS_KAOHAOCHONGTU:
  2809. {
  2810. int nRet = 0;
  2811. EnterCriticalSection(&bantch_db_lock);
  2812. if (bantch_db.is_open()){
  2813. std::string sql = "select count(*) from exception where exception_type=";
  2814. sql += std::to_string(SHIFT_KAOHAOCHONGTU);
  2815. nRet = bantch_db.execScalar(sql.c_str());
  2816. }
  2817. LeaveCriticalSection(&bantch_db_lock);
  2818. return nRet;
  2819. }
  2820. break;
  2821. // 覆盖所有考号冲突
  2822. case BATCH_SRV_CMD::BS_CMD_COVERD_ALL_KAOHAOCHONGTU:
  2823. CoverdAllKaohaochongtu();
  2824. break;
  2825. }
  2826. return 0;
  2827. }
  2828. // 覆盖所有考号冲突
  2829. void CBatchService::CoverdAllKaohaochongtu()
  2830. {
  2831. //
  2832. m_coverd_all_kaohaochongtu = std::async(std::launch::async, [&]()->int{
  2833. LOGI("全部覆盖操作开始");
  2834. std::map<std::string, std::vector<std::pair<std::string,int>>> _map_student_id;
  2835. std::string str_qry_sql = "select student_id,student_paper_id,task_id from student_paper where paper_state=128 order by student_id ,student_paper_id desc";
  2836. EnterCriticalSection(&bantch_db_lock);
  2837. auto _qry = bantch_db.execQuery(str_qry_sql.c_str());
  2838. if (_qry.eof()){
  2839. LeaveCriticalSection(&bantch_db_lock);
  2840. // 覆盖操作结束
  2841. if (m_hwnd != NULL)
  2842. ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD_ALL_KAOHAOCHONGTU, (WPARAM)0, (LPARAM)0);
  2843. return -1;
  2844. }
  2845. while (!_qry.eof()){
  2846. std::string student_id = _qry.getStringField("student_id");
  2847. std::string task_id = _qry.getStringField("task_id");
  2848. _map_student_id[student_id].push_back(std::make_pair(task_id, _qry.getIntField("student_paper_id")));
  2849. _qry.nextRow();
  2850. }
  2851. std::string str_coverd = "";
  2852. std::string str_update = "";
  2853. for (auto it : _map_student_id){
  2854. for (std::size_t i = 0; i < it.second.size(); ++i){
  2855. std::string task_id = it.second[i].first;
  2856. int student_paper_id = it.second[i].second;
  2857. if (i == 0){
  2858. if (m_bErrorHandle){
  2859. // 云处理模式- 被覆盖的更新云端状态
  2860. if (UpateErrorStudentData(task_id)){
  2861. str_update += std::to_string(student_paper_id);
  2862. }
  2863. }
  2864. else{
  2865. str_update += std::to_string(student_paper_id);
  2866. }
  2867. }
  2868. else{
  2869. str_coverd += std::to_string(student_paper_id);
  2870. str_coverd += ",";
  2871. }
  2872. }
  2873. str_update += ",";
  2874. }
  2875. bantch_db.execDML("begin transaction");
  2876. try{
  2877. if (!str_coverd.empty()){
  2878. str_coverd = std::string(str_coverd, 0, str_coverd.size() - 1);
  2879. std::string str_sql_coverd = "update student_paper set paper_state=0, Is_Covered=1 where student_paper_id in(";
  2880. str_sql_coverd += str_coverd + ")";
  2881. bantch_db.execDML(str_sql_coverd.c_str());
  2882. LOGFMTI("被覆盖sql语句:%s", str_sql_coverd.c_str());
  2883. std::string sql_del = "delete from message where student_paper_id in(";
  2884. sql_del += str_coverd + ")";
  2885. bantch_db.execDML(sql_del.c_str());
  2886. LOGFMTI("被覆盖sql语句 message表:%s", sql_del.c_str());
  2887. }
  2888. if (!str_update.empty()){
  2889. str_update = std::string(str_update, 0, str_update.size() - 1);
  2890. std::string str_sql_update = "update student_paper set paper_state=0, Is_Covered=0 where student_paper_id in(";
  2891. str_sql_update += str_update + ")";
  2892. bantch_db.execDML(str_sql_update.c_str());
  2893. LOGFMTI("覆盖sql语句:%s", str_sql_update.c_str());
  2894. }
  2895. }
  2896. catch (...){
  2897. LOGI("全部覆盖操作SQL执行异常");
  2898. bantch_db.execDML("rollback transaction");
  2899. }
  2900. bantch_db.execDML("commit transaction");
  2901. LOGI("全部覆盖操作SQL执行成功-更新界面");
  2902. LeaveCriticalSection(&bantch_db_lock);
  2903. // 删除被覆盖的数据
  2904. // 将最后一条移动到成功列表
  2905. int _update_len = str_update.size() + 1, _coverd_len = str_coverd.size() + 1;
  2906. char *_update = new char[_update_len]; memset(_update, 0, _update_len);
  2907. char *_coverd = new char[_coverd_len]; memset(_coverd, 0, _coverd_len);
  2908. strcpy_s(_update, _update_len, str_update.c_str());
  2909. strcpy_s(_coverd, _coverd_len, str_coverd.c_str());
  2910. ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD_ALL_KAOHAOCHONGTU, (WPARAM)_update, (LPARAM)_coverd);
  2911. LOGI("全部覆盖操作结束");
  2912. // 覆盖操作结束
  2913. if (m_hwnd != NULL)
  2914. ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD_ALL_KAOHAOCHONGTU, (WPARAM)0, (LPARAM)0);
  2915. return 0;
  2916. });
  2917. }
  2918. // 覆盖试卷
  2919. int CBatchService::ReplacePaper(const int paper_id, int &paper_id_ret)
  2920. {
  2921. BOOL bRet = FALSE;
  2922. paper_id_ret = paper_id;
  2923. char sql1[512] = { 0 };
  2924. char sql5[512] = { 0 };
  2925. sprintf_s(sql1, "delete from exception where student_paper_id =%d ", paper_id);
  2926. sprintf_s(sql5, "update student_paper set paper_state=0 where student_paper_id = %d AND paper_state = 128", paper_id);
  2927. EnterCriticalSection(&bantch_db_lock);
  2928. if (bantch_db.execDML(sql5) > 0){
  2929. bantch_db.execDML(sql1);
  2930. char sql0[512];
  2931. sprintf_s(sql0, "select student_paper_id,task_id from student_paper where student_id in (select student_id from student_paper where student_paper_id = %d ) and paper_state = 0 and student_paper_id != %d and Is_Covered != 1 ", paper_id, paper_id);
  2932. CppSQLite3Query q = bantch_db.execQuery(sql0);
  2933. if (!q.eof()){
  2934. int couvered_paper_id = q.getIntField("student_paper_id");
  2935. bool bSendToClientUpdate = true;
  2936. if (m_bErrorHandle){ // 云处理模式- 被覆盖的更新云端状态
  2937. auto task_id = std::to_string(q.getIntField("task_id"));
  2938. if (!UpateErrorStudentData(task_id)){
  2939. //printf("更新状态失败,所以不更新覆盖标记\n");
  2940. bSendToClientUpdate = false;
  2941. }
  2942. }
  2943. if(bSendToClientUpdate){
  2944. std::string sql_del = "delete from message where student_paper_id=";
  2945. sql_del += std::to_string(couvered_paper_id);
  2946. bantch_db.execDML(sql_del.c_str());
  2947. sprintf_s(sql5, "update student_paper set Is_Covered=1 where student_paper_id = %d", couvered_paper_id);
  2948. int nRet = bantch_db.execDML(sql5);
  2949. LOGFMTI("被覆盖paper_id=%d 成功paper_id=%d 数据库更新状况:%d", couvered_paper_id, paper_id, nRet);
  2950. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD, (WPARAM)paper_id, (LPARAM)couvered_paper_id);
  2951. }
  2952. }
  2953. else{
  2954. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD, (WPARAM)paper_id, (LPARAM)paper_id);
  2955. }
  2956. bRet = TRUE;
  2957. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)paper_id);
  2958. }
  2959. LeaveCriticalSection(&bantch_db_lock);
  2960. return bRet;
  2961. }
  2962. // 全部覆盖试卷
  2963. int CBatchService::ReplaceAllKaoHaoChongTu(vector<int> &paper_id_List)
  2964. {
  2965. char mysql0[512];
  2966. sprintf_s(mysql0, "select student_paper_id from student_paper where paper_state = 128");
  2967. EnterCriticalSection(&bantch_db_lock);
  2968. char sql0[512];
  2969. char sql1[512];
  2970. char sql2[512];
  2971. char sql3[512];
  2972. char sql4[512];
  2973. char sql5[512];
  2974. int delete_paper;
  2975. CppSQLite3Query q = bantch_db.execQuery(mysql0);
  2976. while (!q.eof())
  2977. {
  2978. int paper_id = q.getIntField("student_paper_id");
  2979. sprintf_s(sql1, "select * from student_paper where student_id in (select student_id from student_paper where student_paper_id = %d) and paper_state = 0 ", paper_id);
  2980. sprintf_s(sql5, "update student_paper set paper_state=0 where student_paper_id = %d", paper_id);
  2981. paper_id_List.push_back(paper_id);
  2982. CppSQLite3Query q1 = bantch_db.execQuery(sql0);
  2983. if (!q.eof())
  2984. {
  2985. delete_paper = q1.getIntField("student_paper_id");
  2986. sprintf_s(sql1, "delete from exception where student_paper_id =%d ", delete_paper);
  2987. sprintf_s(sql2, "delete from result where page_id in (select pg.page_id from page pg where pg.student_paper_id =%d)", delete_paper);
  2988. sprintf_s(sql3, "delete from page where student_paper_id =%d", delete_paper);
  2989. sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", delete_paper);
  2990. bantch_db.execDML(sql1);
  2991. bantch_db.execDML(sql2);
  2992. bantch_db.execDML(sql3);
  2993. bantch_db.execDML(sql4);
  2994. bantch_db.execDML(sql5);
  2995. // 修改消息
  2996. sprintf_s(sql0, "delete from message where student_paper_id =%d", paper_id);
  2997. sprintf_s(sql1, "UPDATE message SET student_paper_id = %d WHERE student_paper_id = %d ", paper_id, delete_paper);
  2998. bantch_db.execDML(sql0);
  2999. bantch_db.execDML(sql1);
  3000. }
  3001. q.nextRow();
  3002. }
  3003. LeaveCriticalSection(&bantch_db_lock);
  3004. return TRUE;
  3005. }
  3006. //开始上传成绩
  3007. int CBatchService::StartUploadPaper(HWND hWnd, int student_paper_id/* = -1*/, bool bErrorPaper /*= false*/)
  3008. {
  3009. m_result_uploader->SetResultHandler(mainService->GetResultHander());
  3010. m_result_uploader->SetDataBase(&bantch_db_lock, &bantch_db);
  3011. m_result_uploader->SetDataBaseManager(database_db_lock, database_db,m_database_id);
  3012. if (hWnd != NULL)m_result_uploader->SetHandlerWnd(hWnd);
  3013. m_result_uploader->readNewUploadUrl();
  3014. m_result_uploader->SetUploadOnScan(m_upload_manager.IsEanble(), student_paper_id, bErrorPaper);
  3015. return m_result_uploader->Start();
  3016. }
  3017. //是否支持暂停
  3018. BOOL CBatchService::SupportPause(void)
  3019. {
  3020. return mainService->SupportPause();
  3021. }
  3022. //暂停处理
  3023. ServiceState CBatchService::OnPausing(void)
  3024. {
  3025. mainService->Pause();
  3026. while (mainService->GetServiceSate() == pausing || mainService->GetServiceSate() == running){
  3027. Sleep(10);
  3028. }
  3029. ServiceState nextState = IService::OnPausing();
  3030. if (nextState == paused&&m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAUSED, 0, 0);
  3031. return nextState;
  3032. }
  3033. //恢复扫描
  3034. ServiceState CBatchService::OnResuming(void)
  3035. {
  3036. mainService->Resume();
  3037. while (mainService->GetServiceSate() == resuming){
  3038. Sleep(10);
  3039. }
  3040. ServiceState nextState = IService::OnResuming();
  3041. if (nextState == running&&m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_RESUMED, 0, 0);
  3042. return nextState;
  3043. }
  3044. //放弃本次考试
  3045. int CBatchService::GiveUpCurrentBatch()
  3046. {
  3047. char sql[128];
  3048. sprintf_s(sql, "update database set database_state =%d where database_id =%d", DATABASE_STATE_GIVEUP, m_database_id);
  3049. EnterCriticalSection(database_db_lock);
  3050. database_db->execDML("begin transaction");
  3051. database_db->execDML(sql);
  3052. database_db->execDML("commit transaction");
  3053. LeaveCriticalSection(database_db_lock);
  3054. return TRUE;
  3055. }
  3056. //设置继续扫描文件夹路径
  3057. int CBatchService::SetFolderScanDir(const std::string& img_dir)
  3058. {
  3059. mainService->continueScan(img_dir);
  3060. mainService->Start();
  3061. return TRUE;
  3062. }
  3063. //停止服务
  3064. BOOL CBatchService::Stop(void)
  3065. {
  3066. if (IService::Stop()){
  3067. m_abnormal_stop = TRUE;
  3068. return TRUE;
  3069. }
  3070. m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_UPLOAD_STOP, NULL);
  3071. return FALSE;
  3072. }
  3073. int CBatchService::QueryExptionPaperCount(int & total_count)
  3074. {
  3075. EnterCriticalSection(&bantch_db_lock);
  3076. total_count = bantch_db.execScalar("select count(0) from student_paper pp where not pp.paper_state = 0");
  3077. LeaveCriticalSection(&bantch_db_lock);
  3078. return TRUE;
  3079. }
  3080. //查询异常类型信息
  3081. int CBatchService::QueryExptionTypeInfo(vector<EXCEPTION_TYPE_INFO> & infos)
  3082. {
  3083. EnterCriticalSection(&bantch_db_lock);
  3084. CppSQLite3Query query = bantch_db.execQuery("SELECT pe.exception_type, count(DISTINCT pe.student_paper_id) exception_paper_count FROM exception pe GROUP BY pe.exception_type");
  3085. while (!query.eof()){
  3086. EXCEPTION_TYPE_INFO ex_type_info;
  3087. ex_type_info.exception_type = (1 << query.getInt64Field("exception_type"));
  3088. ex_type_info.exception_count = query.getIntField("exception_paper_count");
  3089. switch (ex_type_info.exception_type){
  3090. case EX_DINGWEIDIAN:strcpy(ex_type_info.exception_name, "定位点异常"); break;
  3091. case EX_FEIFASHIJUAN:strcpy(ex_type_info.exception_name, "非法试卷"); break;
  3092. case EX_KAOHAOWEISHIBIE:strcpy(ex_type_info.exception_name, "考号未识别"); break;
  3093. case EX_KAOHAOBUCUNZAI:strcpy(ex_type_info.exception_name, "考号不存在"); break;
  3094. case EX_KAOHAOCHONGTU:strcpy(ex_type_info.exception_name, "考号冲突"); break;
  3095. case EX_LOUTU:strcpy(ex_type_info.exception_name, "考生漏涂"); break;
  3096. case EX_LOUPI:strcpy(ex_type_info.exception_name, "教师漏批"); break;
  3097. case EX_WUPAN:strcpy(ex_type_info.exception_name, "教师误判"); break;
  3098. case EX_WUFASHIBIE_ZHUGUANTI:strcpy(ex_type_info.exception_name, "无法识别解答题"); break;
  3099. case EX_SHIJUANQUEYE:strcpy(ex_type_info.exception_name, "试卷缺页"); break;
  3100. default: strcpy(ex_type_info.exception_name, "未知异常类型"); break;
  3101. }
  3102. infos.push_back(ex_type_info);
  3103. query.nextRow();
  3104. }
  3105. LeaveCriticalSection(&bantch_db_lock);
  3106. return TRUE;
  3107. }
  3108. int CBatchService::SetCookie(CString path, CString name, CString value)
  3109. {
  3110. return InternetSetCookie(path, name, value);
  3111. }
  3112. int CBatchService::SetLocalServerCookie(CString name, CString value)
  3113. {
  3114. switch (CServerConfig::server_address_type){
  3115. case SAT_LOCAL_IN:InternetSetCookie(CServerConfig::server_url_local_in, name, value); break;
  3116. case SAT_LOCAL_OUT:InternetSetCookie(CServerConfig::server_url_local_out, name, value); break;
  3117. }
  3118. return TRUE;
  3119. }
  3120. void CBatchService::Online_saveQuestionStd(long long examId, std::string examName, long examCourseId, std::string courseName, std::string rule /*= ""*/)
  3121. {
  3122. if (m_nSubjectID == 0)
  3123. {
  3124. rapidjson::Document doc;
  3125. doc.Parse(rule.c_str());
  3126. if (doc.HasParseError()) return;
  3127. auto itObject = doc.FindMember("object");
  3128. if (itObject == doc.MemberEnd() || !itObject->value.IsArray() || itObject->value.Size() <= 0) return;
  3129. auto itQuestion = itObject->value.Begin()->FindMember("questions");
  3130. if (itQuestion == itObject->value.Begin()->MemberEnd() || !itQuestion->value.IsArray()) return;
  3131. CppSQLite3DB* bantch_db = &this->bantch_db;
  3132. const char* sql_clear = "delete from question_std";
  3133. bantch_db->execDML(sql_clear);
  3134. const char* sql_clear1 = "delete from exam";
  3135. bantch_db->execDML(sql_clear1);
  3136. const char* sql_exam = "INSERT INTO exam ( exam_id, exam_name, exam_course_id, course_name, full_score ,full_score_objective) VALUES ( :exam_id, :exam_name, :exam_course_id, :course_name, :full_score ,:full_score_objective)";
  3137. CppSQLite3Statement statement_exam = bantch_db->compileStatement(sql_exam);
  3138. const char* sql = "INSERT INTO question_std ( question_code, question_type, multi_answer, answer_all, answer_std, score_full, score_half, option_count,rule_type ) VALUES ( :question_code, :question_type, :multi_answer, :answer_all, :answer_std, :score_full, :score_half, :option_count,:rule_type )";
  3139. CppSQLite3Statement statement = bantch_db->compileStatement(sql);
  3140. bantch_db->execDML("begin transaction");
  3141. float full_score = 0;
  3142. float full_score_keguanti = 0;
  3143. auto fGetQuestionType = [](int nType)->QuestionType{
  3144. switch (nType){
  3145. case 1: return schema::DANXUANTI; break; // 单选题
  3146. case 11:
  3147. case 2: return schema::DUOXUANTI; break; // 多选题
  3148. case 5: return schema::TIANKONGTI; break; // 填空题
  3149. case 7: return schema::ZHUGUANTI; break; // 主观题
  3150. case 17: return schema::XUANZUO_ZHUGUANTI; break; // 选做题
  3151. case 27: return schema::BIZUOTI; break;
  3152. }
  3153. return schema::DANXUANTI;
  3154. };
  3155. for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
  3156. QuestionType question_type;
  3157. int full_score = 0;
  3158. auto itType = it->FindMember("questionTypeId");
  3159. if (itType != it->MemberEnd() && itType->value.IsInt()){
  3160. question_type = fGetQuestionType(itType->value.GetInt());
  3161. }
  3162. else{
  3163. continue;
  3164. }
  3165. auto itScore = it->FindMember("fullScore");
  3166. if (itScore != it->MemberEnd() && itScore->value.IsInt()){
  3167. full_score = itScore->value.GetInt();
  3168. }
  3169. if (question_type == schema::DANXUANTI || question_type == schema::DUOXUANTI || question_type == schema::PANDUANTI)full_score_keguanti += full_score;
  3170. double half_score = 0.0;
  3171. auto itHalfScore = it->FindMember("rule_score_half");
  3172. if (itHalfScore != it->MemberEnd() ){
  3173. if (itHalfScore->value.IsInt() || itHalfScore->value.IsDouble())
  3174. half_score = itHalfScore->value.GetDouble();
  3175. else if (itHalfScore->value.IsString()){
  3176. std::string s = itHalfScore->value.GetString();
  3177. if(!s.empty())
  3178. half_score = std::stod(s);
  3179. }
  3180. }
  3181. else
  3182. {
  3183. itHalfScore = it->FindMember("halfScore");
  3184. if (itHalfScore != it->MemberEnd() && (itHalfScore->value.IsInt() || itHalfScore->value.IsDouble())){
  3185. half_score = itHalfScore->value.GetDouble();
  3186. }
  3187. }
  3188. std::string question_code;
  3189. auto itQuestionCode = it->FindMember("questionNum");
  3190. if (itQuestionCode != it->MemberEnd() && itQuestionCode->value.IsString()){
  3191. question_code = itQuestionCode->value.GetString();
  3192. }
  3193. std::string answer_all;
  3194. auto itAnswer = it->FindMember("answer");
  3195. if (itAnswer != it->MemberEnd() && itAnswer->value.IsString()){
  3196. answer_all = itAnswer->value.GetString();
  3197. }
  3198. int rule_type = 0;
  3199. auto itRuleType = it->FindMember("rule_type");
  3200. if (itRuleType != it->MemberEnd() && itRuleType->value.IsInt()){
  3201. rule_type = itRuleType->value.GetInt();
  3202. }
  3203. auto rule_answer = it->FindMember("rule_answer");
  3204. if (rule_answer != it->MemberEnd() && rule_answer->value.IsString()){
  3205. string str = rule_answer->value.GetString();
  3206. if (str.length()>0)
  3207. {
  3208. answer_all = str;
  3209. }
  3210. }
  3211. statement.bind(":question_code", question_code.c_str());
  3212. statement.bind(":question_type", question_type);
  3213. statement.bind(":multi_answer", question_type == schema::QuestionType::DUOXUANTI);
  3214. statement.bind(":answer_all", answer_all.c_str());
  3215. statement.bind(":answer_std", answer_all.c_str());
  3216. statement.bind(":score_full", full_score);
  3217. statement.bind(":score_half", half_score);
  3218. statement.bind(":option_count", 3);
  3219. statement.bind(":rule_type", rule_type);
  3220. // 单选题、客观题 answer_all 从模板里面取
  3221. if (m_onlineCardTemplate && (question_type == schema::QuestionType::DANXUANTI || question_type == schema::QuestionType::DUOXUANTI))
  3222. {
  3223. for (auto& page : m_onlineCardTemplate->pages)
  3224. {
  3225. for (auto& question : page.second.vctQuestions)
  3226. {
  3227. if (question_code == question.id.c_str())
  3228. {
  3229. string std_answer_all("");
  3230. for (auto& option : question.opt)
  3231. {
  3232. if (std_answer_all.length() > 0)
  3233. {
  3234. std_answer_all.append(",");
  3235. }
  3236. std_answer_all.append(option.optName);
  3237. }
  3238. statement.bind(":answer_all", std_answer_all.c_str());
  3239. break;
  3240. }
  3241. }
  3242. }
  3243. }
  3244. statement.execDML();
  3245. }
  3246. statement_exam.bind(":exam_id", examId);
  3247. statement_exam.bind(":exam_name", examName.c_str());
  3248. statement_exam.bind(":exam_course_id", examCourseId);
  3249. statement_exam.bind(":course_name", courseName.c_str());
  3250. statement_exam.bind(":full_score", full_score);
  3251. statement_exam.bind(":full_score_objective", full_score_keguanti);
  3252. statement_exam.execDML();
  3253. bantch_db->execDML("commit transaction");
  3254. }
  3255. else
  3256. {
  3257. rapidjson::Document doc;
  3258. doc.Parse(rule.c_str());
  3259. if (doc.HasParseError()) return;
  3260. auto itQuestion = doc.FindMember("questions");
  3261. if (itQuestion == doc.MemberEnd() || !itQuestion->value.IsArray() || itQuestion->value.Size() <= 0) return;
  3262. //auto itQuestion = itObject->value.Begin()->FindMember("questions");
  3263. //if (itQuestion == itQuestion->value.Begin()->MemberEnd() || !itQuestion->value.IsArray()) return;
  3264. CppSQLite3DB* bantch_db = &this->bantch_db;
  3265. const char* sql_clear = "delete from question_std";
  3266. bantch_db->execDML(sql_clear);
  3267. const char* sql_clear1 = "delete from exam";
  3268. bantch_db->execDML(sql_clear1);
  3269. const char* sql_exam = "INSERT INTO exam ( exam_id, exam_name, exam_course_id, course_name, full_score ,full_score_objective) VALUES ( :exam_id, :exam_name, :exam_course_id, :course_name, :full_score ,:full_score_objective)";
  3270. CppSQLite3Statement statement_exam = bantch_db->compileStatement(sql_exam);
  3271. const char* sql = "INSERT INTO question_std ( question_code, question_type, multi_answer, answer_all, answer_std, score_full, score_half, option_count,rule_type ) VALUES ( :question_code, :question_type, :multi_answer, :answer_all, :answer_std, :score_full, :score_half, :option_count,:rule_type )";
  3272. CppSQLite3Statement statement = bantch_db->compileStatement(sql);
  3273. bantch_db->execDML("begin transaction");
  3274. float full_score = 0;
  3275. float full_score_keguanti = 0;
  3276. auto fGetQuestionType = [](int nType)->QuestionType{
  3277. switch (nType){
  3278. case 1: return schema::DANXUANTI; break; // 单选题
  3279. case 11:
  3280. case 2: return schema::DUOXUANTI; break; // 多选题
  3281. case 5: return schema::TIANKONGTI; break; // 填空题
  3282. case 7: return schema::ZHUGUANTI; break; // 主观题
  3283. case 17: return schema::XUANZUO_ZHUGUANTI; break; // 选做题
  3284. case 27: return schema::BIZUOTI; break;
  3285. }
  3286. return schema::DANXUANTI;
  3287. };
  3288. for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
  3289. QuestionType question_type;
  3290. int full_score = 0;
  3291. auto itType = it->FindMember("questionTypeId");
  3292. if (itType != it->MemberEnd() && itType->value.IsInt()){
  3293. question_type = fGetQuestionType(itType->value.GetInt());
  3294. statement.bind(":question_type", question_type);
  3295. }
  3296. else{
  3297. continue;
  3298. }
  3299. auto itScore = it->FindMember("fullScore");
  3300. if (itScore != it->MemberEnd() && itScore->value.IsString()){
  3301. full_score = std::atoi(itScore->value.GetString());
  3302. statement.bind(":score_full", itScore->value.GetString());
  3303. }
  3304. if (question_type == schema::DANXUANTI || question_type == schema::DUOXUANTI || question_type == schema::PANDUANTI)full_score_keguanti += full_score;
  3305. double half_score = 0.0;
  3306. auto itHalfScore = it->FindMember("rule_score_half");
  3307. if (itHalfScore != it->MemberEnd() && (itHalfScore->value.IsString())){
  3308. //half_score = itHalfScore->value.GetDouble();
  3309. statement.bind(":score_half", itHalfScore->value.GetString());
  3310. }
  3311. else
  3312. {
  3313. auto itHalfScore1 = it->FindMember("halfScore");
  3314. if (itHalfScore1 != it->MemberEnd() && (itHalfScore1->value.IsString())){
  3315. //half_score = itHalfScore->value.GetDouble();
  3316. statement.bind(":score_half", itHalfScore1->value.GetString());
  3317. }
  3318. }
  3319. std::string question_code;
  3320. int question_id(0);
  3321. auto itQuestionCode = it->FindMember("questionNum");
  3322. if (itQuestionCode != it->MemberEnd() && itQuestionCode->value.IsInt()){
  3323. //question_code = itQuestionCode->value.GetString();
  3324. question_id = itQuestionCode->value.GetInt();
  3325. statement.bind(":question_code", itQuestionCode->value.GetInt());
  3326. }
  3327. std::string answer_all;
  3328. auto itAnswer = it->FindMember("answer");
  3329. if (itAnswer != it->MemberEnd() && itAnswer->value.IsString()){
  3330. answer_all = itAnswer->value.GetString();
  3331. }
  3332. int rule_type = 0;
  3333. auto itRuleType = it->FindMember("rule_type");
  3334. if (itRuleType != it->MemberEnd() && itRuleType->value.IsInt()){
  3335. //rule_type = itRuleType->value.GetInt();
  3336. statement.bind(":rule_type", itRuleType->value.GetInt());
  3337. }
  3338. else
  3339. statement.bind(":rule_type", 2);
  3340. auto rule_answer = it->FindMember("rule_answer");
  3341. if (rule_answer != it->MemberEnd() && rule_answer->value.IsString()){
  3342. string str = rule_answer->value.GetString();
  3343. if (str.length() > 0)
  3344. {
  3345. answer_all = str;
  3346. }
  3347. }
  3348. //statement.bind(":question_code", question_code.c_str());
  3349. //statement.bind(":question_type", question_type);
  3350. statement.bind(":multi_answer", question_type == schema::QuestionType::DUOXUANTI);
  3351. //statement.bind(":answer_all", answer_all.c_str());
  3352. statement.bind(":answer_std", answer_all.c_str());
  3353. //statement.bind(":score_full", full_score);
  3354. //statement.bind(":score_half", half_score);
  3355. statement.bind(":option_count", 3);
  3356. //statement.bind(":rule_type", rule_type);
  3357. // 单选题、客观题 answer_all 从模板里面取
  3358. if (m_onlineCardTemplate && (question_type == schema::QuestionType::DANXUANTI || question_type == schema::QuestionType::DUOXUANTI))
  3359. {
  3360. for (auto& page : m_onlineCardTemplate->pages)
  3361. {
  3362. for (auto& question : page.second.vctQuestions)
  3363. {
  3364. if (question_id == atoi(question.id.c_str()))
  3365. {
  3366. string std_answer_all("");
  3367. for (auto& option : question.opt)
  3368. {
  3369. if (std_answer_all.length() > 0)
  3370. {
  3371. std_answer_all.append(",");
  3372. }
  3373. std_answer_all.append(option.optName);
  3374. }
  3375. statement.bind(":answer_all", std_answer_all.c_str());
  3376. break;
  3377. }
  3378. }
  3379. }
  3380. }
  3381. statement.execDML();
  3382. }
  3383. statement_exam.bind(":exam_id", examId);
  3384. statement_exam.bind(":exam_name", examName.c_str());
  3385. statement_exam.bind(":exam_course_id", examCourseId);
  3386. statement_exam.bind(":course_name", courseName.c_str());
  3387. statement_exam.bind(":full_score", full_score);
  3388. statement_exam.bind(":full_score_objective", full_score_keguanti);
  3389. statement_exam.execDML();
  3390. bantch_db->execDML("commit transaction");
  3391. }
  3392. }
  3393. void CBatchService::saveQuestionStd(long long examId, std::string examName, long examCourseId, std::string courseName, std::vector<schema::SCHEMA_QUESTION> &questions, std::string rule)
  3394. {
  3395. CppSQLite3DB* bantch_db = &this->bantch_db;
  3396. const char* sql_clear = "delete from question_std";
  3397. bantch_db->execDML(sql_clear);
  3398. const char* sql_clear1 = "delete from exam";
  3399. bantch_db->execDML(sql_clear1);
  3400. const char* sql_exam = "INSERT INTO exam ( exam_id, exam_name, exam_course_id, course_name, full_score ,full_score_objective) VALUES ( :exam_id, :exam_name, :exam_course_id, :course_name, :full_score ,:full_score_objective)";
  3401. CppSQLite3Statement statement_exam = bantch_db->compileStatement(sql_exam);
  3402. const char* sql = "INSERT INTO question_std ( question_code, question_type, multi_answer, answer_all, answer_std, score_full, score_half, option_count,rule_type ) VALUES ( :question_code, :question_type, :multi_answer, :answer_all, :answer_std, :score_full, :score_half, :option_count,:rule_type )";
  3403. CppSQLite3Statement statement = bantch_db->compileStatement(sql);
  3404. bantch_db->execDML("begin transaction");
  3405. float full_score = 0;
  3406. float full_score_keguanti = 0;
  3407. Json::Value ruleValue;
  3408. if (!rule.empty())
  3409. {
  3410. Json::Features features;
  3411. Json::Reader re(features);
  3412. Json::Value root;
  3413. re.parse(rule, root);
  3414. ruleValue = root["rules"];
  3415. }
  3416. for (int i = 0; i < questions.size(); i++)
  3417. {
  3418. schema::SCHEMA_QUESTION& row = questions[i];
  3419. full_score += row.score;
  3420. int question_type = row.questionType&schema::QTF_QUESTION_TYPE_MASK;
  3421. if (question_type == schema::DANXUANTI || question_type == schema::DUOXUANTI || question_type == schema::PANDUANTI)full_score_keguanti += row.score;
  3422. statement.bind(":question_code", row.question_code_new);
  3423. statement.bind(":question_type", row.questionType);
  3424. statement.bind(":multi_answer", question_type == schema::QuestionType::DUOXUANTI);
  3425. statement.bind(":answer_all", row.answers.c_str());
  3426. statement.bind(":answer_std", row.answerA.c_str());
  3427. statement.bind(":score_full", row.score);
  3428. statement.bind(":score_half", row.halfScore);
  3429. statement.bind(":option_count", 3);
  3430. statement.bind(":rule_type", 2);
  3431. m_mapKeguantiNickName[row.question_code_new] = row.question_code;
  3432. if (!ruleValue.isNull())
  3433. {
  3434. if (ruleValue.size() > 0)
  3435. {
  3436. Json::Value rule = ruleValue[row.question_code_new];
  3437. if (!rule.isNull())
  3438. {
  3439. int rule_type = rule["rule_type"].asInt();
  3440. //row["questionNum"].asString().c_str()
  3441. statement.bind(":rule_type", rule_type);
  3442. std::string answer = rule["rule_answer"].asString().c_str();
  3443. if (!answer.empty())
  3444. statement.bind(":answer_std", rule["rule_answer"].asString().c_str());
  3445. else
  3446. {
  3447. row.answerA = answer;
  3448. statement.bind(":answer_std", row.answerA.c_str());
  3449. }
  3450. std::string rule_score = rule["rule_score"].asString().c_str();
  3451. if (!rule_score.empty())
  3452. statement.bind(":score_full", atof(rule_score.c_str()));
  3453. else
  3454. {
  3455. row.score = atof(rule_score.c_str());
  3456. statement.bind(":score_full", row.score);
  3457. }
  3458. std::string rule_score_half = rule["rule_score_half"].asString().c_str();
  3459. if (!rule_score_half.empty())
  3460. statement.bind(":score_half", atof(rule_score_half.c_str()));
  3461. else
  3462. {
  3463. row.halfScore = atof(rule_score_half.c_str());
  3464. statement.bind(":score_half", row.halfScore);
  3465. }
  3466. }
  3467. }
  3468. // Json::Value rule = ruleValue[std::stoi(row.question_code_new)];
  3469. // if (!rule.isNull())
  3470. // {
  3471. // int rule_type = rule["rule_type"].asInt();
  3472. // //row["questionNum"].asString().c_str()
  3473. // statement.bind(":rule_type", rule_type);
  3474. // std::string answer = rule["rule_answer"].asString().c_str();
  3475. // if (!answer.empty())
  3476. // statement.bind(":answer_std", rule["rule_answer"].asString().c_str());
  3477. // else
  3478. // statement.bind(":answer_std", row.answerA.c_str());
  3479. // std::string rule_score = rule["rule_score"].asString().c_str();
  3480. // if (!rule_score.empty())
  3481. // statement.bind(":score_full", atof(rule_score.c_str()));
  3482. // else
  3483. // statement.bind(":score_full", row.score);
  3484. // std::string rule_score_half = rule["rule_score_half"].asString().c_str();
  3485. // if (!rule_score_half.empty())
  3486. // statement.bind(":score_half", atof(rule_score_half.c_str()));
  3487. // else
  3488. // statement.bind(":score_half", row.halfScore);
  3489. //
  3490. // }
  3491. }
  3492. statement.execDML();
  3493. }
  3494. statement_exam.bind(":exam_id", examId);
  3495. statement_exam.bind(":exam_name", examName.c_str());
  3496. statement_exam.bind(":exam_course_id", examCourseId);
  3497. statement_exam.bind(":course_name", courseName.c_str());
  3498. statement_exam.bind(":full_score", full_score);
  3499. statement_exam.bind(":full_score_objective", full_score_keguanti);
  3500. statement_exam.execDML();
  3501. bantch_db->execDML("commit transaction");
  3502. // getStdAnswerAndScore();
  3503. }
  3504. int CBatchService::QueryNormalPaper(vector<STUDENT_INFO> & studentList)
  3505. {
  3506. EnterCriticalSection(&bantch_db_lock);
  3507. // 找考号考号冲突的并且已经上传的成功数据,和未上传的成功数据
  3508. string sql = "select s.student_id,s.student_code,s.class_name,s.grade_name,s.student_name,s.class_id,pp.score_total,pp.student_paper_id,pp.ret_upload,pp.paper_state,pp.location_id from student_paper pp left join student s on s.student_id=pp.student_id where pp.student_id in (select student_id from student_paper where paper_state = 128) and paper_state = 0 or (pp.paper_state = 0)";
  3509. CppSQLite3Query q = bantch_db.execQuery(sql.c_str());
  3510. while (!q.eof()){
  3511. STUDENT_INFO si;
  3512. char class_name[64];
  3513. sprintf_s(class_name, "%s(%s)班", q.getStringField("grade_name"), q.getStringField("class_name"));
  3514. si.class_name = class_name;
  3515. si.student_id = q.getInt64Field("student_id");
  3516. si.student_name = q.getStringField("student_name");
  3517. si.student_code = q.getStringField("student_code");
  3518. si.class_id = q.getInt64Field("class_id");
  3519. si.score = (float)q.getFloatField("score_total", -1);
  3520. si.paper_id = q.getIntField("student_paper_id", -1);
  3521. si.location_id = q.getIntField("location_id", -1);
  3522. studentList.push_back(si);
  3523. q.nextRow();
  3524. }
  3525. LeaveCriticalSection(&bantch_db_lock);
  3526. return TRUE;
  3527. }
  3528. int CBatchService::QueryMubanImgPath(int page_index, std::string& imgPath)
  3529. {
  3530. CString imgFilePath;
  3531. imgFilePath.Format(_T("%s\\%05d.jpg"), CString(m_muban_img_dir.c_str()), page_index);
  3532. char fff[1024];
  3533. WideCharToMultiByte(CP_ACP, 0, imgFilePath, -1, fff, 1024, NULL, NULL);
  3534. imgPath = fff;
  3535. return TRUE;
  3536. }
  3537. int CBatchService::QueryMubanImgCount(int& page_count)
  3538. {
  3539. /*return page_count = m_identifor.GetMubanCount();*/
  3540. page_count = m_schema.get() ? m_schema->size() : 0;
  3541. return 1;
  3542. }
  3543. const boost::shared_ptr<const HANDLE_INFO>& CBatchService::GetHandleInfo()
  3544. {
  3545. return m_handleInfo;
  3546. }
  3547. void CBatchService::getStdAnswerAndScore()
  3548. {
  3549. CppSQLite3DB* bantch_db = &this->bantch_db;
  3550. CHttpClient httpClient;
  3551. CString url_str_findPaperInfo, postData, strPaperId;
  3552. string response;
  3553. url_str_findPaperInfo.Format(_T("%s/coachio/iointerface/downLoadThirdPaperSheet"), CServerConfig::server_url);
  3554. readPaperId(strPaperId);
  3555. logForDbg("getStdAnswerAndScore" );
  3556. postData.Format(_T("paperIdStr="));
  3557. postData += strPaperId;
  3558. httpClient.SetSendHeader(MarkHttpHeaderData());
  3559. httpClient.HttpPost(url_str_findPaperInfo, postData, response);
  3560. Json::Features features;
  3561. Json::Reader re(features);
  3562. Json::Value root;
  3563. re.parse(response, root);
  3564. if (root["success"].isInt() && root["success"].asInt()){
  3565. Json::Value objects = root["object"];
  3566. Json::Value object = objects["paper_info"];
  3567. // for (int m = 0; m<object.size(); m++)
  3568. {
  3569. // Json::Value ob = object[m];
  3570. Json::Value rows = object["questions"];
  3571. int array_size = 0;
  3572. array_size = rows.size();
  3573. for (int i = 0; i < array_size; i++)
  3574. {
  3575. Json::Value row = rows[i];
  3576. CppSQLite3Statement stmt = bantch_db->compileStatement("update question_std set answer_std=:answer_std,score_full=:score_full where question_code=:question_code");
  3577. stmt.bind(":question_code", row["questionNum"].asString().c_str());
  3578. stmt.bind(":answer_std", row["answer"].asString().c_str());
  3579. stmt.bind(":score_full", row["fullScore"].asDouble());
  3580. logForDbg("question_code:" + row["questionNum"].asString());
  3581. logForDbg("answer_std:" + row["answer"].asString());
  3582. char strTemp[5] = {"\0"};
  3583. string str;
  3584. sprintf(strTemp, "%.1f", row["fullScore"].asDouble());
  3585. str = strTemp;
  3586. logForDbg("score_full:" + str);
  3587. stmt.execDML();
  3588. }
  3589. }
  3590. }
  3591. }
  3592. CString CBatchService::MarkHttpHeaderData()
  3593. {
  3594. TCHAR FilePath[MAX_PATH];
  3595. GetModuleFileName(NULL, FilePath, MAX_PATH);
  3596. CString ret;
  3597. (_tcsrchr(FilePath, '\\'))[1] = 0;
  3598. if (m_bErrorHandle){
  3599. lstrcat(FilePath, _T("paperinfo.ini"));
  3600. WCHAR JSESSIONID[512];
  3601. GetPrivateProfileString(_T("paperinfo"), _T("session"), _T(""), JSESSIONID, 512, FilePath);
  3602. ret = JSESSIONID;
  3603. }
  3604. else{
  3605. lstrcat(FilePath, _T("config.ini"));
  3606. #ifndef BACK_STAGE
  3607. WCHAR SIG[512];
  3608. GetPrivateProfileString(_T("SESSIONID"), _T("SIG"), _T(""), SIG, 512, FilePath);
  3609. WCHAR TIME[512];
  3610. GetPrivateProfileString(_T("SESSIONID"), _T("TIME"), _T(""), TIME, 512, FilePath);
  3611. WCHAR ID[512];
  3612. GetPrivateProfileString(L"SESSIONID", L"ID", L"", ID, 512, FilePath);
  3613. WCHAR JSESSIONID[512];
  3614. GetPrivateProfileString(_T("SESSIONID"), _T("JSESSIONID"), _T(""), JSESSIONID, 512, FilePath);
  3615. ret.Format(_T("userid=%s&time=%s&sig=%s&session=%s"), ID, TIME, SIG, JSESSIONID);
  3616. #else
  3617. WCHAR MYCOOK[512];
  3618. GetPrivateProfileString(_T("SESSIONID"), _T("MYCOOK"), _T(""), MYCOOK, 512, FilePath);
  3619. CString ret;
  3620. ret.Format(_T("%s"), MYCOOK);
  3621. #endif
  3622. }
  3623. return ret;
  3624. }
  3625. bool CBatchService::readPaperId(CString& strPaperId)
  3626. {
  3627. TCHAR exeFullPath[MAX_PATH];
  3628. CString strPath;
  3629. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  3630. strPath = (CString)exeFullPath;
  3631. int position = strPath.ReverseFind('\\');
  3632. strPath = strPath.Left(position + 1);
  3633. TCHAR FilePath[MAX_PATH];
  3634. GetModuleFileName(NULL, FilePath, MAX_PATH);
  3635. (_tcsrchr(FilePath, '\\'))[1] = 0;
  3636. lstrcat(FilePath, _T("paperInfo.ini"));
  3637. WCHAR PaperId[512];
  3638. GetPrivateProfileString(_T("paperinfo"), _T("paper_str"), _T(""), PaperId, 512, FilePath);
  3639. strPaperId = PaperId;
  3640. return false;
  3641. }
  3642. void CBatchService::logForDbg(string strLog)
  3643. {
  3644. char threadName[4*1024];
  3645. char logName[300];
  3646. char sYear[10], sMonth[10], sDay[25];
  3647. SYSTEMTIME st;
  3648. GetLocalTime(&st);
  3649. int j0 = 0;
  3650. int m_nYear = st.wYear; ///年
  3651. int m_nMonth = st.wMonth; ///月
  3652. int m_nDay = st.wDay; ///日
  3653. int m_nHour = st.wHour; ///小时
  3654. int m_nMinute = st.wMinute; ///分钟
  3655. int m_nSecond = st.wSecond; ///秒
  3656. int m_nMillSecond = st.wMilliseconds; ///毫秒
  3657. sprintf_s(sYear, sizeof(sYear), "%d", m_nYear);
  3658. sprintf_s(sMonth, sizeof(sMonth), "_%02d", m_nMonth);
  3659. sprintf_s(sDay, sizeof(sDay), "_%02d_log.txt", m_nDay);
  3660. strcpy(logName, sYear);
  3661. strcat(logName, sMonth);
  3662. strcat(logName, sDay);
  3663. char strScore[MAX_PATH] = {0};
  3664. for (int i = 0; i < strLog.size(); i++)
  3665. strScore[i] = strLog.at(i);
  3666. sprintf_s(threadName, sizeof(threadName), "%s\n", strScore);
  3667. ThreadLog2(threadName, logName);
  3668. }
  3669. void CBatchService::recordBarcodeFlag(int nFlag)
  3670. {
  3671. TCHAR exeFullPath[MAX_PATH];
  3672. CString strPath;
  3673. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  3674. strPath = (CString)exeFullPath;
  3675. int position = strPath.ReverseFind('\\');
  3676. strPath = strPath.Left(position + 1);
  3677. TCHAR FilePath[MAX_PATH];
  3678. GetModuleFileName(NULL, FilePath, MAX_PATH);
  3679. (_tcsrchr(FilePath, '\\'))[1] = 0;
  3680. lstrcat(FilePath, _T("paperInfo.ini"));
  3681. if (nFlag==0)
  3682. WritePrivateProfileString(_T("paperinfo"), _T("barcode_flag"), L"0", FilePath);
  3683. else
  3684. WritePrivateProfileString(_T("paperinfo"), _T("barcode_flag"), L"1", FilePath);
  3685. return;
  3686. }
  3687. void CBatchService::getCurScanExam(std::string exam_code, std::vector<std::vector<coverStu>> &stuInfo)
  3688. {
  3689. CHttpClient httpClient;
  3690. httpClient.SetSendHeader(MarkHttpHeaderData());
  3691. string response;
  3692. CString url_str;
  3693. //url_str.Format(_T("%s/%s"),CServerConfig::server_url,_T("student!findStudentsByClazzId.action"));
  3694. url_str.Format(_T("%s/%s"), CServerConfig::server_url, _T("coachio/iointerface_v2/getNotUploadStudentList"));
  3695. CString postData;
  3696. CString stExamCode(exam_code.data());
  3697. postData.Format(_T("examGroupId=%s&type=%d"), stExamCode, 1);
  3698. httpClient.HttpPost(url_str, postData, response);
  3699. Json::Features features;
  3700. Json::Reader re(features);
  3701. Json::Value root;
  3702. re.parse(response, root);
  3703. if (root["success"].isInt() && root["success"].asInt()){
  3704. Json::Value rows = root["object"];
  3705. if (rows.isArray()){
  3706. int array_size = rows.size();
  3707. std::vector<coverStu> stuVec;
  3708. for (int i = 0; i<array_size; i++)
  3709. {
  3710. Json::Value row = rows[i];
  3711. coverStu stu;
  3712. stu.stu_name = row["realname"].asString().c_str();
  3713. stu.stu_code1 = row["student_card"].asString().c_str();
  3714. stu.stu_code2 = row["school_student_card"].asString().c_str();
  3715. stu.stu_class = row["class_name"].asString().c_str();
  3716. stu.stu_grade = row["grade"].asString().c_str();
  3717. stuVec.push_back(stu);
  3718. }
  3719. stuInfo.push_back(stuVec);
  3720. }
  3721. }
  3722. postData.Format(_T("examGroupId=%s&type=%d"), stExamCode, 2);
  3723. httpClient.HttpPost(url_str, postData, response);
  3724. re.parse(response, root);
  3725. if (root["success"].isInt() && root["success"].asInt()){
  3726. Json::Value rows = root["object"];
  3727. if (rows.isArray()){
  3728. int array_size = rows.size();
  3729. std::vector<coverStu> stuVec;
  3730. for (int i = 0; i<array_size; i++)
  3731. {
  3732. Json::Value row = rows[i];
  3733. coverStu stu;
  3734. stu.stu_name = row["realname"].asString().c_str();
  3735. stu.stu_code1 = row["student_card"].asString().c_str();
  3736. stu.stu_code2 = row["school_student_card"].asString().c_str();
  3737. stu.stu_class = row["class_name"].asString().c_str();
  3738. stu.stu_grade = row["grade"].asString().c_str();
  3739. stuVec.push_back(stu);
  3740. }
  3741. stuInfo.push_back(stuVec);
  3742. }
  3743. }
  3744. }
  3745. void CBatchService::getCoverStuInfoByExamCode(std::string examCode, std::vector<coverStu> &stuInfo)
  3746. {
  3747. EnterCriticalSection(&bantch_db_lock);
  3748. char sql[256];
  3749. sprintf_s(sql, "select * from student where recoverFlag=1 ");
  3750. CppSQLite3Query query = bantch_db.execQuery(sql);
  3751. while (!query.eof()){
  3752. coverStu stu;
  3753. stu.stu_name = query.getStringField("student_name");
  3754. stu.stu_code1 = query.getStringField("studentCard");
  3755. stu.stu_code2 = query.getStringField("schoolStudentCard");
  3756. stu.stu_class = query.getStringField("class_name");
  3757. stu.stu_grade = query.getStringField("grade_name");
  3758. stuInfo.push_back(stu);
  3759. query.nextRow();
  3760. }
  3761. LeaveCriticalSection(&bantch_db_lock);
  3762. }
  3763. static bool readFile(string & file, string & str)
  3764. {
  3765. ifstream in;
  3766. string line;
  3767. in.open(file, ifstream::in);
  3768. if (!in.is_open())
  3769. return false;
  3770. while (getline(in, line))
  3771. {
  3772. str.append(line + "\n");
  3773. }
  3774. in.close();
  3775. return true;
  3776. }
  3777. void CBatchService::RestoreFile(int paper_id, const std::string&path_rst, const std::string&path_ori)
  3778. {
  3779. std::string sql = std::string("update student_paper set file_name='") + path_rst + "', ori_img ='" + path_ori + "'where student_paper_id = " + std::to_string(paper_id);
  3780. EnterCriticalSection(&bantch_db_lock);
  3781. bantch_db.execDML(sql.c_str());
  3782. LeaveCriticalSection(&bantch_db_lock);
  3783. }
  3784. int CBatchService::RestoreStudentPaper(const std::string task_id, const std::string&task_type, rapidjson::Value&doc)
  3785. {
  3786. // 恢复
  3787. std::string str_student_paper_sql = "INSERT INTO student_paper ("
  3788. "ori_img, picFlag, location_id, paper_type, absent, score_total, file_name,"
  3789. "student_id,paper_state,student_code,paper_code,img_upload,ret_upload,student_paper_id,task_id,task_type)VALUES "
  3790. "("
  3791. ":ori_img, :picFlag, :location_id, :paper_type, :absent, :score_total, :file_name,"
  3792. ":student_id,:paper_state,:student_code,:paper_code,:img_upload,:ret_upload,:student_paper_id, :task_id, :task_type"
  3793. ")";
  3794. EnterCriticalSection(&bantch_db_lock);
  3795. CppSQLite3Statement smt_stu_paper = bantch_db.compileStatement(str_student_paper_sql.c_str());
  3796. smt_stu_paper.bind(":ret_upload", 0);
  3797. smt_stu_paper.bind(":img_upload", 0);
  3798. smt_stu_paper.bind(":task_id", task_id.c_str());
  3799. smt_stu_paper.bind(":task_type", task_type.c_str());
  3800. // student_code
  3801. auto it_student_code = doc.FindMember("student_code");
  3802. if (it_student_code != doc.MemberEnd() && it_student_code->value.IsString()){
  3803. smt_stu_paper.bind(":student_code", it_student_code->value.GetString());
  3804. }
  3805. //paper_code
  3806. auto it_paper_code = doc.FindMember("paper_code");
  3807. if (it_paper_code != doc.MemberEnd() && it_paper_code->value.IsString()){
  3808. smt_stu_paper.bind(":paper_code", it_paper_code->value.GetString());
  3809. }
  3810. //paper_state
  3811. auto it_paper_state = doc.FindMember("paper_state");
  3812. if (it_paper_state != doc.MemberEnd() && it_paper_state->value.IsInt()){
  3813. smt_stu_paper.bind(":paper_state", it_paper_state->value.GetInt());
  3814. }
  3815. // student_id
  3816. auto it_student_id = doc.FindMember("student_id");
  3817. if (it_student_id != doc.MemberEnd() && it_student_id->value.IsString()){
  3818. smt_stu_paper.bind(":student_id", it_student_id->value.GetString());
  3819. }
  3820. // picFlag
  3821. auto it_picFlag = doc.FindMember("picFlag");
  3822. if (it_picFlag != doc.MemberEnd() && it_picFlag->value.IsString()){
  3823. smt_stu_paper.bind(":picFlag", it_picFlag->value.GetString());
  3824. }
  3825. // location_id
  3826. auto it_location_id = doc.FindMember("location_id");
  3827. if (it_location_id != doc.MemberEnd() && it_location_id->value.IsInt()){
  3828. smt_stu_paper.bind(":location_id", it_location_id->value.GetInt());
  3829. }
  3830. // paper_type
  3831. auto it_paper_type = doc.FindMember("paper_type");
  3832. if (it_paper_type != doc.MemberEnd() && it_paper_type->value.GetString()){
  3833. smt_stu_paper.bind(":paper_type", it_paper_type->value.GetString());
  3834. }
  3835. // absent
  3836. auto it_absent = doc.FindMember("absent");
  3837. if (it_absent != doc.MemberEnd() && it_absent->value.IsInt()){
  3838. smt_stu_paper.bind(":absent", it_absent->value.GetInt());
  3839. }
  3840. // score_total
  3841. auto it_score_total = doc.FindMember("score_total");
  3842. if (it_score_total != doc.MemberEnd() && (it_score_total->value.IsInt() || it_score_total->value.IsDouble())){
  3843. smt_stu_paper.bind(":score_total", it_score_total->value.GetDouble());
  3844. }
  3845. smt_stu_paper.execDML();
  3846. CppSQLite3Query query = bantch_db.execQuery("select last_insert_rowId() from student_paper");
  3847. int student_paper_id = query.getIntField(0);
  3848. LeaveCriticalSection(&bantch_db_lock);
  3849. return student_paper_id;
  3850. }
  3851. BOOL CBatchService::UpateErrorStudentData(const std::string&task_id)
  3852. {
  3853. BOOL bRet = TRUE;
  3854. if (!task_id.empty()){
  3855. TCHAR exeFullPath[MAX_PATH];
  3856. CString strPath;
  3857. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  3858. strPath = (CString)exeFullPath;
  3859. int position = strPath.ReverseFind('\\');
  3860. strPath = strPath.Left(position + 1);
  3861. TCHAR FilePath[MAX_PATH];
  3862. GetModuleFileName(NULL, FilePath, MAX_PATH);
  3863. (_tcsrchr(FilePath, '\\'))[1] = 0;
  3864. lstrcat(FilePath, _T("paperinfo.ini"));
  3865. WCHAR szUrl[512] = { 0 };
  3866. GetPrivateProfileString(_T("paperinfo"), _T("errorhandleupdateurl"), _T(""), szUrl, 512, FilePath);
  3867. WCHAR szSession[512] = { 0 };
  3868. GetPrivateProfileString(_T("paperinfo"), _T("session"), _T(""), szSession, 512, FilePath);
  3869. std::string url = UnicodeToAnsi(szUrl), exam_id = std::to_string(m_examId), session = UnicodeToAnsi(szSession);
  3870. CString postData;
  3871. postData.Format(_T("examGroupId=%s&taskIds=%s"), AnsiToUnicode(exam_id), AnsiToUnicode(task_id));
  3872. postData.TrimRight(L",");
  3873. std::string response;
  3874. CHttpClient httpClient;
  3875. httpClient.SetSendHeader(AnsiToUnicode(session));
  3876. httpClient.HttpPost(AnsiToUnicode(url), postData, response);
  3877. if (!response.empty()){
  3878. Json::Features features;
  3879. Json::Reader re(features);
  3880. Json::Value root;
  3881. re.parse(response, root);
  3882. if (root.isMember("success") && root["success"].isInt() && root["success"].asUInt() == 1){
  3883. bRet = TRUE;
  3884. //printf("更新状态成功: url=%s session=%s postdata=%s\n", url.c_str(), session.c_str(), UnicodeToAnsi(postData).c_str());
  3885. }
  3886. else{
  3887. //printf("更新状态失败: url=%s session=%s postdata=%s\n",url.c_str(),session.c_str(), UnicodeToAnsi(postData).c_str());
  3888. }
  3889. }
  3890. }
  3891. return bRet;
  3892. }
  3893. void CBatchService::InitUploadManager(bool bEanble, bool bCountiue, bool bErrorHanle, bool bOnlineCard, IUploudNotify*pNotify)
  3894. {
  3895. if (bEanble&&m_result_uploader){
  3896. m_result_uploader->SetUploadOnScan(bEanble, -1, 0);
  3897. }
  3898. m_upload_manager.Init(bEanble, bCountiue, bErrorHanle,bOnlineCard, m_nSubjectID, pNotify, &bantch_db, &bantch_db_lock);
  3899. }
  3900. void CBatchService::OnScanListFilter(bool bsuccess,int nUploadState)
  3901. {
  3902. m_upload_manager.ScanListFilter(bsuccess,nUploadState);
  3903. }
  3904. int CBatchService::UploadOnScanCmd(int nCmd, const char*param, void*ret)
  3905. {
  3906. return m_upload_manager.UploadOnScanCmd(nCmd, param, -1, ret);
  3907. }
  3908. void DeleteDirectory(CString source);
  3909. void CBatchService::QuickHandle(bool bGetPath, char*path_nor, int nor_len, char*path_exc, int exc_len)
  3910. {
  3911. CString str_nor_dir;
  3912. CString str_exc_dir;
  3913. if (bGetPath){
  3914. str_nor_dir = m_excimg_dir + _T("\\nor\\");
  3915. str_exc_dir = m_excimg_dir + _T("\\exc\\");
  3916. DeleteDirectory(str_nor_dir);
  3917. DeleteDirectory(str_exc_dir);
  3918. CreateDirectory(str_nor_dir, NULL);
  3919. CreateDirectory(str_exc_dir, NULL);
  3920. if (str_exc_dir.GetLength()< nor_len){
  3921. strcpy(path_exc, UnicodeToAnsi(str_exc_dir).c_str());
  3922. }
  3923. if (str_nor_dir.GetLength() < nor_len){
  3924. strcpy(path_nor, UnicodeToAnsi(str_nor_dir).c_str());
  3925. }
  3926. }
  3927. else{
  3928. str_nor_dir = AnsiToUnicode(path_nor);
  3929. str_exc_dir = AnsiToUnicode(path_exc);
  3930. static std::string sql = "select pa.img_oldpath,sp.paper_state from page pa LEFT JOIN student_paper sp ON pa.student_paper_id= sp.student_paper_id";
  3931. EnterCriticalSection(&bantch_db_lock);
  3932. if (bantch_db.is_open()){
  3933. CppSQLite3Query qry = bantch_db.execQuery(sql.c_str());
  3934. int i = 1;
  3935. while (!qry.eof()){
  3936. int state = qry.getIntField("paper_state");
  3937. std::string path = qry.getStringField("img_oldpath");
  3938. CString fileName;
  3939. fileName.Format(_T("%09d.jpg"), i++);
  3940. if (state == 0){
  3941. CopyFileA(path.c_str(), UnicodeToAnsi(str_nor_dir + fileName).c_str(), FALSE);
  3942. }
  3943. else{
  3944. CopyFileA(path.c_str(), UnicodeToAnsi(str_exc_dir + fileName).c_str(), FALSE);
  3945. }
  3946. qry.nextRow();
  3947. }
  3948. }
  3949. LeaveCriticalSection(&bantch_db_lock);
  3950. if (m_hwnd && ::IsWindow(m_hwnd))
  3951. ::PostMessage(m_hwnd, WM_QUICK_HANDLE_STOPED, 0, 0);
  3952. }
  3953. }
  3954. void CBatchService::SetErrorHandle(bool bErrorHandle)
  3955. {
  3956. m_bErrorHandle = bErrorHandle;
  3957. m_result_uploader->SetErrorHandle(m_bErrorHandle);
  3958. }
  3959. static int g_page_id = 1;
  3960. std::map<int, int> CBatchService::RestorePages(int paper_id, const std::string&path, rapidjson::Value&value)
  3961. {
  3962. std::map<int, int> ret;
  3963. std::string sql_fmt = "INSERT INTO page(student_paper_id,identified,img_path,img_oldpath,page_id)VALUES(%d,%d,'%s','%s',%d)";
  3964. EnterCriticalSection(&bantch_db_lock);
  3965. for (auto it_page = value.Begin(); it_page != value.End();++it_page)
  3966. {
  3967. std::string _path="";
  3968. int identified = -1;
  3969. int page_id = 0;
  3970. auto it_name = it_page->FindMember("name");
  3971. if (it_name != it_page->MemberEnd()&& it_name->value.IsString()){
  3972. auto name = it_name->value.GetString();
  3973. _path = path + "ori\\image_" +name;
  3974. }
  3975. auto it_identify = it_page->FindMember("identified");
  3976. if (it_identify != it_page->MemberEnd() && it_identify->value.IsInt()){
  3977. identified = it_identify->value.GetInt();
  3978. }
  3979. auto it_page_id = it_page->FindMember("page_id");
  3980. if (it_page_id != it_page->MemberEnd() && it_page_id->value.IsInt()){
  3981. page_id = it_page_id->value.GetInt();
  3982. ret[page_id] = g_page_id++;
  3983. }
  3984. char sz_sql[256] = { 0 };
  3985. sprintf_s(sz_sql, sql_fmt.c_str(), paper_id, identified, _path.c_str(), _path.c_str(), ret[page_id]);
  3986. bantch_db.execDML(sz_sql);
  3987. }
  3988. LeaveCriticalSection(&bantch_db_lock);
  3989. std::string ori_path = path + "ori\\";
  3990. CreateDirectoryA(ori_path.c_str(),NULL);
  3991. for (int i = 0; i < 10; ++i)
  3992. {
  3993. CString tmp_path = AnsiToUnicode(path + "image_"+ std::to_string(i+1)+".jpg");
  3994. if (PathFileExists(tmp_path)){
  3995. MoveFile(tmp_path, AnsiToUnicode(ori_path + "image_" + std::to_string(i + 1) + ".jpg"));
  3996. }
  3997. else{
  3998. break;
  3999. }
  4000. }
  4001. return ret;
  4002. }
  4003. void CBatchService::RestoreException(int paper_id, rapidjson::Value&value, const std::map<int, int>&mapPageID)
  4004. {
  4005. std::string sql_fmt1 = "INSERT INTO exception(exception_type,exception_name,page_id,student_paper_id)VALUES(%d,'%s',%d,%d)";
  4006. std::string sql_fmt2 = "INSERT INTO exception(exception_type,exception_name,student_paper_id)VALUES(%d,'%s',%d)";
  4007. EnterCriticalSection(&bantch_db_lock);
  4008. for (auto it_ex = value.Begin(); it_ex != value.End();++it_ex)
  4009. {
  4010. std::string exception_name;
  4011. int exception_type = -1, page_id = -1, student_paper_id = -1;
  4012. auto it_type = it_ex->FindMember("exception_type");
  4013. if (it_type != it_ex->MemberEnd() && it_type->value.IsInt()){
  4014. exception_type = it_type->value.GetInt();
  4015. }
  4016. auto it_page_id = it_ex->FindMember("page_id");
  4017. if (it_page_id != it_ex->MemberEnd() && it_page_id->value.IsInt()){
  4018. auto it_find_page_id = mapPageID.find(it_page_id->value.GetInt());
  4019. if (it_find_page_id != mapPageID.end())
  4020. {
  4021. page_id = it_find_page_id->second;
  4022. }
  4023. }
  4024. auto it_name = it_ex->FindMember("exception_name");
  4025. if (it_name != it_ex->MemberEnd() && it_name->value.IsString()){
  4026. exception_name = it_name->value.GetString();
  4027. }
  4028. char sz_sql[256] = { 0 };
  4029. if (page_id==-1){
  4030. sprintf_s(sz_sql, sql_fmt2.c_str(), exception_type, exception_name.c_str(), paper_id);
  4031. }
  4032. else{
  4033. sprintf_s(sz_sql, sql_fmt1.c_str(), exception_type, exception_name.c_str(), page_id, paper_id);
  4034. }
  4035. bantch_db.execDML(sz_sql);
  4036. }
  4037. LeaveCriticalSection(&bantch_db_lock);
  4038. }
  4039. void CBatchService::RestoreResult(int paper_id, rapidjson::Value&value, const std::map<int, int>&mapPageID)
  4040. {
  4041. EnterCriticalSection(&bantch_db_lock);
  4042. std::string sql_fmt = "INSERT INTO result(student_paper_id,question_code,question_state,answer,type,score,score_paper,isright, page_id)VALUES(%d,'%s',%d,'%s',%d,%0.2f,%0.2f,%d, %d)";
  4043. for (auto it_rst = value.Begin(); it_rst != value.End(); ++it_rst)
  4044. {
  4045. std::string answer, question_code;
  4046. float score_paper = 0.0, score = 0.0;
  4047. int type = 0, isright = 0, question_state = 0;
  4048. int page_id = 0;
  4049. auto it_answer = it_rst->FindMember("answer");
  4050. if (it_answer != it_rst->MemberEnd() && it_answer->value.IsString()){
  4051. answer = it_answer->value.GetString();
  4052. }
  4053. auto it_code = it_rst->FindMember("question_code");
  4054. if (it_code != it_rst->MemberEnd() && it_code->value.IsString()){
  4055. question_code = it_code->value.GetString();
  4056. }
  4057. auto it_state = it_rst->FindMember("question_state");
  4058. if (it_state != it_rst->MemberEnd() && it_state->value.IsInt()){
  4059. question_state = it_state->value.GetInt();
  4060. }
  4061. auto it_type = it_rst->FindMember("type");
  4062. if (it_type != it_rst->MemberEnd() && it_type->value.IsInt()){
  4063. type = it_type->value.GetInt();
  4064. }
  4065. auto it_page_id = it_rst->FindMember("page_id");
  4066. if (it_page_id != it_rst->MemberEnd() && it_page_id->value.IsInt()){
  4067. auto it_find_page_id = mapPageID.find(it_page_id->value.GetInt());
  4068. if (it_find_page_id != mapPageID.end())
  4069. {
  4070. page_id = it_find_page_id->second;
  4071. }
  4072. }
  4073. auto it_score_paper = it_rst->FindMember("score_paper");
  4074. if (it_score_paper != it_rst->MemberEnd() && (it_score_paper->value.IsDouble() || it_score_paper->value.IsInt())){
  4075. score_paper = it_score_paper->value.GetDouble();
  4076. }
  4077. auto it_score = it_rst->FindMember("score");
  4078. if (it_score != it_rst->MemberEnd() && (it_score->value.IsDouble() || it_score->value.IsInt())){
  4079. score = it_score->value.GetDouble();
  4080. }
  4081. auto it_is_right = it_rst->FindMember("isright");
  4082. if (it_is_right != it_rst->MemberEnd() && it_is_right->value.IsBool()){
  4083. isright = it_is_right->value.GetBool() ? 1 : 0;
  4084. }
  4085. char sz_sql[256] = { 0 };
  4086. sprintf_s(sz_sql, sql_fmt.c_str(), paper_id, question_code.c_str(), question_state, answer.c_str(), type, score, score_paper, isright, page_id);
  4087. bantch_db.execDML(sz_sql);
  4088. }
  4089. LeaveCriticalSection(&bantch_db_lock);
  4090. }
  4091. void CBatchService::RestoreStudent(rapidjson::Value&value)
  4092. {
  4093. EnterCriticalSection(&bantch_db_lock);
  4094. std::string qry_sql = "select count(*) from student where ";
  4095. std::string sql_fmt = "INSERT INTO student( studentCard,recoverFlag,student_id,student_code,class_name,school_id,grade_name,student_name,class_id,schoolStudentCard,score_total)VALUES('%s',%d ,'%s','%s','%s',%lld ,'%s','%s', %lld ,'%s', %f )";
  4096. std::string studentCard, student_id, student_code, class_name, grade_name, student_name, schoolStudentCard;
  4097. int recoverFlag = 0;
  4098. long long school_id = 0, class_id = 0;
  4099. float score_total = 0.0;
  4100. auto it_student_code = value.FindMember("student_code");
  4101. if (it_student_code != value.MemberEnd() && it_student_code->value.IsString()){
  4102. student_code = it_student_code->value.GetString();
  4103. }
  4104. qry_sql += " student_code='" + student_code + "' and ";
  4105. auto it_student_id = value.FindMember("student_id");
  4106. if (it_student_id != value.MemberEnd() && it_student_id->value.IsString()){
  4107. student_id = it_student_id->value.GetString();
  4108. }
  4109. qry_sql += " student_id='" + student_id + "' and ";
  4110. auto it_school_id = value.FindMember("school_id");
  4111. if (it_school_id != value.MemberEnd() && it_school_id->value.IsString()){
  4112. std::string tmp = it_school_id->value.GetString();
  4113. if (!tmp.empty()){
  4114. school_id = std::stoll(tmp);
  4115. }
  4116. }
  4117. qry_sql += " school_id=" + std::to_string(school_id) + " and ";
  4118. auto it_class_id = value.FindMember("class_id");
  4119. if (it_class_id != value.MemberEnd() && it_class_id->value.IsString()){
  4120. std::string tmp = it_class_id->value.GetString();
  4121. if (!tmp.empty()){
  4122. class_id = std::stoll(tmp);
  4123. }
  4124. }
  4125. qry_sql += " class_id=" + std::to_string(class_id);
  4126. auto it_class_name = value.FindMember("class_name");
  4127. if (it_class_name != value.MemberEnd() && it_class_name->value.IsString()){
  4128. class_name = it_class_id->value.GetString();
  4129. }
  4130. auto it_grade_name = value.FindMember("grade_name");
  4131. if (it_grade_name != value.MemberEnd() && it_grade_name->value.IsString()){
  4132. grade_name = it_grade_name->value.GetString();
  4133. }
  4134. auto it_recoverFlag = value.FindMember("recoverFlag");
  4135. if (it_recoverFlag != value.MemberEnd() && it_recoverFlag->value.IsInt()){
  4136. recoverFlag = it_recoverFlag->value.GetInt();
  4137. }
  4138. auto it_schoolStudentCard = value.FindMember("schoolStudentCard");
  4139. if (it_schoolStudentCard != value.MemberEnd() && it_schoolStudentCard->value.IsString()){
  4140. schoolStudentCard = it_schoolStudentCard->value.GetString();
  4141. }
  4142. auto it_score_total = value.FindMember("score_total");
  4143. if (it_score_total != value.MemberEnd() && (it_score_total->value.IsInt() || it_score_total->value.IsDouble())){
  4144. score_total = it_score_total->value.GetDouble();
  4145. }
  4146. auto it_studentCard = value.FindMember("studentCard");
  4147. if (it_studentCard != value.MemberEnd() && it_studentCard->value.IsString()){
  4148. studentCard = it_studentCard->value.GetString();
  4149. }
  4150. auto it_student_name = value.FindMember("student_name");
  4151. if (it_student_name != value.MemberEnd() && it_student_name->value.IsString()){
  4152. student_name = it_student_name->value.GetString();
  4153. }
  4154. if (bantch_db.execScalar(qry_sql.c_str())<=0){
  4155. char sz_sql[512] = { 0 };
  4156. sprintf_s(sz_sql, sql_fmt.c_str(), studentCard.c_str(), recoverFlag, student_id.c_str(),
  4157. student_code.c_str(), class_name.c_str(), school_id, grade_name.c_str(), student_name.c_str(), class_id, schoolStudentCard.c_str(), score_total);
  4158. bantch_db.execDML(sz_sql);
  4159. }
  4160. LeaveCriticalSection(&bantch_db_lock);
  4161. }
  4162. void CBatchService::RestoreErrorHandleSite(const std::string& task_id, const std::string&type, const std::string& strPath)
  4163. {
  4164. std::string json_path = strPath + "json.txt";
  4165. std::string str_json;
  4166. int stu_paper_id = -1;
  4167. readFile(json_path, str_json);
  4168. try{
  4169. if (!str_json.empty()){
  4170. rapidjson::Document doc;
  4171. doc.Parse(str_json.c_str());
  4172. if (doc.HasParseError()) return;
  4173. // 恢复student_paper表
  4174. auto it_stu_paper = doc.FindMember("student_paper");
  4175. if (it_stu_paper != doc.MemberEnd() && it_stu_paper->value.IsObject())
  4176. stu_paper_id = RestoreStudentPaper(task_id, type, it_stu_paper->value);
  4177. std::map<int, int> mapPageID;
  4178. // 恢复page表
  4179. auto it_pages = doc.FindMember("pages");
  4180. if (it_pages != doc.MemberEnd() && it_pages->value.IsArray()){
  4181. mapPageID = RestorePages(stu_paper_id, strPath, it_pages->value);
  4182. }
  4183. //RestoreFile(stu_paper_id, strPath + "rst.zip", strPath + "ori.zip");
  4184. RestoreFile(stu_paper_id, strPath + "rst\\img", strPath + "ori");
  4185. // 恢复异常表
  4186. auto it_exception = doc.FindMember("exceptions");
  4187. if (stu_paper_id > 0 && it_exception != doc.MemberEnd() && it_exception->value.IsArray())
  4188. RestoreException(stu_paper_id, it_exception->value, mapPageID);
  4189. // 恢复resut表
  4190. auto it_result = doc.FindMember("result");
  4191. if (stu_paper_id > 0 && it_result != doc.MemberEnd() && it_result->value.IsArray())
  4192. RestoreResult(stu_paper_id, it_result->value, mapPageID);
  4193. // 恢复student表
  4194. auto it_student = doc.FindMember("student");
  4195. if (it_student != doc.MemberEnd() && it_student->value.IsObject())
  4196. RestoreStudent(it_student->value);
  4197. }
  4198. }
  4199. catch (CppSQLite3Exception&e){
  4200. ::MessageBoxA(NULL, e.errorMessage(), "提示", MB_OK);
  4201. }
  4202. if (m_hwnd != NULL)
  4203. ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, 0, stu_paper_id);
  4204. }
  4205. void CBatchService::leaveCurrentBatch()
  4206. {
  4207. if (m_upload_manager.IsEanble()){
  4208. m_upload_manager.SetNotifyPtr(nullptr);
  4209. NetOperator::SetClientNotifyPtr(nullptr);
  4210. NetOperator::ClientStop();
  4211. }
  4212. }
  4213. void CBatchService::OnNetNotify(const char*data)
  4214. {
  4215. LOGFMTI("from zxhx:%s",data);
  4216. if (!data) return;
  4217. rapidjson::Document root;
  4218. root.Parse(data);
  4219. if (!root.HasParseError()){
  4220. auto it_task_type = root.FindMember("net_task_type");
  4221. auto it_cmd = root.FindMember("net_task_cmd");
  4222. if (it_cmd != root.MemberEnd() && it_task_type!= root.MemberEnd()){
  4223. std::string task_type = it_task_type->value.GetString();
  4224. std::string cmd = it_cmd->value.GetString();
  4225. if (task_type == "systerm_notify"){
  4226. if (cmd == "server_error"||cmd =="server_close"){
  4227. LOGI("IPC出错,开始重连");
  4228. m_upload_manager.OnTcpError();
  4229. std::async(std::launch::async, [&](){
  4230. NetOperator::ClientStop();
  4231. int nIndex = 1;
  4232. while (NetOperator::InitClient("127.0.0.1", 99995, this) < 0 && nIndex < 100){
  4233. LOGFMTI("第%d次重连失败 %d秒后再次重连", nIndex, nIndex * 2000);
  4234. Sleep(nIndex * 2000);
  4235. nIndex++;
  4236. }
  4237. if (nIndex < 100){
  4238. LOGI("IPC出错,重连成功");
  4239. m_upload_manager.OnReConnect(true);
  4240. }
  4241. else{
  4242. LOGE("IPC出错,重连失败");
  4243. m_upload_manager.OnReConnect(false);
  4244. }
  4245. });
  4246. }
  4247. }
  4248. else{
  4249. // 边扫描边上传服务
  4250. if (m_upload_manager.IsEanble()){
  4251. if (task_type == "upload_on_scan_upload"){
  4252. m_upload_manager.OnNetNotify(data);
  4253. }
  4254. }
  4255. // 未来可能添加的其他服务
  4256. }
  4257. }
  4258. else{
  4259. LOGE("data from zxhx is 非法数据包 ");
  4260. }
  4261. }
  4262. else{
  4263. LOGE("data from zxhx is not a json");
  4264. }
  4265. }
  4266. int CBatchService::ExamineThisScan(PAPER_DETAIL &paper_detail)
  4267. {
  4268. EnterCriticalSection(&bantch_db_lock);
  4269. char sql[512] = { 0 };
  4270. sprintf_s(sql, "select * from student_paper where student_id='%s' and ret_upload=0", paper_detail.student_id);
  4271. bool bExsit(false);
  4272. CppSQLite3Query q = bantch_db.execQuery(sql);
  4273. while (!q.eof())
  4274. {
  4275. int paper_id = q.getIntField(0);
  4276. if (paper_detail.paper_id == paper_id)
  4277. {
  4278. bExsit = true;
  4279. break;
  4280. }
  4281. q.nextRow();
  4282. }
  4283. LeaveCriticalSection(&bantch_db_lock);
  4284. return bExsit;
  4285. }
  4286. int CBatchService::SetAbsentExam(PAPER_DETAIL &paper_detail, int absent)
  4287. {
  4288. EnterCriticalSection(&bantch_db_lock);
  4289. int state = paper_detail.exceptionsFlag;
  4290. if (1 == absent || 2 == absent)
  4291. {
  4292. if (state & EX_SHIJUANQUEKAO)
  4293. {
  4294. state ^= EX_SHIJUANQUEKAO;
  4295. }
  4296. if (2 == absent)
  4297. {
  4298. if (state & EX_KEGUANTIYICHANG)
  4299. {
  4300. state ^= EX_KEGUANTIYICHANG;
  4301. }
  4302. }
  4303. }
  4304. if (3 == absent)
  4305. {
  4306. if (state & EX_KEGUANTIYICHANG)
  4307. {
  4308. state ^= EX_KEGUANTIYICHANG;
  4309. }
  4310. }
  4311. char sql[512] = { 0 };
  4312. if (1 == absent){
  4313. sprintf_s(sql, "update student_paper set paper_state=%d, absent=0 where student_paper_id=%d", state, paper_detail.paper_id);
  4314. }
  4315. else if (2 == absent){
  4316. sprintf_s(sql, "update student_paper set paper_state=%d where student_paper_id=%d", state, paper_detail.paper_id);
  4317. }
  4318. else if (3 == absent){
  4319. sprintf_s(sql, "update student_paper set paper_state=%d, absent=1 where student_paper_id=%d", state, paper_detail.paper_id);
  4320. }
  4321. int rlt = bantch_db.execDML(sql);
  4322. LeaveCriticalSection(&bantch_db_lock);
  4323. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)100, (LPARAM)paper_detail.paper_id);
  4324. return rlt;
  4325. }
  4326. int CBatchService::QueryKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList)
  4327. {
  4328. EnterCriticalSection(&bantch_db_lock);
  4329. char sql[1024] = { 0 };
  4330. sprintf_s(sql, "select question_std.*, result.answer, (select count(1) from result where result.student_paper_id = %d and result.answer = '' and result.type IN(4, 8)) as empty_count, " \
  4331. " (select count(1) from result where result.student_paper_id = %d and result.type IN(4, 8)) as orgin_count" \
  4332. " from result left join question_std on result.question_code = question_std.question_code" \
  4333. " where result.student_paper_id = %d" \
  4334. " and result.type in(4, 8)" \
  4335. " and ((result.type = 4 and (empty_count = orgin_count or result.answer = question_std.answer_all)) or (result.type = 8 and empty_count = orgin_count))", paper_id, paper_id, paper_id);
  4336. CppSQLite3Query q = bantch_db.execQuery(sql);
  4337. while (!q.eof())
  4338. {
  4339. KEGUANTI_DETAIL keguanti;
  4340. strcpy_s(keguanti.question_code, q.getStringField("question_code"));
  4341. strcpy_s(keguanti.answer_all, q.getStringField("answer_all"));
  4342. strcpy_s(keguanti.answer_std, q.getStringField("answer_std"));
  4343. strcpy_s(keguanti.answer, q.getStringField("answer"));
  4344. keguanti.question_type = q.getIntField("question_type");
  4345. keguanti.score_full = q.getFloatField("score_full");
  4346. keguanti.score_half = q.getFloatField("score_half");
  4347. keguanti.question_nick_code = m_mapKeguantiNickName[keguanti.question_code];
  4348. keguantiList.push_back(keguanti);
  4349. q.nextRow();
  4350. }
  4351. LeaveCriticalSection(&bantch_db_lock);
  4352. return TRUE;
  4353. }
  4354. int CBatchService::UpdateKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList)
  4355. {
  4356. try
  4357. {
  4358. EnterCriticalSection(&bantch_db_lock);
  4359. m_scoreCounter.Load();
  4360. database_db->execDML("begin transaction");
  4361. float score_total = 0; // 本次客观题异常经过修正后所增加的分数
  4362. for (auto& iter : keguantiList)
  4363. {
  4364. // 更新客观题分数
  4365. iter.score = m_scoreCounter.GetScore(iter.question_code, iter.answer, 0, 0);
  4366. CppSQLite3Statement stmt = bantch_db.compileStatement("update result set answer=:answer, score=:score, score_paper=:score_paper where question_code=:question_code and student_paper_id=:student_paper_id and type in(4, 8)");
  4367. stmt.bind(":answer", iter.answer);
  4368. stmt.bind(":score", iter.score);
  4369. stmt.bind(":score_paper", iter.score);
  4370. stmt.bind(":question_code", iter.question_code);
  4371. stmt.bind(":student_paper_id", paper_id);
  4372. stmt.execDML();
  4373. score_total += iter.score;
  4374. }
  4375. CppSQLite3Statement stmt = bantch_db.compileStatement("update student_paper set paper_state =paper_state-(paper_state&:paper_state), score_total =score_total+:score_total where student_paper_id=:student_paper_id");
  4376. stmt.bind(":paper_state", EX_KEGUANTIYICHANG);
  4377. stmt.bind(":score_total", score_total);
  4378. stmt.bind(":student_paper_id", paper_id);
  4379. stmt.execDML();
  4380. database_db->execDML("commit transaction");
  4381. }
  4382. catch (...)
  4383. {
  4384. database_db->execDML("rollback transaction");
  4385. OutputDebugString(_T("IResultHandler.SavePaper.catch CppSQLite3Exception"));
  4386. }
  4387. LeaveCriticalSection(&bantch_db_lock);
  4388. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)100, (LPARAM)paper_id);
  4389. return TRUE;
  4390. }