fix: 全面修复 - 实时通讯、报告AI流程、健康概览、用药运动提醒
- SignalR Hub消息持久化+防重复+跨端广播 - 报告VLM+LLM真实AI流程(验证→提取→解读) - 医生审核页重构(严重程度/建议模板/综合评语) - 健康概览五合一趋势图(fl_chart+指标切换) - 用药提醒时区修复+跨午夜+过期提醒 - 运动打卡DayOfWeek映射修复+计划覆盖查询 - 体重与其他四指标同级(Abnormal检查/确认卡牌) - AI Agent支持多种类多时段批量录入 - 删除硬编码假数据(张三/假医生/假AI解读) - 随访/报告审核数据链路全部打通
This commit is contained in:
@@ -106,19 +106,28 @@ public static class MedicationEndpoints
|
||||
group.MapGet("/reminders", async (HttpContext http, AppDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var userId = GetUserId(http);
|
||||
var now = TimeOnly.FromDateTime(DateTime.Now);
|
||||
var windowEnd = now.AddHours(1);
|
||||
var beijingNow = DateTime.UtcNow.AddHours(8);
|
||||
var now = TimeOnly.FromDateTime(beijingNow);
|
||||
var windowFuture = now.AddHours(2); // 接下来2小时
|
||||
var windowPast = now.AddHours(-1); // 过去1小时内(过了还没吃就该提醒)
|
||||
|
||||
var meds = await db.Medications
|
||||
.Where(m => m.UserId == userId && m.IsActive && m.TimeOfDay != null)
|
||||
.ToListAsync(ct);
|
||||
var due = meds.Where(m => m.TimeOfDay!.Any(t => t >= now && t <= windowEnd)).ToList();
|
||||
|
||||
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||
// 同时包含:未来2小时内 + 过去1小时内(防止过了时间就不提醒)
|
||||
var due = meds.Where(m => m.TimeOfDay!.Any(t =>
|
||||
InTimeWindow(t, now, windowFuture) || InTimeWindow(t, windowPast, now)
|
||||
)).ToList();
|
||||
|
||||
var todayStart = DateTime.SpecifyKind(beijingNow.Date, DateTimeKind.Utc);
|
||||
var dueMeds = new List<object>();
|
||||
foreach (var m in due)
|
||||
{
|
||||
var logged = await db.MedicationLogs.AnyAsync(l =>
|
||||
l.MedicationId == m.Id && l.CreatedAt >= today.ToDateTime(TimeOnly.MinValue) && l.Status == MedicationLogStatus.Taken, ct);
|
||||
l.MedicationId == m.Id
|
||||
&& l.CreatedAt >= todayStart
|
||||
&& l.Status == MedicationLogStatus.Taken, ct);
|
||||
if (!logged)
|
||||
dueMeds.Add(new { m.Id, m.Name, m.Dosage, m.TimeOfDay });
|
||||
}
|
||||
@@ -127,6 +136,9 @@ public static class MedicationEndpoints
|
||||
});
|
||||
}
|
||||
|
||||
private static bool InTimeWindow(TimeOnly t, TimeOnly start, TimeOnly end) =>
|
||||
end > start ? (t >= start && t <= end) : (t >= start || t <= end); // 处理跨午夜
|
||||
|
||||
private static Guid GetUserId(HttpContext http) =>
|
||||
Guid.TryParse(http.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value, out var id) ? id : Guid.Empty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user