Переглянути джерело

refactor(channel-pricing): 提取 ParseTagIds 辅助函数 + 移除调试 console.log

- 将 tag ID 解析逻辑提取为 model.ParseTagIds,消除 model 层和 controller 层重复代码
- 统一 TrimSpace 处理(之前 controller 版本漏了)
- 移除 ChannelPricingView 残留的 console.log('Expanded keys:')
- 删除多余空行

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
master
fengsilin 3 тижднів тому
джерело
коміт
235f7c6e5f
3 змінених файлів з 18 додано та 23 видалено
  1. +1
    -10
      controller/channel_pricing.go
  2. +17
    -12
      model/channel_pricing.go
  3. +0
    -1
      web/src/pages/Setting/Ratio/ChannelPricingView.jsx

+ 1
- 10
controller/channel_pricing.go Переглянути файл

@@ -365,16 +365,7 @@ func GetChannelPricingWithTags(c *gin.Context) {
for _, cp := range list {
item := &ChannelPricingWithTags{
ChannelPricing: cp,
Tags: make([]*model.PricingTag, 0),
}
if cp.TagIds != "" {
for _, idStr := range strings.Split(cp.TagIds, ",") {
if id, err := strconv.Atoi(idStr); err == nil {
if tag, ok := tagMap[id]; ok {
item.Tags = append(item.Tags, tag)
}
}
}
Tags: model.ParseTagIds(cp.TagIds, tagMap),
}
result = append(result, item)
}


+ 17
- 12
model/channel_pricing.go Переглянути файл

@@ -172,6 +172,22 @@ func GetEffectivePricing(modelName string, channelId int) (*ChannelPricing, bool
return cp, true
}

// ParseTagIds 解析逗号分隔的标签ID字符串为 PricingTag 切片
func ParseTagIds(tagIds string, tagMap map[int]*PricingTag) []*PricingTag {
if tagIds == "" {
return nil
}
tags := make([]*PricingTag, 0)
for _, idStr := range strings.Split(tagIds, ",") {
if id, err := strconv.Atoi(strings.TrimSpace(idStr)); err == nil {
if tag, ok := tagMap[id]; ok {
tags = append(tags, tag)
}
}
}
return tags
}

// LoadChannelPricingCache 全量加载渠道定价到内存(启动时调用)
func LoadChannelPricingCache() {
var pricings []*ChannelPricing
@@ -234,8 +250,6 @@ func GetChannelPricingByModelWithChannelInfo(modelName string) ([]*ChannelPricin
if !hasPrice {
globalModelPrice = 0
}


// 获取全局扩展比率(用于 CASE WHEN 回退)
globalCacheRatio, _ := ratio_setting.GetCacheRatio(modelName)
globalCacheCreationRatio, _ := ratio_setting.GetCreateCacheRatio(modelName)
@@ -283,16 +297,7 @@ func GetChannelPricingByModelWithChannelInfo(modelName string) ([]*ChannelPricin

// 为每个渠道定价填充标签
for _, result := range results {
if result.TagIds != "" {
result.Tags = make([]*PricingTag, 0)
for _, idStr := range strings.Split(result.TagIds, ",") {
if id, err := strconv.Atoi(strings.TrimSpace(idStr)); err == nil {
if tag, ok := tagMap[id]; ok {
result.Tags = append(result.Tags, tag)
}
}
}
}
result.Tags = ParseTagIds(result.TagIds, tagMap)
}

return results, nil


+ 0
- 1
web/src/pages/Setting/Ratio/ChannelPricingView.jsx Переглянути файл

@@ -463,7 +463,6 @@ const ChannelPricingView = ({ channels, channelPricings, tags, onRefresh }) => {
rowKey="modelName"
expandedRowKeys={expandedRowKeys}
onExpandedRowsChange={(keys) => {
console.log('Expanded keys:', keys);
setExpandedRowKeys(keys);
}}
expandedRowRender={expandedRowRender}


Завантаження…
Відмінити
Зберегти