刷新机制

This commit is contained in:
1
2025-08-28 15:20:05 +00:00
parent 921a121e11
commit e550502e36
3 changed files with 48 additions and 18 deletions

View File

@@ -28,7 +28,7 @@ import (
var tt task.GetTaskBufOutboundInfo
func main() {
// Test_kick()
cmd.Main.Run(gctx.New())
}

View File

@@ -3,9 +3,11 @@ package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"fmt"
"strconv"
"time"
"github.com/dop251/goja"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
@@ -19,12 +21,6 @@ func NewMonsterService() *MonsterService {
return &MonsterService{
&cool.Service{
Model: model.NewMonsterRefresh(),
PageQueryOp: &cool.QueryOp{
FieldEQ: []string{"status", "type"},
},
UniqueKey: map[string]string{
"name": "任务名称不能重复",
},
},
}
}
@@ -37,13 +33,12 @@ func (s *MonsterService) ModifyAfter(ctx g.Ctx, method string, param g.MapStrAny
Name: model.TableNameMonsterRefresh + gconv.String(param["map_id"]),
Force: false,
}))
//todo 待测试,缓存优化
return nil
}
func (s *MonsterService) GetId(mapid uint32) uint32 {
func (s *MonsterService) GetId(mapid uint32) []model.MonsterRefresh {
//todo 待修改更新时候删除缓存
m := cool.DBM(s.Model).Where("map_id", mapid).Cache(
gdb.CacheOption{
Duration: time.Hour,
@@ -54,14 +49,49 @@ func (s *MonsterService) GetId(mapid uint32) uint32 {
var tt []model.MonsterRefresh
m.Scan(&tt)
for _, v := range tt {
// for _, v := range tt {
if v.MapID == int32(mapid) {
return uint32(v.MonsterID)
// if v.MapID == int32(mapid) {
// return uint32(v.MonsterID)
}
// }
}
return 0
// }
return tt
}
func Test_kick() {
const SCRIPT = `
function shouldRefresh(userId, day, dayOfWeek, hour, minute) {
return true;
}
`
t, _ := goja.Compile("test.js", SCRIPT, false)
vm := goja.New()
_, err := vm.RunProgram(t)
if err != nil {
panic(err)
}
sum, ok := goja.AssertFunction(vm.Get("shouldRefresh"))
if !ok {
panic("Not a function")
}
res, err := sum(
goja.Undefined(),
vm.ToValue(1),
vm.ToValue(time.Now().Day()),
vm.ToValue(time.Now().Weekday()),
vm.ToValue(time.Now().Hour()),
vm.ToValue(time.Now().Minute()),
)
if err != nil {
panic(err)
}
fmt.Println(res)
// Output: 42
}

View File

@@ -8,8 +8,8 @@ import (
type UserService struct {
userid uint32
task *cool.Service
reg *cool.Service
task *cool.Service //任务
reg *cool.Service //注册
}
func NewUserService(id uint32) *UserService {