大量后端代码格式化
This commit is contained in:
@@ -170,10 +170,10 @@ public abstract class BaseRepository<T>(IFreeSql freeSql) : IBaseRepository<T> w
|
||||
var dt = await FreeSql.Ado.ExecuteDataTableAsync(completeSql);
|
||||
var result = new List<dynamic>();
|
||||
|
||||
foreach (System.Data.DataRow row in dt.Rows)
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
var expando = new System.Dynamic.ExpandoObject() as IDictionary<string, object>;
|
||||
foreach (System.Data.DataColumn column in dt.Columns)
|
||||
var expando = new ExpandoObject() as IDictionary<string, object>;
|
||||
foreach (DataColumn column in dt.Columns)
|
||||
{
|
||||
expando[column.ColumnName] = row[column];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
global using Entity;
|
||||
global using FreeSql;
|
||||
global using System.Linq;
|
||||
global using System.Data;
|
||||
global using System.Dynamic;
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
t => t.Reason == reason);
|
||||
|
||||
// 按分类筛选
|
||||
if (classifies != null && classifies.Length > 0)
|
||||
if (classifies is { Length: > 0 })
|
||||
{
|
||||
var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList();
|
||||
query = query.Where(t => filterClassifies.Contains(t.Classify));
|
||||
@@ -290,15 +290,13 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
.Page(pageIndex, pageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 按时间降序排列
|
||||
return await query
|
||||
.OrderByDescending(t => t.OccurredAt)
|
||||
.OrderByDescending(t => t.Id)
|
||||
.Page(pageIndex, pageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
// 按时间降序排列
|
||||
return await query
|
||||
.OrderByDescending(t => t.OccurredAt)
|
||||
.OrderByDescending(t => t.Id)
|
||||
.Page(pageIndex, pageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<long> GetTotalCountAsync(
|
||||
@@ -323,7 +321,7 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
t => t.Reason == reason);
|
||||
|
||||
// 按分类筛选
|
||||
if (classifies != null && classifies.Length > 0)
|
||||
if (classifies is { Length: > 0 })
|
||||
{
|
||||
var filterClassifies = classifies.Select(c => c == "未分类" ? string.Empty : c).ToList();
|
||||
query = query.Where(t => filterClassifies.Contains(t.Classify));
|
||||
@@ -471,7 +469,7 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
result.Add(new ReasonGroupDto
|
||||
{
|
||||
Reason = group.Reason,
|
||||
Count = (int)group.Count,
|
||||
Count = group.Count,
|
||||
SampleType = sample.Type,
|
||||
SampleClassify = sample.Classify ?? string.Empty,
|
||||
TransactionIds = records.Select(r => r.Id).ToList(),
|
||||
@@ -615,9 +613,9 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
|
||||
public async Task<List<TransactionRecord>> GetClassifiedByKeywordsAsync(List<string> keywords, int limit = 10)
|
||||
{
|
||||
if (keywords == null || keywords.Count == 0)
|
||||
if (keywords.Count == 0)
|
||||
{
|
||||
return new List<TransactionRecord>();
|
||||
return [];
|
||||
}
|
||||
|
||||
var query = FreeSql.Select<TransactionRecord>()
|
||||
@@ -637,9 +635,9 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
|
||||
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)
|
||||
if (keywords.Count == 0)
|
||||
{
|
||||
return new List<(TransactionRecord, double)>();
|
||||
return [];
|
||||
}
|
||||
|
||||
// 查询所有已分类且包含任意关键词的账单
|
||||
@@ -687,7 +685,7 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
|
||||
if (currentRecord == null)
|
||||
{
|
||||
return new List<TransactionRecord>();
|
||||
return [];
|
||||
}
|
||||
|
||||
var list = await FreeSql.Select<TransactionRecord>()
|
||||
@@ -740,7 +738,7 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
var query = FreeSql.Select<TransactionRecord>()
|
||||
.Where(t => t.OccurredAt >= startDate && t.OccurredAt <= endDate && t.Type == type);
|
||||
|
||||
if (classifies != null && classifies.Any())
|
||||
if (classifies.Any())
|
||||
{
|
||||
query = query.Where(t => classifies.Contains(t.Classify));
|
||||
}
|
||||
@@ -753,12 +751,10 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository<Tran
|
||||
.GroupBy(t => new DateTime(t.OccurredAt.Year, t.OccurredAt.Month, 1))
|
||||
.ToDictionary(g => g.Key, g => g.Sum(x => Math.Abs(x.Amount)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return list
|
||||
.GroupBy(t => t.OccurredAt.Date)
|
||||
.ToDictionary(g => g.Key, g => g.Sum(x => Math.Abs(x.Amount)));
|
||||
}
|
||||
|
||||
return list
|
||||
.GroupBy(t => t.OccurredAt.Date)
|
||||
.ToDictionary(g => g.Key, g => g.Sum(x => Math.Abs(x.Amount)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,7 +786,7 @@ public class ReasonGroupDto
|
||||
/// <summary>
|
||||
/// 该分组的所有账单ID列表
|
||||
/// </summary>
|
||||
public List<long> TransactionIds { get; set; } = new();
|
||||
public List<long> TransactionIds { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 该分组的总金额(绝对值)
|
||||
@@ -804,12 +800,19 @@ public class ReasonGroupDto
|
||||
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; }
|
||||
}
|
||||
|
||||
@@ -819,8 +822,11 @@ public class MonthlyStatistics
|
||||
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; }
|
||||
}
|
||||
|
||||
@@ -830,8 +836,12 @@ public class CategoryStatistics
|
||||
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; }
|
||||
}
|
||||
Reference in New Issue
Block a user