From 5080121075e32417f22b581e2fc0e7e0e4847f25 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Fri, 17 Mar 2023 15:31:50 +0800 Subject: [PATCH] update --- modules/rtask/model_rtask.go | 16 ++++++++++++---- modules/rtask/module.go | 12 +++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/modules/rtask/model_rtask.go b/modules/rtask/model_rtask.go index 7b9be748b..91bb60c90 100644 --- a/modules/rtask/model_rtask.go +++ b/modules/rtask/model_rtask.go @@ -1,6 +1,7 @@ package rtask import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/redis" @@ -36,7 +37,7 @@ func (this *ModelRtask) updateUserRtaskId(uid string, rtaskId int32) (err error) return this.moduleRtask.ModuleUser.ChangeUserExpand(uid, ex_update) } -//查询用户随机任务 +// 查询用户随机任务 func (this *ModelRtask) GetRtask(uid string) *pb.DBRtask { rtask := &pb.DBRtask{Uid: uid} err := this.Get(uid, rtask) @@ -79,16 +80,23 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo } //验证限定条件 var condi *rtaskCondi - if condi, ok = this.moduleRtask.handleMap[condiId]; !ok { + cond, ok := this.moduleRtask.handleMap.Load(condiId) + if !ok { errors.Errorf("condiID: %v handle no found", condiId) return } + + if condi, ok = cond.(*rtaskCondi); !ok { + err = fmt.Errorf("condiType err") + return + } + if condi.verify == nil { errors.Errorf("condiID: %v", condiId) return } - conf, err:= this.moduleRtask.configure.getRtaskTypeById(condiId) - if err!= nil { + conf, err := this.moduleRtask.configure.getRtaskTypeById(condiId) + if err != nil { errors.Errorf("conf not found condiID: %v", condiId) return } diff --git a/modules/rtask/module.go b/modules/rtask/module.go index e935783eb..922c9522e 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -41,13 +41,12 @@ type ModuleRtask struct { modelRtaskRecord *ModelRtaskRecord api *apiComp configure *configureComp - lock sync.Mutex - handleMap map[int32]*rtaskCondi //任务校验处理器 + handleMap sync.Map //map[int32]*rtaskCondi //任务校验处理器 } func NewModule() core.IModule { return &ModuleRtask{ - handleMap: make(map[int32]*rtaskCondi), + // handleMap: make(map[int32]*rtaskCondi), } } @@ -76,12 +75,7 @@ func (this *ModuleRtask) OnInstallComp() { } func (this *ModuleRtask) registerVerifyHandle(condiId int32, condi *rtaskCondi) { - // if _, ok := this.handleMap[condiId]; !ok { - // this.handleMap[condiId] = condi - // } - this.lock.Lock() - defer this.lock.Unlock() - this.handleMap[condiId] = condi + this.handleMap.Store(condiId, condi) } func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {