60 lines
2.0 KiB
Dart
60 lines
2.0 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;
|
|
final activeSdk = await AppFaceTool.isActiveSdk();
|
|
await AppSettingTool.setSysSetting(sysInfo);
|
|
logger.i("|$_tag||同步人脸sdk参数自动激活${activeSdk ? '成功' : '失败'}");
|
|
}
|
|
}
|