report static method

Future<void> report()

Implementation

static Future<void> report() async {
  if (_cache.isEmpty) {
    return;
  }
  int takeCount = _cache.length > batchSize ? batchSize : _cache.length;
  if (takeCount == 0) {
    return;
  }
  List<ReportData> reportCache = _cache.sublist(0, takeCount);
  _cache.removeRange(0, takeCount);
  final instance = TCICController.instance;
  List<Log> logs = <Log>[];
  final config = instance.getConfig();
  final hasClassroomConfig = config.userId.isNotEmpty;
  for (var element in reportCache) {
    Log log = Log();

    if (hasClassroomConfig) {
      final isTeacher = instance.isTeacher();
      final isAssistant = instance.isAssistant();
      final isStudent = instance.isStudent();
      final selfMemberInfo = instance
          .getMembersInfoObs()
          .getMemberInfoByUserId(config.userId);
      final selfMicState = selfMemberInfo?.micState;
      final selfCameraState = selfMemberInfo?.cameraState;
      final schoolId =
          instance.getSchoolInfoObs().getSchoolInfo().schoolId;
      if (isTeacher) {
        element.appUserRole = "teacher";
      } else if (isAssistant) {
        element.appUserRole = "assistant";
      } else if (isStudent) {
        element.appUserRole = "student";
      }
      element.appNewEnterId = schoolId.toString();
      element.statusCamera =
          selfCameraState ?? StateStatusValueEnum.off;
      element.statusMic = selfMicState ?? StateStatusValueEnum.off;
    }
    element.appNativeSdkVersion = config.nativeSdkVersion ?? element.appNativeSdkVersion;
    element.appWebUiVersion = _dartPackageVersion;
    element.statusAppMem = _physicalRamSize;
    element.statusAvailableMem = _availableRamSize;
    element.devPlatform = _systemName;
    element.devSysVersion = _devSysVersion;
    element.devType = _model;
    element.netBandwidth = _deviceId;
    element.appPackageName = _packageName;
    element.toJson().forEach((key, value) {
      log.contents.add(Log_Content(key: key, value: value.toString()));
    });
    log.time = Int64(element.reportTime);
    logs.add(log);
  }
  // 如果发送失败,将数据重新放回_cache中
  LogProducerResult? result = await _logProducer?.send(logs);
  if (result != null) {
    if (result == LogProducerResult.ok) {
    } else {
      // 发送失败,将reportCache重新放回_cache队头
      _cache.insertAll(0, reportCache);
      TCICLog.error(
        "report failed ${result.name}",
        actionModule: ActionModule.report.name,
        actionName: ActionName.report.name,
      );
    }
  } else {
    // 发送失败,将reportCache重新放回_cache队头
    _cache.insertAll(0, reportCache);
    TCICLog.error(
      "report failed",
      actionModule: ActionModule.report.name,
      actionName: ActionName.report.name,
    );
  }
}