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:
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user