使用 maf重构
This commit is contained in:
82
Service/SmartHandleServiceV2.cs
Normal file
82
Service/SmartHandleServiceV2.cs
Normal 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("开始执行智能分类 Agent,ID 数量: {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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user