feat: 应用内通知系统 + 结构化手术史/用药等相关改动
- 新增用户通知 outbox 流水线(EfUserNotificationPipeline)与后台投递 worker - 通知中心页面及前端通知服务接入 - 健康指标异常、用药/运动提醒等事件统一产出站内通知 - 健康档案结构化手术史、用药提醒扫描、医生/用户端点等配套调整 - AppDbContext 注册通知相关实体
This commit is contained in:
@@ -5,12 +5,22 @@ class InAppNotification {
|
||||
final String type;
|
||||
final String title;
|
||||
final String message;
|
||||
final String severity;
|
||||
final String? actionType;
|
||||
final String? actionTargetId;
|
||||
final bool isRead;
|
||||
final DateTime createdAt;
|
||||
|
||||
const InAppNotification({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.message,
|
||||
required this.severity,
|
||||
this.actionType,
|
||||
this.actionTargetId,
|
||||
required this.isRead,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory InAppNotification.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -19,7 +29,36 @@ class InAppNotification {
|
||||
type: json['type']?.toString() ?? '',
|
||||
title: json['title']?.toString() ?? '健康提醒',
|
||||
message: json['message']?.toString() ?? '',
|
||||
severity: json['severity']?.toString() ?? 'info',
|
||||
actionType: json['actionType']?.toString(),
|
||||
actionTargetId: json['actionTargetId']?.toString(),
|
||||
isRead: json['isRead'] == true,
|
||||
createdAt:
|
||||
DateTime.tryParse(json['createdAt']?.toString() ?? '') ??
|
||||
DateTime.now(),
|
||||
);
|
||||
|
||||
InAppNotification copyWith({bool? isRead}) => InAppNotification(
|
||||
id: id,
|
||||
type: type,
|
||||
title: title,
|
||||
message: message,
|
||||
severity: severity,
|
||||
actionType: actionType,
|
||||
actionTargetId: actionTargetId,
|
||||
isRead: isRead ?? this.isRead,
|
||||
createdAt: createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
class InAppNotificationHistory {
|
||||
final int unreadCount;
|
||||
final List<InAppNotification> items;
|
||||
|
||||
const InAppNotificationHistory({
|
||||
required this.unreadCount,
|
||||
required this.items,
|
||||
});
|
||||
}
|
||||
|
||||
class InAppNotificationService {
|
||||
@@ -32,7 +71,9 @@ class InAppNotificationService {
|
||||
final items = response.data['data'] as List? ?? const [];
|
||||
return items
|
||||
.whereType<Map>()
|
||||
.map((item) => InAppNotification.fromJson(Map<String, dynamic>.from(item)))
|
||||
.map(
|
||||
(item) => InAppNotification.fromJson(Map<String, dynamic>.from(item)),
|
||||
)
|
||||
.where((item) => item.id.isNotEmpty)
|
||||
.toList();
|
||||
}
|
||||
@@ -40,4 +81,29 @@ class InAppNotificationService {
|
||||
Future<void> acknowledge(String id) async {
|
||||
await _api.post('/api/notifications/$id/acknowledge');
|
||||
}
|
||||
|
||||
Future<void> markAllRead() async {
|
||||
await _api.post('/api/notifications/read-all');
|
||||
}
|
||||
|
||||
Future<InAppNotificationHistory> getHistory() async {
|
||||
final response = await _api.get('/api/notifications');
|
||||
final data = response.data['data'] as Map? ?? const {};
|
||||
final rawItems = data['items'] as List? ?? const [];
|
||||
return InAppNotificationHistory(
|
||||
unreadCount: data['unreadCount'] as int? ?? 0,
|
||||
items: rawItems
|
||||
.whereType<Map>()
|
||||
.map(
|
||||
(item) =>
|
||||
InAppNotification.fromJson(Map<String, dynamic>.from(item)),
|
||||
)
|
||||
.where((item) => item.id.isNotEmpty)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> delete(String id) async {
|
||||
await _api.delete('/api/notifications/$id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user