All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(common/cool): 更新GetClient函数支持端口参数 更新GetClient函数签名以接收端口参数,并修改客户端映射键的计算方式, 添加GetClientOnly函数用于仅通过uid获取客户端。 fix(common/rpc): 修复RPC调用中的客户端获取方法 将GetClient调用替换为GetClientOnly,确保正确的客户端获取逻辑。 refactor(logic/controller): 重命名Port字段为UID并优化道具列表处理 将Controller结构体中的Port字段重命名为UID以更好地反映其用途, 优化GetUserItemList函数中道具列表的初始化和填充逻辑。 perf(logic): 调整性能分析web服务启动位置 将PprofWeb服务从全局启动移至调试模式下启动,优化服务配置。 refactor(logic/server): 更新服务器UID生成逻辑 修改Maincontroller的UID字段设置方式,使用服务器ID和端口组合生成唯一标识。 refactor(logic/service/player): 移除未使用的导入并优化怪物生成 移除未使用的service导入,优化怪物生成逻辑中的地图数据访问。 feat(logic/service/space): 添加PitS缓存映射并重构空间初始化 添加新的PitS字段
189 lines
4.0 KiB
Go
189 lines
4.0 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"blazing/common/utils"
|
|
"blazing/cool"
|
|
|
|
"blazing/modules/dict/model"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
type DictInfoService struct {
|
|
*cool.Service
|
|
}
|
|
|
|
// func init() {
|
|
|
|
// t, _ := NewDictInfoService().Data(context.TODO(), []string{"mapid"})
|
|
// fmt.Println(t)
|
|
|
|
// }
|
|
|
|
// Data方法, 用于获取数据
|
|
func (s *DictInfoService) Data(ctx context.Context, types []string) (data interface{}, err error) {
|
|
var (
|
|
dictInfoModel = model.NewDictInfo()
|
|
dictTypeModel = model.NewDictType()
|
|
)
|
|
mType := cool.DBM(dictTypeModel).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
})
|
|
// 如果types不为空, 则查询指定类型的数据
|
|
if len(types) > 0 {
|
|
mType = mType.Where("key in (?)", types)
|
|
}
|
|
// 查询所有类型
|
|
typeData, err := mType.All()
|
|
// 如果typeData为空, 则返回空
|
|
if typeData.IsEmpty() {
|
|
return g.Map{}, nil
|
|
}
|
|
data = g.Map{}
|
|
for _, v := range typeData {
|
|
m := cool.DBM(dictInfoModel)
|
|
result, err := m.Where("typeId", v["id"]).FieldsEx("id").Order("ordernum asc").All()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if result.IsEmpty() {
|
|
continue
|
|
}
|
|
data.(g.Map)[v["key"].String()] = result
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *DictInfoService) GetData(types string) (data map[uint32]model.DictInfo) {
|
|
var (
|
|
dictInfoModel = model.NewDictInfo()
|
|
dictTypeModel = model.NewDictType()
|
|
)
|
|
// 如果typeData为空, 则返回空
|
|
var ty *model.DictType
|
|
mType := cool.DBM(dictTypeModel)
|
|
mType.Where("key in (?)", types).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Scan(&ty)
|
|
|
|
// 如果typeData为空, 则返回空
|
|
if ty == nil {
|
|
return nil
|
|
}
|
|
m := cool.DBM(dictInfoModel)
|
|
var ress []model.DictInfo
|
|
m.Where("typeId", ty.ID).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Scan(&ress)
|
|
fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 {
|
|
|
|
return gconv.Uint32(t.Value) //物品id转id
|
|
})
|
|
return fusions
|
|
|
|
}
|
|
|
|
// 获取物品的最大数限制
|
|
func (s *DictInfoService) GetMax(value int64) (max uint32) {
|
|
|
|
m := cool.DBM(s.Model)
|
|
var ress *model.DictInfo
|
|
m.Where("value", value).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Scan(&ress)
|
|
if ress == nil {
|
|
return 0
|
|
}
|
|
|
|
return uint32(ress.Ordernum)
|
|
|
|
}
|
|
|
|
// 获取稀有精灵的光环显示
|
|
func (s *DictInfoService) GetShiny() []int {
|
|
//获取精灵的排序作为精灵的数组
|
|
m := cool.DBM(s.Model)
|
|
|
|
res, _ := m.Where("typeId", 10).Where("ordernum", 1).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Fields("value").All()
|
|
|
|
return res.Array("value").Ints()
|
|
|
|
}
|
|
func (s *DictInfoService) SetItemRemark(id int, b string) {
|
|
//获取精灵的排序作为精灵的数组
|
|
m := cool.DBM(s.Model)
|
|
|
|
m.Where("typeId", 6).Where("value", id).Data("remark", b).Update()
|
|
|
|
}
|
|
|
|
// ModifyAfter 修改后
|
|
func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
|
defer s.Service.ModifyAfter(ctx, method, param)
|
|
if method == "Delete" {
|
|
// 删除后,同时删除子节点
|
|
ids, ok := param["ids"]
|
|
if !ok {
|
|
return
|
|
}
|
|
for _, v := range ids.([]interface{}) {
|
|
err = delChildDict(gconv.Int64(v))
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// delChildDict 删除子字典
|
|
func delChildDict(id int64) error {
|
|
var (
|
|
dictInfoModel = model.NewDictInfo()
|
|
)
|
|
m := cool.DBM(dictInfoModel)
|
|
result, err := m.Where("parentId=?", id).Fields("id").All()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if result.IsEmpty() {
|
|
return nil
|
|
}
|
|
for _, v := range result {
|
|
delChildDict(v["id"].Int64())
|
|
}
|
|
_, err = m.Where("parentId=?", id).Delete()
|
|
return err
|
|
}
|
|
|
|
// NewDictInfoService 初始化 DictInfoService
|
|
func NewDictInfoService() *DictInfoService {
|
|
return &DictInfoService{
|
|
&cool.Service{
|
|
//UniqueKey: map[string]string{"name": "名称不能重复"},
|
|
Model: model.NewDictInfo(),
|
|
ListQueryOp: &cool.QueryOp{
|
|
FieldEQ: []string{"typeId"},
|
|
KeyWordField: []string{"name", "value"},
|
|
AddOrderby: g.MapStrStr{"createTime": "ASC"},
|
|
},
|
|
},
|
|
}
|
|
}
|