diff --git a/AssetManager.Models/DTOs/PortfolioDTO.cs b/AssetManager.Models/DTOs/PortfolioDTO.cs index bcb7639..c4f5271 100644 --- a/AssetManager.Models/DTOs/PortfolioDTO.cs +++ b/AssetManager.Models/DTOs/PortfolioDTO.cs @@ -114,6 +114,7 @@ public class CreateTransactionRequest public string? remark { get; set; } public string assetType { get; set; } = "Stock"; // Stock / Crypto public string? transactionTime { get; set; } // 实际交易时间,可选 + public string? transactionDate { get; set; } // 交易日期,前端传入 YYYY-MM-DD 格式 } public class CreateTransactionResponse diff --git a/AssetManager.Services/PortfolioService.cs b/AssetManager.Services/PortfolioService.cs index 5d61388..f293bbc 100644 --- a/AssetManager.Services/PortfolioService.cs +++ b/AssetManager.Services/PortfolioService.cs @@ -361,7 +361,15 @@ public class PortfolioService : IPortfolioService // 解析实际交易时间,如果解析失败则用当前时间 DateTime transactionTime = DateTime.Now; - if (!string.IsNullOrEmpty(request.transactionTime)) + if (!string.IsNullOrEmpty(request.transactionDate)) + { + if (DateTime.TryParse(request.transactionDate, out var parsedDate)) + { + // 如果只传了日期,时间部分默认用当前时间 + transactionTime = parsedDate.Date + DateTime.Now.TimeOfDay; + } + } + else if (!string.IsNullOrEmpty(request.transactionTime)) { if (DateTime.TryParse(request.transactionTime, out var parsedTime)) {