- 新增用户通知 outbox 流水线(EfUserNotificationPipeline)与后台投递 worker - 通知中心页面及前端通知服务接入 - 健康指标异常、用药/运动提醒等事件统一产出站内通知 - 健康档案结构化手术史、用药提醒扫描、医生/用户端点等配套调整 - AppDbContext 注册通知相关实体
128 lines
3.8 KiB
Dart
128 lines
3.8 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'auth_provider.dart';
|
|
import '../services/health_service.dart';
|
|
import '../services/admin_service.dart';
|
|
import '../services/in_app_notification_service.dart';
|
|
|
|
final exerciseServiceProvider = Provider<ExerciseService>((ref) {
|
|
return ExerciseService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
/// 健康数据服务
|
|
final healthServiceProvider = Provider<HealthService>((ref) {
|
|
return HealthService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final userServiceProvider = Provider<UserService>((ref) {
|
|
return UserService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final medicationServiceProvider = Provider<MedicationService>((ref) {
|
|
return MedicationService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final dietServiceProvider = Provider<DietService>((ref) {
|
|
return DietService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final followUpServiceProvider = Provider<FollowUpService>((ref) {
|
|
return FollowUpService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final consultationServiceProvider = Provider<ConsultationService>((ref) {
|
|
return ConsultationService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final adminServiceProvider = Provider<AdminService>((ref) {
|
|
return AdminService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final inAppNotificationServiceProvider = Provider<InAppNotificationService>((
|
|
ref,
|
|
) {
|
|
return InAppNotificationService(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final notificationUnreadCountProvider = FutureProvider.autoDispose<int>((
|
|
ref,
|
|
) async {
|
|
final history = await ref
|
|
.watch(inAppNotificationServiceProvider)
|
|
.getHistory();
|
|
return history.unreadCount;
|
|
});
|
|
|
|
/// 最新健康数据 Provider
|
|
final latestHealthProvider = FutureProvider.autoDispose<Map<String, dynamic>>((
|
|
ref,
|
|
) async {
|
|
final service = ref.watch(healthServiceProvider);
|
|
return service.getLatest();
|
|
});
|
|
|
|
/// AI 录入数据后调用,刷新侧边栏
|
|
void refreshHealthData(WidgetRef ref) {
|
|
ref.invalidate(latestHealthProvider);
|
|
ref.invalidate(medicationListProvider);
|
|
}
|
|
|
|
/// 用药列表 Provider
|
|
final medicationListProvider =
|
|
FutureProvider.autoDispose<List<Map<String, dynamic>>>((ref) async {
|
|
final service = ref.watch(medicationServiceProvider);
|
|
return service.getList();
|
|
});
|
|
|
|
final medicationReminderProvider =
|
|
FutureProvider.autoDispose<List<Map<String, dynamic>>>((ref) async {
|
|
final service = ref.watch(medicationServiceProvider);
|
|
return service.getReminders();
|
|
});
|
|
|
|
/// 医生列表 Provider
|
|
final doctorListProvider = FutureProvider<List<Map<String, dynamic>>>((
|
|
ref,
|
|
) async {
|
|
final service = ref.watch(consultationServiceProvider);
|
|
return service.getDoctors().timeout(const Duration(seconds: 8));
|
|
});
|
|
|
|
/// 问诊配额 Provider
|
|
final consultationQuotaProvider = FutureProvider<Map<String, dynamic>>((
|
|
ref,
|
|
) async {
|
|
final service = ref.watch(consultationServiceProvider);
|
|
return service.getQuota();
|
|
});
|
|
|
|
/// 当前运动计划 Provider
|
|
final currentExercisePlanProvider =
|
|
FutureProvider.autoDispose<Map<String, dynamic>?>((ref) async {
|
|
final service = ref.watch(exerciseServiceProvider);
|
|
return service.getCurrentPlan().timeout(const Duration(seconds: 8));
|
|
});
|
|
|
|
/// 拍照/相册直接触发(无需跳转页面)
|
|
final cameraActionProvider = NotifierProvider<CameraActionNotifier, String?>(
|
|
CameraActionNotifier.new,
|
|
);
|
|
|
|
class CameraActionNotifier extends Notifier<String?> {
|
|
@override
|
|
String? build() => null;
|
|
void trigger(String action) => state = action;
|
|
void clear() => state = null;
|
|
}
|
|
|
|
/// 拍饮食动作触发(不用跳多余页面)
|
|
final dietActionProvider = NotifierProvider<DietActionNotifier, String?>(
|
|
DietActionNotifier.new,
|
|
);
|
|
|
|
class DietActionNotifier extends Notifier<String?> {
|
|
@override
|
|
String? build() => null;
|
|
void trigger(String action) => state = action;
|
|
void clear() => state = null;
|
|
}
|