123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663 |
- #include "stdafx.h"
- #include "BatchInfo.h"
- #include "log.h"
- #include "io.h"
- //#include "qcloud.h"
- #include "Util.h"
- #include "../cloud/CloudApi.h"
- #include "sys/stat.h"
- #include "../Util/typedef_struct.h"
- #include <codecvt>
- #include <algorithm>
- extern CLog g_log;
- extern HWND g_MsgWnd;
- extern string g_SchoolId;
- extern string g_ServerUrl;
- volatile bool g_ScanThreadRun = true;
- volatile bool g_IsPagesMissed = false;
- static string getBatchCode(string workDir)
- {
- vector<string> strs = splitEx(workDir, "/");
- return strs[strs.size() - 1];
- }
- bool testServerAvaiable3(const CString& serverAdd)
- {
- std::string response;
- CHttpClient httpClient;
- CString url = _T("http://124.71.233.218:17002/teacher/third/card/location?cardId=106&taskId=");
- //url.Format(_T("%s/course/findAllCourse"), serverAdd);
- //httpClient.SetSendHeader(L"");
- 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;
- }
- string UtfToGbk(string strValue)
- {
- int len = MultiByteToWideChar(CP_UTF8, 0, strValue.c_str(), -1, NULL, 0);
- wchar_t* wstr = new wchar_t[len + 1];
- memset(wstr, 0, len + 1);
- MultiByteToWideChar(CP_UTF8, 0, strValue.c_str(), -1, wstr, len);
- len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
- char* str = new char[len + 1];
- memset(str, 0, len + 1);
- WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
- if (wstr)
- delete[] wstr;
- string strRet = string(str);
- if (str)
- delete[] str;
- return strRet;
- }
- std::wstring ANSIToUnicode(const std::string & str)
- {
- std::wstring ret;
- std::mbstate_t state = {};
- const char *src = str.data();
- size_t len = std::mbsrtowcs(nullptr, &src, 0, &state);
- if (static_cast<size_t>(-1) != len) {
- std::unique_ptr< wchar_t[] > buff(new wchar_t[len + 1]);
- len = std::mbsrtowcs(buff.get(), &src, len, &state);
- if (static_cast<size_t>(-1) != len) {
- ret.assign(buff.get(), len);
- }
- }
- return ret;
- }
- string UnicodeToUTF8(const std::wstring & wstr)
- {
- std::string ret;
- try {
- std::wstring_convert< std::codecvt_utf8<wchar_t> > wcv;
- ret = wcv.to_bytes(wstr);
- }
- catch (const std::exception & e) {
- std::cerr << e.what() << std::endl;
- }
- return ret;
- }
- WCHAR *ToUnicode(const char *zFilename)
- {
- int nByte;
- WCHAR *zMbcsFilename;
- int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
- nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL, 0)*sizeof(WCHAR);
- zMbcsFilename = (WCHAR *)malloc(nByte*sizeof(zMbcsFilename[0]));
- if (zMbcsFilename == 0)
- {
- return 0;
- }
- nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
- if (nByte == 0)
- {
- free(zMbcsFilename);
- zMbcsFilename = 0;
- }
- return zMbcsFilename;
- }
- string ToUtf8(const string strSrc)
- {
- string strRet;
- strRet = UnicodeToUTF8(ToUnicode(strSrc.c_str()));
- return strRet;
- }
- //void CopyAllFile(CString dest, CString source)
- //{
- // //AfxMessageBox("创建文件夹"+target);
- // CFileFind finder;
- // CString path;
- // path.Format(_T("%s/*.*"), source);
- // BOOL bWorking = finder.FindFile(path);
- // while (bWorking){
- // bWorking = finder.FindNextFile();
- // if (finder.IsDirectory() && !finder.IsDots()){ //是文件夹 而且 名称不含 . 或 ..
- // CString fTemp;
- // fTemp = dest + finder.GetFileName() + _T("\\");
- // CreateDirectory(fTemp, NULL);
- // CopyAllFile(fTemp, finder.GetFilePath()); //递归创建文件夹+"/"+finder.GetFileName()
- // }
- // else{ //是文件 拷贝文件
- // CopyFile(finder.GetFilePath(), dest + finder.GetFileName(), FALSE);
- // }
- // }
- // RemoveDirectory(source);
- //}
- //
- //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();
- // }
- // }
- // }
- //}
- batch_info GetBatchInfo(int batch_id)
- {
- batch_info info;
- CppSQLite3DB index_db;
- try
- {
- //将数据库文件的路径转换为utf-8编码,以解决中文路径下扫描程序崩溃的问题
- index_db.open(ToUtf8(g_Indexdb).c_str());
- }
- catch (CException* e)
- {
- g_log.PutMsg(LogLvlFailed, "开启index.db3失败 ");
- return info;
- }
- CppSQLite3Query query0;
- char sql[256];
- sprintf_s(sql, "select * from batchs where id=%d", batch_id);
- query0 = index_db.execQuery(sql);
- string strVal;
- if (!query0.eof())
- {
- info.id = batch_id;
- strcpy_s(info.create_time, query0.getStringField("create_time"));
- strVal = query0.getStringField("batchdb_path");
- strVal = ToUtf8(UtfToGbk(strVal));
- strcpy_s(info.batchdb_path, strVal.c_str());
- strVal = query0.getStringField("work_dir");
- //strVal = UtfToGbk(strVal);
- strcpy_s(info.work_dir, strVal.c_str());
- info.state = query0.getIntField("state");
- info.total_cnt = query0.getIntField("total_cnt");
- info.success_cnt = query0.getIntField("success_cnt");
- }
- query0.finalize();
- index_db.close();
- return info;
- }
- bool ParseTemplateFromJson(const std::string&fileName, OnLineCard::PaperTemplate* pOnlineCardTemplate)
- {
- 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 (!pOnlineCardTemplate) return false;
- pOnlineCardTemplate->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;
- pOnlineCardTemplate->subject_id = 0;
- pOnlineCardTemplate->_version = "old";
- // 检测版本号
- auto it_version = doc.FindMember("online_card_version");
- if (it_version != doc.MemberEnd() && it_version->value.IsString()){
- pOnlineCardTemplate->_version = it_version->value.GetString();
- }
- LOGFMTI("在线答题卡版本号:%s", pOnlineCardTemplate->_version.c_str());
- if (pOnlineCardTemplate->_version == "old"){
- // 总页数
- auto itTotalPage = doc.FindMember("totalPage");
- if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
- pOnlineCardTemplate->totalPage = itTotalPage->value.GetInt();
- }
- // 是否使用二维码
- auto itUseQrCode = doc.FindMember("useQrCode");
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
- pOnlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
- }
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
- pOnlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
- }
- // 学校状态
- auto itSchoolStatus = doc.FindMember("school_card_status");
- if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
- pOnlineCardTemplate->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() == pOnlineCardTemplate->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 (!pOnlineCardTemplate->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();
- else if (itFull != itScore->value.MemberEnd() && itFull->value.IsString())
- q.score = atof(itFull->value.GetString());
- }
- // 题目编号 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);
- }
- }
- 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);
- }
- }
- pOnlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
- }
- }
- else{
- return false;
- }
- }
- else{
- // 总页数
- auto itTotalPage = doc.FindMember("totalPage");
- if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
- pOnlineCardTemplate->totalPage = itTotalPage->value.GetInt();
- }
- // 是否使用二维码
- auto itUseQrCode = doc.FindMember("useQrCode");
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
- pOnlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
- }
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
- pOnlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
- }
- // 学校状态
- auto itSchoolStatus = doc.FindMember("school_card_status");
- if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
- pOnlineCardTemplate->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 (!pOnlineCardTemplate->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();
- else if (itFull != itScore->value.MemberEnd() && itFull->value.IsString())
- q.score = atof(itFull->value.GetString());
- }
- // 题目编号 2选做题 4题组
- 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())
- {
- }
- // 打分区域
- 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 && pOnlineCardTemplate->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);
- }
- }
- pOnlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
- }
- }
- else{
- return false;
- }
- }
- pOnlineCardTemplate->open_save_debug_img = false;
- pOnlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
- pOnlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
- pOnlineCardTemplate->dingweidian_w_max_rate = 1.0;
- pOnlineCardTemplate->dingweidian_h_max_rate = 1.0;
- pOnlineCardTemplate->dingweidian_w_min_rate = 0.7;
- pOnlineCardTemplate->dingweidian_h_min_rate = 0.7;
- return true;
- }
- bool CBatch_Server::ParseTemplateFromJsonAll(const std::string&fileName, OnLineCard::PaperTemplate* pOnlineCardTemplate)//全学科在线答题卡
- {
- qid_name.clear();
- //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["12"] = 0; type_map["10"] = 1; type_map["11"] = 1; type_map["12"] = 0;
- /*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());*/
- string strJson = fileName;
- if (!pOnlineCardTemplate) return false;
- pOnlineCardTemplate->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;
- }
- if (x<0 || y<0 || w<0 || h<0)
- {
- throw "pos illegal";
- }
- return std::tie(bRet, Pos{ x, y, w, h });
- };
- rapidjson::Document root;
- root.Parse(strJson.c_str());
- if (root.HasParseError()) return false;
- pOnlineCardTemplate->subject_id = 0;
- pOnlineCardTemplate->_version = "3.1.0";
- auto data = root.FindMember("data");
- if (data == root.MemberEnd())
- {
- return false;
- }
- //auto doc = data->value.FindMember;
- // 检测版本号
- auto it_version = data->value.FindMember("online_card_version");
- if (it_version != data->value.MemberEnd() && it_version->value.IsString()){
- pOnlineCardTemplate->_version = it_version->value.GetString();
- }
- {
- // 总页数
- auto itTotalPage = data->value.FindMember("totalPage");
- if (itTotalPage != data->value.MemberEnd() && itTotalPage->value.IsInt()){
- pOnlineCardTemplate->totalPage = itTotalPage->value.GetInt();
- }
- // 是否使用二维码
- auto itUseQrCode = data->value.FindMember("useQrCode");
- if (itUseQrCode != data->value.MemberEnd() && itUseQrCode->value.IsBool()){
- pOnlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
- }
- if (itUseQrCode != data->value.MemberEnd() && itUseQrCode->value.IsInt()){
- pOnlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
- }
- // 学科名
- auto itSubject = data->value.FindMember("subject_name");
- if (itSubject != data->value.MemberEnd() && itSubject->value.IsString()){
- pOnlineCardTemplate->subject_name = itSubject->value.GetString();
- }
- // 考试名
- auto itCardName = data->value.FindMember("cardName");
- if (itCardName != data->value.MemberEnd() && itCardName->value.IsString()){
- pOnlineCardTemplate->exam_name = itCardName->value.GetString();
- }
- pOnlineCardTemplate->useQrCode = false;
- // 学校状态
- auto itSchoolStatus = data->value.FindMember("school_card_status");
- if (itSchoolStatus != data->value.MemberEnd() && itSchoolStatus->value.IsInt()){
- pOnlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
- }
- int n_duo_xuanti_index = 0;
- std::string temp_all_id = "";
- // 页
- auto itPages = data->value.FindMember("pages");
- if (itPages != data->value.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 (!pOnlineCardTemplate->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;
- q.cut.linkparm = 0;
- // 题目类型
- auto itType = it->FindMember("type");
- string qType = "1";
- if (itType != it->MemberEnd() && itType->value.IsString())
- {
- qType = itType->value.GetString();
- if (type_map.find(qType) != type_map.end())
- {
- q.type = type_map[qType];
- }
- }
- else if (itType != it->MemberEnd() && itType->value.IsInt())
- {
- qType = to_string(itType->value.GetInt());
- if (type_map.find(qType) != type_map.end())
- {
- q.type = type_map[qType];
- }
- }
- else
- {
- return false;
- }
- auto itName = it->FindMember("name");
- if (itType != it->MemberEnd() && itName->value.IsString())
- {
- q.name = itName->value.GetString();
- }
- else if (itName != it->MemberEnd() && itName->value.IsInt())
- {
- q.name = to_string(itName->value.GetInt());
- }
- q.marktype = 0;
- // 题目类型
- auto itMarktype = it->FindMember("marktype");
- if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
- q.marktype = itMarktype->value.GetInt();
- }
- //if (qType == "10")//英文作文
- //{
- // q.marktype = 10;
- // q.type = 1;
- //}
- //else if (qType == "11")//语文作文
- //{
- // q.marktype = 4;
- // q.type = 1;
- //}
- /*else*/
- //if (qType == "12")//判断
- //{
- // q.type = 0;
- //}
- // 分数
- 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();
- else if (itFull != itScore->value.MemberEnd() && itFull->value.IsString())
- q.score = atof(itFull->value.GetString());
- }
- // 题目编号 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.IsString())
- {
- //m_mapKeguantiNickName[q.id] = itNickID->value.GetString();
- }
- // 打分区域
- 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{
- g_log.PutMsg(LogLvlFailed, "错误 打分框无类型 %s 题号=%s ", m_batchDbPath.c_str(), q.id.c_str());
- 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 && pOnlineCardTemplate->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);
- }
- }
- }
- qid_name[q.id] = q.name;
- page.vctQuestions.push_back(q);
- }
- }
- pOnlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
- }
- }
- else{
- return false;
- }
- }
- pOnlineCardTemplate->open_save_debug_img = false;
- pOnlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
- pOnlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
- pOnlineCardTemplate->dingweidian_w_max_rate = 1.0;
- pOnlineCardTemplate->dingweidian_h_max_rate = 1.1;
- pOnlineCardTemplate->dingweidian_w_min_rate = 0.7;
- pOnlineCardTemplate->dingweidian_h_min_rate = 0.7;
- pOnlineCardTemplate->useQrCode = false;
- return true;
- }
- bool ParseTemplateFromJsonAll2(const std::string&fileName, OnLineCard::PaperTemplate* pOnlineCardTemplate)//全学科在线答题卡
- {
- //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["12"] = 0; /*type_map["10"] = 1; type_map["11"] = 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 (!pOnlineCardTemplate) return false;
- pOnlineCardTemplate->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;
- pOnlineCardTemplate->subject_id = 0;
- pOnlineCardTemplate->_version = "3.1.0";
- // 检测版本号
- auto it_version = doc.FindMember("online_card_version");
- if (it_version != doc.MemberEnd() && it_version->value.IsString()){
- pOnlineCardTemplate->_version = it_version->value.GetString();
- }
- LOGFMTI("在线答题卡版本号:%s", pOnlineCardTemplate->_version.c_str());
- {
- // 总页数
- auto itTotalPage = doc.FindMember("totalPage");
- if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
- pOnlineCardTemplate->totalPage = itTotalPage->value.GetInt();
- }
- // 是否使用二维码
- auto itUseQrCode = doc.FindMember("useQrCode");
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
- pOnlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
- }
- if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
- pOnlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
- }
- // 学校状态
- auto itSchoolStatus = doc.FindMember("school_card_status");
- if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
- pOnlineCardTemplate->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 (!pOnlineCardTemplate->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();
- if (type_map.find(qType) != type_map.end())
- {
- q.type = type_map[qType];
- }
- }
- else if (itType != it->MemberEnd() && itType->value.IsInt())
- {
- qType = to_string(itType->value.GetInt());
- if (type_map.find(qType) != type_map.end())
- {
- q.type = type_map[qType];
- }
- }
- else
- {
- return false;
- }
- q.marktype = 0;
- // 题目类型
- auto itMarktype = it->FindMember("marktype");
- if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
- q.marktype = itMarktype->value.GetInt();
- }
- if (qType == "10")//英文作文
- {
- q.marktype = 10;
- q.type = 1;
- }
- else if (qType == "11")//语文作文
- {
- q.marktype = 4;
- q.type = 1;
- }
- else if (qType == "12")//判断
- {
- q.type = 0;
- }
- // 分数
- 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();
- else if (itFull != itScore->value.MemberEnd() && itFull->value.IsString())
- q.score = atof(itFull->value.GetString());
- }
- // 题目编号 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.IsString())
- {
- //m_mapKeguantiNickName[q.id] = itNickID->value.GetString();
- }
- // 打分区域
- 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 && pOnlineCardTemplate->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);
- }
- }
- pOnlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
- }
- }
- else{
- return false;
- }
- }
- pOnlineCardTemplate->open_save_debug_img = false;
- pOnlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
- pOnlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
- pOnlineCardTemplate->dingweidian_w_max_rate = 1.0;
- pOnlineCardTemplate->dingweidian_h_max_rate = 1.0;
- pOnlineCardTemplate->dingweidian_w_min_rate = 0.7;
- pOnlineCardTemplate->dingweidian_h_min_rate = 0.7;
- pOnlineCardTemplate->useQrCode = false;
- return true;
- }
- bool CreateDir(char* path)
- {
- if (_access(path, 0) == 0)
- {
- return true;
- }
- int ret = 0;
- char* szBefore = path;
- while (*szBefore)
- {
- if (*szBefore == '/' || *szBefore == '\\')
- {
- char szDir[512] = { 0 };
- strncpy_s(szDir, 512, path, szBefore - path);
- if (_access(szDir, 0) != 0)
- {
- ret = _mkdir(szDir);
- }
- }
- szBefore++;
- }
- if (_access(path, 0) != 0)
- {
- ret = _mkdir(path);
- }
- return true;
- }
- wstring strA2W(const string &str)
- {
- int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
- wchar_t *wstr = new wchar_t[len + 2];
- memset(wstr, 0, (2 + len)*sizeof(wchar_t));
- MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, wstr, len);
- wstring cstrDestW = wstr;
- delete[] wstr;
- return cstrDestW;
- }
- string strW2A(const wstring &wstr)
- {
- int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
- char *str = new char[len + 2];
- memset(str, 0, len + 2);
- WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, str, len, NULL, NULL);
- string cstrDestA = str;
- delete[] str;
- return cstrDestA;
- }
- vector<string> splitEx(const string& src, string separate_character)
- {
- vector<string> strs;
- int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符
- int lastPosition = 0, index = -1;
- while (-1 != (index = src.find(separate_character, lastPosition)))
- {
- strs.push_back(src.substr(lastPosition, index - lastPosition));
- lastPosition = index + separate_characterLen;
- }
- string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容
- if (!lastString.empty())
- strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队
- return strs;
- }
- //处理字符串中的单引号,以解决执行sql语句是因字段包含单引号而异常的问题
- string handleApostrophe(const string & strSrc)
- {
- vector<string> strVec = splitEx(strSrc, "'");
- string strRet;
- if (strVec.size() == 1)
- strRet = strSrc;
- else
- {
- int i = 0;
- const int nSize = strVec.size();
- for (; i < nSize; i++)
- {
- strRet += strVec.at(i);
- if (i < nSize - 1)
- strRet += "''";
- }
- }
- return strRet;
- }
- DWORD WINAPI SaveCutImageThread(void* param)
- {
- saveImgesPara *para = (saveImgesPara *)param;
- vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
- CString dir = para->dir;
- bool flag = para->flag;
- int subjectID = para->subjectID;
- std::string area_name;
- CString savePath;
- CFile file;
- try
- {
- if ((*area_results)[0]->area_name == "37")
- {
- int a = 1;
- a++;
- }
- if ((*area_results)[0]->area_name == "")
- {
- area_name = (*area_results)[0]->area_name;
- int idx;
- area_name = ((idx = area_name.find('.')) < 0) ? area_name : area_name.substr(0, idx);
- CString question_code;
- question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str()));
- savePath = dir + question_code;
- }
- else
- {
- area_name = (*area_results)[0]->area_name;
- CString question_code;
- question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str()));
- savePath = dir + question_code;
- }
- if ((*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){
- int width = 0;
- int height = 0;
- for (int jj = 0; jj < (*area_results).size(); jj++)
- {
- if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width;
- height += (*area_results)[jj]->height;
- }
- cv::Mat img_big(cv::Size(width, height), CV_8UC3, cv::Scalar(255, 255, 255));
- for (int ii = 0, top = 0; ii < (*area_results).size(); ii++)
- {
- Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data());
- Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_COLOR);
- cv::Rect rc_tmp(0, top, temp_img.cols, temp_img.rows);
- Mat cut = img_big(rc_tmp);
- temp_img.copyTo(cut);
- top += temp_img.rows;
- }
- //////////////////////////////////////////////////////////////////////////
- vector<uchar> dst;
- vector<int> compression_params;
- compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params.push_back(25);
- imencode(".jpg", img_big, dst, compression_params);
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write(dst.data(), dst.size());
- file.Close();
- if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1)
- {
- CString question_code;
- question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str()));
- savePath = dir + question_code;
- //file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- //file.Write(dst.data(), dst.size());
- //file.Close();
- }
- }
- else
- {
- if ((*area_results)[0]->is_cut > 0)
- {
- if (file.Open(savePath, CFile::modeCreate | CFile::modeWrite)){
- file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
- file.Close();
- }
- else{
- auto e = GetLastError();
- int n = 0; ++n;
- }
- if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1)
- {
- CString question_code;
- question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str()));
- savePath = dir + question_code;
- //file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- //file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
- //file.Close();
- }
- }
- else
- {
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
- file.Close();
- }
- }
- if (flag && (*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){
- vector<int> compression_params_low;
- compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_low.push_back(40);
- vector<int> compression_params_high;
- compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
- compression_params_high.push_back(60);
- for (int jj = 0; jj < (*area_results).size(); jj++)
- {
- CString question_code;
- question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj);
- savePath = dir + question_code;
- file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
- file.Write((*area_results)[jj]->img_data.data(), (*area_results)[jj]->img_data.size());
- file.Close();
- }
- }
- para->path1 = area_name;
- para->bSaved = true;
- }
- catch (CMemoryException* e)
- {
- }
- catch (CFileException* e)
- {
- para->bSaved = true;
- }
- catch (CException* e)
- {
- }
- return 0;
- }
- DWORD WINAPI UploadImageThread(void* param)
- {
- uploadImgPara *para = (uploadImgPara *)param;
- return 0;
- }
- int ScanPaper(CBatch_Server* batchInfo, Paper_Page* paper)
- {
- CreateDir((char*)paper->result_dir.c_str());
- paper->scan_time = std::time(0);
- DWORD t0 = GetTickCount();
- for (int i = 0; i < 2; i++)
- {
- PageIdentify identify;
- identify.SetTemplate(batchInfo->m_onlineCardTemplate);
- OMR_RESULT *result_buffer = paper->result[i];
- string strPath = /*UtfToGbk*/(paper->path[i]);
- IplImage *src = cvLoadImage(strPath.c_str());
- if (src == NULL)
- {
- paper->exc_code = paper_exc_open_fail;
- paper->err_msg = "paper_exc_open_fail";
- return IDF_FAILURE;
- }
- IplImage * dst = NULL;
- SchemaPage* pschemaPage1 = NULL;
- CvMemStorage* storage = cvCreateMemStorage(0);
- auto act1 = finally([&]
- {
- if (src != NULL)cvReleaseImage(&src);
- src = NULL;
- if (dst != NULL)cvReleaseImage(&dst);
- dst = NULL;
- if (pschemaPage1 != NULL)delete pschemaPage1;
- pschemaPage1 = NULL;
- cvReleaseMemStorage(&storage);
- storage = NULL;
- });
- {
- std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds> tp = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now());
- auto tmp = std::chrono::duration_cast<std::chrono::microseconds>(tp.time_since_epoch());
- std::time_t timestamp = tmp.count();
- std::string imagePath = paper->result_dir + "schema/";
- CreateDirectoryA(imagePath.c_str(), NULL);
- std::string path = imagePath + std::to_string(timestamp) + ".jpg";
- paper->path_jiaozheng[i] = path;
- }
- int ret = identify.createSchema(src, &dst, &pschemaPage1, paper->result_dir.c_str(), paper->path_jiaozheng[i], false);
- if (ret != identify::result::IDF_SUCCESS) {
- return ret;
- }
- identify.out_result = result_buffer;
- identify.omr_result = (identify::result::OMR_RESULT*)identify.out_result;
- SchemaPage& schemaPage = *pschemaPage1;
- identify.omr_result->is_front_page = schemaPage.is_front_page;
- identify.omr_result->examid_by_qr_code = schemaPage.examid_by_qr_code;
- identify.omr_result->strMagicStudentId = schemaPage.student_code;
- /************************读取学生学号*********************************************/
- if (schemaPage.is_front_page)
- {
- identify.ReadStudentID(schemaPage, dst);
- if (identify.omr_result->qr_result.size()>0)
- {
- paper->student_code = identify.omr_result->qr_result[0].qr_str;
- }
- /************************读取缺考标记*********************************************/
- identify.omr_result->quekaoFlag = identify.ReadQuekaoFlag(schemaPage, dst);
- /************************客观题()*********************************************/
- paper->qr_code = schemaPage.paper_id;
- //paper->student_code=schemaPage.
- }
- identify.ReadKeGuanTi(schemaPage, dst);
- //LOGI("Identify_impl 3");
- /************************查找题目定位点,准备定位数据*********************************************/
- //ret = identify.FindQuestionLocatePoints(schemaPage, dst);
- //if (ret != identify::result::IDF_SUCCESS) {
- // return;
- //}
- //LOGI("Identify_impl 4");
- /************************阅卷读取*************************************************/
- identify.ReadQuestionScore(schemaPage, dst, storage);
- //LOGI("Identify_impl 6");
- /************************根据给定区域切割图片*********************************************/
- identify.ClipImg(schemaPage, dst);
- identify.omr_result->card_index = schemaPage.index;
- {
- IplImage*src_debug = cvCloneImage(dst);
- batchInfo->DrawSchema(src_debug, &schemaPage, identify.omr_result);
- cvSaveImage(paper->path_jiaozheng[i].c_str(), src_debug);
- cvReleaseImage(&src_debug);
- }
- }
- if (paper->result[0]->is_front_page == paper->result[1]->is_front_page)
- {
- paper->exc_code = paper_exc_pages_missed;
- return IDF_FAILURE;
- }
- vector<saveImgesPara*> vct_saveImges;
- map<string, int> cut_area_map;
- if (paper->result[0]->is_front_page == false)
- {
- OMR_RESULT* restemp = paper->result[0];
- paper->result[0] = paper->result[1];
- paper->result[1] = restemp;
- string pathtemp = paper->path[0];
- paper->path[0] = paper->path[1];
- paper->path[1] = pathtemp;
- pathtemp = paper->path_jiaozheng[0];
- paper->path_jiaozheng[0] = paper->path_jiaozheng[1];
- paper->path_jiaozheng[1] = pathtemp;
- }
- for (int i = 0; i < 2; i++)
- {
- OMR_RESULT *m_result_buffer = paper->result[i];
- for (int j = 0; j < m_result_buffer->cut_area_result.size(); j++)
- {
- if (cut_area_map.find(m_result_buffer->cut_area_result[j].area_name) != cut_area_map.end())//已经生成过了
- {
- continue;
- }
- string cut_name = m_result_buffer->cut_area_result[j].area_name;
- vector<CUT_AREA_RESULT*>* area_rst = new vector<CUT_AREA_RESULT*>;
- for (int i2 = 0; i2 < 2; i2++)
- {
- OMR_RESULT *m_result_buffer2 = paper->result[i2];
- for (int j2 = 0; j2 < m_result_buffer2->cut_area_result.size(); j2++)
- {
- if (m_result_buffer2->cut_area_result[j2].area_name == cut_name)//
- {
- area_rst->push_back(&m_result_buffer2->cut_area_result[j2]);
- }
- }
- }
- cut_area_map[cut_name] = 0;
- bool flag = false;
- if (area_rst->size() > 1)
- {
- flag = true;
- }
- wstring strw = strA2W(paper->result_dir);
- saveImgesPara *para = new saveImgesPara(area_rst, strw.c_str(), 0, flag);
- paper->qid_cut_map[(*area_rst)[0]->area_name] = area_rst->size();
- vct_saveImges.push_back(para);
- QueueUserWorkItem(SaveCutImageThread, para, WT_EXECUTELONGFUNCTION);
- }
- }
- string jpgname = paper->result_dir + "/" + "jpgname.txt";
- FILE* pf = fopen(jpgname.c_str(), "wb");
- string jpgpath = "";
- while (true)
- {
- if (vct_saveImges.size() == 0)
- {
- break;
- }
- if (vct_saveImges[0]->bSaved)
- {
- if (vct_saveImges[0]->area_rst->size()>1)
- {
- for (int i = 0; i < vct_saveImges[0]->area_rst->size(); i++)
- {
- saveImgesPara *para = (saveImgesPara *)vct_saveImges[0];
- vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
- char buf[64] = { 0 };
- sprintf_s(buf, "%s_%d", (*area_results)[i]->area_name.c_str(), i);
- jpgpath += buf;
- jpgpath += ",";
- }
- }
- jpgpath += vct_saveImges[0]->path1;
- jpgpath += ",";
- delete vct_saveImges[0]->area_rst;
- vct_saveImges.erase(vct_saveImges.begin());
- continue;
- }
- else
- {
- Sleep(10);
- }
- }
- if (jpgpath.length() > 0)
- {
- jpgpath.erase(jpgpath.end() - 1);
- }
- fwrite(jpgpath.c_str(), 1, jpgpath.length(), pf);
- fclose(pf);
- DWORD t1 = GetTickCount() - t0;
- printf("t1=%d \r\n", t1);
- return identify::result::IDF_SUCCESS;
- }
- unsigned _stdcall ScanThread(void* param)
- {
- CBatch_Server* bInfo = (CBatch_Server*)param;
- if (!bInfo)
- {
- return 0;
- }
- while (g_ScanThreadRun)
- {
- //{
- // g_count++;
- // char buf[128] = { 0 };
- // sprintf_s(buf, 128, "update papers set state = %d", GetTickCount());
- // bInfo->m_batch_db.execDML(buf);
- // continue;
- //}
- Paper_Page* paper = bInfo->ReadNextPaper();
- if (paper == NULL)
- {
- return 0;
- }
- auto act1 = finally([&]
- {
- if (paper != NULL)
- {
- delete paper; paper = NULL;
- }
- });
- if (paper->scan_cnt >= 1)
- {
- paper->exc_code = paper_exc_locate;
- bInfo->UpdatePaper(paper);
- continue;
- }
- paper->scan_cnt++;
- int res = ScanPaper(bInfo, paper);
- if (res == IDF_SUCCESS)
- {
- if (bInfo->m_bUseInputExam)
- {
- bInfo->MakeResultJsonAndUpload(paper);
- }
- else
- {
- string qr_code = paper->qr_code;
- if (qr_code.length() == 0)
- {
- paper->exc_code = paper_exc_qrcode_unmatch;
- bInfo->UpdatePaper(paper);
- }
- else
- {
- vector<string> strs = splitEx(qr_code, ",");
- if (strs[0] != bInfo->m_exam_id)
- {
- paper->exc_code = paper_exc_qrcode_unmatch;
- bInfo->UpdatePaper(paper);
- }
- else
- {
- bInfo->MakeResultJsonAndUpload(paper);
- }
- }
- }
- }
- else
- {
- if (paper->exc_code == paper_exc_pages_missed)
- {
- g_ScanThreadRun = false;
- g_IsPagesMissed = true;
- }
- else
- {
- paper->exc_code = paper_exc_locate;
- }
- bInfo->UpdatePaper(paper);
- }
- }
- }
- bool CBatch_Server::OpenBatchDb()
- {
- if (m_batch_db.is_open())
- {
- return true;
- }
- //判断文件是否存在
- struct stat buffer;
- try
- {
- m_batch_db.open(m_batchDbPath.c_str());
- }
- catch (CException* e)
- {
- g_log.PutMsg(LogLvlFailed, "开启批次数据库失败 %s", m_batchDbPath.c_str());
- return false;
- }
- m_batch_db.execDML("pragma journal_mode = MEMORY");
- m_batch_db.execDML("PRAGMA synchronous = OFF");
- m_total_cnt = m_batch_db.execScalar("SELECT count(0) FROM papers");
- /*{
- m_batch_db.execDML("update papers set state = 0");
- }*/
- return true;
- }
- string CBatch_Server::ReadQRcode(Paper_Page* paper)
- {
- PageIdentify identify;
- string ret = "";
- for (int i = 0; i < 2; i++)
- {
- string strPath = /*UtfToGbk*/(paper->path[i]);
- IplImage *src = cvLoadImage(strPath.c_str());
- if (src == NULL)
- {
- continue;
- }
- auto act1 = finally([&]
- {
- if (src != NULL)cvReleaseImage(&src);
- src = NULL;
- });
- ret = identify.ReadQrCode(src);
- if (ret.length()>0)
- {
- return ret;
- }
- }
- return ret;
- }
- CBatch_Server::CBatch_Server()
- {
- m_onlineCardTemplate = new OnLineCard::PaperTemplate;
- m_onlineCardTemplate->useQrCode = false;
- m_thread_cnt = 1;
- m_bOffline_score = false;
- m_regionQQ = "ap-shanghai";
- m_bucket_nameQQ = "zxhx-1302712961";
- m_hostHuawei = "obs.cn-north-4.myhuaweicloud.com";
- m_bucketHuawei = "obs-cs-1";
- m_indexDbPath = g_Indexdb;
- m_bUseInputExam = false;
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("config.ini"));
- m_bDrawSchema = GetPrivateProfileInt(_T("USER"), _T("DrawSchema"), 1, FilePath);//
- m_bDrawResult = GetPrivateProfileInt(_T("USER"), _T("DrawResult"), 0, FilePath);//
- m_yunType = GetPrivateProfileInt(_T("USER"), _T("YunType"), 0, FilePath);
- }
- CloudSetYunType(m_yunType);
- if (m_yunType == 1)
- InitHuaweiCLoud(const_cast<char *>(m_hostHuawei.c_str()), "XOO6T5NG2ROM3Y8ZIWKT", "IqJjwHmgMPgomZtHYkCUaqbw0oAumWcoq8Typse8", const_cast<char *>(m_bucketHuawei.c_str()));
- else if (m_yunType == 0)
- InitQCLoud(1302712961, "AKIDC9pETRbZfWBbmhoglkT4PUJGzRjmj3Ia", "C6jlX4LKfleGdmfQvGNgj74lESRpBIEJ", const_cast<char *>(m_regionQQ.c_str()), const_cast<char *>(m_bucket_nameQQ.c_str()));
- }
- CBatch_Server::~CBatch_Server()
- {
- if (m_batch_db.is_open())
- m_batch_db.close();
- }
- bool CBatch_Server::GetCardTemplate(string exam_id, string task_id)
- {
- std::string response;
- CHttpClient httpClient;
- CString url;
- url.Format(_T("%s/teacher/third/card/location?cardId=%s&taskId=%s&schoolId=%s"), strA2W(g_ServerUrl).c_str(), strA2W(exam_id).c_str(), strA2W(task_id).c_str(), strA2W(g_SchoolId).c_str());
- //httpClient.SetSendHeader(L"");
- httpClient.HttpGet(url, NULL, response);
- if (response.length() == 0)
- {
- g_log.PutMsg(LogLvlFailed, "模板下载失败 批次ID=%s", m_batch_id.c_str());
- return false;
- }
- Json::Value root;
- Json::Reader(Json::Features()).parse(response, root);
- if (root["code"].isInt() && root["code"].asInt() != 200){
- g_log.PutMsg(LogLvlFailed, "模板不正确 code!=200 批次ID=%s", m_batch_id.c_str());
- return false;
- }
- FILE* pschema = fopen("schema.json", "wb");
- if (pschema)
- {
- fwrite(response.c_str(), 1, response.length(), pschema);
- fclose(pschema);
- }
- //return ParseTemplateFromJsonAll2("D:\\thirdNanCang\\Win32\\Debug\\1111.zip", m_onlineCardTemplate);
- try
- {
- return ParseTemplateFromJsonAll(response, m_onlineCardTemplate);
- }
- catch (const char* msg)
- {
- g_log.PutMsg(LogLvlFailed, "模板不正确 区域位置有负值 批次ID=%s", m_batch_id.c_str());
- return false;
- }
- }
- Paper_Page* CBatch_Server::ReadNextPaper()
- {
- PBQAutoLock autolock(m_lockPageVec);
- if (m_PageVec.size()>0)
- {
- Paper_Page* p = m_PageVec[0];
- m_PageVec.erase(m_PageVec.begin());
- return p;
- }
- else
- {
- return NULL;
- }
- }
- void CBatch_Server::ReadExamInfo()
- {
- OpenBatchDb();
- CppSQLite3Query query0;
- char sql[256];
- sprintf_s(sql, "select * from batchinfo");
- query0 = m_batch_db.execQuery(sql);
- if (!query0.eof())//表示有先扫后传的原图上传
- {
- m_exam_id = query0.getStringField("exam_id");
- m_task_id = query0.getStringField("task_id");
- }
- query0.finalize();
- }
- void CBatch_Server::GetUnScanPapersFromDB()
- {
- CppSQLite3Query query0;
- char sql[256];
- sprintf_s(sql, "select * from papers where state in(0)");
- query0 = m_batch_db.execQuery(sql);
- while (!query0.eof())//表示有先扫后传的原图上传
- {
- Paper_Page* paper = new Paper_Page;
- //paper->Init_result();
- paper->id = query0.getIntField("id");
- paper->scan_cnt = query0.getIntField("scan_cnt");
- paper->path[0] = UtfToGbk(query0.getStringField("page0"));
- paper->path[1] = UtfToGbk(query0.getStringField("page1"));
- paper->path_jiaozheng[0] = query0.getStringField("jiaozheng0");
- paper->path_jiaozheng[1] = query0.getStringField("jiaozheng1");
- paper->result_dir = m_work_dir + "result/" + to_string(paper->id) + "/";
- paper->result_json = paper->result_dir + "result.json";
- paper->yun_header = query0.getStringField("yun_header");
- if (paper->yun_header.length() == 0)
- {
- paper->yun_header = to_string(GetTickCount() + paper->id);
- }
- m_PageVec.push_back(paper);
- query0.nextRow();
- }
- query0.finalize();
- }
- Paper_Page* CBatch_Server::GetPaperFromDB(int paper_id)
- {
- CppSQLite3Query query0;
- char sql[256];
- sprintf_s(sql, "select * from papers where id ='%d'", paper_id);
- query0 = m_batch_db.execQuery(sql);
- Paper_Page* paper = NULL;
- if (!query0.eof())
- {
- paper = new Paper_Page;
- paper->id = query0.getIntField("id");
- paper->scan_cnt = query0.getIntField("scan_cnt");
- paper->path[0] = UtfToGbk(query0.getStringField("page0"));
- paper->path[1] = UtfToGbk(query0.getStringField("page1"));
- paper->path_jiaozheng[0] = query0.getStringField("jiaozheng0");
- paper->path_jiaozheng[1] = query0.getStringField("jiaozheng1");
- paper->result_dir = m_work_dir + "result/" + to_string(paper->id) + "/";
- paper->result_json = paper->result_dir + "result.json";
- paper->yun_header = query0.getStringField("yun_header");
- if (paper->yun_header.length() == 0)
- {
- paper->yun_header = to_string(GetTickCount() + paper->id);
- }
- }
- query0.finalize();
- return paper;
- }
- void CBatch_Server::ReBatchScan(int batch_id, string exam_id)
- {
- batch_info info = GetBatchInfo(batch_id);
- if (info.id == -1)
- {
- g_log.PutMsg(LogLvlFailed, "StartScan 未查到批次=%d", batch_id);
- return;
- }
- m_batch_id = to_string(batch_id);
- m_batchDbPath = info.batchdb_path;
- m_total_cnt = info.total_cnt;
- m_work_dir = UtfToGbk(info.work_dir);
- m_batch_code = getBatchCode(info.work_dir);
- if (!OpenBatchDb())
- {
- return;
- }
- {//重置DB
- char sql[1024] = { 0 };
- sprintf_s(sql, "update papers set scan_cnt=0 ");
- m_batch_db.execDML("begin transaction");
- m_batch_db.execDML(sql);
- m_batch_db.execDML("commit transaction");
- }
- GetUnScanPapersFromDB();
- string qr_code = exam_id;
- if (qr_code.length() == 0)
- {
- g_log.PutErrMsg("ReBatchScan 请输入正确考试号 batch_id=%s", m_batch_id.c_str());
- return;
- }
- vector<string> strs = splitEx(qr_code, ",");
- if (strs.size() == 2)
- {
- m_exam_id = strs[0];
- m_task_id = strs[1];
- }
- else
- {
- m_exam_id = strs[0];
- }
- {
- char sql[1024] = { 0 };
- sprintf_s(sql, "update batchinfo set exam_id ='%s', task_id ='%s'", m_exam_id.c_str(), m_task_id.c_str());
- m_batch_db.execDML("begin transaction");
- m_batch_db.execDML(sql);
- m_batch_db.execDML("commit transaction");
- }
- if (!GetCardTemplate(m_exam_id, m_task_id))
- {
- g_log.PutMsg(LogLvlFailed, "模板解析失败 批次ID=%s", m_batch_id.c_str());
- UpdateIndexDb(m_batch_id, batch_exc_invalid_qrcode);
- return;
- }
- else
- {
- char sql[1024] = { 0 };
- string strExamName = handleApostrophe(m_onlineCardTemplate->exam_name);
- string strSubName = handleApostrophe(m_onlineCardTemplate->subject_name);
- sprintf_s(sql, "update batchinfo set exam_name ='%s', subject_name ='%s'", strExamName.c_str(), strSubName.c_str());
- m_batch_db.execDML("begin transaction");
- m_batch_db.execDML(sql);
- m_batch_db.execDML("commit transaction");
- }
- if (exam_id.length() > 0)
- {
- m_bUseInputExam = true;
- }
- for (int i = 0; i < m_thread_cnt; i++)
- {
- m_thread_handle[i] = (HANDLE)_beginthreadex(NULL, 0, ScanThread, this, NULL, NULL);
- if (m_thread_handle[i] == NULL)
- {
- g_log.PutErrMsg("扫描线程创建失败 batch_id=%s", m_batch_id.c_str());
- return;
- }
- }
- for (int i = 0; i < m_thread_cnt; i++)
- {
- WaitForSingleObject(m_thread_handle[i], INFINITE);
- CloseHandle(m_thread_handle[i]);
- }
- StatisticsBatchInfo(m_batch_id);
- }
- void CBatch_Server::StartScan(int batch_id)//函数返回 扫描结束
- {
- //本地调试时可取消这一句的注释,版本上线时须注释
- //Reset(batch_id);
- batch_info info = GetBatchInfo(batch_id);
- if (info.id == -1)
- {
- g_log.PutMsg(LogLvlFailed, "StartScan 未查到批次=%d", batch_id);
- return;
- }
- m_batch_id = to_string(batch_id);
- m_batchDbPath = info.batchdb_path;
- m_total_cnt = info.total_cnt;
- m_work_dir = UtfToGbk(info.work_dir);
- m_batch_code = getBatchCode(info.work_dir);
- if (!OpenBatchDb())
- {
- return;
- }
- GetUnScanPapersFromDB();
- string qr_code = "";
- bool isJsonOk = false;
- for (int i = 0; i < MIN(m_PageVec.size(), 3); i++)
- {
- Paper_Page* paper = m_PageVec[i];
- if (paper == NULL)
- {
- break;
- }
- qr_code = ReadQRcode(paper);
- if (qr_code.length() == 0)
- {
- continue;
- }
- vector<string> strs = splitEx(qr_code, ",");
- if (strs.size() == 2)
- {
- m_exam_id = strs[0];
- m_task_id = strs[1];
- }
- else
- {
- m_exam_id = strs[0];
- }
- if (!GetCardTemplate(m_exam_id, m_task_id))
- {
- continue;
- }
- else
- {
- isJsonOk = true;
- break;
- }
- }
- if (qr_code.length() == 0)
- {
- g_log.PutErrMsg("未找到二维码 batch_id=%s", m_batch_id.c_str());
- UpdateIndexDb(m_batch_id, batch_exc_invalid_qrcode);
- return;
- }
- else if (isJsonOk == false)
- {
- g_log.PutMsg(LogLvlFailed, "模板解析失败 批次ID=%s", m_batch_id.c_str());
- UpdateIndexDb(m_batch_id, batch_exc_invalid_qrcode);
- return;
- }
- {
- char sql[1024] = { 0 };
- string strExamName = handleApostrophe(m_onlineCardTemplate->exam_name);
- string strSubName = handleApostrophe(m_onlineCardTemplate->subject_name);
- sprintf_s(sql, "update batchinfo set exam_id ='%s', task_id ='%s',exam_name ='%s', subject_name ='%s'", m_exam_id.c_str(), m_task_id.c_str(),
- strExamName.c_str(), strSubName.c_str());
- m_batch_db.execDML("begin transaction");
- m_batch_db.execDML(sql);
- m_batch_db.execDML("commit transaction");
- }
- for (int i = 0; i < m_thread_cnt; i++)
- {
- m_thread_handle[i] = (HANDLE)_beginthreadex(NULL, 0, ScanThread, this, NULL, NULL);
- if (m_thread_handle[i] == NULL)
- {
- g_log.PutErrMsg("扫描线程创建失败 batch_id=%s", m_batch_id.c_str());
- return;
- }
- }
- for (int i = 0; i < m_thread_cnt; i++)
- {
- WaitForSingleObject(m_thread_handle[i], INFINITE);
- CloseHandle(m_thread_handle[i]);
- }
- StatisticsBatchInfo(m_batch_id);
- }
- void CBatch_Server::ReScan(int batch_id, int paper_id, char* page0, char* page1, string exam_id)
- {
- batch_info info = GetBatchInfo(batch_id);
- if (info.id == -1)
- {
- g_log.PutMsg(LogLvlFailed, "ReScan 未查到批次=%d", batch_id);
- return;
- }
- m_batch_id = to_string(batch_id);
- m_batchDbPath = info.batchdb_path;
- m_total_cnt = info.total_cnt;
- m_work_dir = UtfToGbk(info.work_dir);
- m_batch_code = getBatchCode(info.work_dir);
- if (!OpenBatchDb())
- {
- return;
- }
- {//重置DB
- char sql[1024] = { 0 };
- sprintf_s(sql, "update papers set scan_cnt=0 where id = %d", paper_id);
- m_batch_db.execDML("begin transaction");
- m_batch_db.execDML(sql);
- m_batch_db.execDML("commit transaction");
- }
- Paper_Page* paper = GetPaperFromDB(paper_id);
- if (!paper)
- {
- return;
- }
- paper->path[0] = UtfToGbk(page0);
- paper->path[1] = UtfToGbk(page1);
- m_PageVec.push_back(paper);
- if (exam_id.length() == 0)
- {
- ReadExamInfo();
- }
- else
- {
- vector<string> strs = splitEx(exam_id, ",");
- if (strs.size() == 2)
- {
- m_exam_id = strs[0];
- m_task_id = strs[1];
- }
- else
- {
- m_exam_id = strs[0];
- }
- m_bUseInputExam = true;
- }
- if (!GetCardTemplate(m_exam_id, m_task_id))
- {
- g_log.PutMsg(LogLvlFailed, "模板解析失败 批次ID=%s", m_batch_id.c_str());
- return;
- }
- for (int i = 0; i < m_thread_cnt; i++)
- {
- m_thread_handle[i] = (HANDLE)_beginthreadex(NULL, 0, ScanThread, this, NULL, NULL);
- if (m_thread_handle[i] == NULL)
- {
- g_log.PutErrMsg("扫描线程创建失败 batch_id=%s", m_batch_id.c_str());
- return;
- }
- }
- for (int i = 0; i < m_thread_cnt; i++)
- {
- WaitForSingleObject(m_thread_handle[i], INFINITE);
- CloseHandle(m_thread_handle[i]);
- }
- StatisticsBatchInfo(m_batch_id);
- }
- void CBatch_Server::ReScan(int batch_id, vector<int> paper_ids, char* exam_id)
- {
- }
- string CBatch_Server::MakeResultJsonAndUpload(Paper_Page* paper)//调用该函数前Paper_Page必须是识别完成的,本函数不较验
- {
- UpdatePaper(paper);
- CString jsonPath;
- string url_head = "";
- if (m_yunType == 0)
- {
- url_head = "http://" + m_bucket_nameQQ + ".cos." + m_regionQQ + ".myqcloud.com/" + paper->yun_header + "/";
- }
- else
- {
- //m_hostHuawei = "obs.cn-north-4.myhuaweicloud.com";
- //m_bucketHuawei = "obs-cs-1";
- //https://obs-cs-1.obs.cn-north-4.myhuaweicloud.com/D1.jpg
- //https://obs-cs-1.obs.cn-north-4.myhuaweicloud.com/2341881486/
- url_head = "https://" + m_bucketHuawei + "." + m_hostHuawei + "/" + paper->yun_header + "/";
- }
- Json::FastWriter writer;
- Json::Value json;
- json["online_card"] = 1;
- json["exam_id"] = m_exam_id;
- json["task_id"] = m_task_id;
- json["student_code"] = paper->student_code;
- json["pages"] = url_head + "page0.jpg" + "," + url_head + "page1.jpg";;
- json["school_id"] = atoi(g_SchoolId.c_str());
- json["batch_code"] = m_batch_code.c_str();
- json["absent"] = paper->result[0]->quekaoFlag == false ? 0 : 1;
- vector<KEGUANTI_RESULT> keguan_result = paper->result[0]->group_result;
- for (int i = 0; i < paper->result[1]->group_result.size(); i++)
- {
- keguan_result.push_back(paper->result[1]->group_result[i]);
- }
- vector<TIANKONGTI_RESULT> tiankong_result = paper->result[0]->tiankongti_result;
- for (int i = 0; i < paper->result[1]->tiankongti_result.size(); i++)
- {
- tiankong_result.push_back(paper->result[1]->tiankongti_result[i]);
- }
- vector<ZHUGUANTI_RESULT> zhuguan_result = paper->result[0]->zhutuanti_result;
- for (int i = 0; i < paper->result[1]->zhutuanti_result.size(); i++)
- {
- bool pingjie = false;
- for (int j = 0; j < zhuguan_result.size(); j++)
- {
- if (paper->result[1]->zhutuanti_result[i].question_code == zhuguan_result[j].question_code)
- {
- pingjie = true;
- break;
- }
- }
- if (pingjie == false)
- {
- zhuguan_result.push_back(paper->result[1]->zhutuanti_result[i]);
- }
- }
- Json::Value json_array(Json::arrayValue);
- if (paper->result[0]->quekaoFlag != true)
- {
- for (auto& it : keguan_result)
- {
- Json::Value item;
- item["id"] = it.question_code;
- item["answer"] = it.answer;
- item["name"] = qid_name[it.question_code];
- item["url"] = "";
- item["score"] = "";
- json_array.append(item);
- }
- for (auto& it : tiankong_result)
- {
- Json::Value item;
- item["id"] = it.question_code;
- item["answer"] = "";
- item["name"] = qid_name[it.question_code];
- item["url"] = url_head + it.question_code + ".jpg";
- item["score"] = it.question_score;
- if (it.question_score>-0.1 && it.question_score<0.1)
- {
- item["score"] = 0.0;
- }
- json_array.append(item);
- }
- for (auto& it : zhuguan_result)
- {
- Json::Value item;
- item["id"] = it.question_code;
- item["answer"] = "";
- string url = url_head + it.question_code + ".jpg";
- item["name"] = qid_name[it.question_code];
- /* if (paper->qid_cut_map[it.question_code]>1)
- {
- char buf[256] = { 0 };
- for (int i = 0; i < paper->qid_cut_map[it.question_code];i++)
- {
- sprintf_s(buf, "%s%s_%d.jpg", url_head.c_str(), it.question_code.c_str(), i);
- url += ",";
- url += buf;
- }
- }*/
- item["url"] = url;
- item["score"] = it.question_score;
- if (it.question_score > -0.1 && it.question_score < 0.1)
- {
- item["score"] = 0.0;
- }
- json_array.append(item);
- }
- }
- json["questionList"] = json_array;
- string res_json = writer.write(json);
- string json_file = paper->result_dir + "/" + "json.txt";
- FILE* pf = fopen(json_file.c_str(), "wb");
- fwrite(res_json.c_str(), 1, res_json.length(), pf);
- fclose(pf);
- UploadResult(paper);
- return res_json;
- }
- int CBatch_Server::UploadResult(Paper_Page* paper)
- {
- paper->exc_code = paper_exc_upload;
- string jpgname = paper->result_dir + "/" + "jpgname.txt";
- string json_file = paper->result_dir + "/" + "json.txt";
- char* jpgbuf = new char[10240];
- memset(jpgbuf, 0, 10240);
- char* json_buf = new char[20480];
- memset(json_buf, 0, 10240);
- auto act1 = finally([&]
- {
- delete[] json_buf;
- delete[] jpgbuf;
- UpdatePaper(paper);
- //重传完成通知上层界面
- if (paper->exc_code == paper_exc_success)
- ::PostMessage(g_MsgWnd, UM_REUPLOAD_FINISHED, atoi(m_batch_id.c_str()), paper->id);
- else
- ::PostMessage(g_MsgWnd, UM_REUPLOAD_FAILED, atoi(m_batch_id.c_str()), paper->id);
- });
- FILE* pf = fopen(jpgname.c_str(), "rb");
- if (!pf)
- {
- g_log.PutMsg(LogLvlFailed, "打开上传文件失败 %s", jpgname.c_str());
- paper->exc_code = paper_exc_upload;
- return 0;
- }
- fread(jpgbuf, 1, 10240, pf);
- fclose(pf);
- vector<string> jpgs = splitEx(jpgbuf, ",");
- /*FILE* pf2 = fopen(json_file.c_str(), "rb");
- if (!pf2)
- {
- g_log.PutMsg(LogLvlFailed, "打开上传文件失败 %s", json_file.c_str());
- paper->exc_code = paper_exc_upload;
- return 0;
- }
- fread(json_buf, 1, 20480, pf2);
- fclose(pf2);*/
- string strContent;
- string strTemp;
- ifstream in;
- ofstream out;
- in.open(json_file);
- while (getline(in, strTemp))
- {
- strContent += strTemp;
- }
- in.close();
- //Json::Features features;
- //Json::Reader re(features);
- //Json::Value root;
- //re.parse(json_buf, root);
- //Json::Value json_array= root["questionList"];
- {
- char key[512] = { 0 };
- sprintf_s(key, "%s/page0.jpg", paper->yun_header.c_str());
- char url[512] = { 0 };
- bool ret = CloudPutFile(key, (char*)paper->path_jiaozheng[0].c_str(), url);
- if (!ret)
- {
- g_log.PutMsg(LogLvlError, "上传云失败 批次id=%s 试卷id=%d", m_batch_id.c_str(), paper->id);
- return 0;
- }
- memset(key, 0, 512);
- sprintf_s(key, "%s/page1.jpg", paper->yun_header.c_str());
- ret = CloudPutFile(key, (char*)paper->path_jiaozheng[1].c_str(), url);
- if (!ret)
- {
- g_log.PutMsg(LogLvlError, "上传云失败 批次id=%s 试卷id=%d", m_batch_id.c_str(), paper->id);
- return 0;
- }
- }
- for (auto& it : jpgs)
- {
- string id = it;
- string jpgpath = paper->result_dir + "/" + id + ".jpg";
- char key[512] = { 0 };
- sprintf_s(key, "%s/%s.jpg", paper->yun_header.c_str(), id.c_str());
- char url[512] = { 0 };
- bool ret = CloudPutFile(key, (char*)jpgpath.c_str(), url);
- if (!ret)
- {
- g_log.PutMsg(LogLvlError, "上传云失败 批次id=%s 试卷id=%d", m_batch_id.c_str(), paper->id);
- return 0;
- }
- }
- {
- CHttpClient httpClient;
- string response;
- CString url;
- url.Format(_T("%s/teacher/third/student/upload"), strA2W(g_ServerUrl).c_str());
- string strJsonContent = UtfToGbk(strContent);
- CString strJson = CString(_T("json=")) + strA2W(strJsonContent).c_str();
- httpClient.HttpPost(url, strJson, response);
- if (response.find("\"code\":200") != string::npos)
- {
- paper->exc_code = paper_exc_success;
- //上传成功
- }
- else
- {
- Json::Features features;
- Json::Reader re(features);
- Json::Value root;
- re.parse(response, root);
- paper->err_msg = root["msg"].asString();
- }
- }
- return 0;
- }
- void CBatch_Server::StatisticsBatchInfo(string batch_id)
- {
- //return;
- int suc_count = m_batch_db.execScalar("SELECT count(0) FROM papers where state = '-1'");
- if (suc_count == m_total_cnt)
- {
- UpdateIndexDb(m_batch_id, batch_exc_success, suc_count);
- return;
- }
- if (g_IsPagesMissed == true)
- {
- UpdateIndexDb(m_batch_id, batch_exc_pages_missed, suc_count);
- return;
- }
- int exc_count = m_batch_db.execScalar("SELECT count(0) FROM papers where state > 0");
- if (exc_count > 0)
- {
- UpdateIndexDb(m_batch_id, batch_exc_scan_excption);
- return;
- }
- }
- void CBatch_Server::Reset(int batch_id)
- {
- CppSQLite3DB index_db;
- try
- {
- index_db.open(ToUtf8(m_indexDbPath).c_str());
- }
- catch (CException* e)
- {
- g_log.PutMsg(LogLvlFailed, "UpdateIndexDb 开启index.db3失败 ");
- ReleaseMutex(m_hMutexIndex);
- return;
- }
- char sql[1024] = { 0 };
- sprintf_s(sql, 1024, "update batchs set state = 0 ");
- index_db.execDML(sql);
- index_db.close();
- batch_info info = GetBatchInfo(batch_id);
- if (info.id == -1)
- {
- g_log.PutMsg(LogLvlFailed, "StartScan 未查到批次=%d", batch_id);
- return;
- }
- m_batch_id = to_string(batch_id);
- m_batchDbPath = info.batchdb_path;
- m_total_cnt = info.total_cnt;
- m_work_dir = UtfToGbk(info.work_dir);
- m_batch_code = getBatchCode(info.work_dir);
- if (!OpenBatchDb())
- {
- return;
- }
- sprintf_s(sql, "update papers set state = 0,scan_cnt=0");
- m_batch_db.execDML("begin transaction");
- m_batch_db.execDML(sql);
- m_batch_db.execDML("commit transaction");
- }
- void CBatch_Server::UpdatePaper(Paper_Page* paper)
- {
- //return;
- char sql[1024] = { 0 };
- string strErrMsg = handleApostrophe(paper->err_msg);
- string strRestultDir = handleApostrophe(paper->result_dir);
- string strJiaoZheng0 = handleApostrophe(paper->path_jiaozheng[0]);
- string strJiaoZheng1 = handleApostrophe(paper->path_jiaozheng[1]);
- sprintf_s(sql, "update papers set student_id ='%s', student_name ='%s', result_dir ='%s',state = %d,err_msg='%s',scan_time=%lld,qr_code='%s',yun_header='%s',jiaozheng0='%s',jiaozheng1='%s',scan_cnt=%d where id='%d'",
- paper->student_code.c_str(), paper->student_name.c_str(), strRestultDir.c_str(), paper->exc_code, strErrMsg.c_str(), std::time(0), paper->qr_code.c_str(), paper->yun_header.c_str(), strJiaoZheng0.c_str(), strJiaoZheng1.c_str(), paper->scan_cnt, paper->id);
- m_batch_db.execDML("begin transaction");
- m_batch_db.execDML(sql);
- m_batch_db.execDML("commit transaction");
- }
- void CBatch_Server::UpdateIndexDb(string batch_id, long long state, int success_cnt)
- {
- /*DWORD dw = WaitForSingleObject(m_hMutexIndex, 10000);
- if (WAIT_TIMEOUT == dw)
- {
- g_log.PutMsg(LogLvlFailed, "UpdateIndexDb 访问 index_db3 超时");
- return ;
- }*/
- CppSQLite3DB index_db;
- try
- {
- index_db.open(ToUtf8(m_indexDbPath).c_str());
- }
- catch (CException* e)
- {
- g_log.PutMsg(LogLvlFailed, "UpdateIndexDb 开启index.db3失败 ");
- ReleaseMutex(m_hMutexIndex);
- return;
- }
- char sql[1024] = { 0 };
- if (success_cnt<0)
- {
- sprintf_s(sql, 1024, "update batchs set state = %lld where id = '%s'", state, batch_id.c_str());
- }
- else
- {
- sprintf_s(sql, 1024, "update batchs set state = %lld,success_cnt= %d where id = '%s'",
- state, success_cnt, batch_id.c_str());
- }
- index_db.execDML(sql);
- index_db.close();
- ReleaseMutex(m_hMutexIndex);
- }
- void CBatch_Server::ReUploadAllFailed()
- {
- if (!OpenBatchDb())
- return;
- CppSQLite3Query query0;
- char sql[256];
- sprintf_s(sql, "select * from papers where state in(%d)", paper_exc_upload);
- query0 = m_batch_db.execQuery(sql);
- while (!query0.eof())
- {
- Paper_Page* paper = new Paper_Page;
- paper->id = query0.getIntField("id");
- paper->scan_cnt = query0.getIntField("scan_cnt");
- paper->path[0] = UtfToGbk(query0.getStringField("page0"));
- paper->path[1] = UtfToGbk(query0.getStringField("page1"));
- paper->path_jiaozheng[0] = query0.getStringField("jiaozheng0");
- paper->path_jiaozheng[1] = query0.getStringField("jiaozheng1");
- paper->result_dir = UtfToGbk(m_work_dir) + "result/" + to_string(paper->id) + "/";
- paper->result_json = paper->result_dir + "result.json";
- paper->yun_header = query0.getStringField("yun_header");
- paper->student_code = query0.getStringField("student_id");
- paper->qr_code = query0.getStringField("qr_code");
- m_PageVec.push_back(paper);
- query0.nextRow();
- }
- query0.finalize();
- while (true)
- {
- Paper_Page* paper = ReadNextPaper();
- if (paper == NULL)
- {
- break;
- }
- auto act1 = finally([&]
- {
- delete paper; paper = NULL;
- });
- UploadResult(paper);
- }
- StatisticsBatchInfo(m_batch_id);
- }
- void CBatch_Server::DrawSchema(IplImage*dst_img, SchemaPage* pageSchema, OMR_RESULT *result)
- {
- CvFont font;
- float scale = (float)40 * 20 / pageSchema->locatePoints[0].width / pageSchema->locatePoints[0].height;
- scale = sqrt(scale);
- cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 2.0 / scale, 2.0 / scale, 0, 2);
- if (m_bDrawSchema)
- {
- // 绘制定位点
- for (std::size_t i = 0; i < pageSchema->questionLocatePoints.size(); i++){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->questionLocatePoints[i].centerx - pageSchema->questionLocatePoints[i].width / 2.0, pageSchema->questionLocatePoints[i].centery - pageSchema->questionLocatePoints[i].height / 2.0),
- cvPoint(pageSchema->questionLocatePoints[i].centerx + pageSchema->questionLocatePoints[i].width / 2.0, pageSchema->questionLocatePoints[i].centery + pageSchema->questionLocatePoints[i].height / 2.0),
- cvScalar(0, 255, 0));
- }
- // 绘制二维码 条形码
- for (std::size_t i = 0; i < pageSchema->codes.size(); i++){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->codes[i].centerx - pageSchema->codes[i].width / 2.0, pageSchema->codes[i].centery - pageSchema->codes[i].height / 2.0),
- cvPoint(pageSchema->codes[i].centerx + pageSchema->codes[i].width / 2.0, pageSchema->codes[i].centery + pageSchema->codes[i].height / 2.0),
- cvScalar(0, 255, 0));
- cvPutText(dst_img, pageSchema->codes[i].strContent.c_str(), cvPoint(pageSchema->codes[i].centerx - pageSchema->codes[i].width / 2.0, pageSchema->codes[i].centery - pageSchema->codes[i].height / 2.0),
- &font, CV_RGB(255, 0, 0));
- }
- // 客观题
- for (std::size_t i = 0; i < pageSchema->items.size(); i++){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->items[i].centerx - pageSchema->items[i].width / 2.0, pageSchema->items[i].centery - pageSchema->items[i].height / 2.0),
- cvPoint(pageSchema->items[i].centerx + pageSchema->items[i].width / 2.0, pageSchema->items[i].centery + pageSchema->items[i].height / 2.0),
- cvScalar(0, 255, 0));
- }
- // 主观题
- for (std::size_t i = 0; i < pageSchema->question_score.size(); i++){
- if (pageSchema->question_score[i].scoreBox.bXuanZuoTi){
- for (int j = 0; j < pageSchema->question_score[i].countNum; j++){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->question_score[i].item[j].centerx - pageSchema->question_score[i].item[j].width / 2.0, pageSchema->question_score[i].item[j].centery - pageSchema->question_score[i].item[j].height / 2.0),
- cvPoint(pageSchema->question_score[i].item[j].centerx + pageSchema->question_score[i].item[j].width / 2.0, pageSchema->question_score[i].item[j].centery + pageSchema->question_score[i].item[j].height / 2.0),
- cvScalar(0, 255, 0));
- }
- }
- // 绘制打分区域
- int x = pageSchema->question_score[i].scoreBox.pos.x,
- y = pageSchema->question_score[i].scoreBox.pos.y,
- w = pageSchema->question_score[i].scoreBox.pos.w,
- h = pageSchema->question_score[i].scoreBox.pos.h;
- cvDrawRect(dst_img,
- cvPoint(x, y),
- cvPoint(x + w, y + h),
- cvScalar(255, 0, 255));
- }
- // 剪裁区域
- for (std::size_t i = 0; i < pageSchema->cutAreas.size(); ++i)
- {
- cvDrawRect(dst_img,
- cvPoint(pageSchema->cutAreas[i].centerx - pageSchema->cutAreas[i].width / 2.0, pageSchema->cutAreas[i].centery - pageSchema->cutAreas[i].height / 2.0),
- cvPoint(pageSchema->cutAreas[i].centerx + pageSchema->cutAreas[i].width / 2.0, pageSchema->cutAreas[i].centery + pageSchema->cutAreas[i].height / 2.0),
- cvScalar(0, 255, 0));
- }
- // 学号
- for (std::size_t i = 0; i < pageSchema->stuItems.size(); i++){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->stuItems[i].centerx - pageSchema->stuItems[i].width / 2.0, pageSchema->stuItems[i].centery - pageSchema->stuItems[i].height / 2.0),
- cvPoint(pageSchema->stuItems[i].centerx + pageSchema->stuItems[i].width / 2.0, pageSchema->stuItems[i].centery + pageSchema->stuItems[i].height / 2.0),
- cvScalar(0, 255, 0));
- }
- //缺考标识
- if (pageSchema->quekaoLocatePointIndex.size() > 0){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->quekao.centerx - pageSchema->quekao.width / 2.0, pageSchema->quekao.centery - pageSchema->quekao.height / 2.0),
- cvPoint(pageSchema->quekao.centerx + pageSchema->quekao.width / 2.0, pageSchema->quekao.centery + pageSchema->quekao.height / 2.0),
- cvScalar(0, 0, 255));
- }
- }
- if (m_bDrawResult)
- {
- // 绘制二维码 条形码
- for (std::size_t i = 0; i < pageSchema->codes.size(); i++)
- {
- cvPutText(dst_img, pageSchema->codes[i].strContent.c_str(), cvPoint(pageSchema->codes[i].centerx - pageSchema->codes[i].width / 2.0, pageSchema->codes[i].centery - pageSchema->codes[i].height / 2.0),
- &font, CV_RGB(255, 0, 0));
- }
- // 学号
- if (result->qr_result.size()>0 && pageSchema->stuItems.size()>0)
- {
- cvPutText(dst_img, result->qr_result[0].qr_str.c_str(), cvPoint(pageSchema->stuItems[0].centerx - pageSchema->stuItems[0].width / 2.0, pageSchema->stuItems[0].centery - pageSchema->stuItems[0].height / 2.0),
- &font, CV_RGB(255, 0, 0));
- }
- // 客观题
- for (std::size_t i = 0; i < pageSchema->items.size(); i++){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->items[i].centerx - pageSchema->items[i].width / 2.0, pageSchema->items[i].centery - pageSchema->items[i].height / 2.0),
- cvPoint(pageSchema->items[i].centerx + pageSchema->items[i].width / 2.0, pageSchema->items[i].centery + pageSchema->items[i].height / 2.0),
- cvScalar(0, 255, 0));
- if (result->group_result[pageSchema->items[i].keguanti_question_locate_point_index].answer.find(pageSchema->items[i].OutChar) != string::npos)
- {
- cvDrawRect(dst_img,
- cvPoint(pageSchema->items[i].centerx - pageSchema->items[i].width / 2.0, pageSchema->items[i].centery - pageSchema->items[i].height / 2.0),
- cvPoint(pageSchema->items[i].centerx + pageSchema->items[i].width / 2.0, pageSchema->items[i].centery + pageSchema->items[i].height / 2.0),
- cvScalar(0, 0, 255));
- cvPutText(dst_img, tostring(pageSchema->items[i].OutChar).c_str(), cvPoint(pageSchema->items[i].centerx - pageSchema->items[i].width / 2.0, pageSchema->items[i].centery + pageSchema->items[i].height / 2.0),
- &font, CV_RGB(255, 0, 0));
- }
- }
- // 主观题
- for (std::size_t i = 0; i < pageSchema->question_score.size(); i++){
- if (pageSchema->question_score[i].scoreBox.bXuanZuoTi)
- {
- for (int j = 0; j < pageSchema->question_score[i].countNum; j++){
- cvDrawRect(dst_img,
- cvPoint(pageSchema->question_score[i].item[j].centerx - pageSchema->question_score[i].item[j].width / 2.0, pageSchema->question_score[i].item[j].centery - pageSchema->question_score[i].item[j].height / 2.0),
- cvPoint(pageSchema->question_score[i].item[j].centerx + pageSchema->question_score[i].item[j].width / 2.0, pageSchema->question_score[i].item[j].centery + pageSchema->question_score[i].item[j].height / 2.0),
- cvScalar(0, 255, 0));
- }
- }
- // 绘制打分区域
- int x = pageSchema->question_score[i].scoreBox.pos.x,
- y = pageSchema->question_score[i].scoreBox.pos.y,
- w = pageSchema->question_score[i].scoreBox.pos.w,
- h = pageSchema->question_score[i].scoreBox.pos.h;
- cvDrawRect(dst_img,
- cvPoint(x, y),
- cvPoint(x + w, y + h),
- cvScalar(255, 0, 255));
- for (int j = 0; j < result->tiankongti_result.size(); j++)
- {
- if (pageSchema->question_score[i].question_code == result->tiankongti_result[j].question_code)
- {
- double sss = result->tiankongti_result[j].question_score;
- if (sss<0.1 && sss>-0.1)
- {
- sss = 0;
- }
- cvPutText(dst_img, tostring(sss).c_str(), cvPoint(x + w, y + h),
- &font, CV_RGB(255, 0, 0));
- }
- }
- for (int j = 0; j < result->zhutuanti_result.size(); j++)
- {
- if (pageSchema->question_score[i].question_code == result->zhutuanti_result[j].question_code)
- {
- double sss = result->zhutuanti_result[j].question_score;
- if (sss<0.1 && sss>-0.1)
- {
- sss = 0;
- }
- cvPutText(dst_img, tostring(sss).c_str(), cvPoint(x + w, y + h),
- &font, CV_RGB(255, 0, 0));
- }
- }
- }
- }
- }
|