answerWidget.cpp 67 KB

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