answerWidget.cpp 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  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. #include "popMsgBox.h"
  10. answerWidget::answerWidget(QWidget *parent) :
  11. QWidget(parent),
  12. ui(new Ui::answerWidget)
  13. {
  14. ui->setupUi(this);
  15. setStyleSheet(g_appInfoPtr->m_sQssStr);
  16. m_sRemoteList
  17. << "teamviewer"
  18. << "lookmypc"
  19. //<< "xt"
  20. << "winaw32"
  21. << "pcaquickconnect"
  22. << "sessioncontroller"
  23. << "sunlogin";
  24. // << "sunloginremote";
  25. /* << "qq"
  26. <<"wechat"
  27. <<"wemeetapp";*/
  28. m_sRemoteTipList
  29. << "TeamViewer"
  30. << "LookMyPC"
  31. //<< QString::fromLocal8Bit("协通")
  32. << "Symantec PCAnywhere"
  33. << "Symantec PCAnywhere"
  34. << "Symantec PCAnywhere"
  35. << QString::fromLocal8Bit("向日葵");
  36. // << QString::fromLocal8Bit("向日葵");
  37. /*
  38. << "QQ"
  39. << QString::fromLocal8Bit("微信")
  40. << QString::fromLocal8Bit("腾讯会议");*/
  41. qRegisterMetaType<CGetExamById>("CGetExamById");
  42. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamById, this, &answerWidget::onGetExamById);
  43. qRegisterMetaType<CGetExamRecordPaperStruct>("CGetExamRecordPaperStruct");
  44. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamRecordPaperStruct, this, &answerWidget::onGetExamRecordPaperStruct);
  45. qRegisterMetaType<CGetExamProperty>("CGetExamProperty");
  46. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamProperty, this, &answerWidget::onGetExamProperty);
  47. qRegisterMetaType<CWeiXinAnswerEnabled>("CWeiXinAnswerEnabled");
  48. connect(g_httpBllPtr.get(), &CHttpBll::sgnWeiXinAnswerEnabled, this, &answerWidget::onWeiXinAnswerEnabled);
  49. qRegisterMetaType<CGetQuestionContent>("CGetQuestionContent");
  50. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetQuestionContent, this, &answerWidget::onGetQuestionContent);
  51. qRegisterMetaType<CFindExamQuestionList>("CFindExamQuestionList");
  52. connect(g_httpBllPtr.get(), &CHttpBll::sgnFindExamQuestionList, this, &answerWidget::onFindExamQuestionList);
  53. qRegisterMetaType<CStartAnswer>("CStartAnswer");
  54. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartAnswer, this, &answerWidget::onStartAnswer);
  55. qRegisterMetaType<CExamHeartbeat>("CExamHeartbeat");
  56. connect(g_httpBllPtr.get(), &CHttpBll::sgnExamHeartbeat, this, &answerWidget::onExamHeartbeat);
  57. qRegisterMetaType<CSubmitQuestionAnswer>("CSubmitQuestionAnswer");
  58. connect(g_httpBllPtr.get(), &CHttpBll::sgnSubmitQuestionAnswer, this, &answerWidget::onSubmitQuestionAnswer);
  59. qRegisterMetaType<CEndExam>("CEndExam");
  60. connect(g_httpBllPtr.get(), &CHttpBll::sgnEndExam, this, &answerWidget::onEndExam);
  61. // qRegisterMetaType<CGetOrgPropertiesByGroupWithoutCache>("CGetOrgPropertiesByGroupWithoutCache");
  62. // connect(g_httpBllPtr.get(), &CHttpBll::sgnGetOrgPropertiesByGroupWithoutCache, this, &answerWidget::onGetOrgPropertiesByGroupWithoutCache);
  63. qRegisterMetaType<CStartFaceLiveVerify>("CStartFaceLiveVerify");
  64. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartFaceLiveVerify, this, &answerWidget::onStartFaceLiveVerify);
  65. #ifdef _DEBUG
  66. //g_appInfoPtr->m_oExamInfo.bLivenessCheck = false;
  67. // g_appInfoPtr->m_oExamInfo.bFaceCheck = false;
  68. #endif // _DEBUG
  69. //m_MonitorEnumeratorPtr = std::make_shared<CMultiMonitorEnumerator>();
  70. m_nLeftSeconds = 0;
  71. m_nHeartBreatFailedCount = 0;
  72. bShowLeftHint = false;
  73. GetExamProperty();
  74. // CHttpRequestPackage hrp;
  75. // hrp.sUri = QString("/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/%1/%2")
  76. // .arg(g_appInfoPtr->m_oExamInfo.nExamId).arg("SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME,PRACTICE_TYPE");
  77. // hrp.nRequestType = RequestType::rtGetExamProperty;
  78. // hrp.sCommonStr = "SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME";
  79. // g_httpBllPtr->get(hrp);
  80. // {
  81. // CHttpRequestPackage hrp;
  82. // hrp.sUri = QString("/api/ecs_exam_work/exam/%1").arg(g_appInfoPtr->m_oExamInfo.nExamId);
  83. // hrp.nRequestType = RequestType::rtGetExamById;
  84. // g_httpBllPtr->get(hrp);
  85. // }
  86. // CHttpRequestPackage hrp1;
  87. // hrp1.sUri = "/api/ecs_oe_student/client/exam/process/getExamRecordPaperStruct";
  88. // hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  89. // hrp1.nRequestType = RequestType::rtGetExamRecordPaperStruct;
  90. // hrp1.eParamType = HttpParamType::hptUrl;
  91. // g_httpBllPtr->post(hrp1);
  92. // {
  93. // CHttpRequestPackage hrp;
  94. // hrp.sUri = "/api/ecs_oe_student/client/exam/process/findExamQuestionList";
  95. // hrp.nRequestType = RequestType::rtFindExamQuestionList;
  96. // g_httpBllPtr->post(hrp);
  97. // }
  98. // {
  99. // CHttpRequestPackage hrp;
  100. // hrp.sUri = QString("/api/ecs_exam_work/exam/weixinAnswerEnabled/%1")
  101. // .arg(g_appInfoPtr->m_oExamInfo.nExamId);
  102. // hrp.sParamList.push_back(QString::fromLocal8Bit("courseCode,%1").arg(g_appInfoPtr->m_oExamInfo.sCourseCode));
  103. // hrp.nRequestType = RequestType::rtWeiXinAnswerEnabled;
  104. // g_httpBllPtr->get(hrp);
  105. // }
  106. m_pCountDownTimer = std::make_shared<QTimer>();
  107. m_pCountDownTimer->setInterval(1000);
  108. connect(m_pCountDownTimer.get(), &QTimer::timeout, this, [&](){
  109. --m_nLeftSeconds;
  110. ui->label_lastTime->setText(QString("%1:%2:%3").arg(m_nLeftSeconds/60/60, 2, 10, QChar('0'))
  111. .arg(m_nLeftSeconds/60%60, 2, 10, QChar('0'))
  112. .arg(m_nLeftSeconds%60, 2, 10, QChar('0')));
  113. if(m_nLeftSeconds <= 0)
  114. {
  115. // m_pCountDownTimer->stop();
  116. handinPaper();
  117. }
  118. if(m_nLeftSeconds <= 5*60 &&
  119. m_nLeftSeconds >= 5 * 60 - 5 &&
  120. !bShowLeftHint)
  121. {
  122. bShowLeftHint = true;
  123. if(m_ptimeLeftTips == nullptr)
  124. {
  125. m_ptimeLeftTips = std::make_shared<awTimeLeftTips>(MASK_POP_WIDGET_TYPE::wt_timeLeft, (QWidget*)(this->parent()));
  126. connect(m_ptimeLeftTips.get(), &awTimeLeftTips::timeLeftConfirm, this, [&](){
  127. m_ptimeLeftTips.reset();
  128. });
  129. }
  130. m_ptimeLeftTips->show();
  131. }
  132. if(g_appInfoPtr->m_oExamInfo.bLivenessCheck &&
  133. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId > 0)
  134. {
  135. if(bShowLivenessTip && (m_nUsedExamSeconds + m_nEnterExamTime - m_nLeftSeconds + g_appInfoPtr->m_oExamInfo.nActionAlert) > g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute*60)
  136. {
  137. bShowLivenessTip = false;
  138. m_nEnterLivenessFaceSeconds = m_nLeftSeconds - 20;
  139. ShowMsg(QString::fromLocal8Bit("%1秒后开始指定动作检测,请准备!").arg(g_appInfoPtr->m_oExamInfo.nActionAlert), g_appInfoPtr->m_pAnsBgWidget);
  140. }
  141. if((m_nUsedExamSeconds + m_nEnterExamTime - m_nLeftSeconds) > g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute * 60
  142. && m_nEnterLivenessFaceSeconds > m_nLeftSeconds)
  143. {
  144. //活体检测
  145. if(m_pFaceLiveness == nullptr)
  146. {
  147. stopCapture();
  148. m_pFaceLiveness = std::make_shared<faceLiveness>(FACE_LIVENESS_TYPE::flt_inprogress, g_appInfoPtr->m_pAnsBgWidget);
  149. connect(m_pFaceLiveness.get(), &faceLiveness::faceLivenessFaild, this, [&](){
  150. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = 0;
  151. m_pFaceLiveness.reset();
  152. if(g_appInfoPtr->m_oExamInfo.nFaceVerifyTimes < 2)
  153. {
  154. emit gobackLogin();
  155. }
  156. else
  157. {
  158. //交卷
  159. handinPaper(true);
  160. }
  161. });
  162. connect(m_pFaceLiveness.get(), &faceLiveness::faceLivenessSucceed, this, [&](){
  163. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = 0;
  164. m_pFaceLiveness.reset();
  165. if (g_appInfoPtr->m_oExamInfo.bFaceCheck)
  166. {
  167. startCapture();
  168. }
  169. });
  170. m_pFaceLiveness->show();
  171. }
  172. }
  173. }
  174. });
  175. if (g_appInfoPtr->m_bDisableRemoteAssistance)
  176. {
  177. qRegisterMetaType<CGetSoftwareConfig>("CGetSoftwareConfig");
  178. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetSoftwareConfig, this, &answerWidget::onGetSoftwareConfig);
  179. CHttpRequestPackage hrp;
  180. hrp.sUri = QString("https://%1/oe_client/software.json").arg(g_appInfoPtr->m_sEscDomain);
  181. hrp.nRequestType = RequestType::rtGetSoftwareConfig;
  182. g_httpBllPtr->getUrl(hrp);
  183. }
  184. m_pHeartbeatTimer = std::make_shared<QTimer>();
  185. m_pHeartbeatTimer->setInterval(60*1000);
  186. connect(m_pHeartbeatTimer.get(), &QTimer::timeout, this, [&](){
  187. heartBreat();
  188. if(g_appInfoPtr->m_bDisableRemoteAssistance)
  189. {
  190. checkRemoteBreach();
  191. }
  192. });
  193. }
  194. answerWidget::~answerWidget()
  195. {
  196. awMsgBox::clear(this);
  197. if (g_inProcessFace)
  198. {
  199. stopCapture();
  200. g_inProcessFace.reset();
  201. }
  202. delete ui;
  203. }
  204. void answerWidget::GetExamProperty()
  205. {
  206. CHttpRequestPackage hrp;
  207. hrp.sUri = QString("/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/%1/%2")
  208. .arg(g_appInfoPtr->m_oExamInfo.nExamId).arg("SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME,PRACTICE_TYPE");
  209. hrp.nRequestType = RequestType::rtGetExamProperty;
  210. hrp.sCommonStr = "SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME";
  211. g_httpBllPtr->get(hrp);
  212. }
  213. void answerWidget::GetExamById()
  214. {
  215. CHttpRequestPackage hrp;
  216. hrp.sUri = QString("/api/ecs_exam_work/exam/%1").arg(g_appInfoPtr->m_oExamInfo.nExamId);
  217. hrp.nRequestType = RequestType::rtGetExamById;
  218. g_httpBllPtr->get(hrp);
  219. }
  220. void answerWidget::GetExamRecordPaperStruct()
  221. {
  222. CHttpRequestPackage hrp1;
  223. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/getExamRecordPaperStruct";
  224. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  225. hrp1.nRequestType = RequestType::rtGetExamRecordPaperStruct;
  226. hrp1.eParamType = HttpParamType::hptUrl;
  227. g_httpBllPtr->post(hrp1);
  228. }
  229. void answerWidget::FindExamQuestionList()
  230. {
  231. CHttpRequestPackage hrp;
  232. hrp.sUri = "/api/ecs_oe_student/client/exam/process/findExamQuestionList";
  233. hrp.nRequestType = RequestType::rtFindExamQuestionList;
  234. g_httpBllPtr->post(hrp);
  235. }
  236. void answerWidget::WeiXinAnswerEnabled()
  237. {
  238. CHttpRequestPackage hrp;
  239. hrp.sUri = QString("/api/ecs_exam_work/exam/weixinAnswerEnabled/%1")
  240. .arg(g_appInfoPtr->m_oExamInfo.nExamId);
  241. hrp.sParamList.push_back(QString::fromLocal8Bit("courseCode,%1").arg(g_appInfoPtr->m_oExamInfo.sCourseCode));
  242. hrp.nRequestType = RequestType::rtWeiXinAnswerEnabled;
  243. g_httpBllPtr->get(hrp);
  244. }
  245. void answerWidget::onGetSoftwareConfig(CGetSoftwareConfig getSoftwareConfig)
  246. {
  247. if (getSoftwareConfig.nCode == 200)
  248. {
  249. QString sSoftwareConfig = QByteArray::fromBase64(getSoftwareConfig.sSoftwareConfig.toLocal8Bit());
  250. if(!sSoftwareConfig.isEmpty())
  251. {
  252. Json::Reader reader;
  253. Json::Value jsonRoot = Json::Value::null;
  254. if (reader.parse(sSoftwareConfig.toStdString(), jsonRoot))
  255. {
  256. QString sCamera = jsonRoot["vCamList"].asString().c_str();
  257. QStringList cameraList = sCamera.split("\n", QString::SkipEmptyParts);
  258. QString sRemoteApp = jsonRoot["remoteApp"].asString().c_str();
  259. QStringList remoteAppList = sRemoteApp.split("\n", QString::SkipEmptyParts);
  260. m_sRemoteList += remoteAppList;
  261. m_sRemoteTipList += remoteAppList;
  262. }
  263. }
  264. }
  265. }
  266. void answerWidget::checkRemoteBreach()
  267. {
  268. static int nIndex = 0;
  269. ++nIndex;
  270. if(nIndex % 3 == 0)
  271. {
  272. std::shared_ptr<CMultiMonitorEnumerator> m_MonitorEnumeratorPtr = std::make_shared<CMultiMonitorEnumerator>();
  273. bool bExit = false;
  274. QString sCheckStr = "";
  275. if (CCommonTools::isUseRDP())
  276. {
  277. sCheckStr = QString::fromLocal8Bit("检测是否开启远程桌面");
  278. qDebug() << QString::fromLocal8Bit("开启远程桌面");
  279. bExit = true;
  280. }
  281. if (m_MonitorEnumeratorPtr->getMontorNumber() > 1)
  282. {
  283. sCheckStr = QString::fromLocal8Bit("请检测是否开启分屏");
  284. qDebug() << QString::fromLocal8Bit("开启双屏");
  285. bExit = true;
  286. }
  287. QStringList appList;
  288. CCommonTools::getAllAppNameList(appList, m_sRemoteList, m_sRemoteTipList);
  289. if (appList.count() > 0)
  290. {
  291. bExit = true;
  292. for (int i = 0; i < appList.count(); i++)
  293. {
  294. if (sCheckStr.isEmpty())
  295. {
  296. sCheckStr = QString::fromLocal8Bit("请检测是否开启%1").arg(appList[i]);
  297. }
  298. else
  299. {
  300. sCheckStr += QString::fromLocal8Bit("、%1").arg(appList[i]);
  301. }
  302. }
  303. }
  304. QApplication::processEvents();
  305. if (bExit)
  306. {
  307. //退出
  308. awTimeLeftTips *wExitExam = new awTimeLeftTips(MASK_POP_WIDGET_TYPE::wt_exitExam, (QWidget*)(this->parent()));
  309. wExitExam->setText(sCheckStr, QString::fromLocal8Bit("退出考试"));
  310. connect(wExitExam, &awTimeLeftTips::timeLeftConfirm, this, [this, wExitExam]() {
  311. if (m_pNetWorkErrorTimerPtr)
  312. {
  313. m_pNetWorkErrorTimerPtr->stop();
  314. }
  315. delete wExitExam;
  316. emit gobackLogin();
  317. });
  318. wExitExam->show();
  319. if (m_pNetWorkErrorTimerPtr == nullptr)
  320. {
  321. m_pNetWorkErrorTimerPtr = std::make_shared<QTimer>();
  322. m_pNetWorkErrorTimerPtr->setInterval(30 * 1000);
  323. connect(m_pNetWorkErrorTimerPtr.get(), &QTimer::timeout, [this, wExitExam]() {
  324. m_pNetWorkErrorTimerPtr->stop();
  325. delete wExitExam;
  326. emit gobackLogin();
  327. });
  328. }
  329. m_pNetWorkErrorTimerPtr->start();
  330. }
  331. }
  332. }
  333. void answerWidget::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
  334. {
  335. setGeometry(nLeft, nTop, nWidth, nHeight);
  336. ui->widget_aw_answerBG->setGeometry(0, 0, width()*970/(970+270), height());
  337. ui->widget_navigate->setGeometry(ui->widget_aw_answerBG->x() + ui->widget_aw_answerBG->width() + g_appInfoPtr->m_fRate*20, 0,
  338. width() - ui->widget_aw_answerBG->width() - g_appInfoPtr->m_fRate*20, height());
  339. ui->widget_aw_face->setGeometry(0, ui->widget_navigate->height() - g_appInfoPtr->m_fRate*140, ui->widget_navigate->width(), g_appInfoPtr->m_fRate*140);
  340. ui->widget_aw_top->setGeometry(0, 0, ui->widget_aw_answerBG->width(), g_appInfoPtr->m_fRate*56);
  341. ui->widget_ng_top->setGeometry(0, 0, ui->widget_navigate->width(), g_appInfoPtr->m_fRate*56);
  342. ui->label_answerProgress->adjustSize();
  343. ui->label_answerProgress->setGeometry(g_appInfoPtr->m_fRate*20, (ui->widget_aw_top->height() - ui->label_answerProgress->height())/2,
  344. ui->label_answerProgress->width(), ui->label_answerProgress->height());
  345. ui->pgb_answerProgress->setGeometry(ui->label_answerProgress->x() + ui->label_answerProgress->width() + g_appInfoPtr->m_fRate*8,
  346. (ui->widget_aw_top->height() - g_appInfoPtr->m_fRate*20)/2,
  347. g_appInfoPtr->m_fRate*200, g_appInfoPtr->m_fRate*20);
  348. ui->btn_handInPaper->setGeometry(ui->widget_aw_top->width() - g_appInfoPtr->m_fRate*(10 + 100), g_appInfoPtr->m_fRate*10,
  349. g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*36);
  350. ui->label_lastTimeIcon->setGeometry(g_appInfoPtr->m_fRate*48, g_appInfoPtr->m_fRate*12, g_appInfoPtr->m_fRate*32, g_appInfoPtr->m_fRate*32);
  351. ui->label_lastTime->adjustSize();
  352. ui->label_lastTime->setGeometry(ui->label_lastTimeIcon->x() + ui->label_lastTimeIcon->width() + g_appInfoPtr->m_fRate*10,
  353. ui->label_lastTimeIcon->y() + (ui->label_lastTimeIcon->height() - ui->label_lastTime->height())/2,
  354. ui->label_lastTime->width(), ui->label_lastTime->height());
  355. ui->btn_all->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_ng_top->height() + g_appInfoPtr->m_fRate*20,
  356. g_appInfoPtr->m_fRate*90, g_appInfoPtr->m_fRate*28);
  357. 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,
  358. g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*20);
  359. ui->btn_answered->setGeometry(ui->btn_all->x() + ui->btn_all->width() + g_appInfoPtr->m_fRate*10,
  360. ui->btn_all->y(), ui->btn_all->width(), ui->btn_all->height());
  361. ui->btn_answeredNum->setGeometry(ui->btn_answered->x() + ui->btn_answered->width() - g_appInfoPtr->m_fRate*(4 + 30), ui->btn_allNum->y(),
  362. ui->btn_allNum->width(), ui->btn_allNum->height());
  363. ui->btn_unanswered->setGeometry(ui->btn_all->x(), ui->btn_all->y() + ui->btn_all->height() + g_appInfoPtr->m_fRate*10,
  364. ui->btn_all->width(), ui->btn_all->height());
  365. ui->btn_unansweredNum->setGeometry(ui->btn_allNum->x(), ui->btn_unanswered->y() + (ui->btn_unanswered->height() - g_appInfoPtr->m_fRate*20)/2,
  366. ui->btn_allNum->width(), ui->btn_allNum->height());
  367. ui->btn_marked->setGeometry(ui->btn_answered->x(), ui->btn_unanswered->y(), ui->btn_all->width(), ui->btn_all->height());
  368. ui->btn_markedNum->setGeometry(ui->btn_answeredNum->x(), ui->btn_unansweredNum->y(), ui->btn_allNum->width(), ui->btn_allNum->height());
  369. ui->label_HLine->setGeometry(ui->btn_all->x(), ui->btn_unanswered->y() + ui->btn_unanswered->height() + g_appInfoPtr->m_fRate*20,
  370. ui->widget_navigate->width() - ui->btn_all->x()*2, g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1);
  371. ui->lw_aw_questionList->setGeometry(0, ui->label_HLine->y(), ui->widget_navigate->width(),
  372. ui->widget_aw_face->y() - ui->label_HLine->y() - ui->label_HLine->height());
  373. }
  374. void answerWidget::onGetExamById(CGetExamById getExamById)
  375. {
  376. if (getExamById.nCode == 200)
  377. {
  378. m_nRetryCount = 0;
  379. g_appInfoPtr->m_oExamInfo.nExamId = getExamById.nId;
  380. g_appInfoPtr->m_oExamInfo.sExamType = getExamById.sExamType;
  381. g_appInfoPtr->m_oExamInfo.nDuration = getExamById.nDuration;
  382. GetExamRecordPaperStruct();
  383. }
  384. else
  385. {
  386. // if(getExamById.sMessage.isEmpty())
  387. // {
  388. // ShowMsg(QString::fromLocal8Bit("获取考试信息出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  389. // }
  390. // else
  391. // {
  392. // ShowMsg(getExamById.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  393. // }
  394. if(++m_nRetryCount > 3)
  395. {
  396. //退出
  397. exitExamTip();
  398. }
  399. else
  400. {
  401. GetExamById();
  402. }
  403. }
  404. }
  405. void answerWidget::onGetExamRecordPaperStruct(CGetExamRecordPaperStruct getExamRecordPaperStruct)
  406. {
  407. if (getExamRecordPaperStruct.nCode == 200)
  408. {
  409. m_nRetryCount = 0;
  410. m_vPaperGroupStruct.swap(getExamRecordPaperStruct.vPaperGroupStruct);
  411. int nSize = m_vPaperGroupStruct.size();
  412. QString sQuestionId = "";
  413. for (int i = 0; i < nSize; ++i)
  414. {
  415. CPaperGroupStruct &pgs = m_vPaperGroupStruct[i];
  416. awQuestionNavigate *questionItem = new awQuestionNavigate(pgs);
  417. connect(questionItem, &awQuestionNavigate::showSubQuestion, this, [&](QString sQuestionId, int nOrder, bool bHasContent) {
  418. showQuestionByOrder(nOrder);
  419. /*if (bHasContent)
  420. {
  421. for (CQuestionStruct &qs : pgs.vQuestionStruct)
  422. {
  423. if (qs.sQuestionId == sQuestionId)
  424. {
  425. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(pgs.nNumber)).arg(pgs.sGroupName).arg(pgs.nTotalSubquestion);
  426. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(pgs.nAnsweredCount).arg(pgs.nTotalSubquestion);
  427. showSubQuestion(qs, nOrder, sGroupTitleText, sGroupProgressText);
  428. }
  429. }
  430. }
  431. else
  432. {
  433. getQuestionContent(sQuestionId, nOrder);
  434. }
  435. */
  436. });
  437. QListWidgetItem *pItem = new QListWidgetItem;
  438. ui->lw_aw_questionList->addItem(pItem);
  439. ui->lw_aw_questionList->setItemWidget(pItem, questionItem);
  440. int nHeight = questionItem->setUI(ui->lw_aw_questionList->width() - g_appInfoPtr->m_fRate*60);
  441. QSize size = pItem->sizeHint();
  442. size.setHeight(nHeight);
  443. pItem->setSizeHint(size);
  444. }
  445. WeiXinAnswerEnabled();
  446. }
  447. else
  448. {
  449. // if(getExamRecordPaperStruct.sMessage.isEmpty())
  450. // {
  451. // ShowMsg(QString::fromLocal8Bit("获取考试结构出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  452. // }
  453. // else
  454. // {
  455. // ShowMsg(getExamRecordPaperStruct.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  456. // }
  457. if(++m_nRetryCount > 3)
  458. {
  459. //退出
  460. exitExamTip();
  461. }
  462. else
  463. {
  464. GetExamRecordPaperStruct();
  465. }
  466. }
  467. }
  468. CAnsweredQuestion answerWidget::findQuestionByOrder(CFindExamQuestionList &feql, int nOrder)
  469. {
  470. for (int i = 0; i < feql.vAnsweredQuestion.size(); ++i)
  471. {
  472. if (feql.vAnsweredQuestion[i].nOrder == nOrder)
  473. {
  474. return feql.vAnsweredQuestion[i];
  475. }
  476. }
  477. }
  478. void answerWidget::onFindExamQuestionList(CFindExamQuestionList findExamQuestionList)
  479. {
  480. if (findExamQuestionList.nCode == 200)
  481. {
  482. m_nRetryCount = 0;
  483. int nTotal = 0;
  484. int nAnswered = 0;
  485. int nMarked = 0;
  486. int nSize = m_vPaperGroupStruct.size();
  487. for (int i = 0; i < nSize; ++i)
  488. {
  489. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  490. for (int j = 0; j < nQuestionSize; ++j)
  491. {
  492. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  493. for (int k = 0; k < nSubQuestionSize; ++k)
  494. {
  495. nTotal++;
  496. int nOrder = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].nOrder;
  497. CAnsweredQuestion aq= findQuestionByOrder(findExamQuestionList, nOrder);
  498. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].bAnswered = aq.bIsAnswer;
  499. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].bMarked = aq.bIsSign;
  500. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].sStudentAnswer = aq.sStudentAnswer;
  501. if(!aq.sStudentAnswer.isEmpty() && (aq.sQuestionType == QUESTION_TYPE::SingleChoice ||
  502. aq.sQuestionType == QUESTION_TYPE::MultipleChoice ||
  503. aq.sQuestionType == QUESTION_TYPE::TrueOrFalse))
  504. {
  505. Json::Reader reader;
  506. Json::Value jAnswer = Json::Value::null;
  507. if (!reader.parse(aq.sStudentAnswer.toStdString(), jAnswer))
  508. {
  509. // ShowMsg(QString::fromLocal8Bit("解析题干出错!"), g_appInfoPtr->m_answerWidget);
  510. myDebug() << QString::fromLocal8Bit("解析答案出错!");
  511. }
  512. QString sAnswer = "";
  513. int nSize = jAnswer["sections"].size();
  514. for(int i = 0; i < nSize; ++i)
  515. {
  516. int bSize = jAnswer["sections"][i]["blocks"].size();
  517. for(int j = 0; j < bSize; ++j)
  518. {
  519. if(jAnswer["sections"][i]["blocks"][j]["type"] == "text")
  520. {
  521. sAnswer += jAnswer["sections"][i]["blocks"][j]["value"].asString().c_str();
  522. }
  523. }
  524. }
  525. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].sStudentAnswer = sAnswer;
  526. }
  527. if (aq.bIsAnswer)
  528. {
  529. nAnswered++;
  530. }
  531. if (aq.bIsSign)
  532. {
  533. nMarked++;
  534. }
  535. if (!aq.sAudioPlayTimes.isEmpty())
  536. {
  537. Json::Reader reader;
  538. Json::Value jAudioPlayTimes = Json::Value::null;
  539. if (reader.parse(aq.sAudioPlayTimes.toStdString(), jAudioPlayTimes))
  540. {
  541. for (int ja = 0; ja < jAudioPlayTimes.size(); ++ja)
  542. {
  543. Json::Value jAudioPlayItem = jAudioPlayTimes[ja];
  544. g_appInfoPtr->m_jAudioPlayedCount[jAudioPlayItem["name"].asString()] = jAudioPlayItem["times"].asInt();
  545. }
  546. }
  547. }
  548. }
  549. }
  550. }
  551. showQuestionByOrder(1);
  552. on_btn_all_clicked();
  553. ui->btn_allNum->setText(QString::number(nTotal));
  554. ui->btn_answeredNum->setText(QString::number(nAnswered));
  555. ui->btn_markedNum->setText(QString::number(nMarked));
  556. ui->btn_unansweredNum->setText(QString::number(nTotal - nAnswered));
  557. ui->pgb_answerProgress->setMaximum(nTotal);
  558. ui->pgb_answerProgress->setValue(nAnswered);
  559. refreshStatus();
  560. //开始答题
  561. startAnwer();
  562. }
  563. else
  564. {
  565. // if(findExamQuestionList.sMessage.isEmpty())
  566. // {
  567. // ShowMsg(QString::fromLocal8Bit("获取题目信息出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  568. // }
  569. // else
  570. // {
  571. // ShowMsg(findExamQuestionList.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  572. // }
  573. if(++m_nRetryCount > 3)
  574. {
  575. //退出
  576. exitExamTip();
  577. }
  578. else
  579. {
  580. FindExamQuestionList();
  581. }
  582. }
  583. }
  584. void answerWidget::startAnwer()
  585. {
  586. CHttpRequestPackage hrp1;
  587. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/startAnswer";
  588. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  589. hrp1.nRequestType = RequestType::rtStartAnswer;
  590. hrp1.eParamType = HttpParamType::hptUrl;
  591. g_httpBllPtr->post(hrp1);
  592. }
  593. void answerWidget::onGetExamProperty(CGetExamProperty getExamProperty)
  594. {
  595. if (getExamProperty.nCode == 200)
  596. {
  597. m_nRetryCount = 0;
  598. if (getExamProperty.sType == "SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME")
  599. {
  600. m_nSnapshotInterval = getExamProperty.nSnapshotInterval;
  601. g_appInfoPtr->m_oExamInfo.sPracticeType = getExamProperty.sPracticeType;
  602. m_nFreezeTime = getExamProperty.nFreezeTime;
  603. }
  604. GetExamById();
  605. }
  606. else
  607. {
  608. // if(getExamProperty.sMessage.isEmpty())
  609. // {
  610. // ShowMsg(QString::fromLocal8Bit("获取考试信息出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  611. // }
  612. // else
  613. // {
  614. // ShowMsg(getExamProperty.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  615. // }
  616. if(++m_nRetryCount > 3)
  617. {
  618. //退出
  619. exitExamTip();
  620. }
  621. else
  622. {
  623. GetExamProperty();
  624. }
  625. }
  626. }
  627. void answerWidget::onWeiXinAnswerEnabled(CWeiXinAnswerEnabled weiXinAnswerEnabled)
  628. {
  629. if (weiXinAnswerEnabled.nCode == 200)
  630. {
  631. m_nRetryCount = 0;
  632. g_appInfoPtr->m_bWeiXinAnswerEnabled = weiXinAnswerEnabled.bEnabled;
  633. FindExamQuestionList();
  634. }
  635. else
  636. {
  637. // if(weiXinAnswerEnabled.sMessage.isEmpty())
  638. // {
  639. // ShowMsg(QString::fromLocal8Bit("获取考试信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  640. // }
  641. // else
  642. // {
  643. // ShowMsg(weiXinAnswerEnabled.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  644. // }
  645. if(++m_nRetryCount > 3)
  646. {
  647. //退出
  648. exitExamTip();
  649. }
  650. else
  651. {
  652. WeiXinAnswerEnabled();
  653. }
  654. }
  655. }
  656. void answerWidget::showSubQuestion(CQuestionStruct &qs, int nOrder, QString sTitle, QString sProgress)
  657. {
  658. if (qs.sBody.isEmpty())
  659. {
  660. if (m_pQuestion != nullptr)
  661. {
  662. m_pQuestion.reset();
  663. }
  664. if (m_pQuestionSet != nullptr)
  665. {
  666. m_pQuestionSet.reset();
  667. }
  668. m_pQuestion = std::make_shared<question>(qs, nOrder, ui->btn_allNum->text().toInt(), ui->widget_aw_answerBG);
  669. connect(m_pQuestion.get(), &question::uploadAnswer, this, [&](int nIndex, __int64 timeStamp, QString sAnswer){
  670. uploadAnswer(nIndex, sAnswer);
  671. });
  672. connect(m_pQuestion.get(), &question::questionAnswered, this, [&](bool bAnswered, int nIndex){
  673. refreshStatus();
  674. int nSize = m_vPaperGroupStruct.size();
  675. for (int i = 0; i < nSize; ++i)
  676. {
  677. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  678. for (int j = 0; j < nQuestionSize; ++j)
  679. {
  680. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  681. for (int k = 0; k < nSubQuestionSize; ++k)
  682. {
  683. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  684. if(sqs.nOrder == nIndex)
  685. {
  686. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  687. m_pQuestion->setGroupInfo("", sGroupProgressText);
  688. break;
  689. }
  690. }
  691. }
  692. }
  693. });
  694. connect(m_pQuestion.get(), &question::markedItem, this, [&](bool bMarked, int nIndex){
  695. refreshStatus();
  696. });
  697. connect(m_pQuestion.get(), &question::previousQuestion, this, [&](int nOrder){
  698. if(nOrder > 1)
  699. {
  700. showQuestionByOrder(nOrder - 1);
  701. }
  702. });
  703. connect(m_pQuestion.get(), &question::nextQuestion, this, [&](int nOrder){
  704. showQuestionByOrder(nOrder + 1);
  705. });
  706. m_pQuestion->setGroupInfo(sTitle, sProgress);
  707. m_pQuestion->setUI(0, g_appInfoPtr->m_fRate * 86,
  708. ui->widget_aw_answerBG->width(), ui->widget_aw_answerBG->height() - g_appInfoPtr->m_fRate * (86 + 20));
  709. m_pQuestion->show();
  710. }
  711. else
  712. {
  713. if (m_pQuestion != nullptr)
  714. {
  715. m_pQuestion.reset();
  716. }
  717. if (m_pQuestionSet != nullptr)
  718. {
  719. m_pQuestionSet.reset();
  720. }
  721. m_pQuestionSet = std::make_shared<questionSet>(qs, nOrder, ui->btn_allNum->text().toInt(), ui->widget_aw_answerBG);
  722. connect(m_pQuestionSet.get(), &questionSet::uploadAnswer, this, [&](int nIndex, __int64 timeStamp, QString sAnswer){
  723. uploadAnswer(nIndex, sAnswer);
  724. });
  725. connect(m_pQuestionSet.get(), &questionSet::questionAnswered, this, [&](bool bAnswered, int nIndex){
  726. refreshStatus();
  727. int nSize = m_vPaperGroupStruct.size();
  728. for (int i = 0; i < nSize; ++i)
  729. {
  730. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  731. for (int j = 0; j < nQuestionSize; ++j)
  732. {
  733. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  734. for (int k = 0; k < nSubQuestionSize; ++k)
  735. {
  736. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  737. if(sqs.nOrder == nIndex)
  738. {
  739. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  740. m_pQuestionSet->setGroupInfo("", sGroupProgressText);
  741. break;
  742. }
  743. }
  744. }
  745. }
  746. });
  747. connect(m_pQuestionSet.get(), &questionSet::markedItem, this, [&](bool bMarked, int nIndex){
  748. refreshStatus();
  749. });
  750. connect(m_pQuestionSet.get(), &questionSet::previousQuestion, this, [&](int nOrder){
  751. if(nOrder > 1)
  752. {
  753. showQuestionByOrder(nOrder - 1);
  754. }
  755. });
  756. connect(m_pQuestionSet.get(), &questionSet::nextQuestion, this, [&](int nOrder){
  757. showQuestionByOrder(nOrder + 1);
  758. });
  759. m_pQuestionSet->setGroupInfo(sTitle, sProgress);
  760. m_pQuestionSet->setUI(0, g_appInfoPtr->m_fRate * 86,
  761. ui->widget_aw_answerBG->width(), ui->widget_aw_answerBG->height() - g_appInfoPtr->m_fRate * (86 + 20));
  762. m_pQuestionSet->show();
  763. }
  764. }
  765. void answerWidget::refreshStatus()
  766. {
  767. int nCount = ui->lw_aw_questionList->count();
  768. for(int i = 0; i < nCount; ++i)
  769. {
  770. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  771. if(questionItem)
  772. {
  773. questionItem->refreshStatus();
  774. }
  775. }
  776. int nTotal = 0;
  777. int nAnswered = 0;
  778. int nMarked = 0;
  779. int nSize = m_vPaperGroupStruct.size();
  780. for (int i = 0; i < nSize; ++i)
  781. {
  782. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  783. int nAnswerCount = 0;
  784. for (int j = 0; j < nQuestionSize; ++j)
  785. {
  786. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  787. for (int k = 0; k < nSubQuestionSize; ++k)
  788. {
  789. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  790. nTotal++;
  791. if (sqs.bAnswered)
  792. {
  793. nAnswerCount++;
  794. nAnswered++;
  795. }
  796. if (sqs.bMarked)
  797. {
  798. nMarked++;
  799. }
  800. }
  801. }
  802. m_vPaperGroupStruct[i].nAnsweredCount = nAnswerCount;
  803. }
  804. ui->btn_allNum->setText(QString::number(nTotal));
  805. ui->btn_answeredNum->setText(QString::number(nAnswered));
  806. ui->btn_markedNum->setText(QString::number(nMarked));
  807. ui->btn_unansweredNum->setText(QString::number(nTotal - nAnswered));
  808. ui->pgb_answerProgress->setMaximum(nTotal);
  809. ui->pgb_answerProgress->setValue(nAnswered);
  810. }
  811. void answerWidget::showQuestionByOrder(int nOrder)
  812. {
  813. int nSize = m_vPaperGroupStruct.size();
  814. for (int i = 0; i < nSize; ++i)
  815. {
  816. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  817. for (int j = 0; j < nQuestionSize; ++j)
  818. {
  819. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  820. bool bHasContent = m_vPaperGroupStruct[i].vQuestionStruct[j].bHasContent;
  821. for (int k = 0; k < nSubQuestionSize; ++k)
  822. {
  823. CSubQuestionStruct &sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  824. sqs.bCurrent = false;
  825. if(sqs.nOrder == nOrder)
  826. {
  827. sqs.bCurrent = true;
  828. if (bHasContent)
  829. {
  830. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(m_vPaperGroupStruct[i].nNumber)).arg(m_vPaperGroupStruct[i].sGroupName).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  831. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  832. showSubQuestion(m_vPaperGroupStruct[i].vQuestionStruct[j], nOrder, sGroupTitleText, sGroupProgressText);
  833. }
  834. else
  835. {
  836. getQuestionContent(m_vPaperGroupStruct[i].vQuestionStruct[j].sQuestionId, nOrder);
  837. }
  838. }
  839. }
  840. }
  841. }
  842. refreshStatus();
  843. }
  844. void answerWidget::uploadAnswer(int nIndex, QString sAnswer)
  845. {
  846. int nSize = m_vPaperGroupStruct.size();
  847. for (int i = 0; i < nSize; ++i)
  848. {
  849. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  850. for (int j = 0; j < nQuestionSize; ++j)
  851. {
  852. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  853. for (int k = 0; k < nSubQuestionSize; ++k)
  854. {
  855. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  856. if(!sqs.bUpload)
  857. {
  858. CHttpRequestPackage hrp;
  859. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/submitQuestionAnswer");
  860. hrp.nRequestType = RequestType::rtSubmitQuestionAnswer;
  861. hrp.eParamType = HttpParamType::hptCustomBody;
  862. hrp.sParamList.push_back(QString("CustomBody,%1").arg(sAnswer));
  863. hrp.sCommonStr = QString("%1,%2").arg(sqs.nOrder).arg(sqs.nVersion);
  864. g_httpBllPtr->post(hrp);
  865. }
  866. }
  867. }
  868. }
  869. }
  870. void answerWidget::onSubmitQuestionAnswer(CSubmitQuestionAnswer submitQuestionAnswer)
  871. {
  872. if(submitQuestionAnswer.nCode == 200)
  873. {
  874. int nSize = m_vPaperGroupStruct.size();
  875. for (int i = 0; i < nSize; ++i)
  876. {
  877. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  878. for (int j = 0; j < nQuestionSize; ++j)
  879. {
  880. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  881. for (int k = 0; k < nSubQuestionSize; ++k)
  882. {
  883. CSubQuestionStruct &sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  884. if(sqs.nOrder == submitQuestionAnswer.nOrder &&
  885. submitQuestionAnswer.nVersion >= sqs.nVersion)
  886. {
  887. sqs.bUpload = true;
  888. break;
  889. }
  890. }
  891. }
  892. }
  893. }
  894. else
  895. {
  896. if(submitQuestionAnswer.sMessage.isEmpty())
  897. {
  898. ShowMsg(QString::fromLocal8Bit("提交答案失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  899. }
  900. else
  901. {
  902. ShowMsg(submitQuestionAnswer.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  903. }
  904. }
  905. }
  906. void answerWidget::getQuestionContent(QString sQuestionId, int nOrder)
  907. {
  908. CHttpRequestPackage hrp;
  909. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/getQuestionContent")
  910. .arg(g_appInfoPtr->m_oExamInfo.nExamId);
  911. hrp.nRequestType = RequestType::rtGetQuestionContent;
  912. hrp.eParamType = HttpParamType::hptUrl;
  913. hrp.sCommonStr = sQuestionId + "," + QString::number(nOrder);
  914. hrp.sParamList.push_back(QString("questionId,%1").arg(sQuestionId));
  915. g_httpBllPtr->post(hrp);
  916. }
  917. void answerWidget::onGetQuestionContent(CGetQuestionContent getQuestionContent)
  918. {
  919. if (getQuestionContent.nCode == 200)
  920. {
  921. for (CPaperGroupStruct &pgs : m_vPaperGroupStruct)
  922. {
  923. for (CQuestionStruct &qs : pgs.vQuestionStruct)
  924. {
  925. if (qs.sQuestionId == getQuestionContent.sQuestionId)
  926. {
  927. qs.sBody = getQuestionContent.sBody;
  928. qs.sVersion = getQuestionContent.sVersion;
  929. qs.bhasAudios = getQuestionContent.bhasAudios;
  930. for (int i = 0; i < getQuestionContent.vSubQuestion.size(); ++i)
  931. {
  932. CSubQuestion sq = getQuestionContent.vSubQuestion[i];
  933. qs.vSubQuestionStruct[i].sBody = sq.sBody;
  934. qs.vSubQuestionStruct[i].vRightAnswer.swap(sq.vRightAnswer);
  935. qs.vSubQuestionStruct[i].vOptions.swap(sq.vOptions);
  936. }
  937. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(pgs.nNumber)).arg(pgs.sGroupName).arg(pgs.nTotalSubquestion);
  938. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(pgs.nAnsweredCount).arg(pgs.nTotalSubquestion);
  939. showSubQuestion(qs, getQuestionContent.sOrder.toInt(), sGroupTitleText, sGroupProgressText);
  940. break;
  941. }
  942. }
  943. }
  944. }
  945. else
  946. {
  947. if(getQuestionContent.sMessage.isEmpty())
  948. {
  949. ShowMsg(QString::fromLocal8Bit("获取题目内容失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  950. }
  951. else
  952. {
  953. ShowMsg(getQuestionContent.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  954. }
  955. }
  956. }
  957. void answerWidget::onStartAnswer(CStartAnswer startAnswer)
  958. {
  959. if(startAnswer.nCode == 200)
  960. {
  961. m_nRetryCount = 0;
  962. m_nUsedExamSeconds = startAnswer.nUsedExamSeconds;
  963. m_pHeartbeatTimer->start();
  964. heartBreat();
  965. //获取活体参数
  966. if (g_appInfoPtr->m_oExamInfo.bLivenessCheck)
  967. {
  968. StartFaceLiveVerify();
  969. // GetOrgPropertiesByGroupWithoutCache();
  970. // CHttpRequestPackage hrp;
  971. // hrp.sUri = QString("/api/ecs_core/org/getOrgPropertiesByGroupWithoutCache/%1/config4Edit1")
  972. // .arg(g_appInfoPtr->m_sRootOrgId);
  973. // hrp.nRequestType = RequestType::rtGetOrgPropertiesByGroupWithoutCache;
  974. // g_httpBllPtr->get(hrp);
  975. {
  976. // CHttpRequestPackage hrp;
  977. // hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/startFaceLiveVerify")
  978. // .arg(g_appInfoPtr->m_sRootOrgId);
  979. // hrp.nRequestType = RequestType::rtStartFaceLiveVerify;
  980. // hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  981. // hrp.eParamType = HttpParamType::hptUrl;
  982. // g_httpBllPtr->post(hrp);
  983. }
  984. }
  985. }
  986. else
  987. {
  988. // if(startAnswer.sMessage.isEmpty())
  989. // {
  990. // ShowMsg(QString::fromLocal8Bit("开始作答失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  991. // }
  992. // else
  993. // {
  994. // ShowMsg(startAnswer.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  995. // }
  996. if(++m_nRetryCount > 3)
  997. {
  998. //退出
  999. exitExamTip();
  1000. }
  1001. else
  1002. {
  1003. startAnwer();
  1004. }
  1005. }
  1006. }
  1007. void answerWidget::GetOrgPropertiesByGroupWithoutCache()
  1008. {
  1009. CHttpRequestPackage hrp;
  1010. hrp.sUri = QString("/api/ecs_core/org/getOrgPropertiesByGroupWithoutCache/%1/config4Edit1")
  1011. .arg(g_appInfoPtr->m_sRootOrgId);
  1012. hrp.nRequestType = RequestType::rtGetOrgPropertiesByGroupWithoutCache;
  1013. g_httpBllPtr->get(hrp);
  1014. }
  1015. void answerWidget::onGetOrgPropertiesByGroupWithoutCache(CGetOrgPropertiesByGroupWithoutCache orgProperties)
  1016. {
  1017. if(orgProperties.nCode == 200)
  1018. {
  1019. m_nRetryCount = 0;
  1020. g_appInfoPtr->m_oExamInfo.nActionNum = orgProperties.nActionNum;
  1021. g_appInfoPtr->m_oExamInfo.sActionOptions = orgProperties.sActionOptions;
  1022. g_appInfoPtr->m_oExamInfo.sActionOrder = orgProperties.sActionOrder;
  1023. g_appInfoPtr->m_oExamInfo.nActionDuration = orgProperties.nActionDuration;
  1024. g_appInfoPtr->m_oExamInfo.nActionAlert = orgProperties.nActionAlert;
  1025. StartFaceLiveVerify();
  1026. }
  1027. else
  1028. {
  1029. // if(orgProperties.sMessage.isEmpty())
  1030. // {
  1031. // ShowMsg(QString::fromLocal8Bit("获取考试信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1032. // }
  1033. // else
  1034. // {
  1035. // ShowMsg(orgProperties.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1036. // }
  1037. if(++m_nRetryCount > 3)
  1038. {
  1039. //退出
  1040. exitExamTip();
  1041. }
  1042. else
  1043. {
  1044. GetOrgPropertiesByGroupWithoutCache();
  1045. }
  1046. }
  1047. }
  1048. void answerWidget::StartFaceLiveVerify()
  1049. {
  1050. CHttpRequestPackage hrp;
  1051. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/startFaceLiveVerify")
  1052. .arg(g_appInfoPtr->m_sRootOrgId);
  1053. hrp.nRequestType = RequestType::rtStartFaceLiveVerify;
  1054. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  1055. hrp.eParamType = HttpParamType::hptUrl;
  1056. g_httpBllPtr->post(hrp);
  1057. }
  1058. void answerWidget::onStartFaceLiveVerify(CStartFaceLiveVerify startFaceLiveVerify)
  1059. {
  1060. if(startFaceLiveVerify.nCode == 200)
  1061. {
  1062. m_nRetryCount = 0;
  1063. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = startFaceLiveVerify.nFaceLiveVerifyId;
  1064. g_appInfoPtr->m_oExamInfo.nFaceVerifyTimes = startFaceLiveVerify.nTimes;
  1065. g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute = startFaceLiveVerify.nStartMinute;
  1066. bShowLivenessTip = true;
  1067. }
  1068. else
  1069. {
  1070. // if(startFaceLiveVerify.sMessage.isEmpty())
  1071. // {
  1072. // ShowMsg(QString::fromLocal8Bit("开启活体验证失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1073. // }
  1074. // else
  1075. // {
  1076. // ShowMsg(startFaceLiveVerify.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1077. // }
  1078. if(++m_nRetryCount > 3)
  1079. {
  1080. //退出
  1081. exitExamTip();
  1082. }
  1083. else
  1084. {
  1085. StartFaceLiveVerify();
  1086. }
  1087. }
  1088. }
  1089. void answerWidget::heartBreat()
  1090. {
  1091. CHttpRequestPackage hrp;
  1092. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/examHeartbeat");
  1093. hrp.nRequestType = RequestType::rtExamHeartbeat;
  1094. g_httpBllPtr->post(hrp);
  1095. }
  1096. void answerWidget::onExamHeartbeat(CExamHeartbeat examHeartbeat)
  1097. {
  1098. if (examHeartbeat.nCode == 200)
  1099. {
  1100. if(m_nHeartBreatFailedCount > 0)
  1101. {
  1102. //m_pHeartbeatTimer->stop();
  1103. m_pHeartbeatTimer->setInterval(60 * 1000);
  1104. //m_pHeartbeatTimer->start();
  1105. m_nHeartBreatFailedCount = 0;
  1106. }
  1107. m_nLeftSeconds = examHeartbeat.nLeftTime/1000;
  1108. if(m_nEnterExamTime == 0)
  1109. {
  1110. m_nEnterExamTime = m_nLeftSeconds;
  1111. }
  1112. m_pCountDownTimer->start();
  1113. //过程中人脸识别
  1114. if(g_appInfoPtr->m_oExamInfo.bFaceCheck)
  1115. {
  1116. if(g_inProcessFace == nullptr)
  1117. {
  1118. g_inProcessFace = std::make_shared<CInprogressFace>();
  1119. connect(g_inProcessFace.get(), &CInprogressFace::compareFailed, this, [&](QString sErrorMsg){
  1120. ShowMsg(sErrorMsg, g_appInfoPtr->m_pAnsBgWidget);
  1121. });
  1122. startCapture();
  1123. }
  1124. m_nNextFaceCountSecond = m_nLeftSeconds - CCommonTools::genRandomNumber(1, 10);
  1125. }
  1126. }
  1127. else
  1128. {
  1129. if(m_nHeartBreatFailedCount == 0)
  1130. {
  1131. // m_pHeartbeatTimer->stop();
  1132. m_pHeartbeatTimer->setInterval(10 * 1000);
  1133. //m_pHeartbeatTimer->start();
  1134. }
  1135. ++m_nHeartBreatFailedCount;
  1136. if (m_nHeartBreatFailedCount >= m_nHeartBreatFailedExitCount)
  1137. {
  1138. exitExamTip();
  1139. //退出
  1140. // awTimeLeftTips *wExitExam = new awTimeLeftTips(MASK_POP_WIDGET_TYPE::wt_exitExam, (QWidget*)(this->parent()));
  1141. // connect(wExitExam, &awTimeLeftTips::timeLeftConfirm, this, [this, wExitExam]() {
  1142. // if (m_pNetWorkErrorTimerPtr)
  1143. // {
  1144. // m_pNetWorkErrorTimerPtr->stop();
  1145. // }
  1146. // delete wExitExam;
  1147. // emit gobackLogin();
  1148. // });
  1149. // wExitExam->show();
  1150. // if (m_pNetWorkErrorTimerPtr == nullptr)
  1151. // {
  1152. // m_pNetWorkErrorTimerPtr = std::make_shared<QTimer>();
  1153. // m_pNetWorkErrorTimerPtr->setInterval(30 * 1000);
  1154. // connect(m_pNetWorkErrorTimerPtr.get(), &QTimer::timeout, [this, wExitExam]() {
  1155. // m_pNetWorkErrorTimerPtr->stop();
  1156. // delete wExitExam;
  1157. // emit gobackLogin();
  1158. // });
  1159. // }
  1160. // m_pNetWorkErrorTimerPtr->start();
  1161. }
  1162. if(examHeartbeat.sMessage.isEmpty())
  1163. {
  1164. ShowMsg(QString::fromLocal8Bit("网络连接异常,请检查网络设置"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1165. }
  1166. else
  1167. {
  1168. ShowMsg(examHeartbeat.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1169. }
  1170. }
  1171. }
  1172. void answerWidget::exitExamTip()
  1173. {
  1174. //退出
  1175. awTimeLeftTips *wExitExam = new awTimeLeftTips(MASK_POP_WIDGET_TYPE::wt_exitExam, (QWidget*)(this->parent()));
  1176. connect(wExitExam, &awTimeLeftTips::timeLeftConfirm, this, [this, wExitExam]() {
  1177. if (m_pNetWorkErrorTimerPtr)
  1178. {
  1179. m_pNetWorkErrorTimerPtr->stop();
  1180. }
  1181. delete wExitExam;
  1182. emit gobackLogin();
  1183. });
  1184. wExitExam->show();
  1185. if (m_pNetWorkErrorTimerPtr == nullptr)
  1186. {
  1187. m_pNetWorkErrorTimerPtr = std::make_shared<QTimer>();
  1188. m_pNetWorkErrorTimerPtr->setInterval(30 * 1000);
  1189. connect(m_pNetWorkErrorTimerPtr.get(), &QTimer::timeout, [this, wExitExam]() {
  1190. m_pNetWorkErrorTimerPtr->stop();
  1191. delete wExitExam;
  1192. emit gobackLogin();
  1193. });
  1194. }
  1195. m_pNetWorkErrorTimerPtr->start();
  1196. }
  1197. void answerWidget::on_btn_handInPaper_clicked()
  1198. {
  1199. if(m_nFreezeTime*60 > m_nUsedExamSeconds + m_nEnterExamTime - m_nLeftSeconds)
  1200. {
  1201. ShowMsg(QString::fromLocal8Bit("冻结时间内不允许交卷"), this, MSG_ICON_TYPE::mit_error);
  1202. return;
  1203. }
  1204. if(m_pHandinPaper == nullptr)
  1205. {
  1206. m_pHandinPaper = std::make_shared<awHandinPaper>(ui->btn_answeredNum->text().toInt(),
  1207. ui->btn_unansweredNum->text().toInt(),
  1208. ui->btn_markedNum->text().toInt(), (QWidget*)(this->parent()));
  1209. connect(m_pHandinPaper.get(), &awHandinPaper::handinPaper, this, [&](){
  1210. m_pHandinPaper.reset();
  1211. //交卷
  1212. handinPaper();
  1213. });
  1214. connect(m_pHandinPaper.get(), &awHandinPaper::cancelHandinPaper, this, [&](){
  1215. m_pHandinPaper.reset();
  1216. });
  1217. }
  1218. m_pHandinPaper->show();
  1219. }
  1220. bool answerWidget::checkAnswer()
  1221. {
  1222. bool bRet = true;
  1223. int nSize = m_vPaperGroupStruct.size();
  1224. for (int i = 0; i < nSize; ++i)
  1225. {
  1226. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  1227. for (int j = 0; j < nQuestionSize; ++j)
  1228. {
  1229. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  1230. for (int k = 0; k < nSubQuestionSize; ++k)
  1231. {
  1232. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  1233. if (!sqs.bUpload)
  1234. {
  1235. bRet = false;
  1236. CHttpRequestPackage hrp;
  1237. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/submitQuestionAnswer");
  1238. hrp.nRequestType = RequestType::rtSubmitQuestionAnswer;
  1239. hrp.eParamType = HttpParamType::hptCustomBody;
  1240. hrp.sParamList.push_back(QString("CustomBody,%1").arg(sqs.sUploadAnswer));
  1241. hrp.sCommonStr = QString("%1,%2").arg(sqs.nOrder).arg(sqs.nVersion);
  1242. g_httpBllPtr->post(hrp);
  1243. }
  1244. }
  1245. }
  1246. }
  1247. return bRet;
  1248. }
  1249. void answerWidget::handinPaper(bool bForce)
  1250. {
  1251. m_pCountDownTimer->stop();
  1252. if(g_appInfoPtr->m_oExamInfo.bFaceCheck)
  1253. {
  1254. stopCapture();
  1255. }
  1256. if(g_inProcessFace != nullptr)
  1257. {
  1258. stopCapture();
  1259. g_inProcessFace.reset();
  1260. }
  1261. if(m_pResumeExam == nullptr)
  1262. {
  1263. m_pResumeExam = std::make_shared<awResumeExam>((QWidget*)(this->parent()), QString::fromLocal8Bit("交卷中请稍候…"));
  1264. }
  1265. m_pResumeExam->show();
  1266. if (checkAnswer())
  1267. {
  1268. // CHttpRequestPackage hrp;
  1269. // hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1270. // hrp.sCommonStr = __FILE__;
  1271. // hrp.nRequestType = RequestType::rtEndExam;
  1272. // g_httpBllPtr->post(hrp);
  1273. doEndExam(bForce);
  1274. }
  1275. else
  1276. {
  1277. if (m_pHandinPaperTimer == nullptr)
  1278. {
  1279. m_pHandinPaperTimer = std::make_shared<QTimer>();
  1280. m_pHandinPaperTimer->setInterval(10 * 1000);
  1281. connect(m_pHandinPaperTimer.get(), &QTimer::timeout, this, [&]() {
  1282. if (checkAnswer())
  1283. {
  1284. m_pHandinPaperTimer->stop();
  1285. doEndExam(bForce);
  1286. // CHttpRequestPackage hrp;
  1287. // hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1288. // hrp.sCommonStr = __FILE__;
  1289. // hrp.nRequestType = RequestType::rtEndExam;
  1290. // g_httpBllPtr->post(hrp);
  1291. }
  1292. });
  1293. }
  1294. }
  1295. }
  1296. void answerWidget::doEndExam(bool bForce)
  1297. {
  1298. CHttpRequestPackage hrp;
  1299. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1300. if(bForce)
  1301. {
  1302. hrp.sParamList.push_back(QString("force,%1").arg(bForce));
  1303. hrp.eParamType = HttpParamType::hptUrl;
  1304. }
  1305. hrp.sCommonStr = __FILE__;
  1306. hrp.sAdditionStr = bForce ? "1" : "0";
  1307. hrp.nRequestType = RequestType::rtEndExam;
  1308. g_httpBllPtr->post(hrp);
  1309. }
  1310. void answerWidget::onEndExam(CEndExam endExam)
  1311. {
  1312. if(endExam.sModuleName == __FILE__)
  1313. {
  1314. if (endExam.nCode == 200)
  1315. {
  1316. m_pHeartbeatTimer->stop();
  1317. m_pResumeExam.reset();
  1318. if (g_appInfoPtr->m_oExamInfo.sExamType == EXAM_TYPES::PRACTICE)
  1319. {
  1320. if(g_appInfoPtr->m_oExamInfo.sPracticeType != "NO_ANSWER")
  1321. {
  1322. emit showPracticeInfo();
  1323. }
  1324. else
  1325. {
  1326. emit gobackCourseList();
  1327. }
  1328. }
  1329. else
  1330. {
  1331. emit showExamScore();
  1332. }
  1333. }
  1334. else
  1335. {
  1336. QTimer::singleShot(5*1000, this, [&](){
  1337. // CHttpRequestPackage hrp;
  1338. // hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1339. // hrp.sCommonStr = __FILE__;
  1340. // hrp.nRequestType = RequestType::rtEndExam;
  1341. // g_httpBllPtr->post(hrp);
  1342. doEndExam(endExam.bForce);
  1343. });
  1344. }
  1345. }
  1346. }
  1347. void answerWidget::on_btn_all_clicked()
  1348. {
  1349. int nCount = ui->lw_aw_questionList->count();
  1350. for(int i = 0; i < nCount; ++i)
  1351. {
  1352. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1353. if(questionItem)
  1354. {
  1355. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAll);
  1356. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1357. if(listItem)
  1358. {
  1359. QSize size = listItem->sizeHint();
  1360. size.setHeight(nHeight);
  1361. listItem->setSizeHint(size);
  1362. }
  1363. }
  1364. }
  1365. setChecked(ui->btn_all, true);
  1366. setChecked(ui->btn_marked, false);
  1367. setChecked(ui->btn_answered, false);
  1368. setChecked(ui->btn_unanswered, false);
  1369. }
  1370. void answerWidget::setChecked(QPushButton *btn, bool bChecked)
  1371. {
  1372. QString sNormal = QString(R"(QPushButton
  1373. {
  1374. outline:none;
  1375. background:rgba(242,243,247,1);
  1376. border-radius:%1px;
  1377. border:1px solid rgba(240,244,249,1);
  1378. font-size:%2px;
  1379. font-family:"Microsoft YaHei";
  1380. font-weight:500;
  1381. color:rgba(153,153,153,1);
  1382. padding-left:%3px;
  1383. text-align:left;
  1384. })").arg((int)(g_appInfoPtr->m_fRate*14))
  1385. .arg((int)(g_appInfoPtr->m_fRate*12))
  1386. .arg((int)(g_appInfoPtr->m_fRate*15));
  1387. QString sChecked = QString(R"(QPushButton
  1388. {
  1389. outline:none;
  1390. background:rgba(242,243,247,1);
  1391. border-radius:%1px;
  1392. border:1px solid rgba(189,200,217,1);
  1393. font-size:%2px;
  1394. font-family:"Microsoft YaHei";
  1395. font-weight:500;
  1396. color:rgba(153,153,153,1);
  1397. padding-left:%3px;
  1398. text-align:left;
  1399. })").arg((int)(g_appInfoPtr->m_fRate*14))
  1400. .arg((int)(g_appInfoPtr->m_fRate*12))
  1401. .arg((int)(g_appInfoPtr->m_fRate*15));
  1402. btn->setStyleSheet(bChecked ? sChecked : sNormal);
  1403. }
  1404. void answerWidget::on_btn_answered_clicked()
  1405. {
  1406. int nCount = ui->lw_aw_questionList->count();
  1407. for(int i = 0; i < nCount; ++i)
  1408. {
  1409. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1410. if(questionItem)
  1411. {
  1412. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAnswered);
  1413. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1414. if(listItem)
  1415. {
  1416. QSize size = listItem->sizeHint();
  1417. size.setHeight(nHeight);
  1418. listItem->setSizeHint(size);
  1419. }
  1420. }
  1421. }
  1422. setChecked(ui->btn_all, false);
  1423. setChecked(ui->btn_marked, false);
  1424. setChecked(ui->btn_answered, true);
  1425. setChecked(ui->btn_unanswered, false);
  1426. }
  1427. void answerWidget::on_btn_unanswered_clicked()
  1428. {
  1429. int nCount = ui->lw_aw_questionList->count();
  1430. for(int i = 0; i < nCount; ++i)
  1431. {
  1432. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1433. if(questionItem)
  1434. {
  1435. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showUnanswered);
  1436. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1437. if(listItem)
  1438. {
  1439. QSize size = listItem->sizeHint();
  1440. size.setHeight(nHeight);
  1441. listItem->setSizeHint(size);
  1442. }
  1443. }
  1444. }
  1445. setChecked(ui->btn_all, false);
  1446. setChecked(ui->btn_marked, false);
  1447. setChecked(ui->btn_answered, false);
  1448. setChecked(ui->btn_unanswered, true);
  1449. }
  1450. void answerWidget::on_btn_marked_clicked()
  1451. {
  1452. int nCount = ui->lw_aw_questionList->count();
  1453. for(int i = 0; i < nCount; ++i)
  1454. {
  1455. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1456. if(questionItem)
  1457. {
  1458. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showMarked);
  1459. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1460. if(listItem)
  1461. {
  1462. QSize size = listItem->sizeHint();
  1463. size.setHeight(nHeight);
  1464. listItem->setSizeHint(size);
  1465. }
  1466. }
  1467. }
  1468. setChecked(ui->btn_all, false);
  1469. setChecked(ui->btn_marked, true);
  1470. setChecked(ui->btn_answered, false);
  1471. setChecked(ui->btn_unanswered, false);
  1472. }
  1473. void answerWidget::on_btn_allNum_clicked()
  1474. {
  1475. on_btn_all_clicked();
  1476. }
  1477. void answerWidget::on_btn_answeredNum_clicked()
  1478. {
  1479. on_btn_answered_clicked();
  1480. }
  1481. void answerWidget::on_btn_unansweredNum_clicked()
  1482. {
  1483. on_btn_unanswered_clicked();
  1484. }
  1485. void answerWidget::on_btn_markedNum_clicked()
  1486. {
  1487. on_btn_marked_clicked();
  1488. }
  1489. void answerWidget::onRenderVideoFrame(const char* userId, TRTCVideoStreamType streamType, TRTCVideoFrame* frame)
  1490. {
  1491. if(g_clientVideoProcPtr->isCameraTest())
  1492. {
  1493. __int64 nServerTime = g_appInfoPtr->serverMTime();
  1494. if(nServerTime - m_lastFaceTime >= 100)
  1495. {
  1496. m_lastFaceTime = nServerTime;
  1497. cv::Mat matImg;
  1498. cv::cvtColor(cv::Mat(frame->height, frame->width, CV_8UC4, frame->data), matImg, CV_RGBA2RGB);
  1499. if(matImg.empty())
  1500. {
  1501. qDebug()<<"widgetCameraTest frame is empty";
  1502. return;
  1503. }
  1504. std::scoped_lock lock(m_imageMutex);
  1505. m_nCurImage = matImg;
  1506. }
  1507. }
  1508. }
  1509. void answerWidget::startCapture()
  1510. {
  1511. // if(m_pinitTimer == nullptr)
  1512. // {
  1513. // m_pinitTimer = std::make_shared<QTimer>();
  1514. // m_pinitTimer->setInterval(1000);
  1515. // connect(m_pinitTimer.get(), &QTimer::timeout, this, [&](){
  1516. // m_pinitTimer->stop();
  1517. // if(!m_cam.open(0))
  1518. // {
  1519. // ShowMsg(QString::fromLocal8Bit("打开摄像头失败"), this, MSG_ICON_TYPE::mit_error);
  1520. // return;
  1521. // }
  1522. // int inWidth = ui->widget_aw_face->width();
  1523. // m_cam.set(CV_CAP_PROP_FRAME_WIDTH, inWidth*3);
  1524. // int inHeight = ui->widget_aw_face->height();
  1525. // m_cam.set(CV_CAP_PROP_FRAME_HEIGHT, inHeight*3);
  1526. // m_cam.set(CV_CAP_PROP_FPS, 5);
  1527. // m_pVideoTimer->start();
  1528. // });
  1529. // }
  1530. g_clientVideoProcPtr->startTest(this);
  1531. g_inProcessFace->startFaceVerify(true);
  1532. if(m_pVideoTimer == nullptr)
  1533. {
  1534. m_pVideoTimer = std::make_shared<QTimer>();
  1535. m_pVideoTimer->setInterval(200);
  1536. m_nLastCaptureSecond = m_nLeftSeconds;
  1537. connect(m_pVideoTimer.get(), &QTimer::timeout, this, [&](){
  1538. cv::Mat frame;
  1539. {
  1540. std::scoped_lock lock(m_imageMutex);
  1541. frame = m_nCurImage;
  1542. }
  1543. if(frame.empty())
  1544. {
  1545. qDebug()<<"widgetCameraTest frame is empty";
  1546. return;
  1547. }
  1548. if (g_inProcessFace != nullptr &&
  1549. m_nLastCaptureSecond - m_nLeftSeconds > g_appInfoPtr->m_oExamInfo.nSnapshotInterval*60)
  1550. {
  1551. m_nLastCaptureSecond = m_nLeftSeconds;
  1552. g_inProcessFace->addImage(frame);
  1553. }
  1554. if(g_inProcessFace != nullptr &&
  1555. m_nNextFaceCountSecond > m_nLeftSeconds)
  1556. {
  1557. m_nNextFaceCountSecond = m_nLeftSeconds - CCommonTools::genRandomNumber(1, 10);
  1558. g_inProcessFace->addFaceCountImage(frame);
  1559. }
  1560. QImage img = CCommonTools::Mat2QImage(frame);
  1561. ui->widget_aw_face->setAutoFillBackground(true);
  1562. QPalette palette;
  1563. palette.setBrush(QPalette::Window, QBrush(img.scaled(ui->widget_aw_face->width(), ui->widget_aw_face->height())));
  1564. ui->widget_aw_face->setPalette(palette);
  1565. });
  1566. }
  1567. m_pVideoTimer->start();
  1568. }
  1569. void answerWidget::stopCapture()
  1570. {
  1571. m_pVideoTimer->stop();
  1572. g_inProcessFace->startFaceVerify(false);
  1573. g_clientVideoProcPtr->stopTest();
  1574. // m_pVideoTimer->stop();
  1575. // if(m_cam.isOpened())
  1576. // {
  1577. // m_cam.release();
  1578. // }
  1579. }