answerWidget.cpp 64 KB

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