From c4ea9ebe64d9f70ba0a90406d6282a9fab6f1676 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Tue, 6 Jan 2026 10:50:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=86=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E4=B8=BA=E6=9C=AC=E5=9C=B0=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在AgentController和MessageModel中将时间戳转换为本地时区 在iOS和Android的ChatStorageHelper中添加调试日志以便追踪历史记录读取 --- lib/data/models/message_model.dart | 2 +- lib/modules/agent/controllers/agent_controller.dart | 2 +- .../com/yunqiinnovation/chat_storage/ChatStorageHelper.kt | 3 +++ .../chat_storage/Sources/chat_storage/ChatStorageHelper.swift | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/data/models/message_model.dart b/lib/data/models/message_model.dart index e15c07314..c19fe9f81 100644 --- a/lib/data/models/message_model.dart +++ b/lib/data/models/message_model.dart @@ -34,7 +34,7 @@ class Message { sessionid: json['sessionid'] as String, // 会话ID isUser: json['isUser'] as bool, text: json['text'] as String, - timestamp: DateTime.parse(json['timestamp'] as String), + timestamp: DateTime.parse(json['timestamp'] as String).toLocal(), isRecognizing: json['isRecognizing'] as bool? ?? false, hasImage: json['hasImage'] as bool? ?? false, imagePath: json['imagePath'] as String?, diff --git a/lib/modules/agent/controllers/agent_controller.dart b/lib/modules/agent/controllers/agent_controller.dart index f4af0edf5..df79a7cbc 100644 --- a/lib/modules/agent/controllers/agent_controller.dart +++ b/lib/modules/agent/controllers/agent_controller.dart @@ -496,7 +496,7 @@ class AgentController extends GetxController with WidgetsBindingObserver { isUser: msg.sender == 'user', text: msg.message, meta: meta, - timestamp: DateTime.parse(msg.timestamp), + timestamp: DateTime.parse(msg.timestamp).toLocal(), hasImage: hasImage, imagePath: imagePath, ); diff --git a/local_plugins/chat_storage/android/src/main/kotlin/com/yunqiinnovation/chat_storage/ChatStorageHelper.kt b/local_plugins/chat_storage/android/src/main/kotlin/com/yunqiinnovation/chat_storage/ChatStorageHelper.kt index 15def6f51..2bee4b6e6 100644 --- a/local_plugins/chat_storage/android/src/main/kotlin/com/yunqiinnovation/chat_storage/ChatStorageHelper.kt +++ b/local_plugins/chat_storage/android/src/main/kotlin/com/yunqiinnovation/chat_storage/ChatStorageHelper.kt @@ -295,6 +295,9 @@ class ChatStorageHelper(context: Context) { val metadataIndex = cursor.getColumnIndex(ChatDatabaseHelper.COLUMN_METADATA) while (cursor.moveToNext()) { + val timestamp = cursor.getString(timestampIndex) // 👈 提前取出 timestamp + Log.d(TAG, "getMessages: 读取历史记录: $timestamp") // 👈 与 iOS 对齐的 log + val jsonObject = JSONObject().apply { put("id", cursor.getInt(idIndex)) put("agentId", cursor.getString(agentIdIndex)) diff --git a/local_plugins/chat_storage/ios/chat_storage/Sources/chat_storage/ChatStorageHelper.swift b/local_plugins/chat_storage/ios/chat_storage/Sources/chat_storage/ChatStorageHelper.swift index b79f17bed..9591dfe11 100644 --- a/local_plugins/chat_storage/ios/chat_storage/Sources/chat_storage/ChatStorageHelper.swift +++ b/local_plugins/chat_storage/ios/chat_storage/Sources/chat_storage/ChatStorageHelper.swift @@ -175,6 +175,7 @@ public class ChatStorageHelper { let date = Date(timeIntervalSince1970: TimeInterval(createdAt)) let formatter = ISO8601DateFormatter() let timestamp = formatter.string(from: date) + os_log("getMessages: 读取历史记录: %{public}@", log: logger, type: .info, timestamp) var messageDict: [String: Any] = [ "id": id,