Files
bl/modules/blazing/service/monster_refresh.go

68 lines
1.3 KiB
Go
Raw Normal View History

package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"strconv"
"time"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type MonsterService struct {
*cool.Service
}
func NewMonsterService() *MonsterService {
return &MonsterService{
&cool.Service{
Model: model.NewMonsterRefresh(),
PageQueryOp: &cool.QueryOp{
FieldEQ: []string{"status", "type"},
},
UniqueKey: map[string]string{
"name": "任务名称不能重复",
},
},
}
}
func (s *MonsterService) ModifyAfter(ctx g.Ctx, method string, param g.MapStrAny) (err error) {
gconv.String(param["map_id"])
cool.DBM(s.Model).Cache((gdb.CacheOption{
Duration: -1,
Name: model.TableNameMonsterRefresh + gconv.String(param["map_id"]),
Force: false,
}))
//todo 待测试,缓存优化
return nil
}
func (s *MonsterService) GetId(mapid uint32) uint32 {
//todo 待修改更新时候删除缓存
m := cool.DBM(s.Model).Where("map_id", mapid).Cache(
gdb.CacheOption{
Duration: time.Hour,
Name: model.TableNameMonsterRefresh + strconv.Itoa(int(mapid)),
Force: false,
},
)
var tt []model.MonsterRefresh
m.Scan(&tt)
for _, v := range tt {
if v.MapID == int32(mapid) {
return uint32(v.MonsterID)
}
}
return 0
}