Преглед изворни кода

modify followup offline logic

Melon пре 1 година
родитељ
комит
be4cfdcc9c
2 измењених фајлова са 58 додато и 10 уклоњено
  1. 55 9
      lib/mock/services/exam.dart
  2. 3 1
      lib/mock/services/followup.dart

+ 55 - 9
lib/mock/services/exam.dart

@@ -1,27 +1,73 @@
 import 'package:fis_jsonrpc/services/exam.dart';
 import 'package:fis_jsonrpc/services/exam.m.dart';
+import 'package:uuid/uuid.dart';
+import 'package:vitalapp/database/db.dart';
+import 'package:vitalapp/database/entities/defines.dart';
+import 'package:vitalapp/database/entities/exam.dart';
+import 'package:vitalapp/store/store.dart';
 
 class ExamServiceMock extends VitalExamService {
   ExamServiceMock(super.host);
 
   @override
-  Future<String> createExamAsync(CreateExamRequest request) {
+  Future<String> createExamAsync(CreateExamRequest request) async {
     // 同步Server,新增&更新都走这个接口
-    // TODO: implement createExamAsync
-    return super.createExamAsync(request);
+    if (request.code != null && request.code!.isNotEmpty) {
+      final updateResult = await _updateOfflineExamByCreateRequest(request);
+      return updateResult ? request.code! : "";
+    }
+    final entity = ExamEntity();
+    entity.isValid = true;
+    entity.syncType = OfflineDataSyncType.create;
+    // 本地先生成一个Code,上传后更新
+    final uuid = const Uuid().v4().replaceAll('-', '');
+    entity.code = "mock_$uuid";
+    entity.userCode = Store.user.userCode!;
+    entity.patientCode = request.patientCode!;
+    entity.batchNumber = request.batchNumber!;
+    entity.templateKey = request.key!;
+    entity.dataJson = request.examData!;
+
+    final id = await db.repositories.exam.insert(entity);
+    return id > 0 ? entity.code : "";
+  }
+
+  @override
+  Future<bool> updateExamByBatchNumberAsync(
+      UpdateExamByBatchNumberRequest request) async {
+    // TODO: implement updateExamByBatchNumberAsync
+    return super.updateExamByBatchNumberAsync(request);
   }
 
   @override
   Future<List<ExamRecordDTO>> getExamRecordListAsync(
-      GetExamRecordListRequest request) {
+      GetExamRecordListRequest request) async {
     // TODO: implement getExamRecordListAsync
     return super.getExamRecordListAsync(request);
   }
 
-  @override
-  Future<bool> updateExamByBatchNumberAsync(
-      UpdateExamByBatchNumberRequest request) {
-    // TODO: implement updateExamByBatchNumberAsync
-    return super.updateExamByBatchNumberAsync(request);
+  Future<bool> _updateOfflineExamByCreateRequest(
+      CreateExamRequest request) async {
+    ExamEntity entity;
+
+    ExamEntity? history =
+        await db.repositories.exam.singleByCode(request.code!);
+
+    if (history == null) {
+      entity = ExamEntity();
+      entity.isValid = true;
+      entity.syncType = OfflineDataSyncType.create;
+      entity.code = request.code!;
+    } else {
+      entity = history;
+    }
+
+    int result;
+    if (entity.id > 0) {
+      result = await db.repositories.exam.update(entity);
+    } else {
+      result = await db.repositories.exam.insert(entity);
+    }
+    return result > 0;
   }
 }

+ 3 - 1
lib/mock/services/followup.dart

@@ -12,7 +12,9 @@ class FollowUpServiceMock extends VitalFollowUpService {
   @override
   Future<String> createFollowUpAsync(CreateFollowUpRequest request) async {
     final entity = FollowUpEntity();
-    entity.code = const Uuid().v4().replaceAll('-', ''); // 本地先生成一个Code
+    // 本地先生成一个Code,上传后更新
+    final uuid = const Uuid().v4().replaceAll('-', '');
+    entity.code = "mock_$uuid";
     entity.isValid = true;
     entity.syncType = OfflineDataSyncType.create;
     entity.userCode = Store.user.userCode!;