统计样式微调
This commit is contained in:
@@ -13,8 +13,20 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
|
||||
/// <param name="lastId">上一页最后一条记录的ID</param>
|
||||
/// <param name="pageSize">每页数量</param>
|
||||
/// <param name="searchKeyword">搜索关键词(搜索交易摘要和分类)</param>
|
||||
/// <param name="classify">筛选分类</param>
|
||||
/// <param name="type">筛选交易类型</param>
|
||||
/// <param name="year">筛选年份</param>
|
||||
/// <param name="month">筛选月份</param>
|
||||
/// <returns>交易记录列表、最后发生时间和最后ID</returns>
|
||||
Task<(List<TransactionRecord> list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync(DateTime? lastOccurredAt, long? lastId, int pageSize = 20, string? searchKeyword = null);
|
||||
Task<(List<TransactionRecord> list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync(
|
||||
DateTime? lastOccurredAt,
|
||||
long? lastId,
|
||||
int pageSize = 20,
|
||||
string? searchKeyword = null,
|
||||
string? classify = null,
|
||||
TransactionType? type = null,
|
||||
int? year = null,
|
||||
int? month = null);
|
||||
|
||||
/// <summary>
|
||||
/// 获取总数
|
||||
@@ -150,7 +162,15 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<(List<TransactionRecord> list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync(DateTime? lastOccurredAt, long? lastId, int pageSize = 20, string? searchKeyword = null)
|
||||
public async Task<(List<TransactionRecord> list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync(
|
||||
DateTime? lastOccurredAt,
|
||||
long? lastId,
|
||||
int pageSize = 20,
|
||||
string? searchKeyword = null,
|
||||
string? classify = null,
|
||||
TransactionType? type = null,
|
||||
int? year = null,
|
||||
int? month = null)
|
||||
{
|
||||
var query = FreeSql.Select<TransactionRecord>();
|
||||
|
||||
@@ -163,6 +183,26 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
t.ImportFrom.Contains(searchKeyword));
|
||||
}
|
||||
|
||||
// 按分类筛选
|
||||
if (!string.IsNullOrWhiteSpace(classify))
|
||||
{
|
||||
query = query.Where(t => t.Classify == classify);
|
||||
}
|
||||
|
||||
// 按交易类型筛选
|
||||
if (type.HasValue)
|
||||
{
|
||||
query = query.Where(t => t.Type == type.Value);
|
||||
}
|
||||
|
||||
// 按年月筛选
|
||||
if (year.HasValue && month.HasValue)
|
||||
{
|
||||
var startDate = new DateTime(year.Value, month.Value, 1);
|
||||
var endDate = startDate.AddMonths(1);
|
||||
query = query.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate);
|
||||
}
|
||||
|
||||
// 如果提供了游标,则获取小于游标位置的记录
|
||||
if (lastOccurredAt.HasValue && lastId.HasValue)
|
||||
{
|
||||
@@ -200,7 +240,6 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
|
||||
var records = await FreeSql.Select<TransactionRecord>()
|
||||
.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate)
|
||||
.Where(t => t.Type == TransactionType.Expense || t.Type == TransactionType.Income) // 统计消费和收入
|
||||
.ToListAsync();
|
||||
|
||||
var statistics = records
|
||||
|
||||
Reference in New Issue
Block a user