refactor(策略): 将标签存储格式从JSON数组改为逗号分隔字符串

修改策略标签的存储格式,从JSON数组序列化改为简单的逗号分隔字符串,简化数据存储和处理逻辑。同时更新相关控制器和服务层的代码以适应这一变更。
This commit is contained in:
niannian zheng 2026-03-02 17:29:56 +08:00
parent 31c598c4bc
commit fe781db417
3 changed files with 8 additions and 7 deletions

View File

@ -35,7 +35,8 @@ public class StrategyController : ControllerBase
{ {
try try
{ {
tags = System.Text.Json.JsonSerializer.Deserialize<List<string>>(strategy.Tags); // 尝试按逗号分割字符串
tags = strategy.Tags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
} }
catch { } catch { }
} }

View File

@ -39,9 +39,9 @@ public class Strategy
public string Description { get; set; } public string Description { get; set; }
/// <summary> /// <summary>
/// 策略标签 (JSON数组) /// 策略标签 (逗号分隔的字符串)
/// </summary> /// </summary>
[SugarColumn(ColumnName = "tags", IsJson = true)] [SugarColumn(ColumnName = "tags")]
public string Tags { get; set; } public string Tags { get; set; }
/// <summary> /// <summary>

View File

@ -22,9 +22,9 @@ public class StrategyService : IStrategyService
Alias = request.name, Alias = request.name,
Type = request.type, Type = request.type,
Description = request.description, Description = request.description,
Tags = System.Text.Json.JsonSerializer.Serialize(request.tags), Tags = request.tags != null ? string.Join(",", request.tags) : null,
RiskLevel = request.riskLevel, RiskLevel = request.riskLevel,
Config = System.Text.Json.JsonSerializer.Serialize(request.parameters), Config = request.parameters != null ? System.Text.Json.JsonSerializer.Serialize(request.parameters) : null,
CreatedAt = DateTime.Now, CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now UpdatedAt = DateTime.Now
}; };
@ -61,9 +61,9 @@ public class StrategyService : IStrategyService
strategy.Alias = request.name; strategy.Alias = request.name;
strategy.Type = request.type; strategy.Type = request.type;
strategy.Description = request.description; strategy.Description = request.description;
strategy.Tags = System.Text.Json.JsonSerializer.Serialize(request.tags); strategy.Tags = request.tags != null ? string.Join(",", request.tags) : null;
strategy.RiskLevel = request.riskLevel; strategy.RiskLevel = request.riskLevel;
strategy.Config = System.Text.Json.JsonSerializer.Serialize(request.parameters); strategy.Config = request.parameters != null ? System.Text.Json.JsonSerializer.Serialize(request.parameters) : null;
strategy.UpdatedAt = DateTime.Now; strategy.UpdatedAt = DateTime.Now;
_db.Updateable(strategy).ExecuteCommand(); _db.Updateable(strategy).ExecuteCommand();