123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- #include "clOfflineExam.h"
- #include "ui_clOfflineExam.h"
- #include "CAppInfo.h"
- #include "clOperation.h"
- #include "awMsgBox.h"
- #include <QScrollBar>
- #include <QFileDialog>
- clOfflineExam::clOfflineExam(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::clOfflineExam)
- {
- ui->setupUi(this);
- setStyleSheet(g_appInfoPtr->m_sQssStr);
- qRegisterMetaType<CGetOfflineCourse>("CGetOfflineCourse");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnGetOfflineCourse, this, &clOfflineExam::onGetOfflineCourse);
- qRegisterMetaType<CGetOffLineExamAnswerSheet>("CGetOffLineExamAnswerSheet");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnGetOffLineExamAnswerSheet, this, &clOfflineExam::onGetOffLineExamAnswerSheet);
- qRegisterMetaType<CStartOfflineExam>("CStartOfflineExam");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnStartOfflineExam, this, &clOfflineExam::onStartOfflineExam);
- qRegisterMetaType<CGetOffLineExamPaper>("CGetOffLineExamPaper");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnGetOffLineExamPaper, this, &clOfflineExam::onGetOffLineExamPaper);
- qRegisterMetaType<CPreviewOffLineExamPaper>("CPreviewOffLineExamPaper");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnPreviewOffLineExamPaper, this, &clOfflineExam::onPreviewOffLineExamPaper);
- qRegisterMetaType<CGetExamProperty>("CGetExamProperty");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamProperty, this, &clOfflineExam::onGetExamProperty);
- qRegisterMetaType<CDownLoadFileInfo>("CDownLoadFileInfo");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnDownLoadFile, this, &clOfflineExam::onDownLoadFile);
- }
- clOfflineExam::~clOfflineExam()
- {
- delete ui;
- }
- void clOfflineExam::setUI(const int nWidth, const int nHeight)
- {
- setGeometry(0, 0, nWidth, nHeight);
- ui->widget_offlineExam->setGeometry(0, 0, width(), height());
- ui->widget_op_top->setGeometry(0, 0, width(), g_appInfoPtr->m_fRate*72);
- ui->btn_downloadAnswerSheet->setGeometry(ui->widget_op_top->width() - g_appInfoPtr->m_fRate*30 - g_appInfoPtr->m_fRate*144,
- (ui->widget_op_top->height() - g_appInfoPtr->m_fRate*32)/2,
- g_appInfoPtr->m_fRate*144, g_appInfoPtr->m_fRate*32);
- ui->btn_downloadAnswerSheet->setVisible(false);
- ui->btn_downloadAnswerSheet->setIconSize(QSize(g_appInfoPtr->m_fRate*14, g_appInfoPtr->m_fRate*14));
- ui->btn_downloadAnswerSheet->setIcon(QIcon(":/images/icon-download-answer-sheet.png"));
- ui->tablewt_examList->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_op_top->height() + g_appInfoPtr->m_fRate*10,
- ui->widget_offlineExam->width() - g_appInfoPtr->m_fRate*30*2,
- ui->widget_offlineExam->height() - ui->widget_op_top->height() - g_appInfoPtr->m_fRate*(10 + 62));
- ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers);
- //整行选中的方式
- ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows);
- //设置为只能选中一行
- ui->tablewt_examList->setSelectionMode(QAbstractItemView::SingleSelection);
- //隐藏列表头
- ui->tablewt_examList->verticalHeader()->setVisible(false);
- //隐藏边框
- ui->tablewt_examList->setShowGrid(false);
- //表头不高亮显示
- ui->tablewt_examList->horizontalHeader()->setHighlightSections(false);
- //设置行数
- ui->tablewt_examList->setRowCount(10);
- //设置列数
- ui->tablewt_examList->setColumnCount(5);
- ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
- ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
- QStringList sHeadStr;
- sHeadStr << QString::fromLocal8Bit("课程") <<
- QString::fromLocal8Bit("专业") <<
- QString::fromLocal8Bit("进入考试时间") <<
- QString::fromLocal8Bit("状态") <<
- QString::fromLocal8Bit("操作");
- ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
- ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
- ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
- ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
- ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*240);
- ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*220);
- ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*340);
- ui->tablewt_examList->setColumnWidth(3, g_appInfoPtr->m_fRate*90);
- ui->tablewt_examList->setColumnWidth(4, g_appInfoPtr->m_fRate*232);
- ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
-
- }
- void clOfflineExam::showEvent(QShowEvent *)
- {
- refreshCourse();
- }
- void clOfflineExam::refreshCourse()
- {
- CHttpRequestPackage hrp1;
- hrp1.sUri = "/api/ecs_core/org/getAnswersUrl/" + g_appInfoPtr->m_sRootOrgId;
- hrp1.nRequestType = RequestType::rtGetOffLineExamAnswerSheet;
- g_httpBllPtr->get(hrp1);
- CHttpRequestPackage hrp;
- hrp.sUri = "/api/ecs_oe_admin/client/exam/process/getOfflineCourse";
- hrp.nRequestType = RequestType::rtGetOfflineCourse;
- g_httpBllPtr->post(hrp);
- }
- void clOfflineExam::onGetOfflineCourse(CGetOfflineCourse getOfflineCourse)
- {
- if (getOfflineCourse.nCode == 200)
- {
- int nSize = getOfflineCourse.vOfflineCourseInfo.size();
- ui->tablewt_examList->setRowCount(nSize);
- for (int i = 0; i < nSize; ++i)
- {
- COfflineCourseInfo oci = getOfflineCourse.vOfflineCourseInfo[i];
- ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(oci.sCourseName));
- ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(oci.sSpecialtyName));
- ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(oci.sStartTime).arg(oci.sEndTime)));
- CL_OPERATION_TYPE sAnswerStatus = CL_OPERATION_TYPE::cot_offline_status_null;
- CL_OPERATION_TYPE otStatus = CL_OPERATION_TYPE::cot_offline_init_exam;
- if (!oci.sStatus.isEmpty())
- {
- otStatus = CL_OPERATION_TYPE::cot_offline_exam;
- if (oci.vOfflineFileInfo.size() > 0)
- {
- sAnswerStatus = CL_OPERATION_TYPE::cot_offline_status_download;
- }
- }
- clOperation *cloStatus = new clOperation(i, ui->tablewt_examList);
- connect(cloStatus, &clOperation::downloadOfflineAnswer, this, [&](int nRow){
- QString sExportDir = QFileDialog::getExistingDirectory(
- this, QString::fromLocal8Bit("选择导出目录"),
- "/");
- if (sExportDir.isEmpty())
- {
- return;
- }
- //导出
- if (sExportDir.right(1) != "/")
- {
- sExportDir += "/";
- }
- COfflineCourseInfo &oci = m_vOfflineCourseInfo[nRow];
- for (COfflineFileInfo &fileInfo : oci.vOfflineFileInfo)
- {
- QString sFileName = fileInfo.sOfflineFileUrl.right(fileInfo.sOfflineFileUrl.length() - fileInfo.sOfflineFileUrl.lastIndexOf("/") - 1);
- QString sAnswerFile = sExportDir + sFileName;
- fileInfo.sLocalFileName = sAnswerFile;
- CHttpRequestPackage hrp;
- hrp.sUri = fileInfo.sOfflineFileUrl;
- hrp.sCommonStr = sAnswerFile;
- hrp.sAdditionStr = QString::number(nRow);
- hrp.sCommonStr1 = __FILE__;
- hrp.nRequestType = RequestType::rtDownLoadFile;
- hrp.nRetryCount = 3;
- g_httpBllPtr->downLoad(hrp);
- }
- });
- cloStatus->setUI(ui->tablewt_examList->columnWidth(4), ui->tablewt_examList->rowHeight(i), sAnswerStatus);
- ui->tablewt_examList->setCellWidget(i, 3, cloStatus);
- clOperation *clo = new clOperation(i, ui->tablewt_examList);
- connect(clo, &clOperation::offlineExamStart, this, [&](int nRow){
- COfflineCourseInfo oci = m_vOfflineCourseInfo[nRow];
-
- CHttpRequestPackage hrp;
- hrp.sUri = "/api/ecs_oe_admin/client/exam/process/startOfflineExam";
- hrp.sParamList.push_back(QString("examStudentId,%1").arg(oci.nExamStudentId));
- hrp.nRequestType = RequestType::rtStartOfflineExam;
- hrp.eParamType = HttpParamType::hptUrl;
- hrp.sCommonStr = QString::number(nRow);
- g_httpBllPtr->post(hrp);
- });
- connect(clo, &clOperation::viewOfflinePaper, this, [&](int nRow){
- COfflineCourseInfo oci = m_vOfflineCourseInfo[nRow];
-
- CHttpRequestPackage hrp;
- hrp.sUri = QString("/api/branch_ecs_ques/paper/%1").arg(oci.sPaperId);
- hrp.nRequestType = RequestType::rtPreviewOffLineExamPaper;
- hrp.sCommonStr = QString::number(nRow);
- g_httpBllPtr->get(hrp);
- });
- connect(clo, &clOperation::downloadOfflinePaper, this, [&](int nRow){
- COfflineCourseInfo oci = m_vOfflineCourseInfo[nRow];
-
- // QString sExportDir = QFileDialog::getExistingDirectory(
- // this, QString::fromLocal8Bit("选择下载目录"),
- // "/");
- // if (sExportDir.isEmpty())
- // {
- // return;
- // }
- // //导出
- // if (sExportDir.right(1) != "/")
- // {
- // sExportDir += "/";
- // }
- QString sPaperFile = oci.sCourseCode + "_" + oci.sCourseName + ".zip";
- sPaperFile = QFileDialog::getSaveFileName(
- this, oci.sPaperId, sPaperFile,
- "All Files(*.*)");
- if(sPaperFile.isEmpty())
- {
- return;
- }
-
- if (!QFile::exists(sPaperFile))
- {
- CHttpRequestPackage hrp;
- hrp.sUri = QString("/api/branch_ecs_ques/paper/export/%1/PAPER/offLine").arg(oci.sPaperId);
- hrp.nRequestType = RequestType::rtGetOffLineExamPaper;
- hrp.sCommonStr = sPaperFile;
- g_httpBllPtr->get(hrp);
- }
-
- });
- connect(clo, &clOperation::uploadOfflineAnswer, this, [&](int nRow){
- COfflineCourseInfo oci = m_vOfflineCourseInfo[nRow];
- CHttpRequestPackage hrp;
- hrp.sUri = QString("/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/%1/%2")
- .arg(oci.nExamId).arg("OFFLINE_UPLOAD_FILE_TYPE");
- hrp.nRequestType = RequestType::rtGetExamProperty;
- hrp.sCommonStr = "OFFLINE_UPLOAD_FILE_TYPE;" + QString::number(oci.nExamRecordDataId);
- g_httpBllPtr->get(hrp);
- });
- clo->setUI(ui->tablewt_examList->columnWidth(4), ui->tablewt_examList->rowHeight(i), otStatus);
- ui->tablewt_examList->setCellWidget(i, 4, clo);
- }
- m_vOfflineCourseInfo.swap(getOfflineCourse.vOfflineCourseInfo);
- }
- else
- {
- if(getOfflineCourse.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("获取离线考试信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(getOfflineCourse.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- }
- }
- void clOfflineExam::onDownLoadFile(CDownLoadFileInfo downLoadFileInfo)
- {
- if (downLoadFileInfo.sModuleName == __FILE__)
- {
- if(downLoadFileInfo.nCode == 200)
- {
- if(downLoadFileInfo.sAdditionStr == "downloadAnswerSheet")
- {
- ShowMsg(QString::fromLocal8Bit("下载完成"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_succeed);
- }
- else
- {
- int nRow = downLoadFileInfo.sAdditionStr.toInt();
- COfflineCourseInfo oci = m_vOfflineCourseInfo[nRow];
- QString sLocalFileName = oci.vOfflineFileInfo[oci.vOfflineFileInfo.size() - 1].sLocalFileName;
- if(sLocalFileName == downLoadFileInfo.sFileName)
- {
- ShowMsg(QString::fromLocal8Bit("下载完成"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_succeed);
- }
- }
- }
- else
- {
- if(downLoadFileInfo.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("下载失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(downLoadFileInfo.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- }
- }
- // downLoadFileInfo
- // QString sFileName = g_appInfoPtr->m_sStudentPhotoPath.right(g_appInfoPtr->m_sStudentPhotoPath.length() - g_appInfoPtr->m_sStudentPhotoPath.lastIndexOf("/") - 1);
- // QString sAudioFile = g_appInfoPtr->m_sCacheFileDir + "cache/" + sFileName;
- // if (downLoadFileInfo.sFileName == sAudioFile)
- // {
- // if (downLoadFileInfo.nCode == 200)
- // {
- // int nSecord = g_audioPalyerPtr->GetMediaDuration(sAudioFile);
- // m_nMaxTestSecord = nSecord;
- // QString sText = QString("00:00 / %1:%2")
- // .arg((int)(nSecord/60), 2, 10, QChar('0'))
- // .arg((int)(nSecord%60), 2, 10, QChar('0'));
- // ui->label_ap_time->setText(sText);
- // }
- // else
- // {
- // }
- // }
- }
- void clOfflineExam::onGetOffLineExamAnswerSheet(CGetOffLineExamAnswerSheet getOffLineExamAnswerSheet)
- {
- if (getOffLineExamAnswerSheet.nCode == 200)
- {
- if (!getOffLineExamAnswerSheet.sAnswerSheetUrl.isEmpty())
- {
- m_sAnswerSheetUrl = getOffLineExamAnswerSheet.sAnswerSheetUrl;
- ui->btn_downloadAnswerSheet->setVisible(true);
- }
- }
- else
- {
- if(getOffLineExamAnswerSheet.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("获取离线考试信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(getOffLineExamAnswerSheet.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- }
- }
- void clOfflineExam::onStartOfflineExam(CStartOfflineExam startOfflineExam)
- {
- if (startOfflineExam.nCode == 200)
- {
- refreshCourse();
- // int nRow = startOfflineExam.nRow;
- // COfflineCourseInfo &oci = m_vOfflineCourseInfo[nRow];
- // oci.sStatus = "EXAM_ING";
-
- // clOperation *op = dynamic_cast<clOperation*>(ui->tablewt_examList->cellWidget(nRow, 4));
- // if (op)
- // {
- // op->setOperationType(CL_OPERATION_TYPE::cot_offline_exam);
- // }
- // CHttpRequestPackage hrp;
- // hrp.sUri = QString("/api/branch_ecs_ques/paper/export/%1/PAPER/offLine").arg(oci.sPaperId);
- // hrp.nRequestType = RequestType::rtGetOffLineExamPaper;
- // hrp.sCommonStr = QString::number(nRow);
- // g_httpBllPtr->get(hrp);
- }
- else
- {
- if(startOfflineExam.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("离线考试开考失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(startOfflineExam.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- }
- }
- void clOfflineExam::onGetOffLineExamPaper(CGetOffLineExamPaper getOffLineExamPaper)
- {
- if (getOffLineExamPaper.nCode == 200)
- {
- ShowMsg(QString::fromLocal8Bit("下载试卷完成"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_succeed);
- }
- else
- {
- if(getOffLineExamPaper.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("离线考试下载试卷失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(getOffLineExamPaper.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- }
- }
- void clOfflineExam::onPreviewOffLineExamPaper(CPreviewOffLineExamPaper previewOffLineExamPaper)
- {
- if (previewOffLineExamPaper.nCode == 200)
- {
- int nRow = previewOffLineExamPaper.nRow;
- if (m_pViewPaper == nullptr)
- {
- m_pViewPaper = std::make_shared<cloeViewPaper>(previewOffLineExamPaper.sUrl, (QWidget*)this->parent()->parent());
- connect(m_pViewPaper.get(), &cloeViewPaper::goback, this, [&](){
- m_pViewPaper.reset();
- });
- }
- if(nRow >= 0 && nRow < m_vOfflineCourseInfo.size())
- {
- COfflineCourseInfo oci = m_vOfflineCourseInfo[nRow];
- m_pViewPaper->setCourseCodeAndName(oci.sCourseCode, oci.sCourseName);
- }
- m_pViewPaper->show();
- }
- else
- {
- if(previewOffLineExamPaper.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("离线考试下载试卷失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(previewOffLineExamPaper.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- }
- }
- void clOfflineExam::onGetExamProperty(CGetExamProperty getExamProperty)
- {
- if (getExamProperty.nCode == 200)
- {
- QStringList sList = getExamProperty.sType.split(";");
- if (sList.count() != 2)
- {
- return;
- }
- if (sList[0] == "OFFLINE_UPLOAD_FILE_TYPE")
- {
- if(m_pUploadFile == nullptr)
- {
- m_pUploadFile = std::make_shared<cloeUploadFile>(sList[1].toLongLong(), getExamProperty.vOfflineUploadFileType, (QWidget*)this->parent()->parent());
- connect(m_pUploadFile.get(), &cloeUploadFile::cancel, this, [&](){
- m_pUploadFile.reset();
- });
- connect(m_pUploadFile.get(), &cloeUploadFile::uploadSucceed, this, [&]() {
- m_pUploadFile.reset();
-
- CHttpRequestPackage hrp;
- hrp.sUri = "/api/ecs_oe_admin/client/exam/process/getOfflineCourse";
- hrp.nRequestType = RequestType::rtGetOfflineCourse;
- g_httpBllPtr->post(hrp);
- });
- }
- m_pUploadFile->show();
- }
- }
- else
- {
- if(getExamProperty.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("获取离线考试信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(getExamProperty.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
- }
- }
- }
- void clOfflineExam::on_btn_downloadAnswerSheet_clicked()
- {
- // QString sExportDir = QFileDialog::getExistingDirectory(
- // this, QString::fromLocal8Bit("选择下载目录"),
- // "/");
- // if (sExportDir.isEmpty())
- // {
- // return;
- // }
- // //导出
- // if (sExportDir.right(1) != "/")
- // {
- // sExportDir += "/";
- // }
- QString sFileName = m_sAnswerSheetUrl.right(m_sAnswerSheetUrl.length() - m_sAnswerSheetUrl.lastIndexOf("/") - 1);
- // QString sAnswerFile = sExportDir + sFileName;
- QString sAnswerFile = QFileDialog::getSaveFileName(
- this, m_sAnswerSheetUrl, QFileInfo(sFileName).fileName(),
- "All Files(*.*)");
- if(sAnswerFile.isEmpty())
- {
- return;
- }
- CHttpRequestPackage hrp;
- hrp.sUri = m_sAnswerSheetUrl;
- hrp.sCommonStr = sAnswerFile;
- hrp.sAdditionStr = "downloadAnswerSheet";
- hrp.sCommonStr1 = __FILE__;
- hrp.nRequestType = RequestType::rtDownLoadFile;
- hrp.nRetryCount = 3;
- g_httpBllPtr->downLoad(hrp);
- }
|