```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

refactor(common/utils): 重构concurrent_swiss_map使用官方sync.Map实现

- 替换原有的第三方并发map实现,改为基于标准库sync.Map的封装
- 保持完全的API兼容性,原有配置方法变为无实际作用的占位符
- 优化Range方法实现,移除goroutine/channel开销,避免潜在的死锁风险
- 移除依赖的外部库和
This commit is contained in:
昔念
2026-02-25 13:20:38 +08:00
parent 931809edc4
commit c00a796203
10 changed files with 140 additions and 331 deletions

View File

@@ -37,8 +37,6 @@ type PetBaseConfig struct {
SKill []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS技能'" json:"skill"`
Remark string `gorm:"comment:'BOSS备注'" json:"remark"`
// ISMELEE uint32 `gorm:"not null;default:0;comment:'是否乱斗配置'" json:"is_melee"`
// // ===================== BOSS奖励规则Boss_bonus =====================
// BonusProbability int32 `gorm:"not null;default:0;comment:'打赢BOSS给奖励概率-分子值域0-1000默认0'" json:"bonus_probability"`

View File

@@ -13,11 +13,14 @@ type BossConfig struct {
*cool.Model // 嵌入通用Model包含ID/创建时间/更新时间等通用字段)
PetBaseConfig
MapID int32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"`
BossID int32 `gorm:"not null;index;comment:'所属BOSSID'" json:"boss_id" description:"BOSSID"`
Order int32 `gorm:"not null;comment:'排序'" json:"order" description:"排序"`
MapID int32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"`
Script string `gorm:"size:1024;default:'';comment:'BOSS脚本'" json:"script"` //boss出招逻辑做成js脚本
Ordernum int32 `gorm:"not null;comment:'排序'" json:"ordernum" description:"排序"`
ParentID int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID
Remark string `gorm:"comment:'BOSS备注'" json:"remark"`
//是否可捕捉MapPit
IsCapture int `gorm:"type:int;default:0;comment:'是否可捕捉'" json:"is_capture"`
Script string `gorm:"size:1024;default:'';comment:'BOSS脚本'" json:"script"` //boss出招逻辑做成js脚本
}

View File

@@ -1,47 +0,0 @@
package model
import (
"blazing/cool"
)
const (
TableNameMapBoss = "config_map_boss" // 地图BOSS配置表记录BOSS归属、属性、刷新规则、奖励等
)
// MapBoss 地图BOSS核心配置模型完全仿照MapPit实现风格
type MapBoss struct {
*BaseConfig // 复用通用基础配置ID/创建时间/更新时间/删除时间/备注等)
*Event // 嵌入BOSS事件配置
MapID int32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"`
// BOSS唯一标识ID
BossID int `gorm:"not null;index;comment:'BOSSID'" json:"boss_id"`
BossName string `gorm:"type:varchar(100);default:'';comment:'BOSS名称'" json:"boss_name" description:"BOSS名称"`
WinBonusID int `gorm:"type:int;default:0;comment:'胜利奖励ID'" json:"win_bonus_id"`
FailBonusID int `gorm:"type:int;default:0;comment:'失败奖励ID'" json:"fail_bonus_id"`
//是否可捕捉MapPit
IsCapture int `gorm:"type:int;default:0;comment:'是否可捕捉'" json:"is_capture"`
}
// TableName 指定MapBoss对应的数据库表名遵循原模型规范
func (*MapBoss) TableName() string {
return TableNameMapBoss
}
// GroupName 指定表所属的分组保持和MapPit一致
func (*MapBoss) GroupName() string {
return "default"
}
// NewMapBoss 创建一个新的MapBoss实例初始化通用BaseConfig和BossEvent
func NewMapBoss() *MapBoss {
return &MapBoss{
BaseConfig: NewBaseConfig(),
Event: &Event{},
}
}
// init 初始化表结构(程序启动时自动创建/同步表)
func init() {
cool.CreateTable(&MapBoss{})
}

View File

