task 新增同步游戏人生任务接口
This commit is contained in:
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"server/internal/consts"
|
||||
"server/internal/dao"
|
||||
@ -16,6 +18,7 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -435,3 +438,94 @@ func (s *sTask) GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRe
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sTask) SyncTaskFromGamelife(ctx context.Context) (out *model.SyncTaskOut, err error) {
|
||||
stores, err := dao.Stores.Ctx(ctx).Fields(dao.Stores.Columns().Id, dao.Stores.Columns().NetbarAccount).All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
games, err := dao.Games.Ctx(ctx).Fields(dao.Games.Columns().GameName, dao.Games.Columns().GameId).All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, store := range stores {
|
||||
store := store // 捕获循环变量
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
for _, game := range games {
|
||||
activity, err := gamelife.GetGamelifeClient(ctx).RequestActivity(
|
||||
ctx,
|
||||
&model.QQNetbarActivityIn{
|
||||
ServiceName: consts.GetNonLoginTaskList,
|
||||
TaskParam: model.TaskParam{
|
||||
Gid: game["game_id"].Int(),
|
||||
NetBarAccount: store["netbar_account"].String(),
|
||||
Num: 50,
|
||||
Pageidx: "",
|
||||
},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
glog.Errorf(ctx, "获取任务失败,网吧=%s,游戏=%s,错误=%v",
|
||||
store["netbar_account"].String(), game["game_name"].String(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
result, ok := activity.(*model.GameTaskResponse)
|
||||
if !ok {
|
||||
glog.Errorf(ctx, "数据类型转换失败,网吧=%s,游戏=%s",
|
||||
store["netbar_account"].String(), game["game_name"].String())
|
||||
continue
|
||||
}
|
||||
|
||||
var insertCount, skipCount int
|
||||
|
||||
for _, task := range result.TaskList {
|
||||
exist, err := dao.Tasks.Ctx(ctx).
|
||||
Where("task_id = ? AND store_id = ? AND game_id = ?",
|
||||
task.TaskID, store["id"].Int(), game["game_id"].Int()).
|
||||
Count()
|
||||
if err != nil {
|
||||
glog.Errorf(ctx, "检查任务是否存在失败,task_id=%s,网吧=%s,游戏=%s,错误=%v",
|
||||
task.TaskID, store["netbar_account"].String(), game["game_name"].String(), err)
|
||||
continue
|
||||
}
|
||||
if exist > 0 {
|
||||
skipCount++
|
||||
continue
|
||||
}
|
||||
|
||||
taskMap := gconv.Map(task)
|
||||
delete(taskMap, "PrizeList")
|
||||
delete(taskMap, "prize_list")
|
||||
|
||||
_, err = dao.Tasks.Ctx(ctx).Data(do.Tasks{
|
||||
TaskId: task.TaskID,
|
||||
StoreId: store["id"].Int(),
|
||||
GameId: game["game_id"].Int(),
|
||||
NetbarAcconut: store["netbar_account"].String(),
|
||||
Task: gconv.Bytes(taskMap),
|
||||
}).Insert()
|
||||
if err != nil {
|
||||
glog.Errorf(ctx, "插入任务失败,task_id=%s,网吧=%s,游戏=%s,错误=%v",
|
||||
task.TaskID, store["netbar_account"].String(), game["game_name"].String(), err)
|
||||
continue
|
||||
}
|
||||
insertCount++
|
||||
}
|
||||
|
||||
glog.Infof(ctx, "任务同步完成,网吧=%s,游戏=%s,插入任务=%d,跳过任务=%d",
|
||||
store["netbar_account"].String(), game["game_name"].String(), insertCount, skipCount)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return
|
||||
}
|
||||
|
||||
@ -109,3 +109,9 @@ type UserTaskRecordsListOut struct {
|
||||
List []UserTask2
|
||||
Total int
|
||||
}
|
||||
|
||||
type SyncTaskIn struct {
|
||||
}
|
||||
type SyncTaskOut struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
||||
_ "server/utility/gamelife"
|
||||
//_ "server/utility/mqtt/emqx"
|
||||
_ "server/utility/mqtt/emqx"
|
||||
_ "server/utility/myCasbin"
|
||||
_ "server/utility/oss/aliyun"
|
||||
_ "server/utility/rsa"
|
||||
|
||||
@ -22,6 +22,7 @@ type (
|
||||
// GetTask 完成任务
|
||||
GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.GetTaskOut, err error)
|
||||
GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRecordsListIn) (out *model.UserTaskRecordsListOut, err error)
|
||||
SyncTaskFromGamelife(ctx context.Context) (out *model.SyncTaskOut, err error)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user