#include "stdafx.h" #include "ResultHandler.h" #include "basic_struct.h" #include "..\ZLibWrapMemLib\MemZipFile.h" #include "IdentifyService.h" #include "..\ZLibWrapMemLib\UnZipFile.h" #include "..\Schema\schema.h" #include "OnlineCardIdentifor.h" #include #include #include #include #include "ImgUploadManager.h" #include "ServerConfig.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern int g_my_scan_type; //督学卡学校id extern std::string g_strShoolId; extern int g_myindex; extern ::string UnicodeToAnsi(const CString& str); extern CString AnsiToUnicode(const std::string& str); void CResultHandler::SetIdentifor(CIdentifor* identifor) { m_identifor = identifor; } CResultHandler::~CResultHandler() { } CResultHandler::CResultHandler() { m_nOnlineScanType = -1; m_bSvePage = false; m_bErrorHandle = false; m_strQr = ""; m_bUseQr = false; m_hwnd = NULL; m_bOnlineCard = false; m_bUseQrCode =false;//是否使用二维码 m_bIdentifyQrCode = false;// 是否识别二维码 } ServiceState CResultHandler::OnRunning(void) { ServiceState nextState = IService::OnRunning(); if (nextState == pausing) return nextState; if (m_muban_page_count <= 0 && m_identifor->IsMubanLoaded()){ m_muban_page_count = m_identifor->GetMubanCount(); m_isMubanLoaded = TRUE; } if (m_isMubanLoaded == FALSE){ Sleep(10); return running; } CIdentifyTask* task = taskManager->getCurrentHandleTask(); if (task){ pUnhandledPageInfo = task->getUnhandledPageManager(); } else{ if (m_bOnlineCard && m_hwnd != NULL && !m_bIdentifyQrCode) ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)2, (LPARAM)NULL); return stoping; } UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo; 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; if (unhandledPageInfo.unhandled_page_count >= handle_count_limit){ if (m_muban_page_count>0){ SavePaper(handle_count_limit); } else if (unhandledPageInfo.m_stop){//到停止时 模板还是没有 ,直接清除缓存 unhandledPageInfo.unhandled_page_count = 0; } } CResultManager * bm = task->getResultBufferManager(); OMR_RESULT * omr_result = bm->GetResult(TRUE); if (!m_handInfo.get()){ const boost::shared_ptr& handleInfo = identifyService->GetHandleInfo(); if (handleInfo.get()){ setHandlInfo(handleInfo); } } if (omr_result == NULL){ if (unhandledPageInfo.unhandled_page_count <= 0){ taskManager->doneTask(task); } else{ unhandledPageInfo.m_stop = TRUE; } return running; } SavePage(omr_result); return running; } ServiceState CResultHandler::OnStarting(void) { m_bSend = false; m_bSvePage = false; m_bOnlineCard = false; m_bUseQrCode =false;//是否使用二维码 m_bIdentifyQrCode = false;// 是否识别二维码 m_muban_page_count = 0; scoreCounter.SetDataBase(db_lock, bantch_db); scoreCounter.Load(); loadSchema(); return running; } ServiceState CResultHandler::OnStoping(void) { if (m_bOnlineCard && m_bSvePage){ OnLineCard::PaperTemplate* pTmp = static_cast(m_identifor)->GetTemplate(); if (m_hwnd != NULL && !m_bIdentifyQrCode&& !pTmp->useQrCode) ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)2, (LPARAM)NULL); } return IService::OnStoping(); } int CResultHandler::SetHandlerWnd(HWND hwnd) { m_hwnd = hwnd; return 0; } int CResultHandler::SavePage(OMR_RESULT * omr_result) { UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo; char phy_number[20]; int len = sprintf_s(phy_number, "%d", omr_result->phy_card_number); int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE; unhandledPageInfo.unhandled_page_count++; UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index]; unhandled_page.identified = omr_result->identified; int page_index = unhandled_page.page_index = omr_result->card_index; unhandled_page.omr_result = omr_result; unhandled_page.student_code = ""; if (omr_result->identified){ if (m_bUseQr){ if (!m_strQr.empty()){ std::vector< std::string > _out; split(m_strQr, "@", &_out); if (_out.size() >= 3){ unhandled_page.student_code = _out[1]; unhandled_page.student_id = _out[2];; } if (!unhandled_page.student_id.empty())return 0; } } bool needRead = true; for (int i = 0; needRead&&i < omr_result->qr_result.size(); i++) { if (omr_result->qr_result[i].qr_str.length()>0){ unhandled_page.student_code = omr_result->qr_result[i].qr_str; needRead = false; break; } } const std::vector& tiantukaohaoHandleInfo = m_handInfoMap[page_index].tiantukaohaoHandleInfo; for (int i = 0; needRead&&igroup_result[tiantukaohaoHandleInfo[i].group_index[j]].answer.c_str(); student_code += answer; if (answer[0] == '\0') { break; } //if (answer[0] == 0){ student_code += "*"; isRight = false; } } if (student_code.length() < 1) { student_code += "*"; isRight = false; } if (student_code.length() > 30)isRight = false; if (isRight){ if (g_my_scan_type == 0) { unhandled_page.student_code = student_code; } else { /* if (g_myindex <= 5) { unhandled_page.student_code = g_strShoolId; for (int i = 0; i < student_code.length(); i++) { unhandled_page.student_code += student_code.at(student_code.length() - 1 - i); } } else { */ unhandled_page.student_code = (g_strShoolId + student_code); //} } needRead = false; break; } } } return 0; } #include #include #include std::mutex mtxTaskNum; std::atomic taskNum = 0; struct SavePathImgPara{ std::string path; CString pathSave; int m; SavePathImgPara(std::string path1, CString path2, int n) :path(path1), pathSave(path2), m(n){} }; struct saveImgesPara1{ vector *area_rst; CString path; int subjectID; bool flag; //int ID; saveImgesPara1(vector *area_rst1, CString name1, int subjectid, bool flag1) : path(name1), subjectID(subjectid), flag(flag1) { area_rst = area_rst1; //ID = id; //printf("name: %s \r\n ", (*area_rst)[0]->area_name.c_str()); } }; int SavePathImgMy(PVOID para1) { SavePathImgPara *para = (SavePathImgPara *)para1; std::string path = para->path; CString question_code; question_code.Format(_T("\\image_%d.jpg"), para->m + 1); CString oldfile; oldfile = CA2T(path.c_str()); CString savePath = para->pathSave + question_code; CopyFile(oldfile, savePath, FALSE); /* IplImage* pImg = cvLoadImage(path.c_str(), 1); CString question_code; question_code.Format(_T("\\image_%d.jpg"), para->m + 1); CString savePath = para->pathSave + question_code; //savePath.Format(_T("%s%s"), para->pathSave.c_str(), question_code); //zip.PutNextEntry(question_code); vector dst; vector compression_params_low; compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_low.push_back(40); vector compression_params_high; compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_high.push_back(60); cv::Mat _img = cv::cvarrToMat(pImg); if (pImg->height > 500){ imencode(".jpg", _img, dst, compression_params_low); } else{ imencode(".jpg", _img, dst, compression_params_high); } cvReleaseImage(&pImg); //zip.Write(&dst[0], dst.size()); CFile file; file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write(dst.data(), dst.size()); file.Close(); */ return 0; } void saveImgPathMyCallback(PVOID para1/*CString filepath, CString key*/) { std::lock_guard _lk(mtxTaskNum); taskNum--; //delete para1; //para1 = NULL; } int saveImgesMy1(PVOID para1/*CString filepath, CString key*/) { //printf("saveImgesMy1 %p\r\n", para1); saveImgesPara1 *para = (saveImgesPara1 *)para1; vector *area_results = para->area_rst; CString path = para->path; bool flag = para->flag; int subjectID = para->subjectID; //printf("DST name=%s\n", (*area_results)[0]->area_name.c_str()); std::string area_name; CString savePath; CFile file; if ((*area_results)[0]->area_name == "") { area_name = (*area_results)[0]->area_name; int idx; area_name = ((idx = area_name.find('.')) < 0) ? area_name : area_name.substr(0, idx); CString question_code; question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str())); savePath = path + question_code; //printf("flag: %d , subjectID = %d,id: %d \r\n", flag?1:0, subjectID, para->ID); } else { area_name = (*area_results)[0]->area_name; CString question_code; question_code.Format(_T("\\%s.jpg"), CString(area_name.c_str())); //printf("flag: %d , subjectID = %d,id: %d \r\n", flag ? 1 : 0, subjectID, para->ID); savePath = path + question_code; } if ((*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){ int width = 0; int height = 0; for (int jj = 0; jj < (*area_results).size(); jj++) { if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width; height += (*area_results)[jj]->height; } cv::Mat img_big(cv::Size(width, height), CV_8UC3, cv::Scalar(255, 255, 255)); for (int ii = 0, top = 0; ii < (*area_results).size(); ii++) { Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data()); Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_COLOR); cv::Rect rc_tmp(0, top, temp_img.cols, temp_img.rows); Mat cut = img_big(rc_tmp); temp_img.copyTo(cut); top += temp_img.rows; } ////////////////////////////////////////////////////////////////////////// vector dst; //cv::Mat _img = cv::cvarrToMat(img); vector compression_params; compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(25); imencode(".jpg", img_big, dst, compression_params); //cvResetImageROI(img); //zip.Write(&dst[0], dst.size()); file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write(dst.data(), dst.size()); file.Close(); if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1) { CString question_code; question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str())); savePath = path + question_code; file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write(dst.data(), dst.size()); file.Close(); //zip.PutNextEntry(question_code); //zip.Write(&dst[0], dst.size()); } } else { if ((*area_results)[0]->is_cut > 0) { //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size()); if (file.Open(savePath, CFile::modeCreate | CFile::modeWrite)){ file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size()); file.Close(); } else{ auto e = GetLastError(); int n = 0; ++n; } if (!(subjectID != 0) && (*area_results)[0]->is_cut == 1) { //zip.PutNextEntry(AnsiToUnicode(area_name + "f.jpg")); //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size()); CString question_code; question_code.Format(_T("\\%sf.jpg"), CString(area_name.c_str())); savePath = path + question_code; file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size()); file.Close(); } } else { file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write((*area_results)[0]->img_data.data(), (*area_results)[0]->img_data.size()); file.Close(); //zip.Write(area_results[0]->img_data.data(), area_results[0]->img_data.size()); } } if (flag && (*area_results).size() > 1 && (*area_results)[0]->is_cut > 0){ vector compression_params_low; compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_low.push_back(40); vector compression_params_high; compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_high.push_back(60); for (int jj = 0; jj < (*area_results).size(); jj++) { CString question_code; question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1); //zip.PutNextEntry(question_code); savePath = path + question_code; /* int width = (*area_results)[jj]->width; int height = (*area_results)[jj]->height; IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); cvSet(img, cvScalarAll(255)); Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data()); Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE); cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows)); cvCopy(&IplImage(temp_img), img); cvResetImageROI(img); char sz_question_code[520] = { 0 }; WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL); vector dst; cv::Mat _img = cv::cvarrToMat(img); if (img->height > 500){ imencode(".jpg", _img, dst, compression_params_low); } else{ imencode(".jpg", _img, dst, compression_params_high); } cvReleaseImage(&img); */ //zip.Write(&dst[0], dst.size()); file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write((*area_results)[jj]->img_data.data(), (*area_results)[jj]->img_data.size()); file.Close(); } } //printf("path:%s \r\n",CT2A(savePath)); return 0; } bool sort_subindex(const CUT_AREA_RESULT * c1, const CUT_AREA_RESULT * c2){ return c1->area_sub_index < c2->area_sub_index; } int saveImgesMy2(PVOID para1/*CString filepath, CString key*/) { saveImgesPara1 *para = (saveImgesPara1 *)para1; vector *area_results = para->area_rst; CString path = para->path; bool flag = para->flag; int subjectID = para->subjectID; CString question_code; question_code.Format(_T("\\%s.jpg"), CString((*area_results)[0]->area_name.c_str())); //zip.PutNextEntry(question_code); std::sort((*area_results).begin(), (*area_results).end(), sort_subindex); CString savePath = path + question_code; //postMarkTypeID == 10 判断 vector compression_params_low; compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_low.push_back(40); vector compression_params_high; compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_high.push_back(60); int width = 0; int height = 0; int centerx = 0, centery = 0; for (int jj = 0; jj < (*area_results).size(); jj++) { if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width; height += (*area_results)[jj]->height; centerx = (*area_results)[jj]->centerx; centery += (*area_results)[jj]->centery; } IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); cvSet(img, cvScalarAll(255)); for (int ii = 0, top = 0; ii < (*area_results).size(); ii++) { Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data()); Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE); cvSetImageROI(img, cvRect(0, top, temp_img.cols, temp_img.rows)); temp_img.copyTo(cv::cvarrToMat(img)); cvCopy(&IplImage(temp_img), img); top += (*area_results)[ii]->height; } cvResetImageROI(img); vector dst; cv::Mat _img = cv::cvarrToMat(img); if (img->height > 500){ imencode(".jpg", _img, dst, compression_params_low); } else{ imencode(".jpg", _img, dst, compression_params_high); } char sz_question_code[520] = { 0 }; WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL); cvReleaseImage(&img); //zip.Write(&dst[0], dst.size()); CFile file; file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write(dst.data(), dst.size()); file.Close(); //imwrite(savePath.c_str(), img); if (flag && (*area_results).size() > 1){ for (int jj = 0; jj < (*area_results).size(); jj++) { question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1); //zip.PutNextEntry(question_code); CString savePath = path + question_code; width = (*area_results)[jj]->width; height = (*area_results)[jj]->height; IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); cvSet(img, cvScalarAll(255)); //for (int ii = 0, top = 0; ii < area_results.size(); ii++) //{ Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data()); Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE); cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows)); cvCopy(&IplImage(temp_img), img); //top += area_results[ii]->height; //} cvResetImageROI(img); char sz_question_code[520] = { 0 }; WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL); vector dst; cv::Mat _img = cv::cvarrToMat(img); if (img->height > 500){ imencode(".jpg", _img, dst, compression_params_low); } else{ imencode(".jpg", _img, dst, compression_params_high); } cvReleaseImage(&img); //zip.Write(&dst[0], dst.size()); CFile file; file.Open(savePath, CFile::modeCreate | CFile::modeWrite); file.Write(dst.data(), dst.size()); file.Close(); } } return 0; } // 算法组提供的新算法 解决 cvcopy崩溃的问题 // int saveImgesMy2(PVOID para1/*CString filepath, CString key*/) // { // saveImgesPara1 *para = (saveImgesPara1 *)para1; // vector *area_results = para->area_rst; // CString path = para->path; // bool flag = para->flag; // int subjectID = para->subjectID; // // CString question_code; // question_code.Format(_T("\\%s.jpg"), CString((*area_results)[0]->area_name.c_str())); // //zip.PutNextEntry(question_code); // std::sort((*area_results).begin(), (*area_results).end(), sort_subindex); // CString savePath = path + question_code; // //postMarkTypeID == 10 判断 // // // vector compression_params_low; // compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY); // compression_params_low.push_back(40); // vector compression_params_high; // compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY); // compression_params_high.push_back(60); // int width = 0; // int height = 0; // int centerx = 0, centery = 0; // for (int jj = 0; jj < (*area_results).size(); jj++) // { // if ((*area_results)[jj]->width > width)width = (*area_results)[jj]->width; // height += (*area_results)[jj]->height; // centerx = (*area_results)[jj]->centerx; // centery += (*area_results)[jj]->centery; // } // // // cv::Mat _img = cv::Mat(cv::Size(width, height), CV_8U, cv::Scalar(255)); // for (int ii = 0, top = 0; ii < (*area_results).size(); ii++) // { // Mat ff = Mat(1, (*area_results)[ii]->img_data.size(), CV_8U, (*area_results)[ii]->img_data.data()); // Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE); // temp_img.copyTo(_img(cv::Rect(0, top, temp_img.cols, temp_img.rows))); // top += (*area_results)[ii]->height; // } // // vector dst; // if (_img.rows > 500) { // imencode(".jpg", _img, dst, compression_params_low); // } // else { // imencode(".jpg", _img, dst, compression_params_high); // } // char sz_question_code[520] = { 0 }; // WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL); // //zip.Write(&dst[0], dst.size()); // CFile file; // file.Open(savePath, CFile::modeCreate | CFile::modeWrite); // file.Write(dst.data(), dst.size()); // file.Close(); // //imwrite(savePath.c_str(), img); // // if (flag && (*area_results).size() > 1) { // for (int jj = 0; jj < (*area_results).size(); jj++) // { // question_code.Format(_T("\\%s_%d.jpg"), CString((*area_results)[0]->area_name.c_str()), jj + 1); // //zip.PutNextEntry(question_code); // CString savePath = path + question_code; // width = (*area_results)[jj]->width; // height = (*area_results)[jj]->height; // IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); // cvSet(img, cvScalarAll(255)); // //for (int ii = 0, top = 0; ii < area_results.size(); ii++) // //{ // Mat ff = Mat(1, (*area_results)[jj]->img_data.size(), CV_8U, (*area_results)[jj]->img_data.data()); // Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE); // cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows)); // cvCopy(&IplImage(temp_img), img); // //top += area_results[ii]->height; // //} // cvResetImageROI(img); // char sz_question_code[520] = { 0 }; // WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL); // vector dst; // cv::Mat _img = cv::cvarrToMat(img); // if (img->height > 500) { // imencode(".jpg", _img, dst, compression_params_low); // } // else { // imencode(".jpg", _img, dst, compression_params_high); // } // cvReleaseImage(&img); // //zip.Write(&dst[0], dst.size()); // CFile file; // file.Open(savePath, CFile::modeCreate | CFile::modeWrite); // file.Write(dst.data(), dst.size()); // file.Close(); // } // } // return 0; // } void saveImgesMyCallback(PVOID para1/*CString filepath, CString key*/) { std::lock_guard _lk(mtxTaskNum); taskNum--; #ifdef _DEBUG LOGFMTI("回调调用-3 taskNum=%d",taskNum.load()); #endif //delete para1; //para1 = NULL; } void CResultHandler::SavePaper(int handle_count_limit) { //printf("SavePaper \n"); UnhandledPageInfo & unhandledPageInfo = *pUnhandledPageInfo; bool identified;//当前这份试卷是否已识别 int identified_count = 0;//已识别页数 int paper_page_count = 0;//当前这份试卷的页数 int student_paper_id = -1; std::string student_id = "-1"; long class_id = -1; int class_total = -1; char student_name[20] = { 0 }; char class_info[20] = { 0 }; float total_score = 0; long exceptions = EX_NOMARL; string studentcode;//学生证号 std::map page_counts; std::map vecTwoPic; std::map> mm; std::vector _mm_tmp; //筛选语文的主观题和选做题 std::vector postMarkTypeIDVec; bool b_is_same_exam_id = false; /************************************************************************/ /* 确定试卷页数,并确定试卷ID 和 试卷编号 */ /************************************************************************/ for (int i = 0; iis_use_qr_code&& if ( unhandledPageInfo.unhandled_pages[index1].omr_result->is_front_page&& !unhandledPageInfo.unhandled_pages[index1].omr_result->is_same_exam_id) { b_is_same_exam_id = true; if (!m_bSend){ m_bSend = true; if (m_hwnd != NULL) ::PostMessage(m_hwnd, WM_IS_NOT_SAME_EXAM_ID, (WPARAM)1, (LPARAM)NULL); } } OnLineCard::PaperTemplate* pTmp = static_cast(m_identifor)->GetTemplate(); if (unhandledPageInfo.unhandled_pages[index1].omr_result->examid_by_qr_code&&!m_bIdentifyQrCode && !pTmp->useQrCode) { m_bIdentifyQrCode = true; } } BOOL is_next = FALSE;//是否是下一份试卷 //比较考号是否不一样 依此判断是否是下一份试卷 if (unhandledPageInfo.unhandled_pages[index1].student_code.length()>0){ if (studentcode.length()>0){ if (studentcode != unhandledPageInfo.unhandled_pages[index1].student_code){ is_next = TRUE; } } else{ studentcode = unhandledPageInfo.unhandled_pages[index1].student_code; } } if (is_next){ break; } page_counts[unhandledPageInfo.unhandled_pages[index1].page_index]++; //比较试卷页码是否重复 依此判断是否是下一份试卷 for (int j = 0; jpaper_id > 0){ student_paper_id = omr_result->paper_id; } if (m_nOnlineScanType == 0 && omr_result->is_front_page && omr_result->strMagicClassId.length() && omr_result->strMagicStudentId.length()) { CString strPaperCode; readPaperId(strPaperCode); WriteOnlineCardPaperId(strPaperCode, (wstring)AnsiToUnicode(omr_result->strMagicClassId), (wstring)AnsiToUnicode(omr_result->strMagicStudentId)); } std::string str_stu_id = unhandledPageInfo.unhandled_pages[index1].student_id; if (!str_stu_id.empty()){ student_id = str_stu_id; } if (unhandledPageInfo.unhandled_pages[index1].identified){ identified_count++; } } identified = (identified_count == m_muban_page_count&&page_counts.size() == m_muban_page_count); if (page_counts.size()identified){ int indx = unhandledPageInfo.unhandled_pages[page_index].omr_result->card_index; if (existAbsentFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result) && Q == absentFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result)){ isAbsent = 1; } if (existABJuanFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result)){ shijuanleixing = ABJuanFlag(unhandledPageInfo.unhandled_pages[page_index].omr_result); } } } else{ auto tmp = unhandledPageInfo.unhandled_pages[page_index].omr_result; if (tmp&& tmp->identified && isAbsent ==0){ isAbsent = tmp->quekaoFlag; } } } if (isAbsent != 0) exceptions |= EX_SHIJUANQUEKAO; /************************************************************************/ /* 保存切割好的图像 */ /************************************************************************/ // printf("切图\n"); std::map _map_real_name; char sz_file_name[520] = { 0 }; char sz_ori_file_name[520] = { 0 }; if (identified){//将切割好的图像压缩为zip CString filename = m_img_clips_dir + _T("\\") + GetTimeString(); CreateDirectory(filename, NULL); filename += _T("\\img"); CreateDirectory(filename, NULL); CString filename1 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("ori"); CreateDirectory(filename1, NULL); filename1 += _T("\\img"); CreateDirectory(filename1, NULL); WideCharToMultiByte(CP_ACP, 0, filename, -1, sz_file_name, 520, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, filename1, -1, sz_ori_file_name, 520, NULL, NULL);; //CMemFile file; //CMemFile file3; //CMemZipFile zip; //CMemZipFile zip1; //zip.OpenFile(&file); //zip1.OpenFile(&file3); vector area_results; UnhandledPage* unhandledPage[16]; for (int m = 0; mpage_index>unhandledPage[n]->page_index){ UnhandledPage* t_page = unhandledPage[m]; unhandledPage[m] = unhandledPage[n]; unhandledPage[n] = t_page; } } } int nQuestionNo = 0; int nZhuGuanTi = 0, nXuanZuoTi = 0, nZhuGuanTi2 = 0, nXuanZuoTi2 = 0, nCutCount = 0; static bool falg = false; if (!unhandledPageInfo.bOnlineCard){ if (!falg && g_my_scan_type != 1) { loadSchema(); falg = true; } else if (g_my_scan_type == 1) loadSchema(); for (int i = 0; i < m_schema.questions.size(); i++) { if (m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI || m_schema.questions[i].questionType == ZHUGUANTI) { if (10 == m_schema.questions[i].postMarkTypeID || 4 == m_schema.questions[i].postMarkTypeID ) postMarkTypeIDVec.push_back(m_schema.questions[i].question_code_new); } } for (int i = 0; i < m_schema.questions.size(); i++) { if (m_schema.questions[i].questionType == TIANKONGTI || m_schema.questions[i].questionType == ZHUGUANTI) { nZhuGuanTi++; } else if (m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI) { nXuanZuoTi++; } } } vector vecQuestionNo; map mapQuestionNo; if (unhandledPageInfo.bOnlineCard){ OnLineCard::PaperTemplate* pTmp = static_cast(m_identifor)->GetTemplate(); if (pTmp){ for (auto it: pTmp->pages){ for (auto itQ : it.second.vctQuestions){ if (itQ.marktype == 4 || itQ.marktype == 10) { postMarkTypeIDVec.push_back(itQ.id); } vecQuestionNo.push_back(std::stoi(itQ.id)); } } } } else{ for (std::size_t i = 0; i < m_schema.questions.size(); i++) { if (m_schema.questions[i].questionType == TIANKONGTI || m_schema.questions[i].questionType == ZHUGUANTI || m_schema.questions[i].questionType == XUANZUO_ZHUGUANTI) { vecQuestionNo.push_back(atoi(m_schema.questions[i].question_code_new)); } } } if (vecQuestionNo.size()>1) { sort(vecQuestionNo.begin(), vecQuestionNo.end(), less_equal()); } std::map> _map_duoxuanti; //std::vector _vct_all_questions; std::map> _map_duoxuantiquanti; std::string strtempallxuanzuotiqs = ""; std::vector paraVec1; for (int m = 0; mbOnlineCard) { int index1 = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result; for (int i = 0; i < omr_result->zhutuanti_result.size(); i++) { auto question_code = omr_result->zhutuanti_result[i].question_code; if (omr_result->zhutuanti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::XUANZUOTI){ std::string strAllQuestions = omr_result->zhutuanti_result[i].question_code_all; int nSel = -1; if (omr_result->zhutuanti_result[i].question_code_all != omr_result->zhutuanti_result[i].question_code_temp && omr_result->zhutuanti_result[i].xuanze == -2) { //说明是类型4的分组选做题 bool bfindselect = false; //本业查找(一定再这个数据之前) for (int j = i -1 ; j >= 0; j--) { if (omr_result->zhutuanti_result[i].question_code_temp == omr_result->zhutuanti_result[j].question_code_temp && omr_result->zhutuanti_result[j].xuanze != -2) { nSel = omr_result->zhutuanti_result[j].xuanze; omr_result->zhutuanti_result[i].xuanze = nSel; bfindselect = true; break; } } //没有找到,向前面查找 if (!bfindselect) { for (int n = m - 1; n >= 0; n--) { bfindselect = false; int index2 = (unhandledPageInfo.first_unhandled_page_index + n) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index2].omr_result; for (int j = omr_result1->zhutuanti_result.size() - 1; j >= 0; j--) { if (omr_result->zhutuanti_result[i].question_code_temp == omr_result1->zhutuanti_result[j].question_code_temp && omr_result1->zhutuanti_result[j].xuanze != -2) { nSel = omr_result1->zhutuanti_result[j].xuanze; omr_result->zhutuanti_result[i].xuanze = nSel; bfindselect = true; break; } } if (bfindselect) break; } } } else { nSel = omr_result->zhutuanti_result[i].xuanze; } _map_duoxuanti[question_code] = std::make_pair(nSel, strAllQuestions); //if (_vct_all_questions.empty()){ if (strtempallxuanzuotiqs != strAllQuestions){ std::vector _vct_all_questions; split(strAllQuestions, (std::string)",", &_vct_all_questions); _map_duoxuantiquanti[strAllQuestions] = _vct_all_questions; strtempallxuanzuotiqs = strAllQuestions; } } } } ThreadPool *threadPool = CImgUploadManager::GetInstance()->getThreadPool(); int nQueKaoNo = 0, nLengthOfTianTuKaoHao = 0; OMR_RESULT* omr_result = unhandledPage[m]->omr_result; SavePathImgPara *para = new SavePathImgPara(omr_result->img_path, filename1, m); //SavePathImg(omr_result->img_path, zip1, m); paraVec1.push_back(para); std::lock_guard _lk(mtxTaskNum); taskNum++; threadPool->QueueTaskItem(SavePathImgMy, para, saveImgPathMyCallback); if (unhandledPageInfo.bOnlineCard){ nQueKaoNo = 1; } else{ nQueKaoNo = m_schema.pages[m].quekaobiaoji.size(); if (m_schema.pages[m].tiantukaohao.size()>0) { if (m_schema.pages[m].tiantukaohao[m].direction == 1)//Vertical; nLengthOfTianTuKaoHao = m_schema.pages[m].tiantukaohao[m].nCols; else nLengthOfTianTuKaoHao = m_schema.pages[m].tiantukaohao[m].nRows; } } for (int t = 0; t < omr_result->cut_area_result.size(); t++) { if (mapQuestionNo.size() >= 0) { map::iterator it = mapQuestionNo.find(omr_result->cut_area_result[t].area_name); if (it == mapQuestionNo.end()) mapQuestionNo.insert(map::value_type(omr_result->cut_area_result[t].area_name, vecQuestionNo[nCutCount + t])); else nCutCount = nCutCount - 1; } } nCutCount = mapQuestionNo.size(); /*if (isAbsent == 0)*/{ for (int n = 0; ncut_area_result.size(); n++) { int nKeguanti, nQuestionIndex; CString strTimu; char cstrTemp[20]; string strAreaName; nZhuGuanTi2++; const std::vector& xuanzuotiHandleInfo = m_handInfoMap[omr_result->card_index].xuanzuotiHandleInfo; for (int i = 0; i < xuanzuotiHandleInfo.size(); i++) { const char * answer = omr_result->group_result[nQueKaoNo + nLengthOfTianTuKaoHao + i].answer.c_str(); if (omr_result->group_result[nQueKaoNo + nLengthOfTianTuKaoHao + i].answer != "") { mapQuestionNo[omr_result->cut_area_result[omr_result->cut_area_result.size() - i - 1].area_name] = atoi(answer); for (int t = 0; t < xuanzuotiHandleInfo[i].option_question_code[0].size(); t++) { if (omr_result->cut_area_result[n].area_name == xuanzuotiHandleInfo[i].option_question_code[0][t].at(0)) { omr_result->cut_area_result[n].area_name = answer; break; } } } } nKeguanti = m_schema.questions.size(); nKeguanti = _wtoi(strTimu.Left(strTimu.Find('&'))); nQuestionIndex = nKeguanti + atoi(omr_result->cut_area_result[n].area_name.c_str()); itoa(mapQuestionNo[omr_result->cut_area_result[n].area_name], cstrTemp, 10); strAreaName = cstrTemp; auto nIndex = omr_result->cut_area_result[n].area_index; if (pUnhandledPageInfo->bOnlineCard){ nIndex = m * 1000 + nIndex; } mm[nIndex].push_back(&omr_result->cut_area_result[n]); _mm_tmp.push_back(nIndex); } } } std::map>::iterator it; char strPaperCode[MAX_PATH]; std::memset(strPaperCode, 0, MAX_PATH); CString strPaperId; readPaperId(strPaperId); for (int i = 0; igetThreadPool(); std::vector paraVec2; vector area_rstlist[400]; int listpos = 0; if (pUnhandledPageInfo->bOnlineCard){ int idx = 0; std::vector tmp_all_q; std::vector _vct_sel; std::vector _mm_unsel_tmp; std::vector _tmp_name; std::string area_name_t; std::string strtempallxuanzuotiqs = ""; std::vector _vct_all_questions; for (auto it = _mm_tmp.begin(); it != _mm_tmp.end(); ++it, ++idx){ std::vector &area_tmp = mm[*it]; vector &area_rst = area_rstlist[listpos++]; area_rst.push_back(area_tmp[0]); int area_sub_index = area_tmp[0]->area_sub_index; bool is_cut = area_tmp[0]->is_cut; bool b_duoxuan = false; bool b_save = true; bool b_sel = false; std::string name = area_tmp[0]->area_name; auto itFind = _map_duoxuanti.find(area_tmp[0]->area_name); if (itFind != _map_duoxuanti.end()){ if (strtempallxuanzuotiqs != itFind->second.second) { //肯定可以找到 _vct_all_questions.clear(); _vct_sel.clear(); tmp_all_q.clear(); _vct_all_questions = _map_duoxuantiquanti.find(itFind->second.second)->second; strtempallxuanzuotiqs = itFind->second.second; tmp_all_q = _vct_all_questions; } b_duoxuan = true; _tmp_name.push_back(itFind->first); std::string area_name; int sel = itFind->second.first; if (sel >= 0 && sel < _vct_all_questions.size() && std::find(_vct_sel.begin(), _vct_sel.end(), sel) == _vct_sel.end()){ area_name = _vct_all_questions[sel]; _vct_sel.push_back(sel); tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end()); _map_real_name[area_tmp[0]->area_name] = area_name; area_tmp[0]->area_name = area_name; _map_duoxuanti.erase(itFind); b_sel = true; } else{ _mm_unsel_tmp.push_back(*it); std::string area_name = *tmp_all_q.begin(); tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end()); _map_real_name[area_rst[0]->area_name] = area_name; b_save = false; } } int next_id = idx + 1; while (next_id < _mm_tmp.size()) { if (area_sub_index == 1 && is_cut && mm[_mm_tmp[next_id]].size()>0 && mm[_mm_tmp[next_id]][0]->area_sub_index == 0){ ++it; ++idx; if (b_duoxuan && !b_sel){ _mm_unsel_tmp.push_back(*it); b_save = false; } area_rst.push_back(mm[*it][0]); next_id = idx + 1; } else{ break; } } if (b_save){ BOOL flag = false; //if (pUnhandledPageInfo->nSubjectID == 0) { for (int i = 0; i < postMarkTypeIDVec.size(); i++) { for (int j = 0; j < area_rst.size(); j++){ if (postMarkTypeIDVec[i] == area_rst[j]->area_name) { flag = true; break; } } } } if (flag && area_rst.size() > 1 && area_rst[0]->is_cut){ vecTwoPic[area_rst[0]->area_name.c_str()] = area_rst.size(); } //printf("SRC name=%s\n", area_rst[0]->area_name.c_str()); saveImgesPara1 *para = new saveImgesPara1(&area_rst, filename, pUnhandledPageInfo->nSubjectID, flag); ///printf("para %p\r\n", para); paraVec2.push_back(para); std::lock_guard _lk(mtxTaskNum); taskNum++; threadPool->QueueTaskItem(saveImgesMy1, para, saveImgesMyCallback); //SaveImages(area_rst, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic); } //area_rst.clear(); area_name_t = ""; } bool bClear = false; vector &area_rst = area_rstlist[listpos]; idx = 0; for (auto it = _mm_unsel_tmp.begin(); it != _mm_unsel_tmp.end(); ++it, ++idx){ std::vector &area_tmp = mm[*it]; int area_sub_index = area_tmp[0]->area_sub_index; int is_cut = area_tmp[0]->is_cut; int next_id = idx + 1; area_rstlist[listpos].push_back(area_tmp[0]); if (area_sub_index == 1 && (is_cut > 0) && next_id < _mm_unsel_tmp.size() && mm[_mm_unsel_tmp[idx + 1]].size()>0 && mm[_mm_unsel_tmp[idx + 1]][0]->area_sub_index == 0){ continue; } //std::string area_name = *tmp_all_q.begin(); //tmp_all_q.erase(std::remove(tmp_all_q.begin(), tmp_all_q.end(), area_name), tmp_all_q.end()); //_map_real_name[area_rst[0]->area_name] = area_name; //area_rst[0]->area_name = area_name; area_rstlist[listpos][0]->area_name = _map_real_name[area_rstlist[listpos][0]->area_name]; //SaveImages(area_rst, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic); BOOL flag = false; //if (pUnhandledPageInfo->nSubjectID == 0) { for (int i = 0; i < postMarkTypeIDVec.size(); i++) { for (int j = 0; j < area_rstlist[listpos].size(); j++){ if (postMarkTypeIDVec[i] == area_rstlist[listpos][j]->area_name) { flag = true; break; } } } } if (flag && area_rstlist[listpos].size() > 1 && area_rstlist[listpos][0]->is_cut > 0){ vecTwoPic[area_rstlist[listpos][0]->area_name.c_str()] = area_rstlist[listpos].size(); } saveImgesPara1 *para = new saveImgesPara1(&area_rstlist[listpos], filename, pUnhandledPageInfo->nSubjectID, flag); //printf("para %p\r\n", para); paraVec2.push_back(para); std::lock_guard _lk(mtxTaskNum); taskNum++; threadPool->QueueTaskItem(saveImgesMy1, para, saveImgesMyCallback); ++listpos; //area_rst = area_rstlist[++listpos]; //area_rst.clear(); } } else{ for (it = mm.begin(); it != mm.end(); ++it){ BOOL flag = false; //if (pUnhandledPageInfo->nSubjectID == 0) { for (int i = 0; i < postMarkTypeIDVec.size(); i++) { for (int j = 0; j < it->second.size(); j++){ if (postMarkTypeIDVec[i] == it->second[j]->area_name) { vecTwoPic[(it->second[0])->area_name.c_str()] = it->second.size(); flag = true; break; } } } } saveImgesPara1 *para = new saveImgesPara1(&it->second, filename, pUnhandledPageInfo->nSubjectID, flag); ///printf("para %p\r\n", para); paraVec2.push_back(para); std::lock_guard _lk(mtxTaskNum); taskNum++; threadPool->QueueTaskItem(saveImgesMy2, para, saveImgesMyCallback); //SaveImages(it->second, zip, pUnhandledPageInfo->nSubjectID, pUnhandledPageInfo->bOnlineCard, strPaperCode, postMarkTypeIDVec, vecTwoPic); } } while (true) { Sleep(10); if (taskNum.load() == 0) { for (std::vector::iterator iter = paraVec2.begin(); iter != paraVec2.end(); ++iter) { if (*iter != nullptr) { //(*iter)->area_rst.clear(); //delete &(*iter)->area_rst; delete (*iter); (*iter) = nullptr; } } for (std::vector::iterator iter = paraVec1.begin(); iter != paraVec1.end(); ++iter) { if (*iter != nullptr) { delete (*iter); (*iter) = nullptr; } } break; } } for (int i = 0; i < listpos;i++) { area_rstlist[i].clear(); } //printf("taskNum 结束 \n"); //zip.Close(); //zip1.Close(); //CString filename = m_img_clips_dir + _T("\\") + GetTimeString() + _T(".zip"); //CString filename1 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("ori.zip"); //WideCharToMultiByte(CP_ACP, 0, filename, -1, sz_file_name, 520, NULL, NULL); //WideCharToMultiByte(CP_ACP, 0, filename1, -1, sz_ori_file_name, 520, NULL, NULL); //CFile file2(filename, CFile::OpenFlags::modeWrite | CFile::OpenFlags::modeCreate); //CFile file4(filename1, CFile::OpenFlags::modeWrite | CFile::OpenFlags::modeCreate); //file.SeekToBegin(); //file3.SeekToBegin(); //int len; char buffer[4096]; //while ((len = file.Read(buffer, 4096))>0){ // file2.Write(buffer, len); //} //while ((len = file3.Read(buffer, 4096))>0){ // file4.Write(buffer, len); //} //file.Close(); //file2.Close(); //file3.Close(); //file4.Close(); } // printf("切图结束\n"); /************************************************************************/ /* 保存试卷页信息和试卷信息 */ /************************************************************************/ /************************************************************************/ /* 匹配学生(先从本地匹配,没有就远程请求) */ /************************************************************************/ //std::string::iterator end_pos = std::remove(studentcode.begin(), studentcode.end(), ' '); //studentcode.erase(end_pos, studentcode.end()); // bool bGetStuInfo = true; // if (m_bUseQr){ // std::vector split_qr; // split(m_strQr, (std::string)",", &split_qr); // if (split_qr.size() >= 3){ // std::vector _vct; // split(split_qr[2], std::string("@"), &_vct); // if (_vct.size() >= 3){ // bGetStuInfo = false; // } // } // } //if (!m_bUseQr || bGetStuInfo) { if (pUnhandledPageInfo->bOnlineCard){ if (studentcode.empty() && student_id == "-1"){ exceptions |= EX_KAOHAOWEISHIBIE; } else{ exceptions |= EX_KAOHAODAIPIPEI; } } else{ // if (!m_bUseQr || m_strQr.empty()){ const std::tr1::regex pattern("^[a-z0-9A-Z]{1,30}$"); if( (studentcode.length() > 0 && std::regex_match(studentcode, pattern))){ exceptions |= EX_KAOHAODAIPIPEI; } else if (identified || studentcode.length() == 0){ exceptions |= EX_KAOHAOWEISHIBIE; } if (existABJuanFlag() && shijuanleixing != "A"&&shijuanleixing != "B"){ exceptions |= EX_ABJUANWEISHIBIE; } // } } } bool isupdate = false; try{ EnterCriticalSection(db_lock); bantch_db->execDML("begin transaction"); // 扫描反馈 // if (exceptions&EX_KAOHAOWEISHIBIE && g_my_scan_type != 0 && g_my_scan_type != 2) { int index1 = (unhandledPageInfo.first_unhandled_page_index + 0) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result; char sql1[1024]; sprintf_s(sql1, "SELECT * from page where img_oldpath = \"%s\"", omr_result->img_oldpath.c_str()); CppSQLite3Query q = bantch_db->execQuery(sql1); if (!q.eof()) { for (int m = 0; mFreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result); } unhandledPageInfo.first_unhandled_page_index = (unhandledPageInfo.first_unhandled_page_index + paper_page_count) % MAX_UNHANDLED_PAGE; unhandledPageInfo.unhandled_page_count -= paper_page_count; bantch_db->execDML("rollback transaction"); LeaveCriticalSection(db_lock); return; } } // printf("插入保存试卷:%d\n", student_paper_id); //插入保存试卷 if (student_paper_id>0){ isupdate = true; char sql5[512]; 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); bantch_db->execDML(sql5); sprintf_s(sql5, "delete from exception where student_paper_id =%d", student_paper_id); bantch_db->execDML(sql5); sprintf_s(sql5, "delete from page where student_paper_id =%d ", student_paper_id); bantch_db->execDML(sql5); CppSQLite3Statement stmt; if (m_bUseQr &&!pUnhandledPageInfo->bOnlineCard ){ 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"); } else{ 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"); stmt.bind(":student_code", studentcode.c_str()); } stmt.bind(":student_paper_id", student_paper_id); stmt.bind(":ret_upload", 0); stmt.bind(":img_upload", 0); stmt.bind(":file_name", sz_file_name); stmt.bind(":ori_img", sz_ori_file_name); stmt.bind(":paper_state", 999); stmt.bind(":student_id", student_id.c_str()); stmt.bind(":absent", isAbsent); // printf("学生ID:%s isAbsent=%d\n", student_id.c_str(), isAbsent); { std::map::iterator it;// = vecTwoPic.end(); it = vecTwoPic.begin(); CString strPic; while (it != vecTwoPic.end()) { //it->first; //it->second; std::string str2; str2 = it->first; //str1 = it->first.c_str(); int num = it->second; //strPic = strPic + _T("_") + std::to_string(num) + _T("#"); str2 = str2 + "_" + std::to_string(num) + "#"; CString str1(str2.c_str()); //str1.Format(_T("%s_%d#"), str1,num); strPic += str1; it++; } char cStrPic[1024]; WideCharToMultiByte(CP_ACP, 0, strPic, -1, cStrPic, 1024, NULL, NULL); stmt.bind(":picFlag", cStrPic); } stmt.execDML(); } else{ CString strPaperId; readPaperId(strPaperId); 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)"); stmt.bind(":ret_upload", 0); stmt.bind(":img_upload", 0); stmt.bind(":file_name", sz_file_name); stmt.bind(":ori_img", sz_ori_file_name); stmt.bind(":student_code", studentcode.c_str()); stmt.bind(":paper_state", 999); stmt.bind(":student_id", student_id.c_str()); stmt.bind(":absent", isAbsent); stmt.bind(":paper_type", shijuanleixing.c_str()); // printf("学生ID:%s isAbsent=%d\n", student_id.c_str(), isAbsent); char strPaperCode[MAX_PATH]; memset(strPaperCode, 0, MAX_PATH); for (int i = 0; i::iterator it;// = vecTwoPic.end(); it = vecTwoPic.begin(); CString strPic; while (it != vecTwoPic.end()) { //it->first; //it->second; std::string str2; str2 = it->first; //str1 = it->first.c_str(); int num = it->second; //strPic = strPic + _T("_") + std::to_string(num) + _T("#"); str2 = str2 + "_" + std::to_string(num) + "#"; CString str1(str2.c_str()); //str1.Format(_T("%s_%d#"), str1,num); strPic += str1; it++; } char cStrPic[1024]; WideCharToMultiByte(CP_ACP, 0, strPic, -1, cStrPic, 1024, NULL, NULL); stmt.bind(":picFlag", cStrPic); stmt.execDML(); CppSQLite3Query query = bantch_db->execQuery("select last_insert_rowId() from student_paper"); student_paper_id = query.getIntField(0); } char phy_number[20]; 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)"); 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)"); if (exceptions&EX_KAOHAOWEISHIBIE){ stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":exception_type", SHIFT_KAOHAOWEISHIBIE); stmt3.bind(":exception_name", "考号未识别"); stmt3.execDML(); } if (exceptions&EX_DINGWEIDIAN) { stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":exception_type", SHIFT_DINGWEIDIAN); stmt3.bind(":exception_name", "定位点异常"); stmt3.execDML(); } if (exceptions&EX_KAOHAOBUCUNZAI){ stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":exception_type", SHIFT_KAOHAOBUCUNZAI); stmt3.bind(":exception_name", "考号不存在"); stmt3.execDML(); } if (exceptions&EX_KAOHAOCHONGTU){ stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU); stmt3.bind(":exception_name", "考号冲突"); stmt3.execDML(); } if (exceptions&EX_SHIJUANQUEYE){ stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":exception_type", SHIFT_SHIJUANQUEYE); stmt3.bind(":exception_name", "试卷缺页"); stmt3.execDML(); } if (exceptions&EX_ABJUANWEISHIBIE){ stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":exception_type", SHIFT_ABJUANWEISHIBIE); stmt3.bind(":exception_name", "AB卷未识别"); stmt3.execDML(); } vector page_ids; //题号是否被选中(有效选中) map question_selected; for (std::map::iterator it = m_handInfoMap.begin(); it != m_handInfoMap.end(); it++) { const std::vector & xuanzuoti_result_handle_infos = it->second.xuanzuotiHandleInfo; for (int idx_xz = 0; idx_xz& mark_unit_question_codes = xuanzuoti_hi.mark_unit_question_code[index_group]; for (int index_markunit = 0; index_markunit markunit_questioncode; split(mark_unit_question_codes[index_markunit], ",", &markunit_questioncode); for (int index_markunit_q = 0; index_markunit_qbOnlineCard) { int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result; //stmt.bind(":img_path", omr_result->img_path.c_str()); Json::Value item; item["path"] = omr_result->img_path.c_str(); json_array4.append(item); flag4 = true; } } */ int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result; //stmt.bind(":img_path", omr_result->img_path.c_str()); if (omr_result->card_qrFlag == -1) { Json::Value item; item["path"] = omr_result->img_path.c_str(); json_array4.append(item); flag4 = true; } } if (flag4) { //发送消息 MY_DB_INFO fff; int len = 1024; memset(fff.sUrl, 0, 520); //strncpy(fff.sDbBasePath, g_strUpLoadDbPathName.c_str(), g_strUpLoadDbPathName.length() + 1); //getupLoadUrl(fff.sUrl, len); fff.ntype = 3; //二维码错误情况 fff.nmode = 1; COPYDATASTRUCT cpd; // 给COPYDATASTRUCT结构赋值 cpd.dwData = 0; cpd.cbData = sizeof(MY_DB_INFO); cpd.lpData = (&fff); json4["imgs"] = json_array4; char sz_file_name4[520] = { 0 }; CString filename4 = m_img_clips_dir + _T("\\") + GetTimeString() + _T("_json.txt"); WideCharToMultiByte(CP_ACP, 0, filename4, -1, sz_file_name4, 520, NULL, NULL); CFile file; CString fliepath; file.Open(filename4, CFile::modeCreate | CFile::modeWrite); Json::FastWriter writer; std::string json_str = writer.write(json4); DWORD wide_string_len = MultiByteToWideChar(CP_ACP, 0, json_str.c_str(), -1, NULL, 0); WCHAR* wide_string = new WCHAR[wide_string_len]; wide_string_len = MultiByteToWideChar(CP_ACP, 0, json_str.c_str(), -1, wide_string, wide_string_len); DWORD utf8_string_len = WideCharToMultiByte(CP_UTF8, 0, wide_string, -1, NULL, 0, NULL, NULL); CHAR* utf8_string = new CHAR[utf8_string_len]; utf8_string_len = WideCharToMultiByte(CP_UTF8, 0, wide_string, -1, utf8_string, utf8_string_len, NULL, NULL); file.Write((void*)utf8_string, utf8_string_len - 1); file.Close(); delete wide_string; delete utf8_string; //Json::FastWriter writer; //std::string json_str = writer.write(json4); memset(fff.sDbBasePath, 0, 520); std::string str = sz_file_name4; strncpy(fff.sDbBasePath, str.c_str(), str.length() + 1); //std::async(std::launch::async, [cpd](){ CWnd *pWnd = NULL; pWnd = CWnd::FindWindow(NULL, _T("知心慧学学管系统")); if (pWnd){ int ret = pWnd->SendMessage(WM_COPYDATA, NULL, (LPARAM)&cpd); // 发送 } //}); } uint kegunti_orgin_count(0); // 客观题原始题数 uint kegunti_empty_count(0); // 客观题未作答题数 { for (int p = 0; p < paper_page_count; p++) { int index1 = (unhandledPageInfo.first_unhandled_page_index + p) % MAX_UNHANDLED_PAGE; OMR_RESULT* omr_result = unhandledPageInfo.unhandled_pages[index1].omr_result; if (omr_result->identified) { if (pUnhandledPageInfo->bOnlineCard) { kegunti_orgin_count += omr_result->group_result.size(); for (int i = 0; i < omr_result->group_result.size(); i++) { if (omr_result->group_result[i].answer.length() == 0) { kegunti_empty_count++; } } } else { const std::vector& keguantiHandleInfo = m_handInfoMap[omr_result->card_index].keguantiHandleInfo; for (int m = 0; m < keguantiHandleInfo.size(); m++) { const std::vector & group_index = keguantiHandleInfo[m].group_index; const std::vector & group_question_count = keguantiHandleInfo[m].group_question_count; for (int idx_g = 0, idx_q = 0; idx_g < group_index.size(); idx_g++) { for (int idx_g_i = 0; idx_g_i < group_question_count[idx_g]; idx_g_i++, idx_q++) { int i = group_index[idx_g]; kegunti_orgin_count++; if (omr_result->group_result[i].answer.length() == 0) { kegunti_empty_count++; } } } } } } } } std::string strquestioncode = ""; for (int p = 0; pphy_card_number); 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)"); stmt.bind(":identified", omr_result->identified); stmt.bind(":phy_number", phy_number); stmt.bind(":page_index", omr_result->card_index); stmt.bind(":img_path", omr_result->img_path.c_str()); stmt.bind(":img_oldpath", omr_result->img_oldpath.c_str()); stmt.bind(":student_paper_id", student_paper_id); stmt.execDML(); CppSQLite3Query query = bantch_db->execQuery("select last_insert_rowId() from page"); int page_id = query.getIntField(0); page_ids.push_back(page_id); int index = (unhandledPageInfo.first_unhandled_page_index + unhandledPageInfo.unhandled_page_count) % MAX_UNHANDLED_PAGE; UnhandledPage& unhandled_page = unhandledPageInfo.unhandled_pages[index]; if (omr_result->identified){ for (int i = 0; i < omr_result->qr_result.size(); i++) { stmt2.reset(); stmt2.bind(":page_id", page_id); stmt2.bind(":type", RT_CODE); stmt2.bind(":answer", omr_result->qr_result[i].qr_str.c_str()); stmt2.bind(":score", 0); stmt2.bind(":score_paper", 0); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } if (pUnhandledPageInfo->bOnlineCard){ /*******************************保存缺考标记**************************************************/ if (!bInsertQuekaobiao){ stmt2.reset(); stmt2.bind(":page_id", page_id); stmt2.bind(":type", RT_QUEKAOBIAOJI); stmt2.bind(":answer", omr_result->quekaoFlag ? "1" : "0"); stmt2.bind(":score", 0); stmt2.bind(":score_paper", 0); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); bInsertQuekaobiao = true; } /*******************************保存客观题**************************************************/ for (int i = 0; i < omr_result->group_result.size(); i++) { float score = scoreCounter.GetScore(omr_result->group_result[i].question_code, omr_result->group_result[i].answer, 0, 0); total_score += score; stmt2.reset(); stmt2.bind(":page_id", page_id); if (omr_result->group_result[i].omr_question_type == identify::DANXUANTI){ stmt2.bind(":type", RT_KEGUANTI); } else{ stmt2.bind(":type", RT_KEGUANTI_EX); } q_std answer_std = scoreCounter.get_std(omr_result->group_result[i].question_code); // 取出标准答案题 if (kegunti_orgin_count > 0 && kegunti_orgin_count == kegunti_empty_count || (answer_std.question_type == DANXUANTI && omr_result->group_result[i].answer == answer_std.answer_all)) { if (!(exceptions & EX_KEGUANTIYICHANG) && g_my_scan_type != 1 && g_my_scan_type != 2) { exceptions |= EX_KEGUANTIYICHANG; } } stmt2.bind(":answer", omr_result->group_result[i].answer.c_str()); stmt2.bind(":score", score); stmt2.bind(":question_code", omr_result->group_result[i].question_code.c_str()); stmt2.bind(":score_paper", score); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } } else{ /*******************************保存缺考标记**************************************************/ const std::vector& quekaoHandleInfo = m_handInfoMap[omr_result->card_index].quekaoHandleInfo; for (int i = 0; i < quekaoHandleInfo.size(); i++) { stmt2.reset(); stmt2.bind(":page_id", page_id); stmt2.bind(":type", RT_QUEKAOBIAOJI); stmt2.bind(":answer", omr_result->group_result[quekaoHandleInfo[i].group_index[0]].answer.c_str()); stmt2.bind(":score", 0); stmt2.bind(":score_paper", 0); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } /*******************************保存AB卷标记**************************************************/ const std::vector& abjuanHandleInfo = m_handInfoMap[omr_result->card_index].abjuanHandleInfo; for (int i = 0; i < abjuanHandleInfo.size(); i++) { stmt2.reset(); stmt2.bind(":page_id", page_id); stmt2.bind(":type", RT_ABJUANBIAOJI); stmt2.bind(":answer", omr_result->group_result[abjuanHandleInfo[i].group_index[0]].answer.c_str()); stmt2.bind(":score", 0); stmt2.bind(":score_paper", 0); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } /*******************************保存填涂考号**************************************************/ const std::vector& tiantukaohaoHandleInfo = m_handInfoMap[omr_result->card_index].tiantukaohaoHandleInfo; for (int i = 0; i < tiantukaohaoHandleInfo.size(); i++) { std::string kaohao; if (g_my_scan_type == 1) { kaohao = g_strShoolId; } for (int j = 0; j < tiantukaohaoHandleInfo[i].group_index.size(); j++) { kaohao += omr_result->group_result[tiantukaohaoHandleInfo[i].group_index[j]].answer; } stmt2.reset(); stmt2.bind(":page_id", page_id); stmt2.bind(":type", RT_TIANTUKAOHAO); stmt2.bind(":answer", kaohao.c_str()); stmt2.bind(":score", 0); stmt2.bind(":score_paper", 0); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } } /*******************************保存填空题**************************************************/ for (int i = 0; i < omr_result->tiankongti_result.size(); i++) { float score = 0.0; //std::string strscores = ""; if (strquestioncode == omr_result->tiankongti_result[i].question_code) { //相同题号,一定是小题号,不用再统计 continue; } if (!pUnhandledPageInfo->bOnlineCard || omr_result->tiankongti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::TIANKONGTI){ if (omr_result->tiankongti_result[i].maxscore > 0) { //strscores = std::to_string(omr_result->tiankongti_result[i].question_score); score += omr_result->tiankongti_result[i].question_score; strquestioncode = omr_result->tiankongti_result[i].question_code; bool bneedcountiefind = true; //同页对比 for (int j = i + 1; j < omr_result->tiankongti_result.size(); j++) { if (omr_result->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code) { //strscores += ","; //strscores += std::to_string(omr_result->tiankongti_result[j].question_score); score += omr_result->tiankongti_result[j].question_score; } else { bneedcountiefind = false; } } if (bneedcountiefind) { //跨页对比 bool bstopflag = false; for (int q = p + 1; q < paper_page_count; q++) { if (bstopflag) break; int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result; for (int j = 0; omr_result1->tiankongti_result.size(); j++) { if (omr_result1->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code) { //strscores += ","; //strscores += std::to_string(omr_result->tiankongti_result[j].question_score); score += omr_result1->tiankongti_result[j].question_score; } else { bstopflag = true; break; } } } } score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, score); } else { score = scoreCounter.GetScore(omr_result->tiankongti_result[i].question_code, "", omr_result->tiankongti_result[i].isright, 0); } } if (pUnhandledPageInfo->bOnlineCard && omr_result->tiankongti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::TIANKONGTI2){ if (omr_result->tiankongti_result[i].maxscore > 0) { //strscores = std::to_string(omr_result->tiankongti_result[i].question_score); score += omr_result->tiankongti_result[i].question_score; strquestioncode = omr_result->tiankongti_result[i].question_code; bool bneedcountiefind = true; //同页对比 for (int j = i + 1; jtiankongti_result.size(); j++) { if (omr_result->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code) { //strscores += ","; //strscores += std::to_string(omr_result->tiankongti_result[i].question_score); score += omr_result->tiankongti_result[j].question_score; } else { bneedcountiefind = false; } } if (bneedcountiefind) { //跨页对比 bool bstopflag = false; for (int q = p + 1; q < paper_page_count; q++) { if (bstopflag) break; int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result; for (int j = 0; j < omr_result1->tiankongti_result.size(); j++) { if (omr_result1->tiankongti_result[j].question_code == omr_result->tiankongti_result[i].question_code) { //strscores += ","; //strscores += std::to_string(omr_result->tiankongti_result[j].question_score); score += omr_result1->tiankongti_result[j].question_score; } else { bstopflag = true; break; } } } } score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, score); } else { score = scoreCounter.GetScore_TianKongTi2(omr_result->tiankongti_result[i].question_code, omr_result->tiankongti_result[i].question_score); } } total_score += score; stmt2.reset(); stmt2.bind(":page_id", page_id); stmt2.bind(":type", RT_TIANKONGTI); stmt2.bind(":answer", ""); stmt2.bind(":score", score); stmt2.bind(":isright", omr_result->tiankongti_result[i].isright); stmt2.bind(":question_code", omr_result->tiankongti_result[i].question_code.c_str()); stmt2.bind(":score_paper", score); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } int loupi_count = 0; int wufashibie_count = 0; int wupan_count = 0; /*******************************保存主观题**************************************************/ for (int i = 0; izhutuanti_result.size(); i++) { if (strquestioncode == omr_result->zhutuanti_result[i].question_code) { //相同题号,一定是小题号,不用再统计 continue; } float score = 0; if (omr_result->zhutuanti_result[i].maxscore > 0) { score += omr_result->zhutuanti_result[i].question_score; strquestioncode = omr_result->zhutuanti_result[i].question_code; bool bneedcountiefind = true; //同页对比 for (int j = i + 1; jzhutuanti_result.size(); j++) { if (omr_result->zhutuanti_result[j].question_code == omr_result->zhutuanti_result[i].question_code) { //strscores += ","; //strscores += std::to_string(omr_result->tiankongti_result[i].question_score); score += omr_result->zhutuanti_result[j].question_score; } else { bneedcountiefind = false; } } if (bneedcountiefind) { //跨页对比 bool bstopflag = false; for (int q = p + 1; q < paper_page_count; q++) { if (bstopflag) break; int index1 = (unhandledPageInfo.first_unhandled_page_index + q) % MAX_UNHANDLED_PAGE; OMR_RESULT * omr_result1 = unhandledPageInfo.unhandled_pages[index1].omr_result; for (int j = 0; j < omr_result1->zhutuanti_result.size(); j++) { if (omr_result1->zhutuanti_result[j].question_code == omr_result->zhutuanti_result[i].question_code) { //strscores += ","; //strscores += std::to_string(omr_result->tiankongti_result[j].question_score); score += omr_result1->zhutuanti_result[j].question_score; } else { bstopflag = true; break; } } } } score = scoreCounter.GetScore(omr_result->zhutuanti_result[i].question_code, "", 0, score); } else { score = scoreCounter.GetScore(omr_result->zhutuanti_result[i].question_code, "", 0, omr_result->zhutuanti_result[i].question_score); } total_score += score; stmt2.reset(); if (pUnhandledPageInfo->bOnlineCard && omr_result->zhutuanti_result[i].omr_question_type == identify::OMR_QUESTION_TYPE::XUANZUOTI){ std::string strTotal = std::to_string(omr_result->zhutuanti_result[i].total), strRequired = std::to_string(omr_result->zhutuanti_result[i].required), strAllQuestions = omr_result->zhutuanti_result[i].question_code_all, strXuanz = std::to_string(omr_result->zhutuanti_result[i].xuanze); std::string real_name; auto it_find = _map_real_name.find(omr_result->zhutuanti_result[i].question_code); if (it_find != _map_real_name.end()){ real_name = it_find->second; } std::string str_tmp = strAllQuestions + "@" + strXuanz + "@" + strTotal + "@" + strRequired + "@" + real_name; stmt2.bind(":answer", str_tmp.c_str()); stmt2.bind(":type", RT_XUANZUOTI); } else{ stmt2.bind(":answer", ""); stmt2.bind(":type", scoreCounter.get_std(omr_result->zhutuanti_result[i].question_code).question_type == schema::BIZUOTI ? RT_BIZUOTI : RT_ZHUGUANTI); } stmt2.bind(":page_id", page_id); stmt2.bind(":score", score); stmt2.bind(":question_code", omr_result->zhutuanti_result[i].question_code.c_str()); stmt2.bind(":score_paper", omr_result->zhutuanti_result[i].question_score); QUESTION_STATE question_state = QUESTION_STATE_NORMAL; if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_LOUPI){ loupi_count++; question_state = QUESTION_STATE_LOUPI; } if (omr_result->zhutuanti_result[i].question_state == OMR_QUESTION_STATE_WUFASHIBIE){ wufashibie_count++; question_state = QUESTION_STATE_WUFASHIBIE; } 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; } stmt2.bind(":question_state", question_state); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } /*******************************保存选做题**************************************************/ if (!pUnhandledPageInfo->bOnlineCard){ const std::vector& xuanzuotiHandleInfo = m_handInfoMap[omr_result->card_index].xuanzuotiHandleInfo; for (int i = 0; i < xuanzuotiHandleInfo.size(); i++) { for (int index_group = 0; index_group < xuanzuotiHandleInfo[i].group_index.size(); index_group++) { const char * answer = omr_result->group_result[xuanzuotiHandleInfo[i].group_index[index_group]].answer.c_str(); //if (omr_result->group_result[xuanzuotiHandleInfo[i].group_index[index_group]].answer == "") // answer = omr_result->cut_area_result[omr_result->cut_area_result.size() - index_group - 1].area_name.c_str(); const std::vector& mark_units = xuanzuotiHandleInfo[i].mark_unit[index_group]; const std::vector>& option_question_code = xuanzuotiHandleInfo[i].option_question_code[index_group]; int xuantishu = xuanzuotiHandleInfo[i].xuantishu[index_group]; const std::vector& mark_unit_question_codes = xuanzuotiHandleInfo[i].mark_unit_question_code[index_group]; vector answers; split(answer, ",", &answers); int selected_count = 0; vector option_selected(option_question_code.size(), false); vector option_selected_valid(option_question_code.size(), false); int selected_option_count = 0; for (int idx_o = 0; idx_o < option_question_code.size(); idx_o++) { bool found = false; for (int idx_o_q = 0; !found&&idx_o_q < option_question_code[idx_o].size(); idx_o_q++) { for (int idx_a = 0; !found&&idx_a < answers.size(); idx_a++) { if (option_question_code[idx_o][idx_o_q] == answers[idx_a]){ found = true; } } } if (found){ option_selected[idx_o] = true; selected_option_count++; } } bool bIsEmpty = true; for (int j = 0; j < option_selected.size(); j++) { if (option_selected[j] == true) bIsEmpty = false; } if (bIsEmpty) option_selected[0] = true; for (int idx_o = 0, s_count = 0; s_count < xuantishu&&idx_o < option_selected.size(); idx_o++) { if (!option_selected[idx_o])continue; option_selected_valid[idx_o] = true; s_count++; for (int idx_o_q = 0; idx_o_q < option_question_code[idx_o].size(); idx_o_q++) { question_selected[option_question_code[idx_o][idx_o_q]] = true; } } for (int index_markunit = 0; index_markunit < mark_units.size(); index_markunit++) { vector markunit_questioncode; split(mark_unit_question_codes[index_markunit], ",", &markunit_questioncode); std::string question_code_selected; for (int index2 = 0; index2 < markunit_questioncode.size(); index2++) { for (int index_option = 0; index_option < option_question_code.size(); index_option++) { if (!option_selected_valid[index_option])continue; const std::vector& option_question = option_question_code[index_option]; for (int index_option_q = 0; index_option_q < option_question.size(); index_option_q++) { if (option_question[index_option_q] == markunit_questioncode[index2]){ if (question_code_selected.length() > 0){ question_code_selected.append(","); } question_code_selected.append(option_question[index_option_q]); break; } } } } stmt2.reset(); stmt2.bind(":page_id", page_id); stmt2.bind(":type", RT_XUANZUOTI); stmt2.bind(":answer", question_code_selected.c_str()); stmt2.bind(":score", 0); stmt2.bind(":question_code", mark_units[index_markunit].c_str()); stmt2.bind(":score_paper", 0); stmt2.bind(":question_state", QUESTION_STATE_NORMAL); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } } } } } else{ stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":page_id", page_id); stmt3.bind(":exception_type", SHIFT_DINGWEIDIAN); stmt3.bind(":exception_name", "定位点异常"); stmt3.execDML(); exceptions |= EX_DINGWEIDIAN; } } if (!pUnhandledPageInfo->bOnlineCard) { for (int p = 0; pidentified) { /*******************************保存客观题**************************************************/ int loutu_count = 0; const std::vector& keguantiHandleInfo = m_handInfoMap[omr_result->card_index].keguantiHandleInfo; for (int m = 0; m & group_index = keguantiHandleInfo[m].group_index; const std::vector & group_question_count = keguantiHandleInfo[m].group_question_count; const std::vector & question_code = keguantiHandleInfo[m].question_code; for (int idx_g = 0, idx_q = 0; idx_ggroup_result[i].answer, 0, 0); bool isSelected = false; bool isLoutu = false; if (strcmp("*", omr_result->group_result[i].answer.c_str()) == 0){ loutu_count++; isLoutu = true; } if (question_selected.find(question_code[idx_q]) == question_selected.end() || question_selected[question_code[idx_q]]){//不是选做题或者是选中的选做题 加入到总分 total_score += score; isSelected = true; } q_std answer_std = scoreCounter.get_std(question_code[idx_q]); // 取出标准答案题 if (kegunti_orgin_count > 0 && kegunti_orgin_count == kegunti_empty_count || (answer_std.question_type == DANXUANTI && omr_result->group_result[i].answer == answer_std.answer_all)) { if (!(exceptions & EX_KEGUANTIYICHANG) && g_my_scan_type != 1 && g_my_scan_type != 2) { exceptions |= EX_KEGUANTIYICHANG; } } stmt2.bind(":page_id", page_ids[p]); if (answer_std.question_type == DANXUANTI) stmt2.bind(":type", RT_KEGUANTI); else stmt2.bind(":type", RT_KEGUANTI_EX); stmt2.bind(":answer", omr_result->group_result[i].answer.c_str()); stmt2.bind(":score", score); stmt2.bind(":question_code", question_code[idx_q].c_str()); stmt2.bind(":score_paper", score); int question_state = isSelected ? (isLoutu ? QUESTION_STATE_LOUTU : QUESTION_STATE_NORMAL) : (isLoutu ? QUESTION_STATE_UNSELECT_LOUTU : QUESTION_STATE_UNSELECT); stmt2.bind(":question_state", question_state); stmt2.bind(":student_paper_id", student_paper_id); stmt2.execDML(); } /* int reuslt_id=bantch_db->execScalar("select last_insert_rowId() from result"); for(int k=0;k0){//商讨决定不再抛出该异常 stmt3.bind(":student_paper_id", student_paper_id); stmt3.bind(":page_id", page_ids[p]); stmt3.bind(":exception_type", SHIFT_LOUTU); stmt3.bind(":exception_name", "考生漏涂"); stmt3.execDML(); } } } } 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)"); stmt4.bind(":student_paper_id", student_paper_id); stmt4.bind(":message_type", isupdate ? WM_IDENTIFOR_PAPER_STATE_CHAGED : WM_IDENTIFOR_REPORT); stmt4.bind(":identified", identified); stmt4.bind(":class_id", class_id); stmt4.bind(":class_total", class_total); stmt4.bind(":class_info", class_info); stmt4.bind(":exceptions", exceptions); stmt4.bind(":score", total_score); stmt4.bind(":student_id", student_id.c_str()); stmt4.bind(":student_name", student_name); stmt4.bind(":examnumber", studentcode.c_str()); stmt4.execDML(); char sql3[512]; sprintf_s(sql3, "update student_paper set paper_state = %d,score_total= %f where student_paper_id = %d", exceptions, total_score, student_paper_id); bantch_db->execDML(sql3); bantch_db->execDML("commit transaction"); LeaveCriticalSection(db_lock); } catch (...){ bantch_db->execDML("rollback transaction"); LeaveCriticalSection(db_lock); OutputDebugString(_T("IResultHandler.SavePaper.catch CppSQLite3Exception")); } IDENTIFY_MSG * msg = new IDENTIFY_MSG; msg->class_id = class_id; msg->class_total = class_total; strcpy(msg->class_info, class_info); msg->exceptions = exceptions; msg->identified = identified; msg->paper_id = student_paper_id; msg->score = total_score; msg->student_id = -1;// student_id; msg->locationID = g_myindex; strcpy(msg->student_name, student_name); strcpy(msg->examnumber, studentcode.c_str()); if (m_hwnd != NULL) { if (isupdate) { if (m_bUseQr){ if (((exceptions & EX_KAOHAODAIPIPEI) == 0)) ::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)student_paper_id); if (!pUnhandledPageInfo->bOnlineCard){ } } } else { //printf("WM_IDENTIFOR_REPORT:%d\n",msg->paper_id); ::PostMessage(m_hwnd, WM_IDENTIFOR_REPORT, (WPARAM)msg, NULL); } } for (int m = 0; m < paper_page_count; m++) { int page_index = (unhandledPageInfo.first_unhandled_page_index + m) % MAX_UNHANDLED_PAGE; if (pUnhandledPageInfo->bOnlineCard){ static_cast(m_identifor)->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result); } else{ unhandledPageInfo.result->FreeResult(unhandledPageInfo.unhandled_pages[page_index].omr_result); } } unhandledPageInfo.first_unhandled_page_index = (unhandledPageInfo.first_unhandled_page_index + paper_page_count) % MAX_UNHANDLED_PAGE; unhandledPageInfo.unhandled_page_count -= paper_page_count; } void CResultHandler::SaveImages(vector &area_results, CMemZipFile &zip, int subjectID, BOOL bOnlineCard, char *strPaperCode, const std::vector &postMarkTypeIDVec, std::map &vecTwoPic) { CString question_code; question_code.Format(_T("%s.jpg"), CString(area_results[0]->area_name.c_str())); zip.PutNextEntry(question_code); std::sort(area_results.begin(), area_results.end(), sort_subindex); //postMarkTypeID == 10 判断 BOOL flag = false; for (int i = 0; i < postMarkTypeIDVec.size(); i++) { for (int j = 0; j < area_results.size(); j++){ if (postMarkTypeIDVec[i] == area_results[j]->area_name) { flag = true; break; } } } vector compression_params_low; compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_low.push_back(40); vector compression_params_high; compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_high.push_back(60); int width = 0; int height = 0; int centerx = 0, centery = 0; for (int jj = 0; jjwidth>width)width = area_results[jj]->width; height += area_results[jj]->height; centerx = area_results[jj]->centerx; centery += area_results[jj]->centery; } IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); cvSet(img, cvScalarAll(255)); for (int ii = 0, top = 0; ii < area_results.size(); ii++) { Mat ff = Mat(1, area_results[ii]->img_data.size(), CV_8U, area_results[ii]->img_data.data()); Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE); cvSetImageROI(img, cvRect(0, top, temp_img.cols, temp_img.rows)); cvCopy(&IplImage(temp_img), img); top += area_results[ii]->height; } cvResetImageROI(img); vector dst; cv::Mat _img = cv::cvarrToMat(img); if (img->height > 500){ imencode(".jpg", _img, dst, compression_params_low); } else{ imencode(".jpg", _img, dst, compression_params_high); } char sz_question_code[520] = { 0 }; WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL); cvReleaseImage(&img); zip.Write(&dst[0], dst.size()); if (flag && area_results.size() >1){ for (int jj = 0; jj < area_results.size(); jj++) { question_code.Format(_T("%s_%d.jpg"), CString(area_results[0]->area_name.c_str()), jj + 1); zip.PutNextEntry(question_code); width = area_results[jj]->width; height = area_results[jj]->height; IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); cvSet(img, cvScalarAll(255)); //for (int ii = 0, top = 0; ii < area_results.size(); ii++) //{ Mat ff = Mat(1, area_results[jj]->img_data.size(), CV_8U, area_results[jj]->img_data.data()); Mat temp_img = imdecode(ff, CV_LOAD_IMAGE_GRAYSCALE); cvSetImageROI(img, cvRect(0, 0, temp_img.cols, temp_img.rows)); cvCopy(&IplImage(temp_img), img); //top += area_results[ii]->height; //} cvResetImageROI(img); char sz_question_code[520] = { 0 }; WideCharToMultiByte(CP_ACP, 0, question_code, -1, sz_question_code, 520, NULL, NULL); vector dst; cv::Mat _img = cv::cvarrToMat(img); if (img->height > 500){ imencode(".jpg", _img, dst, compression_params_low); } else{ imencode(".jpg", _img, dst, compression_params_high); } cvReleaseImage(&img); zip.Write(&dst[0], dst.size()); } vecTwoPic[area_results[0]->area_name.c_str()] = area_results.size(); } } void CResultHandler::setHandlInfo(const boost::shared_ptr& handInfo) { m_handInfo = handInfo; std::map handInfoMap; for (int i = 0; isize(); i++) { const PAGE_RESULT_HANDLE_INFO & p = (*m_handInfo)[i]; std::map::value_type v(p.page_index, p); handInfoMap.insert(v); } m_handInfoMap = handInfoMap; } bool CResultHandler::existAbsentFlag(OMR_RESULT * omr_result) { const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index]; return handleInfo.quekaoHandleInfo.size()>0; } std::string CResultHandler::absentFlag(OMR_RESULT * omr_result) { const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index]; const std::vector& quekaoHandleInfo = handleInfo.quekaoHandleInfo; if (quekaoHandleInfo.size()>0)return omr_result->group_result[quekaoHandleInfo[0].group_index[0]].answer; return ""; } bool CResultHandler::existABJuanFlag(OMR_RESULT * omr_result) { const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index]; return handleInfo.abjuanHandleInfo.size()>0; } bool CResultHandler::existABJuanFlag() { for (int i = 0; isize(); i++) { if ((*m_handInfo)[i].abjuanHandleInfo.size()>0)return true; } return false; } std::string CResultHandler::ABJuanFlag(OMR_RESULT * omr_result) { const PAGE_RESULT_HANDLE_INFO& handleInfo = m_handInfoMap[omr_result->card_index]; const std::vector& abjuanHandleInfo = handleInfo.abjuanHandleInfo; if (abjuanHandleInfo.size()>0)return omr_result->group_result[abjuanHandleInfo[0].group_index[0]].answer; return ""; } void CResultHandler::IdentifyTaskManager(CIdentifyTaskManager* taskManager) { this->taskManager = taskManager; } BOOL CResultHandler::SupportPause(void) { return TRUE; } ServiceState CResultHandler::OnPausing(void) { return IService::OnPausing(); } void CResultHandler::SetIdentifyService(CIdentifyService* service) { identifyService = service; } bool CResultHandler::readPaperId(CString& strPaperId) { TCHAR exeFullPath[MAX_PATH]; CString strPath; GetModuleFileName(NULL, exeFullPath, MAX_PATH); strPath = (CString)exeFullPath; int position = strPath.ReverseFind('\\'); strPath = strPath.Left(position + 1); TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("paperInfo.ini")); WCHAR PaperId[512]; GetPrivateProfileString(_T("paperinfo"), _T("paper_str"), _T(""), PaperId, 512, FilePath); strPaperId = PaperId; return false; } void CResultHandler::readOnlineCardPaperId(string strPaperCode, string strStudentId) { wstring strCode = AnsiToUnicode(strPaperCode); wstring strKey = AnsiToUnicode(strStudentId); TCHAR exeFullPath[MAX_PATH]; CString strPath; GetModuleFileName(NULL, exeFullPath, MAX_PATH); strPath = (CString)exeFullPath; int position = strPath.ReverseFind('\\'); strPath = strPath.Left(position + 1); TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("magic\\")); lstrcat(FilePath, strCode.c_str()); lstrcat(FilePath, _T("magic.ini")); WCHAR PaperId[512]; GetPrivateProfileString(_T("paperinfo"), strKey.c_str(), _T(""), PaperId, 512, FilePath); m_strOnlineCardPaperId = UnicodeToAnsi(PaperId); } void CResultHandler::WriteOnlineCardPaperId(CString strPaperCode, wstring& strSubGroupId, wstring strStudentId) { TCHAR exeFullPath[MAX_PATH]; CString strPath; GetModuleFileName(NULL, exeFullPath, MAX_PATH); strPath = (CString)exeFullPath; int position = strPath.ReverseFind('\\'); strPath = strPath.Left(position + 1); TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("magic\\")); lstrcat(FilePath, strPaperCode); lstrcat(FilePath, _T("magic.ini")); WritePrivateProfileString(_T("paperinfo"), strStudentId.c_str(), strSubGroupId.c_str(), FilePath); } bool CResultHandler::readTimu(CString& strTimu) { TCHAR exeFullPath[MAX_PATH]; CString strPath; GetModuleFileName(NULL, exeFullPath, MAX_PATH); strPath = (CString)exeFullPath; int position = strPath.ReverseFind('\\'); strPath = strPath.Left(position + 1); TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("paperInfo.ini")); WCHAR Timu[512]; GetPrivateProfileString(_T("paperinfo"), _T("timu_info"), _T(""), Timu, 512, FilePath); strTimu = Timu; return false; } bool CResultHandler::loadSchema() { CString strFileName; if (g_my_scan_type == 0) { TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; strFileName = FilePath; strFileName += _T("\\1111.zip"); } //else else if (g_my_scan_type == 1) { TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; TCHAR FileName[50]; _stprintf(FileName, _T("\\mode\\student%d.schema"), g_myindex); lstrcat(FilePath, FileName); strFileName = FilePath; } else if (g_my_scan_type == 2) { TCHAR cfgPath[MAX_PATH]; GetModuleFileName(NULL, cfgPath, MAX_PATH); (_tcsrchr(cfgPath, '\\'))[1] = 0; lstrcat(cfgPath, _T("config.ini")); TCHAR schoolID[64] = { 0 }; GetPrivateProfileString(_T("USER"), _T("schoolId"), _T(""), schoolID, sizeof(schoolID) / sizeof(TCHAR), cfgPath); TCHAR __version[64] = { 0 }; GetPrivateProfileString(_T("USER"), _T("tifenbaoversion"), _T(""), __version, sizeof(__version) / sizeof(TCHAR), cfgPath); CString version = __version; TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; CString strPath; if (CString(schoolID).GetLength() == 4){ if (version.IsEmpty()){ strPath += "/mode/tifenbaoZixuanka-9.3.0.schema"; } else{ strPath += "/mode/tifenbaoZixuanka-9.3.3.schema"; } } else{ if (version.IsEmpty()){ strPath += "/mode/tifenbaoZixuanka-8.3.0.schema"; } else{ strPath += "/mode/tifenbaoZixuanka-8.3.3.schema"; } } strFileName = CString(FilePath) + strPath; } CUnZipFile uzip(strFileName); std::map> map; while (uzip.HasMoreEntry()){ CString fileNam; uzip.GetNextEntry(fileNam); char buffer[1024 * 8]; int len; std::vector& data = map[fileNam]; data.reserve(1024 * 128); while ((len = uzip.Read(buffer, 1024 * 8))>0){ if (data.capacity()>::iterator schemabytes = map.find(_T("schema.bytes")); if (schemabytes == map.end()){ return false; } SCHEMA_VERSION version; std::vector& data = schemabytes->second; serializor::SchemJsonSerializor::deserialize(std::string((char *)data.data(), data.size()), m_schema, version); if (m_schema.state == 0) return SCH_LOAD_ERR_ZHUANGTAIBUZHENGQUE; return true; } void CResultHandler::SavePathImg(std::string path, CMemZipFile &zip, int i){ IplImage* pImg = cvLoadImage(path.c_str(), 1); CString question_code; question_code.Format(_T("image_%d.jpg"), i + 1); zip.PutNextEntry(question_code); vector dst; vector compression_params_low; compression_params_low.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_low.push_back(40); vector compression_params_high; compression_params_high.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params_high.push_back(60); cv::Mat _img = cv::cvarrToMat(pImg); if (pImg->height > 500){ imencode(".jpg", _img, dst, compression_params_low); } else{ imencode(".jpg", _img, dst, compression_params_high); } cvReleaseImage(&pImg); zip.Write(&dst[0], dst.size()); } #include void ThreadLog4(char* strLogContent, char* fileName) { char buf[200]; _getcwd(buf, sizeof(buf)); strcat_s(buf, "\\ThirdParty\\"); strcat_s(buf, fileName); FILE *file = NULL; fopen_s(&file, buf, "at+"); if (file == NULL) { // printf("路径错误\n"); //system("pause"); return; } fseek(file, 0, SEEK_END); char strLogTemp[5000]; strcpy_s(strLogTemp, sizeof(strLogTemp), strLogContent); fwrite(&strLogTemp, strlen(strLogTemp), 1, file); fclose(file); } void CResultHandler::logForDbg(string strLog) { char logContent[300]; char logName[300]; char sYear[10], sMonth[5], sDay[25]; SYSTEMTIME st; GetLocalTime(&st); int j0 = 0; int m_nYear = st.wYear; ///年 int m_nMonth = st.wMonth; ///月 int m_nDay = st.wDay; ///日 int m_nHour = st.wHour; ///小时 int m_nMinute = st.wMinute; ///分钟 int m_nSecond = st.wSecond; ///秒 int m_nMillSecond = st.wMilliseconds; ///毫秒 char strTime[300]; sprintf(strTime, "----------------------------------%d_%02d_%02d_%d_%02d_%02d", m_nYear, m_nMonth, m_nDay, m_nHour, m_nMinute, m_nSecond); strLog += strTime; sprintf_s(sYear, sizeof(sYear), "%d", m_nYear); sprintf_s(sMonth, sizeof(sMonth), "_%02d", m_nMonth); sprintf_s(sDay, sizeof(sDay), "_%02d_log.txt", m_nDay); strcpy(logName, sYear); strcat(logName, sMonth); strcat(logName, sDay); char strScore[MAX_PATH] = { 0 }; for (int i = 0; i < strLog.size(); i++) strScore[i] = strLog.at(i); sprintf_s(logContent, sizeof(logContent), "%s\n", strScore); ThreadLog4(logContent, logName); } string CResultHandler::GetOnlineCardPaperId(string strPaperCode, string strStudentId) { //if (m_strOnlineCardPaperId.empty()) readOnlineCardPaperId(strPaperCode, strStudentId); return m_strOnlineCardPaperId; }