From b5d0524868bb74dd58a42e545ad95daef726bcc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Fri, 9 Jan 2026 16:21:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BA=A4=E6=98=93?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=92=8C=E9=A2=84=E7=AE=97=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E6=8C=89=E5=88=86=E7=B1=BB=E5=92=8C?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E8=8C=83=E5=9B=B4=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Repository/TransactionRecordRepository.cs | 58 +++++++++------ Service/BudgetService.cs | 7 +- Web/src/components/Budget/BudgetCard.vue | 73 ++++++++++++++++++- Web/src/components/Budget/BudgetSummary.vue | 2 +- Web/src/views/BudgetView.vue | 2 +- .../TransactionRecordController.cs | 14 +++- 6 files changed, 127 insertions(+), 29 deletions(-) diff --git a/Repository/TransactionRecordRepository.cs b/Repository/TransactionRecordRepository.cs index 44edfde..4711b4f 100644 --- a/Repository/TransactionRecordRepository.cs +++ b/Repository/TransactionRecordRepository.cs @@ -12,10 +12,12 @@ public interface ITransactionRecordRepository : IBaseRepository页码,从1开始 /// 每页数量 /// 搜索关键词(搜索交易摘要和分类) - /// 筛选分类 + /// 筛选分类列表 /// 筛选交易类型 /// 筛选年份 /// 筛选月份 + /// 筛选开始日期 + /// 筛选结束日期 /// 筛选交易摘要 /// 是否按金额降序排列,默认为false按时间降序 /// 交易记录列表 @@ -23,10 +25,12 @@ public interface ITransactionRecordRepository : IBaseRepository Task GetTotalCountAsync( string? searchKeyword = null, - string? classify = null, + string[]? classifies = null, TransactionType? type = null, int? year = null, int? month = null, + DateTime? startDate = null, + DateTime? endDate = null, string? reason = null); /// @@ -202,10 +208,12 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository t.Reason == reason); // 按分类筛选 - if (!string.IsNullOrWhiteSpace(classify)) + if (classifies != null && classifies.Length > 0) { - if (classify == "未分类") - { - classify = string.Empty; - } - query = query.Where(t => t.Classify == classify); + var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList(); + query = query.Where(t => filterClassifies.Contains(t.Classify)); } // 按交易类型筛选 @@ -236,10 +241,14 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository t.OccurredAt >= startDate && t.OccurredAt < endDate); + var dateStart = new DateTime(year.Value, month.Value, 1); + var dateEnd = dateStart.AddMonths(1); + query = query.Where(t => t.OccurredAt >= dateStart && t.OccurredAt < dateEnd); } + + // 按日期范围筛选 + query = query.WhereIf(startDate.HasValue, t => t.OccurredAt >= startDate!.Value) + .WhereIf(endDate.HasValue, t => t.OccurredAt <= endDate!.Value); // 根据sortByAmount参数决定排序方式 if (sortByAmount) @@ -264,10 +273,12 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository GetTotalCountAsync( string? searchKeyword = null, - string? classify = null, + string[]? classifies = null, TransactionType? type = null, int? year = null, int? month = null, + DateTime? startDate = null, + DateTime? endDate = null, string? reason = null) { var query = FreeSql.Select(); @@ -282,13 +293,10 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository t.Reason == reason); // 按分类筛选 - if (!string.IsNullOrWhiteSpace(classify)) + if (classifies != null && classifies.Length > 0) { - if (classify == "未分类") - { - classify = string.Empty; - } - query = query.Where(t => t.Classify == classify); + var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList(); + query = query.Where(t => filterClassifies.Contains(t.Classify)); } // 按交易类型筛选 @@ -297,11 +305,15 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository t.OccurredAt >= startDate && t.OccurredAt < endDate); + var dateStart = new DateTime(year.Value, month.Value, 1); + var dateEnd = dateStart.AddMonths(1); + query = query.Where(t => t.OccurredAt >= dateStart && t.OccurredAt < dateEnd); } + // 按日期范围筛选 + query = query.WhereIf(startDate.HasValue, t => t.OccurredAt >= startDate!.Value) + .WhereIf(endDate.HasValue, t => t.OccurredAt <= endDate!.Value); + return await query.CountAsync(); } diff --git a/Service/BudgetService.cs b/Service/BudgetService.cs index a7c99bb..ad7ea9d 100644 --- a/Service/BudgetService.cs +++ b/Service/BudgetService.cs @@ -305,8 +305,9 @@ public class BudgetService( 2. 预算详情:使用 HTML 表格展示预算执行明细(预算项、预算额、实际额、使用/达成率、状态)。 3. 超支/异常预警:重点分析超支项或支出异常的分类。 4. 消费透视:针对“未被预算覆盖的支出”提供分析建议。分析这些账单产生的合理性,并评估是否需要为其中的大额或频发分类建立新预算。 - 5. 改进建议:基于本月整体收入支出情况,给出下月预算调整或消费改进的专业化建议。 + 5. 改进建议:根据当前时间进度和预算完成进度,基于本月整体收入支出情况,给出下月预算调整或消费改进的专业化建议。 6. 语言风格:专业、清晰、简洁,适合财务报告阅读。 + 7. 【格式要求】 1. 使用HTML格式(移动端H5页面风格) @@ -322,6 +323,10 @@ public class BudgetService( 9. 不要使用任何 style 属性或