Browse Source

将连接的蓝牙设备信息传给服务器

周素华 10 months ago
parent
commit
f4440ba044

+ 10 - 0
lib/drfit/dao/device_info_table_dao.dart

@@ -1,6 +1,7 @@
1 1
 import 'package:drift/drift.dart';
2 2
 import 'package:lszlgl/drfit/database.dart';
3 3
 import 'package:lszlgl/drfit/device_info_table.dart';
4
+import 'package:lszlgl/service/user_service.dart';
4 5
 
5 6
 part 'device_info_table_dao.g.dart';
6 7
 
@@ -12,6 +13,15 @@ class DeviceInfoTableDao extends DatabaseAccessor<MyDatabase> {
12 13
     return into(db.deviceInfoTable).insert(deviceInfoTableCompanion, mode: InsertMode.insertOrReplace);
13 14
   }
14 15
 
16
+  Future<List<DeviceInfo>> queryAllDeviceInfo() async {
17
+
18
+    int deviceInfoTableTime = UserService.get().getDeviceInfoTableTime();
19
+    return (select(db.deviceInfoTable)
20
+      ..where((tbl) => tbl.createdAt.isBiggerThanValue(deviceInfoTableTime))
21
+      ..orderBy([(row) => OrderingTerm.asc(row.createdAt)])).get();
22
+  }
23
+
24
+
15 25
 
16 26
 
17 27
 }

+ 29 - 0
lib/drfit/database.dart

@@ -1,11 +1,15 @@
1 1
 import 'dart:io';
2 2
 
3
+import 'package:dio/dio.dart';
3 4
 import 'package:drift/drift.dart';
4 5
 import 'package:drift/native.dart';
5 6
 import 'package:lszlgl/main.dart';
7
+import 'package:lszlgl/model/req/device_req.dart';
6 8
 import 'package:path_provider/path_provider.dart';
7 9
 import 'package:path/path.dart' as p;
8 10
 
11
+import '../network/my_api.dart';
12
+import '../service/user_service.dart';
9 13
 import 'dao/device_info_table_dao.dart';
10 14
 import 'device_info_table.dart';
11 15
 
@@ -20,6 +24,31 @@ class MyDatabase extends _$MyDatabase {
20 24
 
21 25
   @override
22 26
   int get schemaVersion => 1;
27
+
28
+
29
+  /// 同步数据到服务器
30
+  Future<void> savaBleDataToServer() async {
31
+    List<DeviceInfo> deviceInfos = await database.deviceInfoTableDao.queryAllDeviceInfo();
32
+
33
+    List<DeviceReq> deviceRes = [];
34
+    for(DeviceInfo device in deviceInfos) {
35
+      deviceRes.add(DeviceReq.fromJson(device.toJson()));
36
+    }
37
+    if(deviceRes.isEmpty) {
38
+      return;
39
+    }
40
+    try {
41
+      // 获取用户数据
42
+      var user = await MyApi.get().postDeviceInfos(deviceRes);
43
+      logger.d('====user:$user');
44
+      // 记录末次同步id
45
+      UserService.get().saveDeviceInfoTableTime(deviceInfos.last.createdAt);
46
+    } on DioException catch (_) {
47
+    } on Exception catch (a, _) {
48
+    }
49
+
50
+  }
51
+
23 52
 }
24 53
 
25 54
 LazyDatabase _openConnection() {

+ 63 - 8
lib/drfit/database.g.dart

@@ -50,6 +50,12 @@ class $DeviceInfoTableTable extends DeviceInfoTable
50 50
   late final GeneratedColumn<String> bleName = GeneratedColumn<String>(
51 51
       'ble_name', aliasedName, false,
52 52
       type: DriftSqlType.string, requiredDuringInsert: true);
53
+  static const VerificationMeta _createdAtMeta =
54
+      const VerificationMeta('createdAt');
55
+  @override
56
+  late final GeneratedColumn<int> createdAt = GeneratedColumn<int>(
57
+      'created_at', aliasedName, false,
58
+      type: DriftSqlType.int, requiredDuringInsert: true);
53 59
   @override
54 60
   List<GeneratedColumn> get $columns => [
55 61
         username,
@@ -58,7 +64,8 @@ class $DeviceInfoTableTable extends DeviceInfoTable
58 64
         phoneRelease,
59 65
         phoneAddress,
60 66
         bleMac,
61
-        bleName
67
+        bleName,
68
+        createdAt
62 69
       ];
63 70
   @override
64 71
   String get aliasedName => _alias ?? actualTableName;
@@ -120,11 +127,17 @@ class $DeviceInfoTableTable extends DeviceInfoTable
120 127
     } else if (isInserting) {
121 128
       context.missing(_bleNameMeta);
122 129
     }
