70 lines
2.4 KiB
Dart
70 lines
2.4 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:common_utils/common_utils.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
abstract class SyncConfigTool {
|
|
static const _tag = "sync配置工具";
|
|
|
|
// 自动同步设备信息导本地缓存
|
|
static Future<SysSetting?> autoSyncSysInfo() async {
|
|
final login = await AppUserTool.isLogin();
|
|
if (!login) return null;
|
|
final sysSetting = await AppSettingTool.getSysSetting();
|
|
logger.i("|$_tag|开始同步设备信息 sysInfo:|${json.encode(sysSetting)}|");
|
|
if (ObjectUtil.isEmpty(sysSetting)) return null;
|
|
if (ObjectUtil.isEmpty(sysSetting.serviceId)) return null;
|
|
final serviceId = sysSetting.serviceId;
|
|
final pa = {"id": serviceId};
|
|
final data = await HardApi.get(pa);
|
|
if (data == null) {
|
|
logger.e("|$_tag|同步设备信息错误serviceId:|$serviceId|;");
|
|
return null;
|
|
}
|
|
// 基本信息
|
|
await AppSettingTool.updateSysInfoByService(data);
|
|
// 人脸sdk
|
|
await autoSyncFaceSdk(detail: data, sysInfo: sysSetting);
|
|
logger.i("|$_tag|结束同步设备信息 sysInfo:|${json.encode(sysSetting)}|");
|
|
return sysSetting;
|
|
}
|
|
|
|
// 自动同步设备信息导本地缓存-同步人脸sdk
|
|
static Future<void> autoSyncFaceSdk({
|
|
required ServiceHardware detail,
|
|
required SysSetting sysInfo,
|
|
}) 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;
|
|
// 原生插件不保存默认密钥,必须先落盘后再由 AppFaceTool 读取最新后端参数。
|
|
await AppSettingTool.setSysSetting(sysInfo);
|
|
final status = await AppFaceTool.getStatus();
|
|
if (status?.activated == true) {
|
|
logger.i('|$_tag|同步人脸sdk参数完成,当前设备已激活');
|
|
return;
|
|
}
|
|
if (!AppNetworkTool.isAutoNetwork()) {
|
|
logger.i('|$_tag|同步人脸sdk参数完成,离线状态暂不执行激活');
|
|
return;
|
|
}
|
|
final activation = await AppFaceTool.activateSdk();
|
|
logger.i('|$_tag|同步人脸sdk参数后激活结果code:${activation.code}');
|
|
}
|
|
}
|