Sfoglia il codice sorgente

fix: 修复boost result 日志解析错误

Tony 3 mesi fa
parent
commit
2655da70fd
1 ha cambiato i file con 26 aggiunte e 15 eliminazioni
  1. 26 15
      lib/app/controllers/windows_core_api.dart

+ 26 - 15
lib/app/controllers/windows_core_api.dart

@@ -51,7 +51,6 @@ class WindowsCoreApi implements BaseCoreApi {
   int _locationId = 0;
   String _locationCode = '';
   String _boostSessionId = '';
-  int _peekTimeInterval = 0;
 
   /// 内部构造方法,供 BaseCoreApi 工厂使用
   factory WindowsCoreApi.create() => WindowsCoreApi._();
@@ -162,9 +161,13 @@ class WindowsCoreApi implements BaseCoreApi {
       log(_tag, 'stat: $stat');
       try {
         final ts = DateTime.now().millisecondsSinceEpoch;
-        final connectionHistory = (stat?['connectionHistory'] as List?)?.last;
+        final connectionHistory = List<ConnectionHistory>.from(
+          (stat?['connectionHistory'] ?? []).map(
+            (x) => ConnectionHistory.fromJson(x),
+          ),
+        );
 
-        final param = statLogEntryToJson(
+        final param = jsonEncode([
           StatLogEntry(
             id: Uuid().v4(),
             time: ts,
@@ -181,12 +184,17 @@ class WindowsCoreApi implements BaseCoreApi {
               connectionHistory: connectionHistory,
             ),
           ),
-        );
-
-        final nodeId = connectionHistory['nodeId'] ?? 0;
-        final msg =
-            '{"type":"boost_result","locationCode":"$_locationCode","nodeId":"$nodeId","success":true, "param": "$param"}';
-
+        ]);
+
+        final nodeId = connectionHistory.last.nodeId ?? '';
+        final msg = jsonEncode({
+          "type": "boost_result",
+          "locationCode": _locationCode,
+          "nodeId": nodeId,
+          "success": true,
+          "param": param,
+        });
+        log(_tag, msg);
         _eventController.add(msg);
       } catch (e) {
         log(_tag, 'parse stat json error: $e');
@@ -203,9 +211,13 @@ class WindowsCoreApi implements BaseCoreApi {
       log(_tag, 'stat: $stat');
       try {
         final ts = DateTime.now().millisecondsSinceEpoch;
-        final connectionHistory = (stat?['connectionHistory'] as List?)?.last;
+        final connectionHistory = List<ConnectionHistory>.from(
+          (stat?['connectionHistory'] ?? []).map(
+            (x) => ConnectionHistory.fromJson(x),
+          ),
+        );
 
-        final param = statLogEntryToJson(
+        final param = jsonEncode([
           StatLogEntry(
             id: Uuid().v4(),
             time: ts,
@@ -222,11 +234,11 @@ class WindowsCoreApi implements BaseCoreApi {
               connectionHistory: connectionHistory,
             ),
           ),
-        );
+        ]);
 
-        final nodeId = connectionHistory['nodeId'] ?? 0;
+        final nodeId = connectionHistory.last.nodeId ?? '';
         final msg =
-            '{"type":"boost_result","locationCode":"$_locationCode","nodeId":"$nodeId","success":false, "param": "$param"}';
+            '{"type":"boost_result","locationCode":"$_locationCode","nodeId":"$nodeId","success":false, "param": $param}';
 
         _eventController.add(msg);
       } catch (e) {
@@ -336,7 +348,6 @@ class WindowsCoreApi implements BaseCoreApi {
     _locationId = locationId;
     _locationCode = locationCode;
     _boostSessionId = sessionId;
-    _peekTimeInterval = peekTimeInterval;
 
     String geoPath = await _getGeoDirectory();