PC 端完成
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#ifndef API_CLIENT_H
|
||||
#define API_CLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
#include <QMap>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include "AttendanceTypes.h"
|
||||
|
||||
class ApiClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ApiClient(QObject *parent = nullptr);
|
||||
|
||||
void setServerUrl(const QString &url);
|
||||
QString serverUrl() const;
|
||||
|
||||
void fetchRecords(int limit = 1000, int offset = 0);
|
||||
void fetchStatistics();
|
||||
void clearAllRecords();
|
||||
void deleteRecord(const QString ×tamp, const QString &studentId);
|
||||
void fetchTimeSlots();
|
||||
void uploadTimeSlots(const QVector<TimeSlot> &timeSlots);
|
||||
void fetchMappingConfig();
|
||||
void uploadMappingConfig(const QMap<QString, QString> &studentNameMap,
|
||||
const QMap<QString, QString> &classNameMap);
|
||||
void fetchFaceIdMapping();
|
||||
void uploadFaceIdMapping(const QMap<QString, QString> &mapping);
|
||||
void fetchFacePhotos();
|
||||
void fetchAllStudentIds();
|
||||
void deleteFace(const QString &studentId, bool deleteRecords);
|
||||
void checkHealth();
|
||||
|
||||
signals:
|
||||
void recordsFetched(const QVector<AttendanceRecord> &records);
|
||||
void statisticsFetched(int total, int today, const QString &serverTime);
|
||||
void recordsCleared(bool success, const QString &message);
|
||||
void recordDeleted(bool success, const QString &message);
|
||||
void timeSlotsFetched(const QVector<TimeSlot> &timeSlots);
|
||||
void timeSlotsUploaded(bool success, const QString &message);
|
||||
void mappingConfigFetched(const QMap<QString, QString> &studentNameMap,
|
||||
const QMap<QString, QString> &classNameMap);
|
||||
void mappingConfigUploaded(bool success, const QString &message);
|
||||
void faceIdMappingFetched(const QMap<QString, QString> &mapping);
|
||||
void faceIdMappingUploaded(bool success, const QString &message);
|
||||
void facePhotosFetched(const QStringList &photoIds);
|
||||
void allStudentIdsFetched(const QStringList &studentIds);
|
||||
void faceDeleted(bool success, const QString &studentId, int recordsDeleted, const QString &message);
|
||||
void healthChecked(bool healthy, const QString &message);
|
||||
void connectionUnavailable(const QString &message);
|
||||
void networkError(const QString &message);
|
||||
|
||||
private:
|
||||
QString buildUrl(const QString &endpoint, const QMap<QString, QString> ¶ms = {}) const;
|
||||
QNetworkRequest createRequest(const QString &url, bool encryptedResponse = false) const;
|
||||
QVector<AttendanceRecord> parseRecords(const QByteArray &data) const;
|
||||
QByteArray maybeDecrypt(const QByteArray &data, bool encrypted) const;
|
||||
void emitNetworkError(const QString &prefix, QNetworkReply *reply);
|
||||
bool isConnectionError(QNetworkReply::NetworkError error) const;
|
||||
|
||||
QNetworkAccessManager m_networkManager;
|
||||
QString m_serverUrl;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user