This commit is contained in:
wh_zcy 2023-03-17 15:31:50 +08:00
parent adbe3b7415
commit 5080121075
2 changed files with 15 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package rtask package rtask
import ( import (
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis" "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) return this.moduleRtask.ModuleUser.ChangeUserExpand(uid, ex_update)
} }
//查询用户随机任务 // 查询用户随机任务
func (this *ModelRtask) GetRtask(uid string) *pb.DBRtask { func (this *ModelRtask) GetRtask(uid string) *pb.DBRtask {
rtask := &pb.DBRtask{Uid: uid} rtask := &pb.DBRtask{Uid: uid}
err := this.Get(uid, rtask) err := this.Get(uid, rtask)
@ -79,16 +80,23 @@ func (this *ModelRtask) checkCondi(uid string, condiId int32) (err error, ok boo
} }
//验证限定条件 //验证限定条件
var condi *rtaskCondi 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) errors.Errorf("condiID: %v handle no found", condiId)
return return
} }
if condi, ok = cond.(*rtaskCondi); !ok {
err = fmt.Errorf("condiType err")
return
}
if condi.verify == nil { if condi.verify == nil {
errors.Errorf("condiID: %v", condiId) errors.Errorf("condiID: %v", condiId)
return return
} }
conf, err:= this.moduleRtask.configure.getRtaskTypeById(condiId) conf, err := this.moduleRtask.configure.getRtaskTypeById(condiId)
if err!= nil { if err != nil {
errors.Errorf("conf not found condiID: %v", condiId) errors.Errorf("conf not found condiID: %v", condiId)
return return
} }

View File

@ -41,13 +41,12 @@ type ModuleRtask struct {
modelRtaskRecord *ModelRtaskRecord modelRtaskRecord *ModelRtaskRecord
api *apiComp api *apiComp
configure *configureComp configure *configureComp
lock sync.Mutex handleMap sync.Map //map[int32]*rtaskCondi //任务校验处理器
handleMap map[int32]*rtaskCondi //任务校验处理器
} }
func NewModule() core.IModule { func NewModule() core.IModule {
return &ModuleRtask{ 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) { func (this *ModuleRtask) registerVerifyHandle(condiId int32, condi *rtaskCondi) {
// if _, ok := this.handleMap[condiId]; !ok { this.handleMap.Store(condiId, condi)
// this.handleMap[condiId] = condi
// }
this.lock.Lock()
defer this.lock.Unlock()
this.handleMap[condiId] = condi
} }
func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) { func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {