```
docs(health-profile): 添加防编造加固修订记录到导出健康档案设计文档 补充了关于导出摘要出现虚构病例问题的详细分析和修复方案, 包括检索策略优化、空数据兜底处理和prompt重写等三层防护措施。 ```
This commit is contained in:
@@ -53,14 +53,16 @@ enum ReminderService {
|
||||
static func sync(_ reminder: MetricReminder) async {
|
||||
cancel(metricId: reminder.metricId)
|
||||
guard reminder.enabled else { return }
|
||||
let slots = reminder.weekdays.map { wd in
|
||||
Slot(suffix: "w\(wd)",
|
||||
dc: DateComponents(hour: reminder.hour, minute: reminder.minute, weekday: wd))
|
||||
}
|
||||
await schedule(
|
||||
idBase: "\(idPrefix)\(reminder.metricId)",
|
||||
title: String(appLoc: "该测\(reminder.displayName)了"),
|
||||
body: String(appLoc: "在「+ 新建 → 指标记录 → \(reminder.displayName)」记录一次"),
|
||||
hour: reminder.hour,
|
||||
minute: reminder.minute,
|
||||
weekdays: reminder.weekdays,
|
||||
thread: "kangkang.reminder.\(reminder.metricId)"
|
||||
thread: "kangkang.reminder.\(reminder.metricId)",
|
||||
slots: slots
|
||||
)
|
||||
}
|
||||
|
||||
@@ -77,14 +79,28 @@ enum ReminderService {
|
||||
guard reminder.enabled else { return }
|
||||
let title = reminder.title.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let body = reminder.note.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let h = reminder.hour, m = reminder.minute
|
||||
let slots: [Slot]
|
||||
switch reminder.frequency {
|
||||
case .daily:
|
||||
slots = [Slot(suffix: "daily", dc: DateComponents(hour: h, minute: m))]
|
||||
case .weekly:
|
||||
slots = reminder.weekdays.map { wd in
|
||||
Slot(suffix: "w\(wd)", dc: DateComponents(hour: h, minute: m, weekday: wd))
|
||||
}
|
||||
case .monthly:
|
||||
slots = [Slot(suffix: "monthly",
|
||||
dc: DateComponents(day: reminder.dayOfMonth, hour: h, minute: m))]
|
||||
case .yearly:
|
||||
slots = [Slot(suffix: "yearly",
|
||||
dc: DateComponents(month: reminder.month, day: reminder.dayOfMonth, hour: h, minute: m))]
|
||||
}
|
||||
await schedule(
|
||||
idBase: "\(customIdPrefix)\(reminder.id.uuidString)",
|
||||
title: title.isEmpty ? String(appLoc: "提醒") : title,
|
||||
body: body.isEmpty ? String(appLoc: "到点啦,记得完成") : body,
|
||||
hour: reminder.hour,
|
||||
minute: reminder.minute,
|
||||
weekdays: reminder.weekdays,
|
||||
thread: "\(customIdPrefix)\(reminder.id.uuidString)"
|
||||
thread: "\(customIdPrefix)\(reminder.id.uuidString)",
|
||||
slots: slots
|
||||
)
|
||||
}
|
||||
|
||||
@@ -100,16 +116,20 @@ enum ReminderService {
|
||||
|
||||
// MARK: - 共享调度核心
|
||||
|
||||
/// 把一条提醒按 weekdays 展开成 N 条 weekly-repeats 通知。
|
||||
/// `idBase` 是不含 `.w<weekday>` 后缀的稳定前缀;两类提醒共用本核心。
|
||||
/// 一条触发槽:`suffix` 用于拼出稳定且可单独取消的通知 id(`<idBase>.<suffix>`,
|
||||
/// 如 `.daily` / `.w2` / `.monthly` / `.yearly`),`dc` 为对应的重复触发时间分量。
|
||||
private struct Slot {
|
||||
let suffix: String
|
||||
let dc: DateComponents
|
||||
}
|
||||
|
||||
/// 把若干 `Slot` 展开成 N 条 repeats 通知。每日/每周/每月/每年两类提醒共用本核心。
|
||||
private static func schedule(idBase: String,
|
||||
title: String,
|
||||
body: String,
|
||||
hour: Int,
|
||||
minute: Int,
|
||||
weekdays: [Int],
|
||||
thread: String) async {
|
||||
guard !weekdays.isEmpty else { return }
|
||||
thread: String,
|
||||
slots: [Slot]) async {
|
||||
guard !slots.isEmpty else { return }
|
||||
let center = UNUserNotificationCenter.current()
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = title
|
||||
@@ -117,23 +137,20 @@ enum ReminderService {
|
||||
content.sound = .default
|
||||
content.threadIdentifier = thread
|
||||
|
||||
for weekday in weekdays {
|
||||
var comps = DateComponents()
|
||||
comps.hour = hour
|
||||
comps.minute = minute
|
||||
comps.weekday = weekday
|
||||
let trigger = UNCalendarNotificationTrigger(dateMatching: comps, repeats: true)
|
||||
let request = UNNotificationRequest(identifier: "\(idBase).w\(weekday)",
|
||||
for slot in slots {
|
||||
let trigger = UNCalendarNotificationTrigger(dateMatching: slot.dc, repeats: true)
|
||||
let request = UNNotificationRequest(identifier: "\(idBase).\(slot.suffix)",
|
||||
content: content,
|
||||
trigger: trigger)
|
||||
try? await center.add(request)
|
||||
}
|
||||
}
|
||||
|
||||
/// 取消某个 idBase 下 7 个 weekday 的全部 pending 通知(不漏)。
|
||||
/// 取消某个 idBase 下所有可能后缀的 pending 通知(daily/monthly/yearly + 7 个 weekday,不漏)。
|
||||
private static func cancelBase(_ idBase: String) {
|
||||
let center = UNUserNotificationCenter.current()
|
||||
let ids = (1...7).map { "\(idBase).w\($0)" }
|
||||
var ids = ["\(idBase).daily", "\(idBase).monthly", "\(idBase).yearly"]
|
||||
ids += (1...7).map { "\(idBase).w\($0)" }
|
||||
center.removePendingNotificationRequests(withIdentifiers: ids)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user