130
+    if (data.containsKey('created_at')) {
131
+      context.handle(_createdAtMeta,
132
+          createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta));
133
+    } else if (isInserting) {
134
+      context.missing(_createdAtMeta);
135
+    }
123 136
     return context;
124 137
   }
125 138
 
126 139
   @override
127
-  Set<GeneratedColumn> get $primaryKey => {bleMac};
140
+  Set<GeneratedColumn> get $primaryKey => {bleMac, username};
128 141
   @override
129 142
   DeviceInfo map(Map<String, dynamic> data, {String? tablePrefix}) {
130 143
     final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
@@ -143,6 +156,8 @@ class $DeviceInfoTableTable extends DeviceInfoTable
143 156
           .read(DriftSqlType.string, data['${effectivePrefix}ble_mac'])!,
144 157
       bleName: attachedDatabase.typeMapping
145 158
           .read(DriftSqlType.string, data['${effectivePrefix}ble_name'])!,
159
+      createdAt: attachedDatabase.typeMapping
160
+          .read(DriftSqlType.int, data['${effectivePrefix}created_at'])!,
146 161
     );
147 162
   }
148 163
 
@@ -173,6 +188,9 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
173 188
 
174 189
   /// 登录蓝牙名称
175 190
   final String bleName;
191
+
192
+  /// 日期
193
+  final int createdAt;
176 194
   const DeviceInfo(
177 195
       {required this.username,
178 196
       required this.phoneBrand,
@@ -180,7 +198,8 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
180 198
       required this.phoneRelease,
181 199
       required this.phoneAddress,
182 200
       required this.bleMac,
183
-      required this.bleName});
201
+      required this.bleName,
202
+      required this.createdAt});
184 203
   @override
185 204
   Map<String, Expression> toColumns(bool nullToAbsent) {
186 205
     final map = <String, Expression>{};
@@ -191,6 +210,7 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
191 210
     map['phone_address'] = Variable<String>(phoneAddress);
192 211
     map['ble_mac'] = Variable<String>(bleMac);
193 212
     map['ble_name'] = Variable<String>(bleName);
213
+    map['created_at'] = Variable<int>(createdAt);
194 214
     return map;
195 215
   }
196 216
 
@@ -203,6 +223,7 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
203 223
       phoneAddress: Value(phoneAddress),
204 224
       bleMac: Value(bleMac),
205 225
       bleName: Value(bleName),
226
+      createdAt: Value(createdAt),
206 227
     );
207 228
   }
208 229
 
@@ -217,6 +238,7 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
217 238
       phoneAddress: serializer.fromJson<String>(json['phoneAddress']),
218 239
       bleMac: serializer.fromJson<String>(json['bleMac']),
219 240
       bleName: serializer.fromJson<String>(json['bleName']),
241
+      createdAt: serializer.fromJson<int>(json['createdAt']),
220 242
     );
221 243
   }
222 244
   @override
@@ -230,6 +252,7 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
230 252
       'phoneAddress': serializer.toJson<String>(phoneAddress),
231 253
       'bleMac': serializer.toJson<String>(bleMac),
232 254
       'bleName': serializer.toJson<String>(bleName),
255
+      'createdAt': serializer.toJson<int>(createdAt),
233 256
     };
234 257
   }
235 258
 
@@ -240,7 +263,8 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
240 263
           String? phoneRelease,
241 264
           String? phoneAddress,
