fix
This commit is contained in:
@@ -15,7 +15,7 @@ public class TransactionRecordController(
|
||||
/// 获取交易记录列表(分页)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<PagedResponse<Entity.TransactionRecord>> GetListAsync(
|
||||
public async Task<PagedResponse<TransactionRecord>> GetListAsync(
|
||||
[FromQuery] DateTime? lastOccurredAt = null,
|
||||
[FromQuery] long? lastId = null,
|
||||
[FromQuery] string? searchKeyword = null,
|
||||
@@ -39,7 +39,7 @@ public class TransactionRecordController(
|
||||
month);
|
||||
var total = await transactionRepository.GetTotalCountAsync();
|
||||
|
||||
return new PagedResponse<Entity.TransactionRecord>
|
||||
return new PagedResponse<TransactionRecord>
|
||||
{
|
||||
Success = true,
|
||||
Data = list.ToArray(),
|
||||
@@ -51,7 +51,7 @@ public class TransactionRecordController(
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取交易记录列表失败,时间: {LastTime}, ID: {LastId}", lastOccurredAt, lastId);
|
||||
return PagedResponse<Entity.TransactionRecord>.Fail($"获取交易记录列表失败: {ex.Message}");
|
||||
return PagedResponse<TransactionRecord>.Fail($"获取交易记录列表失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,17 +59,17 @@ public class TransactionRecordController(
|
||||
/// 根据ID获取交易记录详情
|
||||
/// </summary>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<BaseResponse<Entity.TransactionRecord>> GetByIdAsync(long id)
|
||||
public async Task<BaseResponse<TransactionRecord>> GetByIdAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var transaction = await transactionRepository.GetByIdAsync(id);
|
||||
if (transaction == null)
|
||||
{
|
||||
return BaseResponse<Entity.TransactionRecord>.Fail("交易记录不存在");
|
||||
return BaseResponse<TransactionRecord>.Fail("交易记录不存在");
|
||||
}
|
||||
|
||||
return new BaseResponse<Entity.TransactionRecord>
|
||||
return new BaseResponse<TransactionRecord>
|
||||
{
|
||||
Success = true,
|
||||
Data = transaction
|
||||
@@ -78,7 +78,7 @@ public class TransactionRecordController(
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取交易记录详情失败,交易ID: {TransactionId}", id);
|
||||
return BaseResponse<Entity.TransactionRecord>.Fail($"获取交易记录详情失败: {ex.Message}");
|
||||
return BaseResponse<TransactionRecord>.Fail($"获取交易记录详情失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ public class TransactionRecordController(
|
||||
/// 根据邮件ID获取交易记录列表
|
||||
/// </summary>
|
||||
[HttpGet("{emailId}")]
|
||||
public async Task<BaseResponse<List<Entity.TransactionRecord>>> GetByEmailIdAsync(long emailId)
|
||||
public async Task<BaseResponse<List<TransactionRecord>>> GetByEmailIdAsync(long emailId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var transactions = await transactionRepository.GetByEmailIdAsync(emailId);
|
||||
return new BaseResponse<List<Entity.TransactionRecord>>
|
||||
return new BaseResponse<List<TransactionRecord>>
|
||||
{
|
||||
Success = true,
|
||||
Data = transactions
|
||||
@@ -100,7 +100,7 @@ public class TransactionRecordController(
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取邮件交易记录失败,邮件ID: {EmailId}", emailId);
|
||||
return BaseResponse<List<Entity.TransactionRecord>>.Fail($"获取邮件交易记录失败: {ex.Message}");
|
||||
return BaseResponse<List<TransactionRecord>>.Fail($"获取邮件交易记录失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class TransactionRecordController(
|
||||
return BaseResponse.Fail("交易时间格式不正确");
|
||||
}
|
||||
|
||||
var transaction = new Entity.TransactionRecord
|
||||
var transaction = new TransactionRecord
|
||||
{
|
||||
OccurredAt = occurredAt,
|
||||
Reason = dto.Reason ?? string.Empty,
|
||||
@@ -416,7 +416,7 @@ public class TransactionRecordController(
|
||||
}
|
||||
|
||||
// 第三步:将查询结果序列化为JSON,直接传递给AI生成分析报告
|
||||
var dataJson = System.Text.Json.JsonSerializer.Serialize(queryResults, new System.Text.Json.JsonSerializerOptions
|
||||
var dataJson = System.Text.Json.JsonSerializer.Serialize(queryResults, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
@@ -482,13 +482,13 @@ public class TransactionRecordController(
|
||||
/// 获取指定日期的交易记录
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<List<Entity.TransactionRecord>>> GetByDateAsync([FromQuery] string date)
|
||||
public async Task<BaseResponse<List<TransactionRecord>>> GetByDateAsync([FromQuery] string date)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!DateTime.TryParse(date, out var targetDate))
|
||||
{
|
||||
return BaseResponse<List<Entity.TransactionRecord>>.Fail("日期格式不正确");
|
||||
return BaseResponse<List<TransactionRecord>>.Fail("日期格式不正确");
|
||||
}
|
||||
|
||||
// 获取当天的开始和结束时间
|
||||
@@ -497,7 +497,7 @@ public class TransactionRecordController(
|
||||
|
||||
var records = await transactionRepository.GetByDateRangeAsync(startDate, endDate);
|
||||
|
||||
return new BaseResponse<List<Entity.TransactionRecord>>
|
||||
return new BaseResponse<List<TransactionRecord>>
|
||||
{
|
||||
Success = true,
|
||||
Data = records
|
||||
@@ -506,7 +506,7 @@ public class TransactionRecordController(
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取指定日期的交易记录失败,日期: {Date}", date);
|
||||
return BaseResponse<List<Entity.TransactionRecord>>.Fail($"获取指定日期的交易记录失败: {ex.Message}");
|
||||
return BaseResponse<List<TransactionRecord>>.Fail($"获取指定日期的交易记录失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,12 +536,12 @@ public class TransactionRecordController(
|
||||
/// 获取未分类的账单列表
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<List<Entity.TransactionRecord>>> GetUnclassifiedAsync([FromQuery] int pageSize = 10)
|
||||
public async Task<BaseResponse<List<TransactionRecord>>> GetUnclassifiedAsync([FromQuery] int pageSize = 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
var records = await transactionRepository.GetUnclassifiedAsync(pageSize);
|
||||
return new BaseResponse<List<Entity.TransactionRecord>>
|
||||
return new BaseResponse<List<TransactionRecord>>
|
||||
{
|
||||
Success = true,
|
||||
Data = records
|
||||
@@ -550,7 +550,7 @@ public class TransactionRecordController(
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取未分类账单列表失败");
|
||||
return BaseResponse<List<Entity.TransactionRecord>>.Fail($"获取未分类账单列表失败: {ex.Message}");
|
||||
return BaseResponse<List<TransactionRecord>>.Fail($"获取未分类账单列表失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ public class TransactionRecordController(
|
||||
}
|
||||
|
||||
// 获取指定ID的账单
|
||||
var records = new List<Entity.TransactionRecord>();
|
||||
var records = new List<TransactionRecord>();
|
||||
foreach (var id in request.TransactionIds)
|
||||
{
|
||||
var record = await transactionRepository.GetByIdAsync(id);
|
||||
@@ -702,14 +702,14 @@ public class TransactionRecordController(
|
||||
/// 获取按交易摘要分组的统计信息(支持分页)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<PagedResponse<Repository.ReasonGroupDto>> GetReasonGroupsAsync(
|
||||
public async Task<PagedResponse<ReasonGroupDto>> GetReasonGroupsAsync(
|
||||
[FromQuery] int pageIndex = 1,
|
||||
[FromQuery] int pageSize = 20)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (list, total) = await transactionRepository.GetReasonGroupsAsync(pageIndex, pageSize);
|
||||
return new PagedResponse<Repository.ReasonGroupDto>
|
||||
return new PagedResponse<ReasonGroupDto>
|
||||
{
|
||||
Success = true,
|
||||
Data = list.ToArray(),
|
||||
@@ -719,7 +719,7 @@ public class TransactionRecordController(
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取交易摘要分组失败");
|
||||
return PagedResponse<Repository.ReasonGroupDto>.Fail($"获取交易摘要分组失败: {ex.Message}");
|
||||
return PagedResponse<ReasonGroupDto>.Fail($"获取交易摘要分组失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,21 +780,33 @@ public class TransactionRecordController(
|
||||
{{categoryInfo}}
|
||||
|
||||
你需要分析用户的需求,提取以下信息:
|
||||
1. 查询SQL, 根据用户的描述生成SQL Where 子句,用于查询交易记录。例如:Reason LIKE '%关键词%'
|
||||
Table Schema:
|
||||
1. 查询SQL, 根据用户的描述生成完整SQL语句,用于查询交易记录。例如:SELECT * FROM TransactionRecord WHERE Reason LIKE '%关键词%' OR Classify LIKE '%关键词2%' LIMIT 500
|
||||
[重要Table Schema:]
|
||||
```
|
||||
TransactionRecord (
|
||||
Id LONG,
|
||||
Reason STRING,
|
||||
Reason STRING NOT NULL,
|
||||
Amount DECIMAL,
|
||||
RefundAmount DECIMAL,
|
||||
Balance DECIMAL,
|
||||
OccurredAt DATETIME,
|
||||
EmailMessageId LONG,
|
||||
Type INT,
|
||||
Classify STRING,
|
||||
ImportNo STRING,
|
||||
ImportFrom STRING
|
||||
Classify STRING NOT NULL,
|
||||
ImportNo STRING NOT NULL,
|
||||
ImportFrom STRING NOT NULL
|
||||
)
|
||||
```
|
||||
[重要]
|
||||
如果用户没有限制,则最多查询500条记录;如果用户指定了时间范围,请在SQL中加入时间过滤条件。
|
||||
[重要SQL限制]
|
||||
必须是SELECT * FROM TransactionRecord 开头的SQL语句。
|
||||
当前日期:{{DateTime.Now:yyyy年M月d日}}
|
||||
[重要SQLite日期函数]
|
||||
- 提取年份:strftime('%Y', OccurredAt)
|
||||
- 提取月份:strftime('%m', OccurredAt)
|
||||
- 提取日期:strftime('%Y-%m-%d', OccurredAt)
|
||||
- 不要使用 YEAR()、MONTH()、DAY() 函数,SQLite不支持
|
||||
2. 目标交易类型(0:支出, 1:收入, 2:不计入收支)
|
||||
3. 目标分类名称(必须从上面的分类列表中选择)
|
||||
|
||||
@@ -835,7 +847,7 @@ public class TransactionRecordController(
|
||||
}
|
||||
|
||||
// 根据关键词查询交易记录
|
||||
var allRecords = await transactionRepository.QueryByWhereAsync(analysisInfo.Sql);
|
||||
var allRecords = await transactionRepository.ExecuteRawSqlAsync(analysisInfo.Sql);
|
||||
logger.LogInformation("NLP分析查询到 {Count} 条记录,SQL: {Sql}", allRecords.Count, analysisInfo.Sql);
|
||||
|
||||
// 为每条记录预设分类
|
||||
|
||||
Reference in New Issue
Block a user