zhuizhu 10 месяцев назад
Родитель
Сommit
902b8d3f9a
7 измененных файлов с 81 добавлено и 12 удалено
  1. 1 1
      api/tapi.cpp
  2. 10 0
      appevent.cpp
  3. 5 0
      appevent.h
  4. 30 0
      examquestionpage.cpp
  5. 15 0
      main.cpp
  6. 10 7
      studentpage.cpp
  7. 10 4
      tcontroller.cpp

+ 1 - 1
api/tapi.cpp

@@ -52,7 +52,7 @@ static QMap<RequestCode, QString> errorMessages
 static QString base_url("http://exam.stem993.cn");
 
 static const QLatin1String scCode("code");
-static const QLatin1String scMessage("message");
+static const QLatin1String scMessage("msg");
 static const QLatin1String scData("data");
 
 // 响应拦截

+ 10 - 0
appevent.cpp

@@ -165,6 +165,16 @@ QJsonObject AppEvent::config() const
     return d->jsonConfig;
 }
 
+QStringList AppEvent::configFilter() const
+{
+    return {"serverIP",
+            "serverPort",
+            "webSocketIP",
+            "webSocketPort",
+            "savedUsername",
+            "savedPassword"};
+}
+
 void AppEvent::loginUser(qint64 id)
 {
     emit loginUserSignal(id);

+ 5 - 0
appevent.h

@@ -54,6 +54,11 @@ public:
     bool configSave();
     QJsonObject config() const;
 
+    // 自己得配置不导出到客户端的
+
+    QStringList configFilter() const;
+    ;
+
     // 更新数据
     void loginUser(qint64 id);
     void loginOutUser(qint64 id);

+ 30 - 0
examquestionpage.cpp

@@ -8,6 +8,7 @@
 #include "widgets/examsmodel.h"
 #include "widgets/pagination.h"
 
+#include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
 #include <QDialog>
@@ -15,6 +16,7 @@
 #include <QHeaderView>
 #include <QLabel>
 #include <QLineEdit>
+#include <QMessageBox>
 #include <QStatusBar>
 #include <QStyledItemDelegate>
 #include <QTableView>
@@ -235,6 +237,7 @@ void ExamsQuestionPage::removeExamsQuestion()
     const QModelIndex index = examsView->currentIndex();
     ExamsTableModel::Exams exams = model->getCurrentExam(index);
     if (exams.id == 0) {
+        qDebug() << "删除不存在id";
         return;
     }
 
@@ -263,6 +266,33 @@ void ExamsQuestionPage::save()
     }
 
     ExamsQuestionModel examsModel(storage);
+    {
+        CWF::SqlQueryManager queryManager(storage);
+        queryManager.select("*", examsModel.getTableName()).where("name = ?");
+        queryManager.prepare();
+        queryManager.addBindValue(examsNameLineEdit->text());
+        queryManager.exec();
+
+        QJsonObject status = queryManager.exec();
+
+        if (status["success"].toBool()) {
+            QJsonArray jsonArray = queryManager.toJson();
+            qDebug() << jsonArray;
+            if (jsonArray.size() > 0) {
+                const QWidgetList widgetList = QApplication::topLevelWidgets();
+                QWidget *parentWidget = nullptr;
+                if (!widgetList.isEmpty()) {
+                    parentWidget = widgetList.first();
+                }
+                QMessageBox::critical(parentWidget,
+                                      tr("Error"),
+                                      QString("存在同名考题[%1] 请修改或者更换一个考题名")
+                                          .arg(examsNameLineEdit->text()));
+                return;
+            }
+        }
+    }
+
     CWF::SqlQueryManager queryManager(storage);
     //queryManager.select("*", examsModel.getTableName()).where("isSelect = ?");
     queryManager.update(examsModel.getTableName(), "name=?,fileDir=?,isSelect=?").where("id = ?");

+ 15 - 0
main.cpp

@@ -112,6 +112,21 @@ int main(int argc, char *argv[])
     ExamsQuestionModel{storage}.updateDB();
     ExamsTestModel{storage}.updateDB();
 
+    CWF::SqlQuery query(storage);
+
+    // 清理数据库
+    QJsonObject status = query.exec(R"(DELETE FROM exams_question
+WHERE id NOT IN (
+    SELECT MIN(id)
+    FROM exams_question
+    GROUP BY name
+);)");
+    if (status["success"].toBool()) {
+        //
+    } else {
+        qDebug() << "清理 exams_question 数据库失败";
+    }
+
     MiddlewareFilter middlewareFilter;
     CWF::CppWebApplication server("/server", &middlewareFilter);
 

+ 10 - 7
studentpage.cpp

@@ -331,16 +331,16 @@ void StudentPage::importFile()
     int checkinNumberIndex = -1;
     int schoolIndex = -1;
 
