feat: 增加组合币种校验,交易币种必须和组合本位币一致
This commit is contained in:
parent
35222fbf26
commit
a23937eac8
@ -358,6 +358,27 @@ public class PortfolioController : ControllerBase
|
||||
});
|
||||
}
|
||||
|
||||
// 校验交易币种必须和组合本位币一致
|
||||
var portfolio = _databaseService.GetDb().Queryable<Portfolio>().Where(p => p.Id == request.portfolioId && p.UserId == userId).First();
|
||||
if (portfolio == null)
|
||||
{
|
||||
return NotFound(new ApiResponse<CreateTransactionResponse>
|
||||
{
|
||||
code = AssetManager.Models.StatusCodes.NotFound,
|
||||
data = null,
|
||||
message = "投资组合不存在"
|
||||
});
|
||||
}
|
||||
if (!string.IsNullOrEmpty(request.currency) && !request.currency.Equals(portfolio.Currency, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return BadRequest(new ApiResponse<CreateTransactionResponse>
|
||||
{
|
||||
code = AssetManager.Models.StatusCodes.BadRequest,
|
||||
data = null,
|
||||
message = $"该组合本位币为 {portfolio.Currency},只能添加相同币种的标的"
|
||||
});
|
||||
}
|
||||
|
||||
// 校验资产类型
|
||||
if (!string.IsNullOrEmpty(request.assetType))
|
||||
{
|
||||
|
||||
@ -365,6 +365,12 @@ public class PortfolioService : IPortfolioService
|
||||
throw new Exception("Portfolio not found or access denied");
|
||||
}
|
||||
|
||||
// 校验交易币种必须和组合本位币一致(双重校验)
|
||||
if (!string.IsNullOrEmpty(request.currency) && !request.currency.Equals(portfolio.Currency, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new Exception($"该组合本位币为 {portfolio.Currency},只能添加相同币种的标的");
|
||||
}
|
||||
|
||||
// 卖出操作校验
|
||||
if (request.type?.ToLower() == "sell")
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user