ResultHandler.cpp 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685
  1. #include "stdafx.h"
  2. #include "ResultHandler.h"
  3. #include "basic_struct.h"
  4. #include "..\ZLibWrapMemLib\MemZipFile.h"
  5. #include "IdentifyService.h"
  6. #include "..\ZLibWrapMemLib\UnZipFile.h"
  7. #include "..\Schema\schema.h"
  8. #include "OnlineCardIdentifor.h"
  9. #include <regex>
  10. #include <thread>
  11. #include <future>
  12. #include <set>
  13. #include "ImgUploadManager.h"
  14. #include "ServerConfig.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. extern int g_my_scan_type;
  21. //督学卡学校id
  22. extern std::string g_strShoolId;
  23. extern int g_myindex;
  24. extern ::string UnicodeToAnsi(const CString& str);
  25. extern CString AnsiToUnicode(const std::string& str);
  26. void CResultHandler::SetIdentifor(CIdentifor* identifor)
  27. {
  28. m_identifor = identifor;
  29. }
  30. CResultHandler::~CResultHandler()
  31. {
  32. }
  33. CResultHandler::CResultHandler()
  34. {
  35. m_nOnlineScanType = -1;
  36. m_bSvePage = false;
  37. m_bErrorHandle = false;
  38. m_strQr = "";
  39. m_bUseQr = false;
  40. m_hwnd = NULL;
  41. m_bOnlineCard = false;
  42. m_bUseQrCode =false;//是否使用二维码
  43. m_bIdentifyQrCode = false;// 是否识别二维码
  44. }
  45. ServiceState CResultHandler::OnRunning(void)
  46. {
  47. ServiceState nextState = IService::OnRunning();
  48. if (nextState == pausing) return nextState;
  49. if (m_muban_page_count <= 0 && m_identifor->IsMubanLoaded()){
  50. m_muban_page_count = m_identifor->GetMubanCount();
  51. m_isMubanLoaded = TRUE;
  52. }
  53. if (m_isMubanLoaded == FALSE){
  54. Sleep(10); return running;
  55. }
  56. CIdentifyTask* task = taskManager->getCurrentHandleTask();
  57. if (task){
  58. pUnhandledPageInfo = task->getUnhandledPageManager();
  59. }
  60. else{
  61. if (m_bOnlineCard && m_hwnd != NULL && !m_bIdentifyQrCode)
  62. ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)2, (LPARAM)NULL);
  63. return stoping;
  64. }
  65. UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo;
  66. int handle_count_limit = (unhandledPageInfo.m_stop&&unhandledPageInfo.unhandled_page_count>0) ? min(m_muban_page_count, unhandledPageInfo.unhandled_page_count) : m_muban_page_count;
  67. if (unhandledPageInfo.unhandled_page_count >= handle_count_limit){
  68. if (m_muban_page_count>0){
  69. SavePaper(handle_count_limit);
  70. }
  71. else if (unhandledPageInfo.m_stop){//到停止时 模板还是没有 ,直接清除缓存
  72. unhandledPageInfo.unhandled_page_count = 0;
  73. }
  74. }
  75. CResultManager * bm = task->getResultBufferManager();
  76. OMR_RESULT * omr_result = bm->GetResult(TRUE);
  77. if (!m_handInfo.get()){
  78. const boost::shared_ptr<const HANDLE_INFO>& handleInfo = identifyService->GetHandleInfo();
  79. if (handleInfo.get()){
  80. setHandlInfo(handleInfo);
  81. }
  82. }
  83. if (omr_result == NULL){
  84. if (unhandledPageInfo.unhandled_page_count <= 0){
  85. taskManager->doneTask(task);
  86. }
  87. else{
  88. unhandledPageInfo.m_stop = TRUE;
  89. }
  90. return running;
  91. }
  92. SavePage(omr_result);
  93. return running;
  94. }
  95. ServiceState CResultHandler::OnStarting(void)
  96. {
  97. m_bSend = false;
  98. m_bSvePage = false;
  99. m_bOnlineCard = false;
  100. m_bUseQrCode =false;//是否使用二维码
  101. m_bIdentifyQrCode = false;// 是否识别二维码
  102. m_muban_page_count = 0;
  103. scoreCounter.SetDataBase(db_lock, bantch_db);
  104. scoreCounter.Load();
  105. loadSchema();
  106. return running;
  107. }
  108. ServiceState CResultHandler::OnStoping(void)
  109. {
  110. if (m_bOnlineCard && m_bSvePage){
  111. OnLineCard::PaperTemplate* pTmp = static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->GetTemplate();
  112. if (m_hwnd != NULL && !m_bIdentifyQrCode&& !pTmp->useQrCode)
  113. ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)2, (LPARAM)NULL);
  114. }
  115. return IService::OnStoping();
  116. }
  117. int CResultHandler::SetHandlerWnd(HWND hwnd)
  118. {
  119. m_hwnd = hwnd;
  120. return 0;
  121. }
  122. int CResultHandler::SavePage(OMR_RESULT * omr_result)
  123. {
  124. UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo;
  125. char phy_number[20];
  126. int len = sprintf_s(phy_number, "%d", omr_result->phy_card_number);
  127. int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE;
  128. unhandledPageInfo.unhandled_page_count++;
  129. UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index];
  130. unhandled_page.identified = omr_result->identified;
  131. int page_index = unhandled_page.page_index = omr_result->card_index;
  132. unhandled_page.omr_result = omr_result;
  133. unhandled_page.student_code = "";
  134. if (omr_result->identified){
  135. if (m_bUseQr){
  136. if (!m_strQr.empty()){
  137. std::vector< std::string > _out;
  138. split(m_strQr, "@", &_out);
  139. if (_out.size() >= 3){
  140. unhandled_page.student_code = _out[1];
  141. unhandled_page.student_id = _out[2];;
  142. }
  143. if (!unhandled_page.student_id.empty())return 0;
  144. }
  145. }
  146. bool needRead = true;
  147. for (int i = 0; needRead&&i < omr_result->qr_result.size(); i++)
  148. {
  149. if (omr_result->qr_result[i].qr_str.length()>0){
  150. unhandled_page.student_code = omr_result->qr_result[i].qr_str;
  151. needRead = false;
  152. break;
  153. }
  154. }
  155. const std::vector<TIANTUKAOHAO_RESULT_HANDLE_INFO>& tiantukaohaoHandleInfo = m_handInfoMap[page_index].tiantukaohaoHandleInfo;
  156. for (int i = 0; needRead&&i<tiantukaohaoHandleInfo.size(); i++)
  157. {
  158. std::string student_code;
  159. bool isRight = true;
  160. for (int j = 0; j<tiantukaohaoHandleInfo[i].group_index.size(); j++)
  161. {
  162. const char * answer = omr_result->group_result[tiantukaohaoHandleInfo[i].group_index[j]].answer.c_str();
  163. student_code += answer;
  164. if (answer[0] == '\0')
  165. {
  166. break;
  167. }
  168. //if (answer[0] == 0){ student_code += "*"; isRight = false; }
  169. }
  170. if (student_code.length() < 1)
  171. {
  172. student_code += "*"; isRight = false;
  173. }
  174. if (student_code.length() > 30)isRight = false;
  175. if (isRight){
  176. if (g_my_scan_type == 0)
  177. {
  178. unhandled_page.student_code = student_code;
  179. }
  180. else
  181. {
  182. /*
  183. if (g_myindex <= 5)
  184. {
  185. unhandled_page.student_code = g_strShoolId;
  186. for (int i = 0; i < student_code.length(); i++)
  187. {
  188. unhandled_page.student_code += student_code.at(student_code.length() - 1 - i);
  189. }
  190. }
  191. else
  192. {
  193. */
  194. unhandled_page.student_code = (g_strShoolId + student_code);
  195. //}
  196. }
  197. needRead = false;
  198. break;
  199. }
  200. }
  201. }
  202. return 0;
  203. }
  204. #include <memory>
  205. #include <mutex>
  206. #include <atomic>
  207. std::mutex mtxTaskNum;
  208. std::atomic<int> taskNum = 0;
  209. struct SavePathImgPara{
  210. std::string path;
  211. CString pathSave;
  212. int m;
  213. SavePathImgPara(std::string path1, CString path2, int n) :path(path1), pathSave(path2), m(n){}
  214. };
  215. struct saveImgesPara1{
  216. vector<CUT_AREA_RESULT*> *area_rst;
  217. CString path;
  218. int subjectID;
  219. bool flag;
  220. //int ID;
  221. saveImgesPara1(vector<CUT_AREA_RESULT*> *area_rst1, CString name1, int subjectid, bool flag1) : path(name1), subjectID(subjectid), flag(flag1)
  222. {
  223. area_rst = area_rst1;
  224. //ID = id;
  225. //printf("name: %s \r\n ", (*area_rst)[0]->area_name.c_str());
  226. }
  227. };
  228. int SavePathImgMy(PVOID para1)
  229. {
  230. SavePathImgPara *para = (SavePathImgPara *)para1;
  231. std::string path = para->path;
  232. CString question_code;
  233. question_code.Format(_T("\\image_%d.jpg"), para->m + 1);
  234. CString oldfile;
  235. oldfile = CA2T(path.c_str());
  236. CString savePath = para->pathSave + question_code;
  237. CopyFile(oldfile, savePath, FALSE);
  238. /*
  239. IplImage* pImg = cvLoadImage(path.c_str(), 1);
  240. CString question_code;
  241. question_code.Format(_T("\\image_%d.jpg"), para->m + 1);
  242. CString savePath = para->pathSave + question_code;
  243. //savePath.Format(_T("%s%s"), para->pathSave.c_str(), question_code);
  244. //zip.PutNextEntry(question_code);
  245. vector<uchar> dst;
  246. vector<int> compression_params_low;
  247. compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
  248. compression_params_low.push_back(40);
  249. vector<int> compression_params_high;
  250. compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
  251. compression_params_high.push_back(60);
  252. cv::Mat _img = cv::cvarrToMat(pImg);
  253. if (pImg->height > 500){
  254. imencode(".jpg", _img, dst, compression_params_low);
  255. }
  256. else{
  257. imencode(".jpg", _img, dst, compression_params_high);
  258. }
  259. cvReleaseImage(&pImg);
  260. //zip.Write(&dst[0], dst.size());
  261. CFile file;
  262. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  263. file.Write(dst.data(), dst.size());
  264. file.Close();
  265. */
  266. return 0;
  267. }
  268. void saveImgPathMyCallback(PVOID para1/*CString filepath, CString key*/)
  269. {
  270. std::lock_guard<std::mutex> _lk(mtxTaskNum);
  271. taskNum--;
  272. //delete para1;
  273. //para1 = NULL;
  274. }
  275. int saveImgesMy1(PVOID para1/*CString filepath, CString key*/)
  276. {
  277. //printf("saveImgesMy1 %p\r\n", para1);
  278. saveImgesPara1 *para = (saveImgesPara1 *)para1;
  279. vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
  280. CString path = para->path;
  281. bool flag = para->flag;
  282. int subjectID = para->subjectID;
  283. //printf("DST name=%s\n", (*area_results)[0]->area_name.c_str());
  284. std::string area_name;
  285. CString savePath;
  286. CFile file;
  287. if ((*area_results)[0]->area_name == "")
  288. {
  289. area_name = (*area_results)[0]->area_name;
  290. int idx;
  291. area_name = ((idx = area_name.find('.')) < 0) ? area_name : area_name.substr(0, idx);
  292. CString question_code;
  293. question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str()));
  294. savePath = path + question_code;
  295. //printf("flag: %d , subjectID = %d,id: %d \r\n", flag?1:0, subjectID, para->ID);
  296. }
  297. else
  298. {
  299. area_name = (*area_results)[0]->area_name;
  300. CString question_code;
  301. question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str()));
  302. //printf("flag: %d , subjectID = %d,id: %d \r\n", flag ? 1 : 0, subjectID, para->ID);
  303. savePath = path + question_code;
  304. }
  305. if ((*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){
  306. int width = 0;
  307. int height = 0;
  308. for (int jj = 0; jj < (*area_results).size(); jj++)
  309. {
  310. if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width;
  311. height += (*area_results)[jj]->height;
  312. }
  313. cv::Mat img_big(cv::Size(width, height), CV_8UC3, cv::Scalar(255, 255, 255));
  314. for (int ii = 0, top = 0; ii < (*area_results).size(); ii++)
  315. {
  316. Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data());
  317. Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_COLOR);
  318. cv::Rect rc_tmp(0, top, temp_img.cols, temp_img.rows);
  319. Mat cut = img_big(rc_tmp);
  320. temp_img.copyTo(cut);
  321. top += temp_img.rows;
  322. }
  323. //////////////////////////////////////////////////////////////////////////
  324. vector<uchar> dst;
  325. //cv::Mat _img = cv::cvarrToMat(img);
  326. vector<int> compression_params;
  327. compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
  328. compression_params.push_back(25);
  329. imencode(".jpg", img_big, dst, compression_params);
  330. //cvResetImageROI(img);
  331. //zip.Write(&dst[0], dst.size());
  332. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  333. file.Write(dst.data(), dst.size());
  334. file.Close();
  335. if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1)
  336. {
  337. CString question_code;
  338. question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str()));
  339. savePath = path + question_code;
  340. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  341. file.Write(dst.data(), dst.size());
  342. file.Close();
  343. //zip.PutNextEntry(question_code);
  344. //zip.Write(&dst[0], dst.size());
  345. }
  346. }
  347. else
  348. {
  349. if ((*area_results)[0]->is_cut > 0)
  350. {
  351. //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size());
  352. if (file.Open(savePath, CFile::modeCreate | CFile::modeWrite)){
  353. file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
  354. file.Close();
  355. }
  356. else{
  357. auto e = GetLastError();
  358. int n = 0; ++n;
  359. }
  360. if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1)
  361. {
  362. //zip.PutNextEntry(AnsiToUnicode(area_name + "f.jpg"));
  363. //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size());
  364. CString question_code;
  365. question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str()));
  366. savePath = path + question_code;
  367. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  368. file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
  369. file.Close();
  370. }
  371. }
  372. else
  373. {
  374. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  375. file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size());
  376. file.Close();
  377. //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size());
  378. }
  379. }
  380. if (flag && (*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){
  381. vector<int> compression_params_low;
  382. compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
  383. compression_params_low.push_back(40);
  384. vector<int> compression_params_high;
  385. compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
  386. compression_params_high.push_back(60);
  387. for (int jj = 0; jj < (*area_results).size(); jj++)
  388. {
  389. CString question_code;
  390. question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1);
  391. //zip.PutNextEntry(question_code);
  392. savePath = path + question_code;
  393. /*
  394. int width = (*area_results)[jj]->width;
  395. int height = (*area_results)[jj]->height;
  396. IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
  397. cvSet(img, cvScalarAll(255));
  398. Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data());
  399. Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
  400. cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
  401. cvCopy(&IplImage(temp_img), img);
  402. cvResetImageROI(img);
  403. char sz_question_code[520] = { 0 };
  404. WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
  405. vector<uchar> dst;
  406. cv::Mat _img = cv::cvarrToMat(img);
  407. if (img->height > 500){
  408. imencode(".jpg", _img, dst, compression_params_low);
  409. }
  410. else{
  411. imencode(".jpg", _img, dst, compression_params_high);
  412. }
  413. cvReleaseImage(&img);
  414. */
  415. //zip.Write(&dst[0], dst.size());
  416. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  417. file.Write((*area_results)[jj]->img_data.data(), (*area_results)[jj]->img_data.size());
  418. file.Close();
  419. }
  420. }
  421. //printf("path:%s \r\n",CT2A(savePath));
  422. return 0;
  423. }
  424. bool sort_subindex(const CUT_AREA_RESULT * c1, const CUT_AREA_RESULT * c2){
  425. return c1->area_sub_index < c2->area_sub_index;
  426. }
  427. int saveImgesMy2(PVOID para1/*CString filepath, CString key*/)
  428. {
  429. saveImgesPara1 *para = (saveImgesPara1 *)para1;
  430. vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
  431. CString path = para->path;
  432. bool flag = para->flag;
  433. int subjectID = para->subjectID;
  434. CString question_code;
  435. question_code.Format(_T("\\%s.jpg"), CString((*area_results)[0]->area_name.c_str()));
  436. //zip.PutNextEntry(question_code);
  437. std::sort((*area_results).begin(), (*area_results).end(), sort_subindex);
  438. CString savePath = path + question_code;
  439. //postMarkTypeID == 10 判断
  440. vector<int> compression_params_low;
  441. compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
  442. compression_params_low.push_back(40);
  443. vector<int> compression_params_high;
  444. compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
  445. compression_params_high.push_back(60);
  446. int width = 0;
  447. int height = 0;
  448. int centerx = 0, centery = 0;
  449. for (int jj = 0; jj < (*area_results).size(); jj++)
  450. {
  451. if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width;
  452. height += (*area_results)[jj]->height;
  453. centerx = (*area_results)[jj]->centerx;
  454. centery += (*area_results)[jj]->centery;
  455. }
  456. IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
  457. cvSet(img, cvScalarAll(255));
  458. for (int ii = 0, top = 0; ii < (*area_results).size(); ii++)
  459. {
  460. Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data());
  461. Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
  462. cvSetImageROI(img, cvRect(0, top, temp_img.cols, temp_img.rows));
  463. temp_img.copyTo(cv::cvarrToMat(img));
  464. cvCopy(&IplImage(temp_img), img);
  465. top += (*area_results)[ii]->height;
  466. }
  467. cvResetImageROI(img);
  468. vector<uchar> dst;
  469. cv::Mat _img = cv::cvarrToMat(img);
  470. if (img->height > 500){
  471. imencode(".jpg", _img, dst, compression_params_low);
  472. }
  473. else{
  474. imencode(".jpg", _img, dst, compression_params_high);
  475. }
  476. char sz_question_code[520] = { 0 };
  477. WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
  478. cvReleaseImage(&img);
  479. //zip.Write(&dst[0], dst.size());
  480. CFile file;
  481. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  482. file.Write(dst.data(), dst.size());
  483. file.Close();
  484. //imwrite(savePath.c_str(), img);
  485. if (flag && (*area_results).size() > 1){
  486. for (int jj = 0; jj < (*area_results).size(); jj++)
  487. {
  488. question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1);
  489. //zip.PutNextEntry(question_code);
  490. CString savePath = path + question_code;
  491. width = (*area_results)[jj]->width;
  492. height = (*area_results)[jj]->height;
  493. IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
  494. cvSet(img, cvScalarAll(255));
  495. //for (int ii = 0, top = 0; ii < area_results.size(); ii++)
  496. //{
  497. Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data());
  498. Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
  499. cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
  500. cvCopy(&IplImage(temp_img), img);
  501. //top += area_results[ii]->height;
  502. //}
  503. cvResetImageROI(img);
  504. char sz_question_code[520] = { 0 };
  505. WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
  506. vector<uchar> dst;
  507. cv::Mat _img = cv::cvarrToMat(img);
  508. if (img->height > 500){
  509. imencode(".jpg", _img, dst, compression_params_low);
  510. }
  511. else{
  512. imencode(".jpg", _img, dst, compression_params_high);
  513. }
  514. cvReleaseImage(&img);
  515. //zip.Write(&dst[0], dst.size());
  516. CFile file;
  517. file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  518. file.Write(dst.data(), dst.size());
  519. file.Close();
  520. }
  521. }
  522. return 0;
  523. }
  524. // 算法组提供的新算法 解决 cvcopy崩溃的问题
  525. // int saveImgesMy2(PVOID para1/*CString filepath, CString key*/)
  526. // {
  527. // saveImgesPara1 *para = (saveImgesPara1 *)para1;
  528. // vector<CUT_AREA_RESULT*> *area_results = para->area_rst;
  529. // CString path = para->path;
  530. // bool flag = para->flag;
  531. // int subjectID = para->subjectID;
  532. //
  533. // CString question_code;
  534. // question_code.Format(_T("\\%s.jpg"), CString((*area_results)[0]->area_name.c_str()));
  535. // //zip.PutNextEntry(question_code);
  536. // std::sort((*area_results).begin(), (*area_results).end(), sort_subindex);
  537. // CString savePath = path + question_code;
  538. // //postMarkTypeID == 10 判断
  539. //
  540. //
  541. // vector<int> compression_params_low;
  542. // compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
  543. // compression_params_low.push_back(40);
  544. // vector<int> compression_params_high;
  545. // compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
  546. // compression_params_high.push_back(60);
  547. // int width = 0;
  548. // int height = 0;
  549. // int centerx = 0, centery = 0;
  550. // for (int jj = 0; jj < (*area_results).size(); jj++)
  551. // {
  552. // if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width;
  553. // height += (*area_results)[jj]->height;
  554. // centerx = (*area_results)[jj]->centerx;
  555. // centery += (*area_results)[jj]->centery;
  556. // }
  557. //
  558. //
  559. // cv::Mat _img = cv::Mat(cv::Size(width, height), CV_8U, cv::Scalar(255));
  560. // for (int ii = 0, top = 0; ii < (*area_results).size(); ii++)
  561. // {
  562. // Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data());
  563. // Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
  564. // temp_img.copyTo(_img(cv::Rect(0, top, temp_img.cols, temp_img.rows)));
  565. // top += (*area_results)[ii]->height;
  566. // }
  567. //
  568. // vector<uchar> dst;
  569. // if (_img.rows > 500) {
  570. // imencode(".jpg", _img, dst, compression_params_low);
  571. // }
  572. // else {
  573. // imencode(".jpg", _img, dst, compression_params_high);
  574. // }
  575. // char sz_question_code[520] = { 0 };
  576. // WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
  577. // //zip.Write(&dst[0], dst.size());
  578. // CFile file;
  579. // file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  580. // file.Write(dst.data(), dst.size());
  581. // file.Close();
  582. // //imwrite(savePath.c_str(), img);
  583. //
  584. // if (flag && (*area_results).size() > 1) {
  585. // for (int jj = 0; jj < (*area_results).size(); jj++)
  586. // {
  587. // question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1);
  588. // //zip.PutNextEntry(question_code);
  589. // CString savePath = path + question_code;
  590. // width = (*area_results)[jj]->width;
  591. // height = (*area_results)[jj]->height;
  592. // IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
  593. // cvSet(img, cvScalarAll(255));
  594. // //for (int ii = 0, top = 0; ii < area_results.size(); ii++)
  595. // //{
  596. // Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data());
  597. // Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
  598. // cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
  599. // cvCopy(&IplImage(temp_img), img);
  600. // //top += area_results[ii]->height;
  601. // //}
  602. // cvResetImageROI(img);
  603. // char sz_question_code[520] = { 0 };
  604. // WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
  605. // vector<uchar> dst;
  606. // cv::Mat _img = cv::cvarrToMat(img);
  607. // if (img->height > 500) {
  608. // imencode(".jpg", _img, dst, compression_params_low);
  609. // }
  610. // else {
  611. // imencode(".jpg", _img, dst, compression_params_high);
  612. // }
  613. // cvReleaseImage(&img);
  614. // //zip.Write(&dst[0], dst.size());
  615. // CFile file;
  616. // file.Open(savePath, CFile::modeCreate | CFile::modeWrite);
  617. // file.Write(dst.data(), dst.size());
  618. // file.Close();
  619. // }
  620. // }
  621. // return 0;
  622. // }
  623. void saveImgesMyCallback(PVOID para1/*CString filepath, CString key*/)
  624. {
  625. std::lock_guard<std::mutex> _lk(mtxTaskNum);
  626. taskNum--;
  627. #ifdef _DEBUG
  628. LOGFMTI("回调调用-3 taskNum=%d",taskNum.load());
  629. #endif
  630. //delete para1;
  631. //para1 = NULL;
  632. }
  633. void CResultHandler::SavePaper(int handle_count_limit)
  634. {
  635. //printf("SavePaper \n");
  636. UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo;
  637. bool identified;//当前这份试卷是否已识别
  638. int identified_count = 0;//已识别页数
  639. int paper_page_count = 0;//当前这份试卷的页数
  640. int student_paper_id = -1;
  641. std::string student_id = "-1";
  642. long class_id = -1;
  643. int class_total = -1;
  644. char student_name[20] = { 0 };
  645. char class_info[20] = { 0 };
  646. float total_score = 0;
  647. long exceptions = EX_NOMARL;
  648. string studentcode;//学生证号
  649. std::map<int, int> page_counts;
  650. std::map<std::string, int> vecTwoPic;
  651. std::map<int, std::vector<CUT_AREA_RESULT*>> mm;
  652. std::vector<int> _mm_tmp;
  653. //筛选语文的主观题和选做题
  654. std::vector<std::string> postMarkTypeIDVec;
  655. bool b_is_same_exam_id = false;
  656. /************************************************************************/
  657. /* 确定试卷页数,并确定试卷ID 和 试卷编号 */
  658. /************************************************************************/
  659. for (int i = 0; i<handle_count_limit; i++)
  660. {
  661. int index1 = (unhandledPageInfo.first_unhandled_page_index + i) % MAX_UNHANDLED_PAGE;
  662. if (unhandledPageInfo.bOnlineCard){
  663. //!unhandledPageInfo.unhandled_pages[index1].omr_result->is_use_qr_code&&
  664. if (
  665. unhandledPageInfo.unhandled_pages[index1].omr_result->is_front_page&&
  666. !unhandledPageInfo.unhandled_pages[index1].omr_result->is_same_exam_id)
  667. {
  668. b_is_same_exam_id = true;
  669. if (!m_bSend){
  670. m_bSend = true;
  671. if (m_hwnd != NULL)
  672. ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)1, (LPARAM)NULL);
  673. }
  674. }
  675. OnLineCard::PaperTemplate* pTmp = static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->GetTemplate();
  676. if (unhandledPageInfo.unhandled_pages[index1].omr_result->examid_by_qr_code&&!m_bIdentifyQrCode &&
  677. !pTmp->useQrCode)
  678. {
  679. m_bIdentifyQrCode = true;
  680. }
  681. }
  682. BOOL is_next = FALSE;//是否是下一份试卷
  683. //比较考号是否不一样 依此判断是否是下一份试卷
  684. if (unhandledPageInfo.unhandled_pages[index1].student_code.length()>0){
  685. if (studentcode.length()>0){
  686. if (studentcode != unhandledPageInfo.unhandled_pages[index1].student_code){
  687. is_next = TRUE;
  688. }
  689. }
  690. else{
  691. studentcode = unhandledPageInfo.unhandled_pages[index1].student_code;
  692. }
  693. }
  694. if (is_next){
  695. break;
  696. }
  697. page_counts[unhandledPageInfo.unhandled_pages[index1].page_index]++;
  698. //比较试卷页码是否重复 依此判断是否是下一份试卷
  699. for (int j = 0; j<i; j++)
  700. {
  701. int index2 = (unhandledPageInfo.first_unhandled_page_index + j) % MAX_UNHANDLED_PAGE;
  702. if (unhandledPageInfo.unhandled_pages[index2].page_index == unhandledPageInfo.unhandled_pages[index1].page_index &&unhandledPageInfo.unhandled_pages[index1].page_index != -1){
  703. is_next = TRUE;
  704. break;
  705. }
  706. }
  707. is_next = FALSE;
  708. if (is_next){
  709. break;
  710. }
  711. paper_page_count++;
  712. OMR_RESULT* omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  713. if (omr_result->paper_id > 0){
  714. student_paper_id = omr_result->paper_id;
  715. }
  716. if (m_nOnlineScanType == 0 && omr_result->is_front_page && omr_result->strMagicClassId.length() && omr_result->strMagicStudentId.length())
  717. {
  718. CString strPaperCode;
  719. readPaperId(strPaperCode);
  720. WriteOnlineCardPaperId(strPaperCode, (wstring)AnsiToUnicode(omr_result->strMagicClassId), (wstring)AnsiToUnicode(omr_result->strMagicStudentId));
  721. }
  722. std::string str_stu_id = unhandledPageInfo.unhandled_pages[index1].student_id;
  723. if (!str_stu_id.empty()){
  724. student_id = str_stu_id;
  725. }
  726. if (unhandledPageInfo.unhandled_pages[index1].identified){
  727. identified_count++;
  728. }
  729. }
  730. identified = (identified_count == m_muban_page_count&&page_counts.size() == m_muban_page_count);
  731. if (page_counts.size()<m_muban_page_count) exceptions |= EX_DINGWEIDIAN; // 出现缺页情况统一为定位点异常 exceptions |= EX_SHIJUANQUEYE;
  732. int isAbsent = 0;
  733. std::string shijuanleixing = "A";
  734. for (int m = 0; m<paper_page_count; m++)
  735. {
  736. int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
  737. if (!unhandledPageInfo.bOnlineCard){
  738. static const std::string Q = "Q";
  739. if (unhandledPageInfo.unhandled_pages[page_index].omr_result->identified){
  740. int indx = unhandledPageInfo.unhandled_pages[page_index].omr_result->card_index;
  741. if (existAbsentFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result) && Q == absentFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result)){
  742. isAbsent = 1;
  743. }
  744. if (existABJuanFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result)){
  745. shijuanleixing = ABJuanFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result);
  746. }
  747. }
  748. }
  749. else{
  750. auto tmp = unhandledPageInfo.unhandled_pages[page_index].omr_result;
  751. if (tmp&& tmp->identified && isAbsent ==0){
  752. isAbsent = tmp->quekaoFlag;
  753. }
  754. }
  755. }
  756. if (isAbsent != 0) exceptions |= EX_SHIJUANQUEKAO;
  757. /************************************************************************/
  758. /* 保存切割好的图像 */
  759. /************************************************************************/
  760. // printf("切图\n");
  761. std::map<std::string, std::string> _map_real_name;
  762. char sz_file_name[520] = { 0 };
  763. char sz_ori_file_name[520] = { 0 };
  764. if (identified){//将切割好的图像压缩为zip
  765. CString filename = m_img_clips_dir + _T("\\") + GetTimeString();
  766. CreateDirectory(filename, NULL);
  767. filename += _T("\\img");
  768. CreateDirectory(filename, NULL);
  769. CString filename1 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("ori");
  770. CreateDirectory(filename1, NULL);
  771. filename1 += _T("\\img");
  772. CreateDirectory(filename1, NULL);
  773. WideCharToMultiByte(CP_ACP, 0, filename, -1, sz_file_name, 520, NULL, NULL);
  774. WideCharToMultiByte(CP_ACP, 0, filename1, -1, sz_ori_file_name, 520, NULL, NULL);;
  775. //CMemFile file;
  776. //CMemFile file3;
  777. //CMemZipFile zip;
  778. //CMemZipFile zip1;
  779. //zip.OpenFile(&file);
  780. //zip1.OpenFile(&file3);
  781. vector<CUT_AREA_RESULT*> area_results;
  782. UnhandledPage* unhandledPage[16];
  783. for (int m = 0; m<paper_page_count; m++)
  784. {
  785. int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
  786. unhandledPage[m] = &unhandledPageInfo.unhandled_pages[page_index];
  787. }
  788. for (int m = 0; m<paper_page_count; m++)
  789. {
  790. for (int n = m + 1; n<paper_page_count; n++){
  791. if (unhandledPage[m]->page_index>unhandledPage[n]->page_index){
  792. UnhandledPage* t_page = unhandledPage[m];
  793. unhandledPage[m] = unhandledPage[n];
  794. unhandledPage[n] = t_page;
  795. }
  796. }
  797. }
  798. int nQuestionNo = 0;
  799. int nZhuGuanTi = 0, nXuanZuoTi = 0, nZhuGuanTi2 = 0, nXuanZuoTi2 = 0, nCutCount = 0;
  800. static bool falg = false;
  801. if (!unhandledPageInfo.bOnlineCard){
  802. if (!falg && g_my_scan_type != 1)
  803. {
  804. loadSchema();
  805. falg = true;
  806. }
  807. else if (g_my_scan_type == 1)
  808. loadSchema();
  809. for (int i = 0; i < m_schema.questions.size(); i++)
  810. {
  811. if (m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI || m_schema.questions[i].questionType == ZHUGUANTI)
  812. {
  813. if (10 == m_schema.questions[i].postMarkTypeID || 4 == m_schema.questions[i].postMarkTypeID )
  814. postMarkTypeIDVec.push_back(m_schema.questions[i].question_code_new);
  815. }
  816. }
  817. for (int i = 0; i < m_schema.questions.size(); i++)
  818. {
  819. if (m_schema.questions[i].questionType == TIANKONGTI || m_schema.questions[i].questionType == ZHUGUANTI)
  820. {
  821. nZhuGuanTi++;
  822. }
  823. else if (m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI)
  824. {
  825. nXuanZuoTi++;
  826. }
  827. }
  828. }
  829. vector<int> vecQuestionNo;
  830. map<string, int> mapQuestionNo;
  831. if (unhandledPageInfo.bOnlineCard){
  832. OnLineCard::PaperTemplate* pTmp = static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->GetTemplate();
  833. if (pTmp){
  834. for (auto it: pTmp->pages){
  835. for (auto itQ : it.second.vctQuestions){
  836. if (itQ.marktype == 4 || itQ.marktype == 10)
  837. {
  838. postMarkTypeIDVec.push_back(itQ.id);
  839. }
  840. vecQuestionNo.push_back(std::stoi(itQ.id));
  841. }
  842. }
  843. }
  844. }
  845. else{
  846. for (std::size_t i = 0; i < m_schema.questions.size(); i++)
  847. {
  848. if (m_schema.questions[i].questionType == TIANKONGTI || m_schema.questions[i].questionType == ZHUGUANTI || m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI)
  849. {
  850. vecQuestionNo.push_back(atoi(m_schema.questions[i].question_code_new));
  851. }
  852. }
  853. }
  854. if (vecQuestionNo.size()>1)
  855. {
  856. sort(vecQuestionNo.begin(), vecQuestionNo.end(), less_equal<int>());
  857. }
  858. std::map<std::string, std::pair<int,std::string>> _map_duoxuanti;
  859. //std::vector<std::string> _vct_all_questions;
  860. std::map<std::string, std::vector<std::string>> _map_duoxuantiquanti;
  861. std::string strtempallxuanzuotiqs = "";
  862. std::vector<SavePathImgPara *> paraVec1;
  863. for (int m = 0; m<paper_page_count; m++)
  864. {
  865. if (pUnhandledPageInfo->bOnlineCard)
  866. {
  867. int index1 = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
  868. OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  869. for (int i = 0; i < omr_result->zhutuanti_result.size(); i++)
  870. {
  871. auto question_code = omr_result->zhutuanti_result[i].question_code;
  872. if (omr_result->zhutuanti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::XUANZUOTI){
  873. std::string strAllQuestions = omr_result->zhutuanti_result[i].question_code_all;
  874. int nSel = -1;
  875. if (omr_result->zhutuanti_result[i].question_code_all != omr_result->zhutuanti_result[i].question_code_temp && omr_result->zhutuanti_result[i].xuanze == -2)
  876. {
  877. //说明是类型4的分组选做题
  878. bool bfindselect = false;
  879. //本业查找(一定再这个数据之前)
  880. for (int j = i -1 ; j >= 0; j--)
  881. {
  882. if (omr_result->zhutuanti_result[i].question_code_temp == omr_result->zhutuanti_result[j].question_code_temp && omr_result->zhutuanti_result[j].xuanze != -2)
  883. {
  884. nSel = omr_result->zhutuanti_result[j].xuanze;
  885. omr_result->zhutuanti_result[i].xuanze = nSel;
  886. bfindselect = true;
  887. break;
  888. }
  889. }
  890. //没有找到,向前面查找
  891. if (!bfindselect)
  892. {
  893. for (int n = m - 1; n >= 0; n--)
  894. {
  895. bfindselect = false;
  896. int index2 = (unhandledPageInfo.first_unhandled_page_index + n) % MAX_UNHANDLED_PAGE;
  897. OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index2].omr_result;
  898. for (int j = omr_result1->zhutuanti_result.size() - 1; j >= 0; j--)
  899. {
  900. if (omr_result->zhutuanti_result[i].question_code_temp == omr_result1->zhutuanti_result[j].question_code_temp && omr_result1->zhutuanti_result[j].xuanze != -2)
  901. {
  902. nSel = omr_result1->zhutuanti_result[j].xuanze;
  903. omr_result->zhutuanti_result[i].xuanze = nSel;
  904. bfindselect = true;
  905. break;
  906. }
  907. }
  908. if (bfindselect)
  909. break;
  910. }
  911. }
  912. }
  913. else
  914. {
  915. nSel = omr_result->zhutuanti_result[i].xuanze;
  916. }
  917. _map_duoxuanti[question_code] = std::make_pair(nSel, strAllQuestions);
  918. //if (_vct_all_questions.empty()){
  919. if (strtempallxuanzuotiqs != strAllQuestions){
  920. std::vector<std::string> _vct_all_questions;
  921. split(strAllQuestions, (std::string)",", &_vct_all_questions);
  922. _map_duoxuantiquanti[strAllQuestions] = _vct_all_questions;
  923. strtempallxuanzuotiqs = strAllQuestions;
  924. }
  925. }
  926. }
  927. }
  928. ThreadPool *threadPool = CImgUploadManager::GetInstance()->getThreadPool();
  929. int nQueKaoNo = 0, nLengthOfTianTuKaoHao = 0;
  930. OMR_RESULT* omr_result = unhandledPage[m]->omr_result;
  931. SavePathImgPara *para = new SavePathImgPara(omr_result->img_path, filename1, m);
  932. //SavePathImg(omr_result->img_path, zip1, m);
  933. paraVec1.push_back(para);
  934. std::lock_guard<std::mutex> _lk(mtxTaskNum);
  935. taskNum++;
  936. threadPool->QueueTaskItem(SavePathImgMy, para, saveImgPathMyCallback);
  937. if (unhandledPageInfo.bOnlineCard){
  938. nQueKaoNo = 1;
  939. }
  940. else{
  941. nQueKaoNo = m_schema.pages[m].quekaobiaoji.size();
  942. if (m_schema.pages[m].tiantukaohao.size()>0)
  943. {
  944. if (m_schema.pages[m].tiantukaohao[m].direction == 1)//Vertical;
  945. nLengthOfTianTuKaoHao = m_schema.pages[m].tiantukaohao[m].nCols;
  946. else
  947. nLengthOfTianTuKaoHao = m_schema.pages[m].tiantukaohao[m].nRows;
  948. }
  949. }
  950. for (int t = 0; t < omr_result->cut_area_result.size(); t++)
  951. {
  952. if (mapQuestionNo.size() >= 0)
  953. {
  954. map<string, int>::iterator it = mapQuestionNo.find(omr_result->cut_area_result[t].area_name);
  955. if (it == mapQuestionNo.end())
  956. mapQuestionNo.insert(map<string, int>::value_type(omr_result->cut_area_result[t].area_name, vecQuestionNo[nCutCount + t]));
  957. else
  958. nCutCount = nCutCount - 1;
  959. }
  960. }
  961. nCutCount = mapQuestionNo.size();
  962. /*if (isAbsent == 0)*/{
  963. for (int n = 0; n<omr_result->cut_area_result.size(); n++)
  964. {
  965. int nKeguanti, nQuestionIndex;
  966. CString strTimu;
  967. char cstrTemp[20];
  968. string strAreaName;
  969. nZhuGuanTi2++;
  970. const std::vector<XUANZUOTI_RESULT_HANDLE_INFO>& xuanzuotiHandleInfo = m_handInfoMap[omr_result->card_index].xuanzuotiHandleInfo;
  971. for (int i = 0; i < xuanzuotiHandleInfo.size(); i++)
  972. {
  973. const char * answer = omr_result->group_result[nQueKaoNo + nLengthOfTianTuKaoHao + i].answer.c_str();
  974. if (omr_result->group_result[nQueKaoNo + nLengthOfTianTuKaoHao + i].answer != "")
  975. {
  976. mapQuestionNo[omr_result->cut_area_result[omr_result->cut_area_result.size() - i - 1].area_name] = atoi(answer);
  977. for (int t = 0; t < xuanzuotiHandleInfo[i].option_question_code[0].size(); t++)
  978. {
  979. if (omr_result->cut_area_result[n].area_name == xuanzuotiHandleInfo[i].option_question_code[0][t].at(0))
  980. {
  981. omr_result->cut_area_result[n].area_name = answer;
  982. break;
  983. }
  984. }
  985. }
  986. }
  987. nKeguanti = m_schema.questions.size();
  988. nKeguanti = _wtoi(strTimu.Left(strTimu.Find('&')));
  989. nQuestionIndex = nKeguanti + atoi(omr_result->cut_area_result[n].area_name.c_str());
  990. itoa(mapQuestionNo[omr_result->cut_area_result[n].area_name], cstrTemp, 10);
  991. strAreaName = cstrTemp;
  992. auto nIndex = omr_result->cut_area_result[n].area_index;
  993. if (pUnhandledPageInfo->bOnlineCard){
  994. nIndex = m * 1000 + nIndex;
  995. }
  996. mm[nIndex].push_back(&omr_result->cut_area_result[n]);
  997. _mm_tmp.push_back(nIndex);
  998. }
  999. }
  1000. }
  1001. std::map<int, std::vector<CUT_AREA_RESULT*>>::iterator it;
  1002. char strPaperCode[MAX_PATH];
  1003. std::memset(strPaperCode, 0, MAX_PATH);
  1004. CString strPaperId;
  1005. readPaperId(strPaperId);
  1006. for (int i = 0; i<strPaperId.GetLength(); i++)
  1007. {
  1008. strPaperCode[i] = strPaperId.GetAt(i);
  1009. }
  1010. ThreadPool *threadPool = CImgUploadManager::GetInstance()->getThreadPool();
  1011. std::vector<saveImgesPara1 *> paraVec2;
  1012. vector<CUT_AREA_RESULT*> area_rstlist[400];
  1013. int listpos = 0;
  1014. if (pUnhandledPageInfo->bOnlineCard){
  1015. int idx = 0;
  1016. std::vector<std::string> tmp_all_q;
  1017. std::vector<int> _vct_sel;
  1018. std::vector<int> _mm_unsel_tmp;
  1019. std::vector<std::string> _tmp_name;
  1020. std::string area_name_t;
  1021. std::string strtempallxuanzuotiqs = "";
  1022. std::vector<std::string> _vct_all_questions;
  1023. for (auto it = _mm_tmp.begin(); it != _mm_tmp.end(); ++it, ++idx){
  1024. std::vector<CUT_AREA_RESULT*> &area_tmp = mm[*it];
  1025. vector<CUT_AREA_RESULT*> &area_rst = area_rstlist[listpos++];
  1026. area_rst.push_back(area_tmp[0]);
  1027. int area_sub_index = area_tmp[0]->area_sub_index;
  1028. bool is_cut = area_tmp[0]->is_cut;
  1029. bool b_duoxuan = false;
  1030. bool b_save = true;
  1031. bool b_sel = false;
  1032. std::string name = area_tmp[0]->area_name;
  1033. auto itFind = _map_duoxuanti.find(area_tmp[0]->area_name);
  1034. if (itFind != _map_duoxuanti.end()){
  1035. if (strtempallxuanzuotiqs != itFind->second.second)
  1036. {
  1037. //肯定可以找到
  1038. _vct_all_questions.clear();
  1039. _vct_sel.clear();
  1040. tmp_all_q.clear();
  1041. _vct_all_questions = _map_duoxuantiquanti.find(itFind->second.second)->second;
  1042. strtempallxuanzuotiqs = itFind->second.second;
  1043. tmp_all_q = _vct_all_questions;
  1044. }
  1045. b_duoxuan = true;
  1046. _tmp_name.push_back(itFind->first);
  1047. std::string area_name;
  1048. int sel = itFind->second.first;
  1049. if (sel >= 0 && sel < _vct_all_questions.size() &&
  1050. std::find(_vct_sel.begin(), _vct_sel.end(), sel) == _vct_sel.end()){
  1051. area_name = _vct_all_questions[sel];
  1052. _vct_sel.push_back(sel);
  1053. tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end());
  1054. _map_real_name[area_tmp[0]->area_name] = area_name;
  1055. area_tmp[0]->area_name = area_name;
  1056. _map_duoxuanti.erase(itFind);
  1057. b_sel = true;
  1058. }
  1059. else{
  1060. _mm_unsel_tmp.push_back(*it);
  1061. std::string area_name = *tmp_all_q.begin();
  1062. tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end());
  1063. _map_real_name[area_rst[0]->area_name] = area_name;
  1064. b_save = false;
  1065. }
  1066. }
  1067. int next_id = idx + 1;
  1068. while (next_id < _mm_tmp.size())
  1069. {
  1070. if (area_sub_index == 1 && is_cut &&
  1071. mm[_mm_tmp[next_id]].size()>0
  1072. && mm[_mm_tmp[next_id]][0]->area_sub_index == 0){
  1073. ++it; ++idx;
  1074. if (b_duoxuan && !b_sel){
  1075. _mm_unsel_tmp.push_back(*it);
  1076. b_save = false;
  1077. }
  1078. area_rst.push_back(mm[*it][0]);
  1079. next_id = idx + 1;
  1080. }
  1081. else{
  1082. break;
  1083. }
  1084. }
  1085. if (b_save){
  1086. BOOL flag = false;
  1087. //if (pUnhandledPageInfo->nSubjectID == 0)
  1088. {
  1089. for (int i = 0; i < postMarkTypeIDVec.size(); i++)
  1090. {
  1091. for (int j = 0; j < area_rst.size(); j++){
  1092. if (postMarkTypeIDVec[i] == area_rst[j]->area_name)
  1093. {
  1094. flag = true;
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. }
  1100. if (flag && area_rst.size() > 1 && area_rst[0]->is_cut){
  1101. vecTwoPic[area_rst[0]->area_name.c_str()] = area_rst.size();
  1102. }
  1103. //printf("SRC name=%s\n", area_rst[0]->area_name.c_str());
  1104. saveImgesPara1 *para = new saveImgesPara1(&area_rst, filename, pUnhandledPageInfo->nSubjectID, flag);
  1105. ///printf("para %p\r\n", para);
  1106. paraVec2.push_back(para);
  1107. std::lock_guard<std::mutex> _lk(mtxTaskNum);
  1108. taskNum++;
  1109. threadPool->QueueTaskItem(saveImgesMy1, para, saveImgesMyCallback);
  1110. //SaveImages(area_rst, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic);
  1111. }
  1112. //area_rst.clear();
  1113. area_name_t = "";
  1114. }
  1115. bool bClear = false;
  1116. vector<CUT_AREA_RESULT*> &area_rst = area_rstlist[listpos];
  1117. idx = 0;
  1118. for (auto it = _mm_unsel_tmp.begin(); it != _mm_unsel_tmp.end(); ++it, ++idx){
  1119. std::vector<CUT_AREA_RESULT*> &area_tmp = mm[*it];
  1120. int area_sub_index = area_tmp[0]->area_sub_index;
  1121. int is_cut = area_tmp[0]->is_cut;
  1122. int next_id = idx + 1;
  1123. area_rstlist[listpos].push_back(area_tmp[0]);
  1124. if (area_sub_index == 1 && (is_cut > 0) &&
  1125. next_id < _mm_unsel_tmp.size() && mm[_mm_unsel_tmp[idx + 1]].size()>0
  1126. && mm[_mm_unsel_tmp[idx + 1]][0]->area_sub_index == 0){
  1127. continue;
  1128. }
  1129. //std::string area_name = *tmp_all_q.begin();
  1130. //tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end());
  1131. //_map_real_name[area_rst[0]->area_name] = area_name;
  1132. //area_rst[0]->area_name = area_name;
  1133. area_rstlist[listpos][0]->area_name = _map_real_name[area_rstlist[listpos][0]->area_name];
  1134. //SaveImages(area_rst, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic);
  1135. BOOL flag = false;
  1136. //if (pUnhandledPageInfo->nSubjectID == 0)
  1137. {
  1138. for (int i = 0; i < postMarkTypeIDVec.size(); i++)
  1139. {
  1140. for (int j = 0; j < area_rstlist[listpos].size(); j++){
  1141. if (postMarkTypeIDVec[i] == area_rstlist[listpos][j]->area_name)
  1142. {
  1143. flag = true;
  1144. break;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. if (flag && area_rstlist[listpos].size() > 1 && area_rstlist[listpos][0]->is_cut > 0){
  1150. vecTwoPic[area_rstlist[listpos][0]->area_name.c_str()] = area_rstlist[listpos].size();
  1151. }
  1152. saveImgesPara1 *para = new saveImgesPara1(&area_rstlist[listpos], filename, pUnhandledPageInfo->nSubjectID, flag);
  1153. //printf("para %p\r\n", para);
  1154. paraVec2.push_back(para);
  1155. std::lock_guard<std::mutex> _lk(mtxTaskNum);
  1156. taskNum++;
  1157. threadPool->QueueTaskItem(saveImgesMy1, para, saveImgesMyCallback);
  1158. ++listpos;
  1159. //area_rst = area_rstlist[++listpos];
  1160. //area_rst.clear();
  1161. }
  1162. }
  1163. else{
  1164. for (it = mm.begin(); it != mm.end(); ++it){
  1165. BOOL flag = false;
  1166. //if (pUnhandledPageInfo->nSubjectID == 0)
  1167. {
  1168. for (int i = 0; i < postMarkTypeIDVec.size(); i++)
  1169. {
  1170. for (int j = 0; j < it->second.size(); j++){
  1171. if (postMarkTypeIDVec[i] == it->second[j]->area_name)
  1172. {
  1173. vecTwoPic[(it->second[0])->area_name.c_str()] = it->second.size();
  1174. flag = true;
  1175. break;
  1176. }
  1177. }
  1178. }
  1179. }
  1180. saveImgesPara1 *para = new saveImgesPara1(&it->second, filename, pUnhandledPageInfo->nSubjectID, flag);
  1181. ///printf("para %p\r\n", para);
  1182. paraVec2.push_back(para);
  1183. std::lock_guard<std::mutex> _lk(mtxTaskNum);
  1184. taskNum++;
  1185. threadPool->QueueTaskItem(saveImgesMy2, para, saveImgesMyCallback);
  1186. //SaveImages(it->second, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic);
  1187. }
  1188. }
  1189. while (true)
  1190. {
  1191. Sleep(10);
  1192. if (taskNum.load() == 0)
  1193. {
  1194. for (std::vector<saveImgesPara1 *>::iterator iter = paraVec2.begin(); iter != paraVec2.end(); ++iter)
  1195. {
  1196. if (*iter != nullptr)
  1197. {
  1198. //(*iter)->area_rst.clear();
  1199. //delete &(*iter)->area_rst;
  1200. delete (*iter);
  1201. (*iter) = nullptr;
  1202. }
  1203. }
  1204. for (std::vector<SavePathImgPara *>::iterator iter = paraVec1.begin(); iter != paraVec1.end(); ++iter)
  1205. {
  1206. if (*iter != nullptr)
  1207. {
  1208. delete (*iter);
  1209. (*iter) = nullptr;
  1210. }
  1211. }
  1212. break;
  1213. }
  1214. }
  1215. for (int i = 0; i < listpos;i++)
  1216. {
  1217. area_rstlist[i].clear();
  1218. }
  1219. //printf("taskNum 结束 \n");
  1220. //zip.Close();
  1221. //zip1.Close();
  1222. //CString filename = m_img_clips_dir + _T("\\") + GetTimeString() + _T(".zip");
  1223. //CString filename1 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("ori.zip");
  1224. //WideCharToMultiByte(CP_ACP, 0, filename, -1, sz_file_name, 520, NULL, NULL);
  1225. //WideCharToMultiByte(CP_ACP, 0, filename1, -1, sz_ori_file_name, 520, NULL, NULL);
  1226. //CFile file2(filename, CFile::OpenFlags::modeWrite | CFile::OpenFlags::modeCreate);
  1227. //CFile file4(filename1, CFile::OpenFlags::modeWrite | CFile::OpenFlags::modeCreate);
  1228. //file.SeekToBegin();
  1229. //file3.SeekToBegin();
  1230. //int len; char buffer[4096];
  1231. //while ((len = file.Read(buffer, 4096))>0){
  1232. // file2.Write(buffer, len);
  1233. //}
  1234. //while ((len = file3.Read(buffer, 4096))>0){
  1235. // file4.Write(buffer, len);
  1236. //}
  1237. //file.Close();
  1238. //file2.Close();
  1239. //file3.Close();
  1240. //file4.Close();
  1241. }
  1242. // printf("切图结束\n");
  1243. /************************************************************************/
  1244. /* 保存试卷页信息和试卷信息 */
  1245. /************************************************************************/
  1246. /************************************************************************/
  1247. /* 匹配学生(先从本地匹配,没有就远程请求) */
  1248. /************************************************************************/
  1249. //std::string::iterator end_pos = std::remove(studentcode.begin(), studentcode.end(), ' ');
  1250. //studentcode.erase(end_pos, studentcode.end());
  1251. // bool bGetStuInfo = true;
  1252. // if (m_bUseQr){
  1253. // std::vector<std::string> split_qr;
  1254. // split(m_strQr, (std::string)",", &split_qr);
  1255. // if (split_qr.size() >= 3){
  1256. // std::vector<std::string> _vct;
  1257. // split(split_qr[2], std::string("@"), &_vct);
  1258. // if (_vct.size() >= 3){
  1259. // bGetStuInfo = false;
  1260. // }
  1261. // }
  1262. // }
  1263. //if (!m_bUseQr || bGetStuInfo)
  1264. {
  1265. if (pUnhandledPageInfo->bOnlineCard){
  1266. if (studentcode.empty() && student_id == "-1"){
  1267. exceptions |= EX_KAOHAOWEISHIBIE;
  1268. }
  1269. else{
  1270. exceptions |= EX_KAOHAODAIPIPEI;
  1271. }
  1272. }
  1273. else{
  1274. // if (!m_bUseQr || m_strQr.empty()){
  1275. const std::tr1::regex pattern("^[a-z0-9A-Z]{1,30}$");
  1276. if( (studentcode.length() > 0 && std::regex_match(studentcode, pattern))){
  1277. exceptions |= EX_KAOHAODAIPIPEI;
  1278. }
  1279. else if (identified || studentcode.length() == 0){
  1280. exceptions |= EX_KAOHAOWEISHIBIE;
  1281. }
  1282. if (existABJuanFlag() && shijuanleixing != "A"&&shijuanleixing != "B"){
  1283. exceptions |= EX_ABJUANWEISHIBIE;
  1284. }
  1285. // }
  1286. }
  1287. }
  1288. bool isupdate = false;
  1289. try{
  1290. EnterCriticalSection(db_lock);
  1291. bantch_db->execDML("begin transaction");
  1292. // 扫描反馈
  1293. //
  1294. if (exceptions&EX_KAOHAOWEISHIBIE && g_my_scan_type != 0 && g_my_scan_type != 2)
  1295. {
  1296. int index1 = (unhandledPageInfo.first_unhandled_page_index + 0) % MAX_UNHANDLED_PAGE;
  1297. OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1298. char sql1[1024];
  1299. sprintf_s(sql1, "SELECT * from page where img_oldpath = \"%s\"", omr_result->img_oldpath.c_str());
  1300. CppSQLite3Query q = bantch_db->execQuery(sql1);
  1301. if (!q.eof())
  1302. {
  1303. for (int m = 0; m<paper_page_count; m++)
  1304. {
  1305. int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
  1306. unhandledPageInfo.result->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result);
  1307. }
  1308. unhandledPageInfo.first_unhandled_page_index = (unhandledPageInfo.first_unhandled_page_index + paper_page_count) % MAX_UNHANDLED_PAGE;
  1309. unhandledPageInfo.unhandled_page_count -= paper_page_count;
  1310. bantch_db->execDML("rollback transaction");
  1311. LeaveCriticalSection(db_lock);
  1312. return;
  1313. }
  1314. }
  1315. // printf("插入保存试卷:%d\n", student_paper_id);
  1316. //插入保存试卷
  1317. if (student_paper_id>0){
  1318. isupdate = true;
  1319. char sql5[512];
  1320. sprintf_s(sql5, "delete from result where page_id in(select pg.page_id from page pg where pg.student_paper_id =%d )", student_paper_id);
  1321. bantch_db->execDML(sql5);
  1322. sprintf_s(sql5, "delete from exception where student_paper_id =%d", student_paper_id);
  1323. bantch_db->execDML(sql5);
  1324. sprintf_s(sql5, "delete from page where student_paper_id =%d ", student_paper_id);
  1325. bantch_db->execDML(sql5);
  1326. CppSQLite3Statement stmt;
  1327. if (m_bUseQr &&!pUnhandledPageInfo->bOnlineCard ){
  1328. stmt = bantch_db->compileStatement("update student_paper set picFlag=:picFlag,ret_upload=:ret_upload,img_upload=:img_upload,paper_state=:paper_state,student_id=:student_id,file_name=:file_name,ori_img=:ori_img,absent=:absent where student_paper_id =:student_paper_id");
  1329. }
  1330. else{
  1331. stmt = bantch_db->compileStatement("update student_paper set picFlag=:picFlag,ret_upload=:ret_upload,img_upload=:img_upload,student_code=:student_code,paper_state=:paper_state,student_id=:student_id,file_name=:file_name,ori_img=:ori_img,absent=:absent where student_paper_id =:student_paper_id");
  1332. stmt.bind(":student_code", studentcode.c_str());
  1333. }
  1334. stmt.bind(":student_paper_id", student_paper_id);
  1335. stmt.bind(":ret_upload", 0);
  1336. stmt.bind(":img_upload", 0);
  1337. stmt.bind(":file_name", sz_file_name);
  1338. stmt.bind(":ori_img", sz_ori_file_name);
  1339. stmt.bind(":paper_state", 999);
  1340. stmt.bind(":student_id", student_id.c_str());
  1341. stmt.bind(":absent", isAbsent);
  1342. // printf("学生ID:%s isAbsent=%d\n", student_id.c_str(), isAbsent);
  1343. {
  1344. std::map<std::string, int>::iterator it;// = vecTwoPic.end();
  1345. it = vecTwoPic.begin();
  1346. CString strPic;
  1347. while (it != vecTwoPic.end())
  1348. {
  1349. //it->first;
  1350. //it->second;
  1351. std::string str2;
  1352. str2 = it->first;
  1353. //str1 = it->first.c_str();
  1354. int num = it->second;
  1355. //strPic = strPic + _T("_") + std::to_string(num) + _T("#");
  1356. str2 = str2 + "_" + std::to_string(num) + "#";
  1357. CString str1(str2.c_str());
  1358. //str1.Format(_T("%s_%d#"), str1,num);
  1359. strPic += str1;
  1360. it++;
  1361. }
  1362. char cStrPic[1024];
  1363. WideCharToMultiByte(CP_ACP, 0, strPic, -1, cStrPic, 1024, NULL, NULL);
  1364. stmt.bind(":picFlag", cStrPic);
  1365. }
  1366. stmt.execDML();
  1367. }
  1368. else{
  1369. CString strPaperId;
  1370. readPaperId(strPaperId);
  1371. CppSQLite3Statement stmt = bantch_db->compileStatement("insert into student_paper(ret_upload,img_upload,student_code,paper_state,student_id,file_name,ori_img,absent,paper_type,paper_code,location_id,picFlag)values(:ret_upload,:img_upload,:student_code,:paper_state,:student_id,:file_name,:ori_img,:absent,:paper_type,:paper_code,:location_id, :picFlag)");
  1372. stmt.bind(":ret_upload", 0);
  1373. stmt.bind(":img_upload", 0);
  1374. stmt.bind(":file_name", sz_file_name);
  1375. stmt.bind(":ori_img", sz_ori_file_name);
  1376. stmt.bind(":student_code", studentcode.c_str());
  1377. stmt.bind(":paper_state", 999);
  1378. stmt.bind(":student_id", student_id.c_str());
  1379. stmt.bind(":absent", isAbsent);
  1380. stmt.bind(":paper_type", shijuanleixing.c_str());
  1381. // printf("学生ID:%s isAbsent=%d\n", student_id.c_str(), isAbsent);
  1382. char strPaperCode[MAX_PATH];
  1383. memset(strPaperCode, 0, MAX_PATH);
  1384. for (int i = 0; i<strPaperId.GetLength(); i++)
  1385. {
  1386. strPaperCode[i] = strPaperId.GetAt(i);
  1387. }
  1388. stmt.bind(":paper_code", strPaperCode);
  1389. stmt.bind(":location_id", g_myindex);
  1390. std::map<std::string, int>::iterator it;// = vecTwoPic.end();
  1391. it = vecTwoPic.begin();
  1392. CString strPic;
  1393. while (it != vecTwoPic.end())
  1394. {
  1395. //it->first;
  1396. //it->second;
  1397. std::string str2;
  1398. str2 = it->first;
  1399. //str1 = it->first.c_str();
  1400. int num = it->second;
  1401. //strPic = strPic + _T("_") + std::to_string(num) + _T("#");
  1402. str2 = str2 + "_" + std::to_string(num) + "#";
  1403. CString str1(str2.c_str());
  1404. //str1.Format(_T("%s_%d#"), str1,num);
  1405. strPic += str1;
  1406. it++;
  1407. }
  1408. char cStrPic[1024];
  1409. WideCharToMultiByte(CP_ACP, 0, strPic, -1, cStrPic, 1024, NULL, NULL);
  1410. stmt.bind(":picFlag", cStrPic);
  1411. stmt.execDML();
  1412. CppSQLite3Query query = bantch_db->execQuery("select last_insert_rowId() from student_paper");
  1413. student_paper_id = query.getIntField(0);
  1414. }
  1415. char phy_number[20];
  1416. CppSQLite3Statement stmt2 = bantch_db->compileStatement("INSERT INTO result ( page_id, type, answer, score, question_code, score_paper, question_state,student_paper_id ,isright) VALUES ( :page_id, :type, :answer, :score, :question_code, :score_paper, :question_state, :student_paper_id,:isright)");
  1417. CppSQLite3Statement stmt3 = bantch_db->compileStatement("insert into exception (exception_type ,exception_name,page_id,student_paper_id) values(:exception_type ,:exception_name,:page_id,:student_paper_id)");
  1418. if (exceptions&EX_KAOHAOWEISHIBIE){
  1419. stmt3.bind(":student_paper_id", student_paper_id);
  1420. stmt3.bind(":exception_type", SHIFT_KAOHAOWEISHIBIE);
  1421. stmt3.bind(":exception_name", "考号未识别");
  1422. stmt3.execDML();
  1423. }
  1424. if (exceptions&EX_DINGWEIDIAN) {
  1425. stmt3.bind(":student_paper_id", student_paper_id);
  1426. stmt3.bind(":exception_type", SHIFT_DINGWEIDIAN);
  1427. stmt3.bind(":exception_name", "定位点异常");
  1428. stmt3.execDML();
  1429. }
  1430. if (exceptions&EX_KAOHAOBUCUNZAI){
  1431. stmt3.bind(":student_paper_id", student_paper_id);
  1432. stmt3.bind(":exception_type", SHIFT_KAOHAOBUCUNZAI);
  1433. stmt3.bind(":exception_name", "考号不存在");
  1434. stmt3.execDML();
  1435. }
  1436. if (exceptions&EX_KAOHAOCHONGTU){
  1437. stmt3.bind(":student_paper_id", student_paper_id);
  1438. stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
  1439. stmt3.bind(":exception_name", "考号冲突");
  1440. stmt3.execDML();
  1441. }
  1442. if (exceptions&EX_SHIJUANQUEYE){
  1443. stmt3.bind(":student_paper_id", student_paper_id);
  1444. stmt3.bind(":exception_type", SHIFT_SHIJUANQUEYE);
  1445. stmt3.bind(":exception_name", "试卷缺页");
  1446. stmt3.execDML();
  1447. }
  1448. if (exceptions&EX_ABJUANWEISHIBIE){
  1449. stmt3.bind(":student_paper_id", student_paper_id);
  1450. stmt3.bind(":exception_type", SHIFT_ABJUANWEISHIBIE);
  1451. stmt3.bind(":exception_name", "AB卷未识别");
  1452. stmt3.execDML();
  1453. }
  1454. vector<int> page_ids;
  1455. //题号是否被选中(有效选中)
  1456. map<string, bool> question_selected;
  1457. for (std::map<int, const PAGE_RESULT_HANDLE_INFO>::iterator it = m_handInfoMap.begin(); it != m_handInfoMap.end(); it++)
  1458. {
  1459. const std::vector<XUANZUOTI_RESULT_HANDLE_INFO> & xuanzuoti_result_handle_infos = it->second.xuanzuotiHandleInfo;
  1460. for (int idx_xz = 0; idx_xz<xuanzuoti_result_handle_infos.size(); idx_xz++)
  1461. {
  1462. const XUANZUOTI_RESULT_HANDLE_INFO & xuanzuoti_hi = xuanzuoti_result_handle_infos[idx_xz];
  1463. for (int index_group = 0; index_group<xuanzuoti_hi.group_index.size(); index_group++)
  1464. {
  1465. const std::vector<std::string>& mark_unit_question_codes = xuanzuoti_hi.mark_unit_question_code[index_group];
  1466. for (int index_markunit = 0; index_markunit<mark_unit_question_codes.size(); index_markunit++)
  1467. {
  1468. vector<string> markunit_questioncode;
  1469. split(mark_unit_question_codes[index_markunit], ",", &markunit_questioncode);
  1470. for (int index_markunit_q = 0; index_markunit_q<markunit_questioncode.size(); index_markunit_q++)
  1471. {
  1472. question_selected[markunit_questioncode[index_markunit_q]] = false;
  1473. }
  1474. }
  1475. }
  1476. }
  1477. }
  1478. bool bInsertQuekaobiao = false;
  1479. Json::Value json_array4(Json::arrayValue);
  1480. Json::Value json4;
  1481. bool flag4 = false;
  1482. for (int p = 0; p < paper_page_count; p++)
  1483. {
  1484. /*
  1485. if (!identified)
  1486. {
  1487. if (pUnhandledPageInfo->bOnlineCard)
  1488. {
  1489. int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
  1490. OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1491. //stmt.bind(":img_path", omr_result->img_path.c_str());
  1492. Json::Value item;
  1493. item["path"] = omr_result->img_path.c_str();
  1494. json_array4.append(item);
  1495. flag4 = true;
  1496. }
  1497. }
  1498. */
  1499. int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
  1500. OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1501. //stmt.bind(":img_path", omr_result->img_path.c_str());
  1502. if (omr_result->card_qrFlag == -1)
  1503. {
  1504. Json::Value item;
  1505. item["path"] = omr_result->img_path.c_str();
  1506. json_array4.append(item);
  1507. flag4 = true;
  1508. }
  1509. }
  1510. if (flag4)
  1511. {
  1512. //发送消息
  1513. MY_DB_INFO fff;
  1514. int len = 1024;
  1515. memset(fff.sUrl, 0, 520);
  1516. //strncpy(fff.sDbBasePath, g_strUpLoadDbPathName.c_str(), g_strUpLoadDbPathName.length() + 1);
  1517. //getupLoadUrl(fff.sUrl, len);
  1518. fff.ntype = 3; //二维码错误情况
  1519. fff.nmode = 1;
  1520. COPYDATASTRUCT cpd; // 给COPYDATASTRUCT结构赋值
  1521. cpd.dwData = 0;
  1522. cpd.cbData = sizeof(MY_DB_INFO);
  1523. cpd.lpData = (&fff);
  1524. json4["imgs"] = json_array4;
  1525. char sz_file_name4[520] = { 0 };
  1526. CString filename4 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("_json.txt");
  1527. WideCharToMultiByte(CP_ACP, 0, filename4, -1, sz_file_name4, 520, NULL, NULL);
  1528. CFile file;
  1529. CString fliepath;
  1530. file.Open(filename4, CFile::modeCreate | CFile::modeWrite);
  1531. Json::FastWriter writer;
  1532. std::string json_str = writer.write(json4);
  1533. DWORD wide_string_len = MultiByteToWideChar(CP_ACP, 0, json_str.c_str(), -1, NULL, 0);
  1534. WCHAR* wide_string = new WCHAR[wide_string_len];
  1535. wide_string_len = MultiByteToWideChar(CP_ACP, 0, json_str.c_str(), -1, wide_string, wide_string_len);
  1536. DWORD utf8_string_len = WideCharToMultiByte(CP_UTF8, 0, wide_string, -1, NULL, 0, NULL, NULL);
  1537. CHAR* utf8_string = new CHAR[utf8_string_len];
  1538. utf8_string_len = WideCharToMultiByte(CP_UTF8, 0, wide_string, -1, utf8_string, utf8_string_len, NULL, NULL);
  1539. file.Write((void*)utf8_string, utf8_string_len - 1);
  1540. file.Close();
  1541. delete wide_string;
  1542. delete utf8_string;
  1543. //Json::FastWriter writer;
  1544. //std::string json_str = writer.write(json4);
  1545. memset(fff.sDbBasePath, 0, 520);
  1546. std::string str = sz_file_name4;
  1547. strncpy(fff.sDbBasePath, str.c_str(), str.length() + 1);
  1548. //std::async(std::launch::async, [cpd](){
  1549. CWnd *pWnd = NULL;
  1550. pWnd = CWnd::FindWindow(NULL, _T("知心慧学学管系统"));
  1551. if (pWnd){
  1552. int ret = pWnd->SendMessage(WM_COPYDATA, NULL, (LPARAM)&cpd); // 发送
  1553. }
  1554. //});
  1555. }
  1556. uint kegunti_orgin_count(0); // 客观题原始题数
  1557. uint kegunti_empty_count(0); // 客观题未作答题数
  1558. {
  1559. for (int p = 0; p < paper_page_count; p++)
  1560. {
  1561. int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
  1562. OMR_RESULT* omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1563. if (omr_result->identified)
  1564. {
  1565. if (pUnhandledPageInfo->bOnlineCard)
  1566. {
  1567. kegunti_orgin_count += omr_result->group_result.size();
  1568. for (int i = 0; i < omr_result->group_result.size(); i++)
  1569. {
  1570. if (omr_result->group_result[i].answer.length() == 0)
  1571. {
  1572. kegunti_empty_count++;
  1573. }
  1574. }
  1575. }
  1576. else
  1577. {
  1578. const std::vector<KEGUANTI_RESULT_HANDLE_INFO>& keguantiHandleInfo = m_handInfoMap[omr_result->card_index].keguantiHandleInfo;
  1579. for (int m = 0; m < keguantiHandleInfo.size(); m++)
  1580. {
  1581. const std::vector<int> & group_index = keguantiHandleInfo[m].group_index;
  1582. const std::vector<int> & group_question_count = keguantiHandleInfo[m].group_question_count;
  1583. for (int idx_g = 0, idx_q = 0; idx_g < group_index.size(); idx_g++)
  1584. {
  1585. for (int idx_g_i = 0; idx_g_i < group_question_count[idx_g]; idx_g_i++, idx_q++)
  1586. {
  1587. int i = group_index[idx_g];
  1588. kegunti_orgin_count++;
  1589. if (omr_result->group_result[i].answer.length() == 0)
  1590. {
  1591. kegunti_empty_count++;
  1592. }
  1593. }
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. std::string strquestioncode = "";
  1601. for (int p = 0; p<paper_page_count; p++)
  1602. {
  1603. int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
  1604. OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1605. int len = sprintf_s(phy_number, "%d", omr_result->phy_card_number);
  1606. CppSQLite3Statement stmt = bantch_db->compileStatement("INSERT INTO page (identified,phy_number,page_index,img_path,img_oldpath,student_paper_id) VALUES (:identified,:phy_number,:page_index,:img_path,:img_oldpath,:student_paper_id)");
  1607. stmt.bind(":identified", omr_result->identified);
  1608. stmt.bind(":phy_number", phy_number);
  1609. stmt.bind(":page_index", omr_result->card_index);
  1610. stmt.bind(":img_path", omr_result->img_path.c_str());
  1611. stmt.bind(":img_oldpath", omr_result->img_oldpath.c_str());
  1612. stmt.bind(":student_paper_id", student_paper_id);
  1613. stmt.execDML();
  1614. CppSQLite3Query query = bantch_db->execQuery("select last_insert_rowId() from page");
  1615. int page_id = query.getIntField(0);
  1616. page_ids.push_back(page_id);
  1617. int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE;
  1618. UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index];
  1619. if (omr_result->identified){
  1620. for (int i = 0; i < omr_result->qr_result.size(); i++)
  1621. {
  1622. stmt2.reset();
  1623. stmt2.bind(":page_id", page_id);
  1624. stmt2.bind(":type", RT_CODE);
  1625. stmt2.bind(":answer", omr_result->qr_result[i].qr_str.c_str());
  1626. stmt2.bind(":score", 0);
  1627. stmt2.bind(":score_paper", 0);
  1628. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  1629. stmt2.bind(":student_paper_id", student_paper_id);
  1630. stmt2.execDML();
  1631. }
  1632. if (pUnhandledPageInfo->bOnlineCard){
  1633. /*******************************保存缺考标记**************************************************/
  1634. if (!bInsertQuekaobiao){
  1635. stmt2.reset();
  1636. stmt2.bind(":page_id", page_id);
  1637. stmt2.bind(":type", RT_QUEKAOBIAOJI);
  1638. stmt2.bind(":answer", omr_result->quekaoFlag ? "1" : "0");
  1639. stmt2.bind(":score", 0);
  1640. stmt2.bind(":score_paper", 0);
  1641. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  1642. stmt2.bind(":student_paper_id", student_paper_id);
  1643. stmt2.execDML();
  1644. bInsertQuekaobiao = true;
  1645. }
  1646. /*******************************保存客观题**************************************************/
  1647. for (int i = 0; i < omr_result->group_result.size(); i++)
  1648. {
  1649. float score = scoreCounter.GetScore(omr_result->group_result[i].question_code, omr_result->group_result[i].answer, 0, 0);
  1650. total_score += score;
  1651. stmt2.reset();
  1652. stmt2.bind(":page_id", page_id);
  1653. if (omr_result->group_result[i].omr_question_type == identify::DANXUANTI){
  1654. stmt2.bind(":type", RT_KEGUANTI);
  1655. }
  1656. else{
  1657. stmt2.bind(":type", RT_KEGUANTI_EX);
  1658. }
  1659. q_std answer_std = scoreCounter.get_std(omr_result->group_result[i].question_code); // 取出标准答案题
  1660. if (kegunti_orgin_count > 0 && kegunti_orgin_count == kegunti_empty_count ||
  1661. (answer_std.question_type == DANXUANTI && omr_result->group_result[i].answer == answer_std.answer_all))
  1662. {
  1663. if (!(exceptions & EX_KEGUANTIYICHANG) && g_my_scan_type != 1 && g_my_scan_type != 2)
  1664. {
  1665. exceptions |= EX_KEGUANTIYICHANG;
  1666. }
  1667. }
  1668. stmt2.bind(":answer", omr_result->group_result[i].answer.c_str());
  1669. stmt2.bind(":score", score);
  1670. stmt2.bind(":question_code", omr_result->group_result[i].question_code.c_str());
  1671. stmt2.bind(":score_paper", score);
  1672. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  1673. stmt2.bind(":student_paper_id", student_paper_id);
  1674. stmt2.execDML();
  1675. }
  1676. }
  1677. else{
  1678. /*******************************保存缺考标记**************************************************/
  1679. const std::vector<QUEKAOBIAOJI_RESULT_HANDLE_INFO>& quekaoHandleInfo = m_handInfoMap[omr_result->card_index].quekaoHandleInfo;
  1680. for (int i = 0; i < quekaoHandleInfo.size(); i++)
  1681. {
  1682. stmt2.reset();
  1683. stmt2.bind(":page_id", page_id);
  1684. stmt2.bind(":type", RT_QUEKAOBIAOJI);
  1685. stmt2.bind(":answer", omr_result->group_result[quekaoHandleInfo[i].group_index[0]].answer.c_str());
  1686. stmt2.bind(":score", 0);
  1687. stmt2.bind(":score_paper", 0);
  1688. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  1689. stmt2.bind(":student_paper_id", student_paper_id);
  1690. stmt2.execDML();
  1691. }
  1692. /*******************************保存AB卷标记**************************************************/
  1693. const std::vector<ABJUAN_RESULT_HANDLE_INFO>& abjuanHandleInfo = m_handInfoMap[omr_result->card_index].abjuanHandleInfo;
  1694. for (int i = 0; i < abjuanHandleInfo.size(); i++)
  1695. {
  1696. stmt2.reset();
  1697. stmt2.bind(":page_id", page_id);
  1698. stmt2.bind(":type", RT_ABJUANBIAOJI);
  1699. stmt2.bind(":answer", omr_result->group_result[abjuanHandleInfo[i].group_index[0]].answer.c_str());
  1700. stmt2.bind(":score", 0);
  1701. stmt2.bind(":score_paper", 0);
  1702. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  1703. stmt2.bind(":student_paper_id", student_paper_id);
  1704. stmt2.execDML();
  1705. }
  1706. /*******************************保存填涂考号**************************************************/
  1707. const std::vector<TIANTUKAOHAO_RESULT_HANDLE_INFO>& tiantukaohaoHandleInfo = m_handInfoMap[omr_result->card_index].tiantukaohaoHandleInfo;
  1708. for (int i = 0; i < tiantukaohaoHandleInfo.size(); i++)
  1709. {
  1710. std::string kaohao;
  1711. if (g_my_scan_type == 1)
  1712. {
  1713. kaohao = g_strShoolId;
  1714. }
  1715. for (int j = 0; j < tiantukaohaoHandleInfo[i].group_index.size(); j++)
  1716. {
  1717. kaohao += omr_result->group_result[tiantukaohaoHandleInfo[i].group_index[j]].answer;
  1718. }
  1719. stmt2.reset();
  1720. stmt2.bind(":page_id", page_id);
  1721. stmt2.bind(":type", RT_TIANTUKAOHAO);
  1722. stmt2.bind(":answer", kaohao.c_str());
  1723. stmt2.bind(":score", 0);
  1724. stmt2.bind(":score_paper", 0);
  1725. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  1726. stmt2.bind(":student_paper_id", student_paper_id);
  1727. stmt2.execDML();
  1728. }
  1729. }
  1730. /*******************************保存填空题**************************************************/
  1731. for (int i = 0; i < omr_result->tiankongti_result.size(); i++)
  1732. {
  1733. float score = 0.0;
  1734. //std::string strscores = "";
  1735. if (strquestioncode == omr_result->tiankongti_result[i].question_code)
  1736. {
  1737. //相同题号,一定是小题号,不用再统计
  1738. continue;
  1739. }
  1740. if (!pUnhandledPageInfo->bOnlineCard ||
  1741. omr_result->tiankongti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::TIANKONGTI){
  1742. if (omr_result->tiankongti_result[i].maxscore > 0)
  1743. {
  1744. //strscores = std::to_string(omr_result->tiankongti_result[i].question_score);
  1745. score += omr_result->tiankongti_result[i].question_score;
  1746. strquestioncode = omr_result->tiankongti_result[i].question_code;
  1747. bool bneedcountiefind = true;
  1748. //同页对比
  1749. for (int j = i + 1; j < omr_result->tiankongti_result.size(); j++)
  1750. {
  1751. if (omr_result->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
  1752. {
  1753. //strscores += ",";
  1754. //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
  1755. score += omr_result->tiankongti_result[j].question_score;
  1756. }
  1757. else
  1758. {
  1759. bneedcountiefind = false;
  1760. }
  1761. }
  1762. if (bneedcountiefind)
  1763. {
  1764. //跨页对比
  1765. bool bstopflag = false;
  1766. for (int q = p + 1; q < paper_page_count; q++)
  1767. {
  1768. if (bstopflag)
  1769. break;
  1770. int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE;
  1771. OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1772. for (int j = 0; omr_result1->tiankongti_result.size(); j++)
  1773. {
  1774. if (omr_result1->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
  1775. {
  1776. //strscores += ",";
  1777. //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
  1778. score += omr_result1->tiankongti_result[j].question_score;
  1779. }
  1780. else
  1781. {
  1782. bstopflag = true;
  1783. break;
  1784. }
  1785. }
  1786. }
  1787. }
  1788. score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, score);
  1789. }
  1790. else
  1791. {
  1792. score = scoreCounter.GetScore(omr_result->tiankongti_result[i].question_code, "", omr_result->tiankongti_result[i].isright, 0);
  1793. }
  1794. }
  1795. if (pUnhandledPageInfo->bOnlineCard &&
  1796. omr_result->tiankongti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::TIANKONGTI2){
  1797. if (omr_result->tiankongti_result[i].maxscore > 0)
  1798. {
  1799. //strscores = std::to_string(omr_result->tiankongti_result[i].question_score);
  1800. score += omr_result->tiankongti_result[i].question_score;
  1801. strquestioncode = omr_result->tiankongti_result[i].question_code;
  1802. bool bneedcountiefind = true;
  1803. //同页对比
  1804. for (int j = i + 1; j<omr_result->tiankongti_result.size(); j++)
  1805. {
  1806. if (omr_result->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
  1807. {
  1808. //strscores += ",";
  1809. //strscores += std::to_string(omr_result->tiankongti_result[i].question_score);
  1810. score += omr_result->tiankongti_result[j].question_score;
  1811. }
  1812. else
  1813. {
  1814. bneedcountiefind = false;
  1815. }
  1816. }
  1817. if (bneedcountiefind)
  1818. {
  1819. //跨页对比
  1820. bool bstopflag = false;
  1821. for (int q = p + 1; q < paper_page_count; q++)
  1822. {
  1823. if (bstopflag)
  1824. break;
  1825. int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE;
  1826. OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1827. for (int j = 0; j < omr_result1->tiankongti_result.size(); j++)
  1828. {
  1829. if (omr_result1->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code)
  1830. {
  1831. //strscores += ",";
  1832. //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
  1833. score += omr_result1->tiankongti_result[j].question_score;
  1834. }
  1835. else
  1836. {
  1837. bstopflag = true;
  1838. break;
  1839. }
  1840. }
  1841. }
  1842. }
  1843. score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, score);
  1844. }
  1845. else
  1846. {
  1847. score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, omr_result->tiankongti_result[i].question_score);
  1848. }
  1849. }
  1850. total_score += score;
  1851. stmt2.reset();
  1852. stmt2.bind(":page_id", page_id);
  1853. stmt2.bind(":type", RT_TIANKONGTI);
  1854. stmt2.bind(":answer", "");
  1855. stmt2.bind(":score", score);
  1856. stmt2.bind(":isright", omr_result->tiankongti_result[i].isright);
  1857. stmt2.bind(":question_code", omr_result->tiankongti_result[i].question_code.c_str());
  1858. stmt2.bind(":score_paper", score);
  1859. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  1860. stmt2.bind(":student_paper_id", student_paper_id);
  1861. stmt2.execDML();
  1862. }
  1863. int loupi_count = 0;
  1864. int wufashibie_count = 0;
  1865. int wupan_count = 0;
  1866. /*******************************保存主观题**************************************************/
  1867. for (int i = 0; i<omr_result->zhutuanti_result.size(); i++)
  1868. {
  1869. if (strquestioncode == omr_result->zhutuanti_result[i].question_code)
  1870. {
  1871. //相同题号,一定是小题号,不用再统计
  1872. continue;
  1873. }
  1874. float score = 0;
  1875. if (omr_result->zhutuanti_result[i].maxscore > 0)
  1876. {
  1877. score += omr_result->zhutuanti_result[i].question_score;
  1878. strquestioncode = omr_result->zhutuanti_result[i].question_code;
  1879. bool bneedcountiefind = true;
  1880. //同页对比
  1881. for (int j = i + 1; j<omr_result->zhutuanti_result.size(); j++)
  1882. {
  1883. if (omr_result->zhutuanti_result[j].question_code == omr_result->zhutuanti_result[i].question_code)
  1884. {
  1885. //strscores += ",";
  1886. //strscores += std::to_string(omr_result->tiankongti_result[i].question_score);
  1887. score += omr_result->zhutuanti_result[j].question_score;
  1888. }
  1889. else
  1890. {
  1891. bneedcountiefind = false;
  1892. }
  1893. }
  1894. if (bneedcountiefind)
  1895. {
  1896. //跨页对比
  1897. bool bstopflag = false;
  1898. for (int q = p + 1; q < paper_page_count; q++)
  1899. {
  1900. if (bstopflag)
  1901. break;
  1902. int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE;
  1903. OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result;
  1904. for (int j = 0; j < omr_result1->zhutuanti_result.size(); j++)
  1905. {
  1906. if (omr_result1->zhutuanti_result[j].question_code == omr_result->zhutuanti_result[i].question_code)
  1907. {
  1908. //strscores += ",";
  1909. //strscores += std::to_string(omr_result->tiankongti_result[j].question_score);
  1910. score += omr_result1->zhutuanti_result[j].question_score;
  1911. }
  1912. else
  1913. {
  1914. bstopflag = true;
  1915. break;
  1916. }
  1917. }
  1918. }
  1919. }
  1920. score = scoreCounter.GetScore(omr_result->zhutuanti_result[i].question_code, "", 0, score);
  1921. }
  1922. else
  1923. {
  1924. score = scoreCounter.GetScore(omr_result->zhutuanti_result[i].question_code, "", 0, omr_result->zhutuanti_result[i].question_score);
  1925. }
  1926. total_score += score;
  1927. stmt2.reset();
  1928. if (pUnhandledPageInfo->bOnlineCard &&
  1929. omr_result->zhutuanti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::XUANZUOTI){
  1930. std::string strTotal = std::to_string(omr_result->zhutuanti_result[i].total),
  1931. strRequired = std::to_string(omr_result->zhutuanti_result[i].required),
  1932. strAllQuestions = omr_result->zhutuanti_result[i].question_code_all,
  1933. strXuanz = std::to_string(omr_result->zhutuanti_result[i].xuanze);
  1934. std::string real_name;
  1935. auto it_find = _map_real_name.find(omr_result->zhutuanti_result[i].question_code);
  1936. if (it_find != _map_real_name.end()){
  1937. real_name = it_find->second;
  1938. }
  1939. std::string str_tmp = strAllQuestions + "@" + strXuanz + "@" + strTotal + "@" + strRequired + "@" + real_name;
  1940. stmt2.bind(":answer", str_tmp.c_str());
  1941. stmt2.bind(":type", RT_XUANZUOTI);
  1942. }
  1943. else{
  1944. stmt2.bind(":answer", "");
  1945. stmt2.bind(":type", scoreCounter.get_std(omr_result->zhutuanti_result[i].question_code).question_type == schema::BIZUOTI ? RT_BIZUOTI : RT_ZHUGUANTI);
  1946. }
  1947. stmt2.bind(":page_id", page_id);
  1948. stmt2.bind(":score", score);
  1949. stmt2.bind(":question_code", omr_result->zhutuanti_result[i].question_code.c_str());
  1950. stmt2.bind(":score_paper", omr_result->zhutuanti_result[i].question_score);
  1951. QUESTION_STATE question_state = QUESTION_STATE_NORMAL;
  1952. if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_LOUPI){ loupi_count++; question_state = QUESTION_STATE_LOUPI; }
  1953. if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_WUFASHIBIE){ wufashibie_count++; question_state = QUESTION_STATE_WUFASHIBIE; }
  1954. if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_NORMAL&&omr_result->zhutuanti_result[i].question_score - score>0.1){ wupan_count++; question_state = QUESTION_STATE_WUPAN; }
  1955. stmt2.bind(":question_state", question_state);
  1956. stmt2.bind(":student_paper_id", student_paper_id);
  1957. stmt2.execDML();
  1958. }
  1959. /*******************************保存选做题**************************************************/
  1960. if (!pUnhandledPageInfo->bOnlineCard){
  1961. const std::vector<XUANZUOTI_RESULT_HANDLE_INFO>& xuanzuotiHandleInfo = m_handInfoMap[omr_result->card_index].xuanzuotiHandleInfo;
  1962. for (int i = 0; i < xuanzuotiHandleInfo.size(); i++)
  1963. {
  1964. for (int index_group = 0; index_group < xuanzuotiHandleInfo[i].group_index.size(); index_group++)
  1965. {
  1966. const char * answer = omr_result->group_result[xuanzuotiHandleInfo[i].group_index[index_group]].answer.c_str();
  1967. //if (omr_result->group_result[xuanzuotiHandleInfo[i].group_index[index_group]].answer == "")
  1968. // answer = omr_result->cut_area_result[omr_result->cut_area_result.size() - index_group - 1].area_name.c_str();
  1969. const std::vector<std::string>& mark_units = xuanzuotiHandleInfo[i].mark_unit[index_group];
  1970. const std::vector<std::vector<std::string>>& option_question_code = xuanzuotiHandleInfo[i].option_question_code[index_group];
  1971. int xuantishu = xuanzuotiHandleInfo[i].xuantishu[index_group];
  1972. const std::vector<std::string>& mark_unit_question_codes = xuanzuotiHandleInfo[i].mark_unit_question_code[index_group];
  1973. vector<string> answers;
  1974. split(answer, ",", &answers);
  1975. int selected_count = 0;
  1976. vector<bool> option_selected(option_question_code.size(), false);
  1977. vector<bool> option_selected_valid(option_question_code.size(), false);
  1978. int selected_option_count = 0;
  1979. for (int idx_o = 0; idx_o < option_question_code.size(); idx_o++)
  1980. {
  1981. bool found = false;
  1982. for (int idx_o_q = 0; !found&&idx_o_q < option_question_code[idx_o].size(); idx_o_q++)
  1983. {
  1984. for (int idx_a = 0; !found&&idx_a < answers.size(); idx_a++)
  1985. {
  1986. if (option_question_code[idx_o][idx_o_q] == answers[idx_a]){ found = true; }
  1987. }
  1988. }
  1989. if (found){ option_selected[idx_o] = true; selected_option_count++; }
  1990. }
  1991. bool bIsEmpty = true;
  1992. for (int j = 0; j < option_selected.size(); j++)
  1993. {
  1994. if (option_selected[j] == true)
  1995. bIsEmpty = false;
  1996. }
  1997. if (bIsEmpty)
  1998. option_selected[0] = true;
  1999. for (int idx_o = 0, s_count = 0; s_count < xuantishu&&idx_o < option_selected.size(); idx_o++)
  2000. {
  2001. if (!option_selected[idx_o])continue;
  2002. option_selected_valid[idx_o] = true; s_count++;
  2003. for (int idx_o_q = 0; idx_o_q < option_question_code[idx_o].size(); idx_o_q++)
  2004. {
  2005. question_selected[option_question_code[idx_o][idx_o_q]] = true;
  2006. }
  2007. }
  2008. for (int index_markunit = 0; index_markunit < mark_units.size(); index_markunit++)
  2009. {
  2010. vector<string> markunit_questioncode;
  2011. split(mark_unit_question_codes[index_markunit], ",", &markunit_questioncode);
  2012. std::string question_code_selected;
  2013. for (int index2 = 0; index2 < markunit_questioncode.size(); index2++)
  2014. {
  2015. for (int index_option = 0; index_option < option_question_code.size(); index_option++)
  2016. {
  2017. if (!option_selected_valid[index_option])continue;
  2018. const std::vector<std::string>& option_question = option_question_code[index_option];
  2019. for (int index_option_q = 0; index_option_q < option_question.size(); index_option_q++)
  2020. {
  2021. if (option_question[index_option_q] == markunit_questioncode[index2]){
  2022. if (question_code_selected.length() > 0){
  2023. question_code_selected.append(",");
  2024. }
  2025. question_code_selected.append(option_question[index_option_q]);
  2026. break;
  2027. }
  2028. }
  2029. }
  2030. }
  2031. stmt2.reset();
  2032. stmt2.bind(":page_id", page_id);
  2033. stmt2.bind(":type", RT_XUANZUOTI);
  2034. stmt2.bind(":answer", question_code_selected.c_str());
  2035. stmt2.bind(":score", 0);
  2036. stmt2.bind(":question_code", mark_units[index_markunit].c_str());
  2037. stmt2.bind(":score_paper", 0);
  2038. stmt2.bind(":question_state", QUESTION_STATE_NORMAL);
  2039. stmt2.bind(":student_paper_id", student_paper_id);
  2040. stmt2.execDML();
  2041. }
  2042. }
  2043. }
  2044. }
  2045. }
  2046. else{
  2047. stmt3.bind(":student_paper_id", student_paper_id);
  2048. stmt3.bind(":page_id", page_id);
  2049. stmt3.bind(":exception_type", SHIFT_DINGWEIDIAN);
  2050. stmt3.bind(":exception_name", "定位点异常");
  2051. stmt3.execDML();
  2052. exceptions |= EX_DINGWEIDIAN;
  2053. }
  2054. }
  2055. if (!pUnhandledPageInfo->bOnlineCard)
  2056. {
  2057. for (int p = 0; p<paper_page_count; p++)
  2058. {
  2059. int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE;
  2060. OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result;
  2061. int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE;
  2062. UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index];
  2063. if (omr_result->identified)
  2064. {
  2065. /*******************************保存客观题**************************************************/
  2066. int loutu_count = 0;
  2067. const std::vector<KEGUANTI_RESULT_HANDLE_INFO>& keguantiHandleInfo = m_handInfoMap[omr_result->card_index].keguantiHandleInfo;
  2068. for (int m = 0; m<keguantiHandleInfo.size(); m++)
  2069. {
  2070. const std::vector<int> & group_index = keguantiHandleInfo[m].group_index;
  2071. const std::vector<int> & group_question_count = keguantiHandleInfo[m].group_question_count;
  2072. const std::vector<std::string> & question_code = keguantiHandleInfo[m].question_code;
  2073. for (int idx_g = 0, idx_q = 0; idx_g<group_index.size(); idx_g++)
  2074. {
  2075. for (int idx_g_i = 0; idx_g_i<group_question_count[idx_g]; idx_g_i++, idx_q++)
  2076. {
  2077. int i = group_index[idx_g];
  2078. float score = scoreCounter.GetScore(question_code[idx_q], omr_result->group_result[i].answer, 0, 0);
  2079. bool isSelected = false;
  2080. bool isLoutu = false;
  2081. if (strcmp("*", omr_result->group_result[i].answer.c_str()) == 0){ loutu_count++; isLoutu = true; }
  2082. if (question_selected.find(question_code[idx_q]) == question_selected.end() || question_selected[question_code[idx_q]]){//不是选做题或者是选中的选做题 加入到总分
  2083. total_score += score;
  2084. isSelected = true;
  2085. }
  2086. q_std answer_std = scoreCounter.get_std(question_code[idx_q]); // 取出标准答案题
  2087. if (kegunti_orgin_count > 0 && kegunti_orgin_count == kegunti_empty_count ||
  2088. (answer_std.question_type == DANXUANTI && omr_result->group_result[i].answer == answer_std.answer_all))
  2089. {
  2090. if (!(exceptions & EX_KEGUANTIYICHANG) && g_my_scan_type != 1 && g_my_scan_type != 2)
  2091. {
  2092. exceptions |= EX_KEGUANTIYICHANG;
  2093. }
  2094. }
  2095. stmt2.bind(":page_id", page_ids[p]);
  2096. if (answer_std.question_type == DANXUANTI)
  2097. stmt2.bind(":type", RT_KEGUANTI);
  2098. else
  2099. stmt2.bind(":type", RT_KEGUANTI_EX);
  2100. stmt2.bind(":answer", omr_result->group_result[i].answer.c_str());
  2101. stmt2.bind(":score", score);
  2102. stmt2.bind(":question_code", question_code[idx_q].c_str());
  2103. stmt2.bind(":score_paper", score);
  2104. int question_state = isSelected ? (isLoutu ? QUESTION_STATE_LOUTU : QUESTION_STATE_NORMAL) : (isLoutu ? QUESTION_STATE_UNSELECT_LOUTU : QUESTION_STATE_UNSELECT);
  2105. stmt2.bind(":question_state", question_state);
  2106. stmt2.bind(":student_paper_id", student_paper_id);
  2107. stmt2.execDML();
  2108. }
  2109. /*
  2110. int reuslt_id=bantch_db->execScalar("select last_insert_rowId() from result");
  2111. for(int k=0;k<options.len;k++){
  2112. char feature[1024];
  2113. float* features =options[k].features;;
  2114. sprintf_s(feature,"{%ff,%ff,%ff,%ff,%ff,%ff,%ff,%ff,%ff}",features[0],features[1],features[2],features[3],features[4],features[5],features[6],features[7],features[8]);
  2115. stmt4.bind(":result_id",reuslt_id);
  2116. stmt4.bind(":option_idx",k);
  2117. stmt4.bind(":feature",feature);
  2118. stmt4.execDML();
  2119. }*/
  2120. }
  2121. }
  2122. /*******************************保存异常信息**************************************************/
  2123. if (FALSE&&loutu_count>0){//商讨决定不再抛出该异常
  2124. stmt3.bind(":student_paper_id", student_paper_id);
  2125. stmt3.bind(":page_id", page_ids[p]);
  2126. stmt3.bind(":exception_type", SHIFT_LOUTU);
  2127. stmt3.bind(":exception_name", "考生漏涂");
  2128. stmt3.execDML();
  2129. }
  2130. }
  2131. }
  2132. }
  2133. CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id ,message_type,identified,class_id,class_total,exceptions,class_info,score,student_id,student_name,examnumber) VALUES (:student_paper_id,:message_type,:identified,:class_id,:class_total,:exceptions,:class_info,:score,:student_id,:student_name,:examnumber)");
  2134. stmt4.bind(":student_paper_id", student_paper_id);
  2135. stmt4.bind(":message_type", isupdate ? WM_IDENTIFOR_PAPER_STATE_CHAGED : WM_IDENTIFOR_REPORT);
  2136. stmt4.bind(":identified", identified);
  2137. stmt4.bind(":class_id", class_id);
  2138. stmt4.bind(":class_total", class_total);
  2139. stmt4.bind(":class_info", class_info);
  2140. stmt4.bind(":exceptions", exceptions);
  2141. stmt4.bind(":score", total_score);
  2142. stmt4.bind(":student_id", student_id.c_str());
  2143. stmt4.bind(":student_name", student_name);
  2144. stmt4.bind(":examnumber", studentcode.c_str());
  2145. stmt4.execDML();
  2146. char sql3[512];
  2147. sprintf_s(sql3, "update student_paper set paper_state = %d,score_total= %f where student_paper_id = %d", exceptions, total_score, student_paper_id);
  2148. bantch_db->execDML(sql3);
  2149. bantch_db->execDML("commit transaction");
  2150. LeaveCriticalSection(db_lock);
  2151. }
  2152. catch (...){
  2153. bantch_db->execDML("rollback transaction");
  2154. LeaveCriticalSection(db_lock);
  2155. OutputDebugString(_T("IResultHandler.SavePaper.catch CppSQLite3Exception"));
  2156. }
  2157. IDENTIFY_MSG * msg = new IDENTIFY_MSG;
  2158. msg->class_id = class_id;
  2159. msg->class_total = class_total;
  2160. strcpy(msg->class_info, class_info);
  2161. msg->exceptions = exceptions;
  2162. msg->identified = identified;
  2163. msg->paper_id = student_paper_id;
  2164. msg->score = total_score;
  2165. msg->student_id = -1;// student_id;
  2166. msg->locationID = g_myindex;
  2167. strcpy(msg->student_name, student_name);
  2168. strcpy(msg->examnumber, studentcode.c_str());
  2169. if (m_hwnd != NULL)
  2170. {
  2171. if (isupdate)
  2172. {
  2173. if (m_bUseQr){
  2174. if (((exceptions & EX_KAOHAODAIPIPEI) == 0))
  2175. ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)student_paper_id);
  2176. if (!pUnhandledPageInfo->bOnlineCard){
  2177. }
  2178. }
  2179. }
  2180. else
  2181. {
  2182. //printf("WM_IDENTIFOR_REPORT:%d\n",msg->paper_id);
  2183. ::PostMessage(m_hwnd, WM_IDENTIFOR_REPORT, (WPARAM)msg, NULL);
  2184. }
  2185. }
  2186. for (int m = 0; m < paper_page_count; m++)
  2187. {
  2188. int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE;
  2189. if (pUnhandledPageInfo->bOnlineCard){
  2190. static_cast<OnLineCard::COnlineCardIdentifor*>(m_identifor)->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result);
  2191. }
  2192. else{
  2193. unhandledPageInfo.result->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result);
  2194. }
  2195. }
  2196. unhandledPageInfo.first_unhandled_page_index = (unhandledPageInfo.first_unhandled_page_index + paper_page_count) % MAX_UNHANDLED_PAGE;
  2197. unhandledPageInfo.unhandled_page_count -= paper_page_count;
  2198. }
  2199. void CResultHandler::SaveImages(vector<CUT_AREA_RESULT*> &area_results, CMemZipFile &zip, int subjectID, BOOL bOnlineCard, char *strPaperCode, const std::vector<std::string> &postMarkTypeIDVec, std::map<std::string, int> &vecTwoPic)
  2200. {
  2201. CString question_code;
  2202. question_code.Format(_T("%s.jpg"), CString(area_results[0]->area_name.c_str()));
  2203. zip.PutNextEntry(question_code);
  2204. std::sort(area_results.begin(), area_results.end(), sort_subindex);
  2205. //postMarkTypeID == 10 判断
  2206. BOOL flag = false;
  2207. for (int i = 0; i < postMarkTypeIDVec.size(); i++)
  2208. {
  2209. for (int j = 0; j < area_results.size(); j++){
  2210. if (postMarkTypeIDVec[i] == area_results[j]->area_name)
  2211. {
  2212. flag = true;
  2213. break;
  2214. }
  2215. }
  2216. }
  2217. vector<int> compression_params_low;
  2218. compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
  2219. compression_params_low.push_back(40);
  2220. vector<int> compression_params_high;
  2221. compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
  2222. compression_params_high.push_back(60);
  2223. int width = 0;
  2224. int height = 0;
  2225. int centerx = 0, centery = 0;
  2226. for (int jj = 0; jj<area_results.size(); jj++)
  2227. {
  2228. if (area_results[jj]->width>width)width = area_results[jj]->width;
  2229. height += area_results[jj]->height;
  2230. centerx = area_results[jj]->centerx;
  2231. centery += area_results[jj]->centery;
  2232. }
  2233. IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
  2234. cvSet(img, cvScalarAll(255));
  2235. for (int ii = 0, top = 0; ii < area_results.size(); ii++)
  2236. {
  2237. Mat ff = Mat(1, area_results[ii]->img_data.size(), CV_8U, area_results[ii]->img_data.data());
  2238. Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
  2239. cvSetImageROI(img, cvRect(0, top, temp_img.cols, temp_img.rows));
  2240. cvCopy(&IplImage(temp_img), img);
  2241. top += area_results[ii]->height;
  2242. }
  2243. cvResetImageROI(img);
  2244. vector<uchar> dst;
  2245. cv::Mat _img = cv::cvarrToMat(img);
  2246. if (img->height > 500){
  2247. imencode(".jpg", _img, dst, compression_params_low);
  2248. }
  2249. else{
  2250. imencode(".jpg", _img, dst, compression_params_high);
  2251. }
  2252. char sz_question_code[520] = { 0 };
  2253. WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
  2254. cvReleaseImage(&img);
  2255. zip.Write(&dst[0], dst.size());
  2256. if (flag && area_results.size() >1){
  2257. for (int jj = 0; jj < area_results.size(); jj++)
  2258. {
  2259. question_code.Format(_T("%s_%d.jpg"), CString(area_results[0]->area_name.c_str()), jj + 1);
  2260. zip.PutNextEntry(question_code);
  2261. width = area_results[jj]->width;
  2262. height = area_results[jj]->height;
  2263. IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
  2264. cvSet(img, cvScalarAll(255));
  2265. //for (int ii = 0, top = 0; ii < area_results.size(); ii++)
  2266. //{
  2267. Mat ff = Mat(1, area_results[jj]->img_data.size(), CV_8U, area_results[jj]->img_data.data());
  2268. Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE);
  2269. cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows));
  2270. cvCopy(&IplImage(temp_img), img);
  2271. //top += area_results[ii]->height;
  2272. //}
  2273. cvResetImageROI(img);
  2274. char sz_question_code[520] = { 0 };
  2275. WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL);
  2276. vector<uchar> dst;
  2277. cv::Mat _img = cv::cvarrToMat(img);
  2278. if (img->height > 500){
  2279. imencode(".jpg", _img, dst, compression_params_low);
  2280. }
  2281. else{
  2282. imencode(".jpg", _img, dst, compression_params_high);
  2283. }
  2284. cvReleaseImage(&img);
  2285. zip.Write(&dst[0], dst.size());
  2286. }
  2287. vecTwoPic[area_results[0]->area_name.c_str()] = area_results.size();
  2288. }
  2289. }
  2290. void CResultHandler::setHandlInfo(const boost::shared_ptr<const HANDLE_INFO>& handInfo)
  2291. {
  2292. m_handInfo = handInfo;
  2293. std::map<int, const PAGE_RESULT_HANDLE_INFO> handInfoMap;
  2294. for (int i = 0; i<m_handInfo->size(); i++)
  2295. {
  2296. const PAGE_RESULT_HANDLE_INFO & p = (*m_handInfo)[i];
  2297. std::map<int, const PAGE_RESULT_HANDLE_INFO>::value_type v(p.page_index, p);
  2298. handInfoMap.insert(v);
  2299. }
  2300. m_handInfoMap = handInfoMap;
  2301. }
  2302. bool CResultHandler::existAbsentFlag(OMR_RESULT * omr_result)
  2303. {
  2304. const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
  2305. return handleInfo.quekaoHandleInfo.size()>0;
  2306. }
  2307. std::string CResultHandler::absentFlag(OMR_RESULT * omr_result)
  2308. {
  2309. const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
  2310. const std::vector<QUEKAOBIAOJI_RESULT_HANDLE_INFO>& quekaoHandleInfo = handleInfo.quekaoHandleInfo;
  2311. if (quekaoHandleInfo.size()>0)return omr_result->group_result[quekaoHandleInfo[0].group_index[0]].answer;
  2312. return "";
  2313. }
  2314. bool CResultHandler::existABJuanFlag(OMR_RESULT * omr_result)
  2315. {
  2316. const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
  2317. return handleInfo.abjuanHandleInfo.size()>0;
  2318. }
  2319. bool CResultHandler::existABJuanFlag()
  2320. {
  2321. for (int i = 0; i<m_handInfo->size(); i++)
  2322. {
  2323. if ((*m_handInfo)[i].abjuanHandleInfo.size()>0)return true;
  2324. }
  2325. return false;
  2326. }
  2327. std::string CResultHandler::ABJuanFlag(OMR_RESULT * omr_result)
  2328. {
  2329. const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index];
  2330. const std::vector<ABJUAN_RESULT_HANDLE_INFO>& abjuanHandleInfo = handleInfo.abjuanHandleInfo;
  2331. if (abjuanHandleInfo.size()>0)return omr_result->group_result[abjuanHandleInfo[0].group_index[0]].answer;
  2332. return "";
  2333. }
  2334. void CResultHandler::IdentifyTaskManager(CIdentifyTaskManager* taskManager)
  2335. {
  2336. this->taskManager = taskManager;
  2337. }
  2338. BOOL CResultHandler::SupportPause(void)
  2339. {
  2340. return TRUE;
  2341. }
  2342. ServiceState CResultHandler::OnPausing(void)
  2343. {
  2344. return IService::OnPausing();
  2345. }
  2346. void CResultHandler::SetIdentifyService(CIdentifyService* service)
  2347. {
  2348. identifyService = service;
  2349. }
  2350. bool CResultHandler::readPaperId(CString& strPaperId)
  2351. {
  2352. TCHAR exeFullPath[MAX_PATH];
  2353. CString strPath;
  2354. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  2355. strPath = (CString)exeFullPath;
  2356. int position = strPath.ReverseFind('\\');
  2357. strPath = strPath.Left(position + 1);
  2358. TCHAR FilePath[MAX_PATH];
  2359. GetModuleFileName(NULL, FilePath, MAX_PATH);
  2360. (_tcsrchr(FilePath, '\\'))[1] = 0;
  2361. lstrcat(FilePath, _T("paperInfo.ini"));
  2362. WCHAR PaperId[512];
  2363. GetPrivateProfileString(_T("paperinfo"), _T("paper_str"), _T(""), PaperId, 512, FilePath);
  2364. strPaperId = PaperId;
  2365. return false;
  2366. }
  2367. void CResultHandler::readOnlineCardPaperId(string strPaperCode, string strStudentId)
  2368. {
  2369. wstring strCode = AnsiToUnicode(strPaperCode);
  2370. wstring strKey = AnsiToUnicode(strStudentId);
  2371. TCHAR exeFullPath[MAX_PATH];
  2372. CString strPath;
  2373. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  2374. strPath = (CString)exeFullPath;
  2375. int position = strPath.ReverseFind('\\');
  2376. strPath = strPath.Left(position + 1);
  2377. TCHAR FilePath[MAX_PATH];
  2378. GetModuleFileName(NULL, FilePath, MAX_PATH);
  2379. (_tcsrchr(FilePath, '\\'))[1] = 0;
  2380. lstrcat(FilePath, _T("magic\\"));
  2381. lstrcat(FilePath, strCode.c_str());
  2382. lstrcat(FilePath, _T("magic.ini"));
  2383. WCHAR PaperId[512];
  2384. GetPrivateProfileString(_T("paperinfo"), strKey.c_str(), _T(""), PaperId, 512, FilePath);
  2385. m_strOnlineCardPaperId = UnicodeToAnsi(PaperId);
  2386. }
  2387. void CResultHandler::WriteOnlineCardPaperId(CString strPaperCode, wstring& strSubGroupId, wstring strStudentId)
  2388. {
  2389. TCHAR exeFullPath[MAX_PATH];
  2390. CString strPath;
  2391. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  2392. strPath = (CString)exeFullPath;
  2393. int position = strPath.ReverseFind('\\');
  2394. strPath = strPath.Left(position + 1);
  2395. TCHAR FilePath[MAX_PATH];
  2396. GetModuleFileName(NULL, FilePath, MAX_PATH);
  2397. (_tcsrchr(FilePath, '\\'))[1] = 0;
  2398. lstrcat(FilePath, _T("magic\\"));
  2399. lstrcat(FilePath, strPaperCode);
  2400. lstrcat(FilePath, _T("magic.ini"));
  2401. WritePrivateProfileString(_T("paperinfo"), strStudentId.c_str(), strSubGroupId.c_str(), FilePath);
  2402. }
  2403. bool CResultHandler::readTimu(CString& strTimu)
  2404. {
  2405. TCHAR exeFullPath[MAX_PATH];
  2406. CString strPath;
  2407. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  2408. strPath = (CString)exeFullPath;
  2409. int position = strPath.ReverseFind('\\');
  2410. strPath = strPath.Left(position + 1);
  2411. TCHAR FilePath[MAX_PATH];
  2412. GetModuleFileName(NULL, FilePath, MAX_PATH);
  2413. (_tcsrchr(FilePath, '\\'))[1] = 0;
  2414. lstrcat(FilePath, _T("paperInfo.ini"));
  2415. WCHAR Timu[512];
  2416. GetPrivateProfileString(_T("paperinfo"), _T("timu_info"), _T(""), Timu, 512, FilePath);
  2417. strTimu = Timu;
  2418. return false;
  2419. }
  2420. bool CResultHandler::loadSchema()
  2421. {
  2422. CString strFileName;
  2423. if (g_my_scan_type == 0)
  2424. {
  2425. TCHAR FilePath[MAX_PATH];
  2426. GetModuleFileName(NULL, FilePath, MAX_PATH);
  2427. (_tcsrchr(FilePath, '\\'))[1] = 0;
  2428. strFileName = FilePath;
  2429. strFileName += _T("\\1111.zip");
  2430. }
  2431. //else
  2432. else if (g_my_scan_type == 1)
  2433. {
  2434. TCHAR FilePath[MAX_PATH];
  2435. GetModuleFileName(NULL, FilePath, MAX_PATH);
  2436. (_tcsrchr(FilePath, '\\'))[1] = 0;
  2437. TCHAR FileName[50];
  2438. _stprintf(FileName, _T("\\mode\\student%d.schema"), g_myindex);
  2439. lstrcat(FilePath, FileName);
  2440. strFileName = FilePath;
  2441. }
  2442. else if (g_my_scan_type == 2)
  2443. {
  2444. TCHAR cfgPath[MAX_PATH];
  2445. GetModuleFileName(NULL, cfgPath, MAX_PATH);
  2446. (_tcsrchr(cfgPath, '\\'))[1] = 0;
  2447. lstrcat(cfgPath, _T("config.ini"));
  2448. TCHAR schoolID[64] = { 0 };
  2449. GetPrivateProfileString(_T("USER"), _T("schoolId"), _T(""), schoolID, sizeof(schoolID) / sizeof(TCHAR), cfgPath);
  2450. TCHAR __version[64] = { 0 };
  2451. GetPrivateProfileString(_T("USER"), _T("tifenbaoversion"), _T(""), __version, sizeof(__version) / sizeof(TCHAR), cfgPath);
  2452. CString version = __version;
  2453. TCHAR FilePath[MAX_PATH];
  2454. GetModuleFileName(NULL, FilePath, MAX_PATH);
  2455. (_tcsrchr(FilePath, '\\'))[1] = 0;
  2456. CString strPath;
  2457. if (CString(schoolID).GetLength() == 4){
  2458. if (version.IsEmpty()){
  2459. strPath += "/mode/tifenbaoZixuanka-9.3.0.schema";
  2460. }
  2461. else{
  2462. strPath += "/mode/tifenbaoZixuanka-9.3.3.schema";
  2463. }
  2464. }
  2465. else{
  2466. if (version.IsEmpty()){
  2467. strPath += "/mode/tifenbaoZixuanka-8.3.0.schema";
  2468. }
  2469. else{
  2470. strPath += "/mode/tifenbaoZixuanka-8.3.3.schema";
  2471. }
  2472. }
  2473. strFileName = CString(FilePath) + strPath;
  2474. }
  2475. CUnZipFile uzip(strFileName);
  2476. std::map<CString, std::vector<unsigned char>> map;
  2477. while (uzip.HasMoreEntry()){
  2478. CString fileNam;
  2479. uzip.GetNextEntry(fileNam);
  2480. char buffer[1024 * 8];
  2481. int len;
  2482. std::vector<unsigned char>& data = map[fileNam];
  2483. data.reserve(1024 * 128);
  2484. while ((len = uzip.Read(buffer, 1024 * 8))>0){
  2485. if (data.capacity()<data.size() + len){
  2486. int c = data.capacity() + 1024 * 128;
  2487. data.reserve(c);
  2488. }
  2489. int oldSize = data.size();
  2490. data.resize(oldSize + len);
  2491. char * dst = (char *)data.data() + oldSize;
  2492. memcpy(dst, buffer, len);
  2493. }
  2494. }
  2495. uzip.Close();
  2496. std::map<CString, std::vector<unsigned char>>::iterator schemabytes = map.find(_T("schema.bytes"));
  2497. if (schemabytes == map.end()){
  2498. return false;
  2499. }
  2500. SCHEMA_VERSION version;
  2501. std::vector<unsigned char>& data = schemabytes->second;
  2502. serializor::SchemJsonSerializor::deserialize(std::string((char *)data.data(), data.size()), m_schema, version);
  2503. if (m_schema.state == 0) return SCH_LOAD_ERR_ZHUANGTAIBUZHENGQUE;
  2504. return true;
  2505. }
  2506. void CResultHandler::SavePathImg(std::string path, CMemZipFile &zip, int i){
  2507. IplImage* pImg = cvLoadImage(path.c_str(), 1);
  2508. CString question_code;
  2509. question_code.Format(_T("image_%d.jpg"), i + 1);
  2510. zip.PutNextEntry(question_code);
  2511. vector<uchar> dst;
  2512. vector<int> compression_params_low;
  2513. compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY);
  2514. compression_params_low.push_back(40);
  2515. vector<int> compression_params_high;
  2516. compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY);
  2517. compression_params_high.push_back(60);
  2518. cv::Mat _img = cv::cvarrToMat(pImg);
  2519. if (pImg->height > 500){
  2520. imencode(".jpg", _img, dst, compression_params_low);
  2521. }
  2522. else{
  2523. imencode(".jpg", _img, dst, compression_params_high);
  2524. }
  2525. cvReleaseImage(&pImg);
  2526. zip.Write(&dst[0], dst.size());
  2527. }
  2528. #include <direct.h>
  2529. void ThreadLog4(char* strLogContent, char* fileName)
  2530. {
  2531. char buf[200];
  2532. _getcwd(buf, sizeof(buf));
  2533. strcat_s(buf, "\\ThirdParty\\");
  2534. strcat_s(buf, fileName);
  2535. FILE *file = NULL;
  2536. fopen_s(&file, buf, "at+");
  2537. if (file == NULL)
  2538. {
  2539. // printf("路径错误\n");
  2540. //system("pause");
  2541. return;
  2542. }
  2543. fseek(file, 0, SEEK_END);
  2544. char strLogTemp[5000];
  2545. strcpy_s(strLogTemp, sizeof(strLogTemp), strLogContent);
  2546. fwrite(&strLogTemp, strlen(strLogTemp), 1, file);
  2547. fclose(file);
  2548. }
  2549. void CResultHandler::logForDbg(string strLog)
  2550. {
  2551. char logContent[300];
  2552. char logName[300];
  2553. char sYear[10], sMonth[5], sDay[25];
  2554. SYSTEMTIME st;
  2555. GetLocalTime(&st);
  2556. int j0 = 0;
  2557. int m_nYear = st.wYear; ///年
  2558. int m_nMonth = st.wMonth; ///月
  2559. int m_nDay = st.wDay; ///日
  2560. int m_nHour = st.wHour; ///小时
  2561. int m_nMinute = st.wMinute; ///分钟
  2562. int m_nSecond = st.wSecond; ///秒
  2563. int m_nMillSecond = st.wMilliseconds; ///毫秒
  2564. char strTime[300];
  2565. sprintf(strTime, "----------------------------------%d_%02d_%02d_%d_%02d_%02d", m_nYear, m_nMonth, m_nDay, m_nHour, m_nMinute, m_nSecond);
  2566. strLog += strTime;
  2567. sprintf_s(sYear, sizeof(sYear), "%d", m_nYear);
  2568. sprintf_s(sMonth, sizeof(sMonth), "_%02d", m_nMonth);
  2569. sprintf_s(sDay, sizeof(sDay), "_%02d_log.txt", m_nDay);
  2570. strcpy(logName, sYear);
  2571. strcat(logName, sMonth);
  2572. strcat(logName, sDay);
  2573. char strScore[MAX_PATH] = { 0 };
  2574. for (int i = 0; i < strLog.size(); i++)
  2575. strScore[i] = strLog.at(i);
  2576. sprintf_s(logContent, sizeof(logContent), "%s\n", strScore);
  2577. ThreadLog4(logContent, logName);
  2578. }
  2579. string CResultHandler::GetOnlineCardPaperId(string strPaperCode, string strStudentId)
  2580. {
  2581. //if (m_strOnlineCardPaperId.empty())
  2582. readOnlineCardPaperId(strPaperCode, strStudentId);
  2583. return m_strOnlineCardPaperId;
  2584. }