From ba60dbc72c4e59290e7228eb656ed6779f9a56b6 Mon Sep 17 00:00:00 2001 From: claw_bot Date: Tue, 10 Mar 2026 02:48:55 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8E=E7=AB=AF=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8D=96=E5=87=BA=E6=93=8D=E4=BD=9C=E6=A0=A1=E9=AA=8C=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E5=8D=96=E5=87=BA=E5=B7=B2=E6=9C=89=E6=8C=81?= =?UTF-8?q?=E4=BB=93=E4=B8=94=E6=95=B0=E9=87=8F=E4=B8=8D=E8=B6=85=E8=BF=87?= =?UTF-8?q?=E6=8C=81=E4=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AssetManager.Services/PortfolioService.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/AssetManager.Services/PortfolioService.cs b/AssetManager.Services/PortfolioService.cs index f293bbc..9c8f6a7 100644 --- a/AssetManager.Services/PortfolioService.cs +++ b/AssetManager.Services/PortfolioService.cs @@ -359,6 +359,26 @@ public class PortfolioService : IPortfolioService throw new Exception("Portfolio not found or access denied"); } + // 卖出操作校验 + if (request.type?.ToLower() == "sell") + { + // 校验是否有该持仓 + var position = _db.Queryable() + .Where(pos => pos.PortfolioId == request.portfolioId && pos.StockCode == request.stockCode) + .First(); + + if (position == null) + { + throw new Exception($"该组合中不存在标的 {request.stockCode},无法卖出"); + } + + // 校验卖出数量不超过持仓数量 + if (request.amount > (double)position.Shares) + { + throw new Exception($"卖出数量不能超过持仓数量,当前持仓 {position.Shares} 份"); + } + } + // 解析实际交易时间,如果解析失败则用当前时间 DateTime transactionTime = DateTime.Now; if (!string.IsNullOrEmpty(request.transactionDate))