feat: 支持transactionDate字段,前端传入的交易日期会自动赋值给TransactionTime
This commit is contained in:
parent
658cfe90e1
commit
c2ed8266cf
@ -114,6 +114,7 @@ public class CreateTransactionRequest
|
|||||||
public string? remark { get; set; }
|
public string? remark { get; set; }
|
||||||
public string assetType { get; set; } = "Stock"; // Stock / Crypto
|
public string assetType { get; set; } = "Stock"; // Stock / Crypto
|
||||||
public string? transactionTime { get; set; } // 实际交易时间,可选
|
public string? transactionTime { get; set; } // 实际交易时间,可选
|
||||||
|
public string? transactionDate { get; set; } // 交易日期,前端传入 YYYY-MM-DD 格式
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CreateTransactionResponse
|
public class CreateTransactionResponse
|
||||||
|
|||||||
@ -361,7 +361,15 @@ public class PortfolioService : IPortfolioService
|
|||||||
|
|
||||||
// 解析实际交易时间,如果解析失败则用当前时间
|
// 解析实际交易时间,如果解析失败则用当前时间
|
||||||
DateTime transactionTime = DateTime.Now;
|
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))
|
if (DateTime.TryParse(request.transactionTime, out var parsedTime))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user