feat(talk): 优化采集逻辑并移除冗余字典服务调用
- 移除了 talk.go 中对 dict 模块的依赖,直接使用配置中的 ItemID - 修改了 talkconfig.go 中的 ItemID 类型为 uint32,提升一致性 - 调整 talk.go 和 talkconfig.go 的缓存获取方式,增强性能 - 更新了 pet_fusion_material_service.go 中字典服务调用方法 - 修复 talk 模型中 TalkID 字段的唯一索引问题 - 日志记录由 Error 改为 Info,避免误导性
This commit is contained in:
@@ -6,9 +6,6 @@ import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/blazing/service"
|
||||
|
||||
dict "blazing/modules/dict/service"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
@@ -39,11 +36,11 @@ func (h Controller) TalkCate(data *item.TalkCateInboundInfo, c *player.Player) (
|
||||
for _, v := range config {
|
||||
count := grand.N(int(v.ItemMinCount), int(v.ItemMaxCount))
|
||||
|
||||
r := dict.DictInfoServiceS.DataID("fusion")
|
||||
trueitemid := gconv.Uint32(r[gconv.Uint32(v.ItemID)].Remark)
|
||||
ret := c.ItemAdd(trueitemid, uint32(count))
|
||||
// r := dict.DictInfoServiceS.DataID("fusion")
|
||||
// trueitemid := gconv.Uint32(r[gconv.Uint32(v.ItemID)].Remark)
|
||||
ret := c.ItemAdd(uint32(v.ItemID), uint32(count))
|
||||
if ret {
|
||||
result.OutList = append(result.OutList, item.CateInfo{ID: trueitemid, Count: uint32(count)})
|
||||
result.OutList = append(result.OutList, item.CateInfo{ID: v.ItemID, Count: uint32(count)})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (h *ClientData) Recv(data common.TomeeHeader) {
|
||||
|
||||
if ok && aa != 0 { //这里实现回复错误包
|
||||
|
||||
cool.Loger.Error(context.Background(), aa.Code())
|
||||
glog.Info(context.Background(), data.UserID, data.CMD, aa.Code())
|
||||
t.SendPack(data.Pack(nil))
|
||||
|
||||
return
|
||||
|
||||
@@ -17,7 +17,7 @@ func NewTalk() *Talk {
|
||||
type Talk struct {
|
||||
*cool.Model
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_resource;comment:'所属玩家ID'" json:"player_id"`
|
||||
TalkID uint32 `gorm:"not null;unique;comment:'资源ID'" json:"talk_id"`
|
||||
TalkID uint32 `gorm:"not null;comment:'资源ID'" json:"talk_id"`
|
||||
Count uint32 `gorm:"not null;comment:'采集计数'" json:"count"`
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ type MineralCollectionConfig struct {
|
||||
DailyCollectCount uint32 `gorm:"column:daily_collect_count;not null;comment:每日可采集次数" json:"daily_collect_count"`
|
||||
|
||||
// ItemID 物品编号(对应道具系统ID)
|
||||
ItemID string `gorm:"column:item_id;type:varchar(16);not null;index:idx_mineral_collection_config_item_id;comment:物品编号(对应道具系统ID)" json:"item_id"`
|
||||
ItemID uint32 `gorm:"column:item_id; not null;index:idx_mineral_collection_config_item_id;comment:物品编号(对应道具系统ID)" json:"item_id"`
|
||||
// ItemMinCount 单次采集最小产出数量
|
||||
ItemMinCount uint32 `gorm:"column:item_min_count;not null;comment:单次采集最小产出数量" json:"item_min_count"`
|
||||
// ItemMaxCount 单次采集最大产出数量
|
||||
|
||||
@@ -36,7 +36,7 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 {
|
||||
|
||||
cacheKey := strings.Join(gconv.Strings(Material1[:]), ":")
|
||||
println(cacheKey, "获取融合id")
|
||||
fusions := service.DictInfoServiceS.DataRemark("fusion")
|
||||
fusions := service.DictInfoServiceS.GetData("fusion")
|
||||
|
||||
for _, v := range Material1 {
|
||||
_, ok := fusions[v]
|
||||
@@ -65,7 +65,7 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 {
|
||||
return effect, nil
|
||||
}, 0)
|
||||
|
||||
effect2s := service.DictInfoServiceS.DataID("effect")
|
||||
effect2s := service.DictInfoServiceS.GetData("effect")
|
||||
effect := ret.Interface().(*model.PetFusionMaterial)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -3,7 +3,6 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/dict/service"
|
||||
)
|
||||
|
||||
type TalkService struct {
|
||||
@@ -30,6 +29,11 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
||||
var talks *model.Talk
|
||||
m1.Where("talk_id", flag).Scan(&talks)
|
||||
if talks == nil {
|
||||
talks = model.NewTalk()
|
||||
talks.PlayerID = uint64(s.userid)
|
||||
talks.TalkID = uint32(flag)
|
||||
s.GModel(s.Model).Data(talks).FieldsEx("id").Insert()
|
||||
|
||||
return 0, true //如果表里没有记载数据,那么就可以直接挖矿
|
||||
}
|
||||
|
||||
@@ -41,9 +45,12 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
||||
return int(talks.Count), true
|
||||
}
|
||||
|
||||
maps := service.DictInfoServiceS.DataRemark("mapid")
|
||||
//maps := service.DictInfoServiceS.DataRemark("mapid")
|
||||
if len(TalkConfigServiceS.GetCache(flag)) == 0 {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
if uint32(maps[mapid].ID) != TalkConfigServiceS.GetCache(flag)[0].MapID {
|
||||
if uint32(mapid) != TalkConfigServiceS.GetCache(flag)[0].MapID {
|
||||
return 0, false //没在地图
|
||||
}
|
||||
if talks.Count >= TalkConfigServiceS.GetCache(flag)[0].DailyCollectCount {
|
||||
@@ -57,10 +64,10 @@ func (s *TalkService) Update(flag int) {
|
||||
m1 := s.GModel(s.Model)
|
||||
|
||||
var talks model.Talk
|
||||
m1.Scan(&talks)
|
||||
m1.Where("talk_id", flag).Scan(&talks)
|
||||
|
||||
talks.PlayerID = uint64(s.userid)
|
||||
talks.TalkID = uint32(flag)
|
||||
//talks.PlayerID = uint64(s.userid)
|
||||
//talks.TalkID = uint32(flag)
|
||||
talks.Count += 1
|
||||
m1.Save(talks)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
)
|
||||
@@ -23,8 +24,12 @@ func NewTalkConfigService() *TalkConfigService {
|
||||
}
|
||||
|
||||
func (s *TalkConfigService) GetCache(flag int) []model.MineralCollectionConfig {
|
||||
var config []model.MineralCollectionConfig
|
||||
cool.DBM(s.Model).Where("type", flag).Scan(&config)
|
||||
return config
|
||||
|
||||
ret, _ := s.Cache.GetOrSetFuncLock(context.Background(), flag, func(context.Context) (interface{}, error) {
|
||||
var config []model.MineralCollectionConfig
|
||||
cool.DBM(s.Model).Where("type", flag).Scan(&config)
|
||||
return config, nil
|
||||
}, 0)
|
||||
return ret.Interface().([]model.MineralCollectionConfig)
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ type DictInfo struct {
|
||||
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
|
||||
ordernum int32 `gorm:"column:ordernum;type:int;not null" json:"ordernum"` // 排序
|
||||
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
|
||||
ParentID *int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID
|
||||
Value int32 `gorm:"column:value;type:int;not null" json:"value"`
|
||||
ParentID *int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID
|
||||
}
|
||||
|
||||
// TableName DictInfo's table name
|
||||
|
||||
@@ -44,7 +44,7 @@ func (s *DictInfoService) Data(ctx context.Context, types []string) (data interf
|
||||
data = g.Map{}
|
||||
for _, v := range typeData {
|
||||
m := cool.DBM(dictInfoModel)
|
||||
result, err := m.Where("typeId", v["id"]).Fields("id", "name", "parentId", "typeId").Order("ordernum asc").All()
|
||||
result, err := m.Where("typeId", v["id"]).FieldsEx("id", "remark").Order("ordernum asc").All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,7 +55,8 @@ func (s *DictInfoService) Data(ctx context.Context, types []string) (data interf
|
||||
}
|
||||
return
|
||||
}
|
||||
func (s *DictInfoService) DataRemark(types string) (data map[uint32]model.DictInfo) {
|
||||
|
||||
func (s *DictInfoService) GetData(types string) (data map[uint32]model.DictInfo) {
|
||||
var (
|
||||
dictInfoModel = model.NewDictInfo()
|
||||
dictTypeModel = model.NewDictType()
|
||||
@@ -75,35 +76,7 @@ func (s *DictInfoService) DataRemark(types string) (data map[uint32]model.DictIn
|
||||
m.Where("typeId", ty.ID).Scan(&ress)
|
||||
fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.Remark) //物品id转id
|
||||
})
|
||||
return fusions, nil
|
||||
}, 0)
|
||||
|
||||
return ret.Interface().(map[uint32]model.DictInfo)
|
||||
|
||||
}
|
||||
func (s *DictInfoService) DataID(types string) (data map[uint32]model.DictInfo) {
|
||||
var (
|
||||
dictInfoModel = model.NewDictInfo()
|
||||
dictTypeModel = model.NewDictType()
|
||||
)
|
||||
ret, _ := cacheDict.GetOrSetFunc(context.Background(), types, func(context.Context) (interface{}, error) {
|
||||
// 如果typeData为空, 则返回空
|
||||
var ty *model.DictType
|
||||
mType := cool.DBM(dictTypeModel)
|
||||
mType.Where("key in (?)", types).Scan(&ty)
|
||||
|
||||
// 如果typeData为空, 则返回空
|
||||
if ty == nil {
|
||||
return []model.DictInfo{}, nil
|
||||
}
|
||||
m := cool.DBM(dictInfoModel)
|
||||
var ress []model.DictInfo
|
||||
m.Where("typeId", ty.ID).Scan(&ress)
|
||||
fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.ID) //物品id转id
|
||||
return gconv.Uint32(t.Value) //物品id转id
|
||||
})
|
||||
return fusions, nil
|
||||
}, 0)
|
||||
|
||||
Reference in New Issue
Block a user