123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #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;i<array_size;i++)
- {
- rapidjson::Value& row = rows[i];
- statement.bind(":question_code", row["qid"].GetString());
- statement.bind(":question_index", i);
- statement.bind(":question_type", row["type"].GetInt());
- statement.bind(":multi_answer", row["type"].GetInt() == 1 ? 1 : 0);
- statement.bind(":answer_all", row.FindMember("selectValues") == row.MemberEnd() ? 0 : row["selectValues"].GetString());
- statement.bind(":answer_std", row.FindMember("answer") == row.MemberEnd() ? 0 : row["answer"].GetString());
- statement.bind(":score_full", row.FindMember("fullScore") == row.MemberEnd() ? 0 : row["fullScore"].GetDouble());
- statement.bind(":score_half", row.FindMember("halfScore") == row.MemberEnd() ? 0 : row["halfScore"].GetDouble());
- int option_count = 0;
- if (row.FindMember("selectValues") != row.MemberEnd() && row["selectValues"].GetStringLength()>0){
- vector<string> 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;
- }
|