Files
bl/modules/config/service/tower.go
昔念 026689f3ed ```
feat(cache): 添加复合键缓存操作支持

添加了基于 uint32+string 组合键的缓存操作方法,包括
GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和
ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景

fix(vscode): 添加 cSpell 配置支持 struc 词汇

refactor(session): 移除过时的会话管理方法

移除了基于单一字符串键的会话管理方法,因为已迁移到使用
复合键的缓存操作方式
```
2026-01-19 18:51:56 +08:00

94 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/cool"
"blazing/modules/config/model"
"github.com/gogf/gf/v2/database/gdb"
)
// 定义塔类型枚举,方便区分不同塔的业务逻辑
type TowerType uint32
const (
TowerType110 TowerType = 110 // 110塔
TowerType500 TowerType = 500 // 500塔
TowerType600 TowerType = 600 // 600塔
)
// TowerService 统一的塔配置服务整合110/500/600塔的逻辑
type TowerService struct {
*cool.Service
towerType TowerType // 标记当前服务对应的塔类型
tableName string // 存储当前塔类型对应的表名
}
// NewTowerService 创建指定类型的塔配置服务
func NewTowerService(towerType TowerType) *TowerService {
var tableName string
switch towerType {
case TowerType110:
tableName = model.TableNamedARKTowerConfig
case TowerType500:
tableName = model.TableNameTrialTowerConfig
case TowerType600:
tableName = model.TableNameBraveTowerConfig
default:
panic("unsupported tower type: " + string(rune(towerType))) // 非支持类型直接panic也可返回error
}
// 创建一个统一的模型,设置对应的表名
unifiedModel := &UnifiedTowerModel{
tableName: tableName,
}
return &TowerService{
Service: &cool.Service{Model: unifiedModel},
towerType: towerType,
tableName: tableName,
}
}
// UnifiedTowerModel 统一的塔模型,通过设置不同的表名来区分不同类型的塔
type UnifiedTowerModel struct {
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model
tableName string
}
// TableName 返回当前模型对应的表名
func (m *UnifiedTowerModel) TableName() string {
return m.tableName
}
// GroupName 返回模型所属组
func (m *UnifiedTowerModel) GroupName() string {
return "default"
}
// Boss 根据塔等级获取对应的Boss配置统一入口
func (s *TowerService) Boss(towerLevel uint32) *model.BaseTowerConfig {
// 构建基础查询条件
query := cool.DBM(s.Model).Where("tower_level = ?", towerLevel).Where("is_enabled", 1)
// 600塔专属的缓存配置
var config model.BaseTowerConfig
query.Cache(gdb.CacheOption{
// Duration: time.Hour, // 可根据需要开启缓存时长
Force: false,
}).Scan(&config)
return &config
}
// 兼容原有调用方式的快捷构造函数(可选,保证代码平滑迁移)
func NewTower110Service() *TowerService {
return NewTowerService(TowerType110)
}
func NewTower500Service() *TowerService {
return NewTowerService(TowerType500)
}
func NewTower600Service() *TowerService {
return NewTowerService(TowerType600)
}