242 265
           String? bleMac,
243
-          String? bleName}) =>
266
+          String? bleName,
267
+          int? createdAt}) =>
244 268
       DeviceInfo(
245 269
         username: username ?? this.username,
246 270
         phoneBrand: phoneBrand ?? this.phoneBrand,
@@ -249,6 +273,7 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
249 273
         phoneAddress: phoneAddress ?? this.phoneAddress,
250 274
         bleMac: bleMac ?? this.bleMac,
251 275
         bleName: bleName ?? this.bleName,
276
+        createdAt: createdAt ?? this.createdAt,
252 277
       );
253 278
   @override
254 279
   String toString() {
@@ -259,14 +284,15 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
259 284
           ..write('phoneRelease: $phoneRelease, ')
260 285
           ..write('phoneAddress: $phoneAddress, ')
261 286
           ..write('bleMac: $bleMac, ')
262
-          ..write('bleName: $bleName')
287
+          ..write('bleName: $bleName, ')
288
+          ..write('createdAt: $createdAt')
263 289
           ..write(')'))
264 290
         .toString();
265 291
   }
266 292
 
267 293
   @override
268 294
   int get hashCode => Object.hash(username, phoneBrand, phoneModel,
269
-      phoneRelease, phoneAddress, bleMac, bleName);
295
+      phoneRelease, phoneAddress, bleMac, bleName, createdAt);
270 296
   @override
271 297
   bool operator ==(Object other) =>
272 298
       identical(this, other) ||
@@ -277,7 +303,8 @@ class DeviceInfo extends DataClass implements Insertable<DeviceInfo> {
277 303
           other.phoneRelease == this.phoneRelease &&
278 304
           other.phoneAddress == this.phoneAddress &&
279 305
           other.bleMac == this.bleMac &&
280
-          other.bleName == this.bleName);
306
+          other.bleName == this.bleName &&
307
+          other.createdAt == this.createdAt);
281 308
 }
282 309
 
283 310
 class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
@@ -288,6 +315,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
288 315
   final Value<String> phoneAddress;
289 316
   final Value<String> bleMac;
290 317
   final Value<String> bleName;
318
+  final Value<int> createdAt;
291 319
   final Value<int> rowid;
292 320
   const DeviceInfoTableCompanion({
293 321
     this.username = const Value.absent(),
@@ -297,6 +325,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
297 325
     this.phoneAddress = const Value.absent(),
298 326
     this.bleMac = const Value.absent(),
299 327
     this.bleName = const Value.absent(),
328
+    this.createdAt = const Value.absent(),
300 329
     this.rowid = const Value.absent(),
301 330
   });
302 331
   DeviceInfoTableCompanion.insert({
@@ -307,6 +336,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
307 336
     required String phoneAddress,
308 337
     required String bleMac,
309 338
     required String bleName,
339
+    required int createdAt,
310 340
     this.rowid = const Value.absent(),
311 341
   })  : username = Value(username),
312 342
         phoneBrand = Value(phoneBrand),
@@ -314,7 +344,8 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
314 344
         phoneRelease = Value(phoneRelease),
315 345
         phoneAddress = Value(phoneAddress),
316 346
         bleMac = Value(bleMac),
317
-        bleName = Value(bleName);
347
+        bleName = Value(bleName),
348
+        createdAt = Value(createdAt);
318 349
   static Insertable<DeviceInfo> custom({
319 350
     Expression<String>? username,
320 351
     Expression<String>? phoneBrand,
@@ -323,6 +354,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
323 354
     Expression<String>? phoneAddress,
324 355
     Expression<String>? bleMac,
325 356
     Expression<String>? bleName,
357
+    Expression<int>? createdAt,
326 358
     Expression<int>? rowid,
327 359
   }) {
328 360
     return RawValuesInsertable({
@@ -333,6 +365,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
333 365
       if (phoneAddress != null) 'phone_address': phoneAddress,
334 366
       if (bleMac != null) 'ble_mac': bleMac,
335 367
       if (bleName != null) 'ble_name': bleName,
368
+      if (createdAt != null) 'created_at': createdAt,
336 369
       if (rowid != null) 'rowid': rowid,
337 370
     });
338 371
   }
