react-native-beidou 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- package com.cmcc_rn_module;
1
+ package com.fxzs.rnbeidou;
2
2
 
3
3
  import android.content.ContentValues;
4
4
  import android.content.Context;
@@ -20,7 +20,7 @@ public class ChatDBManager extends SQLiteOpenHelper {
20
20
  private static final String TAG = "ChatDBManager";
21
21
  private static final String DATABASE_NAME = "beidou_chat.db";
22
22
  private static final int DATABASE_VERSION = 1;
23
-
23
+
24
24
  // 消息表
25
25
  private static final String TABLE_MESSAGES = "messages";
26
26
  private static final String COLUMN_ID = "id";
@@ -28,13 +28,13 @@ public class ChatDBManager extends SQLiteOpenHelper {
28
28
  private static final String COLUMN_CONTENT = "content";
29
29
  private static final String COLUMN_TIMESTAMP = "timestamp";
30
30
  private static final String COLUMN_IS_SEND = "is_send";
31
-
31
+
32
32
  // 会话表
33
33
  private static final String TABLE_CONVERSATIONS = "conversations";
34
34
  private static final String COLUMN_LAST_MESSAGE = "last_message";
35
-
35
+
36
36
  // 创建消息表的SQL语句
37
- private static final String CREATE_MESSAGES_TABLE =
37
+ private static final String CREATE_MESSAGES_TABLE =
38
38
  "CREATE TABLE " + TABLE_MESSAGES + " (" +
39
39
  COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
40
40
  COLUMN_PHONE_NUMBER + " TEXT NOT NULL, " +
@@ -42,27 +42,27 @@ public class ChatDBManager extends SQLiteOpenHelper {
42
42
  COLUMN_TIMESTAMP + " INTEGER NOT NULL, " +
43
43
  COLUMN_IS_SEND + " INTEGER NOT NULL DEFAULT 0" +
44
44
  ")";
45
-
45
+
46
46
  // 创建会话表的SQL语句
47
- private static final String CREATE_CONVERSATIONS_TABLE =
47
+ private static final String CREATE_CONVERSATIONS_TABLE =
48
48
  "CREATE TABLE " + TABLE_CONVERSATIONS + " (" +
49
49
  COLUMN_PHONE_NUMBER + " TEXT PRIMARY KEY, " +
50
50
  COLUMN_LAST_MESSAGE + " TEXT NOT NULL, " +
51
51
  COLUMN_TIMESTAMP + " INTEGER NOT NULL, " +
52
52
  COLUMN_IS_SEND + " INTEGER NOT NULL DEFAULT 0" +
53
53
  ")";
54
-
54
+
55
55
  public ChatDBManager(Context context) {
56
56
  super(context, DATABASE_NAME, null, DATABASE_VERSION);
57
57
  }
58
-
58
+
59
59
  @Override
60
60
  public void onCreate(SQLiteDatabase db) {
61
61
  db.execSQL(CREATE_MESSAGES_TABLE);
62
62
  db.execSQL(CREATE_CONVERSATIONS_TABLE);
63
63
  Log.d(TAG, "数据库创建成功");
64
64
  }
65
-
65
+
66
66
  @Override
67
67
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
68
68
  db.execSQL("DROP TABLE IF EXISTS " + TABLE_MESSAGES);
@@ -70,7 +70,7 @@ public class ChatDBManager extends SQLiteOpenHelper {
70
70
  onCreate(db);
71
71
  Log.d(TAG, "数据库升级完成");
72
72
  }
73
-
73
+
74
74
  /**
75
75
  * 插入消息
76
76
  * @param content 消息内容
@@ -84,16 +84,16 @@ public class ChatDBManager extends SQLiteOpenHelper {
84
84
  try {
85
85
  db = this.getWritableDatabase();
86
86
  db.beginTransaction();
87
-
87
+
88
88
  // 插入消息记录
89
89
  ContentValues messageValues = new ContentValues();
90
90
  messageValues.put(COLUMN_PHONE_NUMBER, phoneNumber);
91
91
  messageValues.put(COLUMN_CONTENT, content);
92
92
  messageValues.put(COLUMN_TIMESTAMP, timestamp);
93
93
  messageValues.put(COLUMN_IS_SEND, isSend ? 1 : 0);
94
-
94
+
95
95
  long messageResult = db.insert(TABLE_MESSAGES, null, messageValues);
96
-
96
+
97
97
  if (messageResult != -1) {
98
98
  // 更新对话表(原子操作:如果不存在则插入,存在则更新)
99
99
  ContentValues conversationValues = new ContentValues();
@@ -101,13 +101,13 @@ public class ChatDBManager extends SQLiteOpenHelper {
101
101
  conversationValues.put(COLUMN_LAST_MESSAGE, content);
102
102
  conversationValues.put(COLUMN_TIMESTAMP, timestamp);
103
103
  conversationValues.put(COLUMN_IS_SEND, isSend ? 1 : 0);
104
-
105
- long conversationResult = db.insertWithOnConflict(TABLE_CONVERSATIONS, null,
104
+
105
+ long conversationResult = db.insertWithOnConflict(TABLE_CONVERSATIONS, null,
106
106
  conversationValues, SQLiteDatabase.CONFLICT_REPLACE);
107
-
107
+
108
108
  if (conversationResult != -1) {
109
109
  db.setTransactionSuccessful();
110
- Log.d(TAG, String.format("插入消息成功 - 手机号: %s, 内容: %s, 是否发送: %b",
110
+ Log.d(TAG, String.format("插入消息成功 - 手机号: %s, 内容: %s, 是否发送: %b",
111
111
  phoneNumber, content, isSend));
112
112
  return true;
113
113
  } else {
@@ -134,7 +134,7 @@ public class ChatDBManager extends SQLiteOpenHelper {
134
134
  }
135
135
  }
136
136
  }
137
-
137
+
138
138
  /**
139
139
  * 获取所有会话列表
140
140
  * @return 会话列表
@@ -143,14 +143,14 @@ public class ChatDBManager extends SQLiteOpenHelper {
143
143
  List<Map<String, Object>> conversations = new ArrayList<>();
144
144
  SQLiteDatabase db = null;
145
145
  Cursor cursor = null;
146
-
146
+
147
147
  try {
148
148
  db = this.getReadableDatabase();
149
-
149
+
150
150
  // 直接从会话表查询,按时间戳倒序排列
151
151
  String query = "SELECT * FROM " + TABLE_CONVERSATIONS + " ORDER BY " + COLUMN_TIMESTAMP + " DESC";
152
152
  cursor = db.rawQuery(query, null);
153
-
153
+
154
154
  if (cursor != null && cursor.moveToFirst()) {
155
155
  do {
156
156
  Map<String, Object> conversation = new HashMap<>();
@@ -161,9 +161,9 @@ public class ChatDBManager extends SQLiteOpenHelper {
161
161
  conversations.add(conversation);
162
162
  } while (cursor.moveToNext());
163
163
  }
164
-
164
+
165
165
  Log.d(TAG, "获取会话列表成功,共 " + conversations.size() + " 个会话");
166
-
166
+
167
167
  } catch (Exception e) {
168
168
  Log.e(TAG, "获取会话列表失败: " + e.getMessage(), e);
169
169
  } finally {
@@ -174,10 +174,10 @@ public class ChatDBManager extends SQLiteOpenHelper {
174
174
  db.close();
175
175
  }
176
176
  }
177
-
177
+
178
178
  return conversations;
179
179
  }
180
-
180
+
181
181
  /**
182
182
  * 获取指定手机号的消息列表
183
183
  * @param phoneNumber 手机号
@@ -189,17 +189,17 @@ public class ChatDBManager extends SQLiteOpenHelper {
189
189
  List<Map<String, Object>> messages = new ArrayList<>();
190
190
  SQLiteDatabase db = null;
191
191
  Cursor cursor = null;
192
-
192
+
193
193
  try {
194
194
  db = this.getReadableDatabase();
195
-
195
+
196
196
  // 注意:iOS版本中查询的表是 uploadForm,但这里应该查询 messages 表
197
197
  // 修正查询语句,使用正确的表名和字段名
198
- String query = String.format("SELECT * FROM %s WHERE %s = ? ORDER BY %s DESC LIMIT %d OFFSET %d",
198
+ String query = String.format("SELECT * FROM %s WHERE %s = ? ORDER BY %s DESC LIMIT %d OFFSET %d",
199
199
  TABLE_MESSAGES, COLUMN_PHONE_NUMBER, COLUMN_TIMESTAMP, pageSize, page * pageSize);
200
-
200
+
201
201
  cursor = db.rawQuery(query, new String[]{phoneNumber});
202
-
202
+
203
203
  if (cursor != null && cursor.moveToFirst()) {
204
204
  do {
205
205
  Map<String, Object> message = new HashMap<>();
@@ -209,10 +209,10 @@ public class ChatDBManager extends SQLiteOpenHelper {
209
209
  messages.add(message);
210
210
  } while (cursor.moveToNext());
211
211
  }
212
-
213
- Log.d(TAG, String.format("获取消息详情成功 - 手机号: %s, 页码: %d, 页大小: %d, 消息数: %d",
212
+
213
+ Log.d(TAG, String.format("获取消息详情成功 - 手机号: %s, 页码: %d, 页大小: %d, 消息数: %d",
214
214
  phoneNumber, page, pageSize, messages.size()));
215
-
215
+
216
216
  } catch (Exception e) {
217
217
  Log.e(TAG, "获取消息详情失败: " + e.getMessage(), e);
218
218
  } finally {
@@ -223,10 +223,10 @@ public class ChatDBManager extends SQLiteOpenHelper {
223
223
  db.close();
224
224
  }
225
225
  }
226
-
226
+
227
227
  return messages;
228
228
  }
229
-
229
+
230
230
  /**
231
231
  * 删除指定手机号的所有消息
232
232
  * @param phoneNumber 手机号
@@ -237,16 +237,16 @@ public class ChatDBManager extends SQLiteOpenHelper {
237
237
  try {
238
238
  db = this.getWritableDatabase();
239
239
  db.beginTransaction();
240
-
240
+
241
241
  // 删除消息记录
242
242
  int deletedMessages = db.delete(TABLE_MESSAGES, COLUMN_PHONE_NUMBER + " = ?", new String[]{phoneNumber});
243
-
243
+
244
244
  // 删除会话记录
245
245
  int deletedConversations = db.delete(TABLE_CONVERSATIONS, COLUMN_PHONE_NUMBER + " = ?", new String[]{phoneNumber});
246
-
246
+
247
247
  db.setTransactionSuccessful();
248
-
249
- Log.d(TAG, String.format("删除消息 - 手机号: %s, 删除消息数: %d, 删除会话数: %d",
248
+
249
+ Log.d(TAG, String.format("删除消息 - 手机号: %s, 删除消息数: %d, 删除会话数: %d",
250
250
  phoneNumber, deletedMessages, deletedConversations));
251
251
  return deletedMessages > 0;
252
252
  } catch (Exception e) {
@@ -265,7 +265,7 @@ public class ChatDBManager extends SQLiteOpenHelper {
265
265
  }
266
266
  }
267
267
  }
268
-
268
+
269
269
  /**
270
270
  * 清空所有消息
271
271
  * @return 清空成功返回true
@@ -275,15 +275,15 @@ public class ChatDBManager extends SQLiteOpenHelper {
275
275
  try {
276
276
  db = this.getWritableDatabase();
277
277
  db.beginTransaction();
278
-
278
+
279
279
  // 清空消息表
280
280
  int deletedMessages = db.delete(TABLE_MESSAGES, null, null);
281
-
281
+
282
282
  // 清空会话表
283
283
  int deletedConversations = db.delete(TABLE_CONVERSATIONS, null, null);
284
-
284
+
285
285
  db.setTransactionSuccessful();
286
-
286
+
287
287
  Log.d(TAG, String.format("清空所有消息,删除消息数: %d, 删除会话数: %d", deletedMessages, deletedConversations));
288
288
  return true;
289
289
  } catch (Exception e) {
@@ -1,4 +1,4 @@
1
- package com.cmcc_rn_module;
1
+ package com.fxzs.rnbeidou;
2
2
 
3
3
  import org.json.JSONArray;
4
4
  import org.json.JSONException;
@@ -34,7 +34,7 @@ public class JsonUtil {
34
34
  Object firstItem = list.get(0);
35
35
  if (firstItem != null) {
36
36
  String className = firstItem.getClass().getSimpleName();
37
- if (className.contains("BlueDeviceInfo") || className.contains("DeviceInfo") ||
37
+ if (className.contains("BlueDeviceInfo") || className.contains("DeviceInfo") ||
38
38
  className.contains("BlueDeviceInfoEntity")) {
39
39
  return convertBlueDeviceInfoListToJson(list);
40
40
  }
@@ -50,7 +50,7 @@ public class JsonUtil {
50
50
  // 特殊处理:如果是BlueDeviceInfo相关的对象,尝试转换为Map
51
51
  if (object != null) {
52
52
  String className = object.getClass().getSimpleName();
53
- if (className.contains("BlueDeviceInfo") || className.contains("DeviceInfo") ||
53
+ if (className.contains("BlueDeviceInfo") || className.contains("DeviceInfo") ||
54
54
  className.contains("BlueDeviceInfoEntity")) {
55
55
  Map<String, Object> deviceMap = convertBlueDeviceInfoToMap(object);
56
56
  return new JSONObject(deviceMap).toString();
@@ -236,4 +236,4 @@ public class JsonUtil {
236
236
  // 可以使用反射或第三方库如BeanUtils
237
237
  throw new UnsupportedOperationException("Map转Bean需要根据项目实际情况实现");
238
238
  }
239
- }
239
+ }