answerWidget.cpp 71 KB

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