answerWidget.cpp 62 KB

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