clOnlinePractice.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #include "clOnlinePractice.h"
  2. #include "ui_clOnlinePractice.h"
  3. #include "CAppInfo.h"
  4. #include "clOperation.h"
  5. #include <QScrollBar>
  6. #include <QListView>
  7. #include <QDateTime>
  8. #include "awMsgBox.h"
  9. #include "logproc.h"
  10. clOnlinePractice::clOnlinePractice(QWidget *parent) :
  11. QWidget(parent),
  12. ui(new Ui::clOnlinePractice)
  13. {
  14. ui->setupUi(this);
  15. setStyleSheet(g_appInfoPtr->m_sQssStr);
  16. m_nCurExamId = 0;
  17. qRegisterMetaType<CQueryBatchList>("CQueryBatchList");
  18. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryBatchList, this, &clOnlinePractice::onQueryBatchList);
  19. qRegisterMetaType<CQueryPracticeCourseList>("CQueryPracticeCourseList");
  20. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryPracticeCourseList, this, &clOnlinePractice::onQueyPracticeCourseList);
  21. }
  22. clOnlinePractice::~clOnlinePractice()
  23. {
  24. delete ui;
  25. }
  26. void clOnlinePractice::setUI(const int nWidth, const int nHeight)
  27. {
  28. setGeometry(0, 0, nWidth, nHeight);
  29. ui->widget_onlinePractice->setGeometry(0, 0, width(), height());
  30. ui->widget_op_top->setGeometry(0, 0, width(), g_appInfoPtr->m_fRate*72);
  31. ui->label_batch->adjustSize();
  32. ui->label_batch->setGeometry(g_appInfoPtr->m_fRate*30, (ui->widget_op_top->height() - ui->label_batch->height())/2,
  33. ui->label_batch->width(), ui->label_batch->height());
  34. ui->cbo_batch->setGeometry(ui->label_batch->x() + ui->label_batch->width() + g_appInfoPtr->m_fRate*10,
  35. (ui->widget_op_top->height() - g_appInfoPtr->m_fRate*32)/2,
  36. g_appInfoPtr->m_fRate*240, g_appInfoPtr->m_fRate*32);
  37. ui->cbo_batch->setView(new QListView);
  38. ui->tablewt_examList->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_op_top->height() + g_appInfoPtr->m_fRate*10,
  39. ui->widget_onlinePractice->width() - g_appInfoPtr->m_fRate*30*2,
  40. ui->widget_onlinePractice->height() - ui->widget_op_top->height() - g_appInfoPtr->m_fRate*(10 + 62));
  41. ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers);
  42. //整行选中的方式
  43. ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows);
  44. //设置为只能选中一行
  45. ui->tablewt_examList->setSelectionMode(QAbstractItemView::SingleSelection);
  46. //隐藏列表头
  47. ui->tablewt_examList->verticalHeader()->setVisible(false);
  48. //隐藏边框
  49. ui->tablewt_examList->setShowGrid(false);
  50. //表头不高亮显示
  51. ui->tablewt_examList->horizontalHeader()->setHighlightSections(false);
  52. //设置行数
  53. ui->tablewt_examList->setRowCount(10);
  54. //设置列数
  55. ui->tablewt_examList->setColumnCount(8);
  56. ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  57. ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  58. QStringList sHeadStr;
  59. sHeadStr << QString::fromLocal8Bit("课程") <<
  60. QString::fromLocal8Bit("考试进入时间") <<
  61. QString::fromLocal8Bit("考试时间周期") <<
  62. QString::fromLocal8Bit("练习次数") <<
  63. QString::fromLocal8Bit("最近正确率") <<
  64. QString::fromLocal8Bit("平均正确率") <<
  65. QString::fromLocal8Bit("最高正确率") <<
  66. QString::fromLocal8Bit("操作");
  67. ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
  68. ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  69. ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  70. ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  71. ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
  72. ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*275);
  73. ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*280);
  74. ui->tablewt_examList->setColumnWidth(3, g_appInfoPtr->m_fRate*66);
  75. ui->tablewt_examList->setColumnWidth(4, g_appInfoPtr->m_fRate*80);
  76. ui->tablewt_examList->setColumnWidth(5, g_appInfoPtr->m_fRate*80);
  77. ui->tablewt_examList->setColumnWidth(6, g_appInfoPtr->m_fRate*80);
  78. ui->tablewt_examList->setColumnWidth(7, g_appInfoPtr->m_fRate*146);
  79. ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
  80. }
  81. void clOnlinePractice::onQueryBatchList(CQueryBatchList queryBatchList)
  82. {
  83. if (queryBatchList.nCode == 200)
  84. {
  85. __int64 nCurExamId = m_nCurExamId;
  86. ui->cbo_batch->clear();
  87. int nIndex = 0;
  88. for (size_t i = 0; i < queryBatchList.vBatchList.size(); ++i)
  89. {
  90. CBatchInfo bi = queryBatchList.vBatchList[i];
  91. ui->cbo_batch->addItem(bi.sName, bi.nId);
  92. if(nCurExamId == bi.nId)
  93. {
  94. nIndex = i;
  95. }
  96. }
  97. if(queryBatchList.vBatchList.size() > 0 )
  98. {
  99. m_nCurExamId = queryBatchList.vBatchList[nIndex].nId;
  100. ui->cbo_batch->setCurrentIndex(nIndex);
  101. myDebug() << "m_nCurExamId" << m_nCurExamId;
  102. }
  103. }
  104. else
  105. {
  106. if(queryBatchList.sMessage.isEmpty())
  107. {
  108. ShowMsg(QString::fromLocal8Bit("获取批次信息失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  109. }
  110. else
  111. {
  112. ShowMsg(queryBatchList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  113. }
  114. }
  115. }
  116. void clOnlinePractice::releaseClopResult()
  117. {
  118. if(m_pResultList)
  119. {
  120. m_pResultList.reset();
  121. }
  122. }
  123. void clOnlinePractice::showEvent(QShowEvent *)
  124. {
  125. refreshExam();
  126. }
  127. void clOnlinePractice::refreshExamInfo()
  128. {
  129. refreshExam();
  130. }
  131. void clOnlinePractice::refreshExam()
  132. {
  133. CHttpRequestPackage hrp;
  134. hrp.sUri = "/api/ecs_exam_work/exam/queryByNameLike";
  135. hrp.sParamList.push_back("examTypes,PRACTICE");
  136. hrp.sParamList.push_back(QString("studentId,%1").arg(g_appInfoPtr->m_nStudentId));
  137. hrp.sParamList.push_back(QString("name,%1").arg(""));
  138. hrp.nRequestType = RequestType::rtQueryBatchList;
  139. g_httpBllPtr->get(hrp);
  140. }
  141. void clOnlinePractice::onQueyPracticeCourseList(CQueryPracticeCourseList queryPracticeCourseList)
  142. {
  143. if (queryPracticeCourseList.nCode == 200)
  144. {
  145. int nSize = queryPracticeCourseList.vPracticeCourseInfo.size();
  146. ui->tablewt_examList->setRowCount(nSize);
  147. for (int i = 0; i < nSize; ++i)
  148. {
  149. CPracticeCourseInfo pci = queryPracticeCourseList.vPracticeCourseInfo[i];
  150. ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(pci.sCourseName));
  151. ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(pci.sStartTime).arg(pci.sEndTime)));
  152. QString sWeekCycle = CWeekTransform::getWeekCycles(pci.vExamCycleWeek);
  153. QString sTimeRange = pci.sExamCycleTimeRange.join(",");
  154. QDateTime dtCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime());
  155. QDateTime dtStartTime = QDateTime::fromString(pci.sStartTime, "yyyy-MM-dd hh:mm:ss");
  156. QDateTime dtEndTime = QDateTime::fromString(pci.sEndTime, "yyyy-MM-dd hh:mm:ss");
  157. bool bIsInExamTime = dtCurrent > dtStartTime && dtCurrent < dtEndTime;
  158. QString sWeek = dtCurrent.toString("ddd");
  159. bool bIsInWeek = sWeekCycle.size() == 0 || sWeekCycle.indexOf(sWeek) >= 0;
  160. QTime tCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).time();
  161. bool bIsInTimeRange = pci.sExamCycleTimeRange.size() == 0 || CWeekTransform::isInTimeRange(tCurrent, pci.sExamCycleTimeRange);
  162. ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(QString::fromLocal8Bit("%1 %2").arg(sWeekCycle).arg(sTimeRange)));
  163. ui->tablewt_examList->setItem(i, 3, new QTableWidgetItem(QString::number(pci.nPracticeCount)));
  164. ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("%1%").arg(pci.fRecentObjectiveAccuracy)));
  165. ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::fromLocal8Bit("%1%").arg(pci.fAveObjectiveAccuracy)));
  166. ui->tablewt_examList->setItem(i, 6, new QTableWidgetItem(QString::fromLocal8Bit("%1%").arg(pci.fMaxObjectiveAccuracy)));
  167. clOperation *clo = new clOperation(i, ui->tablewt_examList);
  168. connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){
  169. if (cot == CL_OPERATION_TYPE::cot_online_practice )
  170. {
  171. QString sWeekCycle = CWeekTransform::getWeekCycles(m_vPracticeCourseInfo[nRow].vExamCycleWeek);
  172. QString sTimeRange = m_vPracticeCourseInfo[nRow].sExamCycleTimeRange.join(",");
  173. QDateTime dtCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime());
  174. QDateTime dtStartTime = QDateTime::fromString(m_vPracticeCourseInfo[nRow].sStartTime, "yyyy-MM-dd hh:mm:ss");
  175. QDateTime dtEndTime = QDateTime::fromString(m_vPracticeCourseInfo[nRow].sEndTime, "yyyy-MM-dd hh:mm:ss");
  176. bool bIsInExamTime = dtCurrent > dtStartTime && dtCurrent < dtEndTime;
  177. QString sWeek = dtCurrent.toString("ddd");
  178. bool bIsInWeek = sWeekCycle.size() == 0 || sWeekCycle.indexOf(sWeek) >= 0;
  179. QTime tCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).time();
  180. bool bIsInTimeRange = m_vPracticeCourseInfo[nRow].sExamCycleTimeRange.size() == 0 || CWeekTransform::isInTimeRange(tCurrent, m_vPracticeCourseInfo[nRow].sExamCycleTimeRange);
  181. if(bIsInWeek && bIsInTimeRange && bIsInExamTime)
  182. {
  183. emit enterExam(cot, m_vPracticeCourseInfo[nRow].nExamId, m_vPracticeCourseInfo[nRow].nExamStudentId,
  184. m_vPracticeCourseInfo[nRow].sCourseCode, m_vPracticeCourseInfo[nRow].sCourseName);
  185. }
  186. }
  187. });
  188. connect(clo, &clOperation::viewPracticeDetail, this, [&](int nRow){
  189. if(m_pResultList == nullptr)
  190. {
  191. m_pResultList = std::make_shared<clopResultList>(m_vPracticeCourseInfo[nRow], ui->cbo_batch->currentText(), this);
  192. connect(m_pResultList.get(), &clopResultList::goback, this, [&](){
  193. m_pResultList.reset();
  194. });
  195. m_pResultList->setUI(0, 0, width(), height());
  196. }
  197. m_pResultList->show();
  198. });
  199. clo->setUI(ui->tablewt_examList->columnWidth(7), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_practice);
  200. clo->setBtn1Enable(bIsInWeek && bIsInTimeRange && bIsInExamTime );
  201. ui->tablewt_examList->setCellWidget(i, 7, clo);
  202. }
  203. m_vPracticeCourseInfo.swap(queryPracticeCourseList.vPracticeCourseInfo);
  204. }
  205. else
  206. {
  207. if(queryPracticeCourseList.sMessage.isEmpty())
  208. {
  209. ShowMsg(QString::fromLocal8Bit("获取练习列表失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  210. }
  211. else
  212. {
  213. ShowMsg(queryPracticeCourseList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  214. }
  215. }
  216. }
  217. void clOnlinePractice::on_cbo_batch_currentIndexChanged(int index)
  218. {
  219. QString sExamId = ui->cbo_batch->currentData().toString();
  220. if(!sExamId.isEmpty())
  221. {
  222. m_nCurExamId = sExamId.toULongLong();
  223. myDebug() << "on_cbo_batch_currentIndexChanged"<<sExamId;
  224. CHttpRequestPackage hrp;
  225. hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryPracticeCourseList";
  226. hrp.sParamList.push_back(QString("examId,%1").arg(sExamId));
  227. hrp.nRequestType = RequestType::rtQueryPracticeCourseList;
  228. hrp.eParamType = HttpParamType::hptUrl;
  229. g_httpBllPtr->post(hrp);
  230. }
  231. }