diff --git a/AssetManager.API/Controllers/PortfolioController.cs b/AssetManager.API/Controllers/PortfolioController.cs index 4a523a6..715eb16 100644 --- a/AssetManager.API/Controllers/PortfolioController.cs +++ b/AssetManager.API/Controllers/PortfolioController.cs @@ -358,6 +358,27 @@ public class PortfolioController : ControllerBase }); } + // 校验交易币种必须和组合本位币一致 + var portfolio = _databaseService.GetDb().Queryable().Where(p => p.Id == request.portfolioId && p.UserId == userId).First(); + if (portfolio == null) + { + return NotFound(new ApiResponse + { + code = AssetManager.Models.StatusCodes.NotFound, + data = null, + message = "投资组合不存在" + }); + } + if (!string.IsNullOrEmpty(request.currency) && !request.currency.Equals(portfolio.Currency, StringComparison.OrdinalIgnoreCase)) + { + return BadRequest(new ApiResponse + { + code = AssetManager.Models.StatusCodes.BadRequest, + data = null, + message = $"该组合本位币为 {portfolio.Currency},只能添加相同币种的标的" + }); + } + // 校验资产类型 if (!string.IsNullOrEmpty(request.assetType)) { diff --git a/AssetManager.Services/PortfolioService.cs b/AssetManager.Services/PortfolioService.cs index bcaf145..3ce4f24 100644 --- a/AssetManager.Services/PortfolioService.cs +++ b/AssetManager.Services/PortfolioService.cs @@ -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") {