feat: implement AI schedule app with multi-device sync
- Qt 6 desktop client with day/month/year views, AI scheduling, and TOML settings\n- Go sync server with SQLite change stream, WebSocket notifications, and Docker deployment\n- Client outbox/LWW sync, offline retry, and dual-client integration tests\n- Linux fcitx5 setup, validation reports, and Windows MinGW preset
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
|
||||
#include "core/ProposedDiff.h"
|
||||
#include "core/SyncTypes.h"
|
||||
#include "core/ScheduleItem.h"
|
||||
|
||||
/*
|
||||
* 类名: SqliteStore
|
||||
* 功能: SQLite 持久化与迁移;只暴露领域对象,不向上层泄漏 SQL 细节
|
||||
* 线程安全: 否;一个实例只允许在其创建线程使用(后续如需跨线程将按线程复用连接)
|
||||
*/
|
||||
class SqliteStore
|
||||
{
|
||||
public:
|
||||
explicit SqliteStore(QString databasePath);
|
||||
~SqliteStore();
|
||||
|
||||
SqliteStore(const SqliteStore&) = delete;
|
||||
SqliteStore& operator=(const SqliteStore&) = delete;
|
||||
|
||||
bool open(QString* error = nullptr);
|
||||
void close();
|
||||
bool isOpen() const;
|
||||
QString databasePath() const;
|
||||
QString lastError() const;
|
||||
int schemaVersion() const;
|
||||
|
||||
bool beginTransaction();
|
||||
bool commit();
|
||||
void rollback();
|
||||
|
||||
bool insertTask(const Task& task);
|
||||
bool updateTask(const Task& task);
|
||||
std::optional<Task> taskById(const QString& id);
|
||||
bool deleteTask(const QString& id);
|
||||
bool hasBlocksForTask(const QString& taskId);
|
||||
|
||||
bool insertTimeBlock(const TimeBlock& block);
|
||||
bool updateTimeBlock(const TimeBlock& block);
|
||||
std::optional<TimeBlock> timeBlockById(const QString& id);
|
||||
bool deleteTimeBlock(const QString& id);
|
||||
|
||||
bool insertProposedDiff(const ProposedDiff& diff);
|
||||
std::optional<ProposedDiff> proposedDiffById(const QString& id);
|
||||
bool updateProposedDiffState(const QString& id, const QString& state, const QString& resolvedAt);
|
||||
|
||||
// 返回与 [fromUtc, toUtc) 相交的所有块,按开始时间升序。
|
||||
QVector<ScheduleItem> blocksInRange(const QDateTime& fromUtc, const QDateTime& toUtc) const;
|
||||
// 已结束但仍未完成、且结束时间在最近 windowDays 内的块。
|
||||
QVector<ScheduleItem> overdueBefore(const QDateTime& nowUtc, int windowDays = 30) const;
|
||||
|
||||
QVector<SyncOutboxItem> outboxBatch(int limit, QString* error = nullptr) const;
|
||||
int outboxCount(QString* error = nullptr) const;
|
||||
bool clearOutboxThrough(qint64 id, QString* error = nullptr);
|
||||
bool setRemoteApplySuppressed(bool enabled, QString* error = nullptr);
|
||||
bool applyRemoteChange(const RemoteChange& change, QString* error = nullptr);
|
||||
qint64 syncCursor(const QString& deviceId, QString* error = nullptr) const;
|
||||
bool setSyncCursor(const QString& deviceId, qint64 seq, QString* error = nullptr);
|
||||
|
||||
private:
|
||||
bool openDatabase(QString* error);
|
||||
bool configureConnection(QString* error);
|
||||
bool migrate(QString* error);
|
||||
bool execScriptStatement(const QString& sql);
|
||||
bool setError(const QString& message) const;
|
||||
bool isOpenInternal() const;
|
||||
|
||||
static QString makeConnectionName();
|
||||
|
||||
QString m_databasePath;
|
||||
QString m_connectionName;
|
||||
QSqlDatabase m_database;
|
||||
int m_schemaVersion = 0;
|
||||
mutable QString m_lastError;
|
||||
};
|
||||
Reference in New Issue
Block a user