chore: 全面规范化代码,遵循 CLAUDE.md 编码规范

- C# 文件命名改为 snake_case(28 个文件重命名)
- C# 类转换为主构造函数(8 个类)
- 空 catch 添加异常类型(2 处)
- 新建 GlobalUsings.cs(Health.Infrastructure、Health.WebApi)
- Flutter 移除 go_router,改用 Riverpod 路由栈
- Flutter 移除 flutter_secure_storage,改用 sqflite 持久化
- 修复 Flutter 构建路径(Flutter SDK 迁至 D 盘)
- 后端端口改为 0.0.0.0:5000,支持局域网访问
This commit is contained in:
MingNian
2026-06-02 12:41:06 +08:00
parent 14d7c30d3d
commit 6e69f1085e
47 changed files with 342 additions and 428 deletions

View File

@@ -1,21 +1,12 @@
using Health.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Health.WebApi.BackgroundServices;
/// <summary>
/// 数据清理后台服务(每小时检查一次)
/// </summary>
public sealed class CleanupService : BackgroundService
public sealed class CleanupService(IServiceScopeFactory scopeFactory, ILogger<CleanupService> logger) : BackgroundService
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ILogger<CleanupService> _logger;
public CleanupService(IServiceScopeFactory scopeFactory, ILogger<CleanupService> logger)
{
_scopeFactory = scopeFactory;
_logger = logger;
}
private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
private readonly ILogger<CleanupService> _logger = logger;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{

View File

@@ -1,23 +1,12 @@
using Health.Domain.Entities;
using Health.Domain.Enums;
using Health.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Health.WebApi.BackgroundServices;
/// <summary>
/// 用药提醒定时扫描服务(每分钟检查一次)
/// </summary>
public sealed class MedicationReminderService : BackgroundService
public sealed class MedicationReminderService(IServiceScopeFactory scopeFactory, ILogger<MedicationReminderService> logger) : BackgroundService
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ILogger<MedicationReminderService> _logger;
public MedicationReminderService(IServiceScopeFactory scopeFactory, ILogger<MedicationReminderService> logger)
{
_scopeFactory = scopeFactory;
_logger = logger;
}
private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
private readonly ILogger<MedicationReminderService> _logger = logger;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{

View File

@@ -1,9 +1,4 @@
using System.Text.Json;
using Health.Domain.Entities;
using Health.Domain.Enums;
using Health.Infrastructure.AI;
using Health.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Health.WebApi.Endpoints;
@@ -135,7 +130,7 @@ public static class AiChatEndpoints
await SseWriteAsync(http, new { action = "answer", data = content }, ct);
}
}
catch { /* 跳过解析失败的 chunk */ }
catch (JsonException) { /* 跳过解析失败的 chunk */ }
}
completedNormally = true;
break;
@@ -311,7 +306,7 @@ public static class AiChatEndpoints
var sub = jwt.Claims.FirstOrDefault(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
return sub != null && Guid.TryParse(sub, out var id) ? id : null;
}
catch { return null; }
catch (Exception) { return null; }
}
private static List<ToolDefinition> GetToolsForAgent(AgentType agentType) => agentType switch

View File

@@ -1,8 +1,4 @@
using System.Text.Json;
using Health.Domain.Entities;
using Health.Infrastructure.Data;
using Health.Infrastructure.Services;
using Microsoft.EntityFrameworkCore;
namespace Health.WebApi.Endpoints;

View File

@@ -1,8 +1,3 @@
using Health.Domain.Entities;
using Health.Domain.Enums;
using Health.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Health.WebApi.Endpoints;
/// <summary>

View File

@@ -1,8 +1,3 @@
using Health.Domain.Entities;
using Health.Domain.Enums;
using Health.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Health.WebApi.Endpoints;
/// <summary>

View File

@@ -1,6 +1,3 @@
using Health.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Health.WebApi.Endpoints;
/// <summary>

View File

@@ -0,0 +1,5 @@
global using Health.Domain.Entities;
global using Health.Domain.Enums;
global using Health.Infrastructure.Data;
global using Microsoft.EntityFrameworkCore;
global using System.Text.Json;

View File

@@ -1,21 +1,14 @@
using System.Net;
using System.Text.Json;
namespace Health.WebApi.Middleware;
/// <summary>
/// 全局异常处理中间件——统一返回 {code, data, message} 格式
/// </summary>
public sealed class ExceptionMiddleware
public sealed class ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger)
{
private readonly RequestDelegate _next;
private readonly ILogger<ExceptionMiddleware> _logger;
public ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger)
{
_next = next;
_logger = logger;
}
private readonly RequestDelegate _next = next;
private readonly ILogger<ExceptionMiddleware> _logger = logger;
public async Task InvokeAsync(HttpContext context)
{

View File

@@ -5,7 +5,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5277",
"applicationUrl": "http://0.0.0.0:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
@@ -14,7 +14,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7102;http://localhost:5277",
"applicationUrl": "https://localhost:7102;http://0.0.0.0:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}