answerWidget.cpp 62 KB

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