1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819 |
- #include "StdAfx.h"
- #include "scan_common.h"
- #include "ResultUploader.h"
- #include <afxinet.h>
- #include <fstream>
- #include "..\EvaluationUtil\MemFileInputFiled.h"
- #include "..\EvaluationUtil\HttpClient.h"
- #include "basic_struct.h"
- #include <codecvt>
- #include "..\ZLibWrapMemLib\MemZipFile.h"
- #include "ServerConfig.h"
- #include "..\ZLibWrapLib\ZLibWrapLib.h"
- #include "..\EvaluationUtil\IInputFiled.h"
- #include "..\EvaluationUtil\FileInputFiled.h"
- #include <direct.h>
- #include <time.h>
- #include "../lib/ucloud/include/api.h"
- #include "NetOperator.h"
- #include "rapidjson/document.h"
- #include "rapidjson/writer.h"
- #include "rapidjson/stringbuffer.h"
- extern bool g_isAllSubject ;//是否是全学科
- int HttpDownloadTemplate(std::string from, std::string fileName);
- void AddStringMember(rapidjson::Value&root, rapidjson::Document::AllocatorType& allocator, const char*key, const char*value)
- {
- rapidjson::Value _key(rapidjson::kStringType);
- rapidjson::Value string_value(rapidjson::kStringType);
- _key.SetString(key, allocator);
- string_value.SetString(value, allocator);
- root.AddMember(_key, string_value, allocator);
- };
- //type 0 INT 1 DOUBLE
- void AddNumberMember(rapidjson::Value&root, rapidjson::Document::AllocatorType& allocator, const char*key, int value, int type){
- rapidjson::Value _key(rapidjson::kStringType);
- rapidjson::Value num_value(rapidjson::kNumberType);
- _key.SetString(key, allocator);
- switch (type){
- case 0: num_value.SetInt(value); break; //int
- case 1: num_value.SetDouble(value); break;//double
- }
- root.AddMember(_key, num_value, allocator);
- };
- long helper_get_file_size(FILE *fp){
- long fsize;
- fseek(fp, 0, SEEK_END);
- fsize = ftell(fp);
- fseek(fp, 0, SEEK_SET);
- return fsize;
- }
- struct UploadMsg
- {
- string strMsg;
- int nTotal;
- };
- static std::string UnicodeToAnsi(const CString& str)
- {
- std::string ret;
- int nLen = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
- if (nLen == 0){
- return ret;
- }
- char* pResult = new char[nLen];
- WideCharToMultiByte(CP_ACP, 0, str, -1, pResult, nLen, NULL, NULL);
- ret = pResult;
- delete[] pResult;
- return ret;
- }
- extern int g_my_scan_type;
- extern std::string g_strUpLoadDbPathName;
- void ThreadLog3(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, "a+");
- if (file == NULL){
- return;
- }
- //fseek(file, 0, SEEK_END);
- //char strLogTemp[5000];
- //strcpy_s(strLogTemp, sizeof(strLogTemp), strLogContent);
- fwrite(strLogContent, strlen(strLogContent), 1, file);
- fclose(file);
- }
- static void DeleteDirectory(CString source)
- {
- //AfxMessageBox("创建文件夹"+target);
- CFileFind finder;
- CString path;
- path.Format(_T("%s/*.*"), source);
- BOOL bWorking = finder.FindFile(path);
- while (bWorking){
- bWorking = finder.FindNextFile();
- if (finder.IsDirectory() && !finder.IsDots()){ //是文件夹 而且 名称不含 . 或 ..
- DeleteDirectory(finder.GetFilePath()); //递归创建文件夹+"/"+finder.GetFileName()
- }
- else{ //是文件 则直接删除
- DeleteFile(finder.GetFilePath());
- }
- }
- RemoveDirectory(source);
- }
- void CopyAllFile(CString dest, CString source)
- {
- //AfxMessageBox("创建文件夹"+target);
- CFileFind finder;
- CString path;
- path.Format(_T("%s/*.*"), source);
- BOOL bWorking = finder.FindFile(path);
- while (bWorking){
- bWorking = finder.FindNextFile();
- if (finder.IsDirectory() && !finder.IsDots()){ //是文件夹 而且 名称不含 . 或 ..
- CString fTemp;
- fTemp = dest + finder.GetFileName() + _T("\\");
- CreateDirectory(fTemp,NULL);
- CopyAllFile(fTemp, finder.GetFilePath()); //递归创建文件夹+"/"+finder.GetFileName()
- }
- else{ //是文件 拷贝文件
- CopyFile(finder.GetFilePath(), dest + finder.GetFileName(),FALSE);
- }
- }
- RemoveDirectory(source);
- }
- #include <boost/uuid/uuid.hpp>
- #include <boost/uuid/uuid_io.hpp>
- #include <boost/uuid/uuid_generators.hpp>
- static CString GetExePath()
- {
- HMODULE module = GetModuleHandle(0);
- TCHAR pFileName[MAX_PATH + 2] = { 0 };
- GetModuleFileName(module, pFileName, MAX_PATH);
- CString csFullPath(pFileName);
- int nPos = csFullPath.ReverseFind(_T('\\'));
- if (nPos < 0)
- return CString("");
- else
- return csFullPath.Left(nPos);
- }
- std::string CResultUploader::get_ucloud_key(const std::string&eid)
- {
- char school_id[128] = { 0 };
- std::string path = UnicodeToAnsi(GetExePath() + _T("\\config.ini"));
- GetPrivateProfileStringA("USER", "schoolId", "", school_id, 128, path.c_str());
- boost::uuids::uuid a_uuid = boost::uuids::random_generator()();
- std::string uuid_string = boost::uuids::to_string(a_uuid);
- SYSTEMTIME tm;
- GetLocalTime(&tm);
- std::string date = std::to_string(tm.wYear) + "/" + std::to_string(tm.wMonth) + "/" + std::to_string(tm.wDay) + "/";
- std::string ret = std::string("kehuduan/backupservices/") + school_id + "/" + eid + "/" + date;
- ret += uuid_string + ".zip";
- return ret;
- }
- CResultUploader::CResultUploader(void)
- {
- m_bUploadOnScanModel = false;
- m_result_hadler = NULL;
- m_hwnd = NULL;
- m_nCourseId = readCourseId();
- m_bOnlineCard = false;
- m_bErrorHandle = false;
- m_nSubjectID = 0;
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- GetModuleFileName(NULL, exeFullPath, MAX_PATH);
- strPath = (CString)exeFullPath;
- int position = strPath.ReverseFind('\\');
- strPath = strPath.Left(position + 1);
- std::string str_path_tmp = UnicodeToAnsi(GetExePath() + _T("\\config.ini"));
- const char* FilePath = str_path_tmp.c_str();
- char szbucket_name[512];
- GetPrivateProfileStringA("GLOBAL", "bucket_name", "zxhx-test", szbucket_name, 512, FilePath);
- bucket_name = szbucket_name;
- ::InitializeCriticalSection(&m_csUploadOnScanPapers);
- }
- CResultUploader::~CResultUploader(void)
- {
- ::DeleteCriticalSection(&m_csUploadOnScanPapers);
- }
- ServiceState CResultUploader::OnStarting(void)
- {
- m_nCourseId = readCourseId();
- m_failtrue = FALSE;
- char sql[512] = { 0 };
- if (!m_bUploadOnScanModel){
- sprintf_s(sql, "update database set database_state =%d where database_id =%d", DATABASE_STATE_RESULT_UPLOADING, database_id);
- EnterCriticalSection(database_db_lock);
- database_db->execDML("begin transaction");
- database_db->execDML(sql);
- database_db->execDML("commit transaction");
- LeaveCriticalSection(database_db_lock);
- }
- if (m_strNewUploadUrl == "")
- {
- if (m_nCourseId == 3 || m_nCourseId == 6 || m_nCourseId == 51)
- url_str.Format(_T("%s/coachio/iointerface_v2/thirdUploadPaper"), CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
- else
- url_str.Format(_T("%s/coachio/iointerface_v2/quan_third_upload_paper"), CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
- }
- else
- {
- if (m_nCourseId == 3 || m_nCourseId == 6 || m_nCourseId == 51)
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/thirdUploadPaper"), m_strNewUploadUrl);
- }
- //url_str.Format(_T("%s/coachio/iointerface_v2/thirdUploadPaper"), m_strNewUploadUrl);
- else
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/quan_third_upload_paper"), m_strNewUploadUrl);
- }
- }
- sprintf_s(sql, "SELECT count(0) FROM student_paper pp LEFT JOIN student stu ON stu.student_id = pp.student_id LEFT JOIN exam em ON 1 = 1 WHERE (pp.ret_upload = 0 or pp.ret_upload = 3)");
- m_total = bantch_db->execScalar(sql);
- m_current_count = 0;
- m_sccuss_count = 0;
- last_student_paper_id = -1;
- if (!m_bUploadOnScanModel){
- upload_database_db.open(g_strUpLoadDbPathName.c_str());
- upload_database_db.execDML("pragma journal_mode = MEMORY");
- if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_RESULT_UPLOAD_STARTED, 0, 0);
- }
- return running;
- }
- void CResultUploader::getupLoadUrl(char *strUrl, int &nlen)
- {
- //http://zsyapi.testing.xueping.com/coachio/iointerface_v2/uploadstudentspapersrs
- if (m_bOnlineCard){
- //魔法词汇宝
- if (m_nOnlineScanType == 0)
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/magic_word_card_upload"), m_strNewUploadUrl);
- }
- else if (m_nSubjectID == 0)
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/uploadstudentspapersrs"), m_strNewUploadUrl);
- }
- else if (m_nSubjectID == 3 || m_nSubjectID == 6 || m_nSubjectID == 51)
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/thirdUploadPaper"), m_strNewUploadUrl);
- }
- else
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/quan_third_upload_paper"), m_strNewUploadUrl);
- }
- }
- else{
- if (g_my_scan_type == 1)
- {
- if (m_strNewUploadUrl == "")
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/upload_card_duxue"), CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
- }
- else
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/upload_card_duxue"), m_strNewUploadUrl);
- }
- }
- else if (g_my_scan_type == 2)
- {
- if (m_strNewUploadUrl == "")
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/UploadStudentProductConfig"), CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
- }
- else
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/UploadStudentProductConfig"), m_strNewUploadUrl);
- }
- }
- else
- {
- if (m_strNewUploadUrl == "")
- {
- if (m_nCourseId == 3 || m_nCourseId == 6 || m_nCourseId == 51)
- url_str.Format(_T("%s/coachio/iointerface_v2/thirdUploadPaper"), CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
- else
- url_str.Format(_T("%s/coachio/iointerface_v2/quan_third_upload_paper"), CServerConfig::server_address_type == SAT_LOCAL_IN ? CServerConfig::server_url_local_in : CServerConfig::server_address_type == SAT_LOCAL_OUT ? CServerConfig::server_url_local_out : CServerConfig::server_url);
- }
- else
- {
- if (m_nCourseId == 3 || m_nCourseId == 6 || m_nCourseId == 51)
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/thirdUploadPaper"), m_strNewUploadUrl);
- }
- //url_str.Format(_T("%s/coachio/iointerface_v2/thirdUploadPaper"), m_strNewUploadUrl);
- else
- {
- url_str.Format(_T("%s/coachio/iointerface_v2/quan_third_upload_paper"), m_strNewUploadUrl);
- }
- }
- }
- }
- int mylen = WideCharToMultiByte(CP_UTF8, 0, url_str, -1, strUrl, nlen, NULL, NULL);
- nlen = mylen;
- }
- ServiceState CResultUploader::OnRunning(void)
- {
- ServiceState nextState = IService::OnRunning();
- if (nextState != running) return nextState;
- //char sql1[1024] = { 0 };
- string strSql;
- if (m_bErrorHandle)
- {
- char sql1[1024] = { 0 };
- sprintf_s(sql1, "SELECT pp.student_paper_id,pp.task_id, pp.paper_code,pp.paper_state, pp.student_id, pp.student_code,pp.absent,pp.picFlag, stu.student_name, stu.class_id, em.exam_course_id, pp.score_total,pp.ori_img, em.exam_id, em.full_score,stu.school_id FROM student_paper pp LEFT JOIN student stu ON stu.student_id = pp.student_id LEFT JOIN exam em ON 1 = 1 WHERE pp.student_paper_id>%d AND (pp.ret_upload = 0 or pp.ret_upload = 3) AND pp.paper_state=0 AND pp.Is_Covered !=1 LIMIT 500", last_student_paper_id);
- strSql = sql1;
- }
- else{
- if (m_bUploadOnScanModel)
- {
- ::EnterCriticalSection(&m_csUploadOnScanPapers);
- if (!m_vctUploadOnScanPapers.empty()){
- std::string strPaperIds;
- for (auto it : m_vctUploadOnScanPapers){
- strPaperIds += std::to_string(it.first);
- strPaperIds += ",";
- }
- strPaperIds = std::string(strPaperIds, 0, strPaperIds.size() - 1);
- // 边扫描边上传 - 上传指定学生的试卷
- strSql = "SELECT pp.student_paper_id, pp.paper_code,pp.paper_state, pp.student_id, pp.student_code,pp.absent,pp.picFlag,\
- stu.student_name, stu.class_id, em.exam_course_id, pp.score_total,pp.ori_img, em.exam_id, \
- em.full_score,stu.school_id FROM student_paper pp LEFT JOIN student stu ON stu.student_id = pp.student_id LEFT JOIN \
- exam em ON 1 = 1 WHERE pp.student_paper_id in(";
- strSql.append(strPaperIds);
- strSql.append(") LIMIT 500");
- }
- else{
- ::LeaveCriticalSection(&m_csUploadOnScanPapers);
- return stoping;
- }
- ::LeaveCriticalSection(&m_csUploadOnScanPapers);
- }
- else
- {
- char sql1[1024] = { 0 };
- sprintf_s(sql1, "SELECT pp.student_paper_id, pp.paper_code,pp.paper_state, pp.student_id, pp.student_code,pp.absent,pp.picFlag, stu.student_name, stu.class_id, em.exam_course_id, pp.score_total,pp.ori_img, em.exam_id, em.full_score,stu.school_id FROM student_paper pp LEFT JOIN student stu ON stu.student_id = pp.student_id LEFT JOIN exam em ON 1 = 1 WHERE pp.student_paper_id>%d AND (pp.ret_upload = 0 or pp.ret_upload = 3) AND pp.Is_Covered !=1 LIMIT 500", last_student_paper_id);
- strSql = sql1;
- }
- }
- CppSQLite3Query q = bantch_db->execQuery(strSql.c_str());
- char sql1[1024] = { 0 };
- if (m_bOnlineCard){
- sprintf_s(sql1, "SELECT r.question_code, r.type, r.answer, r.score,r.question_state,r.isright, qs.score_full, s.school_id,qs.answer_std,qs.question_type,qs.basic_type_id FROM student_paper sp LEFT JOIN page p ON p.student_paper_id = sp.student_paper_id LEFT JOIN result r ON r.page_id = p.page_id LEFT JOIN question_std qs ON qs.question_code = r.question_code LEFT JOIN student s ON s.student_id = sp.student_id WHERE p.student_paper_id = :student_paper_id and qs.question_code is not null");
- }
- else{
- sprintf_s(sql1, "SELECT r.question_code, r.type, r.answer, r.score,r.question_state, qs.score_full, s.school_id,qs.answer_std,qs.question_type FROM student_paper sp LEFT JOIN page p ON p.student_paper_id = sp.student_paper_id LEFT JOIN result r ON r.page_id = p.page_id LEFT JOIN question_std qs ON qs.question_code = r.question_code LEFT JOIN student s ON s.student_id = sp.student_id WHERE p.student_paper_id = :student_paper_id and r.type in(%d,%d,%d) and qs.question_code is not null", RT_KEGUANTI, RT_KEGUANTI_EX, RT_ZHUGUANTI);
- }
- CppSQLite3Statement stmt2 = bantch_db->compileStatement(sql1);
- sprintf_s(sql1, "SELECT r.question_code, r.type, r.answer, r.score, s.school_id FROM student_paper sp LEFT JOIN page p ON p.student_paper_id = sp.student_paper_id LEFT JOIN result r ON r.page_id = p.page_id LEFT JOIN student s ON s.student_id = sp.student_id WHERE p.student_paper_id = :student_paper_id and r.type=%d", RT_XUANZUOTI);
- CppSQLite3Statement stmt3 = bantch_db->compileStatement(sql1);
-
- DWORD lastime =GetCurrentTime();
- CString timeString =GetTimeString();
- string strErrorInfo;
- strErrorInfo = "出错:\r\n";
- int nErrorCount = 0;
- int paperID = -1;
-
- CString moule_dir;
- CString tempUpLoadPath;
- CString tempUpLoadPathChild;
- CString imgPath;
- if (!m_bUploadOnScanModel){
- GetCurrentModuleDir(moule_dir);
- tempUpLoadPath = moule_dir + _T("\\testUpLoad\\");
- CreateDirectory(tempUpLoadPath, NULL);
- tempUpLoadPath += GetTimeString();
- CreateDirectory(tempUpLoadPath, NULL);
- tempUpLoadPathChild = tempUpLoadPath + _T("\\result");
- tempUpLoadPathChild += GetTimeString();
- imgPath = tempUpLoadPathChild + _T("\\img");
- }
- int rows = 0;
- char sql2[512];
- char sql3[512];
- char sz_file_name[520];
- char sz_ori_file_name[520] = {0};
- int temp[4] = { 0 };
- std::string json_str;
- std::string json_ori_str;
- std::string exception_json;
- std::string file_name;
- CppSQLite3Statement stmt4;
- int nRecordIndex = 0;//记录索引防止json重名
- if(!m_bUploadOnScanModel)
- stmt4 = upload_database_db.compileStatement("INSERT INTO student_paper ( student_paper_id, ret_upload, paper_code, student_code, student_id, file_name, json_name,student_name, ret_ori_upload , ori_img ,ori_json ,absent,service_type,exception_json,exc_upload,update_post_data) VALUES ( :student_paper_id, :ret_upload, :paper_code, :student_code, :student_id, :file_name, :json_name,:student_name,:ret_ori_upload ,:ori_img ,:ori_json ,:absent ,:service_type ,:exception_json ,:exc_upload, :update_post_data)");
- if (!q.eof()){
- int service_type = 0;
- 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"));
- service_type = GetPrivateProfileInt(_T("paperinfo"), _T("servicetype"), 0, FilePath);
- LOGI("开始上传成绩");
- std::vector<int> paperids;
- while (!q.eof())
- {
- nRecordIndex++;
- if (m_bUploadOnScanModel){
- GetCurrentModuleDir(moule_dir);
- tempUpLoadPath = moule_dir + _T("\\testUpLoad\\");
- CreateDirectory(tempUpLoadPath, NULL);
- tempUpLoadPath += GetTimeString();
- CreateDirectory(tempUpLoadPath, NULL);
- tempUpLoadPathChild = tempUpLoadPath + _T("\\result");
- tempUpLoadPathChild += GetTimeString();
- imgPath = tempUpLoadPathChild + _T("\\img");
- }
- else {
- stmt4.reset();
- }
- int paper_state = q.getIntField("paper_state");
- CString strStudentCode;
- if (m_bOnlineCard){
- Json::Value json;
- //魔法词汇宝增加json字段mw_id批次id
- if (m_nOnlineScanType != -1)
- {
- if (!m_pWeakResult.expired())
- {
- string strPaperCode = q.getStringField("paper_code");
- string strStudent= q.getStringField("student_id");
- boost::shared_ptr<CResultHandler> ptrResult = m_pWeakResult.lock(); //可以使用lock返回shared_ptr
- string strCardId = ptrResult->GetOnlineCardPaperId(strPaperCode, strStudent);
- //strCardId = "704606658002513920";
- json["mw_id"] = strCardId;
- }
- }
- if (m_nSubjectID == 0)
- {
- CString jsonPath;
- jsonPath.Format(L"%s\\%s%d_json.txt", tempUpLoadPathChild, GetTimeString(), nRecordIndex);
- //jsonPath = tempUpLoadPathChild + _T("\\") + GetTimeString() + _T("_json.txt");
- WideCharToMultiByte(CP_ACP, 0, jsonPath, -1, sz_file_name, 520, NULL, NULL);
- CMemFile file;
- CreateDirectory(tempUpLoadPathChild, NULL);
- CFile zip;
- zip.Open(jsonPath, CFile::modeCreate | CFile::modeWrite);
- Json::FastWriter writer;
- last_student_paper_id = q.getIntField("student_paper_id");
- paperids.push_back(q.getIntField("student_paper_id"));
- rows++;
- CString entryName;
- entryName.Format(_T("result%d.json"), rows);
-
- json["clazzId"] = q.getStringField("class_id");
- json["onlineCard"] = 1;
- json["paperId"] = 0;
- json["paperStr"] = q.getStringField("paper_code");
- json["studentId"] = q.getStringField("student_id");
- json["studentCode"] = q.getStringField("student_id");
-
- json["courseCode"] = "";
- json["totalScore"] = q.getStringField("score_total");;
- json["fullScore"] = q.getFloatField("full_score");
- json["studentPaperId"] = last_student_paper_id;
- json["quekaoFlag"] = q.getIntField("absent");
- paperID = q.getIntField("student_paper_id");
- Json::Value json_array(Json::arrayValue);
- Json::Value json_array2(Json::arrayValue);
- stmt2.reset();
- stmt2.bind(":student_paper_id", q.getIntField("student_paper_id"));
- auto fGetQuestionType = [](RESULT_TYPE nType)->int{
- switch (nType){
- case RT_KEGUANTI: return 1; break; // 单选题
- case RT_KEGUANTI_EX: return 2; break; // 多选题
- case RT_TIANKONGTI: return 5; break; // 填空题
- case RT_ZHUGUANTI: return 7; break; // 主观题
- case RT_XUANZUOTI: return 17; break; // 选做题
- case RT_BIZUOTI:return 27; break; // 必做题
- }
- return -1;
- };
- std::vector<std::string> _vctout;
- std::vector<std::string> _vctallitems;
- std::vector<std::pair<std::string, Json::Value>> sel_items;
- std::string stu_code = "";
- int questionNum = 0;
- if (!(q.getIntField("absent") == 1)){
- CppSQLite3Query q2 = stmt2.execQuery();
- while (!q2.eof()){
- RESULT_TYPE _type = (RESULT_TYPE)q2.getIntField("type");
- if (_type == 0 || _type == 1){
- q2.nextRow();
- continue;
- }
- int type_id = fGetQuestionType(_type);
- Json::Value item;
- item["fullScore"] = q2.getFloatField("score_full");
- item["handlerIndex"] = 1;
- item["paperId"] = "";
- item["questionNum"] = q2.getStringField("question_code");
- item["questionSerial"] = ++questionNum;
-
- item["questionTypeId"] = type_id;
- if (g_isAllSubject)
- {
- string basic_type_id = q2.getStringField("basic_type_id");
- item["basic_type_id"] = basic_type_id;
-
- if (basic_type_id == "12")//判断题
- {
- item["questionTypeId"] = "3";
- }
- }
- item["reportFlag"] = 1;
- item["rightFlag"] = q2.getIntField("isright");
- item["score"] = q2.getFloatField("score");
- stu_code = q.getStringField("student_id");
- item["studentCode"] = stu_code;
- std::string answer = q2.getStringField("answer");
- if (type_id == 17){
- _vctout.clear();
- split(answer, (std::string)"@", &_vctout);
- if (_vctout.size() == 5){
- item["answer"] = _vctout[1];
- if (_vctallitems.empty())
- split(_vctout[0], (std::string)",", &_vctallitems);
- }
- item["questionNum"] = _vctout[4];
- sel_items.push_back(std::make_pair(_vctout[4], item));
- }
- else{
- item["answer"] = answer;
- json_array.append(item);
- }
- q2.nextRow();
- }
- }
- for (std::size_t i = 0; i < _vctallitems.size(); ++i){
- auto itFind = std::find_if(sel_items.begin(), sel_items.end(), [i, &_vctallitems](std::pair<std::string, Json::Value>&it)->bool{
- return it.first == _vctallitems[i];
- });
- if (itFind != sel_items.end()){
- itFind->second["questionSerial"] = std::stoi(itFind->first);
- json_array.append(itFind->second);
- }
- else{
- double full = 0.0;
- std::string str_q_sql = "select * from question_std where question_code='";
- str_q_sql += _vctallitems[i] + "'";
- CppSQLite3Query q_full = bantch_db->execQuery(str_q_sql.c_str());
- while (!q_full.eof()){
- full = q_full.getFloatField("score_full");
- q_full.nextRow();
- }
- Json::Value item;
- item["fullScore"] = full;
- item["handlerIndex"] = 0;
- item["paperId"] = "";
- item["questionNum"] = _vctallitems[i];
- item["questionSerial"] = std::stoi(_vctallitems[i]);
- if (g_isAllSubject)
- {
- item["basic_type_id"] = q_full.getStringField("basic_type_id");
- }
- item["questionTypeId"] = 17;
- item["reportFlag"] = 1;
- item["rightFlag"] = 0;
- item["score"] = 0;
- item["answer"] = "";
- item["studentCode"] = stu_code;
- json_array.append(item);
- }
- }
- json["questionList"] = json_array;
- if (g_isAllSubject)
- {
- json["isAllSubject"] = 1;
- }
- else
- {
- json["isAllSubject"] = 0;
- }
- json_str = writer.write(json);
- 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);
- zip.Write((void*)utf8_string, utf8_string_len - 1);
- delete wide_string;
- delete utf8_string;
- zip.Close();
- Json::Value json1;
- json1["paperStr"] = q.getStringField("paper_code");
- json1["studentCode"] = q.getStringField("student_id");
- json_ori_str = writer.write(json1);
- }
- else
- {
- CString jsonPath;
- jsonPath.Format(L"%s\\%s%d_json.txt", tempUpLoadPathChild, GetTimeString(), nRecordIndex);
- //jsonPath = tempUpLoadPathChild + _T("\\") + GetTimeString() + _T("_json.txt");
- WideCharToMultiByte(CP_ACP, 0, jsonPath, -1, sz_file_name, 520, NULL, NULL);
- CMemFile file;
- //CMemZipFile zip;
- CreateDirectory(tempUpLoadPathChild, NULL);
- CFile zip;
- zip.Open(jsonPath, CFile::modeCreate | CFile::modeWrite);
- Json::FastWriter writer;
- last_student_paper_id = q.getIntField("student_paper_id");
- paperids.push_back(q.getIntField("student_paper_id"));
- rows++;
- CString entryName;
- entryName.Format(_T("result%d.json"), rows);
- //zip.PutNextEntry(entryName);
- //json["schoolId"] = (double)q.getInt64Field("school_id");
- //json["examCourseId"] = (double)q.getInt64Field("exam_course_id");
- json["onlineCard"] = 1;
- json["paperStr"] = q.getStringField("paper_code");
- //json["examId"] = (double)q.getInt64Field("exam_id");
- //json["examineeId"] = q.getStringField("student_id");
- //json["recexamineeCode"] = q.getStringField("student_code");
- json["studentCode"] = q.getStringField("student_id");
- Json::Value json1;
- json1["paperStr"] = q.getStringField("paper_code");
- json1["studentCode"] = q.getStringField("student_id");
- json_ori_str = writer.write(json1);
- json["picFlag"] = q.getStringField("picFlag");
- CString strStudentCode = CString(q.getStringField("student_id"));
- //json["missingFlag"] = q.getIntField("absent");//缺考标记 1缺考
- //json["abType"] = 1;//试卷类型 (1,A卷;2,B卷)
- //json["scanType"] = 1;//考生识别方式(填涂0,条码1,手写2)
- Json::Value json_array(Json::arrayValue);
- Json::Value json_array2(Json::arrayValue);
- Json::Value itemQuestionSelects;
- Json::Value json_array3QuestionSelects(Json::arrayValue);
- stmt2.reset();
- stmt2.bind(":student_paper_id", q.getIntField("student_paper_id"));
- paperID = q.getIntField("student_paper_id");
- auto fGetQuestionType = [](RESULT_TYPE nType)->int{
- switch (nType){
- case RT_KEGUANTI: return 1; break; // 单选题
- case RT_KEGUANTI_EX: return 2; break; // 多选题
- case RT_TIANKONGTI: return 5; break; // 填空题
- case RT_ZHUGUANTI: return 7; break; // 主观题
- case RT_XUANZUOTI: return 17; break; // 选做题
- case RT_BIZUOTI:return 27; break; // 必做题
- }
- return -1;
- };
- Json::Value json_array3(Json::arrayValue);
- std::vector<std::string> _vctout;
- std::vector<std::string> _vctallitems;
- std::vector<std::pair<std::string, Json::Value>> sel_items;
- std::string stu_code = "";
- if (!(q.getIntField("absent") == 1)){
- CppSQLite3Query q2 = stmt2.execQuery();
- int questionNum = 0;
- while (!q2.eof()){
- RESULT_TYPE _type = (RESULT_TYPE)q2.getIntField("type");
- if (_type == 0 || _type == 1){
- q2.nextRow();
- continue;
- }
- int type_id = fGetQuestionType(_type);
- Json::Value item;
- item["fullScore"] = q2.getFloatField("score_full");
- item["handlerIndex"] = 1;
- item["paperId"] = "";
- item["questionNum"] = q2.getStringField("question_code");
- item["questionSerial"] = ++questionNum;
- item["questionTypeId"] = type_id;
- if (g_isAllSubject)
- {
- item["basic_type_id"] = q2.getStringField("basic_type_id");
- if (q2.getStringField("basic_type_id") == "12")//判断题
- {
- item["questionTypeId"] = "3";
- }
- }
-
- item["reportFlag"] = 1;
- item["rightFlag"] = q2.getIntField("isright");
- item["score"] = q2.getFloatField("score");
- stu_code = q.getStringField("student_id");
- item["studentCode"] = stu_code;
- std::string answer = q2.getStringField("answer");
- if (type_id == 17){
- _vctout.clear();
- split(answer, (std::string)"@", &_vctout);
- if (_vctout.size() == 5){
- item["answer"] = _vctout[1];
- bool flagfind = false;
- for (std::size_t i = 0; i < _vctallitems.size(); ++i){
- if (_vctallitems[i] == _vctout[4])
- {
- flagfind = true;
- break;
- }
- }
- if (!flagfind)
- {
- if (_vctallitems.empty())
- {
- split(_vctout[0], (std::string)",", &_vctallitems);
- if (json_array3QuestionSelects.size() > 0)
- {
- itemQuestionSelects["qids"] = json_array3QuestionSelects;
- json_array2.append(itemQuestionSelects);
- }
- }
- else
- {
- std::vector<std::string> _vctallitemstemp;
- split(_vctout[0], (std::string)",", &_vctallitemstemp);
- if (_vctallitemstemp[0] != _vctallitems[0])
- {
- for (std::size_t i = 0; i < _vctallitems.size(); ++i){
- auto itFind = std::find_if(sel_items.begin(), sel_items.end(), [i, &_vctallitems](std::pair<std::string, Json::Value>&it)->bool{
- return it.first == _vctallitems[i];
- });
- if (itFind != sel_items.end()){
- itFind->second["questionSerial"] = std::stoi(itFind->first);
- json_array3.append(itFind->first);
- json_array.append(itFind->second);
- }
- else{
- double full = 0.0;
- std::string str_q_sql = "select * from question_std where question_code='";
- str_q_sql += _vctallitems[i] + "'";
- CppSQLite3Query q_full = bantch_db->execQuery(str_q_sql.c_str());
- while (!q_full.eof()){
- full = q_full.getFloatField("score_full");
- q_full.nextRow();
- }
- Json::Value item;
- item["fullScore"] = full;
- item["handlerIndex"] = 0;
- item["paperId"] = "";
- item["questionNum"] = _vctallitems[i];
- item["questionSerial"] = std::stoi(_vctallitems[i]);
- if (g_isAllSubject)
- {
- item["basic_type_id"] = q2.getStringField("basic_type_id");
- }
- item["questionTypeId"] = 17;
- item["reportFlag"] = 1;
- item["rightFlag"] = 0;
- item["score"] = 0;
- item["answer"] = "";
- item["stdAnswer"] = "";
- item["studentCode"] = stu_code;
- json_array.append(item);
- }
- }
- _vctallitems.clear();
- split(_vctout[0], (std::string)",", &_vctallitems);
- itemQuestionSelects["qids"] = json_array3QuestionSelects;
- json_array2.append(itemQuestionSelects);
- }
- }
- itemQuestionSelects.clear();
- json_array3QuestionSelects.clear();
- json_array3QuestionSelects.append(_vctout[4]);
- itemQuestionSelects["markUnit"] = questionNum;
- }
- else
- {
- json_array3QuestionSelects.append(_vctout[4]);
- }
- }
- item["questionNum"] = _vctout[4];
- item["stdAnswer"] = "";
- sel_items.push_back(std::make_pair(_vctout[4], item));
- }
- else if (type_id == 1 || type_id == 2)
- {
- item["stdAnswer"] = q2.getStringField("answer_std");
- item["answer"] = answer;
- json_array.append(item);
- }
- else if (type_id == 5 || type_id == 7)
- {
- item["stdAnswer"] = "";
- item["answer"] = answer;
- json_array.append(item);
- }
- q2.nextRow();
- //item["subExamCourseId"] = (double)q.getInt64Field("exam_course_id");
- }
- }
- //Json::Value json_array3(Json::arrayValue);
- for (std::size_t i = 0; i < _vctallitems.size(); ++i){
- auto itFind = std::find_if(sel_items.begin(), sel_items.end(), [i, &_vctallitems](std::pair<std::string, Json::Value>&it)->bool{
- return it.first == _vctallitems[i];
- });
- if (itFind != sel_items.end()){
- itFind->second["questionSerial"] = std::stoi(itFind->first);
- json_array3.append(itFind->first);
- json_array.append(itFind->second);
- }
- else{
- double full = 0.0;
- std::string str_q_sql = "select * from question_std where question_code='";
- str_q_sql += _vctallitems[i] + "'";
- CppSQLite3Query q_full = bantch_db->execQuery(str_q_sql.c_str());
- while (!q_full.eof()){
- full = q_full.getFloatField("score_full");
- q_full.nextRow();
- }
- Json::Value item;
- item["fullScore"] = full;
- item["handlerIndex"] = 0;
- item["paperId"] = "";
- item["questionNum"] = _vctallitems[i];
- item["questionSerial"] = std::stoi(_vctallitems[i]);
- if (g_isAllSubject)
- {
- item["basic_type_id"] = q_full.getStringField("basic_type_id");
- }
- item["questionTypeId"] = 17;
- item["reportFlag"] = 1;
- item["rightFlag"] = 0;
- item["score"] = 0;
- item["answer"] = "";
- item["stdAnswer"] = "";
- item["studentCode"] = stu_code;
- json_array.append(item);
- }
- }
- if (_vctallitems.size() > 0)
- {
- itemQuestionSelects["qids"] = json_array3QuestionSelects;
- json_array2.append(itemQuestionSelects);
- }
- json["questionList"] = json_array;
- if (g_isAllSubject)
- {
- json["isAllSubject"] = 1;
- }
- else
- {
- json["isAllSubject"] = 0;
- }
- json["questionSelects"] = json_array2;
- json_str = writer.write(json);
- 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);
- zip.Write((void*)utf8_string, utf8_string_len - 1);
- // LOG4CPLUS_INFO_FMT(pTestLogger, LOG4CPLUS_TEXT("%s"), CString(json_str.c_str()));
- delete wide_string;
- delete utf8_string;
- zip.Close();
- }
- }
- else{
- if (g_my_scan_type == 1)
- {
- Json::FastWriter writer;
- last_student_paper_id = q.getIntField("student_paper_id");
- paperids.push_back(q.getIntField("student_paper_id"));
- rows++;
- Json::Value json;
- Json::Value json1;
- json["paperStr"] = q.getStringField("paper_code");
- json["studentCode"] = q.getStringField("student_id");
- json1["paperStr"] = q.getStringField("paper_code");
- json1["studentCode"] = q.getStringField("student_id");
- json_ori_str = writer.write(json1);
- CString strStudentCode = CString(q.getStringField("student_id"));
- Json::Value json_array(Json::arrayValue);
- Json::Value json_array2(Json::arrayValue);
- stmt2.reset();
- stmt2.bind(":student_paper_id", q.getIntField("student_paper_id"));
- paperID = q.getIntField("student_paper_id");
- if (!(q.getIntField("absent") == 1)){
- CppSQLite3Query q2 = stmt2.execQuery();
- while (!q2.eof()){
- if (q2.getIntField("question_state")&QSF_UNSELECT){//没有选择的题目
- q2.nextRow();
- continue;
- }
- Json::Value item;
- std::string strtempcha = q2.getStringField("question_code");
- std::string codechar = q2.getStringField("answer");
- int number = 0;
- number = (codechar.length() == 0) ? 0 : (codechar.at(0) - 'A');
- {
- switch (strtempcha.at(0))
- {
- case '1':
- temp[0] = number;
- break;
- case '2':
- temp[1] = number;
- break;
- case '3':
- temp[2] = number;
- break;
- case '4':
- temp[3] = number;
- break;
- }
- }
- json_array.append(item);
- q2.nextRow();
- }
- }
- json["total"] = temp[0] * 10 + temp[1];
- json["correct"] = temp[2] * 10 + temp[3];
- //json["examineeScores"] = json_array;
- json_str = writer.write(json);
- //
- }
- else if (g_my_scan_type == 2)
- {
- Json::FastWriter writer;
- last_student_paper_id = q.getIntField("student_paper_id");
- paperids.push_back(q.getIntField("student_paper_id"));
- rows++;
- Json::Value json;
- CString strStudentCode = CString(q.getStringField("student_id"));
- Json::Value json_array(Json::arrayValue);
- Json::Value json_array2(Json::arrayValue);
- stmt2.reset();
- stmt2.bind(":student_paper_id", q.getIntField("student_paper_id"));
- paperID = q.getIntField("student_paper_id");
- if (!(q.getIntField("absent") == 1)){
- CppSQLite3Query q2 = stmt2.execQuery();
- while (!q2.eof()){
- if (q2.getIntField("question_state")&QSF_UNSELECT){//没有选择的题目
- q2.nextRow();
- continue;
- }
- else
- {
- Json::Value item;
- item["questionNum"] = q2.getStringField("question_code");
- item["answer"] = q2.getStringField("answer");
- json_array.append(item);
- q2.nextRow();
- }
- }
- }
- json_str = writer.write(json_array);
- }
- else
- {
- CString jsonPath;
- jsonPath.Format(L"%s\\%s%d_json.txt", tempUpLoadPathChild, GetTimeString(), nRecordIndex);
- //jsonPath = tempUpLoadPathChild + _T("\\") + GetTimeString() + _T("_json.txt");
- WideCharToMultiByte(CP_ACP, 0, jsonPath, -1, sz_file_name, 520, NULL, NULL);
- CMemFile file;
- //CMemZipFile zip;
- CreateDirectory(tempUpLoadPathChild, NULL);
- CFile zip;
- zip.Open(jsonPath, CFile::modeCreate | CFile::modeWrite);
- Json::FastWriter writer;
- last_student_paper_id = q.getIntField("student_paper_id");
- paperids.push_back(q.getIntField("student_paper_id"));
- rows++;
- CString entryName;
- entryName.Format(_T("result%d.json"), rows);
- //zip.PutNextEntry(entryName);
- Json::Value json;
- //json["schoolId"] = (double)q.getInt64Field("school_id");
- //json["examCourseId"] = (double)q.getInt64Field("exam_course_id");
- json["onlineCard"] = 0;
- json["paperStr"] = q.getStringField("paper_code");
- //json["examId"] = (double)q.getInt64Field("exam_id");
- //json["examineeId"] = q.getStringField("student_id");
- //json["recexamineeCode"] = q.getStringField("student_code");
- json["studentCode"] = q.getStringField("student_id");
- Json::Value json1;
- json1["paperStr"] = q.getStringField("paper_code");
- json1["studentCode"] = q.getStringField("student_id");
- json_ori_str = writer.write(json1);
- json["picFlag"] = q.getStringField("picFlag");
- CString strStudentCode = CString(q.getStringField("student_id"));
- //json["missingFlag"] = q.getIntField("absent");//缺考标记 1缺考
- //json["abType"] = 1;//试卷类型 (1,A卷;2,B卷)
- //json["scanType"] = 1;//考生识别方式(填涂0,条码1,手写2)
- Json::Value json_array(Json::arrayValue);
- Json::Value json_array2(Json::arrayValue);
- stmt2.reset();
- stmt2.bind(":student_paper_id", q.getIntField("student_paper_id"));
- paperID = q.getIntField("student_paper_id");
- if (!(q.getIntField("absent") == 1)){
- CppSQLite3Query q2 = stmt2.execQuery();
- while (!q2.eof()){
- if (q2.getIntField("question_state")&QSF_UNSELECT){//没有选择的题目
- q2.nextRow();
- continue;
- }
- Json::Value item;
- //item["subExamCourseId"] = (double)q.getInt64Field("exam_course_id");
- item["questionNum"] = q2.getStringField("question_code");
- item["stdAnswer"] = q2.getStringField("answer_std");
- //item["type"] = (q2.getIntField("question_type") & 0xff);
- item["score"] = q2.getFloatField("score");
- item["answer"] = q2.getStringField("answer");
- json_array.append(item);
- q2.nextRow();
- }
- }
- json["questionList"] = json_array;
- //json["examineeScores"] = json_array;
- stmt3.reset();
- stmt3.bind(":student_paper_id", q.getIntField("student_paper_id"));
- CppSQLite3Query q3 = stmt3.execQuery();
- while (!q3.eof()){
- Json::Value item;
- item["markUnit"] = atoi(q3.getStringField("question_code"));
- string answer = q3.getStringField("answer");
- Json::Value json_array3(Json::arrayValue);
- if (answer.length() > 0){
- vector<string> questions;
- split(answer, ",", &questions);
- for (int i = 0; i < questions.size(); i++){
- json_array3.append(questions[i]);
- }
- }
- item["qids"] = json_array3;
- json_array2.append(item);
- q3.nextRow();
- }
- json["questionSelects"] = json_array2;
- json_str = writer.write(json);
- 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);
- zip.Write((void*)utf8_string, utf8_string_len - 1);
- // LOG4CPLUS_INFO_FMT(pTestLogger, LOG4CPLUS_TEXT("%s"), CString(json_str.c_str()));
- delete wide_string;
- delete utf8_string;
- zip.Close();
- }
- }
- // 图片压缩包解压
- char mySql[512] = { 0 };
- CString zipPath;
- sprintf_s(mySql, "select file_name from student_paper where student_id = '%s' and student_paper_id = %d", q.getStringField("student_id"), paperID);
- CppSQLite3Query query = bantch_db->execQuery(mySql);
- if (query.eof())
- {
- if (nErrorCount > 0)
- {
- strErrorInfo += "\r\n";
- }
- strErrorInfo += q.getStringField("student_name");
- strErrorInfo += ":查找图片失败";
- nErrorCount++;
- if (m_hwnd != NULL&&GetCurrentTime() - lastime > 500) {
- lastime = GetCurrentTime();
- int total_bantch_count = (m_total + 499) / 500;
- int current_bantch = (m_current_count) / 500 + 1;
- int current_count = (m_current_count - 1) % 500 + 1;
- float progress = (int)(10000.0 / total_bantch_count)*(current_bantch - 1 + 0.5*current_count / min(500, m_total - (current_bantch - 1) * 500));
- ::PostMessage(m_hwnd, WM_IDENTIFOR_RESULT_UPLOAD_PROGRESS, progress, 0);
- }
- EnterCriticalSection(db_lock);
- bantch_db->execDML("begin transaction");
- char sql6[512];
- sprintf_s(sql6, "update student_paper set ret_upload = 3 where student_id = '%s'", q.getStringField("student_id"));
- bantch_db->execDML(sql6);
- bantch_db->execDML("commit transaction");
- LeaveCriticalSection(db_lock);
- m_current_count++;
- m_failtrue = TRUE;
- zipPath = "";
- }
- else
- {
- file_name = query.getStringField("file_name");
- zipPath = CString(query.getStringField("file_name"));
- if (PathFileExists(zipPath))
- {
- BOOL suc = ZipExtract(zipPath, imgPath);
- if (!suc){
- CreateDirectory(imgPath, NULL);
- }
- }
- }
- if (!m_bUploadOnScanModel){
- //导入上传库
- stmt4.reset();
- stmt4.bind(":student_paper_id", last_student_paper_id);
- stmt4.bind(":ret_upload", 0);
- stmt4.bind(":paper_code", q.getStringField("paper_code"));
- stmt4.bind(":student_code", q.getStringField("student_code"));
- stmt4.bind(":student_id", q.getStringField("student_id"));
- stmt4.bind(":file_name", query.getStringField("file_name"));
- stmt4.bind(":ret_ori_upload", 0);
- stmt4.bind(":ori_json", json_ori_str.c_str());
- if (g_my_scan_type == 1 || g_my_scan_type == 2)
- {
- stmt4.bind(":json_name", json_str.c_str());
- }
- else
- {
- stmt4.bind(":json_name", sz_file_name);
- }
- stmt4.bind(":student_name", q.getStringField("student_name"));
- stmt4.bind(":ori_img", q.getStringField("ori_img"));
- stmt4.bind(":absent", q.getIntField("absent"));
- stmt4.bind(":exc_upload", 0);
- stmt4.bind(":exception_json","normal");
- stmt4.bind(":update_post_data", "nodata");
- if (m_bErrorHandle){
- auto examid = (unsigned long long)q.getInt64Field("exam_id");
- std::string post_data = std::string("{ \"post_data\": \"examGroupId=") + std::to_string(examid) + "&taskIds=";
- post_data += std::string() + q.getStringField("task_id") + "\",\"url\":\"";
- 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"));
- service_type = GetPrivateProfileInt(_T("paperinfo"), _T("servicetype"), 0, FilePath);
- WCHAR url[512] = { 0 };
- GetPrivateProfileString(_T("paperinfo"), _T("errorhandleupdateurl"), _T(""), url, 512, FilePath);
- post_data += UnicodeToAnsi(url) + "\"}";
- stmt4.bind(":update_post_data", post_data.c_str());
- }
- }
- if ((paper_state&MEX_BUKESHANGCHUANG) != 0)
- {
- CString exceptionTmp = CServerConfig::app_data_dir + _T("\\exception_tmp\\");
- DeleteDirectory(exceptionTmp);
- CreateDirectory(exceptionTmp, NULL);
- Json::Value json;
- // 获取student_paper内容
- std::string student_paper_sql = "select * from student_paper where student_paper_id=";
- student_paper_sql += std::to_string(last_student_paper_id);
- CppSQLite3Query stu_paper_qry = bantch_db->execQuery(student_paper_sql.c_str());
- Json::Value json_stu_paper;
- if (!stu_paper_qry.eof()){
- json_stu_paper["picFlag"] = stu_paper_qry.getStringField("picFlag");
- json_stu_paper["location_id"] = stu_paper_qry.getIntField("location_id");
- json_stu_paper["paper_type"] = stu_paper_qry.getStringField("paper_type");
- json_stu_paper["absent"] = stu_paper_qry.getIntField("absent");
- json_stu_paper["score_total"] = stu_paper_qry.getFloatField("score_total");
- json_stu_paper["student_id"] = stu_paper_qry.getStringField("student_id");
- json_stu_paper["paper_state"] = stu_paper_qry.getIntField("paper_state");
- json_stu_paper["student_code"] = stu_paper_qry.getStringField("student_code");
- json_stu_paper["paper_code"] = stu_paper_qry.getStringField("paper_code");
- }
- // 获取student内容
- std::string stu_id = q.getStringField("student_id");
- Json::Value json_stu;
- if (!stu_id.empty() && stu_id != "-1"){
- std::string student_sql = "select * from student where student_id='";
- student_sql += stu_id + "'";
- CppSQLite3Query stu_qry = bantch_db->execQuery(student_sql.c_str());
- if (!stu_qry.eof()){
- json_stu["studentCard"] = stu_qry.getStringField("studentCard");
- json_stu["recoverFlag"] = stu_qry.getIntField("recoverFlag");
- json_stu["student_id"] = stu_qry.getStringField("student_id");
- json_stu["student_code"] = stu_qry.getStringField("student_code");
- json_stu["class_name"] = stu_qry.getStringField("class_name");
- json_stu["school_id"] = std::to_string(stu_qry.getIntField("school_id"));
- json_stu["grade_name"] = stu_qry.getStringField("grade_name");
- json_stu["student_name"] = stu_qry.getStringField("student_name");
- json_stu["class_id"] = std::to_string(stu_qry.getInt64Field("class_id"));
- json_stu["schoolStudentCard"] = stu_qry.getStringField("schoolStudentCard");
- json_stu["score_total"] = stu_qry.getFloatField("score_total");
- }
- }
- // 获取原卷 获取答卷
- Json::Value json_array_page(Json::arrayValue);
- std::string page_sql = "select img_oldpath,img_path ,identified,page_id from page where student_paper_id=";
- page_sql += std::to_string(last_student_paper_id);
- CppSQLite3Query page_qry = bantch_db->execQuery(page_sql.c_str());
- int i = 1;
- while (!page_qry.eof()){
- std::string name = std::to_string(i++) + ".jpg";
- std::string new_file_name = CServerConfig::app_data_dir_string + std::string("\\exception_tmp\\image_") + name;
- std::string path = page_qry.getStringField("img_path");
- int page_id = page_qry.getIntField("page_id");
- int identified = page_qry.getIntField("identified");
- CopyFileA(path.c_str(), new_file_name.c_str(), FALSE);
- Json::Value item;
- item["name"] = name.c_str();
- item["identified"] = identified;
- item["page_id"] = page_id;
- json_array_page.append(item);
- page_qry.nextRow();
- }
- std::string rst_path = query.getStringField("file_name");
- if (!rst_path.empty()){
- /*
- std::string new_rst_path = std::string("D:\\exception_tmp\\rst") + ".zip";
- CopyFileA(rst_path.c_str(), new_rst_path.c_str(), FALSE);
- json["restult_file"] = "rst.zip";
- */
- CString UplaodPath;
- UplaodPath = CString(rst_path.c_str());
- UplaodPath = UplaodPath.Mid(0, UplaodPath.GetLength() - 4);
- rst_path = CT2A(UplaodPath);
- std::string new_rst_path = CServerConfig::app_data_dir_string + std::string("\\exception_tmp\\rst\\");
- CString rstPath = CServerConfig::app_data_dir + _T("\\exception_tmp\\rst\\");
- CreateDirectory(rstPath, NULL);
- //CopyFileA(rst_path.c_str(), new_rst_path.c_str(), FALSE);
- CopyAllFile(CString(new_rst_path.c_str()), CString(rst_path.c_str()));
- json["restult_file"] = "rst";
- }
- else{
- json["rst_file"] = "";
- }
- // 获取异常
- std::string ex_sql = "select * from exception where student_paper_id = ";
- ex_sql += std::to_string(last_student_paper_id);
- CppSQLite3Query ex_qry = bantch_db->execQuery(ex_sql.c_str());
- Json::Value json_array_ex(Json::arrayValue);
- while (!ex_qry.eof()){
- int exception_id = ex_qry.getIntField("exception_id");
- int exception_type = ex_qry.getIntField("exception_type");
- std::string exception_name = ex_qry.getStringField("exception_name");
- Json::Value item;
- item["exception_id"] = exception_id;
- item["exception_type"] = exception_type;
- item["exception_name"] = exception_name;
- if (!ex_qry.fieldIsNull("page_id")){
- int page_id = ex_qry.getIntField("page_id");
- item["page_id"] = page_id;
- }
- json_array_ex.append(item);
- ex_qry.nextRow();
- }
- // 获取识别结果
- std::string rst_sql = "select * from result where student_paper_id = ";
- rst_sql += std::to_string(last_student_paper_id);
- CppSQLite3Query rst_qry = bantch_db->execQuery(rst_sql.c_str());
- Json::Value json_array_rst(Json::arrayValue);
- while (!rst_qry.eof()){
- int result_id = rst_qry.getIntField("result_id");
- int page_id = rst_qry.getIntField("page_id");
- int type = rst_qry.getIntField("type");
- std::string answer = rst_qry.getStringField("answer");
- float score = rst_qry.getFloatField("score");
- std::string question_code = rst_qry.getStringField("question_code");
- float score_paper = rst_qry.getFloatField("score_paper");
- int question_state = rst_qry.getIntField("question_state");
- bool isright = rst_qry.getIntField("isright");
- Json::Value item;
- item["result_id"] = result_id;
- item["page_id"] = page_id;
- item["type"] = type;
- item["answer"] = answer;
- item["score"] = score;
- item["question_code"] = question_code;
- item["score_paper"] = score_paper;
- item["question_state"] = question_state;
- item["isright"] = isright;
- json_array_rst.append(item);
- rst_qry.nextRow();
- }
- json["pages"] = json_array_page;
- json["student_paper"] = json_stu_paper;
- json["exceptions"] = json_array_ex;
- json["result"] = json_array_rst;
- json["student_paper_id"] = last_student_paper_id;
- json["student"] = json_stu;
- Json::FastWriter writer;
- exception_json = writer.write(json);
- std::ofstream ofs;
- std::string json_path = CServerConfig::app_data_dir_string + "\\exception_tmp\\json.txt";
- ofs.open(json_path, ios::out);
- ofs << exception_json;
- ofs.close();
- CString str_ucoud_path = CServerConfig::app_data_dir + _T("\\temp_ucloud_path\\exception_ucloud.zip");
- ZipCompress(CServerConfig::app_data_dir + _T("\\exception_tmp\\*.*"), str_ucoud_path);
- // 调用云上传
- std::string ucloud_key = get_ucloud_key(stu_paper_qry.getStringField("paper_code"));
-
- std::string exceptionZipPath = CServerConfig::app_data_dir_string + "\\temp_ucloud_path\\exception_ucloud.zip";
- auto error = ufile_put_file_by_filepath(bucket_name.c_str(), ucloud_key.c_str(), "", exceptionZipPath.c_str());
- if UFILE_HAS_ERROR(error.code) {
- }
- else{
- char szucloud_domain[512] = { 0 };
- char YunService[128] = { 0 };
- std::string str_path_tmp = UnicodeToAnsi(GetExePath() + _T("\\config.ini"));
- const char* FilePath = str_path_tmp.c_str();
- GetPrivateProfileStringA("USER", "YunService", "UCLOUD", YunService, sizeof(YunService) / sizeof(char), FilePath);
- if (strcmp(YunService, "UCLOUD") == 0){
- GetPrivateProfileStringA("GLOBAL", "ucloud_domain", "http://zxhx-test.cn-bj.ufileos.com/", szucloud_domain, 512, FilePath);
- }
- else{
- char url[512];
- GetPrivateProfileStringA("GLOBAL", "server_url", "http://127.0.0.1:8080/reportTask", url, 512, FilePath);
- bool isTestEnv = false;
- if (strstr(url, "test") != NULL || strstr(url, "dev") != NULL){
- isTestEnv = true;
- }
- if (isTestEnv){
- GetPrivateProfileStringA("GLOBAL", "ucloud_domain", "http://zxhx-1302712961.cos.ap-shanghai.myqcloud.com/", szucloud_domain, 512, FilePath);
- }
- else{
- GetPrivateProfileStringA("GLOBAL", "ucloud_domain", "http://zxhx-pro-1302712961.cos.ap-beijing.myqcloud.com/", szucloud_domain, 512, FilePath);
- }
- }
- std::string ucloud_url = std::string(szucloud_domain) + ucloud_key;
- LOGFMTI("ucloud_url=%s", ucloud_url.c_str());
- /* HttpDownloadTemplate(ucloud_url, "d:\\11111.zip");*/
- //调用 put 成功;
- Json::Value exception_json_value;
- exception_json_value["cloud_key"] = ucloud_url;
- //exception_json_value["cloud_url"] = ucloud_url;
- exception_json = writer.write(exception_json_value);
- }
-
- if (!m_bUploadOnScanModel){
- stmt4.bind(":exc_upload", 0);
- stmt4.bind(":service_type", service_type);
- stmt4.bind(":exception_json", exception_json.c_str());
- }
- }
- if (m_bUploadOnScanModel){
- rapidjson::Document doc;
- doc.SetObject();
- rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
- // 数据头
- AddStringMember(doc, allocator, "net_task_type", "upload_on_scan_upload");
- AddStringMember(doc, allocator, "net_task_cmd", "upload_on_scan_add_upload_task");
- rapidjson::Value _data; _data.SetObject();
- // 数据体
- AddStringMember(_data, allocator, "bantch_code", UnicodeToAnsi(m_batch_code).c_str());
- AddStringMember(_data, allocator, "exam_id", std::to_string(q.getInt64Field("exam_id")).c_str());
- AddNumberMember(_data, allocator, "student_paper_id", last_student_paper_id, 0);
- AddNumberMember(_data, allocator, "ret_upload", 0, 0);
- //导入上传库
- AddStringMember(_data, allocator, "paper_code", q.getStringField("paper_code"));
- AddStringMember(_data, allocator, "student_code", q.getStringField("student_code"));
- AddStringMember(_data, allocator, "student_id", q.getStringField("student_id"));
- AddStringMember(_data, allocator, "file_name", file_name.c_str());
- AddNumberMember(_data, allocator, "ret_ori_upload", 0, 0);
- AddStringMember(_data, allocator, "ori_json", json_ori_str.c_str());
- if (g_my_scan_type == 1 || g_my_scan_type == 2){
- AddStringMember(_data, allocator, "json_name", json_str.c_str());
- }
- else{
- AddStringMember(_data, allocator, "json_name", sz_file_name);
- }
- AddStringMember(_data, allocator, "student_name", q.getStringField("student_name"));
- AddStringMember(_data, allocator, "ori_img", q.getStringField("ori_img"));
- AddNumberMember(_data, allocator, "absent", q.getIntField("absent"), 0);
- AddNumberMember(_data, allocator, "exc_upload", 0, 0);
- AddNumberMember(_data, allocator, "service_type", service_type, 0);
- if ((paper_state&MEX_BUKESHANGCHUANG) != 0){
- AddNumberMember(_data, allocator, "exc_upload", 0, 0);
- AddStringMember(_data, allocator, "exception_json", exception_json.c_str());
- }
- else{
- AddStringMember(_data, allocator, "exception_json", "normal");
- AddStringMember(_data, allocator, "update_post_data", "nodata");
- }
- doc.AddMember("data", _data, allocator);
- rapidjson::StringBuffer buffer;
- rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
- doc.Accept(writer);
- std::string reststring = buffer.GetString();
- // rapidjson::Document __doc;
- // __doc.Parse(reststring.c_str());
- // if (!__doc.HasParseError()){
- // std::string str = __doc["data"]["json_name"].GetString();
- // int id = __doc["data"]["student_paper_id"].GetInt();
- // rapidjson::Document _doc;
- // _doc.Parse(str.c_str());
- // if (!_doc.HasParseError())
- // {
- // int n = 0;
- // ++n;
- // }
- // }
- int nRet = -20;
- std::string sql_qry_paper_state = "select paper_state from student_paper where student_paper_id=";
- sql_qry_paper_state += std::to_string(last_student_paper_id);
- if (db_lock &&bantch_db && bantch_db->is_open()){
- ::EnterCriticalSection(db_lock);
- auto paper_state_qry = bantch_db->execQuery(sql_qry_paper_state.c_str());
- if (!paper_state_qry.eof()){
- paper_state = paper_state_qry.getIntField("paper_state");
- }
- ::LeaveCriticalSection(db_lock);
- LOGFMTI("试卷ID=%d 试卷状态:%d", last_student_paper_id, paper_state);
- ::EnterCriticalSection(&m_csUploadOnScanPapers);
- auto it_find = m_vctUploadOnScanPapers.find(last_student_paper_id);
- if (it_find != m_vctUploadOnScanPapers.end() && it_find->second == (paper_state != 0)){
- LOGD(std::string("向知心慧学端发送上传任务 data=") + reststring);
- nRet = NetOperator::ClientSendData(reststring.c_str());
- if (nRet < 0){
- LOGFMTD("向知心慧学端发送上传任务-失败 删除目录:%s", UnicodeToAnsi(imgPath).c_str());
- DeleteDirectory(imgPath);
- }
- else{
- m_vctUploadOnScanPapers.erase(it_find);
- LOGD("向知心慧学端发送上传任务-成功");
- }
- }
- ::LeaveCriticalSection(&m_csUploadOnScanPapers);
- }
- Sleep(5);
- }
- else{
- stmt4.execDML();
- //修改成功标识
- EnterCriticalSection(db_lock);
- bantch_db->execDML("begin transaction");
- char sql6[512];
- sprintf_s(sql6, "update student_paper set ret_upload = 2 where student_paper_id = %d", last_student_paper_id);
- bantch_db->execDML(sql6);
- bantch_db->execDML("commit transaction");
- LeaveCriticalSection(db_lock);
- }
- q.nextRow();
- }
- if (m_bUploadOnScanModel){
- ServiceState _state = stoping;
- ::EnterCriticalSection(&m_csUploadOnScanPapers);
- if (!m_vctUploadOnScanPapers.empty())
- _state = running;
- ::LeaveCriticalSection(&m_csUploadOnScanPapers);
- return _state;
- }
- else{
- if (m_hwnd != NULL) {
- int total_bantch_count = (m_total + 499) / 500;
- int current_bantch = (m_current_count) / 500 + 1;
- int current_count = (m_current_count - 1) % 500 + 1;
- float progress = (int)(10000.0 / total_bantch_count)*(current_bantch - 1 + 0.8);
- ::PostMessage(m_hwnd, WM_IDENTIFOR_RESULT_UPLOAD_PROGRESS, progress, 0);
- }
- }
- }
- if (rows == 0){
- if (m_result_hadler == NULL || m_result_hadler->GetServiceSate() == stoped){
- Stop();
- }
- else{
- Sleep(1000);
- }
- }
- return running;
- }
- void CResultUploader::SetUploadOnScan(bool bUploadOnScan, int student_paper_id, bool bErrorPaper)
- {
- m_bUploadOnScanModel = bUploadOnScan;
- if (student_paper_id >0 && bUploadOnScan){
- ::EnterCriticalSection(&m_csUploadOnScanPapers);
- auto it_find = m_vctUploadOnScanPapers.find(student_paper_id);
- if (it_find == m_vctUploadOnScanPapers.end()){
- m_vctUploadOnScanPapers.insert(std::make_pair(student_paper_id, bErrorPaper));
- }
- ::LeaveCriticalSection(&m_csUploadOnScanPapers);
- }
- }
- CString UnicodeToChinese(const std::string str)
- {
- CString cstr;
- int i = 0;
- int j = 0;
- int len = 0;
- len = str.length();
- if (len <= 0){
- return false;
- }
- int nValue = 0;
- WCHAR * pWchar;
- wchar_t* szHex;
- char strchar[6] = { '0', 'x', '\0' };
- for (i = 0; i < len; i++)
- {
- if (str[i] == 'x'&& i>0 && str[i - 1] == '\\')
- {
- for (j = 2;str[i] != '\\'&& i < len; j++)
- {
- i++;
- strchar[j] = str[i];
- }
- USES_CONVERSION;
- szHex = A2W(strchar);
- StrToIntExW(szHex, STIF_SUPPORT_HEX, &nValue);
- pWchar = (WCHAR*)& nValue;
- cstr = cstr + pWchar;
- }
- else if (str[i] != '\\'){
- cstr += str[i];
- }
- }
- return cstr;
- }
- //从文件读入到string里
- std::string readFileIntoString(const std::string& filename)
- {
- ifstream ifile(filename);
- //将文件读入到ostringstream对象buf中
- ostringstream buf;
- char ch;
- while (buf&&ifile.get(ch))
- buf.put(ch);
- //返回与流对象buf关联的字符串
- return buf.str();
- }
- wstring strUTF8toW(const string& src)
- {
- wstring result = L"";
- int n = MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, NULL, 0);
- result.resize(n);
- ::MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, (LPWSTR)result.c_str(), result.length());
- return result;
- }
- CString AnsiToUnicode(const std::string& str);
- std::string UnicodeToAnsi(const CString& str);
- #include "rapidjson/document.h"
- ServiceState CResultUploader::OnStoping(void)
- {
- // 边扫描边上传
- if (m_bUploadOnScanModel){
- LOGI(" m_bUploadOnScanModel 开始上传成绩结束");
- return IService::OnStoping();
- }
- LOGI("开始上传成绩结束");
- upload_database_db.close();
- if (!m_failtrue){
- char sql[512] = { 0 };
- sprintf_s(sql, "select count(0) from student_paper p left join student s on s.student_id = p.student_id where (p.paper_state&%d)=0", MEX_BUKESHANGCHUANG);
- int total_count = bantch_db->execScalar(sql);
- sprintf_s(sql, "update database set database_state =%d,total_upload_count=%d where database_id =%d", DATABASE_STATE_RESULT_UPLOADED, total_count, database_id);
- EnterCriticalSection(database_db_lock);
- database_db->execDML("begin transaction");
- database_db->execDML(sql);
- database_db->execDML("commit transaction");
- LeaveCriticalSection(database_db_lock);
- }
-
- {
- //通信
- CWnd *pWnd = CWnd::FindWindow(NULL, _T("知心慧学学管系统"));
- if (pWnd == NULL)
- {
- UploadMsg* msg = new UploadMsg;
- msg->strMsg = m_strMsg;
- msg->nTotal = (m_total << 16) + m_sccuss_count;
- ::PostMessage(m_hwnd, WM_IDENTIFOR_RESULT_UPLOAD_COMPLETED, FALSE, (LPARAM)msg);
- return IService::OnStoping();
- }
- //发送消息
- MY_DB_INFO fff;
- int len = 1024;
- fff.nmode = 0;
- memset(&fff, 0, sizeof(MY_DB_INFO));
- strncpy(fff.sDbBasePath, g_strUpLoadDbPathName.c_str(), g_strUpLoadDbPathName.length() + 1);
- getupLoadUrl(fff.sUrl, len);
- int service_type = 0;
- 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);
- {
- TCHAR exam_name[256] = { 0 };
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("config.ini"));
- GetPrivateProfileString(_T("THIRD"), _T("exam_name"), _T(""), exam_name, sizeof(exam_name) / sizeof(TCHAR), FilePath);
- sprintf_s(fff.sExamName, "%s", UnicodeToAnsi(exam_name).c_str());
- }
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("paperinfo.ini"));
- service_type = GetPrivateProfileInt(_T("paperinfo"), _T("servicetype"), 0, FilePath);
- WCHAR szSubjectID[512] = { 0 };
- GetPrivateProfileString(_T("paperinfo"), _T("subject_id"), _T(""), szSubjectID, 512, FilePath);
- sprintf_s(fff.sSubjectName, "%s", UnicodeToAnsi(szSubjectID).c_str());
- if (m_bErrorHandle)
- {
- WCHAR URL[512] = { 0 };
- GetPrivateProfileString(_T("paperinfo"), _T("uploadurl"), _T(""), URL, 512, FilePath);
- CString tmp = URL;
- if (tmp != _T("nourl")){
- sprintf_s(fff.sabsentUrl, "%s/coachio/iointerface_v2/delPaperStudent", UnicodeToAnsi(tmp).c_str());
- WCHAR session[512] = { 0 };
- GetPrivateProfileString(_T("paperinfo"), _T("session"), _T(""), session, 512, FilePath);
- sprintf_s(fff.sSeesion, "%s", UnicodeToAnsi(session).c_str());
- }
- }
-
- if (g_my_scan_type == 0)
- fff.ntype = 1;
- else if (g_my_scan_type == 1)
- fff.ntype = 2;
- else if (g_my_scan_type == 2)
- fff.ntype = 3;
- fff.course_id = m_nCourseId;
- fff.bScanType = service_type;
- printf("发送数学开始上传:service_type=%d \n url=%s \n upload_url=%s\n session=%s\n", fff.bScanType, fff.sUrl, fff.sabsentUrl, fff.sSeesion);
- //魔法词汇卡
- if (m_nOnlineScanType == 0)
- {
- fff.nmode = 0;
- fff.ntype = 6;
- }
- COPYDATASTRUCT cpd; // 给COPYDATASTRUCT结构赋值
- cpd.dwData = 0;
- cpd.cbData = sizeof(MY_DB_INFO);
- cpd.lpData = (&fff);
- int ret = pWnd->SendMessage(WM_COPYDATA, NULL, (LPARAM)&cpd); // 发送
- if (m_hwnd != NULL)
- {
- UploadMsg* msg = new UploadMsg;
- msg->strMsg = m_strMsg;
- msg->nTotal = (m_total << 16) + m_sccuss_count;
- ::PostMessage(m_hwnd, WM_IDENTIFOR_RESULT_UPLOAD_COMPLETED, !m_failtrue, (LPARAM)msg);
- }
- }
- return IService::OnStoping();
- }
- void CResultUploader::SetResultHandler(CResultHandler * result_hadler)
- {
- m_result_hadler = result_hadler;
- }
- void CResultUploader::SetResultHandler(boost::shared_ptr<CResultHandler> pPtr)
- {
- m_pWeakResult = pPtr;
- }
- int CResultUploader::SetHandlerWnd(HWND hwnd)
- {
- m_hwnd = hwnd;
- return 0;
- }
- CString CResultUploader::MarkHttpHeaderData()
- {
- TCHAR FilePath[MAX_PATH];
- GetModuleFileName(NULL, FilePath, MAX_PATH);
- CString ret;
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- if (m_bErrorHandle){
- lstrcat(FilePath, _T("paperinfo.ini"));
- WCHAR JSESSIONID[512];
- GetPrivateProfileString(_T("paperinfo"), _T("session"), _T(""), JSESSIONID, 512, FilePath);
- ret = JSESSIONID;
- }
- else{
- lstrcat(FilePath, _T("config.ini"));
- #ifndef BACK_STAGE
- WCHAR SIG[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("SIG"), _T(""), SIG, 512, FilePath);
- WCHAR TIME[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("TIME"), _T(""), TIME, 512, FilePath);
- WCHAR ID[512];
- GetPrivateProfileString(L"SESSIONID", L"ID", L"", ID, 512, FilePath);
- WCHAR JSESSIONID[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("JSESSIONID"), _T(""), JSESSIONID, 512, FilePath);
- ret.Format(_T("userid=%s&time=%s&sig=%s&session=%s"), ID, TIME, SIG, JSESSIONID);
- #else
- WCHAR MYCOOK[512];
- GetPrivateProfileString(_T("SESSIONID"), _T("MYCOOK"), _T(""), MYCOOK, 512, FilePath);
- CString ret;
- ret.Format(_T("%s"), MYCOOK);
- #endif
- }
- return ret;
- }
- void CResultUploader::readNewUploadUrl()
- {
- 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("config.ini"));
- WCHAR GroupId[512];
- GetPrivateProfileString(_T("USER"), _T("groupid"), _T(""), GroupId, 512, FilePath);
- m_strNewUploadUrl = GroupId;
- if (m_bErrorHandle)
- {
- (_tcsrchr(FilePath, '\\'))[1] = 0;
- lstrcat(FilePath, _T("paperinfo.ini"));
- WCHAR URL[512] = { 0 };
- GetPrivateProfileString(_T("paperinfo"), _T("uploadurl"), _T(""), URL, 512, FilePath);
- CString tmp = URL;
- if (tmp != _T("nourl")){
- m_strNewUploadUrl = tmp;
- }
- }
- return;
- }
- int CResultUploader::readCourseId()
- {
- TCHAR exeFullPath[MAX_PATH];
- CString strPath;
- int nSubjectId;
- 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 SubjectId[512];
- GetPrivateProfileString(_T("paperinfo"), _T("subject_id"), _T("3"), SubjectId, 512, FilePath);
- nSubjectId = _wtoi(SubjectId);
- return nSubjectId;
- }
- void CResultUploader::logForDbg(string strLog)
- {
- char logName[300] = { 0 };
- 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 + strLog;
- 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);
- ThreadLog3((char*)strLog.c_str(),logName);
- }
|