feat: 更新交易记录和预算服务,支持按分类和日期范围筛选
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 26s
Docker Build & Deploy / Deploy to Production (push) Successful in 9s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 26s
Docker Build & Deploy / Deploy to Production (push) Successful in 9s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
This commit is contained in:
@@ -12,10 +12,12 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
|
||||
/// <param name="pageIndex">页码,从1开始</param>
|
||||
/// <param name="pageSize">每页数量</param>
|
||||
/// <param name="searchKeyword">搜索关键词(搜索交易摘要和分类)</param>
|
||||
/// <param name="classify">筛选分类</param>
|
||||
/// <param name="classifies">筛选分类列表</param>
|
||||
/// <param name="type">筛选交易类型</param>
|
||||
/// <param name="year">筛选年份</param>
|
||||
/// <param name="month">筛选月份</param>
|
||||
/// <param name="startDate">筛选开始日期</param>
|
||||
/// <param name="endDate">筛选结束日期</param>
|
||||
/// <param name="reason">筛选交易摘要</param>
|
||||
/// <param name="sortByAmount">是否按金额降序排列,默认为false按时间降序</param>
|
||||
/// <returns>交易记录列表</returns>
|
||||
@@ -23,10 +25,12 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
|
||||
int pageIndex = 1,
|
||||
int pageSize = 20,
|
||||
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,
|
||||
bool sortByAmount = false);
|
||||
|
||||
@@ -35,10 +39,12 @@ public interface ITransactionRecordRepository : IBaseRepository<TransactionRecor
|
||||
/// </summary>
|
||||
Task<long> 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);
|
||||
|
||||
/// <summary>
|
||||
@@ -202,10 +208,12 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
int pageIndex = 1,
|
||||
int pageSize = 20,
|
||||
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,
|
||||
bool sortByAmount = false)
|
||||
{
|
||||
@@ -221,13 +229,10 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
t => 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<Tran
|
||||
// 按年月筛选
|
||||
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);
|
||||
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<Tran
|
||||
|
||||
public async Task<long> 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<TransactionRecord>();
|
||||
@@ -282,13 +293,10 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
t => 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<Tran
|
||||
// 按年月筛选
|
||||
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);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user