@@ -345,6 +378,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
345 378
       Value<String>? phoneAddress,
346 379
       Value<String>? bleMac,
347 380
       Value<String>? bleName,
381
+      Value<int>? createdAt,
348 382
       Value<int>? rowid}) {
349 383
     return DeviceInfoTableCompanion(
350 384
       username: username ?? this.username,
@@ -354,6 +388,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
354 388
       phoneAddress: phoneAddress ?? this.phoneAddress,
355 389
       bleMac: bleMac ?? this.bleMac,
356 390
       bleName: bleName ?? this.bleName,
391
+      createdAt: createdAt ?? this.createdAt,
357 392
       rowid: rowid ?? this.rowid,
358 393
     );
359 394
   }
@@ -382,6 +417,9 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
382 417
     if (bleName.present) {
383 418
       map['ble_name'] = Variable<String>(bleName.value);
384 419
     }
420
+    if (createdAt.present) {
421
+      map['created_at'] = Variable<int>(createdAt.value);
422
+    }
385 423
     if (rowid.present) {
386 424
       map['rowid'] = Variable<int>(rowid.value);
387 425
     }
@@ -398,6 +436,7 @@ class DeviceInfoTableCompanion extends UpdateCompanion<DeviceInfo> {
398 436
           ..write('phoneAddress: $phoneAddress, ')
399 437
           ..write('bleMac: $bleMac, ')
400 438
           ..write('bleName: $bleName, ')
439
+          ..write('createdAt: $createdAt, ')
401 440
           ..write('rowid: $rowid')
402 441
           ..write(')'))
403 442
         .toString();
@@ -427,6 +466,7 @@ typedef $$DeviceInfoTableTableInsertCompanionBuilder = DeviceInfoTableCompanion
427 466
   required String phoneAddress,
428 467
   required String bleMac,
429 468
   required String bleName,
469
+  required int createdAt,
430 470
   Value<int> rowid,
431 471
 });
432 472
 typedef $$DeviceInfoTableTableUpdateCompanionBuilder = DeviceInfoTableCompanion
@@ -438,6 +478,7 @@ typedef $$DeviceInfoTableTableUpdateCompanionBuilder = DeviceInfoTableCompanion
438 478
   Value<String> phoneAddress,
439 479
   Value<String> bleMac,
440 480
   Value<String> bleName,
481
+  Value<int> createdAt,
441 482
   Value<int> rowid,
442 483
 });
443 484
 
@@ -469,6 +510,7 @@ class $$DeviceInfoTableTableTableManager extends RootTableManager<
469 510
             Value<String> phoneAddress = const Value.absent(),
470 511
             Value<String> bleMac = const Value.absent(),
471 512
             Value<String> bleName = const Value.absent(),
513
+            Value<int> createdAt = const Value.absent(),
472 514
             Value<int> rowid = const Value.absent(),
473 515
           }) =>
474 516
               DeviceInfoTableCompanion(
@@ -479,6 +521,7 @@ class $$DeviceInfoTableTableTableManager extends RootTableManager<
479 521
             phoneAddress: phoneAddress,
480 522
             bleMac: bleMac,
481 523
             bleName: bleName,
524
+            createdAt: createdAt,
482 525
             rowid: rowid,
483 526
           ),
484 527
           getInsertCompanionBuilder: ({
@@ -489,6 +532,7 @@ class $$DeviceInfoTableTableTableManager extends RootTableManager<
489 532
             required String phoneAddress,
490 533
             required String bleMac,
491 534
             required String bleName,
535
+            required int createdAt,
492 536
             Value<int> rowid = const Value.absent(),
493 537
           }) =>
494 538
               DeviceInfoTableCompanion.insert(
@@ -499,6 +543,7 @@ class $$DeviceInfoTableTableTableManager extends RootTableManager<
499 543
             phoneAddress: phoneAddress,
500 544
             bleMac: bleMac,
501 545
             bleName: bleName,
546
+            createdAt: createdAt,
502 547
             rowid: rowid,
503 548
           ),
