From 5bc318725d803b9331c8b4fe3e4120b21b548fc1 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Tue, 17 Mar 2026 01:50:47 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=BB=84=E5=90=88?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8D=E7=A7=B0/=E7=AD=96=E7=95=A5/?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PortfolioController.cs | 27 +++++++++++++++ AssetManager.Models/DTOs/PortfolioDTO.cs | 10 ++++++ AssetManager.Services/IPortfolioFacade.cs | 5 +++ AssetManager.Services/IPortfolioService.cs | 1 + AssetManager.Services/PortfolioFacade.cs | 6 ++++ AssetManager.Services/PortfolioService.cs | 34 +++++++++++++++++++ 6 files changed, 83 insertions(+) diff --git a/AssetManager.API/Controllers/PortfolioController.cs b/AssetManager.API/Controllers/PortfolioController.cs index 5db6232..609047b 100755 --- a/AssetManager.API/Controllers/PortfolioController.cs +++ b/AssetManager.API/Controllers/PortfolioController.cs @@ -171,6 +171,33 @@ public class PortfolioController : ControllerBase } } + /// + /// 更新投资组合 + /// + [HttpPut("{id}")] + public async Task>> UpdatePortfolio(string id, [FromBody] UpdatePortfolioRequest request) + { + var userId = GetCurrentUserId(); + var success = await _portfolioFacade.UpdatePortfolioAsync(id, request, userId); + + if (!success) + { + return NotFound(new ApiResponse + { + code = Models.StatusCodes.NotFound, + data = null, + message = "组合不存在" + }); + } + + return Ok(new ApiResponse + { + code = Models.StatusCodes.Success, + data = null, + message = "更新成功" + }); + } + /// /// 删除投资组合 /// diff --git a/AssetManager.Models/DTOs/PortfolioDTO.cs b/AssetManager.Models/DTOs/PortfolioDTO.cs index d00cddc..316c7ff 100755 --- a/AssetManager.Models/DTOs/PortfolioDTO.cs +++ b/AssetManager.Models/DTOs/PortfolioDTO.cs @@ -11,6 +11,16 @@ public class CreatePortfolioRequest public List? Stocks { get; set; } } +/// +/// 更新投资组合请求 +/// +public class UpdatePortfolioRequest +{ + public string? Name { get; set; } + public string? StrategyId { get; set; } + public string? Status { get; set; } +} + /// /// 股票项 /// diff --git a/AssetManager.Services/IPortfolioFacade.cs b/AssetManager.Services/IPortfolioFacade.cs index 51f1945..2a02be0 100644 --- a/AssetManager.Services/IPortfolioFacade.cs +++ b/AssetManager.Services/IPortfolioFacade.cs @@ -47,6 +47,11 @@ public interface IPortfolioFacade /// Task DeletePortfolioAsync(string portfolioId, string userId); + /// + /// 更新投资组合 + /// + Task UpdatePortfolioAsync(string portfolioId, UpdatePortfolioRequest request, string userId); + /// /// 创建投资组合(含用户验证和币种校验) /// diff --git a/AssetManager.Services/IPortfolioService.cs b/AssetManager.Services/IPortfolioService.cs index 1a7cd05..8660f21 100755 --- a/AssetManager.Services/IPortfolioService.cs +++ b/AssetManager.Services/IPortfolioService.cs @@ -6,6 +6,7 @@ public interface IPortfolioService { CreatePortfolioResponse CreatePortfolio(CreatePortfolioRequest request, string userId); Task CreatePortfolioAsync(CreatePortfolioRequest request, string userId); + Task UpdatePortfolioAsync(string portfolioId, UpdatePortfolioRequest request, string userId); List GetPortfolios(string userId); Task> GetPortfolioListAsync(string userId); TotalAssetsResponse GetTotalAssets(string userId); diff --git a/AssetManager.Services/PortfolioFacade.cs b/AssetManager.Services/PortfolioFacade.cs index 12583de..e97c636 100644 --- a/AssetManager.Services/PortfolioFacade.cs +++ b/AssetManager.Services/PortfolioFacade.cs @@ -146,6 +146,12 @@ public class PortfolioFacade : IPortfolioFacade return await _portfolioService.DeletePortfolioAsync(portfolioId, userId); } + public async Task UpdatePortfolioAsync(string portfolioId, UpdatePortfolioRequest request, string userId) + { + _logger.LogInformation("更新组合: {PortfolioId}", portfolioId); + return await _portfolioService.UpdatePortfolioAsync(portfolioId, request, userId); + } + /// /// 创建投资组合(含用户验证和币种校验) /// diff --git a/AssetManager.Services/PortfolioService.cs b/AssetManager.Services/PortfolioService.cs index 1a7110a..dde1b9e 100755 --- a/AssetManager.Services/PortfolioService.cs +++ b/AssetManager.Services/PortfolioService.cs @@ -739,6 +739,40 @@ public class PortfolioService : IPortfolioService }; } + public async Task UpdatePortfolioAsync(string portfolioId, UpdatePortfolioRequest request, string userId) + { + var portfolio = _db.Queryable() + .Where(p => p.Id == portfolioId && p.UserId == userId) + .First(); + + if (portfolio == null) + { + return false; + } + + // 更新字段 + if (!string.IsNullOrEmpty(request.Name)) + { + portfolio.Name = request.Name; + } + + // 策略可以为空(解绑策略) + portfolio.StrategyId = request.StrategyId; + + if (!string.IsNullOrEmpty(request.Status)) + { + portfolio.Status = request.Status; + } + + portfolio.UpdatedAt = DateTime.Now; + + _db.Updateable(portfolio).ExecuteCommand(); + _logger.LogInformation("更新投资组合: {PortfolioId}, 名称: {Name}, 策略: {StrategyId}", + portfolioId, portfolio.Name, portfolio.StrategyId ?? "无"); + + return true; + } + public async Task DeletePortfolioAsync(string portfolioId, string userId) { var portfolio = _db.Queryable()