使用 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

@@ -9,6 +9,7 @@ using Repository;
public class TransactionRecordController(
ITransactionRecordRepository transactionRepository,
ISmartHandleService smartHandleService,
ISmartHandleServiceV2 smartHandleServiceV2,
ILogger<TransactionRecordController> logger
) : ControllerBase
{
@@ -603,28 +604,28 @@ public class TransactionRecordController(
/// 一句话录账解析
/// </summary>
[HttpPost]
public async Task<BaseResponse<TransactionParseResult>> ParseOneLine([FromBody] ParseOneLineRequestDto request)
public async Task<BaseResponse<Service.AgentFramework.TransactionParseResult>> ParseOneLine([FromBody] ParseOneLineRequestDto request)
{
if (string.IsNullOrEmpty(request.Text))
{
return "请求参数缺失text".Fail<TransactionParseResult>();
return "请求参数缺失text".Fail<Service.AgentFramework.TransactionParseResult>();
}
try
{
var result = await smartHandleService.ParseOneLineBillAsync(request.Text);
var agentResult = await smartHandleServiceV2.ParseOneLineBillAgentAsync(request.Text);
if (result == null)
if (agentResult?.Data == null)
{
return "AI解析失败".Fail<TransactionParseResult>();
return "AI解析失败".Fail<Service.AgentFramework.TransactionParseResult>();
}
return result.Ok();
return agentResult.Data.Ok();
}
catch (Exception ex)
{
logger.LogError(ex, "一句话录账解析失败,文本: {Text}", request.Text);
return ("AI解析失败: " + ex.Message).Fail<TransactionParseResult>();
return ("AI解析失败: " + ex.Message).Fail<Service.AgentFramework.TransactionParseResult>();
}
}

View File

@@ -1,4 +1,5 @@
global using Service;
global using Service.AgentFramework;
global using Common;
global using Microsoft.AspNetCore.Mvc;
global using WebApi.Controllers.Dto;

View File

@@ -1,3 +1,5 @@
using System.Text;
using Microsoft.Agents.AI;
using FreeSql;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
@@ -33,6 +35,10 @@ builder.Services.AddControllers(options =>
builder.Services.AddOpenApi();
builder.Services.AddHttpClient();
// 注册 Agent Framework
builder.Services.AddAgentFramework();
#if DEBUG
// 配置 CORS
builder.Services.AddCors(options =>
{
@@ -43,6 +49,7 @@ builder.Services.AddCors(options =>
.AllowAnyMethod();
});
});
#endif
// 绑定配置
builder.Services.Configure<EmailSettings>(builder.Configuration.GetSection("EmailSettings"));
@@ -111,7 +118,7 @@ var fsql = new FreeSqlBuilder()
.UseMonitorCommand(
cmd =>
{
Log.Debug("执行SQL: {Sql}", cmd.CommandText);
Log.Verbose("执行SQL: {Sql}", cmd.CommandText);
}
)
.Build();
@@ -121,6 +128,9 @@ builder.Services.AddSingleton(fsql);
// 自动扫描注册服务和仓储
builder.Services.AddServices();
// 注册 Agent Framework
builder.Services.AddAgentFramework();
// 注册日志清理后台服务
builder.Services.AddHostedService<LogCleanupService>();

View File

@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.DevUI" />
<PackageReference Include="Microsoft.Agents.AI.Hosting" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Scalar.AspNetCore" />