更新预算归档功能,添加归档总结和更新归档总结接口,优化预算统计逻辑,调整相关样式
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 34s
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 1s
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 34s
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 1s
This commit is contained in:
@@ -11,7 +11,7 @@ public class BudgetController(
|
||||
/// 获取预算列表
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<List<BudgetResult>>> GetListAsync([FromQuery] DateTime? referenceDate = null)
|
||||
public async Task<BaseResponse<List<BudgetResult>>> GetListAsync([FromQuery] DateTime referenceDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -30,41 +30,11 @@ public class BudgetController(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取单个预算统计信息
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<BudgetResult>> GetStatisticsAsync([FromQuery] long id, [FromQuery] DateTime referenceDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 参数验证
|
||||
if (id == 0)
|
||||
{
|
||||
return "预算 Id 无效".Fail<BudgetResult>();
|
||||
}
|
||||
|
||||
var result = await budgetService.GetStatisticsAsync(id, referenceDate);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return "预算不存在".Fail<BudgetResult>();
|
||||
}
|
||||
|
||||
return result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取预算统计失败, Id: {Id}", id);
|
||||
return $"获取预算统计失败: {ex.Message}".Fail<BudgetResult>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分类统计信息(月度和年度)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<BudgetCategoryStats>> GetCategoryStatsAsync([FromQuery] BudgetCategory category, [FromQuery] DateTime? referenceDate = null)
|
||||
public async Task<BaseResponse<BudgetCategoryStats>> GetCategoryStatsAsync([FromQuery] BudgetCategory category, [FromQuery] DateTime referenceDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -96,6 +66,42 @@ public class BudgetController(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取归档总结
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<string?>> GetArchiveSummaryAsync([FromQuery] DateTime referenceDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await budgetService.GetArchiveSummaryAsync(referenceDate.Year, referenceDate.Month);
|
||||
return result.Ok<string?>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取归档总结失败");
|
||||
return $"获取归档总结失败: {ex.Message}".Fail<string?>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新归档总结
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse> UpdateArchiveSummaryAsync([FromBody] UpdateArchiveSummaryDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
await budgetService.UpdateArchiveSummaryAsync(dto.ReferenceDate.Year, dto.ReferenceDate.Month, dto.Summary);
|
||||
return BaseResponse.Done();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "更新归档总结失败");
|
||||
return $"更新归档总结失败: {ex.Message}".Fail();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除预算
|
||||
/// </summary>
|
||||
@@ -189,30 +195,6 @@ public class BudgetController(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 归档预算
|
||||
/// </summary>
|
||||
[HttpPost("{year}/{month}")]
|
||||
public async Task<BaseResponse> ArchiveBudgetsAsync(int year, int month)
|
||||
{
|
||||
try
|
||||
{
|
||||
var msg = await budgetService.ArchiveBudgetsAsync(year, month);
|
||||
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
return msg.Fail();
|
||||
}
|
||||
|
||||
return BaseResponse.Done();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "归档预算失败, 归档日期: {Year}-{Month}", year, month);
|
||||
return $"归档预算失败: {ex.Message}".Fail();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> ValidateBudgetSelectedCategoriesAsync(BudgetRecord record)
|
||||
{
|
||||
var allBudgets = await budgetRepository.GetAllAsync();
|
||||
|
||||
@@ -15,3 +15,9 @@ public class UpdateBudgetDto : CreateBudgetDto
|
||||
public long Id { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateArchiveSummaryDto
|
||||
{
|
||||
public DateTime ReferenceDate { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,8 @@ var fsql = new FreeSqlBuilder()
|
||||
)
|
||||
.Build();
|
||||
|
||||
fsql.UseJsonMap();
|
||||
|
||||
builder.Services.AddSingleton(fsql);
|
||||
|
||||
// 自动扫描注册服务和仓储
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FreeSql.Extensions.JsonMap" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
|
||||
<PackageReference Include="Scalar.AspNetCore" />
|
||||
|
||||
Reference in New Issue
Block a user