添加任务埋点类型

This commit is contained in:
wh_zcy 2023-03-30 15:14:55 +08:00
parent cfe15751c0
commit f5385563c6
4 changed files with 72 additions and 90 deletions

View File

@ -63,7 +63,7 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq)
return return
} }
a.module.Debug("刷新", log.Field{Key: "taskIds", Value: taskIds}) // a.module.Debug("刷新", log.Field{Key: "taskIds", Value: taskIds})
//更新公告任务 //更新公告任务
if err := a.module.modelDispatch.updateTasks(session.GetUserId(), d.Nb, taskIds); err != nil { if err := a.module.modelDispatch.updateTasks(session.GetUserId(), d.Nb, taskIds); err != nil {
a.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()}) a.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()})

View File

@ -79,7 +79,7 @@ func (this *modelDispatch) getDBDispatch(uid string) (dis *pb.DBDispatch) {
} }
// 获取随机任务ID // 获取随机任务ID
func (this *modelDispatch) getTasksWeight(uid string, d *pb.DBDispatch) int32 { func (this *modelDispatch) getTasksWeight(d *pb.DBDispatch) int32 {
if d == nil { if d == nil {
return 0 return 0
} }
@ -120,40 +120,9 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
var n int var n int
n = len(dispatch.Nb.Tasks) n = len(dispatch.Nb.Tasks)
var existIds []int32
for _, v := range dispatch.Nb.Tasks {
existIds = append(existIds, v.TaskId)
}
if n == 0 { if n == 0 {
//随机6个任务 //随机任务
total := 0 tasks = this.randomTask(dispatch, NOTICE_NUM)
for total < 6 {
tId := this.getTasksWeight(uid, dispatch)
if tId == 0 {
return
}
//去重
if _, ok := utils.Findx(existIds, int32(tId)); !ok {
existIds = append(existIds, int32(tId))
total++
}
}
for _, id := range existIds {
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
if err != nil {
continue
}
//公告持续截至时间
duration := configure.Now().Unix() + int64(taskConf.Taskcd)
tasks = append(tasks, &pb.DispatchTask{
TaskId: int32(id),
Duration: duration,
})
}
} else { } else {
var randCount int var randCount int
for i := 0; i < len(dispatch.Nb.Tasks); i++ { for i := 0; i < len(dispatch.Nb.Tasks); i++ {
@ -166,97 +135,107 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
} }
} }
//追加随机 //追加随机
tasks = append(tasks, this.addRandomTask(uid, dispatch, randCount)...) tasks = append(tasks, this.addRandomTask(dispatch, randCount)...)
} }
return return
} }
func (this *modelDispatch) addRandomTask(uid string, dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) { func (this *modelDispatch) randomTask(dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) {
total := 0
for total < n {
rid := this.getTasksWeight(dispatch)
if rid == 0 {
return nil
}
if len(dispatch.Nb.Tasks) == 0 {
dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, &pb.DispatchTask{
TaskId: rid,
})
total++
} else {
//去重
exist := false
for _, v := range dispatch.Nb.Tasks {
if v.TaskId == rid {
exist = true
}
}
if !exist {
dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, &pb.DispatchTask{
TaskId: rid,
})
total++
}
}
}
//更新任务持续截至时间
for _, task := range dispatch.Nb.Tasks {
taskConf, err := this.module.configure.getDispatchTaskConf(task.TaskId)
if err != nil {
return nil
}
if task.Duration == 0 {
duration := configure.Now().Unix() + int64(taskConf.Taskcd)
task.Duration = duration
}
tasks = append(tasks, task)
}
return
}
func (this *modelDispatch) addRandomTask(dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) {
if n <= 0 { if n <= 0 {
tasks = dispatch.Nb.Tasks tasks = dispatch.Nb.Tasks
return return
} }
var existIds []int32 return this.randomTask(dispatch, n)
for _, v := range dispatch.Nb.Tasks {
existIds = append(existIds, v.TaskId)
}
total := 0
for total < n {
rid := this.getTasksWeight(uid, dispatch)
if rid == 0 {
return nil
}
//去重
if _, ok := utils.Findx(existIds, int32(rid)); !ok {
existIds = append(existIds, int32(rid))
total++
}
}
for _, id := range existIds {
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
if err != nil {
return nil
}
//公告持续截至时间
duration := configure.Now().Unix() + int64(taskConf.Taskcd)
dt := &pb.DispatchTask{
TaskId: int32(id),
Duration: duration,
}
tasks = append(tasks, dt)
}
return
} }
// 替换指定的已完成任务 // 替换指定的已完成任务
func (this *modelDispatch) replaceTask(uid string, taskId int32, dispatch *pb.DBDispatch) (tasks []*pb.DispatchTask, oldTask *pb.DispatchTask) { func (this *modelDispatch) replaceTask(uid string, taskId int32, dispatch *pb.DBDispatch) (tasks []*pb.DispatchTask, oldTask *pb.DispatchTask) {
tasks = dispatch.Nb.Tasks
var randCount int var randCount int
for i := 0; i < len(tasks); i++ { for i := 0; i < len(dispatch.Nb.Tasks); i++ {
//替换状态是完成的任务 //替换状态是完成的任务
if tasks[i].Status == 2 { if dispatch.Nb.Tasks[i].Status == 2 {
if taskId != tasks[i].TaskId { if taskId != dispatch.Nb.Tasks[i].TaskId {
continue continue
} }
oldTask = tasks[i] oldTask = dispatch.Nb.Tasks[i]
//删除 //删除
tasks = append(tasks[:i], tasks[i+1:]...) dispatch.Nb.Tasks = append(dispatch.Nb.Tasks[:i], dispatch.Nb.Tasks[i+1:]...)
i-- i--
randCount++ randCount++
break break
} }
} }
tasks = append(tasks, this.addRandomTask(uid, dispatch, randCount)...) tasks = append(tasks, this.addRandomTask(dispatch, randCount)...)
return return
} }
// 替换所有完成的任务 // 替换所有完成的任务
func (this *modelDispatch) replaceFinishedTask(uid string, dispatch *pb.DBDispatch) (tasks []*pb.DispatchTask, oldtasks []*pb.DispatchTask) { func (this *modelDispatch) replaceFinishedTask(uid string, dispatch *pb.DBDispatch) (tasks []*pb.DispatchTask, oldtasks []*pb.DispatchTask) {
var randCount int var randCount int
tmp := dispatch.Nb.Tasks for i := 0; i < len(dispatch.Nb.Tasks); i++ {
for i := 0; i < len(tmp); i++ {
//替换状态是完成的任务 //替换状态是完成的任务
if tmp[i].Status == 2 { if dispatch.Nb.Tasks[i].Status == 2 {
//删除 //删除
oldtasks = append(oldtasks, tmp[i]) oldtasks = append(oldtasks, dispatch.Nb.Tasks[i])
dispatch.Nb.Tasks = append(dispatch.Nb.Tasks[:i], dispatch.Nb.Tasks[i+1:]...) dispatch.Nb.Tasks = append(dispatch.Nb.Tasks[:i], dispatch.Nb.Tasks[i+1:]...)
i-- i--
randCount++ randCount++
} else { } else {
tasks = append(tasks, tmp[i]) tasks = append(tasks, dispatch.Nb.Tasks[i])
} }
} }
tasks = append(tasks, this.addRandomTask(uid, dispatch, randCount)...) tasks = append(tasks, this.addRandomTask(dispatch, randCount)...)
return return
} }
@ -420,9 +399,9 @@ func (this *modelDispatch) updateNotice(uid string, dispatch *pb.DBDispatch) err
//刷新任务 //刷新任务
count := len(dispatch.Nb.Tasks) count := len(dispatch.Nb.Tasks)
if count < 6 { if count < NOTICE_NUM {
randCount = 6 - count randCount = NOTICE_NUM - count
dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, this.addRandomTask(uid, dispatch, randCount)...) dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, this.addRandomTask(dispatch, randCount)...)
} }
//判断是否有下一等级 //判断是否有下一等级

View File

@ -6,6 +6,9 @@ import (
"go_dreamfactory/modules" "go_dreamfactory/modules"
) )
// 默认6条公告数量
const NOTICE_NUM int = 6
// 派遣 // 派遣
type Dispatch struct { type Dispatch struct {
modules.ModuleBase modules.ModuleBase

View File

@ -186,7 +186,7 @@ func (this *ModuleRtask) getHandle(tt comm.TaskType) (condis []*rtaskCondi) {
comm.Rtype26, comm.Rtype27, comm.Rtype28, comm.Rtype38, comm.Rtype26, comm.Rtype27, comm.Rtype28, comm.Rtype38,
comm.Rtype39, comm.Rtype50, comm.Rtype51, comm.Rtype53, comm.Rtype39, comm.Rtype50, comm.Rtype51, comm.Rtype53,
comm.Rtype54, comm.Rtype57, comm.Rtype58, comm.Rtype60, comm.Rtype54, comm.Rtype57, comm.Rtype58, comm.Rtype60,
comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104, comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype73, comm.Rtype88, comm.Rtype104,
comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131, comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131,
comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146, comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146,
comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156: comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156: