BatchService.cpp 185 KB

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