feat(player): 重构任务状态管理逻辑

将任务状态相关的 GetTask 和 SetTask 方法从 player 包迁移至 model.PlayerInfo 结构体中,
统一通过 c.Info 调
This commit is contained in:
2025-12-08 19:16:37 +08:00
parent 8983222dcb
commit ec0552b59a
13 changed files with 192 additions and 138 deletions

View File

@@ -8,6 +8,7 @@ import (
"blazing/modules/dict/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcache"
"github.com/gogf/gf/v2/util/gconv"
)
@@ -53,29 +54,38 @@ func (s *DictInfoService) Data(ctx context.Context, types []string) (data interf
}
return
}
func (s *DictInfoService) DataOne(types string) (data []model.DictInfo, err error) {
func (s *DictInfoService) DataOne(types string) (data []model.DictInfo) {
var (
dictInfoModel = model.NewDictInfo()
dictTypeModel = model.NewDictType()
)
// 如果typeData为空, 则返回空
var ty *model.DictType
mType := cool.DBM(dictTypeModel)
mType.Where("key in (?)", types).Scan(&ty)
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)
// 如果typeData为空, 则返回空
if ty == nil {
return []model.DictInfo{}, nil
}
m := cool.DBM(dictInfoModel)
var ress []model.DictInfo
m.Where("typeId", ty.ID).Scan(&ress)
return ress, nil
}, 0)
return ret.Interface().([]model.DictInfo)
return ress, nil
}
var (
cacheDict = gcache.New()
)
// ModifyAfter 修改后
func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) {
cacheDict.Clear(context.Background())
if method == "Delete" {
// 删除后,同时删除子节点
ids, ok := param["ids"]