```
feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
This commit is contained in:
@@ -3,7 +3,23 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
)
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
"github.com/google/uuid"
|
||||
) // 1. 扩展字符集:数字+大小写字母+安全符号(避开URL/输入易冲突的符号,如/、?、&)
|
||||
|
||||
const charsetWithSymbol = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz"
|
||||
|
||||
func Generate16CharSecure() string {
|
||||
result := make([]byte, 16)
|
||||
for i := 0; i < 16; i++ {
|
||||
|
||||
result[i] = charsetWithSymbol[grand.N(0, len(charsetWithSymbol)-1)]
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
type CdkService struct {
|
||||
*cool.Service
|
||||
@@ -13,6 +29,33 @@ func NewCdkService() *CdkService {
|
||||
return &CdkService{
|
||||
&cool.Service{
|
||||
Model: model.NewCDKConfig(),
|
||||
InsertParam: func(ctx context.Context) g.MapStrAny {
|
||||
uuid.NewV7()
|
||||
return g.MapStrAny{
|
||||
"cdk_code": Generate16CharSecure(),
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
func (s *CdkService) Get(id string) *model.CDKConfig {
|
||||
var item *model.CDKConfig
|
||||
dbm(s.Model).Where("cdk_code", id).WhereNot("exchange_remain_count", 0).Scan(&item)
|
||||
|
||||
return item
|
||||
|
||||
}
|
||||
func (s *CdkService) Set(id string) bool {
|
||||
|
||||
res, err := cool.DBM(s.Model).Where("cdk_code", id).WhereNot("exchange_remain_count", 0).Decrement("exchange_remain_count", 1)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
rows, _ := res.RowsAffected()
|
||||
if rows == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
@@ -23,26 +23,13 @@ func NewTaskService() *TaskService {
|
||||
},
|
||||
}
|
||||
}
|
||||
func (s *TaskService) Get(id, os uint32) *model.TaskConfig {
|
||||
func (s *TaskService) Get(id, os int) *model.TaskConfig {
|
||||
var item []model.TaskConfig
|
||||
dbm(s.Model).Where("task_id", id).Scan(&item)
|
||||
var res *model.TaskConfig
|
||||
if len(item) == 1 { //只有一个直接默认
|
||||
if item[0].OutState == os {
|
||||
res = &item[0]
|
||||
}
|
||||
if item[0].OutState < 10 {
|
||||
res = &item[0]
|
||||
}
|
||||
|
||||
}
|
||||
if len(item) > 1 { //
|
||||
|
||||
for _, v := range item {
|
||||
if v.OutState == os {
|
||||
res = &item[os]
|
||||
return res
|
||||
}
|
||||
for _, v := range item {
|
||||
if v.OutState == os {
|
||||
res = &v
|
||||
|
||||
}
|
||||
|
||||
@@ -53,13 +40,20 @@ func (s *TaskService) Get(id, os uint32) *model.TaskConfig {
|
||||
}
|
||||
func (s *TaskService) GetDaily() []model.TaskConfig {
|
||||
var item []model.TaskConfig
|
||||
cool.DBM(s.Model).Where("task_type", 1).
|
||||
Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Scan(&item)
|
||||
dbm(s.Model).Where("task_type", 1).Scan(&item)
|
||||
|
||||
return item
|
||||
|
||||
}
|
||||
func (s *TaskService) IsAcceptable(taskid uint32) bool {
|
||||
|
||||
con, _ := cool.DBM(s.Model).Where("is_acceptable", 1).Where("task_id", taskid).
|
||||
Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Count()
|
||||
|
||||
return con > 0
|
||||
|
||||
}
|
||||
|
||||
@@ -68,28 +68,15 @@ func (m *UnifiedTowerModel) GroupName() string {
|
||||
// Boss 根据塔等级获取对应的Boss配置(统一入口)
|
||||
func (s *TowerService) Boss(towerLevel uint32) *model.BaseTowerConfig {
|
||||
// 构建基础查询条件
|
||||
query := cool.DBM(s.Model).Where("tower_level = ?", towerLevel)
|
||||
query := cool.DBM(s.Model).Where("tower_level = ?", towerLevel).Where("is_enabled", 1)
|
||||
|
||||
// 根据塔类型处理不同的缓存逻辑
|
||||
switch s.towerType {
|
||||
case TowerType110, TowerType500:
|
||||
// 110塔和500塔使用普通查询
|
||||
var config model.BaseTowerConfig
|
||||
query.Scan(&config)
|
||||
return &config
|
||||
|
||||
case TowerType600:
|
||||
// 600塔专属的缓存配置
|
||||
var config model.BaseTowerConfig
|
||||
query.Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour, // 可根据需要开启缓存时长
|
||||
Force: false,
|
||||
}).Scan(&config)
|
||||
return &config
|
||||
|
||||
default:
|
||||
return nil // 非支持类型返回nil,也可根据业务需求调整
|
||||
}
|
||||
// 600塔专属的缓存配置
|
||||
var config model.BaseTowerConfig
|
||||
query.Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour, // 可根据需要开启缓存时长
|
||||
Force: false,
|
||||
}).Scan(&config)
|
||||
return &config
|
||||
}
|
||||
|
||||
// 兼容原有调用方式的快捷构造函数(可选,保证代码平滑迁移)
|
||||
@@ -103,4 +90,4 @@ func NewTower500Service() *TowerService {
|
||||
|
||||
func NewTower600Service() *TowerService {
|
||||
return NewTowerService(TowerType600)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user