大量后端代码格式化

This commit is contained in:
SunCheng
2026-01-18 22:04:56 +08:00
parent 298ce03aa6
commit 4e2bf0da6c
36 changed files with 278 additions and 200 deletions

View File

@@ -6,7 +6,7 @@ public class CreateBudgetDto
public BudgetPeriodType Type { get; set; } = BudgetPeriodType.Month;
public decimal Limit { get; set; }
public BudgetCategory Category { get; set; }
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
public string[] SelectedCategories { get; set; } = [];
public DateTime? StartDate { get; set; }
public bool NoLimit { get; set; } = false;
public bool IsMandatoryExpense { get; set; } = false;

View File

@@ -6,21 +6,28 @@
public class EmailMessageDto
{
public long Id { get; set; }
public string Subject { get; set; } = string.Empty;
public string From { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public string HtmlBody { get; set; } = string.Empty;
public DateTime ReceivedDate { get; set; }
public DateTime CreateTime { get; set; }
public DateTime? UpdateTime { get; set; }
/// <summary>
/// 已解析的账单数量
/// </summary>
public int TransactionCount { get; set; }
public string ToName { get; set; } = string.Empty;
/// <summary>
/// 从实体转换为DTO
/// </summary>

View File

@@ -86,10 +86,8 @@ public class EmailMessageController(
{
return BaseResponse.Done();
}
else
{
return "删除邮件失败,邮件不存在".Fail();
}
return "删除邮件失败,邮件不存在".Fail();
}
catch (Exception ex)
{
@@ -117,10 +115,8 @@ public class EmailMessageController(
{
return BaseResponse.Done();
}
else
{
return "重新分析失败".Fail();
}
return "重新分析失败".Fail();
}
catch (Exception ex)
{

View File

@@ -1,4 +1,5 @@
using Quartz;
using Quartz.Impl.Matchers;
namespace WebApi.Controllers;
@@ -12,7 +13,7 @@ public class JobController(ISchedulerFactory schedulerFactory, ILogger<JobContro
try
{
var scheduler = await schedulerFactory.GetScheduler();
var jobKeys = await scheduler.GetJobKeys(Quartz.Impl.Matchers.GroupMatcher<JobKey>.AnyGroup());
var jobKeys = await scheduler.GetJobKeys(GroupMatcher<JobKey>.AnyGroup());
var jobStatuses = new List<JobStatus>();
foreach (var jobKey in jobKeys)
@@ -101,9 +102,13 @@ public class JobController(ISchedulerFactory schedulerFactory, ILogger<JobContro
public class JobStatus
{
public string Name { get; set; } = string.Empty;
public string JobDescription { get; set; } = string.Empty;
public string TriggerDescription { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string NextRunTime { get; set; } = string.Empty;
}

View File

@@ -1,4 +1,6 @@
namespace WebApi.Controllers;
using System.Text.RegularExpressions;
namespace WebApi.Controllers;
[ApiController]
[Route("api/[controller]/[action]")]
@@ -102,7 +104,7 @@ public class LogController(ILogger<LogController> logger) : ControllerBase
var currentLog = new StringBuilder();
// 日志行开始的正则表达式
var logStartPattern = new System.Text.RegularExpressions.Regex(
var logStartPattern = new Regex(
@"^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [+-]\d{2}:\d{2}\]"
);
@@ -151,10 +153,10 @@ public class LogController(ILogger<LogController> logger) : ControllerBase
// 日志格式示例: [2025-12-29 16:38:45.730 +08:00] [INF] Message here
// 使用正则表达式解析
// 使用 Singleline 模式使 '.' 可以匹配换行,这样 multi-line 消息可以被完整捕获。
var match = System.Text.RegularExpressions.Regex.Match(
var match = Regex.Match(
line,
@"^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [+-]\d{2}:\d{2})\] \[([A-Z]{2,5})\] ([\s\S]*)$",
System.Text.RegularExpressions.RegexOptions.Singleline
RegexOptions.Singleline
);
if (match.Success)

View File

@@ -4,7 +4,7 @@
[Route("api/[controller]/[action]")]
public class NotificationController(INotificationService notificationService) : ControllerBase
{
[HttpGet()]
[HttpGet]
public async Task<BaseResponse<string>> GetVapidPublicKey()
{
try

View File

@@ -85,10 +85,8 @@ public class TransactionCategoryController(
{
return category.Id.Ok();
}
else
{
return "创建分类失败".Fail<long>();
}
return "创建分类失败".Fail<long>();
}
catch (Exception ex)
{
@@ -133,10 +131,8 @@ public class TransactionCategoryController(
{
return "更新分类成功".Ok();
}
else
{
return "更新分类失败".Fail();
}
return "更新分类失败".Fail();
}
catch (Exception ex)
{
@@ -165,10 +161,8 @@ public class TransactionCategoryController(
{
return BaseResponse.Done();
}
else
{
return "删除分类失败,分类不存在".Fail();
}
return "删除分类失败,分类不存在".Fail();
}
catch (Exception ex)
{
@@ -196,10 +190,8 @@ public class TransactionCategoryController(
{
return categories.Count.Ok();
}
else
{
return "批量创建分类失败".Fail<int>();
}
return "批量创建分类失败".Fail<int>();
}
catch (Exception ex)
{

View File

@@ -1,7 +1,5 @@
namespace WebApi.Controllers;
using Repository;
/// <summary>
/// 周期性账单控制器
/// </summary>

View File

@@ -1,8 +1,4 @@
namespace WebApi.Controllers;
using System.Text.Json;
using System.Text.Json.Nodes;
using Repository;
namespace WebApi.Controllers;
[ApiController]
[Route("api/[controller]/[action]")]
@@ -183,10 +179,8 @@ public class TransactionRecordController(
{
return BaseResponse.Done();
}
else
{
return "创建交易记录失败".Fail();
}
return "创建交易记录失败".Fail();
}
catch (Exception ex)
{
@@ -225,10 +219,8 @@ public class TransactionRecordController(
{
return BaseResponse.Done();
}
else
{
return "更新交易记录失败".Fail();
}
return "更新交易记录失败".Fail();
}
catch (Exception ex)
{
@@ -250,10 +242,8 @@ public class TransactionRecordController(
{
return BaseResponse.Done();
}
else
{
return "删除交易记录失败,记录不存在".Fail();
}
return "删除交易记录失败,记录不存在".Fail();
}
catch (Exception ex)
{
@@ -413,7 +403,7 @@ public class TransactionRecordController(
return;
}
await smartHandleService.AnalyzeBillAsync(request.UserInput, async (chunk) =>
await smartHandleService.AnalyzeBillAsync(request.UserInput, async chunk =>
{
await WriteEventAsync(chunk);
});
@@ -500,7 +490,7 @@ public class TransactionRecordController(
return;
}
await smartHandleService.SmartClassifyAsync(request.TransactionIds.ToArray(), async (chunk) =>
await smartHandleService.SmartClassifyAsync(request.TransactionIds.ToArray(), async chunk =>
{
var (eventType, content) = chunk;
await TrySetUnconfirmedAsync(eventType, content);
@@ -550,7 +540,6 @@ public class TransactionRecordController(
catch (Exception ex)
{
logger.LogError(ex, "解析智能分类结果失败,内容: {Content}", content);
return;
}
}
@@ -746,7 +735,18 @@ public record CreateTransactionDto(
decimal Amount,
TransactionType Type,
string? Classify
);
)
{
public string OccurredAt { get; init; } = OccurredAt;
public string? Reason { get; init; } = Reason;
public decimal Amount { get; init; } = Amount;
public TransactionType Type { get; init; } = Type;
public string? Classify { get; init; } = Classify;
}
/// <summary>
/// 更新交易记录DTO
@@ -758,7 +758,20 @@ public record UpdateTransactionDto(
decimal Balance,
TransactionType Type,
string? Classify
);
)
{
public long Id { get; init; } = Id;
public string? Reason { get; init; } = Reason;
public decimal Amount { get; init; } = Amount;
public decimal Balance { get; init; } = Balance;
public TransactionType Type { get; init; } = Type;
public string? Classify { get; init; } = Classify;
}
/// <summary>
/// 日历统计响应DTO
@@ -769,14 +782,28 @@ public record DailyStatisticsDto(
decimal Expense,
decimal Income,
decimal Balance
);
)
{
public string Date { get; init; } = Date;
public int Count { get; init; } = Count;
public decimal Expense { get; init; } = Expense;
public decimal Income { get; init; } = Income;
public decimal Balance { get; init; } = Balance;
}
/// <summary>
/// 智能分类请求DTO
/// </summary>
public record SmartClassifyRequest(
List<long>? TransactionIds = null
);
)
{
public List<long>? TransactionIds { get; init; } = TransactionIds;
}
/// <summary>
/// 批量更新分类项DTO
@@ -785,7 +812,14 @@ public record BatchUpdateClassifyItem(
long Id,
string? Classify,
TransactionType? Type = null
);
)
{
public long Id { get; init; } = Id;
public string? Classify { get; init; } = Classify;
public TransactionType? Type { get; init; } = Type;
}
/// <summary>
/// 按摘要批量更新DTO
@@ -794,14 +828,24 @@ public record BatchUpdateByReasonDto(
string Reason,
TransactionType Type,
string Classify
);
)
{
public string Reason { get; init; } = Reason;
public TransactionType Type { get; init; } = Type;
public string Classify { get; init; } = Classify;
}
/// <summary>
/// 账单分析请求DTO
/// </summary>
public record BillAnalysisRequest(
string UserInput
);
)
{
public string UserInput { get; init; } = UserInput;
}
/// <summary>
/// 抵账请求DTO
@@ -809,13 +853,23 @@ public record BillAnalysisRequest(
public record OffsetTransactionDto(
long Id1,
long Id2
);
)
{
public long Id1 { get; init; } = Id1;
public long Id2 { get; init; } = Id2;
}
public record ParseOneLineRequestDto(
string Text
);
)
{
public string Text { get; init; } = Text;
}
public record ConfirmAllUnconfirmedRequestDto(
long[] Ids
);
)
{
public long[] Ids { get; init; } = Ids;
}

View File

@@ -1,4 +1,5 @@
using Quartz;
using Service.Jobs;
namespace WebApi;
@@ -13,7 +14,7 @@ public static class Expand
// 配置邮件同步任务 - 每10分钟执行一次
var emailJobKey = new JobKey("EmailSyncJob");
q.AddJob<Service.Jobs.EmailSyncJob>(opts => opts
q.AddJob<EmailSyncJob>(opts => opts
.WithIdentity(emailJobKey)
.WithDescription("邮件同步任务"));
q.AddTrigger(opts => opts
@@ -24,7 +25,7 @@ public static class Expand
// 配置周期性账单任务 - 每天早上6点执行
var periodicBillJobKey = new JobKey("PeriodicBillJob");
q.AddJob<Service.Jobs.PeriodicBillJob>(opts => opts
q.AddJob<PeriodicBillJob>(opts => opts
.WithIdentity(periodicBillJobKey)
.WithDescription("周期性账单任务"));
q.AddTrigger(opts => opts
@@ -35,7 +36,7 @@ public static class Expand
// 配置预算归档任务 - 每个月1号晚11点执行
var budgetArchiveJobKey = new JobKey("BudgetArchiveJob");
q.AddJob<Service.Jobs.BudgetArchiveJob>(opts => opts
q.AddJob<BudgetArchiveJob>(opts => opts
.WithIdentity(budgetArchiveJobKey)
.WithDescription("预算归档任务"));
q.AddTrigger(opts => opts

View File

@@ -5,3 +5,5 @@ global using WebApi.Controllers.Dto;
global using Repository;
global using Entity;
global using System.Text;
global using System.Text.Json;
global using System.Text.Json.Nodes;

View File

@@ -46,7 +46,7 @@ builder.Services.AddCors(options =>
// 绑定配置
builder.Services.Configure<EmailSettings>(builder.Configuration.GetSection("EmailSettings"));
builder.Services.Configure<AISettings>(builder.Configuration.GetSection("OpenAI"));
builder.Services.Configure<AiSettings>(builder.Configuration.GetSection("OpenAI"));
builder.Services.Configure<JwtSettings>(builder.Configuration.GetSection("JwtSettings"));
builder.Services.Configure<AuthSettings>(builder.Configuration.GetSection("AuthSettings"));