#include "StdAfx.h" #include "CBasicDataDownloader.h" #include "..\EvaluationUtil\HttpClient.h" #include "basic_struct.h" #include "ServerConfig.h" #include "rapidjson/document.h" CBasicDataDownloader::CBasicDataDownloader(void) { } CBasicDataDownloader::~CBasicDataDownloader(void) { } int CBasicDataDownloader::download_question_std( CString examId,CString examCourseId ) { m_task_type = DOWNLOAD_QUESTION_STD; m_examId =examId; m_examCourseId = examCourseId; m_data_state = DS_LOADING; return IService::Start(); } ServiceState CBasicDataDownloader::OnRunning( void ) { switch(m_task_type){ case DOWNLOAD_QUESTION_STD: download_question_std0(m_examId,m_examCourseId); break; case DOWNLOAD_SAME_CLASS_STUDENT: break; } return stoping; } int CBasicDataDownloader::GetErrorCode(){ return m_error_code; }; //下载题目标准信息 int CBasicDataDownloader::download_question_std0( CString examId,CString examCourseId ) { m_error_code = BDD_ERROR_CODE_NORMAL; CHttpClient httpClient; string response; CString url_str; url_str.Format(_T("%s/%s"),CServerConfig::server_url,_T("/question/findHandCardQidDetails")); CString postData; postData.Format(_T("examId=%s&examCourseId=%s"),examId,examCourseId); httpClient.HttpPost(url_str,postData,response); rapidjson::Document doc; doc.Parse(response.c_str()); rapidjson::Value& root = doc; if(root["success"].IsInt()){ if(root["success"].GetInt()){ rapidjson::Value& rows = root["object"]; const char* sql ="INSERT INTO question_std (question_code, question_index, question_type, multi_answer, answer_all, answer_std, score_full, score_half, option_count,mark_unit) VALUES (:question_code, :question_index, :question_type, :multi_answer, :answer_all, :answer_std, :score_full, :score_half, :option_count,:mark_unit)"; CppSQLite3Statement statement= bantch_db->compileStatement(sql); if(rows.IsArray()){ bantch_db->execDML("begin transaction"); int array_size =rows.Size(); for (int i=0;i0){ vector options; split(row["selectValues"].GetString(), ",", &options); option_count = options.size(); } else{ option_count = 0; } statement.bind(":option_count", option_count); statement.bind(":mark_unit", row.FindMember("markUnit") == row.MemberEnd() ? 0 : (int)row["markUnit"].GetInt()); statement.execDML(); } bantch_db->execDML("commit transaction"); } m_data_state = DS_COMPLETE; }else{ m_error_code = BDD_ERROR_CODE_SERVER_ERROR; m_message =root["message"].GetString(); m_data_state = DS_ERROR; } }else if(root["session"].IsBool()&&root["session"].GetBool()){ m_error_code = BDD_ERROR_CODE_SERVER_ERROR; m_message ="长时间未操作,需要重新认证身份!"; m_data_state = DS_ERROR; }else{ m_error_code = BDD_ERROR_CODE_REQUEST_FAILTURE; m_data_state = DS_ERROR; } return 0; } std::string CBasicDataDownloader::GetExamName() { return m_exam_name; } std::string CBasicDataDownloader::GetCourseCode() { return m_course_code; } string CBasicDataDownloader::GetErrorMsg() { return m_message; }