-    for (int col = 0; col < 8; ++col) {
+    for (int col = 0; col < 20; ++col) {
         QVariant value = xlsx.read(1, col);
         QString strValue = value.toString();
-
+        qDebug() << strValue;
         if (strValue == "\xE5\xA7\x93\xE5\x90\x8D") { // UTF-8 编码的 "姓名"
             nameIndex = col;
         } else if (strValue == "\x53\x57\x5F\x49\x44") { // UTF-8 编码的 "SW_ID"
             SWIDIndex = col;
-        } else if (strValue
-                   == "\xE8\x80\x83\xE8\xAF\x95\xE7\xBC\x96\xE5\x8F\xB7") { // UTF-8 编码的 "考试编号"
+        } else if (strValue == "\xE8\x80\x83\xE8\xAF\x95\xE7\xBC\x96\xE5\x8F\xB7"
+                   || strValue == "赛队编号") { // UTF-8 编码的 "考试编号"
             examineeNumberIndex = col;
         } else if (strValue
                    == "\xE8\x80\x83\xE8\xAF\x95\xE5\x86\x85\xE5\xAE\xB9") { // UTF-8 编码的 "考试内容"
@@ -348,15 +348,18 @@ void StudentPage::importFile()
         } else if (strValue == "\xE7\xBB\x84\xE5\x88\xAB") { // UTF-8 编码的 "组别"
             groupIndex = col;
         } else if (strValue
-                   == "\xE6\x9C\x80\xE5\xA4\xA7\xE5\xAE\x8C\xE6\x88\x90\xE6\x97\xB6\xE9\x97" "\xB4") { // UTF-8 编码的 "最大完成时间"
+                   == "\xE6\x9C\x80\xE5\xA4\xA7\xE5\xAE\x8C\xE6\x88\x90\xE6\x97\xB6\xE9\x97"
+                      "\xB4") { // UTF-8 编码的 "最大完成时间"
             maxTimeIndex = col;
         } else if (strValue
                    == "\xE5\xAE\x8C\xE6\x88\x90\xE6\x97\xB6\xE9\x97\xB4") { // UTF-8 编码的 "完成时间"
             timeIndex = col;
         } else if (strValue
-                   == "\xE7\xAD\x94\xE6\xA1\x88\xE6\x96\x87\xE4\xBB\xB6\xE5\x90\x8D\xE7\xA7" "\xB0") { // UTF-8 编码的 "答案文件名称"
+                   == "\xE7\xAD\x94\xE6\xA1\x88\xE6\x96\x87\xE4\xBB\xB6\xE5\x90\x8D\xE7\xA7"
+                      "\xB0") { // UTF-8 编码的 "答案文件名称"
             AnswerFileNameIndex = col;
-        } else if (strValue == "\347\255\276\345\210\260\345\217\267") { // UTF-8 编码的 "签到号"
+        } else if (strValue == "\347\255\276\345\210\260\345\217\267"
+                   || strValue == "座位号") { // UTF-8 编码的 "签到号"
             checkinNumberIndex = col;
         } else if (strValue == "\345\255\246\346\240\241") { // UTF-8 编码的 "学校"
             schoolIndex = col;

+ 10 - 4
tcontroller.cpp

@@ -370,12 +370,12 @@ void ExamsController::doPost(CWF::Request &request, CWF::Response &response) con
             }
         }
     }
-
+    qDebug() << "个人考试题目:" << examContent;
     UserModel user(storage);
     ExamsQuestionModel exams(storage);
 
     // 个人考试内容是空 获取默认选择的考试内容
-    if (examContent.isEmpty()) {
+    if (examContent.isEmpty() || examContent == "") {
         CWF::SqlQuery query(storage);
         QJsonObject status = query.exec(QString("SELECT * FROM exams_question WHERE isSelect = 1"));
         if (status["success"].toBool()) {
@@ -386,7 +386,7 @@ void ExamsController::doPost(CWF::Request &request, CWF::Response &response) con
             }
         }
     }
-
+    qDebug() << "使用考试题目:" << examContent;
     // 获取考试内容
 
     CWF::SqlQueryManager queryManager(storage);
@@ -403,10 +403,15 @@ void ExamsController::doPost(CWF::Request &request, CWF::Response &response) con
                         {"data", QJsonValue()}});
         return;
     }
+    qDebug() << "数据库考试题目:" << jsonArray;
     for (const QJsonValue &json : jsonArray) {
         if (json.isObject()) {
             QJsonObject obj = json.toObject();
             const QString dir = obj["fileDir"].toString();
+            if (dir == "") {
+                continue;
+            }
+            qDebug() << "数据库考试题目信息文件或者目录:" << dir;
 
             const QStringList files = listFiles(dir, dir);
             response.write(QJsonObject{{"status", true},
@@ -517,7 +522,7 @@ void ExamsFilesController::doGet(CWF::Request &request, CWF::Response &response)
         response.addHeader(CWF::HTTP::CONTENT_TYPE, getMimeType(fileName).toUtf8());
         response.write(file.readAll());
     } else {
-        response.sendJsonError(0, file.errorString().toUtf8());
+        response.sendJsonError(0, (file.errorString() + path).toUtf8());
     }
 }
 
@@ -603,6 +608,7 @@ void UploadedFilesController::doPost(CWF::Request &request, CWF::Response &respo
                                .arg(user.getName())
                                .arg(user.getExamineeNumber())
                                .arg(QString(it.key()));
+                continue;
             }
 
             const QString filePath = dir.absoluteFilePath(fileName);