feat: 优化多个组件的高度设置,确保更好的用户体验;更新交易记录控制器以处理智能分类结果
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 28s
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 28s
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:
@@ -1,5 +1,7 @@
|
||||
namespace WebApi.Controllers;
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Repository;
|
||||
|
||||
[ApiController]
|
||||
@@ -30,8 +32,8 @@ public class TransactionRecordController(
|
||||
{
|
||||
try
|
||||
{
|
||||
string[]? classifies = string.IsNullOrWhiteSpace(classify)
|
||||
? null
|
||||
string[]? classifies = string.IsNullOrWhiteSpace(classify)
|
||||
? null
|
||||
: classify.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
TransactionType? transactionType = type.HasValue ? (TransactionType)type.Value : null;
|
||||
@@ -212,7 +214,7 @@ public class TransactionRecordController(
|
||||
transaction.Balance = dto.Balance;
|
||||
transaction.Type = dto.Type;
|
||||
transaction.Classify = dto.Classify ?? string.Empty;
|
||||
|
||||
|
||||
// 清除待确认状态
|
||||
transaction.UnconfirmedClassify = null;
|
||||
transaction.UnconfirmedType = null;
|
||||
@@ -452,12 +454,57 @@ public class TransactionRecordController(
|
||||
await smartHandleService.SmartClassifyAsync(request.TransactionIds.ToArray(), async (chunk) =>
|
||||
{
|
||||
var (eventType, content) = chunk;
|
||||
await TrySetUnconfirmedAsync(eventType, content);
|
||||
await WriteEventAsync(eventType, content);
|
||||
});
|
||||
|
||||
await Response.Body.FlushAsync();
|
||||
}
|
||||
|
||||
private async Task TrySetUnconfirmedAsync(string eventType, string content)
|
||||
{
|
||||
if (eventType != "data")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var jsonObject = JsonSerializer.Deserialize<JsonObject>(content);
|
||||
var id = jsonObject?["id"]?.GetValue<long>() ?? 0;
|
||||
var classify = jsonObject?["Classify"]?.GetValue<string>() ?? string.Empty;
|
||||
var typeValue = jsonObject?["Type"]?.GetValue<int>() ?? -1;
|
||||
|
||||
if(id == 0 || typeValue == -1 || string.IsNullOrEmpty(classify))
|
||||
{
|
||||
logger.LogWarning("解析智能分类结果时,发现无效数据,内容: {Content}", content);
|
||||
return;
|
||||
}
|
||||
|
||||
var record = await transactionRepository.GetByIdAsync(id);
|
||||
if (record == null)
|
||||
{
|
||||
logger.LogWarning("解析智能分类结果时,未找到对应的交易记录,ID: {Id}", id);
|
||||
return;
|
||||
}
|
||||
|
||||
record.UnconfirmedClassify = classify;
|
||||
record.UnconfirmedType = (TransactionType)typeValue;
|
||||
|
||||
var success = await transactionRepository.UpdateAsync(record);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
logger.LogWarning("解析智能分类结果时,更新交易记录失败,ID: {Id}", id);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "解析智能分类结果失败,内容: {Content}", content);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量更新账单分类
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user