使用 maf重构

This commit is contained in:
孙诚
2026-01-12 14:34:03 +08:00
parent 255c82759e
commit db61f70335
20 changed files with 1632 additions and 27 deletions

View File

@@ -0,0 +1,82 @@
namespace Service;
/// <summary>
/// 智能处理服务 - 使用 Agent Framework 重构
/// </summary>
public interface ISmartHandleServiceV2
{
/// <summary>
/// 使用 Agent Framework 进行智能分类
/// </summary>
Task<AgentResult<ClassificationResult[]>> SmartClassifyAgentAsync(
long[] transactionIds,
Action<(string type, string data)> chunkAction);
/// <summary>
/// 使用 Agent Framework 解析单行账单
/// </summary>
Task<AgentResult<AgentFramework.TransactionParseResult?>> ParseOneLineBillAgentAsync(string text);
}
/// <summary>
/// 智能处理服务实现 - Agent Framework 版本
/// </summary>
public class SmartHandleServiceV2(
ClassificationAgent classificationAgent,
ParsingAgent parsingAgent,
ITransactionCategoryRepository categoryRepository,
ILogger<SmartHandleServiceV2> logger
) : ISmartHandleServiceV2
{
/// <summary>
/// 使用 Agent Framework 进行智能分类
/// </summary>
public async Task<AgentResult<ClassificationResult[]>> SmartClassifyAgentAsync(
long[] transactionIds,
Action<(string type, string data)> chunkAction)
{
try
{
logger.LogInformation("开始执行智能分类 AgentID 数量: {Count}", transactionIds.Length);
var result = await classificationAgent.ExecuteAsync(transactionIds, categoryRepository);
logger.LogInformation("分类完成:{Summary}", result.Summary);
return result;
}
catch (Exception ex)
{
logger.LogError(ex, "智能分类 Agent 执行失败");
throw;
}
}
/// <summary>
/// 使用 Agent Framework 解析单行账单
/// </summary>
public async Task<AgentResult<AgentFramework.TransactionParseResult?>> ParseOneLineBillAgentAsync(string text)
{
try
{
logger.LogInformation("开始解析账单: {Text}", text);
var result = await parsingAgent.ExecuteAsync(text);
if (result.Success)
{
logger.LogInformation("解析成功: {Summary}", result.Summary);
}
else
{
logger.LogWarning("解析失败: {Error}", result.Error);
}
return result;
}
catch (Exception ex)
{
logger.LogError(ex, "解析 Agent 执行失败");
throw;
}
}
}