answerWidget.cpp 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  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. startCapture();
  1184. }
  1185. m_nNextFaceCountSecond = m_nLeftSeconds - CCommonTools::genRandomNumber(1, 10);
  1186. }
  1187. }
  1188. else
  1189. {
  1190. if(m_nHeartBreatFailedCount == 0)
  1191. {
  1192. // m_pHeartbeatTimer->stop();
  1193. m_pHeartbeatTimer->setInterval(10 * 1000);
  1194. //m_pHeartbeatTimer->start();
  1195. }
  1196. ++m_nHeartBreatFailedCount;
  1197. if (m_nHeartBreatFailedCount >= m_nHeartBreatFailedExitCount)
  1198. {
  1199. exitExamTip();
  1200. //退出
  1201. // awTimeLeftTips *wExitExam = new awTimeLeftTips(MASK_POP_WIDGET_TYPE::wt_exitExam, (QWidget*)(this->parent()));
  1202. // connect(wExitExam, &awTimeLeftTips::timeLeftConfirm, this, [this, wExitExam]() {
  1203. // if (m_pNetWorkErrorTimerPtr)
  1204. // {
  1205. // m_pNetWorkErrorTimerPtr->stop();
  1206. // }
  1207. // delete wExitExam;
  1208. // emit gobackLogin();
  1209. // });
  1210. // wExitExam->show();
  1211. // if (m_pNetWorkErrorTimerPtr == nullptr)
  1212. // {
  1213. // m_pNetWorkErrorTimerPtr = std::make_shared<QTimer>();
  1214. // m_pNetWorkErrorTimerPtr->setInterval(30 * 1000);
  1215. // connect(m_pNetWorkErrorTimerPtr.get(), &QTimer::timeout, [this, wExitExam]() {
  1216. // m_pNetWorkErrorTimerPtr->stop();
  1217. // delete wExitExam;
  1218. // emit gobackLogin();
  1219. // });
  1220. // }
  1221. // m_pNetWorkErrorTimerPtr->start();
  1222. }
  1223. if(examHeartbeat.sMessage.isEmpty())
  1224. {
  1225. ShowMsg(QString::fromLocal8Bit("网络连接异常,请检查网络设置"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1226. }
  1227. else
  1228. {
  1229. ShowMsg(examHeartbeat.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1230. }
  1231. }
  1232. }
  1233. void answerWidget::exitExamTip()
  1234. {
  1235. //退出
  1236. awTimeLeftTips *wExitExam = new awTimeLeftTips(MASK_POP_WIDGET_TYPE::wt_exitExam, (QWidget*)(this->parent()));
  1237. connect(wExitExam, &awTimeLeftTips::timeLeftConfirm, this, [this, wExitExam]() {
  1238. if (m_pNetWorkErrorTimerPtr)
  1239. {
  1240. m_pNetWorkErrorTimerPtr->stop();
  1241. }
  1242. delete wExitExam;
  1243. emit gobackLogin();
  1244. });
  1245. wExitExam->show();
  1246. if (m_pNetWorkErrorTimerPtr == nullptr)
  1247. {
  1248. m_pNetWorkErrorTimerPtr = std::make_shared<QTimer>();
  1249. m_pNetWorkErrorTimerPtr->setInterval(30 * 1000);
  1250. connect(m_pNetWorkErrorTimerPtr.get(), &QTimer::timeout, [this, wExitExam]() {
  1251. m_pNetWorkErrorTimerPtr->stop();
  1252. delete wExitExam;
  1253. emit gobackLogin();
  1254. });
  1255. }
  1256. m_pNetWorkErrorTimerPtr->start();
  1257. }
  1258. bool answerWidget::allMutipleQuestionHas2Answers()
  1259. {
  1260. int nSize = m_vPaperGroupStruct.size();
  1261. for (int i = 0; i < nSize; ++i)
  1262. {
  1263. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  1264. for (int j = 0; j < nQuestionSize; ++j)
  1265. {
  1266. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  1267. for (int k = 0; k < nSubQuestionSize; ++k)
  1268. {
  1269. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  1270. if (sqs.sQuestionType == QUESTION_TYPE::MultipleChoice && sqs.sStudentAnswer.length() < 2)
  1271. {
  1272. return false;
  1273. }
  1274. }
  1275. }
  1276. }
  1277. return true;
  1278. }
  1279. void answerWidget::onExamControlCheckTime(CBaseResponsePackage res)
  1280. {
  1281. if(res.nCode == 200)
  1282. {
  1283. if(m_pHandinPaper == nullptr)
  1284. {
  1285. m_pHandinPaper = std::make_shared<awHandinPaper>(ui->btn_answeredNum->text().toInt(),
  1286. ui->btn_unansweredNum->text().toInt(),
  1287. ui->btn_markedNum->text().toInt(), (QWidget*)(this->parent()));
  1288. connect(m_pHandinPaper.get(), &awHandinPaper::handinPaper, this, [&](){
  1289. m_pHandinPaper.reset();
  1290. //交卷
  1291. handinPaper();
  1292. });
  1293. connect(m_pHandinPaper.get(), &awHandinPaper::cancelHandinPaper, this, [&](){
  1294. m_pHandinPaper.reset();
  1295. });
  1296. }
  1297. if(g_appInfoPtr->m_bMutipleAnserCountTips)
  1298. {
  1299. if(!allMutipleQuestionHas2Answers())
  1300. {
  1301. m_pHandinPaper->showMutipleChoiceTip();
  1302. }
  1303. }
  1304. m_pHandinPaper->show();
  1305. }
  1306. else
  1307. {
  1308. if(res.sMessage.isEmpty())
  1309. {
  1310. res.sMessage = QString::fromLocal8Bit("交卷时间检查失败");
  1311. }
  1312. ShowMsg(res.sMessage, this);
  1313. }
  1314. }
  1315. void answerWidget::on_btn_handInPaper_clicked()
  1316. {
  1317. // if(m_nFreezeTime*60 > m_nUsedExamSeconds + m_nEnterExamTime - m_nLeftSeconds)
  1318. // {
  1319. // ShowMsg(QString::fromLocal8Bit("冻结时间内不允许交卷"), this, MSG_ICON_TYPE::mit_error);
  1320. // return;
  1321. // }
  1322. ui->btn_handInPaper->setEnabled(false);
  1323. CHttpRequestPackage hrp;
  1324. hrp.sUri = QString("/api/ecs_oe_student/examControl/check/time");
  1325. hrp.nRequestType = RequestType::rtExamControlCheckTime;
  1326. g_httpBllPtr->post(hrp);
  1327. QTimer::singleShot(3000, this, [&](){
  1328. ui->btn_handInPaper->setEnabled(true);
  1329. });
  1330. }
  1331. bool answerWidget::checkAnswer()
  1332. {
  1333. bool bRet = true;
  1334. int nSize = m_vPaperGroupStruct.size();
  1335. for (int i = 0; i < nSize; ++i)
  1336. {
  1337. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  1338. for (int j = 0; j < nQuestionSize; ++j)
  1339. {
  1340. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  1341. for (int k = 0; k < nSubQuestionSize; ++k)
  1342. {
  1343. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  1344. if (!sqs.bUpload)
  1345. {
  1346. bRet = false;
  1347. CHttpRequestPackage hrp;
  1348. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/submitQuestionAnswer");
  1349. hrp.nRequestType = RequestType::rtSubmitQuestionAnswer;
  1350. hrp.eParamType = HttpParamType::hptCustomBody;
  1351. hrp.sParamList.push_back(QString("CustomBody,%1").arg(sqs.sUploadAnswer));
  1352. hrp.sCommonStr = QString("%1,%2").arg(sqs.nOrder).arg(sqs.nVersion);
  1353. g_httpBllPtr->post(hrp);
  1354. }
  1355. }
  1356. }
  1357. }
  1358. return bRet;
  1359. }
  1360. void answerWidget::handinPaper(bool bForce)
  1361. {
  1362. m_pCountDownTimer->stop();
  1363. if(g_appInfoPtr->m_oExamInfo.bFaceCheck)
  1364. {
  1365. stopCapture();
  1366. }
  1367. if(g_inProcessFace != nullptr)
  1368. {
  1369. stopCapture();
  1370. g_inProcessFace.reset();
  1371. }
  1372. if(m_pResumeExam == nullptr)
  1373. {
  1374. m_pResumeExam = std::make_shared<awResumeExam>((QWidget*)(this->parent()), QString::fromLocal8Bit("交卷中请稍候…"));
  1375. }
  1376. m_pResumeExam->show();
  1377. if (checkAnswer())
  1378. {
  1379. // CHttpRequestPackage hrp;
  1380. // hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1381. // hrp.sCommonStr = __FILE__;
  1382. // hrp.nRequestType = RequestType::rtEndExam;
  1383. // g_httpBllPtr->post(hrp);
  1384. doEndExam(bForce);
  1385. }
  1386. else
  1387. {
  1388. if (m_pHandinPaperTimer == nullptr)
  1389. {
  1390. m_pHandinPaperTimer = std::make_shared<QTimer>();
  1391. m_pHandinPaperTimer->setInterval(10 * 1000);
  1392. connect(m_pHandinPaperTimer.get(), &QTimer::timeout, this, [&]() {
  1393. if (checkAnswer())
  1394. {
  1395. m_pHandinPaperTimer->stop();
  1396. doEndExam(bForce);
  1397. // CHttpRequestPackage hrp;
  1398. // hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1399. // hrp.sCommonStr = __FILE__;
  1400. // hrp.nRequestType = RequestType::rtEndExam;
  1401. // g_httpBllPtr->post(hrp);
  1402. }
  1403. });
  1404. }
  1405. }
  1406. }
  1407. void answerWidget::doEndExam(bool bForce)
  1408. {
  1409. CHttpRequestPackage hrp;
  1410. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1411. if(bForce)
  1412. {
  1413. hrp.sParamList.push_back(QString("force,%1").arg(bForce));
  1414. hrp.eParamType = HttpParamType::hptUrl;
  1415. }
  1416. hrp.sCommonStr = __FILE__;
  1417. hrp.sAdditionStr = bForce ? "1" : "0";
  1418. hrp.nRequestType = RequestType::rtEndExam;
  1419. g_httpBllPtr->post(hrp);
  1420. }
  1421. void answerWidget::onEndExam(CEndExam endExam)
  1422. {
  1423. if(endExam.sModuleName == __FILE__)
  1424. {
  1425. if (endExam.nCode == 200)
  1426. {
  1427. m_pHeartbeatTimer->stop();
  1428. m_pResumeExam.reset();
  1429. if (g_appInfoPtr->m_oExamInfo.sExamType == EXAM_TYPES::PRACTICE)
  1430. {
  1431. if(g_appInfoPtr->m_oExamInfo.sPracticeType != "NO_ANSWER")
  1432. {
  1433. emit showPracticeInfo();
  1434. }
  1435. else
  1436. {
  1437. emit gobackCourseList();
  1438. }
  1439. }
  1440. else
  1441. {
  1442. emit showExamScore();
  1443. }
  1444. }
  1445. else
  1446. {
  1447. QTimer::singleShot(5*1000, this, [&](){
  1448. // CHttpRequestPackage hrp;
  1449. // hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1450. // hrp.sCommonStr = __FILE__;
  1451. // hrp.nRequestType = RequestType::rtEndExam;
  1452. // g_httpBllPtr->post(hrp);
  1453. doEndExam(endExam.bForce);
  1454. });
  1455. }
  1456. }
  1457. }
  1458. void answerWidget::on_btn_all_clicked()
  1459. {
  1460. int nCount = ui->lw_aw_questionList->count();
  1461. for(int i = 0; i < nCount; ++i)
  1462. {
  1463. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1464. if(questionItem)
  1465. {
  1466. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAll);
  1467. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1468. if(listItem)
  1469. {
  1470. QSize size = listItem->sizeHint();
  1471. size.setHeight(nHeight);
  1472. listItem->setSizeHint(size);
  1473. }
  1474. }
  1475. }
  1476. setChecked(ui->btn_all, true);
  1477. setChecked(ui->btn_marked, false);
  1478. setChecked(ui->btn_answered, false);
  1479. setChecked(ui->btn_unanswered, false);
  1480. }
  1481. void answerWidget::setChecked(QPushButton *btn, bool bChecked)
  1482. {
  1483. QString sNormal = QString(R"(QPushButton
  1484. {
  1485. outline:none;
  1486. background:rgba(242,243,247,1);
  1487. border-radius:%1px;
  1488. border:1px solid rgba(240,244,249,1);
  1489. font-size:%2px;
  1490. font-family:"Microsoft YaHei";
  1491. font-weight:500;
  1492. color:rgba(153,153,153,1);
  1493. padding-left:%3px;
  1494. text-align:left;
  1495. })").arg((int)(g_appInfoPtr->m_fRate*14))
  1496. .arg((int)(g_appInfoPtr->m_fRate*12))
  1497. .arg((int)(g_appInfoPtr->m_fRate*15));
  1498. QString sChecked = QString(R"(QPushButton
  1499. {
  1500. outline:none;
  1501. background:rgba(242,243,247,1);
  1502. border-radius:%1px;
  1503. border:1px solid rgba(189,200,217,1);
  1504. font-size:%2px;
  1505. font-family:"Microsoft YaHei";
  1506. font-weight:500;
  1507. color:rgba(153,153,153,1);
  1508. padding-left:%3px;
  1509. text-align:left;
  1510. })").arg((int)(g_appInfoPtr->m_fRate*14))
  1511. .arg((int)(g_appInfoPtr->m_fRate*12))
  1512. .arg((int)(g_appInfoPtr->m_fRate*15));
  1513. btn->setStyleSheet(bChecked ? sChecked : sNormal);
  1514. }
  1515. void answerWidget::on_btn_answered_clicked()
  1516. {
  1517. int nCount = ui->lw_aw_questionList->count();
  1518. for(int i = 0; i < nCount; ++i)
  1519. {
  1520. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1521. if(questionItem)
  1522. {
  1523. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAnswered);
  1524. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1525. if(listItem)
  1526. {
  1527. QSize size = listItem->sizeHint();
  1528. size.setHeight(nHeight);
  1529. listItem->setSizeHint(size);
  1530. }
  1531. }
  1532. }
  1533. setChecked(ui->btn_all, false);
  1534. setChecked(ui->btn_marked, false);
  1535. setChecked(ui->btn_answered, true);
  1536. setChecked(ui->btn_unanswered, false);
  1537. }
  1538. void answerWidget::on_btn_unanswered_clicked()
  1539. {
  1540. int nCount = ui->lw_aw_questionList->count();
  1541. for(int i = 0; i < nCount; ++i)
  1542. {
  1543. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1544. if(questionItem)
  1545. {
  1546. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showUnanswered);
  1547. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1548. if(listItem)
  1549. {
  1550. QSize size = listItem->sizeHint();
  1551. size.setHeight(nHeight);
  1552. listItem->setSizeHint(size);
  1553. }
  1554. }
  1555. }
  1556. setChecked(ui->btn_all, false);
  1557. setChecked(ui->btn_marked, false);
  1558. setChecked(ui->btn_answered, false);
  1559. setChecked(ui->btn_unanswered, true);
  1560. }
  1561. void answerWidget::on_btn_marked_clicked()
  1562. {
  1563. int nCount = ui->lw_aw_questionList->count();
  1564. for(int i = 0; i < nCount; ++i)
  1565. {
  1566. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1567. if(questionItem)
  1568. {
  1569. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showMarked);
  1570. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1571. if(listItem)
  1572. {
  1573. QSize size = listItem->sizeHint();
  1574. size.setHeight(nHeight);
  1575. listItem->setSizeHint(size);
  1576. }
  1577. }
  1578. }
  1579. setChecked(ui->btn_all, false);
  1580. setChecked(ui->btn_marked, true);
  1581. setChecked(ui->btn_answered, false);
  1582. setChecked(ui->btn_unanswered, false);
  1583. }
  1584. void answerWidget::on_btn_allNum_clicked()
  1585. {
  1586. on_btn_all_clicked();
  1587. }
  1588. void answerWidget::on_btn_answeredNum_clicked()
  1589. {
  1590. on_btn_answered_clicked();
  1591. }
  1592. void answerWidget::on_btn_unansweredNum_clicked()
  1593. {
  1594. on_btn_unanswered_clicked();
  1595. }
  1596. void answerWidget::on_btn_markedNum_clicked()
  1597. {
  1598. on_btn_marked_clicked();
  1599. }
  1600. void answerWidget::onRenderVideoFrame(const char* userId, TRTCVideoStreamType streamType, TRTCVideoFrame* frame)
  1601. {
  1602. if(g_clientVideoProcPtr->isCameraTest())
  1603. {
  1604. __int64 nServerTime = g_appInfoPtr->serverMTime();
  1605. if(nServerTime - m_lastFaceTime >= 100)
  1606. {
  1607. m_lastFaceTime = nServerTime;
  1608. cv::Mat matImg;
  1609. cv::cvtColor(cv::Mat(frame->height, frame->width, CV_8UC4, frame->data), matImg, CV_RGBA2RGB);
  1610. if(matImg.empty())
  1611. {
  1612. qDebug()<<"widgetCameraTest frame is empty";
  1613. return;
  1614. }
  1615. std::scoped_lock lock(m_imageMutex);
  1616. m_nCurImage = matImg;
  1617. }
  1618. }
  1619. }
  1620. void answerWidget::startCapture()
  1621. {
  1622. // if(m_pinitTimer == nullptr)
  1623. // {
  1624. // m_pinitTimer = std::make_shared<QTimer>();
  1625. // m_pinitTimer->setInterval(1000);
  1626. // connect(m_pinitTimer.get(), &QTimer::timeout, this, [&](){
  1627. // m_pinitTimer->stop();
  1628. // if(!m_cam.open(0))
  1629. // {
  1630. // ShowMsg(QString::fromLocal8Bit("打开摄像头失败"), this, MSG_ICON_TYPE::mit_error);
  1631. // return;
  1632. // }
  1633. // int inWidth = ui->widget_aw_face->width();
  1634. // m_cam.set(CV_CAP_PROP_FRAME_WIDTH, inWidth*3);
  1635. // int inHeight = ui->widget_aw_face->height();
  1636. // m_cam.set(CV_CAP_PROP_FRAME_HEIGHT, inHeight*3);
  1637. // m_cam.set(CV_CAP_PROP_FPS, 5);
  1638. // m_pVideoTimer->start();
  1639. // });
  1640. // }
  1641. g_clientVideoProcPtr->startTest(this);
  1642. g_inProcessFace->startFaceVerify(true);
  1643. if(m_pVideoTimer == nullptr)
  1644. {
  1645. m_pVideoTimer = std::make_shared<QTimer>();
  1646. m_pVideoTimer->setInterval(200);
  1647. m_nLastCaptureSecond = m_nLeftSeconds;
  1648. connect(m_pVideoTimer.get(), &QTimer::timeout, this, [&](){
  1649. cv::Mat frame;
  1650. {
  1651. std::scoped_lock lock(m_imageMutex);
  1652. frame = m_nCurImage;
  1653. }
  1654. if(frame.empty())
  1655. {
  1656. qDebug()<<"widgetCameraTest frame is empty";
  1657. return;
  1658. }
  1659. if (g_inProcessFace != nullptr &&
  1660. g_appInfoPtr->m_oExamInfo.bIsExamInProgress &&
  1661. !m_bExamInpressFaceCaptured)
  1662. {
  1663. m_bExamInpressFaceCaptured = true;
  1664. g_inProcessFace->addImage(frame);
  1665. }
  1666. if (g_inProcessFace != nullptr &&
  1667. m_nLastCaptureSecond - m_nLeftSeconds > g_appInfoPtr->m_oExamInfo.nSnapshotInterval*60)
  1668. {
  1669. m_nLastCaptureSecond = m_nLeftSeconds;
  1670. g_inProcessFace->addImage(frame);
  1671. }
  1672. if(g_inProcessFace != nullptr &&
  1673. m_nNextFaceCountSecond > m_nLeftSeconds)
  1674. {
  1675. m_nNextFaceCountSecond = m_nLeftSeconds - CCommonTools::genRandomNumber(1, 10);
  1676. g_inProcessFace->addFaceCountImage(frame);
  1677. }
  1678. QImage img = CCommonTools::Mat2QImage(frame);
  1679. ui->widget_aw_face->setAutoFillBackground(true);
  1680. QPalette palette;
  1681. palette.setBrush(QPalette::Window, QBrush(img.scaled(ui->widget_aw_face->width(), ui->widget_aw_face->height())));
  1682. ui->widget_aw_face->setPalette(palette);
  1683. });
  1684. }
  1685. m_pVideoTimer->start();
  1686. }
  1687. void answerWidget::stopCapture()
  1688. {
  1689. m_pVideoTimer->stop();
  1690. g_inProcessFace->startFaceVerify(false);
  1691. g_clientVideoProcPtr->stopTest();
  1692. // m_pVideoTimer->stop();
  1693. // if(m_cam.isOpened())
  1694. // {
  1695. // m_cam.release();
  1696. // }
  1697. }