You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.9 KiB
96 lines
2.9 KiB
4 months ago
|
package serviceGame
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/gogf/gf/v2/database/gdb"
|
||
|
"github.com/gogf/gf/v2/frame/g"
|
||
|
"github.com/gogf/gf/v2/util/gconv"
|
||
|
"tyj_admin/api/v1/game"
|
||
|
"tyj_admin/internal/consts"
|
||
|
"tyj_admin/internal/dao"
|
||
|
"tyj_admin/internal/model/do"
|
||
|
"tyj_admin/library/liberr"
|
||
|
)
|
||
|
|
||
|
type IGameClientBug interface {
|
||
|
List(ctx context.Context, req *game.ClientBugListReq) (res *game.ClientBugListRes, err error)
|
||
|
Add(ctx context.Context, req *game.ClientBugAddReq) (res *game.ClientBugAddRes, err error)
|
||
|
UpdateState(ctx context.Context, req *game.OperateClientBugReq) (res *game.OperateClientBugRes, err error)
|
||
|
}
|
||
|
|
||
|
type gameClientBugImpl struct {
|
||
|
}
|
||
|
|
||
|
func GameClientBug() IGameClientBug {
|
||
|
return &gameClientBugImpl{}
|
||
|
}
|
||
|
|
||
|
func (c gameClientBugImpl) UpdateState(ctx context.Context, req *game.OperateClientBugReq) (res *game.OperateClientBugRes, err error) {
|
||
|
err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
|
||
|
err = g.Try(ctx, func(ctx context.Context) {
|
||
|
_, err = dao.GameBugClient.Ctx(ctx).TX(tx).WherePri(req.Id).Update(do.GameBugClient{State: 1})
|
||
|
})
|
||
|
return err
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (c gameClientBugImpl) List(ctx context.Context, req *game.ClientBugListReq) (res *game.ClientBugListRes, err error) {
|
||
|
res = new(game.ClientBugListRes)
|
||
|
g.Try(ctx, func(ctx context.Context) {
|
||
|
model := dao.GameBugClient.Ctx(ctx)
|
||
|
if req.State != 0 {
|
||
|
model = model.Where("state=?", gconv.Int(req.State-1))
|
||
|
}
|
||
|
if req.Uid != 0 {
|
||
|
model = model.Where("uid=?", req.Uid)
|
||
|
}
|
||
|
if req.Log != "" {
|
||
|
model = model.Where("bug like ?", req.Log+"%")
|
||
|
}
|
||
|
if req.Stack != "" {
|
||
|
model = model.Where("stack_trace like ?", req.Stack+"%")
|
||
|
}
|
||
|
if req.LowTime != 0 {
|
||
|
model = model.Where(`UNIX_TIMESTAMP(create_time)>=?`, req.LowTime/1000)
|
||
|
}
|
||
|
if req.UpTime != 0 {
|
||
|
model = model.Where(`UNIX_TIMESTAMP(create_time)<=?`, req.UpTime/1000)
|
||
|
}
|
||
|
res.Total, err = model.Count()
|
||
|
liberr.ErrIsNil(ctx, err, "获取BUG数据失败")
|
||
|
if req.PageNum == 0 {
|
||
|
req.PageNum = 1
|
||
|
}
|
||
|
res.CurrentPage = req.PageNum
|
||
|
if req.PageSize == 0 {
|
||
|
req.PageSize = consts.PageSize
|
||
|
}
|
||
|
err = model.Page(res.CurrentPage, req.PageSize).OrderDesc("id").Scan(&res.Bugs)
|
||
|
liberr.ErrIsNil(ctx, err, "获取bug数据失败")
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (c gameClientBugImpl) Add(ctx context.Context, req *game.ClientBugAddReq) (res *game.ClientBugAddRes, err error) {
|
||
|
err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
|
||
|
err = g.Try(ctx, func(ctx context.Context) {
|
||
|
_, err = dao.GameBugClient.Ctx(ctx).TX(tx).InsertAndGetId(do.GameBugClient{
|
||
|
Uid: req.Uid,
|
||
|
Bug: req.Bug,
|
||
|
LogType: req.LogType,
|
||
|
StackTrace: req.StackTrace,
|
||
|
Channel: req.Channel,
|
||
|
SubChannel: req.SubChannel,
|
||
|
DeviceModel: req.DeviceModel,
|
||
|
DeviceType: req.DeviceType,
|
||
|
OperationSystem: req.OperationSystem,
|
||
|
SystemMemorySize: req.SystemMemorySize,
|
||
|
})
|
||
|
|
||
|
})
|
||
|
return err
|
||
|
})
|
||
|
return
|
||
|
}
|