11
This commit is contained in:
1 parent
dc5ef2bc9e
commit
c4806fbaf2
5 files changed
+53
-34
No files matched your search
@@ -817,7 +817,14 @@ class SyncCheckTool {
|
||||
? _ScheduledTaskActionResult.skipped(update.message)
|
||||
: _ScheduledTaskActionResult.success(update.message);
|
||||
case ScheduledTaskType.configSync:
|
||||
await SyncConfigTool.autoSyncSysInfo();
|
||||
final result = await SyncConfigTool.autoSyncSysInfo();
|
||||
// 配置变化才广播刷新:面板页收到 CONFIG 会弹"配置修改中"遮罩,
|
||||
// 无条件广播会让收银页随定时周期反复被遮罩打断。
|
||||
if (result != null &&
|
||||
result.changed &&
|
||||
Get.isRegistered<AppControl>()) {
|
||||
Get.find<AppControl>().mqUpdateEventBus.fire(MqtActionEnum.CONFIG);
|
||||
}
|
||||
return const _ScheduledTaskActionResult.success('设备配置同步完成');
|
||||
case ScheduledTaskType.departmentFaceSync:
|
||||
final mode = request.debugAllFaces
|
||||
|
||||
@@ -4,11 +4,16 @@ import 'package:common_utils/common_utils.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
/// 设备配置同步结果:setting 为已落库的最新快照,changed 表示业务字段是否有变化。
|
||||
typedef SysConfigSyncResult = ({SysSetting setting, bool changed});
|
||||
|
||||
abstract class SyncConfigTool {
|
||||
static const _tag = "sync配置工具";
|
||||
|
||||
// 自动同步设备信息导本地缓存
|
||||
static Future<SysSetting?> autoSyncSysInfo() async {
|
||||
/// 自动同步设备信息到本地缓存;未登录、未绑定或接口失败返回 null。
|
||||
/// 返回的必须是同步后的最新快照:调用方会直接用它刷新界面(如基本信息页),
|
||||
/// 返回同步前的旧实例会让页面继续显示旧端口等配置。
|
||||
static Future<SysConfigSyncResult?> autoSyncSysInfo() async {
|
||||
final login = await AppUserTool.isLogin();
|
||||
if (!login) return null;
|
||||
final sysSetting = await AppSettingTool.getSysSetting();
|
||||
@@ -23,37 +28,32 @@ abstract class SyncConfigTool {
|
||||
return null;
|
||||
}
|
||||
// 基本信息
|
||||
await AppSettingTool.updateSysInfoByService(data);
|
||||
final changed = await AppSettingTool.updateSysInfoByService(data);
|
||||
// 人脸sdk
|
||||
await autoSyncFaceSdk(detail: data, sysInfo: sysSetting);
|
||||
logger.i("|$_tag|结束同步设备信息 sysInfo:|${json.encode(sysSetting)}|");
|
||||
return sysSetting;
|
||||
final latest = await AppSettingTool.getSysSetting();
|
||||
await autoSyncFaceSdk(
|
||||
detail: data,
|
||||
before: sysSetting,
|
||||
latest: latest,
|
||||
);
|
||||
logger.i("|$_tag|结束同步设备信息 sysInfo:|${json.encode(latest)}|");
|
||||
return (setting: latest, changed: changed);
|
||||
}
|
||||
|
||||
// 自动同步设备信息导本地缓存-同步人脸sdk
|
||||
/// 同步后检查人脸 SDK 参数并记录激活状态;回写必须用最新快照 latest。
|
||||
/// before 仅用于判定服务端是否变更了人脸参数;若用同步前的旧实例整体回写,
|
||||
/// 会把 updateSysInfoByService 刚写入的新 MQTT 配置回滚成旧值。
|
||||
static Future<void> autoSyncFaceSdk({
|
||||
required ServiceHardware detail,
|
||||
required SysSetting sysInfo,
|
||||
required SysSetting before,
|
||||
required SysSetting latest,
|
||||
}) async {
|
||||
final appId = detail.faceAppId;
|
||||
final sdkKey = detail.faceSdkKey;
|
||||
final activeKey = detail.faceActiveKey;
|
||||
bool isUpdate = false;
|
||||
if (appId != sysInfo.faceAppId) {
|
||||
sysInfo.faceAppId = appId;
|
||||
isUpdate = true;
|
||||
}
|
||||
if (sdkKey != sysInfo.faceSdkKey) {
|
||||
sysInfo.faceSdkKey = sdkKey;
|
||||
isUpdate = true;
|
||||
}
|
||||
if (activeKey != sysInfo.faceActiveKey) {
|
||||
sysInfo.faceActiveKey = activeKey;
|
||||
isUpdate = true;
|
||||
}
|
||||
if (!isUpdate) return;
|
||||
final changed = detail.faceAppId != before.faceAppId ||
|
||||
detail.faceSdkKey != before.faceSdkKey ||
|
||||
detail.faceActiveKey != before.faceActiveKey;
|
||||
if (!changed) return;
|
||||
final activeSdk = await AppFaceTool.isActiveSdk();
|
||||
await AppSettingTool.setSysSetting(sysInfo);
|
||||
await AppSettingTool.setSysSetting(latest);
|
||||
logger.i("|$_tag||同步人脸sdk参数自动激活${activeSdk ? '成功' : '失败'}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user