2025-12-25 11:20:56 +08:00
|
|
|
|
namespace Repository;
|
|
|
|
|
|
|
|
|
|
|
|
public interface ITransactionRecordRepository : IBaseRepository<TransactionRecord>
|
|
|
|
|
|
{
|
|
|
|
|
|
Task<TransactionRecord?> ExistsByEmailMessageIdAsync(long emailMessageId, DateTime occurredAt);
|
|
|
|
|
|
|
|
|
|
|
|
Task<TransactionRecord?> ExistsByImportNoAsync(string importNo, string importFrom);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-27 22:05:50 +08:00
|
|
|
|
/// 分页获取交易记录列表
|
2025-12-25 11:20:56 +08:00
|
|
|
|
/// </summary>
|
2025-12-27 22:05:50 +08:00
|
|
|
|
/// <param name="pageIndex">页码,从1开始</param>
|
2025-12-25 11:20:56 +08:00
|
|
|
|
/// <param name="pageSize">每页数量</param>
|
|
|
|
|
|
/// <param name="searchKeyword">搜索关键词(搜索交易摘要和分类)</param>
|
2026-01-09 16:21:03 +08:00
|
|
|
|
/// <param name="classifies">筛选分类列表</param>
|
2025-12-26 17:56:08 +08:00
|
|
|
|
/// <param name="type">筛选交易类型</param>
|
|
|
|
|
|
/// <param name="year">筛选年份</param>
|
|
|
|
|
|
/// <param name="month">筛选月份</param>
|
2026-01-09 16:21:03 +08:00
|
|
|
|
/// <param name="startDate">筛选开始日期</param>
|
|
|
|
|
|
/// <param name="endDate">筛选结束日期</param>
|
2025-12-30 17:02:30 +08:00
|
|
|
|
/// <param name="reason">筛选交易摘要</param>
|
2025-12-27 22:05:50 +08:00
|
|
|
|
/// <param name="sortByAmount">是否按金额降序排列,默认为false按时间降序</param>
|
|
|
|
|
|
/// <returns>交易记录列表</returns>
|
|
|
|
|
|
Task<List<TransactionRecord>> GetPagedListAsync(
|
|
|
|
|
|
int pageIndex = 1,
|
2025-12-27 11:50:12 +08:00
|
|
|
|
int pageSize = 20,
|
2025-12-26 17:56:08 +08:00
|
|
|
|
string? searchKeyword = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
string[]? classifies = null,
|
2025-12-26 17:56:08 +08:00
|
|
|
|
TransactionType? type = null,
|
|
|
|
|
|
int? year = null,
|
2025-12-27 22:05:50 +08:00
|
|
|
|
int? month = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
DateTime? startDate = null,
|
|
|
|
|
|
DateTime? endDate = null,
|
2025-12-30 17:02:30 +08:00
|
|
|
|
string? reason = null,
|
2025-12-27 22:05:50 +08:00
|
|
|
|
bool sortByAmount = false);
|
2025-12-25 11:20:56 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取总数
|
|
|
|
|
|
/// </summary>
|
2025-12-27 22:05:50 +08:00
|
|
|
|
Task<long> GetTotalCountAsync(
|
|
|
|
|
|
string? searchKeyword = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
string[]? classifies = null,
|
2025-12-27 22:05:50 +08:00
|
|
|
|
TransactionType? type = null,
|
|
|
|
|
|
int? year = null,
|
2025-12-30 17:02:30 +08:00
|
|
|
|
int? month = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
DateTime? startDate = null,
|
|
|
|
|
|
DateTime? endDate = null,
|
2025-12-30 17:02:30 +08:00
|
|
|
|
string? reason = null);
|
2025-12-25 11:20:56 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取所有不同的交易分类
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Task<List<string>> GetDistinctClassifyAsync();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定月份每天的消费统计
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="year">年份</param>
|
|
|
|
|
|
/// <param name="month">月份</param>
|
|
|
|
|
|
/// <returns>每天的消费笔数和金额</returns>
|
|
|
|
|
|
Task<Dictionary<string, (int count, decimal amount)>> GetDailyStatisticsAsync(int year, int month);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定日期范围内的交易记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="startDate">开始日期</param>
|
|
|
|
|
|
/// <param name="endDate">结束日期</param>
|
|
|
|
|
|
/// <returns>交易记录列表</returns>
|
|
|
|
|
|
Task<List<TransactionRecord>> GetByDateRangeAsync(DateTime startDate, DateTime endDate);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定邮件的交易记录数量
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="emailMessageId">邮件ID</param>
|
|
|
|
|
|
/// <returns>交易记录数量</returns>
|
|
|
|
|
|
Task<int> GetCountByEmailIdAsync(long emailMessageId);
|
|
|
|
|
|
|
2025-12-26 17:13:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取月度统计数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="year">年份</param>
|
|
|
|
|
|
/// <param name="month">月份</param>
|
|
|
|
|
|
/// <returns>月度统计数据</returns>
|
|
|
|
|
|
Task<MonthlyStatistics> GetMonthlyStatisticsAsync(int year, int month);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取分类统计数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="year">年份</param>
|
|
|
|
|
|
/// <param name="month">月份</param>
|
|
|
|
|
|
/// <param name="type">交易类型(0:支出, 1:收入)</param>
|
|
|
|
|
|
/// <returns>分类统计列表</returns>
|
|
|
|
|
|
Task<List<CategoryStatistics>> GetCategoryStatisticsAsync(int year, int month, TransactionType type);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取多个月的趋势统计数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="startYear">开始年份</param>
|
|
|
|
|
|
/// <param name="startMonth">开始月份</param>
|
|
|
|
|
|
/// <param name="monthCount">月份数量</param>
|
|
|
|
|
|
/// <returns>趋势统计列表</returns>
|
|
|
|
|
|
Task<List<TrendStatistics>> GetTrendStatisticsAsync(int startYear, int startMonth, int monthCount);
|
|
|
|
|
|
|
2025-12-25 11:20:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定邮件的交易记录列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="emailMessageId">邮件ID</param>
|
|
|
|
|
|
/// <returns>交易记录列表</returns>
|
|
|
|
|
|
Task<List<TransactionRecord>> GetByEmailIdAsync(long emailMessageId);
|
2025-12-25 15:40:50 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取未分类的账单数量
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>未分类账单数量</returns>
|
|
|
|
|
|
Task<int> GetUnclassifiedCountAsync();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取未分类的账单列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="pageSize">每页数量</param>
|
|
|
|
|
|
/// <returns>未分类账单列表</returns>
|
|
|
|
|
|
Task<List<TransactionRecord>> GetUnclassifiedAsync(int pageSize = 10);
|
2025-12-26 15:21:31 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取按交易摘要(Reason)分组的统计信息(支持分页)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="pageIndex">页码,从1开始</param>
|
|
|
|
|
|
/// <param name="pageSize">每页数量</param>
|
|
|
|
|
|
/// <returns>分组统计列表和总数</returns>
|
|
|
|
|
|
Task<(List<ReasonGroupDto> list, int total)> GetReasonGroupsAsync(int pageIndex = 1, int pageSize = 20);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 按摘要批量更新交易记录的分类
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reason">交易摘要</param>
|
|
|
|
|
|
/// <param name="type">交易类型</param>
|
|
|
|
|
|
/// <param name="classify">分类名称</param>
|
|
|
|
|
|
/// <returns>更新的记录数量</returns>
|
|
|
|
|
|
Task<int> BatchUpdateByReasonAsync(string reason, TransactionType type, string classify);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据关键词查询交易记录(模糊匹配Reason字段)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="keyword">关键词</param>
|
|
|
|
|
|
/// <returns>匹配的交易记录列表</returns>
|
2025-12-26 17:13:57 +08:00
|
|
|
|
Task<List<TransactionRecord>> QueryByWhereAsync(string sql);
|
2025-12-27 11:50:12 +08:00
|
|
|
|
|
2025-12-26 17:13:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 执行完整的SQL查询
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="completeSql">完整的SELECT SQL语句</param>
|
|
|
|
|
|
/// <returns>查询结果列表</returns>
|
|
|
|
|
|
Task<List<TransactionRecord>> ExecuteRawSqlAsync(string completeSql);
|
|
|
|
|
|
|
2025-12-29 20:30:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据关键词查询已分类的账单(用于智能分类参考)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="keywords">关键词列表</param>
|
|
|
|
|
|
/// <param name="limit">返回结果数量限制</param>
|
|
|
|
|
|
/// <returns>已分类的账单列表</returns>
|
|
|
|
|
|
Task<List<TransactionRecord>> GetClassifiedByKeywordsAsync(List<string> keywords, int limit = 10);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据关键词查询已分类的账单,并计算相关度分数
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="keywords">关键词列表</param>
|
|
|
|
|
|
/// <param name="minMatchRate">最小匹配率(0.0-1.0),默认0.3表示至少匹配30%的关键词</param>
|
|
|
|
|
|
/// <param name="limit">返回结果数量限制</param>
|
|
|
|
|
|
/// <returns>带相关度分数的已分类账单列表</returns>
|
|
|
|
|
|
Task<List<(TransactionRecord record, double relevanceScore)>> GetClassifiedByKeywordsWithScoreAsync(List<string> keywords, double minMatchRate = 0.3, int limit = 10);
|
2026-01-01 14:43:43 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取抵账候选列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="currentId">当前交易ID</param>
|
|
|
|
|
|
/// <param name="amount">当前交易金额</param>
|
|
|
|
|
|
/// <param name="currentType">当前交易类型</param>
|
|
|
|
|
|
/// <returns>候选交易列表</returns>
|
|
|
|
|
|
Task<List<TransactionRecord>> GetCandidatesForOffsetAsync(long currentId, decimal amount, TransactionType currentType);
|
2026-01-01 15:20:59 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新分类名称
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="oldName">旧分类名称</param>
|
|
|
|
|
|
/// <param name="newName">新分类名称</param>
|
|
|
|
|
|
/// <param name="type">交易类型</param>
|
|
|
|
|
|
/// <returns>影响行数</returns>
|
|
|
|
|
|
Task<int> UpdateCategoryNameAsync(string oldName, string newName, TransactionType type);
|
2025-12-25 11:20:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<TransactionRecord>(freeSql), ITransactionRecordRepository
|
|
|
|
|
|
{
|
|
|
|
|
|
public async Task<TransactionRecord?> ExistsByEmailMessageIdAsync(long emailMessageId, DateTime occurredAt)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.EmailMessageId == emailMessageId && t.OccurredAt == occurredAt)
|
|
|
|
|
|
.FirstAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<TransactionRecord?> ExistsByImportNoAsync(string importNo, string importFrom)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.ImportNo == importNo && t.ImportFrom == importFrom)
|
|
|
|
|
|
.FirstAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-27 22:05:50 +08:00
|
|
|
|
public async Task<List<TransactionRecord>> GetPagedListAsync(
|
|
|
|
|
|
int pageIndex = 1,
|
2025-12-27 11:50:12 +08:00
|
|
|
|
int pageSize = 20,
|
2025-12-26 17:56:08 +08:00
|
|
|
|
string? searchKeyword = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
string[]? classifies = null,
|
2025-12-26 17:56:08 +08:00
|
|
|
|
TransactionType? type = null,
|
|
|
|
|
|
int? year = null,
|
2025-12-27 22:05:50 +08:00
|
|
|
|
int? month = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
DateTime? startDate = null,
|
|
|
|
|
|
DateTime? endDate = null,
|
2025-12-30 17:02:30 +08:00
|
|
|
|
string? reason = null,
|
2025-12-27 22:05:50 +08:00
|
|
|
|
bool sortByAmount = false)
|
2025-12-25 11:20:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
var query = FreeSql.Select<TransactionRecord>();
|
|
|
|
|
|
|
|
|
|
|
|
// 如果提供了搜索关键词,则添加搜索条件
|
2025-12-27 11:50:12 +08:00
|
|
|
|
query = query.WhereIf(!string.IsNullOrWhiteSpace(searchKeyword),
|
|
|
|
|
|
t => t.Reason.Contains(searchKeyword!) ||
|
|
|
|
|
|
t.Classify.Contains(searchKeyword!) ||
|
|
|
|
|
|
t.Card.Contains(searchKeyword!) ||
|
2025-12-30 17:02:30 +08:00
|
|
|
|
t.ImportFrom.Contains(searchKeyword!))
|
|
|
|
|
|
.WhereIf(!string.IsNullOrWhiteSpace(reason),
|
|
|
|
|
|
t => t.Reason == reason);
|
2025-12-25 11:20:56 +08:00
|
|
|
|
|
2025-12-26 17:56:08 +08:00
|
|
|
|
// 按分类筛选
|
2026-01-09 16:21:03 +08:00
|
|
|
|
if (classifies != null && classifies.Length > 0)
|
2025-12-26 17:56:08 +08:00
|
|
|
|
{
|
2026-01-09 16:21:03 +08:00
|
|
|
|
var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList();
|
|
|
|
|
|
query = query.Where(t => filterClassifies.Contains(t.Classify));
|
2025-12-26 17:56:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 按交易类型筛选
|
2025-12-27 11:50:12 +08:00
|
|
|
|
query = query.WhereIf(type.HasValue, t => t.Type == type!.Value);
|
2025-12-26 17:56:08 +08:00
|
|
|
|
|
|
|
|
|
|
// 按年月筛选
|
|
|
|
|
|
if (year.HasValue && month.HasValue)
|
|
|
|
|
|
{
|
2026-01-09 16:21:03 +08:00
|
|
|
|
var dateStart = new DateTime(year.Value, month.Value, 1);
|
|
|
|
|
|
var dateEnd = dateStart.AddMonths(1);
|
|
|
|
|
|
query = query.Where(t => t.OccurredAt >= dateStart && t.OccurredAt < dateEnd);
|
2025-12-26 17:56:08 +08:00
|
|
|
|
}
|
2026-01-09 16:21:03 +08:00
|
|
|
|
|
|
|
|
|
|
// 按日期范围筛选
|
|
|
|
|
|
query = query.WhereIf(startDate.HasValue, t => t.OccurredAt >= startDate!.Value)
|
|
|
|
|
|
.WhereIf(endDate.HasValue, t => t.OccurredAt <= endDate!.Value);
|
2025-12-26 17:56:08 +08:00
|
|
|
|
|
2025-12-27 22:05:50 +08:00
|
|
|
|
// 根据sortByAmount参数决定排序方式
|
|
|
|
|
|
if (sortByAmount)
|
2025-12-25 11:20:56 +08:00
|
|
|
|
{
|
2025-12-27 22:05:50 +08:00
|
|
|
|
// 按金额降序排列
|
|
|
|
|
|
return await query
|
|
|
|
|
|
.OrderByDescending(t => t.Amount)
|
|
|
|
|
|
.OrderByDescending(t => t.Id)
|
|
|
|
|
|
.Page(pageIndex, pageSize)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 按时间降序排列
|
|
|
|
|
|
return await query
|
|
|
|
|
|
.OrderByDescending(t => t.OccurredAt)
|
|
|
|
|
|
.OrderByDescending(t => t.Id)
|
|
|
|
|
|
.Page(pageIndex, pageSize)
|
|
|
|
|
|
.ToListAsync();
|
2025-12-25 11:20:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-27 22:05:50 +08:00
|
|
|
|
public async Task<long> GetTotalCountAsync(
|
|
|
|
|
|
string? searchKeyword = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
string[]? classifies = null,
|
2025-12-27 22:05:50 +08:00
|
|
|
|
TransactionType? type = null,
|
|
|
|
|
|
int? year = null,
|
2025-12-30 17:02:30 +08:00
|
|
|
|
int? month = null,
|
2026-01-09 16:21:03 +08:00
|
|
|
|
DateTime? startDate = null,
|
|
|
|
|
|
DateTime? endDate = null,
|
2025-12-30 17:02:30 +08:00
|
|
|
|
string? reason = null)
|
2025-12-25 11:20:56 +08:00
|
|
|
|
{
|
2025-12-27 22:05:50 +08:00
|
|
|
|
var query = FreeSql.Select<TransactionRecord>();
|
|
|
|
|
|
|
|
|
|
|
|
// 如果提供了搜索关键词,则添加搜索条件
|
|
|
|
|
|
query = query.WhereIf(!string.IsNullOrWhiteSpace(searchKeyword),
|
|
|
|
|
|
t => t.Reason.Contains(searchKeyword!) ||
|
|
|
|
|
|
t.Classify.Contains(searchKeyword!) ||
|
|
|
|
|
|
t.Card.Contains(searchKeyword!) ||
|
2025-12-30 17:02:30 +08:00
|
|
|
|
t.ImportFrom.Contains(searchKeyword!))
|
|
|
|
|
|
.WhereIf(!string.IsNullOrWhiteSpace(reason),
|
|
|
|
|
|
t => t.Reason == reason);
|
2025-12-27 22:05:50 +08:00
|
|
|
|
|
|
|
|
|
|
// 按分类筛选
|
2026-01-09 16:21:03 +08:00
|
|
|
|
if (classifies != null && classifies.Length > 0)
|
2025-12-27 22:05:50 +08:00
|
|
|
|
{
|
2026-01-09 16:21:03 +08:00
|
|
|
|
var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList();
|
|
|
|
|
|
query = query.Where(t => filterClassifies.Contains(t.Classify));
|
2025-12-27 22:05:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 按交易类型筛选
|
|
|
|
|
|
query = query.WhereIf(type.HasValue, t => t.Type == type!.Value);
|
|
|
|
|
|
|
|
|
|
|
|
// 按年月筛选
|
|
|
|
|
|
if (year.HasValue && month.HasValue)
|
|
|
|
|
|
{
|
2026-01-09 16:21:03 +08:00
|
|
|
|
var dateStart = new DateTime(year.Value, month.Value, 1);
|
|
|
|
|
|
var dateEnd = dateStart.AddMonths(1);
|
|
|
|
|
|
query = query.Where(t => t.OccurredAt >= dateStart && t.OccurredAt < dateEnd);
|
2025-12-27 22:05:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-09 16:21:03 +08:00
|
|
|
|
// 按日期范围筛选
|
|
|
|
|
|
query = query.WhereIf(startDate.HasValue, t => t.OccurredAt >= startDate!.Value)
|
|
|
|
|
|
.WhereIf(endDate.HasValue, t => t.OccurredAt <= endDate!.Value);
|
|
|
|
|
|
|
2025-12-27 22:05:50 +08:00
|
|
|
|
return await query.CountAsync();
|
2025-12-25 11:20:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<string>> GetDistinctClassifyAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => !string.IsNullOrEmpty(t.Classify))
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToListAsync(t => t.Classify);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<Dictionary<string, (int count, decimal amount)>> GetDailyStatisticsAsync(int year, int month)
|
|
|
|
|
|
{
|
|
|
|
|
|
var startDate = new DateTime(year, month, 1);
|
|
|
|
|
|
var endDate = startDate.AddMonths(1);
|
|
|
|
|
|
|
|
|
|
|
|
var records = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var statistics = records
|
|
|
|
|
|
.GroupBy(t => t.OccurredAt.ToString("yyyy-MM-dd"))
|
|
|
|
|
|
.ToDictionary(
|
|
|
|
|
|
g => g.Key,
|
|
|
|
|
|
g =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// 分别统计收入和支出
|
|
|
|
|
|
var income = g.Where(t => t.Type == TransactionType.Income).Sum(t => t.Amount);
|
|
|
|
|
|
var expense = g.Where(t => t.Type == TransactionType.Expense).Sum(t => t.Amount);
|
|
|
|
|
|
// 净额 = 收入 - 支出(消费大于收入时为负数)
|
|
|
|
|
|
var netAmount = income - expense;
|
|
|
|
|
|
return (count: g.Count(), amount: netAmount);
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return statistics;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<TransactionRecord>> GetByDateRangeAsync(DateTime startDate, DateTime endDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.OccurredAt >= startDate && t.OccurredAt <= endDate)
|
|
|
|
|
|
.OrderBy(t => t.OccurredAt)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> GetCountByEmailIdAsync(long emailMessageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (int)await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.EmailMessageId == emailMessageId)
|
|
|
|
|
|
.CountAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<TransactionRecord>> GetByEmailIdAsync(long emailMessageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.EmailMessageId == emailMessageId)
|
|
|
|
|
|
.OrderBy(t => t.OccurredAt)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
2025-12-25 15:40:50 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task<int> GetUnclassifiedCountAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
return (int)await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.Classify))
|
|
|
|
|
|
.CountAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<TransactionRecord>> GetUnclassifiedAsync(int pageSize = 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.Classify))
|
|
|
|
|
|
.OrderByDescending(t => t.OccurredAt)
|
|
|
|
|
|
.Page(1, pageSize)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
2025-12-26 15:21:31 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task<(List<ReasonGroupDto> list, int total)> GetReasonGroupsAsync(int pageIndex = 1, int pageSize = 20)
|
|
|
|
|
|
{
|
2025-12-29 20:30:15 +08:00
|
|
|
|
// 先按照Reason分组,统计每个Reason的数量和总金额
|
2025-12-26 15:21:31 +08:00
|
|
|
|
var groups = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => !string.IsNullOrEmpty(t.Reason))
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.Classify)) // 只统计未分类的
|
|
|
|
|
|
.GroupBy(t => t.Reason)
|
|
|
|
|
|
.ToListAsync(g => new
|
|
|
|
|
|
{
|
|
|
|
|
|
Reason = g.Key,
|
2025-12-29 20:30:15 +08:00
|
|
|
|
Count = g.Count(),
|
|
|
|
|
|
TotalAmount = g.Sum(g.Value.Amount)
|
2025-12-26 15:21:31 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-29 20:30:15 +08:00
|
|
|
|
// 按总金额绝对值降序排序
|
|
|
|
|
|
var sortedGroups = groups.OrderByDescending(g => Math.Abs(g.TotalAmount)).ToList();
|
2025-12-26 15:21:31 +08:00
|
|
|
|
var total = sortedGroups.Count;
|
|
|
|
|
|
|
|
|
|
|
|
// 分页
|
|
|
|
|
|
var pagedGroups = sortedGroups
|
|
|
|
|
|
.Skip((pageIndex - 1) * pageSize)
|
|
|
|
|
|
.Take(pageSize)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
2025-12-29 20:30:15 +08:00
|
|
|
|
// 为每个分组获取详细信息
|
2025-12-26 15:21:31 +08:00
|
|
|
|
var result = new List<ReasonGroupDto>();
|
|
|
|
|
|
foreach (var group in pagedGroups)
|
|
|
|
|
|
{
|
2025-12-29 20:30:15 +08:00
|
|
|
|
// 获取该分组的所有记录
|
|
|
|
|
|
var records = await FreeSql.Select<TransactionRecord>()
|
2025-12-26 15:21:31 +08:00
|
|
|
|
.Where(t => t.Reason == group.Reason)
|
2025-12-29 20:30:15 +08:00
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.Classify))
|
|
|
|
|
|
.ToListAsync();
|
2025-12-26 15:21:31 +08:00
|
|
|
|
|
2025-12-29 20:30:15 +08:00
|
|
|
|
if (records.Count > 0)
|
2025-12-26 15:21:31 +08:00
|
|
|
|
{
|
2025-12-29 20:30:15 +08:00
|
|
|
|
var sample = records.First();
|
2025-12-26 15:21:31 +08:00
|
|
|
|
result.Add(new ReasonGroupDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Reason = group.Reason,
|
|
|
|
|
|
Count = (int)group.Count,
|
|
|
|
|
|
SampleType = sample.Type,
|
2025-12-29 20:30:15 +08:00
|
|
|
|
SampleClassify = sample.Classify ?? string.Empty,
|
|
|
|
|
|
TransactionIds = records.Select(r => r.Id).ToList(),
|
|
|
|
|
|
TotalAmount = Math.Abs(group.TotalAmount)
|
2025-12-26 15:21:31 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (result, total);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> BatchUpdateByReasonAsync(string reason, TransactionType type, string classify)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Update<TransactionRecord>()
|
|
|
|
|
|
.Set(t => t.Type, type)
|
|
|
|
|
|
.Set(t => t.Classify, classify)
|
|
|
|
|
|
.Where(t => t.Reason == reason)
|
|
|
|
|
|
.ExecuteAffrowsAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-26 17:13:57 +08:00
|
|
|
|
public async Task<List<TransactionRecord>> QueryByWhereAsync(string sql)
|
2025-12-26 15:21:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(sql)
|
|
|
|
|
|
.OrderByDescending(t => t.OccurredAt)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
2025-12-26 17:13:57 +08:00
|
|
|
|
public async Task<List<TransactionRecord>> ExecuteRawSqlAsync(string completeSql)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Ado.QueryAsync<TransactionRecord>(completeSql);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<MonthlyStatistics> GetMonthlyStatisticsAsync(int year, int month)
|
|
|
|
|
|
{
|
|
|
|
|
|
var startDate = new DateTime(year, month, 1);
|
|
|
|
|
|
var endDate = startDate.AddMonths(1);
|
|
|
|
|
|
|
|
|
|
|
|
var records = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var statistics = new MonthlyStatistics
|
|
|
|
|
|
{
|
|
|
|
|
|
Year = year,
|
|
|
|
|
|
Month = month
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var record in records)
|
|
|
|
|
|
{
|
|
|
|
|
|
var amount = Math.Abs(record.Amount);
|
2025-12-27 11:50:12 +08:00
|
|
|
|
|
2025-12-26 17:13:57 +08:00
|
|
|
|
if (record.Type == TransactionType.Expense)
|
|
|
|
|
|
{
|
|
|
|
|
|
statistics.TotalExpense += amount;
|
|
|
|
|
|
statistics.ExpenseCount++;
|
|
|
|
|
|
if (amount > statistics.MaxExpense)
|
|
|
|
|
|
{
|
|
|
|
|
|
statistics.MaxExpense = amount;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (record.Type == TransactionType.Income)
|
|
|
|
|
|
{
|
|
|
|
|
|
statistics.TotalIncome += amount;
|
|
|
|
|
|
statistics.IncomeCount++;
|
|
|
|
|
|
if (amount > statistics.MaxIncome)
|
|
|
|
|
|
{
|
|
|
|
|
|
statistics.MaxIncome = amount;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
statistics.Balance = statistics.TotalIncome - statistics.TotalExpense;
|
|
|
|
|
|
statistics.TotalCount = records.Count;
|
|
|
|
|
|
|
|
|
|
|
|
return statistics;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<CategoryStatistics>> GetCategoryStatisticsAsync(int year, int month, TransactionType type)
|
|
|
|
|
|
{
|
|
|
|
|
|
var startDate = new DateTime(year, month, 1);
|
|
|
|
|
|
var endDate = startDate.AddMonths(1);
|
|
|
|
|
|
|
|
|
|
|
|
var records = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate && t.Type == type)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var categoryGroups = records
|
|
|
|
|
|
.GroupBy(t => t.Classify ?? "未分类")
|
|
|
|
|
|
.Select(g => new CategoryStatistics
|
|
|
|
|
|
{
|
|
|
|
|
|
Classify = g.Key,
|
|
|
|
|
|
Amount = g.Sum(t => Math.Abs(t.Amount)),
|
|
|
|
|
|
Count = g.Count()
|
|
|
|
|
|
})
|
|
|
|
|
|
.OrderByDescending(c => c.Amount)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// 计算百分比
|
|
|
|
|
|
var total = categoryGroups.Sum(c => c.Amount);
|
|
|
|
|
|
if (total > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var category in categoryGroups)
|
|
|
|
|
|
{
|
|
|
|
|
|
category.Percent = Math.Round((category.Amount / total) * 100, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return categoryGroups;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<TrendStatistics>> GetTrendStatisticsAsync(int startYear, int startMonth, int monthCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
var trends = new List<TrendStatistics>();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < monthCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var targetYear = startYear;
|
|
|
|
|
|
var targetMonth = startMonth + i;
|
|
|
|
|
|
|
|
|
|
|
|
// 处理月份溢出
|
|
|
|
|
|
while (targetMonth > 12)
|
|
|
|
|
|
{
|
|
|
|
|
|
targetMonth -= 12;
|
|
|
|
|
|
targetYear++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var startDate = new DateTime(targetYear, targetMonth, 1);
|
|
|
|
|
|
var endDate = startDate.AddMonths(1);
|
|
|
|
|
|
|
|
|
|
|
|
var records = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var expense = records.Where(t => t.Type == TransactionType.Expense).Sum(t => Math.Abs(t.Amount));
|
|
|
|
|
|
var income = records.Where(t => t.Type == TransactionType.Income).Sum(t => Math.Abs(t.Amount));
|
|
|
|
|
|
|
|
|
|
|
|
trends.Add(new TrendStatistics
|
|
|
|
|
|
{
|
|
|
|
|
|
Year = targetYear,
|
|
|
|
|
|
Month = targetMonth,
|
|
|
|
|
|
Expense = expense,
|
|
|
|
|
|
Income = income,
|
|
|
|
|
|
Balance = income - expense
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return trends;
|
|
|
|
|
|
}
|
2025-12-29 20:30:15 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task<List<TransactionRecord>> GetClassifiedByKeywordsAsync(List<string> keywords, int limit = 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (keywords == null || keywords.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new List<TransactionRecord>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var query = FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.Classify != ""); // 只查询已分类的账单
|
|
|
|
|
|
|
|
|
|
|
|
// 构建OR条件:Reason包含任意一个关键词
|
|
|
|
|
|
if (keywords.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
query = query.Where(t => keywords.Any(keyword => t.Reason.Contains(keyword)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await query
|
|
|
|
|
|
.OrderByDescending(t => t.OccurredAt)
|
|
|
|
|
|
.Limit(limit)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<(TransactionRecord record, double relevanceScore)>> GetClassifiedByKeywordsWithScoreAsync(List<string> keywords, double minMatchRate = 0.3, int limit = 10)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (keywords == null || keywords.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new List<(TransactionRecord, double)>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查询所有已分类且包含任意关键词的账单
|
|
|
|
|
|
var candidates = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.Classify != "")
|
|
|
|
|
|
.Where(t => keywords.Any(keyword => t.Reason.Contains(keyword)))
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// 计算每个候选账单的相关度分数
|
|
|
|
|
|
var scoredResults = candidates
|
|
|
|
|
|
.Select(record =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var matchedCount = keywords.Count(keyword => record.Reason.Contains(keyword, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
var matchRate = (double)matchedCount / keywords.Count;
|
|
|
|
|
|
|
|
|
|
|
|
// 额外加分:完全匹配整个摘要(相似度更高)
|
|
|
|
|
|
var exactMatchBonus = keywords.Any(k => record.Reason.Equals(k, StringComparison.OrdinalIgnoreCase)) ? 0.2 : 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
// 长度相似度加分:长度越接近,相关度越高
|
|
|
|
|
|
var avgKeywordLength = keywords.Average(k => k.Length);
|
|
|
|
|
|
var lengthSimilarity = 1.0 - Math.Min(1.0, Math.Abs(record.Reason.Length - avgKeywordLength) / Math.Max(record.Reason.Length, avgKeywordLength));
|
|
|
|
|
|
var lengthBonus = lengthSimilarity * 0.1;
|
|
|
|
|
|
|
|
|
|
|
|
var score = matchRate + exactMatchBonus + lengthBonus;
|
|
|
|
|
|
return (record, score);
|
|
|
|
|
|
})
|
|
|
|
|
|
.Where(x => x.score >= minMatchRate) // 过滤低相关度结果
|
|
|
|
|
|
.OrderByDescending(x => x.score) // 按相关度降序
|
|
|
|
|
|
.ThenByDescending(x => x.record.OccurredAt) // 相同分数时,按时间降序
|
|
|
|
|
|
.Take(limit)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return scoredResults;
|
|
|
|
|
|
}
|
2026-01-01 14:43:43 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task<List<TransactionRecord>> GetCandidatesForOffsetAsync(long currentId, decimal amount, TransactionType currentType)
|
|
|
|
|
|
{
|
|
|
|
|
|
var absAmount = Math.Abs(amount);
|
|
|
|
|
|
var minAmount = absAmount - 5;
|
|
|
|
|
|
var maxAmount = absAmount + 5;
|
|
|
|
|
|
|
2026-01-02 18:51:28 +08:00
|
|
|
|
var currentRecord = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.Id == currentId)
|
|
|
|
|
|
.FirstAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (currentRecord == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new List<TransactionRecord>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-01 14:43:43 +08:00
|
|
|
|
var list = await FreeSql.Select<TransactionRecord>()
|
|
|
|
|
|
.Where(t => t.Id != currentId)
|
|
|
|
|
|
.Where(t => t.Type != currentType)
|
|
|
|
|
|
.Where(t => Math.Abs(t.Amount) >= minAmount && Math.Abs(t.Amount) <= maxAmount)
|
|
|
|
|
|
.Take(50)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
2026-01-02 18:51:28 +08:00
|
|
|
|
return list.OrderBy(t => Math.Abs(Math.Abs(t.Amount) - absAmount))
|
|
|
|
|
|
.ThenBy(x=> Math.Abs((x.OccurredAt - currentRecord.OccurredAt).TotalSeconds))
|
|
|
|
|
|
.ToList();
|
2026-01-01 14:43:43 +08:00
|
|
|
|
}
|
2026-01-01 15:20:59 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task<int> UpdateCategoryNameAsync(string oldName, string newName, TransactionType type)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await FreeSql.Update<TransactionRecord>()
|
|
|
|
|
|
.Set(a => a.Classify, newName)
|
|
|
|
|
|
.Where(a => a.Classify == oldName && a.Type == type)
|
|
|
|
|
|
.ExecuteAffrowsAsync();
|
|
|
|
|
|
}
|
2025-12-26 15:21:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 按Reason分组统计DTO
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ReasonGroupDto
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 交易摘要
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Reason { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 该摘要的记录数量
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int Count { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 示例交易类型(该分组中第一条记录的类型)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public TransactionType SampleType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 示例分类(该分组中第一条记录的分类)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string SampleClassify { get; set; } = string.Empty;
|
2025-12-29 20:30:15 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 该分组的所有账单ID列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public List<long> TransactionIds { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 该分组的总金额(绝对值)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public decimal TotalAmount { get; set; }
|
2025-12-26 17:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 月度统计数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class MonthlyStatistics
|
|
|
|
|
|
{
|
|
|
|
|
|
public int Year { get; set; }
|
|
|
|
|
|
public int Month { get; set; }
|
|
|
|
|
|
public decimal TotalExpense { get; set; }
|
|
|
|
|
|
public decimal TotalIncome { get; set; }
|
|
|
|
|
|
public decimal Balance { get; set; }
|
|
|
|
|
|
public int ExpenseCount { get; set; }
|
|
|
|
|
|
public int IncomeCount { get; set; }
|
|
|
|
|
|
public int TotalCount { get; set; }
|
|
|
|
|
|
public decimal MaxExpense { get; set; }
|
|
|
|
|
|
public decimal MaxIncome { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分类统计数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class CategoryStatistics
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Classify { get; set; } = string.Empty;
|
|
|
|
|
|
public decimal Amount { get; set; }
|
|
|
|
|
|
public int Count { get; set; }
|
|
|
|
|
|
public decimal Percent { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 趋势统计数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class TrendStatistics
|
|
|
|
|
|
{
|
|
|
|
|
|
public int Year { get; set; }
|
|
|
|
|
|
public int Month { get; set; }
|
|
|
|
|
|
public decimal Expense { get; set; }
|
|
|
|
|
|
public decimal Income { get; set; }
|
|
|
|
|
|
public decimal Balance { get; set; }
|
2025-12-25 11:20:56 +08:00
|
|
|
|
}
|