Files
EmailBill/Service/SmartHandleServiceV2.cs
2026-01-12 14:34:03 +08:00

83 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
}