feat:消费机打印机
This commit is contained in:
1 parent
4d7bc5ed33
commit
4a18fc6eb1
39 files changed
+2061
-219
No files matched your search
@@ -19,6 +19,16 @@ class SyncCheckTool {
|
||||
/// 应用级任务调度单例,由 AppControl 初始化并由设置页读取响应式状态。
|
||||
static final SyncCheckTool instance = SyncCheckTool._();
|
||||
|
||||
/// 打印角色允许注册的后台任务;其余商品、人脸、订单和取餐任务属于收银角色。
|
||||
static const Set<ScheduledTaskType> _printerTaskTypes = {
|
||||
ScheduledTaskType.mqReconnect,
|
||||
ScheduledTaskType.printCheck,
|
||||
ScheduledTaskType.deviceStatus,
|
||||
ScheduledTaskType.autoUpdate,
|
||||
ScheduledTaskType.terminalLogUpload,
|
||||
ScheduledTaskType.expiredLogCleanup,
|
||||
};
|
||||
|
||||
/// 当前已加载的任务配置,以稳定任务类型为键并向设置页提供响应式更新。
|
||||
final configs = <ScheduledTaskType, ScheduledTaskConfig>{}.obs;
|
||||
|
||||
@@ -52,6 +62,16 @@ class SyncCheckTool {
|
||||
/// 是否已经完成本轮启动,防止 AppControl 重复注册相同 Cron 任务。
|
||||
bool _started = false;
|
||||
|
||||
/// 当前调度任务对应的终端角色;设备首次绑定改变角色时据此重建任务集合。
|
||||
TerminalRole? _activeRole;
|
||||
|
||||
/// 当前已经注册的终端角色,供状态诊断和测试确认角色切换结果。
|
||||
TerminalRole? get activeRole => _activeRole;
|
||||
|
||||
/// 当前注册到 Cron 的任务类型快照。
|
||||
Set<ScheduledTaskType> get scheduledTaskTypes =>
|
||||
Set.unmodifiable(_scheduledTasks.keys);
|
||||
|
||||
/// 当前进程最近一次补排部门人脸同步的本地日期,保证同一天最多自动补排一次。
|
||||
DateTime? _lastDepartmentFaceCatchUpDate;
|
||||
|
||||
@@ -333,19 +353,33 @@ class SyncCheckTool {
|
||||
),
|
||||
];
|
||||
|
||||
/// 初始化结构化配置并注册全部已启用任务;同一生命周期内重复调用直接返回。
|
||||
Future<void> startAll() async {
|
||||
if (_started) return;
|
||||
/// 初始化结构化配置并注册全部已启用任务;角色改变时先释放旧角色任务再重新注册。
|
||||
Future<void> startAll(
|
||||
{TerminalRole terminalRole = TerminalRole.cashier}) async {
|
||||
await _disposeFuture;
|
||||
if (_started && _activeRole == terminalRole) return;
|
||||
if (_started) await dispose();
|
||||
_started = true;
|
||||
_activeRole = terminalRole;
|
||||
_cron ??= Cron();
|
||||
await _loadState();
|
||||
for (final config in configs.values) {
|
||||
if (!supportsTask(terminalRole, config.type)) {
|
||||
continue;
|
||||
}
|
||||
await _rebuildTask(config);
|
||||
}
|
||||
queueMissedDepartmentFaceSync();
|
||||
if (terminalRole == TerminalRole.cashier) {
|
||||
queueMissedDepartmentFaceSync();
|
||||
}
|
||||
}
|
||||
|
||||
/// 判断指定角色是否允许执行某类后台任务,打印角色只保留通信、打印和运维任务。
|
||||
static bool supportsTask(
|
||||
TerminalRole terminalRole, ScheduledTaskType taskType) =>
|
||||
terminalRole == TerminalRole.cashier ||
|
||||
_printerTaskTypes.contains(taskType);
|
||||
|
||||
/// 在每天 00:40 之后检查当天是否成功完成部门人脸同步,并在首次启动或恢复时补排一次。
|
||||
///
|
||||
/// 补排只加入同一人脸任务队列并要求完整空闲,不会阻塞启动或打断支付、识别和业务弹框。
|
||||
@@ -787,6 +821,7 @@ class SyncCheckTool {
|
||||
if (!AppNetworkTool.isAutoNetwork()) {
|
||||
return const _ScheduledTaskActionResult.skipped('网络不可用,本次跳过');
|
||||
}
|
||||
await SyncPrintTool.pullPendingTasks();
|
||||
await SyncPrintTool.doCheckPrint();
|
||||
await SyncPrintTool.doCheckSync();
|
||||
return const _ScheduledTaskActionResult.success('打印任务检查完成');
|
||||
@@ -804,7 +839,14 @@ class SyncCheckTool {
|
||||
);
|
||||
return const _ScheduledTaskActionResult.success('取餐广播检查完成');
|
||||
case ScheduledTaskType.deviceStatus:
|
||||
await AppDeviceStatusTool.refreshAll();
|
||||
final setting = await AppSettingTool.getSysSetting();
|
||||
if (setting.terminalRole == TerminalRole.printer) {
|
||||
final available =
|
||||
await Get.find<AppControl>().printManage.checkAvailable();
|
||||
AppDeviceStatusTool.updatePrinter(available);
|
||||
} else {
|
||||
await AppDeviceStatusTool.refreshAll();
|
||||
}
|
||||
return const _ScheduledTaskActionResult.success('设备状态检查完成');
|
||||
case ScheduledTaskType.autoUpdate:
|
||||
final update = await TerminalAutoUpdateTool.run();
|
||||
@@ -1044,6 +1086,7 @@ class SyncCheckTool {
|
||||
/// 取消轮询和全部 Cron 句柄、清空待执行状态并关闭 Cron 实例。
|
||||
Future<void> _dispose() async {
|
||||
_started = false;
|
||||
_activeRole = null;
|
||||
_idleTimer?.cancel();
|
||||
_idleTimer = null;
|
||||
for (final task in _scheduledTasks.values) {
|
||||
|
||||
Reference in new issue
Block a user