@@ -22,26 +22,26 @@ const (
// MapNode 地图节点配置模型
type MapNode struct {
*BaseConfig
*Event // 嵌入BOSS事件配置
// 基础关联字段
MapID uint32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"`
NodeType int `gorm:"not null;default:0;comment:'节点类型0是游戏自带分支,其余自增)'" json:"node_type" description:"节点类型"`
NodeID uint32 `gorm:"not null;default:0;comment:'节点ID'" json:"node_id" description:"节点ID"`
NodeName string `gorm:"type:varchar(100);default:'';comment:'节点名称'" json:"node_name" description:"节点名称"`
//节点激活脚本
// NodeActiveScript string `gorm:"type:text;comment:'节点激活脚本'" json:"node_active_script" description:"节点激活脚本"`
//
// 节点核心配置
NodeType int `gorm:"not null;default:0;comment:'节点类型1-BOSS2-NPC3-场景触发4-传送门)'" json:"node_type" description:"节点类型"`
PositionX float64 `gorm:"not null;default:0;comment:'节点X坐标'" json:"position_x" description:"X坐标"`
PositionY float64 `gorm:"not null;default:0;comment:'节点Y坐标'" json:"position_y" description:"Y坐标"`
WinBonusID int `gorm:"type:int;default:0;comment:'胜利奖励ID'" json:"win_bonus_id"`
FailBonusID int `gorm:"type:int;default:0;comment:'失败奖励ID'" json:"fail_bonus_id"`
// 剧情相关配置
TriggerPlotID uint32 `gorm:"default:0;comment:'触发剧情ID0表示无剧情'" json:"trigger_plot_id" description:"触发剧情ID"`
BindPlotIDs []uint32 `gorm:"type:int[];comment:'绑定的剧情ID列表'" json:"bind_plot_ids" description:"绑定剧情ID列表"`
TriggerPlotID uint32 `gorm:"default:0;comment:'触发剧情ID0表示无剧情'" json:"trigger_plot_id" description:"触发剧情ID"`
//BindPlotIDs []uint32 `gorm:"type:int[];comment:'绑定的剧情ID列表'" json:"bind_plot_ids" description:"绑定剧情ID列表"`
//完成后的脚本回调比如战胜和击败绑定不同的任务ID以及剧情绑定不同的ID
PlotFinishScript string `gorm:"type:text;comment:'剧情完成后脚本回调'" json:"plot_finish_script" description:"剧情完成后脚本回调"`
//回调通boss打完给前端发送固定事件
//PlotFinishScript string `gorm:"type:text;comment:'剧情完成后脚本回调'" json:"plot_finish_script" description:"剧情完成后脚本回调"`
// BOSS相关配置
BindBossID uint32 `gorm:"default:0;comment:'绑定的BOSS ID0表示无BOSS'" json:"bind_boss_id" description:"绑定BOSS ID"`
}

View File

@@ -11,12 +11,11 @@ const (
TableNameBraveTowerConfig = "config_tower_600" // 勇者之塔600配置表
)
// -------------------------- 核心基类:所有塔配置的通用结构 --------------------------
type BaseTowerConfig struct {
*BaseConfig
TowerLevel uint32 `gorm:"not null;default:0;uniqueIndex;comment:'塔层数(唯一标识每层配置)'" json:"tower_level" description:"塔层数"`
BossIds []uint32 `gorm:"not null;type:jsonb;default:'[]';comment:'绑定BOSS ID数组关联config_pet_boss表主键'" json:"boss_ids" description:"绑定BOSS数组"`
Name string `gorm:"type:varchar(100);default:'';comment:'塔名称'" json:"name" description:"塔名称"`
TowerLevel uint32 `gorm:"not null;default:0;uniqueIndex;comment:'塔层数'" json:"tower_level" `
BossIds []uint32 `gorm:"not null;type:jsonb;default:'[]';comment:'绑定BOSS ID数组'" json:"boss_ids" `
}
// NewBaseTowerConfig 创建基础塔配置实例(所有塔类型共用)
@@ -26,9 +25,6 @@ func NewBaseTowerConfig() *BaseTowerConfig {
}
}
// -------------------------- 各塔类型专属配置模型(无额外字段,仅绑定不同表名)--------------------------
// Tower110Config 勇者之塔110配置模型
type Tower110Config struct {
*BaseTowerConfig
}

View File

@@ -15,7 +15,11 @@ func NewBossService() *BossService {
Model: model.NewBossConfig(),
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"desc"},
FieldEQ: []string{"boss_id", "map_id"},
FieldEQ: []string{"map_id"},
},
ListQueryOp: &cool.QueryOp{
KeyWordField: []string{"desc"},
FieldEQ: []string{"map_id", "parentId"},
},
},
}

View File

@@ -15,6 +15,7 @@ func NewMapService() *MapService {
Model: model.NewMapConfig(),
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"remake"},
FieldEQ: []string{"map_id"},
},
},
}

View File

@@ -12,7 +12,7 @@ type MapBossService struct {
func NewMapBossService() *MapBossService {
return &MapBossService{
&cool.Service{
Model: model.NewMapBoss(),
Model: model.NewMapNode(),
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"remake"},
FieldEQ: []string{"map_id"},