getCloudControlConfig method

dynamic getCloudControlConfig()

Implementation

getCloudControlConfig() async {
  try {
    final schoolId = getSchoolInfoObs().getSchoolInfo().schoolId;
    if (schoolId == 0) {
      TCICLog.error(
        'schoolId is 0',
        actionModule: ActionModule.tcicController.name,
        actionName: ActionName.getCloudControlConfig.name,
      );
      return null;
    }
    final cloudControlConfigJson = sharedPreferences.getString(
      "cloudControlConfig-$schoolId",
    );
    if (cloudControlConfigJson != null) {
      final localCloudControlConfigMap = jsonDecode(cloudControlConfigJson);
      TCICLog.info(
        'getCloudControlConfig from local: $localCloudControlConfigMap',
        actionModule: ActionModule.tcicController.name,
        actionName: ActionName.getCloudControlConfig.name,
      );
      mergeLocalCloudControlConfig(localCloudControlConfigMap);
    }
    final cloudControlConfig = await networkService.getCloudControlConfig(
      schoolId,
    );
    if (cloudControlConfig != null) {
      // 存本地,下次再使用时直接从本地读取
      sharedPreferences.setString(
        "cloudControlConfig-$schoolId",
        jsonEncode(cloudControlConfig),
      );
      TCICLog.info(
        'getCloudControlConfig success: $cloudControlConfig',
        actionModule: ActionModule.tcicController.name,
        actionName: ActionName.getCloudControlConfig.name,
      );
    } else {}
  } catch (e) {
    TCICLog.error(
      'getCloudControlConfig failed: $e',
      actionModule: ActionModule.tcicController.name,
      actionName: ActionName.getCloudControlConfig.name,
    );
    return null;
  }
}