504 549
         ));
@@ -553,6 +598,11 @@ class $$DeviceInfoTableTableFilterComposer
553 598
       column: $state.table.bleName,
554 599
       builder: (column, joinBuilders) =>
555 600
           ColumnFilters(column, joinBuilders: joinBuilders));
601
+
602
+  ColumnFilters<int> get createdAt => $state.composableBuilder(
603
+      column: $state.table.createdAt,
604
+      builder: (column, joinBuilders) =>
605
+          ColumnFilters(column, joinBuilders: joinBuilders));
556 606
 }
557 607
 
558 608
 class $$DeviceInfoTableTableOrderingComposer
@@ -592,6 +642,11 @@ class $$DeviceInfoTableTableOrderingComposer
592 642
       column: $state.table.bleName,
593 643
       builder: (column, joinBuilders) =>
594 644
           ColumnOrderings(column, joinBuilders: joinBuilders));
645
+
646
+  ColumnOrderings<int> get createdAt => $state.composableBuilder(
647
+      column: $state.table.createdAt,
648
+      builder: (column, joinBuilders) =>
649
+          ColumnOrderings(column, joinBuilders: joinBuilders));
595 650
 }
596 651
 
597 652
 class _$MyDatabaseManager {

+ 4 - 1
lib/drfit/device_info_table.dart

@@ -1,5 +1,6 @@
1 1
 import 'package:drift/drift.dart';
2 2
 
3
+
3 4
 @DataClassName('DeviceInfo')
4 5
 class DeviceInfoTable extends Table {
5 6
 
@@ -17,7 +18,9 @@ class DeviceInfoTable extends Table {
17 18
   TextColumn get bleMac => text()();
18 19
   /// 登录蓝牙名称
19 20
   TextColumn get bleName => text()();
21
+  /// 日期
22
+  IntColumn get createdAt => integer()();
20 23
 
21 24
   @override
22
-  Set<Column<Object>>? get primaryKey => {bleMac};
25
+  Set<Column<Object>>? get primaryKey => {bleMac, username};
23 26
 }

+ 1 - 0
lib/drfit/model_factory.dart

@@ -20,6 +20,7 @@ class ModelFactory {
20 20
       phoneAddress: Value(phoneAddress),
21 21
       bleMac: Value(bleMac),
22 22
       bleName: Value(bleName),
23
+      createdAt: Value(DateTime.now().millisecondsSinceEpoch)
23 24
     );
24 25
     return tsc;
25 26
   }

+ 0 - 7
lib/main.dart

@@ -11,9 +11,6 @@ import 'package:logger/logger.dart';
11 11
 import 'package:lszlgl/config/colors.dart';
12 12
 import 'package:lszlgl/drfit/database.dart';
13 13
 import 'package:lszlgl/router/my_navigator.dart';
14
-import 'package:lszlgl/service/print_service.dart';
15
-import 'package:path_provider/path_provider.dart';
16
-import 'package:path/path.dart' as p;
17 14
 
18 15
 late Logger logger;
19 16
 late MyDatabase database;
@@ -21,9 +18,6 @@ late MyDatabase database;
21 18
 void main() async {
22 19
   logger = Logger(printer: PrettyPrinter(methodCount: 0));
23 20
 
24
-
25
-  // database = MyDatabase(NativeDatabase.memory());
26
-
27 21
   initReportException(() async {
28 22
     SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent));
29 23
     SystemChrome.setPreferredOrientations([
@@ -33,7 +27,6 @@ void main() async {
33 27
 
34 28
     runApp(const MyApp());
35 29
     database = MyDatabase();
36
-    PrintService.getDeviceInfo();
37 30
   });
38 31
 }
39 32
 

+ 42 - 0
lib/model/req/device_req.dart

@@ -0,0 +1,42 @@
1
+
2
+import 'package:json_annotation/json_annotation.dart';
3
+
4
+part 'device_req.g.dart';
5
+
6
+@JsonSerializable()
7
+class DeviceReq {
8
+
9
+  /// 登录用户名
10
+  final String username;
11
+
12
+  /// 登录手机品牌,如Redmi
13
+  final String phoneBrand;
14
+
15
+  /// 登录手机认证型号,如22120RN86C
16
+  final String phoneModel;
17
+
18
+  /// 登录手机版本,如14
19
+  final String phoneRelease;
20
+
21
+  /// 登录手机所在地址,如"北京市西城区月坛北街18号靠近物资大院"
22
+  final String phoneAddress;
23
+
24
+  /// 登录蓝牙mac地址
25
+  final String bleMac;
26
+
27
+  /// 登录蓝牙名称
28
+  final String bleName;
29
+  const DeviceReq(
30
+      {required this.username,
31
+        required this.phoneBrand,
32
+        required this.phoneModel,
33
+        required this.phoneRelease,
34
+        required this.phoneAddress,
35
+        required this.bleMac,
36
+        required this.bleName});
37
+
38
+
39
+  factory DeviceReq.fromJson(Map<String, dynamic> json) => _$DeviceReqFromJson(json);
40
+
41
+  Map<String, dynamic> toJson() => _$DeviceReqToJson(this);
42
+}

+ 27 - 0
lib/model/req/device_req.g.dart

@@ -0,0 +1,27 @@
1
+// GENERATED CODE - DO NOT MODIFY BY HAND
2
+
3
+part of 'device_req.dart';
4
+
5
+// **************************************************************************
6
+// JsonSerializableGenerator
7
+// **************************************************************************
8
+
9
+DeviceReq _$DeviceReqFromJson(Map<String, dynamic> json) => DeviceReq(
10
+      username: json['username'] as String,
11
+      phoneBrand: json['phoneBrand'] as String,
12
+      phoneModel: json['phoneModel'] as String,
13
+      phoneRelease: json['phoneRelease'] as String,
14
+      phoneAddress: json['phoneAddress'] as String,
15
+      bleMac: json['bleMac'] as String,
16
+      bleName: json['bleName'] as String,
17
+    );
18
+
19
+Map<String, dynamic> _$DeviceReqToJson(DeviceReq instance) => <String, dynamic>{
20
+      'username': instance.username,
21
+      'phoneBrand': instance.phoneBrand,
22
+      'phoneModel': instance.phoneModel,
23
+      'phoneRelease': instance.phoneRelease,
24
+      'phoneAddress': instance.phoneAddress,
25
+      'bleMac': instance.bleMac,
26
+      'bleName': instance.bleName,
27
+    };

+ 7 - 0
lib/network/api.dart

@@ -10,6 +10,8 @@ import 'package:lszlgl/model/rsp/user_rsp.dart';
10 10
 import 'package:lszlgl/network/base_dio.dart';
11 11
 import 'package:retrofit/retrofit.dart';
12 12
 
13
+import '../drfit/database.dart';
14
+import '../model/req/device_req.dart';
13 15
 import '../model/rsp/district_rsp.dart';
14 16
 
15 17
 part 'api.g.dart';
@@ -83,4 +85,9 @@ abstract class Api {
83 85
   /// 上传图片
84 86
   @POST('/admin-api/infra/file/upload')
85 87
   Future<ApiRsp<String?>> upload(@Part(name: 'file') File file);
88
+
89
+  /// 提交设备绑定信息
90
+  @POST('/admin-api/zj/base-device/createBatch')
91
+  Future<ApiRsp> postDeviceInfos(@Body() List<DeviceReq> req);
92
+
86 93
 }

+ 30 - 0
lib/network/api.g.dart

@@ -513,6 +513,36 @@ class _Api implements Api {
513 513
     return value;
514 514
   }
515 515
 
516
+  @override
517
+  Future<ApiRsp<dynamic>> postDeviceInfos(List<DeviceReq> req) async {
518
+    const _extra = <String, dynamic>{};
519
+    final queryParameters = <String, dynamic>{};
520
+    final _headers = <String, dynamic>{};
521
+    final _data = req.map((e) => e.toJson()).toList();
522
+    final _result = await _dio
523
+        .fetch<Map<String, dynamic>>(_setStreamType<ApiRsp<dynamic>>(Options(
524
+      method: 'POST',
525
+      headers: _headers,
526
+      extra: _extra,
527
+    )
528
+            .compose(
529
+              _dio.options,
530
+              '/admin-api/zj/base-device/createBatch',
531
+              queryParameters: queryParameters,
532
+              data: _data,
533
+            )
534
+            .copyWith(
535
+                baseUrl: _combineBaseUrls(
536
+              _dio.options.baseUrl,
537
+              baseUrl,
538
+            ))));
539
+    final value = ApiRsp<dynamic>.fromJson(
540
+      _result.data!,
541
+      (json) => json as dynamic,
542
+    );
543
+    return value;
544
+  }
545
+
516 546
   RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
517 547
     if (T != dynamic &&
518 548
         !(requestOptions.responseType == ResponseType.bytes ||

+ 1 - 0
lib/network/my_api.dart

@@ -10,6 +10,7 @@ class MyApi {
10 10
   static String testUrl = 'http://121.36.17.6:19090';
11 11
 
12 12
   static Api get({Dio? dio, String? baseUrl}) {
13
+
13 14
     if (kReleaseMode) {
14 15
       baseUrl ??= productUrl;
15 16
     } else {

+ 8 - 0
lib/page/login/login_page.dart

@@ -12,9 +12,13 @@ import 'package:lszlgl/service/user_service.dart';
12 12
 import 'package:lszlgl/widget/button.dart';
13 13
 
14 14
 import '../../config/reresh_config.dart';
15
+import '../../drfit/database.dart';
15 16
 import '../../network/base_dio.dart';
16 17
 import '../../utils/location_utils.dart';
17 18
 import '../../utils/sp_utils.dart';
19
+import 'package:lszlgl/service/print_service.dart';
20
+import 'package:path_provider/path_provider.dart';
21
+import 'package:path/path.dart' as p;
18 22
 
19 23
 /// 登录页面
20 24
 class LoginPage extends StatefulWidget {
@@ -92,6 +96,10 @@ class _LoginPageState extends BaseLifecycleState<LoginPage> {
92 96
     LocationUtils.updatePrivacyShow(true, true);
93 97
     LocationUtils.updatePrivacyAgree(true);
94 98
     LocationUtils.setApiKey(kReleaseMode ? '2c783509376e267b24d63b21681686fa' : '7d0c033909f84adc14a0e60a835f044f', '');
99
+    /// 获取手机设备信息
100
+    PrintService.getDeviceInfo();
101
+    /// 同步数据库里的蓝牙设备信息到服务器
102
+    database.savaBleDataToServer();
95 103
 
96 104
     /// 初始化基础库 end
97 105
     MyNavigator.dismissLoading();

+ 1 - 0
lib/page/print/print_page.dart

@@ -143,6 +143,7 @@ class _PrintPageState extends BaseLifecycleState<PrintPage> {
143 143
           PrintService.connectedDeviceList.add(deviceInfo);
144 144
         });
145 145
         await savaToSqlite(deviceInfo); // 保存记录到数据库
146
+        database.savaBleDataToServer(); // 同步记录到服务器
146 147
       } else {
147 148
         MyNavigator.dismiss();
148 149
         MyNavigator.showToast('连接失败');

+ 12 - 0
lib/service/user_service.dart

@@ -54,4 +54,16 @@ class UserService {
54 54
     if (user == null) return null;
55 55
     return UserRsp.fromJson(jsonDecode(user));
56 56
   }
57
+
58
+  /// 存储数据库DeviceInfoTable表的id号,用于记录同步的位置
59
+  Future<void> saveDeviceInfoTableTime(int timeId) async {
60
+
61
+    await SPUtils.getInstance().saveInt('DeviceInfoTableTimeInt', timeId);
62
+  }
63
+
64
+  /// 获取登录信息
65
+  int getDeviceInfoTableTime() {
66
+    return SPUtils.getInstance().getInt('DeviceInfoTableTimeInt') ?? -1;
67
+  }
68
+
57 69
 }