From c2ed8266cf99981a138ee88c907dffe0287e7fe1 Mon Sep 17 00:00:00 2001 From: claw_bot Date: Tue, 10 Mar 2026 02:17:36 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81transactionDate?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=89=8D=E7=AB=AF=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E7=9A=84=E4=BA=A4=E6=98=93=E6=97=A5=E6=9C=9F=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B5=8B=E5=80=BC=E7=BB=99TransactionTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AssetManager.Models/DTOs/PortfolioDTO.cs | 1 + AssetManager.Services/PortfolioService.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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)) {