answerWidget.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. #include "answerWidget.h"
  2. #include "ui_answerWidget.h"
  3. #include "CAppInfo.h"
  4. #include "awMsgBox.h"
  5. #include "awQuestionNavigate.h"
  6. #include "CCommonTools.h"
  7. #include "logproc.h"
  8. #include "inprogressFace.h"
  9. answerWidget::answerWidget(QWidget *parent) :
  10. QWidget(parent),
  11. ui(new Ui::answerWidget)
  12. {
  13. ui->setupUi(this);
  14. setStyleSheet(g_appInfoPtr->m_sQssStr);
  15. qRegisterMetaType<CGetExamById>("CGetExamById");
  16. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamById, this, &answerWidget::onGetExamById);
  17. qRegisterMetaType<CGetExamRecordPaperStruct>("CGetExamRecordPaperStruct");
  18. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamRecordPaperStruct, this, &answerWidget::onGetExamRecordPaperStruct);
  19. qRegisterMetaType<CGetExamProperty>("CGetExamProperty");
  20. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamProperty, this, &answerWidget::onGetExamProperty);
  21. qRegisterMetaType<CWeiXinAnswerEnabled>("CWeiXinAnswerEnabled");
  22. connect(g_httpBllPtr.get(), &CHttpBll::sgnWeiXinAnswerEnabled, this, &answerWidget::onWeiXinAnswerEnabled);
  23. qRegisterMetaType<CGetQuestionContent>("CGetQuestionContent");
  24. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetQuestionContent, this, &answerWidget::onGetQuestionContent);
  25. qRegisterMetaType<CFindExamQuestionList>("CFindExamQuestionList");
  26. connect(g_httpBllPtr.get(), &CHttpBll::sgnFindExamQuestionList, this, &answerWidget::onFindExamQuestionList);
  27. qRegisterMetaType<CStartAnswer>("CStartAnswer");
  28. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartAnswer, this, &answerWidget::onStartAnswer);
  29. qRegisterMetaType<CExamHeartbeat>("CExamHeartbeat");
  30. connect(g_httpBllPtr.get(), &CHttpBll::sgnExamHeartbeat, this, &answerWidget::onExamHeartbeat);
  31. qRegisterMetaType<CSubmitQuestionAnswer>("CSubmitQuestionAnswer");
  32. connect(g_httpBllPtr.get(), &CHttpBll::sgnSubmitQuestionAnswer, this, &answerWidget::onSubmitQuestionAnswer);
  33. qRegisterMetaType<CEndExam>("CEndExam");
  34. connect(g_httpBllPtr.get(), &CHttpBll::sgnEndExam, this, &answerWidget::onEndExam);
  35. qRegisterMetaType<CGetOrgPropertiesByGroupWithoutCache>("CGetOrgPropertiesByGroupWithoutCache");
  36. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetOrgPropertiesByGroupWithoutCache, this, &answerWidget::onGetOrgPropertiesByGroupWithoutCache);
  37. qRegisterMetaType<CStartFaceLiveVerify>("CStartFaceLiveVerify");
  38. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartFaceLiveVerify, this, &answerWidget::onStartFaceLiveVerify);
  39. m_nLeftSeconds = 0;
  40. CHttpRequestPackage hrp;
  41. hrp.sUri = QString("/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/%1/%2")
  42. .arg(g_appInfoPtr->m_oExamInfo.nExamId).arg("SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME,PRACTICE_TYPE");
  43. hrp.nRequestType = RequestType::rtGetExamProperty;
  44. hrp.sCommonStr = "SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME";
  45. g_httpBllPtr->get(hrp);
  46. {
  47. CHttpRequestPackage hrp;
  48. hrp.sUri = QString("/api/ecs_exam_work/exam/%1").arg(g_appInfoPtr->m_oExamInfo.nExamId);
  49. hrp.nRequestType = RequestType::rtGetExamById;
  50. g_httpBllPtr->get(hrp);
  51. }
  52. CHttpRequestPackage hrp1;
  53. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/getExamRecordPaperStruct";
  54. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  55. hrp1.nRequestType = RequestType::rtGetExamRecordPaperStruct;
  56. hrp1.eParamType = HttpParamType::hptUrl;
  57. g_httpBllPtr->post(hrp1);
  58. {
  59. CHttpRequestPackage hrp;
  60. hrp.sUri = "/api/ecs_oe_student/client/exam/process/findExamQuestionList";
  61. hrp.nRequestType = RequestType::rtFindExamQuestionList;
  62. g_httpBllPtr->post(hrp);
  63. }
  64. {
  65. CHttpRequestPackage hrp;
  66. hrp.sUri = QString("/api/ecs_exam_work/exam/weixinAnswerEnabled/%1")
  67. .arg(g_appInfoPtr->m_oExamInfo.nExamId);
  68. hrp.nRequestType = RequestType::rtWeiXinAnswerEnabled;
  69. g_httpBllPtr->get(hrp);
  70. }
  71. m_pCountDownTimer = std::make_shared<QTimer>();
  72. m_pCountDownTimer->setInterval(1000);
  73. connect(m_pCountDownTimer.get(), &QTimer::timeout, this, [&](){
  74. --m_nLeftSeconds;
  75. ui->label_lastTime->setText(QString("%1:%2:%3").arg(m_nLeftSeconds/60/60, 2, 10, QChar('0'))
  76. .arg(m_nLeftSeconds/60%60, 2, 10, QChar('0'))
  77. .arg(m_nLeftSeconds%60, 2, 10, QChar('0')));
  78. if(m_nLeftSeconds <= 0)
  79. {
  80. m_pCountDownTimer->stop();
  81. handinPaper();
  82. }
  83. if(g_appInfoPtr->m_oExamInfo.bLivenessCheck &&
  84. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId > 0)
  85. {
  86. if(bShowLivenessTip && ((g_appInfoPtr->m_oExamInfo.nDuration - g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute)*60 + g_appInfoPtr->m_oExamInfo.nActionAlert) > m_nLeftSeconds)
  87. {
  88. bShowLivenessTip = false;
  89. ShowMsg(QString::fromLocal8Bit("%1秒后开始指定动作检测,请准备!").arg(g_appInfoPtr->m_oExamInfo.nActionAlert), g_appInfoPtr->m_pAnsBgWidget);
  90. }
  91. if((g_appInfoPtr->m_oExamInfo.nDuration - g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute)*60 > m_nLeftSeconds)
  92. {
  93. //活体检测
  94. if(m_pFaceLiveness == nullptr)
  95. {
  96. stopCapture();
  97. m_pFaceLiveness = std::make_shared<faceLiveness>(g_appInfoPtr->m_pAnsBgWidget);
  98. connect(m_pFaceLiveness.get(), &faceLiveness::faceLivenessFaild, this, [&](){
  99. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = 0;
  100. m_pFaceLiveness.reset();
  101. if(g_appInfoPtr->m_oExamInfo.nFaceVerifyTimes < 2)
  102. {
  103. CHttpRequestPackage hrp;
  104. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/startFaceLiveVerify")
  105. .arg(g_appInfoPtr->m_sRootOrgId);
  106. hrp.nRequestType = RequestType::rtStartFaceLiveVerify;
  107. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  108. hrp.eParamType = HttpParamType::hptUrl;
  109. g_httpBllPtr->post(hrp);
  110. }
  111. startCapture();
  112. });
  113. connect(m_pFaceLiveness.get(), &faceLiveness::faceLivenessSucceed, this, [&](){
  114. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = 0;
  115. m_pFaceLiveness.reset();
  116. startCapture();
  117. });
  118. m_pFaceLiveness->show();
  119. }
  120. }
  121. }
  122. });
  123. m_pHeartbeatTimer = std::make_shared<QTimer>();
  124. m_pHeartbeatTimer->setInterval(60*1000);
  125. connect(m_pHeartbeatTimer.get(), &QTimer::timeout, this, [&](){
  126. heartBreat();
  127. });
  128. }
  129. answerWidget::~answerWidget()
  130. {
  131. delete ui;
  132. }
  133. void answerWidget::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
  134. {
  135. setGeometry(nLeft, nTop, nWidth, nHeight);
  136. ui->widget_aw_answerBG->setGeometry(0, 0, width()*970/(970+270), height());
  137. ui->widget_navigate->setGeometry(ui->widget_aw_answerBG->x() + ui->widget_aw_answerBG->width() + g_appInfoPtr->m_fRate*20, 0,
  138. width() - ui->widget_aw_answerBG->width() - g_appInfoPtr->m_fRate*20, height());
  139. ui->widget_aw_face->setGeometry(0, ui->widget_navigate->height() - g_appInfoPtr->m_fRate*140, ui->widget_navigate->width(), g_appInfoPtr->m_fRate*140);
  140. ui->widget_aw_top->setGeometry(0, 0, ui->widget_aw_answerBG->width(), g_appInfoPtr->m_fRate*56);
  141. ui->widget_ng_top->setGeometry(0, 0, ui->widget_navigate->width(), g_appInfoPtr->m_fRate*56);
  142. ui->label_answerProgress->adjustSize();
  143. ui->label_answerProgress->setGeometry(g_appInfoPtr->m_fRate*20, (ui->widget_aw_top->height() - ui->label_answerProgress->height())/2,
  144. ui->label_answerProgress->width(), ui->label_answerProgress->height());
  145. ui->pgb_answerProgress->setGeometry(ui->label_answerProgress->x() + ui->label_answerProgress->width() + g_appInfoPtr->m_fRate*8,
  146. (ui->widget_aw_top->height() - g_appInfoPtr->m_fRate*20)/2,
  147. g_appInfoPtr->m_fRate*200, g_appInfoPtr->m_fRate*20);
  148. ui->btn_handInPaper->setGeometry(ui->widget_aw_top->width() - g_appInfoPtr->m_fRate*(10 + 100), g_appInfoPtr->m_fRate*10,
  149. g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*36);
  150. ui->label_lastTimeIcon->setGeometry(g_appInfoPtr->m_fRate*48, g_appInfoPtr->m_fRate*12, g_appInfoPtr->m_fRate*32, g_appInfoPtr->m_fRate*32);
  151. ui->label_lastTime->adjustSize();
  152. ui->label_lastTime->setGeometry(ui->label_lastTimeIcon->x() + ui->label_lastTimeIcon->width() + g_appInfoPtr->m_fRate*10,
  153. ui->label_lastTimeIcon->y() + (ui->label_lastTimeIcon->height() - ui->label_lastTime->height())/2,
  154. ui->label_lastTime->width(), ui->label_lastTime->height());
  155. ui->btn_all->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_ng_top->height() + g_appInfoPtr->m_fRate*20,
  156. g_appInfoPtr->m_fRate*90, 28);
  157. ui->btn_allNum->setGeometry(ui->btn_all->x() + ui->btn_all->width() - g_appInfoPtr->m_fRate*(4 + 30), ui->btn_all->y() + (ui->btn_all->height() - g_appInfoPtr->m_fRate*20)/2,
  158. g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*20);
  159. ui->btn_answered->setGeometry(ui->btn_all->x() + ui->btn_all->width() + g_appInfoPtr->m_fRate*10,
  160. ui->btn_all->y(), ui->btn_all->width(), ui->btn_all->height());
  161. ui->btn_answeredNum->setGeometry(ui->btn_answered->x() + ui->btn_answered->width() - g_appInfoPtr->m_fRate*(4 + 30), ui->btn_allNum->y(),
  162. ui->btn_allNum->width(), ui->btn_allNum->height());
  163. ui->btn_unanswered->setGeometry(ui->btn_all->x(), ui->btn_all->y() + ui->btn_all->height() + g_appInfoPtr->m_fRate*10,
  164. ui->btn_all->width(), ui->btn_all->height());
  165. ui->btn_unansweredNum->setGeometry(ui->btn_allNum->x(), ui->btn_unanswered->y() + (ui->btn_unanswered->height() - g_appInfoPtr->m_fRate*20)/2,
  166. ui->btn_allNum->width(), ui->btn_allNum->height());
  167. ui->btn_marked->setGeometry(ui->btn_answered->x(), ui->btn_unanswered->y(), ui->btn_all->width(), ui->btn_all->height());
  168. ui->btn_markedNum->setGeometry(ui->btn_answeredNum->x(), ui->btn_unansweredNum->y(), ui->btn_allNum->width(), ui->btn_allNum->height());
  169. ui->label_HLine->setGeometry(ui->btn_all->x(), ui->btn_unanswered->y() + ui->btn_unanswered->height() + g_appInfoPtr->m_fRate*20,
  170. ui->widget_navigate->width() - ui->btn_all->x()*2, g_appInfoPtr->m_fRate*1);
  171. ui->lw_aw_questionList->setGeometry(0, ui->label_HLine->y(), ui->widget_navigate->width(),
  172. ui->widget_aw_face->y() - ui->label_HLine->y() - ui->label_HLine->height());
  173. }
  174. void answerWidget::onGetExamById(CGetExamById getExamById)
  175. {
  176. if (getExamById.nCode == 200)
  177. {
  178. g_appInfoPtr->m_oExamInfo.nExamId = getExamById.nId;
  179. g_appInfoPtr->m_oExamInfo.sExamType = getExamById.sExamType;
  180. g_appInfoPtr->m_oExamInfo.nDuration = getExamById.nDuration;
  181. }
  182. else
  183. {
  184. if(getExamById.sMessage.isEmpty())
  185. {
  186. ShowMsg(QString::fromLocal8Bit("获取考试信息出错"), g_appInfoPtr->m_pAnsBgWidget);
  187. }
  188. else
  189. {
  190. ShowMsg(getExamById.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  191. }
  192. }
  193. }
  194. void answerWidget::onGetExamRecordPaperStruct(CGetExamRecordPaperStruct getExamRecordPaperStruct)
  195. {
  196. if (getExamRecordPaperStruct.nCode == 200)
  197. {
  198. m_vPaperGroupStruct.swap(getExamRecordPaperStruct.vPaperGroupStruct);
  199. int nSize = m_vPaperGroupStruct.size();
  200. QString sQuestionId = "";
  201. for (int i = 0; i < nSize; ++i)
  202. {
  203. CPaperGroupStruct &pgs = m_vPaperGroupStruct[i];
  204. awQuestionNavigate *questionItem = new awQuestionNavigate(pgs);
  205. connect(questionItem, &awQuestionNavigate::showSubQuestion, this, [&](QString sQuestionId, int nOrder, bool bHasContent) {
  206. showQuestionByOrder(nOrder);
  207. /*if (bHasContent)
  208. {
  209. for (CQuestionStruct &qs : pgs.vQuestionStruct)
  210. {
  211. if (qs.sQuestionId == sQuestionId)
  212. {
  213. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(pgs.nNumber)).arg(pgs.sGroupName).arg(pgs.nTotalSubquestion);
  214. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(pgs.nAnsweredCount).arg(pgs.nTotalSubquestion);
  215. showSubQuestion(qs, nOrder, sGroupTitleText, sGroupProgressText);
  216. }
  217. }
  218. }
  219. else
  220. {
  221. getQuestionContent(sQuestionId, nOrder);
  222. }
  223. */
  224. });
  225. QListWidgetItem *pItem = new QListWidgetItem;
  226. ui->lw_aw_questionList->addItem(pItem);
  227. ui->lw_aw_questionList->setItemWidget(pItem, questionItem);
  228. int nHeight = questionItem->setUI(ui->lw_aw_questionList->width() - g_appInfoPtr->m_fRate*60);
  229. QSize size = pItem->sizeHint();
  230. size.setHeight(nHeight);
  231. pItem->setSizeHint(size);
  232. }
  233. }
  234. else
  235. {
  236. if(getExamRecordPaperStruct.sMessage.isEmpty())
  237. {
  238. ShowMsg(QString::fromLocal8Bit("获取考试结构出错"), g_appInfoPtr->m_pAnsBgWidget);
  239. }
  240. else
  241. {
  242. ShowMsg(getExamRecordPaperStruct.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  243. }
  244. }
  245. }
  246. CAnsweredQuestion answerWidget::findQuestionByOrder(CFindExamQuestionList &feql, int nOrder)
  247. {
  248. for (int i = 0; i < feql.vAnsweredQuestion.size(); ++i)
  249. {
  250. if (feql.vAnsweredQuestion[i].nOrder == nOrder)
  251. {
  252. return feql.vAnsweredQuestion[i];
  253. }
  254. }
  255. }
  256. void answerWidget::onFindExamQuestionList(CFindExamQuestionList findExamQuestionList)
  257. {
  258. if (findExamQuestionList.nCode == 200)
  259. {
  260. int nTotal = 0;
  261. int nAnswered = 0;
  262. int nMarked = 0;
  263. int nSize = m_vPaperGroupStruct.size();
  264. for (int i = 0; i < nSize; ++i)
  265. {
  266. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  267. for (int j = 0; j < nQuestionSize; ++j)
  268. {
  269. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  270. for (int k = 0; k < nSubQuestionSize; ++k)
  271. {
  272. nTotal++;
  273. int nOrder = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].nOrder;
  274. CAnsweredQuestion aq= findQuestionByOrder(findExamQuestionList, nOrder);
  275. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].bAnswered = aq.bIsAnswer;
  276. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].bMarked = aq.bIsSign;
  277. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].sStudentAnswer = aq.sStudentAnswer;
  278. if (aq.bIsAnswer)
  279. {
  280. nAnswered++;
  281. }
  282. if (aq.bIsSign)
  283. {
  284. nMarked++;
  285. }
  286. if (!aq.sAudioPlayTimes.isEmpty())
  287. {
  288. Json::Reader reader;
  289. Json::Value jAudioPlayTimes = Json::Value::null;
  290. if (reader.parse(aq.sAudioPlayTimes.toStdString(), jAudioPlayTimes))
  291. {
  292. for (int ja = 0; ja < jAudioPlayTimes.size(); ++ja)
  293. {
  294. Json::Value jAudioPlayItem = jAudioPlayTimes[ja];
  295. g_appInfoPtr->m_jAudioPlayedCount[jAudioPlayItem["name"].asString()] = jAudioPlayItem["times"].asInt();
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. showQuestionByOrder(1);
  303. ui->btn_allNum->setText(QString::number(nTotal));
  304. ui->btn_answeredNum->setText(QString::number(nAnswered));
  305. ui->btn_markedNum->setText(QString::number(nMarked));
  306. ui->btn_unansweredNum->setText(QString::number(nTotal - nAnswered));
  307. ui->pgb_answerProgress->setMaximum(nTotal);
  308. ui->pgb_answerProgress->setValue(nAnswered);
  309. refreshStatus();
  310. //开始答题
  311. CHttpRequestPackage hrp1;
  312. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/startAnswer";
  313. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  314. hrp1.nRequestType = RequestType::rtStartAnswer;
  315. hrp1.eParamType = HttpParamType::hptUrl;
  316. g_httpBllPtr->post(hrp1);
  317. }
  318. else
  319. {
  320. if(findExamQuestionList.sMessage.isEmpty())
  321. {
  322. ShowMsg(QString::fromLocal8Bit("获取题目信息出错"), g_appInfoPtr->m_pAnsBgWidget);
  323. }
  324. else
  325. {
  326. ShowMsg(findExamQuestionList.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  327. }
  328. }
  329. }
  330. void answerWidget::onGetExamProperty(CGetExamProperty getExamProperty)
  331. {
  332. if (getExamProperty.nCode == 200)
  333. {
  334. if (getExamProperty.sType == "SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME")
  335. {
  336. m_nSnapshotInterval = getExamProperty.nSnapshotInterval;
  337. g_appInfoPtr->m_oExamInfo.sPracticeType = getExamProperty.sPracticeType;
  338. m_nFreezeTime = getExamProperty.nFreezeTime;
  339. }
  340. }
  341. else
  342. {
  343. if(getExamProperty.sMessage.isEmpty())
  344. {
  345. ShowMsg(QString::fromLocal8Bit("获取考试信息出错"), g_appInfoPtr->m_pAnsBgWidget);
  346. }
  347. else
  348. {
  349. ShowMsg(getExamProperty.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  350. }
  351. }
  352. }
  353. void answerWidget::onWeiXinAnswerEnabled(CWeiXinAnswerEnabled weiXinAnswerEnabled)
  354. {
  355. if (weiXinAnswerEnabled.nCode == 200)
  356. {
  357. g_appInfoPtr->m_bWeiXinAnswerEnabled = weiXinAnswerEnabled.bEnabled;
  358. }
  359. else
  360. {
  361. if(weiXinAnswerEnabled.sMessage.isEmpty())
  362. {
  363. ShowMsg(QString::fromLocal8Bit("获取考试信息失败"), g_appInfoPtr->m_pAnsBgWidget);
  364. }
  365. else
  366. {
  367. ShowMsg(weiXinAnswerEnabled.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  368. }
  369. }
  370. }
  371. void answerWidget::showSubQuestion(CQuestionStruct &qs, int nOrder, QString sTitle, QString sProgress)
  372. {
  373. if (qs.sBody.isEmpty())
  374. {
  375. if (m_pQuestion != nullptr)
  376. {
  377. m_pQuestion.reset();
  378. }
  379. if (m_pQuestionSet != nullptr)
  380. {
  381. m_pQuestionSet.reset();
  382. }
  383. m_pQuestion = std::make_shared<question>(qs, nOrder, ui->widget_aw_answerBG);
  384. connect(m_pQuestion.get(), &question::uploadAnswer, this, [&](int nIndex, __int64 timeStamp, QString sAnswer){
  385. uploadAnswer(nIndex, sAnswer);
  386. });
  387. connect(m_pQuestion.get(), &question::questionAnswered, this, [&](bool bAnswered, int nIndex){
  388. refreshStatus();
  389. int nSize = m_vPaperGroupStruct.size();
  390. for (int i = 0; i < nSize; ++i)
  391. {
  392. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  393. for (int j = 0; j < nQuestionSize; ++j)
  394. {
  395. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  396. for (int k = 0; k < nSubQuestionSize; ++k)
  397. {
  398. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  399. if(sqs.nOrder == nIndex)
  400. {
  401. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  402. m_pQuestion->setGroupInfo("", sGroupProgressText);
  403. break;
  404. }
  405. }
  406. }
  407. }
  408. });
  409. connect(m_pQuestion.get(), &question::markedItem, this, [&](bool bMarked, int nIndex){
  410. refreshStatus();
  411. });
  412. connect(m_pQuestion.get(), &question::previousQuestion, this, [&](int nOrder){
  413. if(nOrder > 1)
  414. {
  415. showQuestionByOrder(nOrder - 1);
  416. }
  417. });
  418. connect(m_pQuestion.get(), &question::nextQuestion, this, [&](int nOrder){
  419. showQuestionByOrder(nOrder + 1);
  420. });
  421. m_pQuestion->setGroupInfo(sTitle, sProgress);
  422. m_pQuestion->setUI(0, g_appInfoPtr->m_fRate * 86,
  423. ui->widget_aw_answerBG->width(), ui->widget_aw_answerBG->height() - g_appInfoPtr->m_fRate * (86 + 20));
  424. m_pQuestion->show();
  425. }
  426. else
  427. {
  428. if (m_pQuestion != nullptr)
  429. {
  430. m_pQuestion.reset();
  431. }
  432. if (m_pQuestionSet != nullptr)
  433. {
  434. m_pQuestionSet.reset();
  435. }
  436. m_pQuestionSet = std::make_shared<questionSet>(qs, nOrder, ui->widget_aw_answerBG);
  437. connect(m_pQuestionSet.get(), &questionSet::uploadAnswer, this, [&](int nIndex, __int64 timeStamp, QString sAnswer){
  438. uploadAnswer(nIndex, sAnswer);
  439. });
  440. connect(m_pQuestionSet.get(), &questionSet::questionAnswered, this, [&](bool bAnswered, int nIndex){
  441. refreshStatus();
  442. int nSize = m_vPaperGroupStruct.size();
  443. for (int i = 0; i < nSize; ++i)
  444. {
  445. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  446. for (int j = 0; j < nQuestionSize; ++j)
  447. {
  448. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  449. for (int k = 0; k < nSubQuestionSize; ++k)
  450. {
  451. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  452. if(sqs.nOrder == nIndex)
  453. {
  454. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  455. m_pQuestionSet->setGroupInfo("", sGroupProgressText);
  456. break;
  457. }
  458. }
  459. }
  460. }
  461. });
  462. connect(m_pQuestionSet.get(), &questionSet::markedItem, this, [&](bool bMarked, int nIndex){
  463. refreshStatus();
  464. });
  465. connect(m_pQuestionSet.get(), &questionSet::previousQuestion, this, [&](int nOrder){
  466. if(nOrder > 1)
  467. {
  468. showQuestionByOrder(nOrder - 1);
  469. }
  470. });
  471. connect(m_pQuestionSet.get(), &questionSet::nextQuestion, this, [&](int nOrder){
  472. showQuestionByOrder(nOrder + 1);
  473. });
  474. m_pQuestionSet->setGroupInfo(sTitle, sProgress);
  475. m_pQuestionSet->setUI(0, g_appInfoPtr->m_fRate * 86,
  476. ui->widget_aw_answerBG->width(), ui->widget_aw_answerBG->height() - g_appInfoPtr->m_fRate * (86 + 20));
  477. m_pQuestionSet->show();
  478. }
  479. }
  480. void answerWidget::refreshStatus()
  481. {
  482. int nCount = ui->lw_aw_questionList->count();
  483. for(int i = 0; i < nCount; ++i)
  484. {
  485. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  486. if(questionItem)
  487. {
  488. questionItem->refreshStatus();
  489. }
  490. }
  491. int nTotal = 0;
  492. int nAnswered = 0;
  493. int nMarked = 0;
  494. int nSize = m_vPaperGroupStruct.size();
  495. for (int i = 0; i < nSize; ++i)
  496. {
  497. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  498. int nAnswerCount = 0;
  499. for (int j = 0; j < nQuestionSize; ++j)
  500. {
  501. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  502. for (int k = 0; k < nSubQuestionSize; ++k)
  503. {
  504. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  505. nTotal++;
  506. if (sqs.bAnswered)
  507. {
  508. nAnswerCount++;
  509. nAnswered++;
  510. }
  511. if (sqs.bMarked)
  512. {
  513. nMarked++;
  514. }
  515. }
  516. }
  517. m_vPaperGroupStruct[i].nAnsweredCount = nAnswerCount;
  518. }
  519. ui->btn_allNum->setText(QString::number(nTotal));
  520. ui->btn_answeredNum->setText(QString::number(nAnswered));
  521. ui->btn_markedNum->setText(QString::number(nMarked));
  522. ui->btn_unansweredNum->setText(QString::number(nTotal - nAnswered));
  523. ui->pgb_answerProgress->setMaximum(nTotal);
  524. ui->pgb_answerProgress->setValue(nAnswered);
  525. }
  526. void answerWidget::showQuestionByOrder(int nOrder)
  527. {
  528. int nSize = m_vPaperGroupStruct.size();
  529. for (int i = 0; i < nSize; ++i)
  530. {
  531. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  532. for (int j = 0; j < nQuestionSize; ++j)
  533. {
  534. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  535. bool bHasContent = m_vPaperGroupStruct[i].vQuestionStruct[j].bHasContent;
  536. for (int k = 0; k < nSubQuestionSize; ++k)
  537. {
  538. CSubQuestionStruct &sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  539. sqs.bCurrent = false;
  540. if(sqs.nOrder == nOrder)
  541. {
  542. sqs.bCurrent = true;
  543. if (bHasContent)
  544. {
  545. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(m_vPaperGroupStruct[i].nNumber)).arg(m_vPaperGroupStruct[i].sGroupName).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  546. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  547. showSubQuestion(m_vPaperGroupStruct[i].vQuestionStruct[j], nOrder, sGroupTitleText, sGroupProgressText);
  548. }
  549. else
  550. {
  551. getQuestionContent(m_vPaperGroupStruct[i].vQuestionStruct[j].sQuestionId, nOrder);
  552. }
  553. }
  554. }
  555. }
  556. }
  557. refreshStatus();
  558. }
  559. void answerWidget::uploadAnswer(int nIndex, QString sAnswer)
  560. {
  561. int nSize = m_vPaperGroupStruct.size();
  562. for (int i = 0; i < nSize; ++i)
  563. {
  564. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  565. for (int j = 0; j < nQuestionSize; ++j)
  566. {
  567. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  568. for (int k = 0; k < nSubQuestionSize; ++k)
  569. {
  570. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  571. if(!sqs.bUpload)
  572. {
  573. CHttpRequestPackage hrp;
  574. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/submitQuestionAnswer");
  575. hrp.nRequestType = RequestType::rtSubmitQuestionAnswer;
  576. hrp.eParamType = HttpParamType::hptCustomBody;
  577. hrp.sParamList.push_back(QString("CustomBody,%1").arg(sAnswer));
  578. hrp.sCommonStr = QString("%1,%2").arg(sqs.nOrder).arg(sqs.nVersion);
  579. g_httpBllPtr->post(hrp);
  580. }
  581. }
  582. }
  583. }
  584. }
  585. void answerWidget::onSubmitQuestionAnswer(CSubmitQuestionAnswer submitQuestionAnswer)
  586. {
  587. if(submitQuestionAnswer.nCode == 200)
  588. {
  589. int nSize = m_vPaperGroupStruct.size();
  590. for (int i = 0; i < nSize; ++i)
  591. {
  592. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  593. for (int j = 0; j < nQuestionSize; ++j)
  594. {
  595. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  596. for (int k = 0; k < nSubQuestionSize; ++k)
  597. {
  598. CSubQuestionStruct &sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  599. if(sqs.nOrder == submitQuestionAnswer.nOrder &&
  600. submitQuestionAnswer.nVersion >= sqs.nVersion)
  601. {
  602. sqs.bUpload = true;
  603. break;
  604. }
  605. }
  606. }
  607. }
  608. }
  609. else
  610. {
  611. if(submitQuestionAnswer.sMessage.isEmpty())
  612. {
  613. ShowMsg(QString::fromLocal8Bit("提交答案失败"), g_appInfoPtr->m_pAnsBgWidget);
  614. }
  615. else
  616. {
  617. ShowMsg(submitQuestionAnswer.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  618. }
  619. }
  620. }
  621. void answerWidget::getQuestionContent(QString sQuestionId, int nOrder)
  622. {
  623. CHttpRequestPackage hrp;
  624. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/getQuestionContent")
  625. .arg(g_appInfoPtr->m_oExamInfo.nExamId);
  626. hrp.nRequestType = RequestType::rtGetQuestionContent;
  627. hrp.eParamType = HttpParamType::hptUrl;
  628. hrp.sCommonStr = sQuestionId + "," + QString::number(nOrder);
  629. hrp.sParamList.push_back(QString("questionId,%1").arg(sQuestionId));
  630. g_httpBllPtr->post(hrp);
  631. }
  632. void answerWidget::onGetQuestionContent(CGetQuestionContent getQuestionContent)
  633. {
  634. if (getQuestionContent.nCode == 200)
  635. {
  636. for (CPaperGroupStruct &pgs : m_vPaperGroupStruct)
  637. {
  638. for (CQuestionStruct &qs : pgs.vQuestionStruct)
  639. {
  640. if (qs.sQuestionId == getQuestionContent.sQuestionId)
  641. {
  642. qs.sBody = getQuestionContent.sBody;
  643. qs.sVersion = getQuestionContent.sVersion;
  644. qs.bhasAudios = getQuestionContent.bhasAudios;
  645. for (int i = 0; i < getQuestionContent.vSubQuestion.size(); ++i)
  646. {
  647. CSubQuestion sq = getQuestionContent.vSubQuestion[i];
  648. qs.vSubQuestionStruct[i].sBody = sq.sBody;
  649. qs.vSubQuestionStruct[i].vRightAnswer.swap(sq.vRightAnswer);
  650. qs.vSubQuestionStruct[i].vOptions.swap(sq.vOptions);
  651. }
  652. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(pgs.nNumber)).arg(pgs.sGroupName).arg(pgs.nTotalSubquestion);
  653. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(pgs.nAnsweredCount).arg(pgs.nTotalSubquestion);
  654. showSubQuestion(qs, getQuestionContent.sOrder.toInt(), sGroupTitleText, sGroupProgressText);
  655. break;
  656. }
  657. }
  658. }
  659. }
  660. else
  661. {
  662. if(getQuestionContent.sMessage.isEmpty())
  663. {
  664. ShowMsg(QString::fromLocal8Bit("获取题目内容失败"), g_appInfoPtr->m_pAnsBgWidget);
  665. }
  666. else
  667. {
  668. ShowMsg(getQuestionContent.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  669. }
  670. }
  671. }
  672. void answerWidget::onStartAnswer(CStartAnswer startAnswer)
  673. {
  674. if(startAnswer.nCode == 200)
  675. {
  676. m_pHeartbeatTimer->start();
  677. heartBreat();
  678. //获取活体参数
  679. if (g_appInfoPtr->m_oExamInfo.bLivenessCheck)
  680. {
  681. CHttpRequestPackage hrp;
  682. hrp.sUri = QString("/api/ecs_core/org/getOrgPropertiesByGroupWithoutCache/%1/config4Edit1")
  683. .arg(g_appInfoPtr->m_sRootOrgId);
  684. hrp.nRequestType = RequestType::rtGetOrgPropertiesByGroupWithoutCache;
  685. g_httpBllPtr->get(hrp);
  686. {
  687. CHttpRequestPackage hrp;
  688. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/startFaceLiveVerify")
  689. .arg(g_appInfoPtr->m_sRootOrgId);
  690. hrp.nRequestType = RequestType::rtStartFaceLiveVerify;
  691. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  692. hrp.eParamType = HttpParamType::hptUrl;
  693. g_httpBllPtr->post(hrp);
  694. }
  695. }
  696. }
  697. else
  698. {
  699. if(startAnswer.sMessage.isEmpty())
  700. {
  701. ShowMsg(QString::fromLocal8Bit("开始作答失败"), g_appInfoPtr->m_pAnsBgWidget);
  702. }
  703. else
  704. {
  705. ShowMsg(startAnswer.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  706. }
  707. }
  708. }
  709. void answerWidget::onGetOrgPropertiesByGroupWithoutCache(CGetOrgPropertiesByGroupWithoutCache orgProperties)
  710. {
  711. if(orgProperties.nCode == 200)
  712. {
  713. g_appInfoPtr->m_oExamInfo.nActionNum = orgProperties.nActionNum;
  714. g_appInfoPtr->m_oExamInfo.sActionOptions = orgProperties.sActionOptions;
  715. g_appInfoPtr->m_oExamInfo.sActionOrder = orgProperties.sActionOrder;
  716. g_appInfoPtr->m_oExamInfo.nActionDuration = orgProperties.nActionDuration;
  717. g_appInfoPtr->m_oExamInfo.nActionAlert = orgProperties.nActionAlert;
  718. }
  719. else
  720. {
  721. if(orgProperties.sMessage.isEmpty())
  722. {
  723. ShowMsg(QString::fromLocal8Bit("获取考试信息失败"), g_appInfoPtr->m_pAnsBgWidget);
  724. }
  725. else
  726. {
  727. ShowMsg(orgProperties.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  728. }
  729. }
  730. }
  731. void answerWidget::onStartFaceLiveVerify(CStartFaceLiveVerify startFaceLiveVerify)
  732. {
  733. if(startFaceLiveVerify.nCode == 200)
  734. {
  735. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = startFaceLiveVerify.nFaceLiveVerifyId;
  736. g_appInfoPtr->m_oExamInfo.nFaceVerifyTimes = startFaceLiveVerify.nTimes;
  737. g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute = startFaceLiveVerify.nStartMinute;
  738. bShowLivenessTip = true;
  739. }
  740. else
  741. {
  742. if(startFaceLiveVerify.sMessage.isEmpty())
  743. {
  744. ShowMsg(QString::fromLocal8Bit("开启活体验证失败"), g_appInfoPtr->m_pAnsBgWidget);
  745. }
  746. else
  747. {
  748. ShowMsg(startFaceLiveVerify.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  749. }
  750. }
  751. }
  752. void answerWidget::heartBreat()
  753. {
  754. CHttpRequestPackage hrp;
  755. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/examHeartbeat");
  756. hrp.nRequestType = RequestType::rtExamHeartbeat;
  757. g_httpBllPtr->post(hrp);
  758. }
  759. void answerWidget::onExamHeartbeat(CExamHeartbeat examHeartbeat)
  760. {
  761. if (examHeartbeat.nCode == 200)
  762. {
  763. m_nLeftSeconds = examHeartbeat.nLeftTime/1000;
  764. m_pCountDownTimer->start();
  765. //过程中人脸识别
  766. if(g_appInfoPtr->m_oExamInfo.bFaceCheck)
  767. {
  768. if(g_inProcessFace == nullptr)
  769. {
  770. g_inProcessFace = std::make_shared<CInprogressFace>();
  771. connect(g_inProcessFace.get(), &CInprogressFace::compareFailed, this, [&](QString sErrorMsg){
  772. ShowMsg(sErrorMsg, g_appInfoPtr->m_pAnsBgWidget);
  773. });
  774. startCapture();
  775. }
  776. }
  777. }
  778. else
  779. {
  780. if(examHeartbeat.sMessage.isEmpty())
  781. {
  782. ShowMsg(QString::fromLocal8Bit("考试心跳提交失败"), g_appInfoPtr->m_pAnsBgWidget);
  783. }
  784. else
  785. {
  786. ShowMsg(examHeartbeat.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  787. }
  788. }
  789. }
  790. void answerWidget::on_btn_handInPaper_clicked()
  791. {
  792. if((g_appInfoPtr->m_oExamInfo.nDuration - m_nFreezeTime)*60 < m_nLeftSeconds)
  793. {
  794. ShowMsg(QString::fromLocal8Bit("冻结时间内不允许交卷"), this);
  795. return;
  796. }
  797. if(m_pHandinPaper == nullptr)
  798. {
  799. m_pHandinPaper = std::make_shared<awHandinPaper>(ui->btn_answeredNum->text().toInt(),
  800. ui->btn_unansweredNum->text().toInt(),
  801. ui->btn_markedNum->text().toInt(), (QWidget*)(this->parent()));
  802. connect(m_pHandinPaper.get(), &awHandinPaper::handinPaper, this, [&](){
  803. m_pHandinPaper.reset();
  804. //交卷
  805. m_pCountDownTimer->stop();
  806. m_pHeartbeatTimer->stop();
  807. if(g_appInfoPtr->m_oExamInfo.bLivenessCheck)
  808. {
  809. stopCapture();
  810. }
  811. if(g_inProcessFace != nullptr)
  812. {
  813. g_inProcessFace.reset();
  814. }
  815. handinPaper();
  816. });
  817. connect(m_pHandinPaper.get(), &awHandinPaper::cancelHandinPaper, this, [&](){
  818. m_pHandinPaper.reset();
  819. });
  820. }
  821. m_pHandinPaper->show();
  822. }
  823. bool answerWidget::checkAnswer()
  824. {
  825. bool bRet = true;
  826. int nSize = m_vPaperGroupStruct.size();
  827. for (int i = 0; i < nSize; ++i)
  828. {
  829. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  830. for (int j = 0; j < nQuestionSize; ++j)
  831. {
  832. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  833. for (int k = 0; k < nSubQuestionSize; ++k)
  834. {
  835. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  836. if (!sqs.bUpload)
  837. {
  838. bRet = false;
  839. CHttpRequestPackage hrp;
  840. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/submitQuestionAnswer");
  841. hrp.nRequestType = RequestType::rtSubmitQuestionAnswer;
  842. hrp.eParamType = HttpParamType::hptCustomBody;
  843. hrp.sParamList.push_back(QString("CustomBody,%1").arg(sqs.sUploadAnswer));
  844. hrp.sCommonStr = QString("%1,%2").arg(sqs.nOrder).arg(sqs.nVersion);
  845. g_httpBllPtr->post(hrp);
  846. }
  847. }
  848. }
  849. }
  850. return bRet;
  851. }
  852. void answerWidget::handinPaper()
  853. {
  854. if(m_pResumeExam == nullptr)
  855. {
  856. m_pResumeExam = std::make_shared<awResumeExam>((QWidget*)(this->parent()), QString::fromLocal8Bit("交卷中请稍候…"));
  857. }
  858. m_pResumeExam->show();
  859. if (checkAnswer())
  860. {
  861. CHttpRequestPackage hrp;
  862. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  863. hrp.nRequestType = RequestType::rtEndExam;
  864. g_httpBllPtr->post(hrp);
  865. }
  866. else
  867. {
  868. if (m_pHandinPaperTimer == nullptr)
  869. {
  870. m_pHandinPaperTimer = std::make_shared<QTimer>();
  871. m_pHandinPaperTimer->setInterval(10 * 1000);
  872. connect(m_pHandinPaperTimer.get(), &QTimer::timeout, this, [&]() {
  873. if (checkAnswer())
  874. {
  875. m_pHandinPaperTimer->stop();
  876. CHttpRequestPackage hrp;
  877. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  878. hrp.nRequestType = RequestType::rtEndExam;
  879. g_httpBllPtr->post(hrp);
  880. }
  881. });
  882. }
  883. }
  884. }
  885. void answerWidget::onEndExam(CEndExam endExam)
  886. {
  887. if (endExam.nCode == 200)
  888. {
  889. m_pResumeExam.reset();
  890. if (g_appInfoPtr->m_oExamInfo.sExamType == EXAM_TYPES::PRACTICE)
  891. {
  892. if(g_appInfoPtr->m_oExamInfo.sPracticeType != "NO_ANSWER")
  893. {
  894. emit showPracticeInfo();
  895. }
  896. else
  897. {
  898. emit gobackCourseList();
  899. }
  900. }
  901. else
  902. {
  903. emit showExamScore();
  904. }
  905. }
  906. else
  907. {
  908. if(endExam.sMessage.isEmpty())
  909. {
  910. ShowMsg(QString::fromLocal8Bit("交卷失败"), g_appInfoPtr->m_pAnsBgWidget);
  911. }
  912. else
  913. {
  914. ShowMsg(endExam.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  915. }
  916. }
  917. }
  918. void answerWidget::on_btn_all_clicked()
  919. {
  920. int nCount = ui->lw_aw_questionList->count();
  921. for(int i = 0; i < nCount; ++i)
  922. {
  923. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  924. if(questionItem)
  925. {
  926. questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAll);
  927. }
  928. }
  929. }
  930. void answerWidget::on_btn_answered_clicked()
  931. {
  932. int nCount = ui->lw_aw_questionList->count();
  933. for(int i = 0; i < nCount; ++i)
  934. {
  935. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  936. if(questionItem)
  937. {
  938. questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAnswered);
  939. }
  940. }
  941. }
  942. void answerWidget::on_btn_unanswered_clicked()
  943. {
  944. int nCount = ui->lw_aw_questionList->count();
  945. for(int i = 0; i < nCount; ++i)
  946. {
  947. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  948. if(questionItem)
  949. {
  950. questionItem->setShowType(ITEM_SHOW_TYPE::ist_showUnanswered);
  951. }
  952. }
  953. }
  954. void answerWidget::on_btn_marked_clicked()
  955. {
  956. int nCount = ui->lw_aw_questionList->count();
  957. for(int i = 0; i < nCount; ++i)
  958. {
  959. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  960. if(questionItem)
  961. {
  962. questionItem->setShowType(ITEM_SHOW_TYPE::ist_showMarked);
  963. }
  964. }
  965. }
  966. void answerWidget::on_btn_allNum_clicked()
  967. {
  968. on_btn_all_clicked();
  969. }
  970. void answerWidget::on_btn_answeredNum_clicked()
  971. {
  972. on_btn_answered_clicked();
  973. }
  974. void answerWidget::on_btn_unansweredNum_clicked()
  975. {
  976. on_btn_unanswered_clicked();
  977. }
  978. void answerWidget::on_btn_markedNum_clicked()
  979. {
  980. on_btn_marked_clicked();
  981. }
  982. void answerWidget::startCapture()
  983. {
  984. if(m_pinitTimer == nullptr)
  985. {
  986. m_pinitTimer = std::make_shared<QTimer>();
  987. m_pinitTimer->setInterval(1000);
  988. connect(m_pinitTimer.get(), &QTimer::timeout, this, [&](){
  989. m_pinitTimer->stop();
  990. if(!m_cam.open(0))
  991. {
  992. ShowMsg(QString::fromLocal8Bit("打开摄像头失败"), this);
  993. return;
  994. }
  995. int inWidth = ui->widget_aw_face->width();
  996. m_cam.set(CV_CAP_PROP_FRAME_WIDTH, inWidth*3);
  997. int inHeight = ui->widget_aw_face->height();
  998. m_cam.set(CV_CAP_PROP_FRAME_HEIGHT, inHeight*3);
  999. m_cam.set(CV_CAP_PROP_FPS, 5);
  1000. m_pVideoTimer->start();
  1001. });
  1002. }
  1003. g_inProcessFace->startFaceVerify(true);
  1004. if(m_pVideoTimer == nullptr)
  1005. {
  1006. m_pVideoTimer = std::make_shared<QTimer>();
  1007. m_pVideoTimer->setInterval(200);
  1008. m_nLastCaptureSecond = m_nLeftSeconds;
  1009. connect(m_pVideoTimer.get(), &QTimer::timeout, this, [&](){
  1010. cv::Mat frame;
  1011. m_cam>>frame;
  1012. if(frame.empty())
  1013. {
  1014. qDebug()<<"widgetCameraTest frame is empty";
  1015. return;
  1016. }
  1017. if (g_inProcessFace != nullptr &&
  1018. m_nLastCaptureSecond - m_nLeftSeconds > g_appInfoPtr->m_oExamInfo.nSnapshotInterval)
  1019. {
  1020. m_nLastCaptureSecond = m_nLeftSeconds;
  1021. g_inProcessFace->addImage(frame);
  1022. }
  1023. QImage img = CCommonTools::Mat2QImage(frame);
  1024. ui->widget_aw_face->setAutoFillBackground(true);
  1025. QPalette palette;
  1026. palette.setBrush(QPalette::Window, QBrush(img.scaled(ui->widget_aw_face->width(), ui->widget_aw_face->height())));
  1027. ui->widget_aw_face->setPalette(palette);
  1028. });
  1029. }
  1030. m_pinitTimer->start();
  1031. }
  1032. void answerWidget::stopCapture()
  1033. {
  1034. g_inProcessFace->startFaceVerify(false);
  1035. m_pVideoTimer->stop();
  1036. if(m_cam.isOpened())
  1037. {
  1038. m_cam.release();
  1039. }
  1040. }