feat:设备日志模块
feat:定时任务 feat:设置页面用路由重构
This commit is contained in:
1 parent
1033f403b1
commit
2efa7a3c19
60 files changed
+6560
-643
No files matched your search
@@ -28,6 +28,18 @@ abstract class AppSettingTool {
|
||||
"reservationQueryVerificationDateScope";
|
||||
static const String _serialCardConfigKey = "serialCardConfig";
|
||||
|
||||
/// v8 之前短暂保存定时任务配置的旧 sysJson 键,仅供一次性迁移读取。
|
||||
static const String _scheduledTaskConfigsKey = "scheduledTaskConfigs";
|
||||
|
||||
/// v8 之前短暂保存任务最近执行结果的旧 sysJson 键,仅供一次性迁移读取。
|
||||
static const String _scheduledTaskRecordsKey = "scheduledTaskRecords";
|
||||
|
||||
/// v8 之前保存日志文件成功上传状态的旧 sysJson 键,仅供一次性迁移读取。
|
||||
static const String _terminalLogUploadStatesKey = "terminalLogUploadStates";
|
||||
|
||||
/// v8 之前保存最近日志上传汇总的旧 sysJson 键,仅供一次性迁移清理。
|
||||
static const String _terminalLogUploadSummaryKey = "terminalLogUploadSummary";
|
||||
|
||||
/// 人工硬件输入历史在现有 sysJson 扩展配置中的存储键。
|
||||
static const String _hardwareInputHistoryKey = "hardwareInputHistory";
|
||||
|
||||
@@ -40,6 +52,9 @@ abstract class AppSettingTool {
|
||||
),
|
||||
);
|
||||
|
||||
/// sysJson 扩展数据的进程内写入队列,避免迁移清理与设置保存相互覆盖。
|
||||
static Future<void> _extensionWriteQueue = Future.value();
|
||||
|
||||
static Future<void> removeSettingCache() async {
|
||||
await _settingCache.emptyCache();
|
||||
}
|
||||
@@ -143,6 +158,100 @@ abstract class AppSettingTool {
|
||||
await _setSetting(sysJson: sysInfo);
|
||||
}
|
||||
|
||||
/// 读取完整 sysJson 为可修改映射,仅供旧结构化数据迁移方法使用。
|
||||
static Future<Map<String, dynamic>> _getSysExtensionJson() async {
|
||||
final setting = await _getSetting();
|
||||
return Map<String, dynamic>.from(json.decode(setting.sysJson));
|
||||
}
|
||||
|
||||
/// 仅用于把 v8 之前短暂写入 sysJson 的任务配置导入结构化表,不再提供 JSON 写入口。
|
||||
static Future<List<ScheduledTaskConfig>> getScheduledTaskConfigs() async {
|
||||
final sysJson = await _getSysExtensionJson();
|
||||
final raw = sysJson[_scheduledTaskConfigsKey];
|
||||
if (raw is! List) return const [];
|
||||
return raw
|
||||
.whereType<Map>()
|
||||
.map((item) => ScheduledTaskConfig.fromJson(
|
||||
Map<String, dynamic>.from(item),
|
||||
))
|
||||
.toList(growable: false);
|
||||
}
|
||||
|
||||
/// 读取 v8 之前的任务执行快照并按当前枚举过滤未知任务,仅用于迁移。
|
||||
static Future<Map<ScheduledTaskType, ScheduledTaskRecord>>
|
||||
getScheduledTaskRecords() async {
|
||||
final sysJson = await _getSysExtensionJson();
|
||||
final raw = sysJson[_scheduledTaskRecordsKey];
|
||||
if (raw is! Map) return const {};
|
||||
final result = <ScheduledTaskType, ScheduledTaskRecord>{};
|
||||
for (final entry in raw.entries) {
|
||||
ScheduledTaskType? type;
|
||||
for (final item in ScheduledTaskType.values) {
|
||||
if (item.name == entry.key.toString()) {
|
||||
type = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (type == null || entry.value is! Map) continue;
|
||||
result[type] = ScheduledTaskRecord.fromJson(
|
||||
Map<String, dynamic>.from(entry.value as Map),
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// 读取 v8 之前按相对路径保存的成功上传状态,仅用于导入文件上传记录表。
|
||||
static Future<Map<String, TerminalLogUploadState>>
|
||||
getTerminalLogUploadStates() async {
|
||||
final sysJson = await _getSysExtensionJson();
|
||||
final raw = sysJson[_terminalLogUploadStatesKey];
|
||||
if (raw is! Map) return const {};
|
||||
return raw.map(
|
||||
(key, value) => MapEntry(
|
||||
key.toString(),
|
||||
TerminalLogUploadState.fromJson(
|
||||
Map<String, dynamic>.from(value as Map),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 读取 v8 之前的最近上传汇总;仅保留兼容能力,不再作为运行时数据源。
|
||||
static Future<TerminalLogUploadSummary> getTerminalLogUploadSummary() async {
|
||||
final sysJson = await _getSysExtensionJson();
|
||||
final raw = sysJson[_terminalLogUploadSummaryKey];
|
||||
if (raw is! Map) return const TerminalLogUploadSummary();
|
||||
return TerminalLogUploadSummary.fromJson(Map<String, dynamic>.from(raw));
|
||||
}
|
||||
|
||||
/// v8 已将任务与上传状态迁入独立表,导入成功后移除旧 JSON,避免形成双写数据源。
|
||||
static Future<void> clearLegacyScheduledTaskState({
|
||||
required bool includeUploadState,
|
||||
}) async {
|
||||
final operation = _extensionWriteQueue.catchError((_) {}).then((_) async {
|
||||
final app = Get.find<AppControl>();
|
||||
final settingDao = app.dataBase.getSettingDao;
|
||||
final setting = await settingDao.get();
|
||||
if (setting == null) throw StateError('终端设置尚未初始化');
|
||||
final sysJson = Map<String, dynamic>.from(json.decode(setting.sysJson));
|
||||
sysJson.remove(_scheduledTaskConfigsKey);
|
||||
sysJson.remove(_scheduledTaskRecordsKey);
|
||||
if (includeUploadState) {
|
||||
sysJson.remove(_terminalLogUploadStatesKey);
|
||||
sysJson.remove(_terminalLogUploadSummaryKey);
|
||||
}
|
||||
setting.sysJson = json.encode(sysJson);
|
||||
await settingDao.edit(setting);
|
||||
await _settingCache.putFile(
|
||||
_settingKey,
|
||||
Uint8List.fromList(utf8.encode(json.encode(setting.toJson()))),
|
||||
fileExtension: 'json',
|
||||
);
|
||||
});
|
||||
_extensionWriteQueue = operation;
|
||||
await operation;
|
||||
}
|
||||
|
||||
static Future<void> setUserSetting(UserSetting userInfo) async {
|
||||
final globalUserInfo = await getUserSetting();
|
||||
if (globalUserInfo == userInfo) return;
|
||||
|
||||
Reference in new issue
Block a user