123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563 |
- #include "StdAfx.h"
- #include "BatchService.h"
- #include "scan_common.h"
- #include "..\EvaluationUtil\HttpClient.h"
- #include "..\Schema\schema_struct.h"
- #include "SchemaLoader.h"
- #include "basic_struct_result.h"
- #include "..\Identifier\schema_struct.h"
- #include "ServerConfig.h"
- //#include "Log4cplusInitalizer.h"
- #include "TemplateManager.h"
- #include "resource.h"
- #include "IdentifyService.h"
- #include "ResultUploader.h"
- #include <direct.h>
- #include <time.h>
- #include "OnlineCardIdentifyService.h"
- #include <fstream>
- #include "../Identifier/OnLineCardSchemaStruct.h"
- #include "..\ZLibWrapMemLib\UnZipFile.h"
- #include "..\ZLibWrapMemLib\MemZipFile.h"
- #include "..\ZLibWrapLib\ZLibWrapLib.h"
- #include "OnlineCardStudentMatcher.h"
- #include "ResultUploader.h"
- #include <future>
- using namespace schema;
- using namespace OnLineCard;
- CString GetExePath()
- {
- HMODULE module = GetModuleHandle(0);
- TCHAR pFileName[MAX_PATH + 2] = { 0 };
- GetModuleFileName(module, pFileName, MAX_PATH);
- CString csFullPath(pFileName);
- int nPos = csFullPath.ReverseFind(_T('\\'));
- if (nPos < 0)
- return CString("");
- else
- return csFullPath.Left(nPos);
- }
- CString AnsiToUnicode(const std::string& str);
- std::string UnicodeToAnsi(const CString& str);
- int g_my_scan_type;//0答题卡 1督学卡
- int g_my_continue_scan = 0;
- //督学卡学校id
- std::string g_strShoolId;
- std::string g_strUpLoadDbPathName;
- int g_myindex = 1;
- extern int g_flagid;
- void ThreadLog2(char* ThreadName, char* fileName)
- {
- char buf[200];
- _getcwd(buf, sizeof(buf));
- strcat_s(buf, "\\ThirdParty\\");
- strcat_s(buf, fileName);
- FILE *file = NULL;
- fopen_s(&file, buf, "at+");
- if (file == NULL)
- {
- // printf("路径错误\n");
- //system("pause");
- return;
- }
- fseek(file, 0, SEEK_END);
- char bufThread[200];
- strcpy_s(bufThread, sizeof(bufThread), ThreadName);
- fwrite(&bufThread, strlen(bufThread), 1, file);
- fclose(file);
- }
- CBatchService::CBatchService(bool bOnlineCard, int nSubjectID, int nOnlineScanType)
- :m_bantch_state(DATABASE_STATE_CREATE),
- m_result_uploader(new CResultUploader()),
- m_bOnlineCard(bOnlineCard),
- m_nSubjectID(nSubjectID),
- m_nOnlineScanType(nOnlineScanType)
- {
- m_eventZXHXCreateDB = CreateEvent(NULL, false, false, NULL);
- m_result_uploader->EnableOnLineCard(m_bOnlineCard, m_nSubjectID, nOnlineScanType);
- m_upload_manager.m_pBatchService = this;
- m_onlineCardTemplate = new OnLineCard::PaperTemplate;
- InitializeCriticalSection(&bantch_db_lock);
- m_bErrorHandle = false;
- NetOperator::SetClientNotifyPtr(this);
- if (getRunFlag() == _T("1")){
- CString _ini_file = GetExePath() + _T("\\..\\config.ini");
- TCHAR sz_b_code[100] = { 0 };
- GetPrivateProfileString(_T("THRID"), _T("cur_bantch_code"), _T(""), sz_b_code, sizeof(sz_b_code) / sizeof(TCHAR), _ini_file);
- auto bantch_code = UnicodeToAnsi(sz_b_code);
- m_upload_manager.SetBatchCode(bantch_code);
- }
- LOGI("连接知心慧学");
- int nRet = NetOperator::InitClient("127.0.0.1", 99995, this);
- if (nRet==-1){
- LOGI("连接知心慧学已存在,无需再次连接");
- }
- else if (nRet<0){
- LOGE("连接知心慧学-ERROR");
- }
- else{
- LOGI("连接知心慧学-SUCCESS");
- }
- }
- CBatchService::~CBatchService(void)
- {
- if (m_coverd_all_kaohaochongtu.valid()){
- LOGI("等待覆盖所有考号冲突线程退出");
- m_coverd_all_kaohaochongtu.wait();
- LOGI("覆盖所有考号冲突线程退出");
- }
- if (m_onlineCardTemplate)
- delete m_onlineCardTemplate;
- m_onlineCardTemplate = nullptr;
- DeleteCriticalSection(&bantch_db_lock);
- CloseHandle(m_eventZXHXCreateDB);
- NetOperator::SetClientNotifyPtr(NULL);
- }
- //开始扫描处理函数
- ServiceState CBatchService::OnStarting(void)
- {
- char sql[512];
- sprintf_s(sql, "update database set database_state =%d where database_id =%d", DATABASE_STATE_SCANNING, m_database_id);
- EnterCriticalSection(database_db_lock);
- database_db->execDML("begin transaction");
- database_db->execDML(sql);
- database_db->execDML("commit transaction");
- LeaveCriticalSection(database_db_lock);
- mainService->SetHandlerWnd(m_hwnd);
- mainService->Start();
- while (mainService->GetServiceSate()== starting)
- {
- Sleep(10);
- }
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_STARTED, 0, 0);
- return running;
- }
- ServiceState CBatchService::OnRunning(void)
- {
- ServiceState nextState = IService::OnRunning();
- if (nextState == pausing) return nextState;
- if (nextState == stoping) return nextState;
- if (mainService->GetServiceSate()==stoped){
- return stoping;
- }else{
- Sleep(10);
- }
- return running;
- }
- static void resetQueScore(std::vector<schema::SCHEMA_QUESTION> &questions, std::string rule)
- {
- Json::Value qesScores;
- if (rule.empty())
- return;
- Json::Features features;
- Json::Reader re(features);
- Json::Value root;
- re.parse(rule, root);
- qesScores = root["questions"];
- if (qesScores.isNull())
- return;
- int array_size = 0;
- array_size = qesScores.size();
- for (int i = 0; i < array_size; i++)
- {
- Json::Value row = qesScores[i];
- int qesid = row["questionNum"].asInt();
- int qestype = row["questionTypeId"].asInt();
- float score = atof(row["fullScore"].asString().c_str());
- string answer = "";
- if (!row["answer"].isNull())
- {
- answer = row["answer"].asString();
- }
- for (auto& it : questions)
- {
- char str[25];
- itoa(qesid, str, 10);
- if (strcmp(it.question_code_new, str) == 0)
- {
- it.score = score;
- if (answer.length())
- {
- it.answerA = answer;
- }
- break;
- }
- }
- }
- }
- int CBatchService::LoadSchema(long long examId, std::string examName, long examCourseId, std::string courseName, std::string schemaPath, std::string rule/*=""*/)
- {
- if (m_upload_manager.IsEanble()){
- // 边扫描边上传模式
- ScanParamInfo obj;
- obj.subject_id = std::to_string(m_examCourseId);
- obj.course_name = m_courseName;
- obj.exam_id = std::to_string(m_examId);
- CString _ini_file = GetExePath() + _T("\\..\\config.ini");
- if (m_upload_manager.IsContinue()){
- TCHAR sz_b_code[100] = { 0 };
- GetPrivateProfileString(_T("THRID"), _T("cur_bantch_code"), _T(""), sz_b_code, sizeof(sz_b_code) / sizeof(TCHAR), _ini_file);
- obj.bantch_code = UnicodeToAnsi(sz_b_code);
- }
- else{
- obj.bantch_code = UnicodeToAnsi(m_bantch_code);
- WritePrivateProfileString(_T("THRID"), _T("cur_bantch_code"), m_bantch_code, _ini_file);
- }
- m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_START_SCAN, (const char*)&obj, m_nOnlineScanType);
- m_result_uploader->SetBatchCode(AnsiToUnicode(obj.bantch_code));
- if (WaitForSingleObject(m_eventZXHXCreateDB, INFINITE) != WAIT_OBJECT_0){
- LOGI("等待知心慧学创建数据库超时");
- ::PostMessage(m_hwnd, WM_IDENTIFOR_STOPED, 0, 0);
- return IDF_LOAD_FAILURE;
- }
- else{
- if (!m_upload_manager.IsZXHXCreateUploadDBSuccess()){
- LOGI("知心慧学创建数据库错误,无法扫描OR扫描后无法上传");
- ::PostMessage(m_hwnd, WM_IDENTIFOR_STOPED, 0, 0);
- return IDF_LOAD_FAILURE;
- }
- }
- }
- m_examId = examId;
- m_examCourseId = examCourseId;
- CSchemaLoader schemaLoader;
- if (!m_bOnlineCard){
- int ret = schemaLoader.Load(schemaPath, m_muban_img_dir, m_schema0, m_schema, m_handleInfo);
- if (ret == SCH_LOAD_SUCCESS)
- {
- resetQueScore(m_schema0.questions, rule);
- saveQuestionStd(examId, examName, examCourseId, courseName, m_schema0.questions, rule);
- recordBarcodeFlag(0);
- for (int i = 0; i < m_schema0.pages.size(); i++)
- {
- if (m_schema0.pages[i].codes.size()>0)
- recordBarcodeFlag(1);
- }
- g_myindex = 1;
- mainService->SetFolderPageNumber(m_schema0.pages.size());
- return IDF_LOAD_SUCCESS;
- }
- else
- {
- return IDF_LOAD_CLASS_SCHEMA | ret;
- }
- }
- else
- {
- if (m_onlineCardTemplate)
- {
- if (ParseTemplateFromJson(schemaPath))
- {
- Online_saveQuestionStd(examId, examName, examCourseId, courseName, rule);
- mainService->SetFolderPageNumber(m_onlineCardTemplate->pages.size());
- return IDF_LOAD_SUCCESS;
- }
- else
- {
- return IDF_LOAD_FAILURE;
- }
- }
- else
- return IDF_LOAD_FAILURE;
- }
- return IDF_LOAD_FAILURE;
- }
- #include "pugixml/pugixml.hpp"
- // void ParseTemplateOffset(const std::string&file_name, OnLineCard::PaperTemplate* m_onlineCard)
- // {
- // if (m_onlineCard->pages.size() <= 0)return;
- // if (!m_onlineCard) return;
- // pugi::xml_document doc;
- // auto result = doc.load_file(file_name.c_str());
- // if (result.status != pugi::status_ok)
- // return;
- // for (auto child = doc.child("item_info").first_child(); child; child = child.next_sibling())
- // {
- // std::string child_name = child.name();
- // if (child_name == "dingweidian_w_max_rate"){
- // std::string value = child.attribute("value").value();
- // if (!value.empty())
- // m_onlineCard->dingweidian_w_max_rate = std::stof(value);
- // }
- // else if (child_name == "dingweidian_w_min_rate"){
- // std::string value = child.attribute("value").value();
- // if (!value.empty())
- // m_onlineCard->dingweidian_w_min_rate = std::stof(value);
- // }
- // else if (child_name == "dingweidian_h_max_rate"){
- // std::string value = child.attribute("value").value();
- // if (!value.empty())
- // m_onlineCard->dingweidian_h_max_rate = std::stof(value);
- // }
- // else if (child_name == "dingweidian_h_min_rate"){
- // std::string value = child.attribute("value").value();
- // if (!value.empty())
- // m_onlineCard->dingweidian_h_min_rate = std::stof(value);
- // }
- // else if (child_name == "dingweidian_range_top"){
- // std::string value = child.attribute("value").value();
- // if (!value.empty())
- // m_onlineCard->dingweidian_range_top = std::stoi(value);
- // }
- // else if (child_name == "dingweidian_rang_buttom"){
- // std::string value = child.attribute("value").value();
- // if (!value.empty())
- // m_onlineCard->dingweidian_rang_buttom = std::stoi(value);
- // }
- // else if (child_name == "open_save_debug_img"){
- // std::string value = child.attribute("value").value();
- // if (!value.empty())
- // m_onlineCard->open_save_debug_img = (std::stoi(value) == 1);
- // }
- // else{
- // Item_Pos_offset_Info info;
- // for (pugi::xml_attribute attr = child.first_attribute(); attr; attr = attr.next_attribute()){
- // std::string attr_name = attr.name();
- // if (attr_name == "type"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.type = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "x_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.x_offset = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "y_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.y_offset = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "w_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.w_offset = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "h_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.h_offset = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "score_x_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.x_offset_score = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "score_y_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.y_offset_score = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "score_w_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.w_offset_score = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "score_h_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.h_offset_score = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "id"){
- // info.question_id = attr.value();
- // }
- // else if (attr_name == "opt_x_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.x_offset_opt = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "opt_y_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.y_offset_opt = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "opt_w_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.w_offset_opt = (item_type)std::stoi(value);
- // }
- // else if (attr_name == "opt_h_offset"){
- // std::string value = attr.value();
- // if (!value.empty())
- // info.h_offset_opt = (item_type)std::stoi(value);
- // }
- // }
- // std::string key = info.question_id;
- // if (info.type == item_type::type_absent || //缺考标记
- // info.type == item_type::type_qrbar || // 二维码
- // info.type == item_type::type_tiaoxingma){ // 条形码
- // Pos*pos = &m_onlineCard->pages[1].absent;
- // if (info.type == item_type::type_qrbar)pos = &m_onlineCard->pages[1].QrCode;
- // else if (info.type == item_type::type_tiaoxingma)pos = &m_onlineCard->pages[1].studentcode_bar;
- // pos->x += info.x_offset;
- // pos->y += info.y_offset;
- // pos->w += info.w_offset;
- // pos->h += info.h_offset;
- // continue;
- // }
- // else if (info.type == item_type::type_tiantukaohao){
- // key = "tiantukaohao";
- // }
- // else if (info.type == item_type::type_question_keguan){
- // key = "question_keguan";
- // }
- // else if (info.type == item_type::type_question_keguan_d){
- // key = "question_keguan_d";
- // }
- // else if (info.type == item_type::type_question_keguan_b){
- // key = "question_keguan_b";
- // }
- // m_onlineCard->_map_offset_info[key] = info;
- // }
- // }
- //
- // // 更新
- // // 填涂考号
- // auto it_find = m_onlineCard->_map_offset_info.find("tiantukaohao");
- // if (it_find != m_onlineCard->_map_offset_info.end()){
- // int nIndex = 0;
- // for (std::size_t row = 0; row < m_onlineCard->pages[1].studentcode_fill.size(); row++)
- // {
- // for (std::size_t col = 0; col < m_onlineCard->pages[1].studentcode_fill[row].size(); col++, nIndex++)
- // {
- // m_onlineCard->pages[1].studentcode_fill[row][col].pos.x += it_find->second.x_offset;
- // m_onlineCard->pages[1].studentcode_fill[row][col].pos.y += it_find->second.y_offset;
- // m_onlineCard->pages[1].studentcode_fill[row][col].pos.w += it_find->second.w_offset;
- // m_onlineCard->pages[1].studentcode_fill[row][col].pos.h += it_find->second.h_offset;
- // }
- // }
- // }
- // auto &it_keguanti = m_onlineCard->_map_offset_info.find("question_keguan");
- // auto &it_keguanti_d = m_onlineCard->_map_offset_info.find("question_keguan_d");
- // auto &it_keguanti_b = m_onlineCard->_map_offset_info.find("question_keguan_b");
- // for (std::size_t n = 0; n < m_onlineCard->pages.size(); ++n)
- // {
- // for (std::size_t i = 0; i < m_onlineCard->pages[n + 1].vctQuestions.size(); ++i)
- // {
- // std::string id = m_onlineCard->pages[n + 1].vctQuestions[i].id;
- // auto it_find = m_onlineCard->_map_offset_info.find(id);
- // if (it_find != m_onlineCard->_map_offset_info.end()){
- // // 主观题
- // if ( m_onlineCard->pages[n + 1].vctQuestions[i].type == 1 ||
- // m_onlineCard->pages[n + 1].vctQuestions[i].type == 3 ||
- // m_onlineCard->pages[n + 1].vctQuestions[i].type == 2){
- // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.x += it_find->second.x_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.y += it_find->second.y_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.w += it_find->second.w_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.h += it_find->second.h_offset;
- //
- // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.x += it_find->second.x_offset_score;
- // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.y += it_find->second.y_offset_score;
- // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.w += it_find->second.w_offset_score;
- // m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.h += it_find->second.h_offset_score;
- // if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 2){
- // // 选做题
- // for (std::size_t j = 0; j <m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_find->second.x_offset_opt;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_find->second.y_offset_opt;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_find->second.w_offset_opt;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_find->second.h_offset_opt;
- // }
- // }
- // }
- // }
- // // 单选题
- // else if (m_onlineCard->pages[n + 1].vctQuestions[i].type==0 && it_keguanti != m_onlineCard->_map_offset_info.end()){
- // for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_keguanti->second.x_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_keguanti->second.y_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_keguanti->second.w_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_keguanti->second.h_offset;
- // }
- // }
- // // 多选题
- // else if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 8 && it_keguanti_d != m_onlineCard->_map_offset_info.end()){
- // for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_keguanti_d->second.x_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_keguanti_d->second.y_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_keguanti_d->second.w_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_keguanti_d->second.h_offset;
- // }
- // }
- // // 不定项选择题
- // else if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 5 && it_keguanti_b != m_onlineCard->_map_offset_info.end()){
- // for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_keguanti_b->second.x_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_keguanti_b->second.y_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_keguanti_b->second.w_offset;
- // m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_keguanti_b->second.h_offset;
- // }
- // }
- // }
- // }
- // }
- void ParseTemplateOffset(const std::string&file_name, OnLineCard::PaperTemplate* m_onlineCard)
- {
- if (m_onlineCard->pages.size() <= 0)return;
- if (!m_onlineCard) return;
- pugi::xml_document doc;
- auto result = doc.load_file(file_name.c_str());
- if (result.status != pugi::status_ok)
- return;
- for (auto child = doc.child("item_info").first_child(); child; child = child.next_sibling())
- {
- std::string child_name = child.name();
- if (child_name == "dingweidian_w_max_rate"){
- std::string value = child.attribute("value").value();
- if (!value.empty())
- m_onlineCard->dingweidian_w_max_rate = std::stof(value);
- }
- else if (child_name == "dingweidian_w_min_rate"){
- std::string value = child.attribute("value").value();
- if (!value.empty())
- m_onlineCard->dingweidian_w_min_rate = std::stof(value);
- }
- else if (child_name == "dingweidian_h_max_rate"){
- std::string value = child.attribute("value").value();
- if (!value.empty())
- m_onlineCard->dingweidian_h_max_rate = std::stof(value);
- }
- else if (child_name == "dingweidian_h_min_rate"){
- std::string value = child.attribute("value").value();
- if (!value.empty())
- m_onlineCard->dingweidian_h_min_rate = std::stof(value);
- }
- else if (child_name == "dingweidian_range_top"){
- std::string value = child.attribute("value").value();
- if (!value.empty())
- m_onlineCard->dingweidian_range_top = std::stoi(value);
- }
- else if (child_name == "dingweidian_rang_buttom"){
- std::string value = child.attribute("value").value();
- if (!value.empty())
- m_onlineCard->dingweidian_rang_buttom = std::stoi(value);
- }
- else if (child_name == "open_save_debug_img"){
- std::string value = child.attribute("value").value();
- if (!value.empty())
- m_onlineCard->open_save_debug_img = (std::stoi(value) == 1);
- }
- else{
- Item_Pos_offset_Info info;
- for (pugi::xml_attribute attr = child.first_attribute(); attr; attr = attr.next_attribute()){
- std::string attr_name = attr.name();
- if (attr_name == "type"){
- std::string value = attr.value();
- if (!value.empty())
- info.type = (item_type)std::stoi(value);
- }
- else if (attr_name == "x_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.x_offset = (item_type)std::stoi(value);
- }
- else if (attr_name == "y_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.y_offset = (item_type)std::stoi(value);
- }
- else if (attr_name == "w_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.w_offset = (item_type)std::stoi(value);
- }
- else if (attr_name == "h_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.h_offset = (item_type)std::stoi(value);
- }
- else if (attr_name == "score_x_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.x_offset_score = (item_type)std::stoi(value);
- }
- else if (attr_name == "score_y_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.y_offset_score = (item_type)std::stoi(value);
- }
- else if (attr_name == "score_w_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.w_offset_score = (item_type)std::stoi(value);
- }
- else if (attr_name == "score_h_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.h_offset_score = (item_type)std::stoi(value);
- }
- else if (attr_name == "id"){
- info.question_id = attr.value();
- }
- else if (attr_name == "opt_x_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.x_offset_opt = (item_type)std::stoi(value);
- }
- else if (attr_name == "opt_y_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.y_offset_opt = (item_type)std::stoi(value);
- }
- else if (attr_name == "opt_w_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.w_offset_opt = (item_type)std::stoi(value);
- }
- else if (attr_name == "opt_h_offset"){
- std::string value = attr.value();
- if (!value.empty())
- info.h_offset_opt = (item_type)std::stoi(value);
- }
- else if (attr_name == "link_param"){
- std::string value = attr.value();
- if (!value.empty())
- info.link_param = (item_type)std::stoi(value);
- }
- }
- for (pugi::xml_node opt_info = child.first_child(); opt_info; opt_info = opt_info.next_sibling()){
- Item_Pos_offset_Info _opt_info;
- for (pugi::xml_attribute attr = opt_info.first_attribute(); attr; attr = attr.next_attribute()){
- std::string attr_name = attr.name();
- if (attr_name == "index"){
- // 选项序号 从0开始
- _opt_info.question_id = attr.value();
- }
- else if (attr_name == "x_offset"){
- std::string value = attr.value();
- if (!value.empty())
- _opt_info.x_offset = (item_type)std::stoi(value);
- }
- else if (attr_name == "y_offset"){
- std::string value = attr.value();
- if (!value.empty())
- _opt_info.y_offset = (item_type)std::stoi(value);
- }
- else if (attr_name == "w_offset"){
- std::string value = attr.value();
- if (!value.empty())
- _opt_info.w_offset = (item_type)std::stoi(value);
- }
- else if (attr_name == "h_offset"){
- std::string value = attr.value();
- if (!value.empty())
- _opt_info.h_offset = (item_type)std::stoi(value);
- }
- }
- info._child_info[std::stoi(_opt_info.question_id)] = _opt_info;
- }
- std::string key = info.question_id;
- if (info.type == item_type::type_absent || //缺考标记
- info.type == item_type::type_qrbar || // 二维码
- info.type == item_type::type_tiaoxingma){ // 条形码
- Pos*pos = &m_onlineCard->pages[1].absent;
- if (info.type == item_type::type_qrbar)pos = &m_onlineCard->pages[1].QrCode;
- else if (info.type == item_type::type_tiaoxingma)pos = &m_onlineCard->pages[1].studentcode_bar;
- pos->x += info.x_offset;
- pos->y += info.y_offset;
- pos->w += info.w_offset;
- pos->h += info.h_offset;
- continue;
- }
- else if (info.type == item_type::type_tiantukaohao){
- info.question_id = "tiantukaohao";
- }
- if (info.link_param>1)
- {
- info.question_id += "_";
- info.question_id += std::to_string(info.link_param);
- }
- m_onlineCard->_map_offset_info[info.question_id] = info;
- }
- }
- // 更新
- // 填涂考号
- auto it_find = m_onlineCard->_map_offset_info.find("tiantukaohao");
- if (it_find != m_onlineCard->_map_offset_info.end()){
- int nIndex = 0;
- for (std::size_t row = 0; row < m_onlineCard->pages[1].studentcode_fill.size(); row++)
- {
- for (std::size_t col = 0; col < m_onlineCard->pages[1].studentcode_fill[row].size(); col++, nIndex++)
- {
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.x += it_find->second.x_offset;
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.y += it_find->second.y_offset;
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.w += it_find->second.w_offset;
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.h += it_find->second.h_offset;
- auto it_opt_find = it_find->second._child_info.find(nIndex);
- if (it_opt_find != it_find->second._child_info.end()){
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.x += it_opt_find->second.x_offset;
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.y += it_opt_find->second.y_offset;
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.w += it_opt_find->second.w_offset;
- m_onlineCard->pages[1].studentcode_fill[row][col].pos.h += it_opt_find->second.h_offset;
- }
- }
- }
- }
- for (std::size_t n = 0; n < m_onlineCard->pages.size(); ++n)
- {
- for (std::size_t i = 0; i < m_onlineCard->pages[n + 1].vctQuestions.size(); ++i)
- {
- std::string id = m_onlineCard->pages[n + 1].vctQuestions[i].id;
- if ((m_onlineCard->pages[n + 1].vctQuestions[i].type == 1||
- m_onlineCard->pages[n + 1].vctQuestions[i].type == 2) && m_onlineCard->pages[n + 1].vctQuestions[i].cut.linkparm>1){
- id += "_";
- id += std::to_string(m_onlineCard->pages[n + 1].vctQuestions[i].cut.linkparm);
- }
- auto it_find = m_onlineCard->_map_offset_info.find(id);
- if (it_find != m_onlineCard->_map_offset_info.end()){
- // 主观题
- if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 1|| // 主观题
- m_onlineCard->pages[n + 1].vctQuestions[i].type == 3|| // 填空题
- m_onlineCard->pages[n + 1].vctQuestions[i].type == 2) // 选做题
- {
- m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.x += it_find->second.x_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.y += it_find->second.y_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.w += it_find->second.w_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].cut.pos.h += it_find->second.h_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.x += it_find->second.x_offset_score;
- m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.y += it_find->second.y_offset_score;
- m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.w += it_find->second.w_offset_score;
- m_onlineCard->pages[n + 1].vctQuestions[i].scoreBox.pos.h += it_find->second.h_offset_score;
- if (m_onlineCard->pages[n + 1].vctQuestions[i].type == 2){
- // 选做题
- for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j)
- {
- auto it_opt_find = it_find->second._child_info.find(j);
- if (it_opt_find != it_find->second._child_info.end()){
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_opt_find->second.x_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_opt_find->second.y_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_opt_find->second.w_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_opt_find->second.h_offset;
- }
- }
- }
- }
- else
- {
- // 选择题 多选题 不定项选择题
- for (std::size_t j = 0; j < m_onlineCard->pages[n + 1].vctQuestions[i].opt.size(); ++j){
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_find->second.x_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_find->second.y_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_find->second.w_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_find->second.h_offset;
- auto it_opt_find = it_find->second._child_info.find(j);
- if (it_opt_find != it_find->second._child_info.end()){
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.x += it_opt_find->second.x_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.y += it_opt_find->second.y_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.w += it_opt_find->second.w_offset;
- m_onlineCard->pages[n + 1].vctQuestions[i].opt[j].pos.h += it_opt_find->second.h_offset;
- }
- }
- }
- }
- }
- }
- }
- bool CBatchService::ParseTemplateFromJsonAll(const std::string&fileName)//全学科在线答题卡
- {
- //1 单选 2 小题单选 3 多选 4 小题多选 5 单空 6 多空 7 小题多空 8 解答 9 小题解答 10 英语作文 11 语文作文 12 判断题
- //0选择 1解答 2选作 3填空 4编组 5不定项 8不定项
- map<string, int> type_map;//新旧题型对应
- type_map["1"] = 0; type_map["2"] = 0; type_map["3"] = 5; type_map["4"] = 5; type_map["5"] = 3; type_map["6"] = 3;
- type_map["7"] = 3; type_map["8"] = 1; type_map["9"] = 1; /*type_map["10"] = 1; type_map["11"] = 1; type_map["12"] = 1;*/
- CUnZipFile uzip(CString(fileName.c_str()));
- std::map<CString, std::vector<unsigned char>> map1;
- while (uzip.HasMoreEntry()){
- CString fileNam;
- uzip.GetNextEntry(fileNam);
- char buffer[1024 * 8];
- int len;
- std::vector<unsigned char>& data = map1[fileNam];
- data.reserve(1024 * 128);
- while ((len = uzip.Read(buffer, 1024 * 8)) > 0){
- if (data.capacity() < data.size() + len){
- int c = data.capacity() + 1024 * 128;
- data.reserve(c);
- }
- int oldSize = data.size();
- data.resize(oldSize + len);
- char * dst = (char *)data.data() + oldSize;
- memcpy(dst, buffer, len);
- }
- }
- uzip.Close();
- auto schemabytes = map1.find(_T("json.txt"));
- if (schemabytes == map1.end()){
- return SCH_LOAD_ERR_MISSINGFORMAT;
- }
- std::vector<unsigned char>& data = schemabytes->second;
- auto strJson = std::string((char *)data.data(), data.size());
- if (!m_onlineCardTemplate) return false;
- m_onlineCardTemplate->pages.clear();
- auto pfGetPos = [](const rapidjson::Value&value)->std::tuple<bool, Pos>{
- bool bRet = false;
- double x = 0.0, y = 0.0, w = 0.0, h = 0.0;
- auto itX = value.FindMember("x");
- if (itX != value.MemberEnd() && (itX->value.IsInt() || itX->value.IsDouble())){
- x = itX->value.GetDouble();
- }
- auto itY = value.FindMember("y");
- if (itY != value.MemberEnd() && (itY->value.IsInt() || itY->value.IsDouble())){
- y = itY->value.GetDouble();
- }
- auto itW = value.FindMember("width");
- if (itW != value.MemberEnd() && (itW->value.IsInt() || itW->value.IsDouble())){
- w = itW->value.GetDouble();
- }
- auto itH = value.FindMember("height");
- if (itH != value.MemberEnd() && (itH->value.IsInt() || itH->value.IsDouble())){
- h = itH->value.GetDouble();
- bRet = true;
- }
- return std::tie(bRet, Pos{ x, y, w, h });
- };
- rapidjson::Document doc;
- doc.Parse(strJson.c_str());
- if (doc.HasParseError()) return false;
- m_onlineCardTemplate->subject_id = m_nSubjectID;
- m_onlineCardTemplate->_version = "old";
-
- // 检测版本号
- auto it_version = doc.FindMember("online_card_version");
- if (it_version != doc.MemberEnd() && it_version->value.IsString()){
- m_onlineCardTemplate->_version = it_version->value.GetString();
- }
- LOGFMTI("在线答题卡版本号:%s", m_onlineCardTemplate->_version.c_str());
- {
- // 总页数
- auto itTotalPage = doc.FindMember("totalPage");
- if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
- m_onlineCardTemplate->totalPage = itTotalPage->value.GetInt();
- }
- // 是否使用二维码
- auto itUseQrCode = doc.FindMember("useQrCode");
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
- m_onlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
- }
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
- m_onlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
- }
- // 学校状态
- auto itSchoolStatus = doc.FindMember("school_card_status");
- if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
- m_onlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
- }
- int n_duo_xuanti_index = 0;
- std::string temp_all_id = "";
- // 页
- auto itPages = doc.FindMember("pages");
- if (itPages != doc.MemberEnd() && itPages->value.IsArray()/* && itPages->value.Size() == m_onlineCardTemplate->totalPage*/){
- for (auto itPage = itPages->value.Begin(); itPage != itPages->value.End(); ++itPage){
- if (!itPage->IsObject()) return false;
- PageTemplate page;
- // 页号
- auto itPageNo = itPage->FindMember("pageNo");
- if (itPageNo != itPage->MemberEnd() && itPageNo->value.IsInt()){
- page.pageNo = itPageNo->value.GetInt();
- }
- else {
- return false;
- }
- // 定位点
- auto itLocations = itPage->FindMember("location");
- if (itLocations != itPage->MemberEnd() && itLocations->value.IsArray()){
- for (auto it = itLocations->value.Begin(); it != itLocations->value.End(); ++it){
- Location lc;
- auto itType = it->FindMember("type");
- if (itType != it->MemberEnd() && itType->value.IsInt()){
- lc.type = itType->value.GetInt();
- }
- auto tm = pfGetPos(*it);
- if (std::get<0>(tm)){
- lc.pos = std::get<1>(tm);
- }
- page.location.push_back(lc);
- }
- }
- if (page.pageNo == 1){
- if (!m_onlineCardTemplate->useQrCode){
- // 条形码
- auto itBar = itPage->FindMember("studentcode_bar");
- if (itBar != itPage->MemberEnd() && itBar->value.IsObject()){
- auto itObj = itBar->value.FindMember("object");
- if (itObj != itBar->value.MemberEnd() && itObj->value.IsObject()){
- auto t = pfGetPos(itObj->value);
- page.studentcode_bar = std::get<1>(t);
- }
- }
- // 填涂考号
- auto itFill = itPage->FindMember("studentcode_fill");
- if (itFill != itPage->MemberEnd() && itFill->value.IsObject()){
- auto itObj = itFill->value.FindMember("object");
- if (itObj != itFill->value.MemberEnd() && itObj->value.IsArray()){
- for (auto itRow = itObj->value.Begin(); itRow != itObj->value.End(); ++itRow){
- auto itGroup = itRow->FindMember("group");
- if (itGroup != itRow->MemberEnd() && itGroup->value.IsArray()){
- std::vector<Opt> _vctOpt;
- for (auto itCol = itGroup->value.Begin(); itCol != itGroup->value.End(); ++itCol){
- Opt opt;
- auto itOptName = itCol->FindMember("optName");
- if (itOptName != itCol->MemberEnd() && itOptName->value.IsInt())
- opt.optName = std::to_string(itOptName->value.GetInt());
- auto t = pfGetPos(*itCol);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- _vctOpt.push_back(opt);
- }
- page.studentcode_fill.push_back(_vctOpt);
- }
- }
- }
- }
- }
- // 缺考标记
- auto itAbsent = itPage->FindMember("absent");
- if (itAbsent != itPage->MemberEnd() && itAbsent->value.IsObject()){
- auto t = pfGetPos(itAbsent->value);
- if (std::get<0>(t)){
- page.absent = std::get<1>(t);
- }
- }
- // 二维码
- auto itQrCode = itPage->FindMember("QrCode");
- if (itQrCode != itPage->MemberEnd() && itQrCode->value.IsObject()){
- auto t = pfGetPos(itQrCode->value);
- if (std::get<0>(t)){
- page.QrCode = std::get<1>(t);
- }
- }
- } // end if page.pageNo == 0
- // 长宽
- auto itImge = itPage->FindMember("imge");
- if (itImge != itPage->MemberEnd()){
- auto t = std::get<1>(pfGetPos(itImge->value));
- page.w = t.w;
- page.h = t.h;
- }
- else{
- return false;
- }
- // 题目
- auto itQuestion = itPage->FindMember("questions");
- if (itQuestion != itPage->MemberEnd() && itQuestion->value.IsArray())
- {
- for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it)
- {
- question q;
- // 题目类型
- auto itType = it->FindMember("type");
- string qType = "1";
- if (itType != it->MemberEnd() && itType->value.IsString())
- {
- qType = itType->value.GetString();
- q.type = atoi(qType.c_str());
- }
- else
- {
- return false;
- }
- q.marktype = 0;
- // 题目类型
- auto itMarktype = it->FindMember("marktype");
- if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
- q.marktype = itMarktype->value.GetInt();
- }
- // 分数
- auto itScore = it->FindMember("score");
- if (itScore != it->MemberEnd() && itScore->value.IsObject()){
- auto itFull = itScore->value.FindMember("full");
- if (itFull != itScore->value.MemberEnd() && (itFull->value.IsDouble() || itFull->value.IsInt()))
- q.score = itFull->value.GetDouble();
- }
- // 题目编号 2选做题
- auto itId = it->FindMember((q.type == 2 || q.type == 4) ? "editorId" : "id");
- if (itId != it->MemberEnd() && itId->value.IsString()){
- q.id = itId->value.GetString();
- }
- if (itId != it->MemberEnd() && itId->value.IsInt()){
- q.id = std::to_string(itId->value.GetInt());
- }
- if (q.type == 2 || q.type == 4){
- auto itAllID = it->FindMember("id");
- if (itAllID != it->MemberEnd() && itAllID->value.IsString()){
- q.all_id = itAllID->value.GetString();
- }
- }
- auto itSmallQtNo = it->FindMember("smallQtNo");
- if (itSmallQtNo != it->MemberEnd() && !(itSmallQtNo->value.IsNull()))
- {
- q.smallQtNo = itSmallQtNo->value.GetInt();
- }
- else
- {
- q.smallQtNo = -1;
- }
- auto itNickID = it->FindMember("name");
- if (itNickID != it->MemberEnd() && !(itNickID->value.IsNull()) && itNickID->value.IsInt())
- {
- m_mapKeguantiNickName[q.id] = std::to_string(itNickID->value.GetInt());
- }
- // 打分区域
- auto itScoreBox = it->FindMember("scorebox");
- if (itScoreBox != it->MemberEnd() && itScoreBox->value.IsObject()){
- // 打分框类型
- auto itType = itScoreBox->value.FindMember("type");
- if (itType != itScoreBox->value.MemberEnd() && itType->value.IsString()){
- q.scoreBox.type = std::stoi(itType->value.GetString());
- }
- else if (itType != itScoreBox->value.MemberEnd() && itType->value.IsInt()){
- q.scoreBox.type = itType->value.GetInt();
- }
- else{
- return false;
- }
- if (q.smallQtNo != -1)
- {
- // 小问最大分值
- auto itmaxScore = itScoreBox->value.FindMember("maxscore");
- if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsString()){
- q.scoreBox.maxsorce = std::stod(itmaxScore->value.GetString());
- }
- else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsDouble()){
- q.scoreBox.maxsorce = itScoreBox->value.GetDouble();
- }
- else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsInt()){
- q.scoreBox.maxsorce = itmaxScore->value.GetInt();
- }
- else{
- q.scoreBox.maxsorce = 0.0;
- }
- }
- else
- {
- q.scoreBox.maxsorce = 0.0;
- }
- // 分数上限
- auto itLimit = itScoreBox->value.FindMember("limit");
- if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsString())
- q.scoreBox.limit = std::stoi(itLimit->value.GetString());
- if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsInt())
- q.scoreBox.limit = itLimit->value.GetInt();
- // 最后一个格子是否为小数 1是 2否
- auto itPoint = itScoreBox->value.FindMember("point");
- if (itPoint != itScoreBox->value.MemberEnd()){
- if (itPoint->value.IsInt()){
- q.scoreBox.bPoint = (itPoint->value.GetInt() == 1);
- }
- else if (itPoint->value.IsString()){
- std::string str = itPoint->value.GetString();
- q.scoreBox.bPoint = (str == "1");
- }
- }
- // 填空题带打分
- if (q.scoreBox.type == 3){
- auto itScore = itScoreBox->value.FindMember("Score");
- if (itScore != itScoreBox->value.MemberEnd() && itScore->value.IsArray()){
- for (auto it = itScore->value.Begin(); it != itScore->value.End(); ++it){
- if (it->IsString()){
- std::string str = it->GetString();
- if (!str.empty())
- q.scoreBox.vctScore.push_back(std::stoi(str));
- }
- }
- }
- }
- // 打分位置
- auto t = pfGetPos(itScoreBox->value);
- if (std::get<0>(t))
- q.scoreBox.pos = std::get<1>(t);
- }
- // 几选几
- if (q.type == 2 || q.type == 4){ // 选做题
- rapidjson::Value::ConstMemberIterator itSel = it->FindMember("select");
- if (itSel != it->MemberEnd() && itSel->value.IsInt()){
- q.selItem = itSel->value.GetInt();
- }
- rapidjson::Value::ConstMemberIterator itTotal = it->FindMember("total");
- if (itTotal != it->MemberEnd() && itTotal->value.IsInt()){
- q.selTotal = itTotal->value.GetInt();
- }
- }
- // 剪裁区域
- if (q.type == 1 || q.type == 3 || q.type == 2 || q.type == 4){ // 1 解答题 2 选做题 3 填空题
- auto itCut = it->FindMember("cut");
- if (itCut != it->MemberEnd() && itCut->value.IsObject()){
- auto itLink = itCut->value.FindMember("linkparm");
- if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
- q.cut.linkparm = itLink->value.GetInt();
- if (itLink != itCut->value.MemberEnd() && itLink->value.IsString())
- q.cut.linkparm = std::stoi(itLink->value.GetString());
- auto t = pfGetPos(itCut->value);
- if (std::get<0>(t))
- q.cut.pos = std::get<1>(t);
- if (q.type == 3 && m_onlineCardTemplate->subject_id == 8)
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("config.ini"));
- int english = GetPrivateProfileInt(_T("USER"), _T("english_height"), 30, FilePath);//英语填空题高度加大比例
- if (english > 0 && english <= 30)
- {
- q.cut.pos.h = q.cut.pos.h* (1.0 + english / 100.0);
- }
- }
- }
- if (q.type == 2){
- if (temp_all_id != q.all_id)
- {
- temp_all_id = q.all_id;
- n_duo_xuanti_index = 0;
- }
- if (q.cut.linkparm < 2){
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index++];
- }
- else
- {
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index - 1];
- }
- }
- else if (q.type == 4)
- {
- if (temp_all_id != q.all_id)
- {
- temp_all_id = q.all_id;
- n_duo_xuanti_index = 0;
- }
- if (q.cut.linkparm < 1){
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index++];
- }
- else
- {
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index - 1];
- }
- }
- }
- // 选项 单选题 多选题
- if (q.type == 0 || q.type == 8 || q.type == 5){
- auto itOpts = it->FindMember("opt");
- if (itOpts != it->MemberEnd() && itOpts->value.IsArray()){
- for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt){
- Opt opt;
- auto t = pfGetPos(*itOpt);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- auto itOptName = itOpt->FindMember("optName");
- if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
- opt.optName = itOptName->value.GetString();
- q.opt.push_back(opt);
- }
- }
- }
- else if (q.type == 2 || q.type == 4){ // 选作
- auto itSelectqts = it->FindMember("selectqts");
- if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
- for (auto itOpt = itSelectqts->value.Begin(); itOpt != itSelectqts->value.End(); ++itOpt){
- Opt opt;
- auto t = pfGetPos(*itOpt);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- auto itOptName = itOpt->FindMember("optName");
- if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
- opt.optName = itOptName->value.GetString();
- q.opt.push_back(opt);
- }
- }
- }
- page.vctQuestions.push_back(q);
- }
- }
- m_onlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
- }
- }
- else{
- return false;
- }
- }
- m_onlineCardTemplate->open_save_debug_img = false;
- m_onlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
- m_onlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
- m_onlineCardTemplate->dingweidian_w_max_rate = 1.0;
- m_onlineCardTemplate->dingweidian_h_max_rate = 1.0;
- m_onlineCardTemplate->dingweidian_w_min_rate = 0.7;
- m_onlineCardTemplate->dingweidian_h_min_rate = 0.7;
- CString _ini_file = GetExePath() + _T("\\config.ini");
- TCHAR sz_offset_file_name[MAX_PATH] = { 0 };
- GetPrivateProfileString(_T("USER"), _T("offset_file"), _T(""), sz_offset_file_name, sizeof(sz_offset_file_name) / sizeof(TCHAR), _ini_file);
- ParseTemplateOffset(UnicodeToAnsi(GetExePath() + _T("\\") + sz_offset_file_name), m_onlineCardTemplate);
- return true;
- }
- bool CBatchService::ParseTemplateFromJson(const std::string&fileName)
- {
- CUnZipFile uzip(CString(fileName.c_str()));
- std::map<CString, std::vector<unsigned char>> map;
- while (uzip.HasMoreEntry()){
- CString fileNam;
- uzip.GetNextEntry(fileNam);
- char buffer[1024 * 8];
- int len;
- std::vector<unsigned char>& data = map[fileNam];
- data.reserve(1024 * 128);
- while ((len = uzip.Read(buffer, 1024 * 8)) > 0){
- if (data.capacity() < data.size() + len){
- int c = data.capacity() + 1024 * 128;
- data.reserve(c);
- }
- int oldSize = data.size();
- data.resize(oldSize + len);
- char * dst = (char *)data.data() + oldSize;
- memcpy(dst, buffer, len);
- }
- }
- uzip.Close();
- auto schemabytes = map.find(_T("json.txt"));
- if (schemabytes == map.end()){
- return SCH_LOAD_ERR_MISSINGFORMAT;
- }
- std::vector<unsigned char>& data = schemabytes->second;
- auto strJson = std::string((char *)data.data(), data.size());
- if (!m_onlineCardTemplate) return false;
- m_onlineCardTemplate->pages.clear();
- auto pfGetPos = [](const rapidjson::Value&value)->std::tuple<bool, Pos>{
- bool bRet = false;
- double x = 0.0, y = 0.0, w = 0.0, h = 0.0;
- auto itX = value.FindMember("x");
- if (itX != value.MemberEnd() && (itX->value.IsInt() || itX->value.IsDouble())){
- x = itX->value.GetDouble();
- }
- auto itY = value.FindMember("y");
- if (itY != value.MemberEnd() && (itY->value.IsInt() || itY->value.IsDouble())){
- y = itY->value.GetDouble();
- }
- auto itW = value.FindMember("width");
- if (itW != value.MemberEnd() && (itW->value.IsInt() || itW->value.IsDouble())){
- w = itW->value.GetDouble();
- }
- auto itH = value.FindMember("height");
- if (itH != value.MemberEnd() && (itH->value.IsInt() || itH->value.IsDouble())){
- h = itH->value.GetDouble();
- bRet = true;
- }
- return std::tie(bRet, Pos{ x, y, w, h });
- };
- rapidjson::Document doc;
- doc.Parse(strJson.c_str());
- if (doc.HasParseError()) return false;
- m_onlineCardTemplate->subject_id = m_nSubjectID;
- m_onlineCardTemplate->_version = "old";
- auto isAllSubjectCard = doc.FindMember("isAllSubjectCard");
- if (isAllSubjectCard != doc.MemberEnd() && isAllSubjectCard->value.IsInt()){
- int nisAllSubjectCard = isAllSubjectCard->value.GetInt();
- if (nisAllSubjectCard == 1)
- {
- return ParseTemplateFromJsonAll(fileName);
- }
- }
-
- // 检测版本号
- auto it_version = doc.FindMember("online_card_version");
- if (it_version!= doc.MemberEnd() && it_version->value.IsString()){
- m_onlineCardTemplate->_version = it_version->value.GetString();
- }
- LOGFMTI("在线答题卡版本号:%s",m_onlineCardTemplate->_version.c_str());
- if (m_onlineCardTemplate->_version=="old"){
- // 总页数
- auto itTotalPage = doc.FindMember("totalPage");
- if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
- m_onlineCardTemplate->totalPage = itTotalPage->value.GetInt();
- }
- // 是否使用二维码
- auto itUseQrCode = doc.FindMember("useQrCode");
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
- m_onlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
- }
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
- m_onlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
- }
- // 学校状态
- auto itSchoolStatus = doc.FindMember("school_card_status");
- if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
- m_onlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
- }
- int n_duo_xuanti_index = 0;
- // 页
- auto itPages = doc.FindMember("pages");
- if (itPages != doc.MemberEnd() && itPages->value.IsArray() && itPages->value.Size() == m_onlineCardTemplate->totalPage){
- for (auto itPage = itPages->value.Begin(); itPage != itPages->value.End(); ++itPage){
- if (!itPage->IsObject()) return false;
- PageTemplate page;
- // 页号
- auto itPageNo = itPage->FindMember("pageNo");
- if (itPageNo != itPage->MemberEnd() && itPageNo->value.IsInt()){
- page.pageNo = itPageNo->value.GetInt();
- }
- else {
- return false;
- }
- // 定位点
- auto itLocations = itPage->FindMember("location");
- if (itLocations != itPage->MemberEnd() && itLocations->value.IsArray()){
- for (auto it = itLocations->value.Begin(); it != itLocations->value.End(); ++it){
- Location lc;
- auto itType = it->FindMember("type");
- if (itType != it->MemberEnd() && itType->value.IsInt()){
- lc.type = itType->value.GetInt();
- }
- auto tm = pfGetPos(*it);
- if (std::get<0>(tm)){
- lc.pos = std::get<1>(tm);
- }
- page.location.push_back(lc);
- }
- }
- if (page.pageNo == 1){
- if (!m_onlineCardTemplate->useQrCode){
- // 条形码
- auto itBar = itPage->FindMember("studentcode_bar");
- if (itBar != itPage->MemberEnd() && itBar->value.IsObject()){
- auto itObj = itBar->value.FindMember("object");
- if (itObj != itBar->value.MemberEnd() && itObj->value.IsObject()){
- auto t = pfGetPos(itObj->value);
- page.studentcode_bar = std::get<1>(t);
- }
- }
- // 填涂考号
- auto itFill = itPage->FindMember("studentcode_fill");
- if (itFill != itPage->MemberEnd() && itFill->value.IsObject()){
- auto itObj = itFill->value.FindMember("object");
- if (itObj != itFill->value.MemberEnd() && itObj->value.IsArray()){
- for (auto itRow = itObj->value.Begin(); itRow != itObj->value.End(); ++itRow){
- auto itGroup = itRow->FindMember("group");
- if (itGroup != itRow->MemberEnd() && itGroup->value.IsArray()){
- std::vector<Opt> _vctOpt;
- for (auto itCol = itGroup->value.Begin(); itCol != itGroup->value.End(); ++itCol){
- Opt opt;
- auto itOptName = itCol->FindMember("optName");
- if (itOptName != itCol->MemberEnd() && itOptName->value.IsInt())
- opt.optName = std::to_string(itOptName->value.GetInt());
- auto t = pfGetPos(*itCol);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- _vctOpt.push_back(opt);
- }
- page.studentcode_fill.push_back(_vctOpt);
- }
- }
- }
- }
- }
- // 缺考标记
- auto itAbsent = itPage->FindMember("absent");
- if (itAbsent != itPage->MemberEnd() && itAbsent->value.IsObject()){
- auto t = pfGetPos(itAbsent->value);
- if (std::get<0>(t)){
- page.absent = std::get<1>(t);
- }
- }
- // 二维码
- auto itQrCode = itPage->FindMember("QrCode");
- if (itQrCode != itPage->MemberEnd() && itQrCode->value.IsObject()){
- auto t = pfGetPos(itQrCode->value);
- if (std::get<0>(t)){
- page.QrCode = std::get<1>(t);
- }
- }
- } // end if page.pageNo == 0
- // 长宽
- auto itImge = itPage->FindMember("imge");
- if (itImge != itPage->MemberEnd()){
- auto t = std::get<1>(pfGetPos(itImge->value));
- page.w = t.w;
- page.h = t.h;
- }
- else{
- return false;
- }
- // 题目
- auto itQuestion = itPage->FindMember("questions");
- if (itQuestion != itPage->MemberEnd() && itQuestion->value.IsArray()){
- for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
- question q;
- // 题目类型
- auto itType = it->FindMember("type");
- if (itType != it->MemberEnd() && itType->value.IsInt()){
- q.type = itType->value.GetInt();
- }
- else{
- return false;
- }
- q.marktype = 0;
- // 题目类型
- auto itMarktype = it->FindMember("marktype");
- if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
- q.marktype = itMarktype->value.GetInt();
- }
- // 分数
- auto itScore = it->FindMember("score");
- if (itScore != it->MemberEnd() && itScore->value.IsObject()){
- auto itFull = itScore->value.FindMember("full");
- if (itFull != itScore->value.MemberEnd() && (itFull->value.IsDouble() || itFull->value.IsInt()))
- q.score = itFull->value.GetDouble();
- }
- // 题目编号 2选做题
- auto itId = it->FindMember(q.type == 2 ? "editorId" : "id");
- if (itId != it->MemberEnd() && itId->value.IsString()){
- q.id = itId->value.GetString();
- }
- if (q.type == 2){
- auto itAllID = it->FindMember("id");
- if (itAllID != it->MemberEnd() && itAllID->value.IsString()){
- q.all_id = itAllID->value.GetString();
- }
- }
- // 目前应该只有填空题有这个参数
- auto itSmallQtNo = it->FindMember("smallQtNo");
- if (itSmallQtNo != it->MemberEnd() && !(itSmallQtNo->value.IsNull()))
- {
- q.smallQtNo = itSmallQtNo->value.GetInt();
- }
- else
- {
- q.smallQtNo = -1;
- }
- // 打分区域
- auto itScoreBox = it->FindMember("scorebox");
- if (itScoreBox != it->MemberEnd() && itScoreBox->value.IsObject()){
- // 打分框类型
- auto itType = itScoreBox->value.FindMember("type");
- if (itType != itScoreBox->value.MemberEnd() && itType->value.IsString()){
- q.scoreBox.type = std::stoi(itType->value.GetString());
- }
- else if (itType != itScoreBox->value.MemberEnd() && itType->value.IsInt()){
- q.scoreBox.type = itType->value.GetInt();
- }
- else{
- return false;
- }
- // 分数上限
- auto itLimit = itScoreBox->value.FindMember("limit");
- if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsString())
- q.scoreBox.limit = std::stoi(itLimit->value.GetString());
- // 最后一个格子是否为小数 1是 2否
- auto itPoint = itScoreBox->value.FindMember("point");
- if (itPoint != itScoreBox->value.MemberEnd()){
- if (itPoint->value.IsInt()){
- if (itPoint->value.GetInt() == 1 || itPoint->value.GetInt() == 2)
- q.scoreBox.bPoint = (itPoint->value.GetInt() == 1);
- }
- else if (itPoint->value.IsString()){
- std::string str = itPoint->value.GetString();
- if (str == "1" || str == "2")
- q.scoreBox.bPoint = (str == "1");
- }
- }
- // 填空题带打分
- if (q.scoreBox.type == 3){
- auto itScore = itScoreBox->value.FindMember("Score");
- if (itScore != itScoreBox->value.MemberEnd() && itScore->value.IsArray()){
- for (auto it = itScore->value.Begin(); it != itScore->value.End(); ++it){
- if (it->IsString()){
- std::string str = it->GetString();
- if (!str.empty())
- q.scoreBox.vctScore.push_back(std::stoi(str));
- }
- }
- }
- }
- // 打分位置
- auto t = pfGetPos(itScoreBox->value);
- if (std::get<0>(t))
- q.scoreBox.pos = std::get<1>(t);
- }
- // 剪裁区域
- if (q.type == 1 || q.type == 3){
- auto itCut = it->FindMember("cut");
- if (itCut != it->MemberEnd() && itCut->value.IsObject()){
- auto itLink = itCut->value.FindMember("linkparm");
- if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
- q.cut.linkparm = itLink->value.GetInt();
- auto t = pfGetPos(itCut->value);
- if (std::get<0>(t))
- q.cut.pos = std::get<1>(t);
- if (q.type == 3 && m_onlineCardTemplate->subject_id == 8)
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("config.ini"));
- int english = GetPrivateProfileInt(_T("USER"), _T("english_height"), 30, FilePath);//英语填空题高度加大比例
- if (english > 0 && english <= 30)
- {
- q.cut.pos.h = q.cut.pos.h* (1.0 + english / 100.0);
- }
- }
- }
- }
- else if (q.type == 2){ // 选做题
- rapidjson::Value::ConstMemberIterator itSel = it->FindMember("select");
- if (itSel != it->MemberEnd() && itSel->value.IsInt()){
- q.selItem = itSel->value.GetInt();
- }
- rapidjson::Value::ConstMemberIterator itTotal = it->FindMember("total");
- if (itTotal != it->MemberEnd() && itTotal->value.IsInt()){
- q.selTotal = itTotal->value.GetInt();
- }
- auto itSelectqts = it->FindMember("selectqts");
- if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
- rapidjson::Value::ConstMemberIterator itCut = itSelectqts->value.Begin()->FindMember("cut");
- if (itCut != itSelectqts->value.Begin()->MemberEnd() && itCut->value.IsObject()){
- rapidjson::Value::ConstMemberIterator itLink = itCut->value.FindMember("linkparm");
- if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
- q.cut.linkparm = itLink->value.GetInt();
- auto t = pfGetPos(itCut->value);
- if (std::get<0>(t))
- q.cut.pos = std::get<1>(t);
- }
- }
- if (q.cut.linkparm < 2){
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index++];
- }
- else
- {
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index - 1];
- }
- }
- // 选项 单选题 多选题
- if (q.type == 0 || q.type == 8 || q.type == 5){
- auto itOpts = it->FindMember("opt");
- if (itOpts != it->MemberEnd() && itOpts->value.IsArray()){
- int i = 0;
- for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt,++i){
- Opt opt;
- auto t = pfGetPos(*itOpt);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- auto itOptName = itOpt->FindMember("optName");
- if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
- opt.optName = itOptName->value.GetString();
- q.opt.push_back(opt);
- }
- }
- }
- else if (q.type == 2){ // 多选题
- auto itSelectqts = it->FindMember("selectqts");
- if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
- auto itOpts = itSelectqts->value.Begin()->FindMember("opt");
- if (itOpts != itSelectqts->value.Begin()->MemberEnd() && itOpts->value.IsArray()){
- q.selTotal = itOpts->value.Size();
- for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt){
- Opt opt;
- auto t = pfGetPos(*itOpt);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- auto itOptName = itOpt->FindMember("optName");
- if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
- opt.optName = itOptName->value.GetString();
- q.opt.push_back(opt);
- }
- }
- }
- }
- page.vctQuestions.push_back(q);
- }
- }
- m_onlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
- }
- }
- else{
- return false;
- }
- }
- else{
- // 总页数
- auto itTotalPage = doc.FindMember("totalPage");
- if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
- m_onlineCardTemplate->totalPage = itTotalPage->value.GetInt();
- }
- // 是否使用二维码
- auto itUseQrCode = doc.FindMember("useQrCode");
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
- m_onlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
- }
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
- m_onlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
- }
- // 学校状态
- auto itSchoolStatus = doc.FindMember("school_card_status");
- if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
- m_onlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
- }
- int n_duo_xuanti_index = 0;
- std::string temp_all_id = "";
- // 页
- auto itPages = doc.FindMember("pages");
- if (itPages != doc.MemberEnd() && itPages->value.IsArray()/* && itPages->value.Size() == m_onlineCardTemplate->totalPage*/){
- for (auto itPage = itPages->value.Begin(); itPage != itPages->value.End(); ++itPage){
- if (!itPage->IsObject()) return false;
- PageTemplate page;
- // 页号
- auto itPageNo = itPage->FindMember("pageNo");
- if (itPageNo != itPage->MemberEnd() && itPageNo->value.IsInt()){
- page.pageNo = itPageNo->value.GetInt();
- }
- else {
- return false;
- }
- // 定位点
- auto itLocations = itPage->FindMember("location");
- if (itLocations != itPage->MemberEnd() && itLocations->value.IsArray()){
- for (auto it = itLocations->value.Begin(); it != itLocations->value.End(); ++it){
- Location lc;
- auto itType = it->FindMember("type");
- if (itType != it->MemberEnd() && itType->value.IsInt()){
- lc.type = itType->value.GetInt();
- }
- auto tm = pfGetPos(*it);
- if (std::get<0>(tm)){
- lc.pos = std::get<1>(tm);
- }
- page.location.push_back(lc);
- }
- }
- if (page.pageNo == 1){
- if (!m_onlineCardTemplate->useQrCode){
- // 条形码
- auto itBar = itPage->FindMember("studentcode_bar");
- if (itBar != itPage->MemberEnd() && itBar->value.IsObject()){
- auto itObj = itBar->value.FindMember("object");
- if (itObj != itBar->value.MemberEnd() && itObj->value.IsObject()){
- auto t = pfGetPos(itObj->value);
- page.studentcode_bar = std::get<1>(t);
- }
- }
- // 填涂考号
- auto itFill = itPage->FindMember("studentcode_fill");
- if (itFill != itPage->MemberEnd() && itFill->value.IsObject()){
- auto itObj = itFill->value.FindMember("object");
- if (itObj != itFill->value.MemberEnd() && itObj->value.IsArray()){
- for (auto itRow = itObj->value.Begin(); itRow != itObj->value.End(); ++itRow){
- auto itGroup = itRow->FindMember("group");
- if (itGroup != itRow->MemberEnd() && itGroup->value.IsArray()){
- std::vector<Opt> _vctOpt;
- for (auto itCol = itGroup->value.Begin(); itCol != itGroup->value.End(); ++itCol){
- Opt opt;
- auto itOptName = itCol->FindMember("optName");
- if (itOptName != itCol->MemberEnd() && itOptName->value.IsInt())
- opt.optName = std::to_string(itOptName->value.GetInt());
- auto t = pfGetPos(*itCol);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- _vctOpt.push_back(opt);
- }
- page.studentcode_fill.push_back(_vctOpt);
- }
- }
- }
- }
- }
- // 缺考标记
- auto itAbsent = itPage->FindMember("absent");
- if (itAbsent != itPage->MemberEnd() && itAbsent->value.IsObject()){
- auto t = pfGetPos(itAbsent->value);
- if (std::get<0>(t)){
- page.absent = std::get<1>(t);
- }
- }
- // 二维码
- auto itQrCode = itPage->FindMember("QrCode");
- if (itQrCode != itPage->MemberEnd() && itQrCode->value.IsObject()){
- auto t = pfGetPos(itQrCode->value);
- if (std::get<0>(t)){
- page.QrCode = std::get<1>(t);
- }
- }
- } // end if page.pageNo == 0
- // 长宽
- auto itImge = itPage->FindMember("imge");
- if (itImge != itPage->MemberEnd()){
- auto t = std::get<1>(pfGetPos(itImge->value));
- page.w = t.w;
- page.h = t.h;
- }
- else{
- return false;
- }
- // 题目
- auto itQuestion = itPage->FindMember("questions");
- if (itQuestion != itPage->MemberEnd() && itQuestion->value.IsArray()){
- for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
- question q;
- // 题目类型
- auto itType = it->FindMember("type");
- if (itType != it->MemberEnd() && itType->value.IsInt()){
- q.type = itType->value.GetInt();
- }
- else{
- return false;
- }
- q.marktype = 0;
- // 题目类型
- auto itMarktype = it->FindMember("marktype");
- if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
- q.marktype = itMarktype->value.GetInt();
- }
- // 分数
- auto itScore = it->FindMember("score");
- if (itScore != it->MemberEnd() && itScore->value.IsObject()){
- auto itFull = itScore->value.FindMember("full");
- if (itFull != itScore->value.MemberEnd() && (itFull->value.IsDouble() || itFull->value.IsInt()))
- q.score = itFull->value.GetDouble();
- }
- // 题目编号 2选做题
- auto itId = it->FindMember((q.type == 2 || q.type == 4 )? "editorId" : "id");
- if (itId != it->MemberEnd() && itId->value.IsString()){
- q.id = itId->value.GetString();
- }
- if (itId != it->MemberEnd() && itId->value.IsInt()){
- q.id = std::to_string(itId->value.GetInt());
- }
- if (q.type == 2 || q.type == 4){
- auto itAllID = it->FindMember("id");
- if (itAllID != it->MemberEnd() && itAllID->value.IsString()){
- q.all_id = itAllID->value.GetString();
- }
- }
- auto itSmallQtNo = it->FindMember("smallQtNo");
- if (itSmallQtNo != it->MemberEnd() && !(itSmallQtNo->value.IsNull()))
- {
- q.smallQtNo = itSmallQtNo->value.GetInt();
- }
- else
- {
- q.smallQtNo = -1;
- }
- auto itNickID = it->FindMember("name");
- if (itNickID != it->MemberEnd() && !(itNickID->value.IsNull()) && itNickID->value.IsInt())
- {
- m_mapKeguantiNickName[q.id] = std::to_string(itNickID->value.GetInt());
- }
- // 打分区域
- auto itScoreBox = it->FindMember("scorebox");
- if (itScoreBox != it->MemberEnd() && itScoreBox->value.IsObject()){
- // 打分框类型
- auto itType = itScoreBox->value.FindMember("type");
- if (itType != itScoreBox->value.MemberEnd() && itType->value.IsString()){
- q.scoreBox.type = std::stoi(itType->value.GetString());
- }
- else if (itType != itScoreBox->value.MemberEnd() && itType->value.IsInt()){
- q.scoreBox.type = itType->value.GetInt();
- }
- else{
- return false;
- }
- if (q.smallQtNo != -1)
- {
- // 小问最大分值
- auto itmaxScore = itScoreBox->value.FindMember("maxscore");
- if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsString()){
- q.scoreBox.maxsorce = std::stod(itmaxScore->value.GetString());
- }
- else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsDouble()){
- q.scoreBox.maxsorce = itScoreBox->value.GetDouble();
- }
- else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsInt()){
- q.scoreBox.maxsorce = itmaxScore->value.GetInt();
- }
- else{
- q.scoreBox.maxsorce = 0.0;
- }
- }
- else
- {
- q.scoreBox.maxsorce = 0.0;
- }
-
- // 分数上限
- auto itLimit = itScoreBox->value.FindMember("limit");
- if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsString())
- q.scoreBox.limit = std::stoi(itLimit->value.GetString());
- if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsInt())
- q.scoreBox.limit = itLimit->value.GetInt();
- // 最后一个格子是否为小数 1是 2否
- auto itPoint = itScoreBox->value.FindMember("point");
- if (itPoint != itScoreBox->value.MemberEnd()){
- if (itPoint->value.IsInt()){
- q.scoreBox.bPoint = (itPoint->value.GetInt() == 1);
- }
- else if (itPoint->value.IsString()){
- std::string str = itPoint->value.GetString();
- q.scoreBox.bPoint = (str == "1");
- }
- }
- // 填空题带打分
- if (q.scoreBox.type == 3){
- auto itScore = itScoreBox->value.FindMember("Score");
- if (itScore != itScoreBox->value.MemberEnd() && itScore->value.IsArray()){
- for (auto it = itScore->value.Begin(); it != itScore->value.End(); ++it){
- if (it->IsString()){
- std::string str = it->GetString();
- if (!str.empty())
- q.scoreBox.vctScore.push_back(std::stoi(str));
- }
- }
- }
- }
- // 打分位置
- auto t = pfGetPos(itScoreBox->value);
- if (std::get<0>(t))
- q.scoreBox.pos = std::get<1>(t);
- }
- // 几选几
- if (q.type == 2 || q.type == 4){ // 选做题
- rapidjson::Value::ConstMemberIterator itSel = it->FindMember("select");
- if (itSel != it->MemberEnd() && itSel->value.IsInt()){
- q.selItem = itSel->value.GetInt();
- }
- rapidjson::Value::ConstMemberIterator itTotal = it->FindMember("total");
- if (itTotal != it->MemberEnd() && itTotal->value.IsInt()){
- q.selTotal = itTotal->value.GetInt();
- }
- }
- // 剪裁区域
- if (q.type == 1 || q.type == 3 || q.type == 2 || q.type == 4){ // 1 解答题 2 选做题 3 填空题
- auto itCut = it->FindMember("cut");
- if (itCut != it->MemberEnd() && itCut->value.IsObject()){
- auto itLink = itCut->value.FindMember("linkparm");
- if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
- q.cut.linkparm = itLink->value.GetInt();
- if (itLink != itCut->value.MemberEnd() && itLink->value.IsString())
- q.cut.linkparm = std::stoi(itLink->value.GetString());
- auto t = pfGetPos(itCut->value);
- if (std::get<0>(t))
- q.cut.pos = std::get<1>(t);
- if (q.type == 3 && m_onlineCardTemplate->subject_id==8)
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("config.ini"));
- int english = GetPrivateProfileInt(_T("USER"), _T("english_height"), 30, FilePath);//英语填空题高度加大比例
- if (english > 0 && english <= 30)
- {
- q.cut.pos.h = q.cut.pos.h* (1.0 + english / 100.0);
- }
- }
- }
- if (q.type == 2){
- if (temp_all_id != q.all_id)
- {
- temp_all_id = q.all_id;
- n_duo_xuanti_index = 0;
- }
- if (q.cut.linkparm < 2){
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index++];
- }
- else
- {
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index - 1];
- }
- }
- else if (q.type == 4)
- {
- if (temp_all_id != q.all_id)
- {
- temp_all_id = q.all_id;
- n_duo_xuanti_index = 0;
- }
- if (q.cut.linkparm < 1){
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index++];
- }
- else
- {
- std::vector<std::string> split_qr;
- split(q.all_id, (std::string)",", &split_qr);
- if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
- q.id = split_qr[n_duo_xuanti_index - 1];
- }
- }
- }
- // 选项 单选题 多选题
- if (q.type == 0 || q.type == 8 || q.type == 5){
- auto itOpts = it->FindMember("opt");
- if (itOpts != it->MemberEnd() && itOpts->value.IsArray()){
- for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt){
- Opt opt;
- auto t = pfGetPos(*itOpt);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- auto itOptName = itOpt->FindMember("optName");
- if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
- opt.optName = itOptName->value.GetString();
- q.opt.push_back(opt);
- }
- }
- }
- else if (q.type == 2 || q.type == 4){ // 多选题
- auto itSelectqts = it->FindMember("selectqts");
- if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
- for (auto itOpt = itSelectqts->value.Begin(); itOpt != itSelectqts->value.End(); ++itOpt){
- Opt opt;
- auto t = pfGetPos(*itOpt);
- if (std::get<0>(t))
- opt.pos = std::get<1>(t);
- auto itOptName = itOpt->FindMember("optName");
- if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
- opt.optName = itOptName->value.GetString();
- q.opt.push_back(opt);
- }
- }
- }
- page.vctQuestions.push_back(q);
- }
- }
- m_onlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
- }
- }
- else{
- return false;
- }
- }
- m_onlineCardTemplate->open_save_debug_img = false;
- m_onlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
- m_onlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
- m_onlineCardTemplate->dingweidian_w_max_rate = 1.0;
- m_onlineCardTemplate->dingweidian_h_max_rate = 1.0;
- m_onlineCardTemplate->dingweidian_w_min_rate = 0.7;
- m_onlineCardTemplate->dingweidian_h_min_rate = 0.7;
- CString _ini_file = GetExePath() + _T("\\config.ini");
- TCHAR sz_offset_file_name[MAX_PATH] = { 0 };
- GetPrivateProfileString(_T("USER"), _T("offset_file"), _T(""), sz_offset_file_name, sizeof(sz_offset_file_name) / sizeof(TCHAR), _ini_file);
- ParseTemplateOffset(UnicodeToAnsi(GetExePath() + _T("\\") + sz_offset_file_name), m_onlineCardTemplate);
- return true;
- }
- int CBatchService::loadDuXueFirstMode()
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- TCHAR FileName[50];
- _stprintf(FileName, _T("\\mode\\student1.schema"));
- lstrcat(FilePath, FileName);
- CT2CA pszConvertedAnsiString(FilePath);
- std::string schemaPath(pszConvertedAnsiString);
- CSchemaLoader schemaLoader;
- int ret = schemaLoader.Load(schemaPath, m_muban_img_dir, m_schema0, m_schema, m_handleInfo);
- return ret;
- }
- //停止扫描处理函数
- ServiceState CBatchService::OnStoping(void)
- {
- mainService->Stop();
- while (mainService->GetServiceSate()!=stoped)
- {
- Sleep(10);
- }
- if (g_my_scan_type == 1&&g_myindex < MAX_STRUENTS_NUM)
- {
-
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- TCHAR FileName[50];
- _stprintf(FileName, _T("\\mode\\student%d.schema"), g_myindex+1);
- lstrcat(FilePath, FileName);
- CT2CA pszConvertedAnsiString(FilePath);
- std::string schemaPath(pszConvertedAnsiString);
- CSchemaLoader schemaLoader;
- int ret = schemaLoader.Load(schemaPath, m_muban_img_dir, m_schema0, m_schema, m_handleInfo);
- g_myindex++;
- ServiceState nextState = OnStarting();
- return nextState;
- }
- char sql[128];
- sprintf_s(sql, "update database set database_state =%d where database_id =%d", DATABASE_STATE_SCAN_OVER, m_database_id);
- EnterCriticalSection(database_db_lock);
- database_db->execDML("begin transaction");
- database_db->execDML(sql);
- database_db->execDML("commit transaction");
- LeaveCriticalSection(database_db_lock);
- if (m_hwnd != NULL&&m_abnormal_stop == FALSE)
- {
- ::PostMessage(m_hwnd, WM_IDENTIFOR_COMPLETE, 0, 0);
- }
- ServiceState nextState = IService::OnStoping();
- if (nextState == stoped&&m_hwnd != NULL)
- {
- ::PostMessage(m_hwnd, WM_IDENTIFOR_STOPED, 0, 0);
- }
- return nextState;
- }
- #include <io.h>
- #include <stdio.h>
- #include <stdlib.h>
- //设置消息接收窗口
- int CBatchService::SetHandlerWnd(HWND hwnd)
- {
- m_hwnd = hwnd;
- if (mainService.get()){
- mainService->SetHandlerWnd(hwnd);
- }
- return TRUE;
- }
- //检测服务是是否可以访问
- bool testServerAvaiable2(const CString& serverAdd){
- std::string response;
- CHttpClient httpClient;
- CString url;
- url.Format(_T("%s/course/findAllCourse"), serverAdd);
- httpClient.HttpGet(url, NULL, response);
- Json::Value root;
- Json::Reader(Json::Features()).parse(response, root);
- if (root["success"].isInt() && root["success"].asInt() == 1){
- return true;
- }
- return false;
- }
- /*
- 准备扫描
- 1、检测本地服务器状态
- 2、创建当前批次目录
- 3、创建当前批次数据库
- 4、创建主要服务
- */
- int CBatchService::ReadyScan(FEEDER_TYPE feederType, const ScanParam & param)
- {
- m_examId = param.examId;
- m_examCourseId = param.examCourseId;
- m_examName = param.examName;
- m_courseName = param.courseName;
- // Log4cplusInitalizer::initalize();
- std::string response;
- CHttpClient httpClient;
- CString url;
- url.Format(_T("%s/exam/getServerUrl?examId=%I64d"), CServerConfig::server_url, param.examId);
- // AfxMessageBox(url);
- #if 0
- httpClient.HttpGet(url, NULL, response);
- AfxMessageBox(L"CBatchService::HttpGet after!");
- Json::Value root;
- AfxMessageBox(L"CBatchService::ReadyScan");
- Json::Reader(Json::Features()).parse(response, root);
- AfxMessageBox(L"CBatchService::Json::Reader");
- if (root["success"].isInt() && root["success"].asInt() == 1){
- CServerConfig::server_address_type = SAT_REMOTE;
- Json::Value object = root["object"];
- //标记本地服务器是否是不可用状态
- bool isLocalServerUnavailable = false;
- if (object["url"].isString() && object["url"].asCString() != (string)""){
- CServerConfig::server_url_local_in = object["url"].asCString();
- if (!testServerAvaiable2(CServerConfig::server_url_local_in)){
- isLocalServerUnavailable = true;
- }
- CServerConfig::server_address_type = SAT_LOCAL_IN;
- }
- if (isLocalServerUnavailable&&object["outurl"].isString() && object["outurl"].asCString() != (string)""){
- CServerConfig::server_url_local_out = object["outurl"].asCString();
- if (testServerAvaiable2(CServerConfig::server_url_local_out)){
- isLocalServerUnavailable = false;
- }
- else {
- isLocalServerUnavailable = true;
- }
- CServerConfig::server_address_type = SAT_LOCAL_OUT;
- }
- //本地服务器不可用,返回错误
- if (isLocalServerUnavailable)return 2;
- }
- #endif
- m_feeder_type = feederType;
- CString moule_dir =CServerConfig::scan_data_dir;
- m_bantch_code = GetTimeString();
- CString tempExamId;
- tempExamId.Format(_T("%llu"), param.examId);
- if (g_my_scan_type == 1)
- {
- m_bantch_dir = moule_dir + _T("\\duxueka") + tempExamId;
- }
- else
- {
- m_bantch_dir = moule_dir + _T("\\datika") + tempExamId;
- }
- m_norimg_dir = m_bantch_dir + _T("\\nor_imgs");
- m_excimg_dir = m_bantch_dir + _T("\\") + m_bantch_code + _T("\\exc_imgs");
- m_img_down_load_dir = m_bantch_dir + _T("\\img_down_load");
- m_muban_img_dir = CT2A(m_bantch_dir + _T("\\muban_imgs"));
- m_img_clips_dir = m_bantch_dir + _T("\\clips");
- m_img_alynasis_dir = m_bantch_dir + _T("\\alynasis");
- m_img_alynasis_result_dir = m_bantch_dir + _T("\\alynasis_result");
- CreateDirectory(m_bantch_dir, NULL);
- CreateDirectory(m_norimg_dir, NULL);
- CreateDirectory(m_bantch_dir + _T("\\") + m_bantch_code, NULL);
- CreateDirectory(m_excimg_dir, NULL);
- CreateDirectory(m_img_clips_dir, NULL);
- CreateDirectory(CA2T(m_muban_img_dir.c_str()), NULL);
- CreateDirectory(m_img_down_load_dir, NULL);
- CreateDirectory(m_img_alynasis_dir, NULL);
- CreateDirectory(m_img_alynasis_result_dir, NULL);
- CString path = m_bantch_dir + _T("\\result.db3");
- CString uploadPath = m_excimg_dir + _T("\\upload.db3");
- char db_file_name[520];
- char db_file_name1[520];
- char db_upload_file_name[520];
- char db_upload_file_name1[520];
- WideCharToMultiByte(CP_UTF8, 0, path, -1, db_file_name, 520, NULL, NULL);
- WideCharToMultiByte(CP_ACP, 0, path, -1, db_file_name1, 520, NULL, NULL);
- WideCharToMultiByte(CP_UTF8, 0, uploadPath, -1, db_upload_file_name, 520, NULL, NULL);
- WideCharToMultiByte(CP_ACP, 0, uploadPath, -1, db_upload_file_name1, 520, NULL, NULL);
- g_strUpLoadDbPathName = db_upload_file_name;
- if (_access(db_file_name1, 0) == -1)
- {
- // 不存在首次拷贝
- CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_RESULT, path);
- }
- if (_access(db_upload_file_name1, 0) == -1)
- {
- CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_UPLOAD, uploadPath);
- }
- EnterCriticalSection(database_db_lock);
- database_db->execDML("begin transaction");
- 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 )";
- CppSQLite3Statement stmt = database_db->compileStatement(sql);
- CT2A szbantch_code(m_bantch_code);
- CT2A szbantch_dir(m_bantch_dir);
- 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);
- stmt.bind(":database_state", DATABASE_STATE_CREATE);
- stmt.bind(":create_time", szbantch_code);
- stmt.bind(":db_file_name", db_file_name);
- stmt.bind(":bantch_code", szbantch_code);
- stmt.bind(":bantch_dir", szbantch_dir);
- stmt.bind(":server_address", server_address);
- switch (feederType&FEEDER_TYPE_MASK){
- case Folder:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
- case Scanner:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
- case AdjustBatch:
- stmt.bind(":exam_id", param.examId);
- stmt.bind(":exam_course_id", param.examCourseId);
- stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_BATCH);
- stmt.bind(":exam_course_id_from", param.examCourseIdOld);
- stmt.bind(":batch_code_from", param.batch.c_str());
- break;
- case AdjustExaminne:
- stmt.bind(":exam_id", param.examId);
- stmt.bind(":exam_course_id", param.examCourseId);
- stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_EXAMINNE);
- stmt.bind(":exam_course_id_from", param.examCourseIdOld);
- stmt.bind(":batch_code_from", param.batch.c_str());
- stmt.bind(":examinne_id_from", param.examinneid.c_str());
- break;
- }
- stmt.bind(":exam_name", param.examName.c_str());
- stmt.bind(":course_name", param.courseName.c_str());
- stmt.execDML();
- CppSQLite3Query query = database_db->execQuery("select last_insert_rowId() from DATABASE");
- m_database_id = query.getIntField(0);
- database_db->execDML("commit transaction");
- LeaveCriticalSection(database_db_lock);
- strncpy(m_db_file_name, db_file_name, 520);
- bantch_db.open(db_file_name);
- bantch_db.execDML("pragma journal_mode = MEMORY");
- if (g_my_continue_scan != 1)
- {
- //情况没有上传的
- vector<int> listpaper_id;
- char sql1[512];
- sprintf_s(sql1, "select student_paper_id from student_paper where ret_upload = 0 OR paper_state !=0 OR Is_Covered=1");
- EnterCriticalSection(&bantch_db_lock);
- CppSQLite3Query q = bantch_db.execQuery(sql1);
- std::string _param;
- while (!q.eof()){
- int student_paper_id = q.getIntField("student_paper_id");
- _param += std::to_string(student_paper_id) + ",";
- listpaper_id.push_back(q.getIntField("student_paper_id"));
- q.nextRow();
- }
- if (!_param.empty()){
- _param = std::string(_param, 0, _param.size() - 1);
- if (m_upload_manager.IsEanble())
- m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, _param.c_str());
- std::string str1 = std::string("") + "delete from exception where student_paper_id in(" + _param + ")";
- 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 + "))";
- std::string str3 = std::string("") + "delete from page where student_paper_id in(" + _param + ")";
- std::string str4 = std::string("") + "delete from student_paper where student_paper_id in(" + _param + ")";
- bantch_db.execDML(str1.c_str());
- bantch_db.execDML(str2.c_str());
- bantch_db.execDML(str3.c_str());
- bantch_db.execDML(str4.c_str());
- bantch_db.execDML("delete from message");
- }
- // while (!q.eof()){
- // int student_paper_id = q.getIntField("student_paper_id");
- // listpaper_id.push_back(q.getIntField("student_paper_id"));
- // q.nextRow();
- // }
- // for (int i = 0; i < listpaper_id.size(); i++)
- // {
- // char sql1[512];
- // char sql2[512];
- // char sql3[512];
- // char sql4[512];
- // sprintf_s(sql1, "delete from exception where student_paper_id =%d ", listpaper_id[i]);
- // 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]);
- // sprintf_s(sql3, "delete from page where student_paper_id =%d", listpaper_id[i]);
- // sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", listpaper_id[i]);
- // bantch_db.execDML(sql1);
- // bantch_db.execDML(sql2);
- // bantch_db.execDML(sql3);
- // bantch_db.execDML(sql4);
- // bantch_db.execDML("delete from message");
- // m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, std::to_string(listpaper_id[i]).c_str());
- // }
- LeaveCriticalSection(&bantch_db_lock);
- }
- m_result_uploader->EnableOnLineCard(m_bOnlineCard, m_nSubjectID, m_nOnlineScanType);
- if (m_bOnlineCard){
- mainService.reset(new OnLineCard::COnlineCardIdentifyService(this));
- mainService->m_nOnlineScanType = m_nOnlineScanType;
- }else{
- mainService.reset(new CIdentifyService(this));
- }
- mainService->InitService();
- mainService->SetBianShiBieBianShangChuan(m_upload_manager.IsEanble());
- if (m_bOnlineCard){
- static_cast<OnLineCard::COnlineCardIdentifyService*>(mainService.get())->SetQr(-1,false, std::to_string(m_examId));
- static_cast<OnLineCard::COnlineCardIdentifyService*>(mainService.get())->SetTemplate(m_onlineCardTemplate);
- }
- mainService->SerErrorHandle(m_bErrorHandle);
- mainService->setMainService(true);
- 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);
- mainService->SetDataBase(&bantch_db_lock, &bantch_db);
- mainService->ReadScan(feederType, param);
- m_scoreCounter.SetDataBase(&bantch_db_lock, &bantch_db);
-
- if (m_hwnd != NULL) ::PostMessage(m_hwnd, WM_IDENTIFOR_READY, 0, 0);
- return TRUE;
- }
- void DeleteDirectory(CString source);
- int CBatchService::PreErrorHandleRestoreSite(bool bcontinue, int scan_type, FEEDER_TYPE feederType, const ScanParam & param)
- {
- g_my_scan_type = scan_type;
- m_examId = param.examId;
- m_examCourseId = 0;
- m_examName = "";
- m_courseName = "";
- std::string response;
- CString moule_dir = CServerConfig::scan_data_dir;
- m_bantch_code = GetTimeString();
- CString tempExamId;
- tempExamId.Format(_T("%llu"), m_examId);
- if (g_my_scan_type == 1)
- {
- m_bantch_dir = moule_dir + _T("\\duxueka_errorhandle") + m_bantch_code + tempExamId;
- }
- else
- {
- m_bantch_dir = moule_dir + _T("\\datika_errorhandle") + m_bantch_code + tempExamId;
- }
- m_norimg_dir = m_bantch_dir + _T("\\nor_imgs");
- m_excimg_dir = m_bantch_dir + _T("\\") + m_bantch_code + _T("\\exc_imgs");
- m_img_down_load_dir = m_bantch_dir + _T("\\img_down_load");
- m_muban_img_dir = CT2A(m_bantch_dir + _T("\\muban_imgs"));
- m_img_clips_dir = m_bantch_dir + _T("\\clips");
- m_img_alynasis_dir = m_bantch_dir + _T("\\alynasis");
- m_img_alynasis_result_dir = m_bantch_dir + _T("\\alynasis_result");
- //DeleteDirectory(m_bantch_dir);
- CreateDirectory(m_bantch_dir, NULL);
- CreateDirectory(m_norimg_dir, NULL);
- CreateDirectory(m_bantch_dir + _T("\\") + m_bantch_code, NULL);
- CreateDirectory(m_excimg_dir, NULL);
- CreateDirectory(m_img_clips_dir, NULL);
- CreateDirectory(CA2T(m_muban_img_dir.c_str()), NULL);
- CreateDirectory(m_img_down_load_dir, NULL);
- CreateDirectory(m_img_alynasis_dir, NULL);
- CreateDirectory(m_img_alynasis_result_dir, NULL);
- CString path = m_bantch_dir + _T("\\result.db3");
- CString uploadPath = m_excimg_dir + _T("\\upload.db3");
- char db_file_name[520];
- char db_file_name1[520];
- char db_upload_file_name[520];
- char db_upload_file_name1[520];
- WideCharToMultiByte(CP_UTF8, 0, path, -1, db_file_name, 520, NULL, NULL);
- WideCharToMultiByte(CP_ACP, 0, path, -1, db_file_name1, 520, NULL, NULL);
- WideCharToMultiByte(CP_UTF8, 0, uploadPath, -1, db_upload_file_name, 520, NULL, NULL);
- WideCharToMultiByte(CP_ACP, 0, uploadPath, -1, db_upload_file_name1, 520, NULL, NULL);
- g_strUpLoadDbPathName = db_upload_file_name;
- if (_access(db_file_name1, 0) == -1)
- {
- // 不存在首次拷贝
- CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_RESULT, path);
- }
- if (_access(db_upload_file_name1, 0) == -1)
- {
- CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_UPLOAD, uploadPath);
- }
- EnterCriticalSection(database_db_lock);
- database_db->execDML("begin transaction");
- 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 )";
- CppSQLite3Statement stmt = database_db->compileStatement(sql);
- CT2A szbantch_code(m_bantch_code);
- CT2A szbantch_dir(m_bantch_dir);
- 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);
- stmt.bind(":database_state", DATABASE_STATE_CREATE);
- stmt.bind(":create_time", szbantch_code);
- stmt.bind(":db_file_name", db_file_name);
- stmt.bind(":bantch_code", szbantch_code);
- stmt.bind(":bantch_dir", szbantch_dir);
- stmt.bind(":server_address", server_address);
- switch (feederType&FEEDER_TYPE_MASK){
- case Folder:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
- case Scanner:stmt.bind(":scan_type", SCAN_TASK_TYPE_NORMAL); break;
- case AdjustBatch:
- stmt.bind(":exam_id", param.examId);
- stmt.bind(":exam_course_id", param.examCourseId);
- stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_BATCH);
- stmt.bind(":exam_course_id_from", param.examCourseIdOld);
- stmt.bind(":batch_code_from", param.batch.c_str());
- break;
- case AdjustExaminne:
- stmt.bind(":exam_id", param.examId);
- stmt.bind(":exam_course_id", param.examCourseId);
- stmt.bind(":scan_type", SCAN_TASK_TYPE_ADJUST_EXAMINNE);
- stmt.bind(":exam_course_id_from", param.examCourseIdOld);
- stmt.bind(":batch_code_from", param.batch.c_str());
- stmt.bind(":examinne_id_from", param.examinneid.c_str());
- break;
- }
- stmt.bind(":exam_name", param.examName.c_str());
- stmt.bind(":course_name", param.courseName.c_str());
- stmt.execDML();
- CppSQLite3Query query = database_db->execQuery("select last_insert_rowId() from DATABASE");
- m_database_id = query.getIntField(0);
- database_db->execDML("commit transaction");
- LeaveCriticalSection(database_db_lock);
- strncpy(m_db_file_name, db_file_name, 520);
- bantch_db.open(db_file_name);
- bantch_db.execDML("pragma journal_mode = MEMORY");
- return 0;
- }
- //查询异常试卷
- int CBatchService::QueryExceptionPaper(const long exception_type, vector<STUDENT_INFO>& studentList)
- {
- EnterCriticalSection(&bantch_db_lock);
- char sql[512];
- 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);
- CppSQLite3Query q = bantch_db.execQuery(sql);
- while (!q.eof()){
- STUDENT_INFO si;
- char class_name[64];
- sprintf_s(class_name, "%s(%s)班", q.getStringField("grade_name"), q.getStringField("class_name"));
- si.class_name = class_name;
- si.student_id = q.getInt64Field("student_id");
- si.student_name = q.getStringField("student_name");
- si.student_code = q.getStringField("student_code");
- si.class_id = q.getInt64Field("class_id");
- si.score = (float)q.getFloatField("score_total", -1);
- si.paper_id = q.getIntField("student_paper_id", -1);
- si.location_id = q.getIntField("location_id", -1);
- studentList.push_back(si);
- q.nextRow();
- }
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- //查询试卷详情,包括异常信息,试卷图像信息,试卷题目信息
- int CBatchService::QueryPaperDetail(const int paper_id, PAPER_DETAIL &paper_detail, vector<PAGE_DETAIL> &pageList, vector<GROUP_QUESTION> &questionList)
- {
- EnterCriticalSection(&bantch_db_lock);
- char sql[512];
- 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);
- CppSQLite3Query q = bantch_db.execQuery(sql);
- if (!q.eof())
- {
- if (m_onlineCardTemplate->useQrCode && m_onlineCardTemplate->schoolCardStatus == 1)//使用二维码 且使用学校准考证
- {
- strcpy_s(paper_detail.examnumber, q.getStringField("schoolStudentCard"));
- }
- else
- {
- strcpy_s(paper_detail.examnumber, q.getStringField("student_code"));
- }
-
- paper_detail.exceptionsFlag = q.getInt64Field("paper_state");
- strcpy_s(paper_detail.student_name, q.getStringField("student_name"));
- paper_detail.score = q.getFloatField("score_total");
- strcpy_s(paper_detail.student_id, q.getStringField("student_id"));
- strcpy_s(paper_detail.class_name, q.getStringField("class_name"));
- paper_detail.fullScore = q.getFloatField("full_score");
- paper_detail.fullScoreObjective = q.getFloatField("full_score_objective");
- paper_detail.location_id = q.getInt64Field("location_id");
- paper_detail.has_covered = (BatchServiceCmd(BATCH_SRV_CMD::BS_CMD_IS_HAS_COVERD, (void*)&paper_id, NULL)>0);
- }
- else{
- strcpy_s(paper_detail.examnumber, "");
- paper_detail.exceptionsFlag = 0;
- strcpy_s(paper_detail.student_name, "");
- paper_detail.score = 0;
- strcpy_s(paper_detail.student_id, "");
- paper_detail.fullScore = 0;
- paper_detail.fullScoreObjective = 0;
- paper_detail.location_id = 0;
- LeaveCriticalSection(&bantch_db_lock);
- return FALSE;
- }
- std::map<int, PAGE_DETAIL> mm;
- //页码信息
- 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);
- q = bantch_db.execQuery(sql);
- while (!q.eof()){
- PAGE_DETAIL pd;
- pd.page_id = q.getIntField("page_id");
- pd.page_index = q.getIntField("page_index");
- pd.img_path = q.getStringField("img_path");
- pd.img_oldpath=q.getStringField("img_oldpath");
- pd.phy_number = atoi(q.getStringField("phy_number"));
- pd.exceptions.clear();
- mm[pd.page_id] = pd;
- q.nextRow();
- }
- std::map<std::string, QUESTION_INFO> mm2;
- std::vector<QUESTION_INFO*> quesitons;
- // 题目标准
- 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");
- q = bantch_db.execQuery(sql);
- while (!q.eof()){
- QUESTION_INFO qi;
- qi.answer_std = q.getStringField("answer_std");
- qi.answer_stu = "";
- qi.is_mutil = q.getIntField("multi_answer");
- qi.option_count = q.getIntField("option_count");
- qi.question_code = q.getStringField("question_code");
- //qi.question_id =-1;
- qi.question_type = (QUESTION_TYPE)q.getIntField("question_type");
- qi.score_full = q.getFloatField("score_full");
- qi.score_half = q.getFloatField("score_half");
- qi.score_stu = 0;
- mm2[qi.question_code] = qi;
- quesitons.push_back(&mm2[qi.question_code]);
- q.nextRow();
- }
- 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);
- if (bantch_db.execScalar(sql) <= 0){//不存在定位点异常时,查询分数
- // 题目得分信息
- 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);
- q = bantch_db.execQuery(sql);
- while (!q.eof()){
- string question_code = q.getStringField("question_code");
- mm2[question_code].question_state = (QUESTION_STATE)q.getIntField("question_state");
- mm2[question_code].score_stu = (mm2[question_code].question_state == QUESTION_STATE_NORMAL) ? q.getFloatField("score") : q.getFloatField("score_paper");
- mm2[question_code].answer_stu = q.getStringField("answer");
- q.nextRow();
- }
- }
- //页面异常信息
- 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);
- q = bantch_db.execQuery(sql);
- while (!q.eof()){
- int page_id = q.getIntField("page_id");
- EXCEPTION_INFO ei;
- ei.exception_id = q.getIntField("exception_id");
- ei.type = (EXCEPTION_TYPE)q.getInt64Field("exception_type");
- ei.x = 0;
- ei.y = 0;
- ei.w = 0;
- ei.h = 0;
- mm[page_id].exceptions.push_back(ei);
- q.nextRow();
- }
- //试卷异常信息
- paper_detail.paper_id = paper_id;
- paper_detail.exceptions.clear();
- 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);
- q = bantch_db.execQuery(sql);
- while (!q.eof()){
- EXCEPTION_INFO ei;
- ei.exception_id = q.getIntField("exception_id");
- ei.type = (EXCEPTION_TYPE)q.getInt64Field("exception_type");
- ei.x = 0;
- ei.y = 0;
- ei.w = 0;
- ei.h = 0;
- paper_detail.exceptions.push_back(ei);
- q.nextRow();
- }
- for (map<int, PAGE_DETAIL>::iterator it = mm.begin(); it != mm.end(); it++)
- {
- pageList.push_back(it->second);
- }
- LeaveCriticalSection(&bantch_db_lock);
- memset(paper_detail.sz_upload_error_msg, 0, sizeof(paper_detail.sz_upload_error_msg));
- if (m_upload_manager.IsEanble()){
- paper_detail.paper_upload_state = m_upload_manager.GetPaperUploadState(paper_detail.paper_id,paper_detail.sz_upload_error_msg,512);
- bool isexception = 0 != (paper_detail.exceptionsFlag&(~EX_KAOHAODAIPIPEI));
- if (isexception && paper_detail.paper_upload_state==0){
- paper_detail.paper_upload_state = 4;
- }
- }
- return TRUE;
- }
- //重新识别
- int CBatchService::ReIdentify(const int paper_id, const std::string& student_code, const std::vector<img_param>& params)
- {
- CppSQLite3Statement statm = bantch_db.compileStatement("update student_paper set paper_state =:paper_state where student_paper_id=:student_paper_id");
- statm.bind(":paper_state", EX_SHIJUANCHONGXINSHIBIEZHONG);
- statm.bind(":student_paper_id", paper_id);
- statm.execDML();
- m_result_uploader->EnableOnLineCard(m_bOnlineCard, m_nSubjectID, m_nOnlineScanType);
- boost::shared_ptr<CIdentifyService> subService_;
- if (m_bOnlineCard){
- subService_ = boost::make_shared<OnLineCard::COnlineCardIdentifyService>(this);
- }
- else{
- subService_ = boost::make_shared<CIdentifyService>(this);
- }
- subService_->m_nOnlineScanType = m_nOnlineScanType;
- subService_->InitService();
- subService_->SerErrorHandle(m_bErrorHandle);
- subService_->SetBianShiBieBianShangChuan(m_upload_manager.IsEanble());
- std::string qr;
- if (m_bOnlineCard){
- static_cast<OnLineCard::COnlineCardIdentifyService*>(subService_.get())->SetTemplate(m_onlineCardTemplate);
- qr = std::to_string(m_examId) + "," + std::to_string(paper_id) + (student_code.empty() ? "" : ("," + student_code));
- }
- else{
- qr = student_code;
- }
- subService_->SetQr(paper_id,true, qr);
- CString newdbFile = CServerConfig::app_data_dir + _T("\\result_1111.db3");
- CopyFile(m_bantch_dir + _T("\\result.db3"), newdbFile, FALSE);
- CopyFile(m_bantch_dir + _T("\\result.db3"), _T("D:\\result_1111.db3"),FALSE);
- 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);
- subService_->SetHandlerWnd(m_hwnd);
- subService_->SetDataBase(&bantch_db_lock, &bantch_db);
- subService_->ReIdentify(paper_id, params);
- subService.push_back(subService_);
- subService_->Start();
- //if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_STARTED, 0, 0);
- return 1;
- }
- //更新试卷对应考试
- 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*/)
- {
- EnterCriticalSection(&bantch_db_lock);
- // 添加学生
- 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";
- CppSQLite3Statement statement = bantch_db.compileStatement(sql3);
- statement.bind(":student_id", examinee_id.c_str());
- statement.bind(":student_code", student_code.c_str());
- statement.bind(":school_id", schoolId);
- statement.bind(":student_name", studentName.c_str());
- statement.bind(":studentCard", stuCode.c_str());
- statement.bind(":schoolStudentCard", stuSchoolCode.c_str());
- statement.bind(":class_name", className.c_str());
- statement.bind(":grade_name", gradeName.c_str());
- statement.execDML();
- char sql[512];
- char sqlTemp[512];
- long exceptions = MEX_KAOHAOYICHANG;
- 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);
- CppSQLite3Query query_student_paper = bantch_db.execQuery(sql);
- if (query_student_paper.eof()){ LeaveCriticalSection(&bantch_db_lock); return FALSE; }
- const std::string student_id_old = query_student_paper.getStringField("student_id");
- long paper_state = query_student_paper.getInt64Field("paper_state");
- bantch_db.execDML("begin transaction");
- if (paper_state&EX_KAOHAOCHONGTU){
- 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);
- CppSQLite3Query q2 = bantch_db.execQuery(sql);
- vector<int> resolved_ids;
- int same_code_count = 0;
- while (!q2.eof()){
- long paper_state_t = q2.getInt64Field("paper_state");
- if (paper_state_t&EX_KAOHAOCHONGTU)
- resolved_ids.push_back(q2.getIntField("student_paper_id"));
- same_code_count++;
- q2.nextRow();
- }
- if (same_code_count == 1 && resolved_ids.size() == 1){//解决了考号冲突
- 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]);
- bantch_db.execDML(sql);
- sprintf_s(sql, "delete from exception where student_paper_id = %d and exception_type in(%d)", resolved_ids[0], SHIFT_KAOHAOCHONGTU);
- bantch_db.execDML(sql);
- }
- }
- 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);
- bantch_db.execDML(sql);
- //更新这次修改消息
- sprintf_s(sql, "update message set identified =1 , examnumber=\"%s\",exceptions=16 where student_paper_id=%d", student_code.c_str(), paper_id);
- bantch_db.execDML(sql);
- //删除
- sprintf_s(sql, "delete from message where student_paper_id =%d and message_type = %d", paper_id, WM_IDENTIFOR_PAPER_STATE_CHAGED);
- bantch_db.execDML(sql);
- //添加
- CppSQLite3Statement stmt4 = bantch_db.compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
- stmt4.bind(":student_paper_id", paper_id);
- stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
- stmt4.execDML();
- 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);
- bantch_db.execDML(sql);
- sprintf_s(sql, "update result set answer ='%s' where student_paper_id=%d and type =3", student_code.c_str(), paper_id);
- logForDbg(sql);
- bantch_db.execDML(sql);
- sprintf_s(sql, "update result set answer ='%s' where student_paper_id=%d and type =0", student_code.c_str(), paper_id);
- logForDbg(sql);
- bantch_db.execDML(sql);
- //updatefile(&bantch_db, paper_id, (string)CT2A(m_norimg_dir), (string)CT2A(m_excimg_dir));
- vector<int> conflict_ids;
- {//更新考号后导致其他试卷考号冲突情况
- 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());
- CppSQLite3Query q2 = bantch_db.execQuery(sql);
- while (!q2.eof()){
- long paper_state_t = q2.getInt64Field("paper_state");
- if (!(paper_state_t&EX_KAOHAOCHONGTU))
- conflict_ids.push_back(q2.getIntField("student_paper_id"));
- q2.nextRow();
- }
- if (conflict_ids.size()>1){
- for (int m = 0; m < conflict_ids.size(); m++)
- {
- 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]);
- bantch_db.execDML(sql);
- 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)");
- stmt3.bind(":student_paper_id", conflict_ids[m]);
- stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
- stmt3.bind(":exception_name", "考号冲突");
- stmt3.execDML();
- {
- //删除
- sprintf_s(sql, "delete from message where student_paper_id =%d and message_type = %d", conflict_ids[m], WM_IDENTIFOR_PAPER_STATE_CHAGED);
- bantch_db.execDML(sql);
- //添加
- CppSQLite3Statement stmt4 = bantch_db.compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
- stmt4.bind(":student_paper_id", conflict_ids[m]);
- stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
- stmt4.execDML();
- }
- }
- }
- }
- for (int m = 0; m < conflict_ids.size(); m++)
- {
- if (paper_id != conflict_ids[m]){
- bantch_db.execDML(sql);
- if (m_upload_manager.IsEanble()){
- m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, std::to_string(conflict_ids[m]).c_str());
- }
- }
- }
- bantch_db.execDML("commit transaction");
- LeaveCriticalSection(&bantch_db_lock);
- for (int m = 0; m < conflict_ids.size(); m++)
- {
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)conflict_ids[m]);
- }
- return TRUE;
- }
- int CBatchService::ClearDbTemp()
- {
- //情况没有上传的
- vector<int> listpaper_id;
- char sql1[512];
- sprintf_s(sql1, "select student_paper_id from student_paper where ret_upload = 0");
- EnterCriticalSection(&bantch_db_lock);
- CppSQLite3Query q = bantch_db.execQuery(sql1);
- while (!q.eof()){
- listpaper_id.push_back(q.getIntField("student_paper_id"));
- q.nextRow();
- }
- for (int i = 0; i < listpaper_id.size(); i++)
- {
- char sql1[512];
- char sql2[512];
- char sql3[512];
- char sql4[512];
- sprintf_s(sql1, "delete from exception where student_paper_id =%d ", listpaper_id[i]);
- 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]);
- sprintf_s(sql3, "delete from page where student_paper_id =%d", listpaper_id[i]);
- sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", listpaper_id[i]);
- bantch_db.execDML(sql1);
- bantch_db.execDML(sql2);
- bantch_db.execDML(sql3);
- bantch_db.execDML(sql4);
- }
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- //忽略试卷
- int CBatchService::IgnorePaper(const int paper_id)
- {
- char sql1[512];
- char sql2[512];
- char sql3[512];
- char sql4[512];
- char sql5[512];
- sprintf_s(sql1, "delete from exception where student_paper_id =%d ", paper_id);
- 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);
- sprintf_s(sql3, "delete from page where student_paper_id =%d", paper_id);
- sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", paper_id);
- sprintf_s(sql5, "delete from message where student_paper_id =%d", paper_id);
- EnterCriticalSection(&bantch_db_lock);
- bantch_db.execDML(sql1);
- bantch_db.execDML(sql2);
- bantch_db.execDML(sql3);
- bantch_db.execDML(sql4);
- bantch_db.execDML(sql5);
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- //忽略某类型的异常
- int CBatchService::IgnoreException(const long exceptions)
- {
- char number_string[10];
- //忽略必须处理的异常将删除试卷
- EnterCriticalSection(&bantch_db_lock);
- if (exceptions&MEX_BIXUCHULIYICHANG){
- char sql0[512];
- 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);
- bantch_db.execDML(sql0);
- }
- //忽略非必须处理异常,只删除异常
- const long non_must_handle_exceptions[3] = { EX_LOUTU, EX_LOUPI, EX_WUPAN };
- const long non_must_handle_exception_shifts[3] = { SHIFT_LOUTU, SHIFT_LOUPI, SHIFT_WUPAN };
- if (exceptions&MEX_FEIBIXUCHULIYICHANG){
- char sql0[512];
- 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);
- bantch_db.execDML(sql0);
- }
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- vector<int> CBatchService::GetAllConfictPaper(int student_paper_id, string student_id)//获取冲突试卷
- {
- char sql5[1024] = { 0 };
- 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);
- CppSQLite3Query q2 = bantch_db.execQuery(sql5);
- vector<int> all_conflict_ids;
- vector<int> conflict_ids;
- while (!q2.eof()){
- long paper_state_t = q2.getInt64Field("paper_state");
- all_conflict_ids.push_back(q2.getIntField("student_paper_id"));
- if (!(paper_state_t&EX_KAOHAOCHONGTU))
- conflict_ids.push_back(q2.getIntField("student_paper_id"));
- q2.nextRow();
- }
- return all_conflict_ids;
- }
- int CBatchService::BatchServiceCmd(int cmd, void*param, void*ret)
- {
- switch (cmd){
- // 获取被覆盖的试卷
- case BATCH_SRV_CMD::BS_CMD_GET_BE_COVERD_PAPERS:
- {
- if (param && ret){
- std::vector<int>& vctRetStuInfo = *static_cast<std::vector<int>*>(ret);
- vctRetStuInfo.clear();
- int student_paper_id = *(int*)param;
- 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";
- char sz_sql[512] = { 0 };
- sprintf_s(sz_sql, sql_fmt.c_str(), student_paper_id, student_paper_id);;
- EnterCriticalSection(&bantch_db_lock);
- if (bantch_db.is_open()){
- CppSQLite3Query q = bantch_db.execQuery(sz_sql);
- while (!q.eof()){
- vctRetStuInfo.push_back(q.getIntField("student_paper_id"));
- q.nextRow();
- }
- }
- LeaveCriticalSection(&bantch_db_lock);
- }
- }
- break;
- // 判断是否有被覆盖的
- case BATCH_SRV_CMD::BS_CMD_IS_HAS_COVERD:
- {
- int nRet = 0;
- if (param){
- int student_paper_id = *(int*)param;
- EnterCriticalSection(&bantch_db_lock);
- if (bantch_db.is_open()){
- 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";
- char sz_sql[512] = { 0 };
- sprintf_s(sz_sql, sql_fmt.c_str(), student_paper_id, student_paper_id);
- nRet = bantch_db.execScalar(sz_sql);
- }
- LeaveCriticalSection(&bantch_db_lock);
-
- }
- return nRet;
- }
- break;
- // 判断是否有考号冲突
- case BATCH_SRV_CMD::BS_CMD_IS_HAS_KAOHAOCHONGTU:
- {
- int nRet = 0;
- EnterCriticalSection(&bantch_db_lock);
- if (bantch_db.is_open()){
- std::string sql = "select count(*) from exception where exception_type=";
- sql += std::to_string(SHIFT_KAOHAOCHONGTU);
- nRet = bantch_db.execScalar(sql.c_str());
- }
- LeaveCriticalSection(&bantch_db_lock);
- return nRet;
- }
- break;
- // 覆盖所有考号冲突
- case BATCH_SRV_CMD::BS_CMD_COVERD_ALL_KAOHAOCHONGTU:
- CoverdAllKaohaochongtu();
- break;
- }
- return 0;
- }
- // 覆盖所有考号冲突
- void CBatchService::CoverdAllKaohaochongtu()
- {
- //
- m_coverd_all_kaohaochongtu = std::async(std::launch::async, [&]()->int{
- LOGI("全部覆盖操作开始");
- std::map<std::string, std::vector<std::pair<std::string,int>>> _map_student_id;
- 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";
- EnterCriticalSection(&bantch_db_lock);
- auto _qry = bantch_db.execQuery(str_qry_sql.c_str());
- if (_qry.eof()){
- LeaveCriticalSection(&bantch_db_lock);
- // 覆盖操作结束
- if (m_hwnd != NULL)
- ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD_ALL_KAOHAOCHONGTU, (WPARAM)0, (LPARAM)0);
- return -1;
- }
- while (!_qry.eof()){
- std::string student_id = _qry.getStringField("student_id");
- std::string task_id = _qry.getStringField("task_id");
- _map_student_id[student_id].push_back(std::make_pair(task_id, _qry.getIntField("student_paper_id")));
- _qry.nextRow();
- }
- std::string str_coverd = "";
- std::string str_update = "";
- for (auto it : _map_student_id){
- for (std::size_t i = 0; i < it.second.size(); ++i){
- std::string task_id = it.second[i].first;
- int student_paper_id = it.second[i].second;
- if (i == 0){
- if (m_bErrorHandle){
- // 云处理模式- 被覆盖的更新云端状态
- if (UpateErrorStudentData(task_id)){
- str_update += std::to_string(student_paper_id);
- }
- }
- else{
- str_update += std::to_string(student_paper_id);
- }
- }
- else{
- str_coverd += std::to_string(student_paper_id);
- str_coverd += ",";
- }
- }
- str_update += ",";
- }
- bantch_db.execDML("begin transaction");
- try{
- if (!str_coverd.empty()){
- str_coverd = std::string(str_coverd, 0, str_coverd.size() - 1);
- std::string str_sql_coverd = "update student_paper set paper_state=0, Is_Covered=1 where student_paper_id in(";
- str_sql_coverd += str_coverd + ")";
- bantch_db.execDML(str_sql_coverd.c_str());
- LOGFMTI("被覆盖sql语句:%s", str_sql_coverd.c_str());
- std::string sql_del = "delete from message where student_paper_id in(";
- sql_del += str_coverd + ")";
- bantch_db.execDML(sql_del.c_str());
- LOGFMTI("被覆盖sql语句 message表:%s", sql_del.c_str());
- }
- if (!str_update.empty()){
- str_update = std::string(str_update, 0, str_update.size() - 1);
- std::string str_sql_update = "update student_paper set paper_state=0, Is_Covered=0 where student_paper_id in(";
- str_sql_update += str_update + ")";
- bantch_db.execDML(str_sql_update.c_str());
- LOGFMTI("覆盖sql语句:%s", str_sql_update.c_str());
- }
- }
- catch (...){
- LOGI("全部覆盖操作SQL执行异常");
- bantch_db.execDML("rollback transaction");
- }
- bantch_db.execDML("commit transaction");
- LOGI("全部覆盖操作SQL执行成功-更新界面");
- LeaveCriticalSection(&bantch_db_lock);
- // 删除被覆盖的数据
- // 将最后一条移动到成功列表
- int _update_len = str_update.size() + 1, _coverd_len = str_coverd.size() + 1;
- char *_update = new char[_update_len]; memset(_update, 0, _update_len);
- char *_coverd = new char[_coverd_len]; memset(_coverd, 0, _coverd_len);
- strcpy_s(_update, _update_len, str_update.c_str());
- strcpy_s(_coverd, _coverd_len, str_coverd.c_str());
- ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD_ALL_KAOHAOCHONGTU, (WPARAM)_update, (LPARAM)_coverd);
- LOGI("全部覆盖操作结束");
- // 覆盖操作结束
- if (m_hwnd != NULL)
- ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD_ALL_KAOHAOCHONGTU, (WPARAM)0, (LPARAM)0);
- return 0;
- });
- }
- // 覆盖试卷
- int CBatchService::ReplacePaper(const int paper_id, int &paper_id_ret)
- {
- BOOL bRet = FALSE;
- paper_id_ret = paper_id;
- char sql1[512] = { 0 };
- char sql5[512] = { 0 };
- sprintf_s(sql1, "delete from exception where student_paper_id =%d ", paper_id);
- sprintf_s(sql5, "update student_paper set paper_state=0 where student_paper_id = %d AND paper_state = 128", paper_id);
- EnterCriticalSection(&bantch_db_lock);
- if (bantch_db.execDML(sql5) > 0){
- bantch_db.execDML(sql1);
- char sql0[512];
- 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);
- CppSQLite3Query q = bantch_db.execQuery(sql0);
- if (!q.eof()){
- int couvered_paper_id = q.getIntField("student_paper_id");
- bool bSendToClientUpdate = true;
- if (m_bErrorHandle){ // 云处理模式- 被覆盖的更新云端状态
- auto task_id = std::to_string(q.getIntField("task_id"));
- if (!UpateErrorStudentData(task_id)){
- //printf("更新状态失败,所以不更新覆盖标记\n");
- bSendToClientUpdate = false;
- }
- }
- if(bSendToClientUpdate){
- std::string sql_del = "delete from message where student_paper_id=";
- sql_del += std::to_string(couvered_paper_id);
- bantch_db.execDML(sql_del.c_str());
- sprintf_s(sql5, "update student_paper set Is_Covered=1 where student_paper_id = %d", couvered_paper_id);
- int nRet = bantch_db.execDML(sql5);
- LOGFMTI("被覆盖paper_id=%d 成功paper_id=%d 数据库更新状况:%d", couvered_paper_id, paper_id, nRet);
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD, (WPARAM)paper_id, (LPARAM)couvered_paper_id);
- }
- }
- else{
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_COVERD, (WPARAM)paper_id, (LPARAM)paper_id);
- }
- bRet = TRUE;
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)paper_id);
- }
- LeaveCriticalSection(&bantch_db_lock);
- return bRet;
- }
- // 全部覆盖试卷
- int CBatchService::ReplaceAllKaoHaoChongTu(vector<int> &paper_id_List)
- {
- char mysql0[512];
- sprintf_s(mysql0, "select student_paper_id from student_paper where paper_state = 128");
- EnterCriticalSection(&bantch_db_lock);
- char sql0[512];
- char sql1[512];
- char sql2[512];
- char sql3[512];
- char sql4[512];
- char sql5[512];
- int delete_paper;
- CppSQLite3Query q = bantch_db.execQuery(mysql0);
- while (!q.eof())
- {
- int paper_id = q.getIntField("student_paper_id");
- 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);
- sprintf_s(sql5, "update student_paper set paper_state=0 where student_paper_id = %d", paper_id);
- paper_id_List.push_back(paper_id);
- CppSQLite3Query q1 = bantch_db.execQuery(sql0);
- if (!q.eof())
- {
- delete_paper = q1.getIntField("student_paper_id");
- sprintf_s(sql1, "delete from exception where student_paper_id =%d ", delete_paper);
- 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);
- sprintf_s(sql3, "delete from page where student_paper_id =%d", delete_paper);
- sprintf_s(sql4, "delete from student_paper where student_paper_id =%d", delete_paper);
- bantch_db.execDML(sql1);
- bantch_db.execDML(sql2);
- bantch_db.execDML(sql3);
- bantch_db.execDML(sql4);
- bantch_db.execDML(sql5);
- // 修改消息
- sprintf_s(sql0, "delete from message where student_paper_id =%d", paper_id);
- sprintf_s(sql1, "UPDATE message SET student_paper_id = %d WHERE student_paper_id = %d ", paper_id, delete_paper);
- bantch_db.execDML(sql0);
- bantch_db.execDML(sql1);
- }
- q.nextRow();
- }
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- //开始上传成绩
- int CBatchService::StartUploadPaper(HWND hWnd, int student_paper_id/* = -1*/, bool bErrorPaper /*= false*/)
- {
- m_result_uploader->SetResultHandler(mainService->GetResultHander());
- m_result_uploader->SetDataBase(&bantch_db_lock, &bantch_db);
- m_result_uploader->SetDataBaseManager(database_db_lock, database_db,m_database_id);
- if (hWnd != NULL)m_result_uploader->SetHandlerWnd(hWnd);
- m_result_uploader->readNewUploadUrl();
- m_result_uploader->SetUploadOnScan(m_upload_manager.IsEanble(), student_paper_id, bErrorPaper);
- return m_result_uploader->Start();
- }
- //是否支持暂停
- BOOL CBatchService::SupportPause(void)
- {
- return mainService->SupportPause();
- }
- //暂停处理
- ServiceState CBatchService::OnPausing(void)
- {
- mainService->Pause();
- while (mainService->GetServiceSate() == pausing || mainService->GetServiceSate() == running){
- Sleep(10);
- }
- ServiceState nextState = IService::OnPausing();
- if (nextState == paused&&m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAUSED, 0, 0);
- return nextState;
- }
- //恢复扫描
- ServiceState CBatchService::OnResuming(void)
- {
- mainService->Resume();
- while (mainService->GetServiceSate() == resuming){
- Sleep(10);
- }
- ServiceState nextState = IService::OnResuming();
- if (nextState == running&&m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_RESUMED, 0, 0);
- return nextState;
- }
- //放弃本次考试
- int CBatchService::GiveUpCurrentBatch()
- {
- char sql[128];
- sprintf_s(sql, "update database set database_state =%d where database_id =%d", DATABASE_STATE_GIVEUP, m_database_id);
- EnterCriticalSection(database_db_lock);
- database_db->execDML("begin transaction");
- database_db->execDML(sql);
- database_db->execDML("commit transaction");
- LeaveCriticalSection(database_db_lock);
- return TRUE;
- }
- //设置继续扫描文件夹路径
- int CBatchService::SetFolderScanDir(const std::string& img_dir)
- {
- mainService->continueScan(img_dir);
- mainService->Start();
- return TRUE;
- }
- //停止服务
- BOOL CBatchService::Stop(void)
- {
- if (IService::Stop()){
- m_abnormal_stop = TRUE;
- return TRUE;
- }
- m_upload_manager.UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_UPLOAD_STOP, NULL);
- return FALSE;
- }
- int CBatchService::QueryExptionPaperCount(int & total_count)
- {
- EnterCriticalSection(&bantch_db_lock);
- total_count = bantch_db.execScalar("select count(0) from student_paper pp where not pp.paper_state = 0");
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- //查询异常类型信息
- int CBatchService::QueryExptionTypeInfo(vector<EXCEPTION_TYPE_INFO> & infos)
- {
- EnterCriticalSection(&bantch_db_lock);
- 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");
- while (!query.eof()){
- EXCEPTION_TYPE_INFO ex_type_info;
- ex_type_info.exception_type = (1 << query.getInt64Field("exception_type"));
- ex_type_info.exception_count = query.getIntField("exception_paper_count");
- switch (ex_type_info.exception_type){
- case EX_DINGWEIDIAN:strcpy(ex_type_info.exception_name, "定位点异常"); break;
- case EX_FEIFASHIJUAN:strcpy(ex_type_info.exception_name, "非法试卷"); break;
- case EX_KAOHAOWEISHIBIE:strcpy(ex_type_info.exception_name, "考号未识别"); break;
- case EX_KAOHAOBUCUNZAI:strcpy(ex_type_info.exception_name, "考号不存在"); break;
- case EX_KAOHAOCHONGTU:strcpy(ex_type_info.exception_name, "考号冲突"); break;
- case EX_LOUTU:strcpy(ex_type_info.exception_name, "考生漏涂"); break;
- case EX_LOUPI:strcpy(ex_type_info.exception_name, "教师漏批"); break;
- case EX_WUPAN:strcpy(ex_type_info.exception_name, "教师误判"); break;
- case EX_WUFASHIBIE_ZHUGUANTI:strcpy(ex_type_info.exception_name, "无法识别解答题"); break;
- case EX_SHIJUANQUEYE:strcpy(ex_type_info.exception_name, "试卷缺页"); break;
- default: strcpy(ex_type_info.exception_name, "未知异常类型"); break;
- }
- infos.push_back(ex_type_info);
- query.nextRow();
- }
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- int CBatchService::SetCookie(CString path, CString name, CString value)
- {
- return InternetSetCookie(path, name, value);
- }
- int CBatchService::SetLocalServerCookie(CString name, CString value)
- {
- switch (CServerConfig::server_address_type){
- case SAT_LOCAL_IN:InternetSetCookie(CServerConfig::server_url_local_in, name, value); break;
- case SAT_LOCAL_OUT:InternetSetCookie(CServerConfig::server_url_local_out, name, value); break;
- }
- return TRUE;
- }
- void CBatchService::Online_saveQuestionStd(long long examId, std::string examName, long examCourseId, std::string courseName, std::string rule /*= ""*/)
- {
- if (m_nSubjectID == 0)
- {
- rapidjson::Document doc;
- doc.Parse(rule.c_str());
- if (doc.HasParseError()) return;
- auto itObject = doc.FindMember("object");
- if (itObject == doc.MemberEnd() || !itObject->value.IsArray() || itObject->value.Size() <= 0) return;
- auto itQuestion = itObject->value.Begin()->FindMember("questions");
- if (itQuestion == itObject->value.Begin()->MemberEnd() || !itQuestion->value.IsArray()) return;
- CppSQLite3DB* bantch_db = &this->bantch_db;
- const char* sql_clear = "delete from question_std";
- bantch_db->execDML(sql_clear);
- const char* sql_clear1 = "delete from exam";
- bantch_db->execDML(sql_clear1);
- 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)";
- CppSQLite3Statement statement_exam = bantch_db->compileStatement(sql_exam);
- 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 )";
- CppSQLite3Statement statement = bantch_db->compileStatement(sql);
- bantch_db->execDML("begin transaction");
- float full_score = 0;
- float full_score_keguanti = 0;
- auto fGetQuestionType = [](int nType)->QuestionType{
- switch (nType){
- case 1: return schema::DANXUANTI; break; // 单选题
- case 11:
- case 2: return schema::DUOXUANTI; break; // 多选题
- case 5: return schema::TIANKONGTI; break; // 填空题
- case 7: return schema::ZHUGUANTI; break; // 主观题
- case 17: return schema::XUANZUO_ZHUGUANTI; break; // 选做题
- case 27: return schema::BIZUOTI; break;
- }
- return schema::DANXUANTI;
- };
- for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
- QuestionType question_type;
- int full_score = 0;
- auto itType = it->FindMember("questionTypeId");
- if (itType != it->MemberEnd() && itType->value.IsInt()){
- question_type = fGetQuestionType(itType->value.GetInt());
- }
- else{
- continue;
- }
- auto itScore = it->FindMember("fullScore");
- if (itScore != it->MemberEnd() && itScore->value.IsInt()){
- full_score = itScore->value.GetInt();
- }
- if (question_type == schema::DANXUANTI || question_type == schema::DUOXUANTI || question_type == schema::PANDUANTI)full_score_keguanti += full_score;
- double half_score = 0.0;
- auto itHalfScore = it->FindMember("rule_score_half");
- if (itHalfScore != it->MemberEnd() ){
- if (itHalfScore->value.IsInt() || itHalfScore->value.IsDouble())
- half_score = itHalfScore->value.GetDouble();
- else if (itHalfScore->value.IsString()){
- std::string s = itHalfScore->value.GetString();
- if(!s.empty())
- half_score = std::stod(s);
- }
- }
- else
- {
- itHalfScore = it->FindMember("halfScore");
- if (itHalfScore != it->MemberEnd() && (itHalfScore->value.IsInt() || itHalfScore->value.IsDouble())){
- half_score = itHalfScore->value.GetDouble();
- }
- }
- std::string question_code;
- auto itQuestionCode = it->FindMember("questionNum");
- if (itQuestionCode != it->MemberEnd() && itQuestionCode->value.IsString()){
- question_code = itQuestionCode->value.GetString();
- }
- std::string answer_all;
- auto itAnswer = it->FindMember("answer");
- if (itAnswer != it->MemberEnd() && itAnswer->value.IsString()){
- answer_all = itAnswer->value.GetString();
- }
- int rule_type = 0;
- auto itRuleType = it->FindMember("rule_type");
- if (itRuleType != it->MemberEnd() && itRuleType->value.IsInt()){
- rule_type = itRuleType->value.GetInt();
- }
- auto rule_answer = it->FindMember("rule_answer");
- if (rule_answer != it->MemberEnd() && rule_answer->value.IsString()){
- string str = rule_answer->value.GetString();
- if (str.length()>0)
- {
- answer_all = str;
- }
-
- }
- statement.bind(":question_code", question_code.c_str());
- statement.bind(":question_type", question_type);
- statement.bind(":multi_answer", question_type == schema::QuestionType::DUOXUANTI);
- statement.bind(":answer_all", answer_all.c_str());
- statement.bind(":answer_std", answer_all.c_str());
- statement.bind(":score_full", full_score);
- statement.bind(":score_half", half_score);
- statement.bind(":option_count", 3);
- statement.bind(":rule_type", rule_type);
- // 单选题、客观题 answer_all 从模板里面取
- if (m_onlineCardTemplate && (question_type == schema::QuestionType::DANXUANTI || question_type == schema::QuestionType::DUOXUANTI))
- {
- for (auto& page : m_onlineCardTemplate->pages)
- {
- for (auto& question : page.second.vctQuestions)
- {
- if (question_code == question.id.c_str())
- {
- string std_answer_all("");
- for (auto& option : question.opt)
- {
- if (std_answer_all.length() > 0)
- {
- std_answer_all.append(",");
- }
- std_answer_all.append(option.optName);
- }
- statement.bind(":answer_all", std_answer_all.c_str());
- break;
- }
- }
- }
- }
- statement.execDML();
- }
- statement_exam.bind(":exam_id", examId);
- statement_exam.bind(":exam_name", examName.c_str());
- statement_exam.bind(":exam_course_id", examCourseId);
- statement_exam.bind(":course_name", courseName.c_str());
- statement_exam.bind(":full_score", full_score);
- statement_exam.bind(":full_score_objective", full_score_keguanti);
- statement_exam.execDML();
- bantch_db->execDML("commit transaction");
- }
- else
- {
- rapidjson::Document doc;
- doc.Parse(rule.c_str());
- if (doc.HasParseError()) return;
- auto itQuestion = doc.FindMember("questions");
- if (itQuestion == doc.MemberEnd() || !itQuestion->value.IsArray() || itQuestion->value.Size() <= 0) return;
- //auto itQuestion = itObject->value.Begin()->FindMember("questions");
- //if (itQuestion == itQuestion->value.Begin()->MemberEnd() || !itQuestion->value.IsArray()) return;
- CppSQLite3DB* bantch_db = &this->bantch_db;
- const char* sql_clear = "delete from question_std";
- bantch_db->execDML(sql_clear);
- const char* sql_clear1 = "delete from exam";
- bantch_db->execDML(sql_clear1);
- 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)";
- CppSQLite3Statement statement_exam = bantch_db->compileStatement(sql_exam);
- 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 )";
- CppSQLite3Statement statement = bantch_db->compileStatement(sql);
- bantch_db->execDML("begin transaction");
- float full_score = 0;
- float full_score_keguanti = 0;
- auto fGetQuestionType = [](int nType)->QuestionType{
- switch (nType){
- case 1: return schema::DANXUANTI; break; // 单选题
- case 11:
- case 2: return schema::DUOXUANTI; break; // 多选题
- case 5: return schema::TIANKONGTI; break; // 填空题
- case 7: return schema::ZHUGUANTI; break; // 主观题
- case 17: return schema::XUANZUO_ZHUGUANTI; break; // 选做题
- case 27: return schema::BIZUOTI; break;
- }
- return schema::DANXUANTI;
- };
- for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it){
- QuestionType question_type;
- int full_score = 0;
- auto itType = it->FindMember("questionTypeId");
- if (itType != it->MemberEnd() && itType->value.IsInt()){
- question_type = fGetQuestionType(itType->value.GetInt());
- statement.bind(":question_type", question_type);
- }
- else{
- continue;
- }
- auto itScore = it->FindMember("fullScore");
- if (itScore != it->MemberEnd() && itScore->value.IsString()){
- full_score = std::atoi(itScore->value.GetString());
- statement.bind(":score_full", itScore->value.GetString());
- }
- if (question_type == schema::DANXUANTI || question_type == schema::DUOXUANTI || question_type == schema::PANDUANTI)full_score_keguanti += full_score;
- double half_score = 0.0;
- auto itHalfScore = it->FindMember("rule_score_half");
- if (itHalfScore != it->MemberEnd() && (itHalfScore->value.IsString())){
- //half_score = itHalfScore->value.GetDouble();
- statement.bind(":score_half", itHalfScore->value.GetString());
- }
- else
- {
- auto itHalfScore1 = it->FindMember("halfScore");
- if (itHalfScore1 != it->MemberEnd() && (itHalfScore1->value.IsString())){
- //half_score = itHalfScore->value.GetDouble();
- statement.bind(":score_half", itHalfScore1->value.GetString());
- }
- }
- std::string question_code;
- int question_id(0);
- auto itQuestionCode = it->FindMember("questionNum");
- if (itQuestionCode != it->MemberEnd() && itQuestionCode->value.IsInt()){
- //question_code = itQuestionCode->value.GetString();
- question_id = itQuestionCode->value.GetInt();
- statement.bind(":question_code", itQuestionCode->value.GetInt());
- }
- std::string answer_all;
- auto itAnswer = it->FindMember("answer");
- if (itAnswer != it->MemberEnd() && itAnswer->value.IsString()){
- answer_all = itAnswer->value.GetString();
- }
- int rule_type = 0;
- auto itRuleType = it->FindMember("rule_type");
- if (itRuleType != it->MemberEnd() && itRuleType->value.IsInt()){
- //rule_type = itRuleType->value.GetInt();
- statement.bind(":rule_type", itRuleType->value.GetInt());
- }
- else
- statement.bind(":rule_type", 2);
-
- auto rule_answer = it->FindMember("rule_answer");
- if (rule_answer != it->MemberEnd() && rule_answer->value.IsString()){
- string str = rule_answer->value.GetString();
- if (str.length() > 0)
- {
- answer_all = str;
- }
- }
- //statement.bind(":question_code", question_code.c_str());
- //statement.bind(":question_type", question_type);
- statement.bind(":multi_answer", question_type == schema::QuestionType::DUOXUANTI);
- //statement.bind(":answer_all", answer_all.c_str());
- statement.bind(":answer_std", answer_all.c_str());
- //statement.bind(":score_full", full_score);
- //statement.bind(":score_half", half_score);
- statement.bind(":option_count", 3);
- //statement.bind(":rule_type", rule_type);
- // 单选题、客观题 answer_all 从模板里面取
- if (m_onlineCardTemplate && (question_type == schema::QuestionType::DANXUANTI || question_type == schema::QuestionType::DUOXUANTI))
- {
- for (auto& page : m_onlineCardTemplate->pages)
- {
- for (auto& question : page.second.vctQuestions)
- {
- if (question_id == atoi(question.id.c_str()))
- {
- string std_answer_all("");
- for (auto& option : question.opt)
- {
- if (std_answer_all.length() > 0)
- {
- std_answer_all.append(",");
- }
- std_answer_all.append(option.optName);
- }
- statement.bind(":answer_all", std_answer_all.c_str());
- break;
- }
- }
- }
- }
- statement.execDML();
- }
- statement_exam.bind(":exam_id", examId);
- statement_exam.bind(":exam_name", examName.c_str());
- statement_exam.bind(":exam_course_id", examCourseId);
- statement_exam.bind(":course_name", courseName.c_str());
- statement_exam.bind(":full_score", full_score);
- statement_exam.bind(":full_score_objective", full_score_keguanti);
- statement_exam.execDML();
- bantch_db->execDML("commit transaction");
- }
- }
- void CBatchService::saveQuestionStd(long long examId, std::string examName, long examCourseId, std::string courseName, std::vector<schema::SCHEMA_QUESTION> &questions, std::string rule)
- {
- CppSQLite3DB* bantch_db = &this->bantch_db;
- const char* sql_clear = "delete from question_std";
- bantch_db->execDML(sql_clear);
- const char* sql_clear1 = "delete from exam";
- bantch_db->execDML(sql_clear1);
- 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)";
- CppSQLite3Statement statement_exam = bantch_db->compileStatement(sql_exam);
- 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 )";
- CppSQLite3Statement statement = bantch_db->compileStatement(sql);
- bantch_db->execDML("begin transaction");
- float full_score = 0;
- float full_score_keguanti = 0;
- Json::Value ruleValue;
- if (!rule.empty())
- {
- Json::Features features;
- Json::Reader re(features);
- Json::Value root;
- re.parse(rule, root);
- ruleValue = root["rules"];
- }
- for (int i = 0; i < questions.size(); i++)
- {
- schema::SCHEMA_QUESTION& row = questions[i];
- full_score += row.score;
- int question_type = row.questionType&schema::QTF_QUESTION_TYPE_MASK;
- if (question_type == schema::DANXUANTI || question_type == schema::DUOXUANTI || question_type == schema::PANDUANTI)full_score_keguanti += row.score;
- statement.bind(":question_code", row.question_code_new);
- statement.bind(":question_type", row.questionType);
- statement.bind(":multi_answer", question_type == schema::QuestionType::DUOXUANTI);
- statement.bind(":answer_all", row.answers.c_str());
- statement.bind(":answer_std", row.answerA.c_str());
- statement.bind(":score_full", row.score);
- statement.bind(":score_half", row.halfScore);
- statement.bind(":option_count", 3);
- statement.bind(":rule_type", 2);
- m_mapKeguantiNickName[row.question_code_new] = row.question_code;
- if (!ruleValue.isNull())
- {
- if (ruleValue.size() > 0)
- {
- Json::Value rule = ruleValue[row.question_code_new];
- if (!rule.isNull())
- {
- int rule_type = rule["rule_type"].asInt();
- //row["questionNum"].asString().c_str()
- statement.bind(":rule_type", rule_type);
- std::string answer = rule["rule_answer"].asString().c_str();
- if (!answer.empty())
- statement.bind(":answer_std", rule["rule_answer"].asString().c_str());
- else
- {
- row.answerA = answer;
- statement.bind(":answer_std", row.answerA.c_str());
- }
-
- std::string rule_score = rule["rule_score"].asString().c_str();
- if (!rule_score.empty())
- statement.bind(":score_full", atof(rule_score.c_str()));
- else
- {
- row.score = atof(rule_score.c_str());
- statement.bind(":score_full", row.score);
- }
-
- std::string rule_score_half = rule["rule_score_half"].asString().c_str();
- if (!rule_score_half.empty())
- statement.bind(":score_half", atof(rule_score_half.c_str()));
- else
- {
- row.halfScore = atof(rule_score_half.c_str());
- statement.bind(":score_half", row.halfScore);
- }
-
- }
- }
- // Json::Value rule = ruleValue[std::stoi(row.question_code_new)];
- // if (!rule.isNull())
- // {
- // int rule_type = rule["rule_type"].asInt();
- // //row["questionNum"].asString().c_str()
- // statement.bind(":rule_type", rule_type);
- // std::string answer = rule["rule_answer"].asString().c_str();
- // if (!answer.empty())
- // statement.bind(":answer_std", rule["rule_answer"].asString().c_str());
- // else
- // statement.bind(":answer_std", row.answerA.c_str());
- // std::string rule_score = rule["rule_score"].asString().c_str();
- // if (!rule_score.empty())
- // statement.bind(":score_full", atof(rule_score.c_str()));
- // else
- // statement.bind(":score_full", row.score);
- // std::string rule_score_half = rule["rule_score_half"].asString().c_str();
- // if (!rule_score_half.empty())
- // statement.bind(":score_half", atof(rule_score_half.c_str()));
- // else
- // statement.bind(":score_half", row.halfScore);
- //
- // }
- }
- statement.execDML();
- }
- statement_exam.bind(":exam_id", examId);
- statement_exam.bind(":exam_name", examName.c_str());
- statement_exam.bind(":exam_course_id", examCourseId);
- statement_exam.bind(":course_name", courseName.c_str());
- statement_exam.bind(":full_score", full_score);
- statement_exam.bind(":full_score_objective", full_score_keguanti);
- statement_exam.execDML();
- bantch_db->execDML("commit transaction");
- // getStdAnswerAndScore();
- }
- int CBatchService::QueryNormalPaper(vector<STUDENT_INFO> & studentList)
- {
- EnterCriticalSection(&bantch_db_lock);
- // 找考号考号冲突的并且已经上传的成功数据,和未上传的成功数据
- 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)";
- CppSQLite3Query q = bantch_db.execQuery(sql.c_str());
- while (!q.eof()){
- STUDENT_INFO si;
- char class_name[64];
- sprintf_s(class_name, "%s(%s)班", q.getStringField("grade_name"), q.getStringField("class_name"));
- si.class_name = class_name;
- si.student_id = q.getInt64Field("student_id");
- si.student_name = q.getStringField("student_name");
- si.student_code = q.getStringField("student_code");
- si.class_id = q.getInt64Field("class_id");
- si.score = (float)q.getFloatField("score_total", -1);
- si.paper_id = q.getIntField("student_paper_id", -1);
- si.location_id = q.getIntField("location_id", -1);
- studentList.push_back(si);
- q.nextRow();
- }
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- int CBatchService::QueryMubanImgPath(int page_index, std::string& imgPath)
- {
- CString imgFilePath;
- imgFilePath.Format(_T("%s\\%05d.jpg"), CString(m_muban_img_dir.c_str()), page_index);
- char fff[1024];
- WideCharToMultiByte(CP_ACP, 0, imgFilePath, -1, fff, 1024, NULL, NULL);
- imgPath = fff;
- return TRUE;
- }
- int CBatchService::QueryMubanImgCount(int& page_count)
- {
- /*return page_count = m_identifor.GetMubanCount();*/
- page_count = m_schema.get() ? m_schema->size() : 0;
- return 1;
- }
- const boost::shared_ptr<const HANDLE_INFO>& CBatchService::GetHandleInfo()
- {
- return m_handleInfo;
- }
- void CBatchService::getStdAnswerAndScore()
- {
- CppSQLite3DB* bantch_db = &this->bantch_db;
- CHttpClient httpClient;
- CString url_str_findPaperInfo, postData, strPaperId;
- string response;
- url_str_findPaperInfo.Format(_T("%s/coachio/iointerface/downLoadThirdPaperSheet"), CServerConfig::server_url);
-
- readPaperId(strPaperId);
- logForDbg("getStdAnswerAndScore" );
- postData.Format(_T("paperIdStr="));
- postData += strPaperId;
- httpClient.SetSendHeader(MarkHttpHeaderData());
- httpClient.HttpPost(url_str_findPaperInfo, postData, response);
- Json::Features features;
- Json::Reader re(features);
- Json::Value root;
- re.parse(response, root);
- if (root["success"].isInt() && root["success"].asInt()){
- Json::Value objects = root["object"];
- Json::Value object = objects["paper_info"];
- // for (int m = 0; m<object.size(); m++)
- {
- // Json::Value ob = object[m];
- Json::Value rows = object["questions"];
- int array_size = 0;
- array_size = rows.size();
- for (int i = 0; i < array_size; i++)
- {
- Json::Value row = rows[i];
- CppSQLite3Statement stmt = bantch_db->compileStatement("update question_std set answer_std=:answer_std,score_full=:score_full where question_code=:question_code");
- stmt.bind(":question_code", row["questionNum"].asString().c_str());
- stmt.bind(":answer_std", row["answer"].asString().c_str());
- stmt.bind(":score_full", row["fullScore"].asDouble());
- logForDbg("question_code:" + row["questionNum"].asString());
- logForDbg("answer_std:" + row["answer"].asString());
- char strTemp[5] = {"\0"};
- string str;
- sprintf(strTemp, "%.1f", row["fullScore"].asDouble());
- str = strTemp;
- logForDbg("score_full:" + str);
- stmt.execDML();
- }
- }
- }
- }
- CString CBatchService::MarkHttpHeaderData()
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- CString ret;
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- if (m_bErrorHandle){
- lstrcat(FilePath, _T("paperinfo.ini"));
- WCHAR JSESSIONID[512];
- GetPrivateProfileString(_T("paperinfo"), _T("session"), _T(""), JSESSIONID, 512, FilePath);
- ret = JSESSIONID;
- }
- else{
- lstrcat(FilePath, _T("config.ini"));
- #ifndef BACK_STAGE
- WCHAR SIG[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("SIG"), _T(""), SIG, 512, FilePath);
- WCHAR TIME[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("TIME"), _T(""), TIME, 512, FilePath);
- WCHAR ID[512];
- GetPrivateProfileString(L"SESSIONID", L"ID", L"", ID, 512, FilePath);
- WCHAR JSESSIONID[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("JSESSIONID"), _T(""), JSESSIONID, 512, FilePath);
-
- ret.Format(_T("userid=%s&time=%s&sig=%s&session=%s"), ID, TIME, SIG, JSESSIONID);
- #else
- WCHAR MYCOOK[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("MYCOOK"), _T(""), MYCOOK, 512, FilePath);
- CString ret;
- ret.Format(_T("%s"), MYCOOK);
- #endif
- }
- return ret;
- }
- bool CBatchService::readPaperId(CString& strPaperId)
- {
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- GetModuleFileName(NULL, exeFullPath, MAX_PATH);
- strPath = (CString)exeFullPath;
- int position = strPath.ReverseFind('\\');
- strPath = strPath.Left(position + 1);
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("paperInfo.ini"));
- WCHAR PaperId[512];
- GetPrivateProfileString(_T("paperinfo"), _T("paper_str"), _T(""), PaperId, 512, FilePath);
- strPaperId = PaperId;
- return false;
- }
- void CBatchService::logForDbg(string strLog)
- {
- char threadName[4*1024];
- char logName[300];
- char sYear[10], sMonth[10], sDay[25];
- SYSTEMTIME st;
- GetLocalTime(&st);
- int j0 = 0;
- int m_nYear = st.wYear; ///年
- int m_nMonth = st.wMonth; ///月
- int m_nDay = st.wDay; ///日
- int m_nHour = st.wHour; ///小时
- int m_nMinute = st.wMinute; ///分钟
- int m_nSecond = st.wSecond; ///秒
- int m_nMillSecond = st.wMilliseconds; ///毫秒
- sprintf_s(sYear, sizeof(sYear), "%d", m_nYear);
- sprintf_s(sMonth, sizeof(sMonth), "_%02d", m_nMonth);
- sprintf_s(sDay, sizeof(sDay), "_%02d_log.txt", m_nDay);
- strcpy(logName, sYear);
- strcat(logName, sMonth);
- strcat(logName, sDay);
- char strScore[MAX_PATH] = {0};
- for (int i = 0; i < strLog.size(); i++)
- strScore[i] = strLog.at(i);
- sprintf_s(threadName, sizeof(threadName), "%s\n", strScore);
- ThreadLog2(threadName, logName);
- }
- void CBatchService::recordBarcodeFlag(int nFlag)
- {
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- GetModuleFileName(NULL, exeFullPath, MAX_PATH);
- strPath = (CString)exeFullPath;
- int position = strPath.ReverseFind('\\');
- strPath = strPath.Left(position + 1);
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("paperInfo.ini"));
- if (nFlag==0)
- WritePrivateProfileString(_T("paperinfo"), _T("barcode_flag"), L"0", FilePath);
- else
- WritePrivateProfileString(_T("paperinfo"), _T("barcode_flag"), L"1", FilePath);
- return;
- }
- void CBatchService::getCurScanExam(std::string exam_code, std::vector<std::vector<coverStu>> &stuInfo)
- {
- CHttpClient httpClient;
- httpClient.SetSendHeader(MarkHttpHeaderData());
- string response;
- CString url_str;
- //url_str.Format(_T("%s/%s"),CServerConfig::server_url,_T("student!findStudentsByClazzId.action"));
- url_str.Format(_T("%s/%s"), CServerConfig::server_url, _T("coachio/iointerface_v2/getNotUploadStudentList"));
- CString postData;
- CString stExamCode(exam_code.data());
- postData.Format(_T("examGroupId=%s&type=%d"), stExamCode, 1);
- httpClient.HttpPost(url_str, postData, response);
- Json::Features features;
- Json::Reader re(features);
- Json::Value root;
- re.parse(response, root);
- if (root["success"].isInt() && root["success"].asInt()){
- Json::Value rows = root["object"];
- if (rows.isArray()){
- int array_size = rows.size();
- std::vector<coverStu> stuVec;
- for (int i = 0; i<array_size; i++)
- {
- Json::Value row = rows[i];
- coverStu stu;
- stu.stu_name = row["realname"].asString().c_str();
- stu.stu_code1 = row["student_card"].asString().c_str();
- stu.stu_code2 = row["school_student_card"].asString().c_str();
- stu.stu_class = row["class_name"].asString().c_str();
- stu.stu_grade = row["grade"].asString().c_str();
- stuVec.push_back(stu);
- }
- stuInfo.push_back(stuVec);
- }
- }
- postData.Format(_T("examGroupId=%s&type=%d"), stExamCode, 2);
- httpClient.HttpPost(url_str, postData, response);
- re.parse(response, root);
- if (root["success"].isInt() && root["success"].asInt()){
- Json::Value rows = root["object"];
- if (rows.isArray()){
- int array_size = rows.size();
- std::vector<coverStu> stuVec;
- for (int i = 0; i<array_size; i++)
- {
- Json::Value row = rows[i];
- coverStu stu;
- stu.stu_name = row["realname"].asString().c_str();
- stu.stu_code1 = row["student_card"].asString().c_str();
- stu.stu_code2 = row["school_student_card"].asString().c_str();
- stu.stu_class = row["class_name"].asString().c_str();
- stu.stu_grade = row["grade"].asString().c_str();
- stuVec.push_back(stu);
- }
- stuInfo.push_back(stuVec);
- }
- }
- }
- void CBatchService::getCoverStuInfoByExamCode(std::string examCode, std::vector<coverStu> &stuInfo)
- {
- EnterCriticalSection(&bantch_db_lock);
- char sql[256];
- sprintf_s(sql, "select * from student where recoverFlag=1 ");
- CppSQLite3Query query = bantch_db.execQuery(sql);
- while (!query.eof()){
- coverStu stu;
- stu.stu_name = query.getStringField("student_name");
- stu.stu_code1 = query.getStringField("studentCard");
- stu.stu_code2 = query.getStringField("schoolStudentCard");
- stu.stu_class = query.getStringField("class_name");
- stu.stu_grade = query.getStringField("grade_name");
- stuInfo.push_back(stu);
- query.nextRow();
- }
- LeaveCriticalSection(&bantch_db_lock);
- }
- static bool readFile(string & file, string & str)
- {
- ifstream in;
- string line;
- in.open(file, ifstream::in);
- if (!in.is_open())
- return false;
- while (getline(in, line))
- {
- str.append(line + "\n");
- }
- in.close();
- return true;
- }
- void CBatchService::RestoreFile(int paper_id, const std::string&path_rst, const std::string&path_ori)
- {
- 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);
- EnterCriticalSection(&bantch_db_lock);
- bantch_db.execDML(sql.c_str());
- LeaveCriticalSection(&bantch_db_lock);
- }
- int CBatchService::RestoreStudentPaper(const std::string task_id, const std::string&task_type, rapidjson::Value&doc)
- {
- // 恢复
- std::string str_student_paper_sql = "INSERT INTO student_paper ("
- "ori_img, picFlag, location_id, paper_type, absent, score_total, file_name,"
- "student_id,paper_state,student_code,paper_code,img_upload,ret_upload,student_paper_id,task_id,task_type)VALUES "
- "("
- ":ori_img, :picFlag, :location_id, :paper_type, :absent, :score_total, :file_name,"
- ":student_id,:paper_state,:student_code,:paper_code,:img_upload,:ret_upload,:student_paper_id, :task_id, :task_type"
- ")";
- EnterCriticalSection(&bantch_db_lock);
- CppSQLite3Statement smt_stu_paper = bantch_db.compileStatement(str_student_paper_sql.c_str());
- smt_stu_paper.bind(":ret_upload", 0);
- smt_stu_paper.bind(":img_upload", 0);
- smt_stu_paper.bind(":task_id", task_id.c_str());
- smt_stu_paper.bind(":task_type", task_type.c_str());
- // student_code
- auto it_student_code = doc.FindMember("student_code");
- if (it_student_code != doc.MemberEnd() && it_student_code->value.IsString()){
- smt_stu_paper.bind(":student_code", it_student_code->value.GetString());
- }
- //paper_code
- auto it_paper_code = doc.FindMember("paper_code");
- if (it_paper_code != doc.MemberEnd() && it_paper_code->value.IsString()){
- smt_stu_paper.bind(":paper_code", it_paper_code->value.GetString());
- }
- //paper_state
- auto it_paper_state = doc.FindMember("paper_state");
- if (it_paper_state != doc.MemberEnd() && it_paper_state->value.IsInt()){
- smt_stu_paper.bind(":paper_state", it_paper_state->value.GetInt());
- }
- // student_id
- auto it_student_id = doc.FindMember("student_id");
- if (it_student_id != doc.MemberEnd() && it_student_id->value.IsString()){
- smt_stu_paper.bind(":student_id", it_student_id->value.GetString());
- }
- // picFlag
- auto it_picFlag = doc.FindMember("picFlag");
- if (it_picFlag != doc.MemberEnd() && it_picFlag->value.IsString()){
- smt_stu_paper.bind(":picFlag", it_picFlag->value.GetString());
- }
- // location_id
- auto it_location_id = doc.FindMember("location_id");
- if (it_location_id != doc.MemberEnd() && it_location_id->value.IsInt()){
- smt_stu_paper.bind(":location_id", it_location_id->value.GetInt());
- }
- // paper_type
- auto it_paper_type = doc.FindMember("paper_type");
- if (it_paper_type != doc.MemberEnd() && it_paper_type->value.GetString()){
- smt_stu_paper.bind(":paper_type", it_paper_type->value.GetString());
- }
- // absent
- auto it_absent = doc.FindMember("absent");
- if (it_absent != doc.MemberEnd() && it_absent->value.IsInt()){
- smt_stu_paper.bind(":absent", it_absent->value.GetInt());
- }
- // score_total
- auto it_score_total = doc.FindMember("score_total");
- if (it_score_total != doc.MemberEnd() && (it_score_total->value.IsInt() || it_score_total->value.IsDouble())){
- smt_stu_paper.bind(":score_total", it_score_total->value.GetDouble());
- }
- smt_stu_paper.execDML();
- CppSQLite3Query query = bantch_db.execQuery("select last_insert_rowId() from student_paper");
- int student_paper_id = query.getIntField(0);
- LeaveCriticalSection(&bantch_db_lock);
- return student_paper_id;
- }
- BOOL CBatchService::UpateErrorStudentData(const std::string&task_id)
- {
- BOOL bRet = TRUE;
- if (!task_id.empty()){
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- GetModuleFileName(NULL, exeFullPath, MAX_PATH);
- strPath = (CString)exeFullPath;
- int position = strPath.ReverseFind('\\');
- strPath = strPath.Left(position + 1);
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("paperinfo.ini"));
- WCHAR szUrl[512] = { 0 };
- GetPrivateProfileString(_T("paperinfo"), _T("errorhandleupdateurl"), _T(""), szUrl, 512, FilePath);
- WCHAR szSession[512] = { 0 };
- GetPrivateProfileString(_T("paperinfo"), _T("session"), _T(""), szSession, 512, FilePath);
- std::string url = UnicodeToAnsi(szUrl), exam_id = std::to_string(m_examId), session = UnicodeToAnsi(szSession);
- CString postData;
- postData.Format(_T("examGroupId=%s&taskIds=%s"), AnsiToUnicode(exam_id), AnsiToUnicode(task_id));
- postData.TrimRight(L",");
- std::string response;
- CHttpClient httpClient;
- httpClient.SetSendHeader(AnsiToUnicode(session));
- httpClient.HttpPost(AnsiToUnicode(url), postData, response);
- if (!response.empty()){
- Json::Features features;
- Json::Reader re(features);
- Json::Value root;
- re.parse(response, root);
- if (root.isMember("success") && root["success"].isInt() && root["success"].asUInt() == 1){
- bRet = TRUE;
- //printf("更新状态成功: url=%s session=%s postdata=%s\n", url.c_str(), session.c_str(), UnicodeToAnsi(postData).c_str());
- }
- else{
- //printf("更新状态失败: url=%s session=%s postdata=%s\n",url.c_str(),session.c_str(), UnicodeToAnsi(postData).c_str());
- }
- }
- }
- return bRet;
- }
- void CBatchService::InitUploadManager(bool bEanble, bool bCountiue, bool bErrorHanle, bool bOnlineCard, IUploudNotify*pNotify)
- {
- if (bEanble&&m_result_uploader){
- m_result_uploader->SetUploadOnScan(bEanble, -1, 0);
- }
- m_upload_manager.Init(bEanble, bCountiue, bErrorHanle,bOnlineCard, m_nSubjectID, pNotify, &bantch_db, &bantch_db_lock);
- }
- void CBatchService::OnScanListFilter(bool bsuccess,int nUploadState)
- {
- m_upload_manager.ScanListFilter(bsuccess,nUploadState);
- }
- int CBatchService::UploadOnScanCmd(int nCmd, const char*param, void*ret)
- {
- return m_upload_manager.UploadOnScanCmd(nCmd, param, -1, ret);
- }
- void DeleteDirectory(CString source);
- void CBatchService::QuickHandle(bool bGetPath, char*path_nor, int nor_len, char*path_exc, int exc_len)
- {
-
- CString str_nor_dir;
- CString str_exc_dir;
- if (bGetPath){
- str_nor_dir = m_excimg_dir + _T("\\nor\\");
- str_exc_dir = m_excimg_dir + _T("\\exc\\");
- DeleteDirectory(str_nor_dir);
- DeleteDirectory(str_exc_dir);
- CreateDirectory(str_nor_dir, NULL);
- CreateDirectory(str_exc_dir, NULL);
- if (str_exc_dir.GetLength()< nor_len){
- strcpy(path_exc, UnicodeToAnsi(str_exc_dir).c_str());
- }
- if (str_nor_dir.GetLength() < nor_len){
- strcpy(path_nor, UnicodeToAnsi(str_nor_dir).c_str());
- }
- }
- else{
- str_nor_dir = AnsiToUnicode(path_nor);
- str_exc_dir = AnsiToUnicode(path_exc);
- 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";
- EnterCriticalSection(&bantch_db_lock);
- if (bantch_db.is_open()){
- CppSQLite3Query qry = bantch_db.execQuery(sql.c_str());
- int i = 1;
- while (!qry.eof()){
- int state = qry.getIntField("paper_state");
- std::string path = qry.getStringField("img_oldpath");
- CString fileName;
- fileName.Format(_T("%09d.jpg"), i++);
- if (state == 0){
- CopyFileA(path.c_str(), UnicodeToAnsi(str_nor_dir + fileName).c_str(), FALSE);
- }
- else{
- CopyFileA(path.c_str(), UnicodeToAnsi(str_exc_dir + fileName).c_str(), FALSE);
- }
- qry.nextRow();
- }
- }
- LeaveCriticalSection(&bantch_db_lock);
- if (m_hwnd && ::IsWindow(m_hwnd))
- ::PostMessage(m_hwnd, WM_QUICK_HANDLE_STOPED, 0, 0);
- }
- }
- void CBatchService::SetErrorHandle(bool bErrorHandle)
- {
- m_bErrorHandle = bErrorHandle;
- m_result_uploader->SetErrorHandle(m_bErrorHandle);
- }
- static int g_page_id = 1;
- std::map<int, int> CBatchService::RestorePages(int paper_id, const std::string&path, rapidjson::Value&value)
- {
- std::map<int, int> ret;
- std::string sql_fmt = "INSERT INTO page(student_paper_id,identified,img_path,img_oldpath,page_id)VALUES(%d,%d,'%s','%s',%d)";
- EnterCriticalSection(&bantch_db_lock);
- for (auto it_page = value.Begin(); it_page != value.End();++it_page)
- {
- std::string _path="";
- int identified = -1;
- int page_id = 0;
- auto it_name = it_page->FindMember("name");
- if (it_name != it_page->MemberEnd()&& it_name->value.IsString()){
- auto name = it_name->value.GetString();
- _path = path + "ori\\image_" +name;
- }
- auto it_identify = it_page->FindMember("identified");
- if (it_identify != it_page->MemberEnd() && it_identify->value.IsInt()){
- identified = it_identify->value.GetInt();
- }
- auto it_page_id = it_page->FindMember("page_id");
- if (it_page_id != it_page->MemberEnd() && it_page_id->value.IsInt()){
- page_id = it_page_id->value.GetInt();
- ret[page_id] = g_page_id++;
- }
- char sz_sql[256] = { 0 };
- sprintf_s(sz_sql, sql_fmt.c_str(), paper_id, identified, _path.c_str(), _path.c_str(), ret[page_id]);
- bantch_db.execDML(sz_sql);
- }
- LeaveCriticalSection(&bantch_db_lock);
- std::string ori_path = path + "ori\\";
- CreateDirectoryA(ori_path.c_str(),NULL);
- for (int i = 0; i < 10; ++i)
- {
- CString tmp_path = AnsiToUnicode(path + "image_"+ std::to_string(i+1)+".jpg");
- if (PathFileExists(tmp_path)){
- MoveFile(tmp_path, AnsiToUnicode(ori_path + "image_" + std::to_string(i + 1) + ".jpg"));
- }
- else{
- break;
- }
- }
- return ret;
- }
- void CBatchService::RestoreException(int paper_id, rapidjson::Value&value, const std::map<int, int>&mapPageID)
- {
- std::string sql_fmt1 = "INSERT INTO exception(exception_type,exception_name,page_id,student_paper_id)VALUES(%d,'%s',%d,%d)";
- std::string sql_fmt2 = "INSERT INTO exception(exception_type,exception_name,student_paper_id)VALUES(%d,'%s',%d)";
- EnterCriticalSection(&bantch_db_lock);
- for (auto it_ex = value.Begin(); it_ex != value.End();++it_ex)
- {
- std::string exception_name;
- int exception_type = -1, page_id = -1, student_paper_id = -1;
- auto it_type = it_ex->FindMember("exception_type");
- if (it_type != it_ex->MemberEnd() && it_type->value.IsInt()){
- exception_type = it_type->value.GetInt();
- }
- auto it_page_id = it_ex->FindMember("page_id");
- if (it_page_id != it_ex->MemberEnd() && it_page_id->value.IsInt()){
- auto it_find_page_id = mapPageID.find(it_page_id->value.GetInt());
- if (it_find_page_id != mapPageID.end())
- {
- page_id = it_find_page_id->second;
- }
- }
- auto it_name = it_ex->FindMember("exception_name");
- if (it_name != it_ex->MemberEnd() && it_name->value.IsString()){
- exception_name = it_name->value.GetString();
- }
- char sz_sql[256] = { 0 };
- if (page_id==-1){
- sprintf_s(sz_sql, sql_fmt2.c_str(), exception_type, exception_name.c_str(), paper_id);
- }
- else{
- sprintf_s(sz_sql, sql_fmt1.c_str(), exception_type, exception_name.c_str(), page_id, paper_id);
- }
- bantch_db.execDML(sz_sql);
- }
- LeaveCriticalSection(&bantch_db_lock);
- }
- void CBatchService::RestoreResult(int paper_id, rapidjson::Value&value, const std::map<int, int>&mapPageID)
- {
- EnterCriticalSection(&bantch_db_lock);
- 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)";
- for (auto it_rst = value.Begin(); it_rst != value.End(); ++it_rst)
- {
- std::string answer, question_code;
- float score_paper = 0.0, score = 0.0;
- int type = 0, isright = 0, question_state = 0;
- int page_id = 0;
- auto it_answer = it_rst->FindMember("answer");
- if (it_answer != it_rst->MemberEnd() && it_answer->value.IsString()){
- answer = it_answer->value.GetString();
- }
- auto it_code = it_rst->FindMember("question_code");
- if (it_code != it_rst->MemberEnd() && it_code->value.IsString()){
- question_code = it_code->value.GetString();
- }
- auto it_state = it_rst->FindMember("question_state");
- if (it_state != it_rst->MemberEnd() && it_state->value.IsInt()){
- question_state = it_state->value.GetInt();
- }
- auto it_type = it_rst->FindMember("type");
- if (it_type != it_rst->MemberEnd() && it_type->value.IsInt()){
- type = it_type->value.GetInt();
- }
- auto it_page_id = it_rst->FindMember("page_id");
- if (it_page_id != it_rst->MemberEnd() && it_page_id->value.IsInt()){
- auto it_find_page_id = mapPageID.find(it_page_id->value.GetInt());
- if (it_find_page_id != mapPageID.end())
- {
- page_id = it_find_page_id->second;
- }
- }
- auto it_score_paper = it_rst->FindMember("score_paper");
- if (it_score_paper != it_rst->MemberEnd() && (it_score_paper->value.IsDouble() || it_score_paper->value.IsInt())){
- score_paper = it_score_paper->value.GetDouble();
- }
- auto it_score = it_rst->FindMember("score");
- if (it_score != it_rst->MemberEnd() && (it_score->value.IsDouble() || it_score->value.IsInt())){
- score = it_score->value.GetDouble();
- }
- auto it_is_right = it_rst->FindMember("isright");
- if (it_is_right != it_rst->MemberEnd() && it_is_right->value.IsBool()){
- isright = it_is_right->value.GetBool() ? 1 : 0;
- }
- char sz_sql[256] = { 0 };
- 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);
- bantch_db.execDML(sz_sql);
- }
- LeaveCriticalSection(&bantch_db_lock);
- }
- void CBatchService::RestoreStudent(rapidjson::Value&value)
- {
- EnterCriticalSection(&bantch_db_lock);
- std::string qry_sql = "select count(*) from student where ";
- 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 )";
- std::string studentCard, student_id, student_code, class_name, grade_name, student_name, schoolStudentCard;
- int recoverFlag = 0;
- long long school_id = 0, class_id = 0;
- float score_total = 0.0;
- auto it_student_code = value.FindMember("student_code");
- if (it_student_code != value.MemberEnd() && it_student_code->value.IsString()){
- student_code = it_student_code->value.GetString();
- }
- qry_sql += " student_code='" + student_code + "' and ";
- auto it_student_id = value.FindMember("student_id");
- if (it_student_id != value.MemberEnd() && it_student_id->value.IsString()){
- student_id = it_student_id->value.GetString();
- }
- qry_sql += " student_id='" + student_id + "' and ";
- auto it_school_id = value.FindMember("school_id");
- if (it_school_id != value.MemberEnd() && it_school_id->value.IsString()){
- std::string tmp = it_school_id->value.GetString();
- if (!tmp.empty()){
- school_id = std::stoll(tmp);
- }
- }
- qry_sql += " school_id=" + std::to_string(school_id) + " and ";
- auto it_class_id = value.FindMember("class_id");
- if (it_class_id != value.MemberEnd() && it_class_id->value.IsString()){
- std::string tmp = it_class_id->value.GetString();
- if (!tmp.empty()){
- class_id = std::stoll(tmp);
- }
- }
- qry_sql += " class_id=" + std::to_string(class_id);
- auto it_class_name = value.FindMember("class_name");
- if (it_class_name != value.MemberEnd() && it_class_name->value.IsString()){
- class_name = it_class_id->value.GetString();
- }
- auto it_grade_name = value.FindMember("grade_name");
- if (it_grade_name != value.MemberEnd() && it_grade_name->value.IsString()){
- grade_name = it_grade_name->value.GetString();
- }
- auto it_recoverFlag = value.FindMember("recoverFlag");
- if (it_recoverFlag != value.MemberEnd() && it_recoverFlag->value.IsInt()){
- recoverFlag = it_recoverFlag->value.GetInt();
- }
- auto it_schoolStudentCard = value.FindMember("schoolStudentCard");
- if (it_schoolStudentCard != value.MemberEnd() && it_schoolStudentCard->value.IsString()){
- schoolStudentCard = it_schoolStudentCard->value.GetString();
- }
- auto it_score_total = value.FindMember("score_total");
- if (it_score_total != value.MemberEnd() && (it_score_total->value.IsInt() || it_score_total->value.IsDouble())){
- score_total = it_score_total->value.GetDouble();
- }
- auto it_studentCard = value.FindMember("studentCard");
- if (it_studentCard != value.MemberEnd() && it_studentCard->value.IsString()){
- studentCard = it_studentCard->value.GetString();
- }
- auto it_student_name = value.FindMember("student_name");
- if (it_student_name != value.MemberEnd() && it_student_name->value.IsString()){
- student_name = it_student_name->value.GetString();
- }
- if (bantch_db.execScalar(qry_sql.c_str())<=0){
- char sz_sql[512] = { 0 };
- sprintf_s(sz_sql, sql_fmt.c_str(), studentCard.c_str(), recoverFlag, student_id.c_str(),
- 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);
- bantch_db.execDML(sz_sql);
- }
- LeaveCriticalSection(&bantch_db_lock);
- }
- void CBatchService::RestoreErrorHandleSite(const std::string& task_id, const std::string&type, const std::string& strPath)
- {
- std::string json_path = strPath + "json.txt";
- std::string str_json;
- int stu_paper_id = -1;
- readFile(json_path, str_json);
- try{
- if (!str_json.empty()){
- rapidjson::Document doc;
- doc.Parse(str_json.c_str());
- if (doc.HasParseError()) return;
- // 恢复student_paper表
- auto it_stu_paper = doc.FindMember("student_paper");
- if (it_stu_paper != doc.MemberEnd() && it_stu_paper->value.IsObject())
- stu_paper_id = RestoreStudentPaper(task_id, type, it_stu_paper->value);
- std::map<int, int> mapPageID;
- // 恢复page表
- auto it_pages = doc.FindMember("pages");
- if (it_pages != doc.MemberEnd() && it_pages->value.IsArray()){
- mapPageID = RestorePages(stu_paper_id, strPath, it_pages->value);
- }
- //RestoreFile(stu_paper_id, strPath + "rst.zip", strPath + "ori.zip");
- RestoreFile(stu_paper_id, strPath + "rst\\img", strPath + "ori");
- // 恢复异常表
- auto it_exception = doc.FindMember("exceptions");
- if (stu_paper_id > 0 && it_exception != doc.MemberEnd() && it_exception->value.IsArray())
- RestoreException(stu_paper_id, it_exception->value, mapPageID);
- // 恢复resut表
- auto it_result = doc.FindMember("result");
- if (stu_paper_id > 0 && it_result != doc.MemberEnd() && it_result->value.IsArray())
- RestoreResult(stu_paper_id, it_result->value, mapPageID);
- // 恢复student表
- auto it_student = doc.FindMember("student");
- if (it_student != doc.MemberEnd() && it_student->value.IsObject())
- RestoreStudent(it_student->value);
- }
- }
- catch (CppSQLite3Exception&e){
- ::MessageBoxA(NULL, e.errorMessage(), "提示", MB_OK);
- }
- if (m_hwnd != NULL)
- ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, 0, stu_paper_id);
- }
- void CBatchService::leaveCurrentBatch()
- {
- if (m_upload_manager.IsEanble()){
- m_upload_manager.SetNotifyPtr(nullptr);
- NetOperator::SetClientNotifyPtr(nullptr);
- NetOperator::ClientStop();
- }
- }
- void CBatchService::OnNetNotify(const char*data)
- {
- LOGFMTI("from zxhx:%s",data);
- if (!data) return;
- rapidjson::Document root;
- root.Parse(data);
- if (!root.HasParseError()){
- auto it_task_type = root.FindMember("net_task_type");
- auto it_cmd = root.FindMember("net_task_cmd");
- if (it_cmd != root.MemberEnd() && it_task_type!= root.MemberEnd()){
-
- std::string task_type = it_task_type->value.GetString();
- std::string cmd = it_cmd->value.GetString();
- if (task_type == "systerm_notify"){
- if (cmd == "server_error"||cmd =="server_close"){
- LOGI("IPC出错,开始重连");
- m_upload_manager.OnTcpError();
- std::async(std::launch::async, [&](){
- NetOperator::ClientStop();
- int nIndex = 1;
- while (NetOperator::InitClient("127.0.0.1", 99995, this) < 0 && nIndex < 100){
- LOGFMTI("第%d次重连失败 %d秒后再次重连", nIndex, nIndex * 2000);
- Sleep(nIndex * 2000);
- nIndex++;
- }
- if (nIndex < 100){
- LOGI("IPC出错,重连成功");
- m_upload_manager.OnReConnect(true);
- }
- else{
- LOGE("IPC出错,重连失败");
- m_upload_manager.OnReConnect(false);
- }
- });
- }
- }
- else{
- // 边扫描边上传服务
- if (m_upload_manager.IsEanble()){
- if (task_type == "upload_on_scan_upload"){
- m_upload_manager.OnNetNotify(data);
- }
- }
- // 未来可能添加的其他服务
- }
- }
- else{
- LOGE("data from zxhx is 非法数据包 ");
- }
- }
- else{
- LOGE("data from zxhx is not a json");
- }
- }
- int CBatchService::ExamineThisScan(PAPER_DETAIL &paper_detail)
- {
- EnterCriticalSection(&bantch_db_lock);
- char sql[512] = { 0 };
- sprintf_s(sql, "select * from student_paper where student_id='%s' and ret_upload=0", paper_detail.student_id);
- bool bExsit(false);
- CppSQLite3Query q = bantch_db.execQuery(sql);
- while (!q.eof())
- {
- int paper_id = q.getIntField(0);
- if (paper_detail.paper_id == paper_id)
- {
- bExsit = true;
- break;
- }
- q.nextRow();
- }
- LeaveCriticalSection(&bantch_db_lock);
- return bExsit;
- }
- int CBatchService::SetAbsentExam(PAPER_DETAIL &paper_detail, int absent)
- {
- EnterCriticalSection(&bantch_db_lock);
- int state = paper_detail.exceptionsFlag;
- if (1 == absent || 2 == absent)
- {
- if (state & EX_SHIJUANQUEKAO)
- {
- state ^= EX_SHIJUANQUEKAO;
- }
- if (2 == absent)
- {
- if (state & EX_KEGUANTIYICHANG)
- {
- state ^= EX_KEGUANTIYICHANG;
- }
- }
- }
- if (3 == absent)
- {
- if (state & EX_KEGUANTIYICHANG)
- {
- state ^= EX_KEGUANTIYICHANG;
- }
- }
- char sql[512] = { 0 };
-
- if (1 == absent){
- sprintf_s(sql, "update student_paper set paper_state=%d, absent=0 where student_paper_id=%d", state, paper_detail.paper_id);
- }
- else if (2 == absent){
- sprintf_s(sql, "update student_paper set paper_state=%d where student_paper_id=%d", state, paper_detail.paper_id);
- }
- else if (3 == absent){
- sprintf_s(sql, "update student_paper set paper_state=%d, absent=1 where student_paper_id=%d", state, paper_detail.paper_id);
- }
- int rlt = bantch_db.execDML(sql);
- LeaveCriticalSection(&bantch_db_lock);
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)100, (LPARAM)paper_detail.paper_id);
- return rlt;
- }
- int CBatchService::QueryKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList)
- {
- EnterCriticalSection(&bantch_db_lock);
- char sql[1024] = { 0 };
- 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, " \
- " (select count(1) from result where result.student_paper_id = %d and result.type IN(4, 8)) as orgin_count" \
- " from result left join question_std on result.question_code = question_std.question_code" \
- " where result.student_paper_id = %d" \
- " and result.type in(4, 8)" \
- " 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);
- CppSQLite3Query q = bantch_db.execQuery(sql);
- while (!q.eof())
- {
- KEGUANTI_DETAIL keguanti;
- strcpy_s(keguanti.question_code, q.getStringField("question_code"));
- strcpy_s(keguanti.answer_all, q.getStringField("answer_all"));
- strcpy_s(keguanti.answer_std, q.getStringField("answer_std"));
- strcpy_s(keguanti.answer, q.getStringField("answer"));
- keguanti.question_type = q.getIntField("question_type");
- keguanti.score_full = q.getFloatField("score_full");
- keguanti.score_half = q.getFloatField("score_half");
- keguanti.question_nick_code = m_mapKeguantiNickName[keguanti.question_code];
- keguantiList.push_back(keguanti);
- q.nextRow();
- }
- LeaveCriticalSection(&bantch_db_lock);
- return TRUE;
- }
- int CBatchService::UpdateKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList)
- {
- try
- {
- EnterCriticalSection(&bantch_db_lock);
- m_scoreCounter.Load();
- database_db->execDML("begin transaction");
- float score_total = 0; // 本次客观题异常经过修正后所增加的分数
- for (auto& iter : keguantiList)
- {
- // 更新客观题分数
- iter.score = m_scoreCounter.GetScore(iter.question_code, iter.answer, 0, 0);
- 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)");
- stmt.bind(":answer", iter.answer);
- stmt.bind(":score", iter.score);
- stmt.bind(":score_paper", iter.score);
- stmt.bind(":question_code", iter.question_code);
- stmt.bind(":student_paper_id", paper_id);
- stmt.execDML();
- score_total += iter.score;
- }
- 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");
- stmt.bind(":paper_state", EX_KEGUANTIYICHANG);
- stmt.bind(":score_total", score_total);
- stmt.bind(":student_paper_id", paper_id);
- stmt.execDML();
- database_db->execDML("commit transaction");
- }
- catch (...)
- {
- database_db->execDML("rollback transaction");
- OutputDebugString(_T("IResultHandler.SavePaper.catch CppSQLite3Exception"));
- }
- LeaveCriticalSection(&bantch_db_lock);
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)100, (LPARAM)paper_id);
- return TRUE;
- }
|