report static method
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>[];
for (var element in reportCache) {
Log log = Log();
final isTeacher = instance.isTeacher();
final isAssistant = instance.isAssistant();
final isStudent = instance.isStudent();
final selfMemberInfo = instance.getMembersInfoObs().getMemberInfoByUserId(
instance.getConfig().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.appNativeSdkVersion = instance.getConfig().nativeSdkVersion ?? element.appNativeSdkVersion;
element.appWebUiVersion = _dartPackageVersion;
// 补齐上报信息
element.statusAppMem = _physicalRamSize;
element.statusAvailableMem = _availableRamSize;
element.statusCamera = selfCameraState ?? StateStatusValueEnum.off;
element.statusMic = selfMicState ?? StateStatusValueEnum.off;
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,
);
}
}