|
@@ -1365,31 +1365,34 @@ func (s *ServiceStatisticsLog) ComputerSevenStatistics(ctx context.Context, api
|
|
|
|
|
|
|
|
// 定时统计设备信息
|
|
// 定时统计设备信息
|
|
|
func (s *ServiceStatisticsLog) DeviceStatistics() {
|
|
func (s *ServiceStatisticsLog) DeviceStatistics() {
|
|
|
- var devices []log.DeviceLog
|
|
|
|
|
date := time.Now().Format("2006-01-02")
|
|
date := time.Now().Format("2006-01-02")
|
|
|
- db := global.GVA_DB.Model(&log.DeviceLog{})
|
|
|
|
|
- db.Where("create_date = ?", date)
|
|
|
|
|
- db.Where("is_err = ?", 1)
|
|
|
|
|
- db.Group("game_id")
|
|
|
|
|
- db.Select("game_id")
|
|
|
|
|
- db.Find(&devices)
|
|
|
|
|
- if len(devices) == 0 {
|
|
|
|
|
|
|
+ db := global.GVA_DB.Model(&task.GameTask{})
|
|
|
|
|
+ var apiList []task.GameTask
|
|
|
|
|
+ db = db.Where("is_del = ?", -1)
|
|
|
|
|
+ db = db.Where("status = ?", 1)
|
|
|
|
|
+ db.Order("id desc").Find(&apiList)
|
|
|
|
|
+ if len(apiList) == 0 {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ retainedDeviceErr := s.DeviceIdStatistics(date, 1)
|
|
|
|
|
+ newDeviceErr := s.DeviceIdStatistics(date, 2)
|
|
|
|
|
+ undefinedErr := s.DeviceErrLogStatistics(date, 1)
|
|
|
|
|
+ DefinedErr := s.DeviceErrLogStatistics(date, 2)
|
|
|
completeData, _ := s.GameTargetComplete.CompleteTaskData(date)
|
|
completeData, _ := s.GameTargetComplete.CompleteTaskData(date)
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
- for _, game := range devices {
|
|
|
|
|
|
|
+ for _, game := range apiList {
|
|
|
deviceLog := new(log.DeviceStatistics)
|
|
deviceLog := new(log.DeviceStatistics)
|
|
|
- deviceLog.GameId = game.GameId
|
|
|
|
|
- gameDeviceAccountErrKey := fmt.Sprintf(loging2.GameDeviceAccountErrKey, date, game.GameId)
|
|
|
|
|
- gameDeviceErrKey := fmt.Sprintf(loging2.GameDeviceErrKey, date, game.GameId)
|
|
|
|
|
|
|
+ gameId := game.TaskId
|
|
|
|
|
+ deviceLog.GameId = gameId
|
|
|
|
|
+ gameDeviceAccountErrKey := fmt.Sprintf(loging2.GameDeviceAccountErrKey, date, gameId)
|
|
|
|
|
+ gameDeviceErrKey := fmt.Sprintf(loging2.GameDeviceErrKey, date, gameId)
|
|
|
deviceLog.AccountErrNum, _ = s.GetCacheNum(ctx, gameDeviceAccountErrKey)
|
|
deviceLog.AccountErrNum, _ = s.GetCacheNum(ctx, gameDeviceAccountErrKey)
|
|
|
deviceLog.DeviceErrNum, _ = s.GetCacheNum(ctx, gameDeviceErrKey)
|
|
deviceLog.DeviceErrNum, _ = s.GetCacheNum(ctx, gameDeviceErrKey)
|
|
|
- n, _ := s.LogicalLog.NodeLogGetNum(ctx, date, game.GameId, "4300000", loging2.OkStatus, 0)
|
|
|
|
|
- r, _ := s.LogicalLog.NodeLogGetNum(ctx, date, game.GameId, "4300000", loging2.OkStatus, 1)
|
|
|
|
|
|
|
+ n, _ := s.LogicalLog.NodeLogGetNum(ctx, date, gameId, "4300000", loging2.OkStatus, 0)
|
|
|
|
|
+ r, _ := s.LogicalLog.NodeLogGetNum(ctx, date, gameId, "4300000", loging2.OkStatus, 1)
|
|
|
deviceLog.SimulatorStartNum = n + r
|
|
deviceLog.SimulatorStartNum = n + r
|
|
|
- deviceLog.NewComplete = completeData[game.GameId].NewComplete
|
|
|
|
|
- deviceLog.RetainedComplete = completeData[game.GameId].RetainedComplete
|
|
|
|
|
|
|
+ deviceLog.NewComplete = completeData[gameId].NewComplete
|
|
|
|
|
+ deviceLog.RetainedComplete = completeData[gameId].RetainedComplete
|
|
|
if deviceLog.DeviceErrNum != 0 {
|
|
if deviceLog.DeviceErrNum != 0 {
|
|
|
deviceLog.DeviceErrRate = utils.Decimal(float64(deviceLog.DeviceErrNum) / float64(deviceLog.RetainedComplete) * 100)
|
|
deviceLog.DeviceErrRate = utils.Decimal(float64(deviceLog.DeviceErrNum) / float64(deviceLog.RetainedComplete) * 100)
|
|
|
}
|
|
}
|
|
@@ -1397,41 +1400,138 @@ func (s *ServiceStatisticsLog) DeviceStatistics() {
|
|
|
deviceLog.AccountErrRate = utils.Decimal(float64(deviceLog.AccountErrNum) / float64(deviceLog.NewComplete) * 100)
|
|
deviceLog.AccountErrRate = utils.Decimal(float64(deviceLog.AccountErrNum) / float64(deviceLog.NewComplete) * 100)
|
|
|
}
|
|
}
|
|
|
deviceLog.CreateDate = date
|
|
deviceLog.CreateDate = date
|
|
|
- if !errors.Is(global.GVA_DB.Where("create_date = ?", date).Where("game_id = ?", game.GameId).First(&log.DeviceStatistics{}).Error, gorm.ErrRecordNotFound) {
|
|
|
|
|
- global.GVA_DB.Where("create_date = ?", date).Where("game_id = ?", game.GameId).Omit("create_date,game_id").Updates(deviceLog)
|
|
|
|
|
|
|
+ if _, ok := retainedDeviceErr[gameId]; ok {
|
|
|
|
|
+ if retainedDeviceErr[gameId].Count != 0 {
|
|
|
|
|
+ deviceLog.RetainedDeviceIdErr = retainedDeviceErr[gameId].Count
|
|
|
|
|
+ deviceLog.RetainedDeviceIdRate = utils.Decimal(float64(deviceLog.RetainedDeviceIdErr) / float64(deviceLog.RetainedComplete) * 100)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if _, ok := newDeviceErr[gameId]; ok {
|
|
|
|
|
+ if newDeviceErr[gameId].Count != 0 {
|
|
|
|
|
+ deviceLog.NewDeviceIdErr = newDeviceErr[gameId].Count
|
|
|
|
|
+ deviceLog.NewDeviceIdRate = utils.Decimal(float64(deviceLog.NewDeviceIdErr) / float64(deviceLog.NewComplete) * 100)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if _, ok := undefinedErr[gameId]; ok {
|
|
|
|
|
+ if undefinedErr[gameId].Count != 0 {
|
|
|
|
|
+ deviceLog.UndefinedErr = undefinedErr[gameId].Count
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if _, ok := DefinedErr[gameId]; ok {
|
|
|
|
|
+ if DefinedErr[gameId].Count != 0 {
|
|
|
|
|
+ deviceLog.DefinedErr = DefinedErr[gameId].Count
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if !errors.Is(global.GVA_DB.Where("create_date = ?", date).Where("game_id = ?", gameId).First(&log.DeviceStatistics{}).Error, gorm.ErrRecordNotFound) {
|
|
|
|
|
+ global.GVA_DB.Where("create_date = ?", date).Where("game_id = ?", gameId).Omit("create_date,game_id").Updates(&deviceLog)
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
- global.GVA_DB.Save(deviceLog)
|
|
|
|
|
|
|
+ global.GVA_DB.Create(&deviceLog)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type DeviceErr struct {
|
|
|
|
|
+ GameId int `json:"game_id"`
|
|
|
|
|
+ Count int `json:"count"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (s *ServiceStatisticsLog) DeviceIdStatistics(date string, status int) map[int]DeviceErr {
|
|
|
|
|
+ var devicesErr []DeviceErr
|
|
|
|
|
+ db := global.GVA_DB.Model(&log.ScriptDeviceErr{})
|
|
|
|
|
+ db.Where("create_date = ?", date)
|
|
|
|
|
+ db.Where("status = ?", status)
|
|
|
|
|
+ db.Group("current_game_id")
|
|
|
|
|
+ db.Select("current_game_id game_id, count(*) count")
|
|
|
|
|
+ db.Find(&devicesErr)
|
|
|
|
|
+ if len(devicesErr) == 0 {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ devicesErrMaps := make(map[int]DeviceErr, len(devicesErr))
|
|
|
|
|
+ for _, game := range devicesErr {
|
|
|
|
|
+ devicesErrMaps[game.GameId] = game
|
|
|
|
|
+ }
|
|
|
|
|
+ return devicesErrMaps
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (s *ServiceStatisticsLog) DeviceErrLogStatistics(date string, status int) map[int]DeviceErr {
|
|
|
|
|
+ var devicesErr []DeviceErr
|
|
|
|
|
+ db := global.GVA_DB.Model(&log.DeviceErrLog{})
|
|
|
|
|
+ db.Where("create_date = ?", date)
|
|
|
|
|
+ db.Where("status = ?", status)
|
|
|
|
|
+ db.Group("game_id")
|
|
|
|
|
+ db.Select("game_id, count(*) count")
|
|
|
|
|
+ db.Find(&devicesErr)
|
|
|
|
|
+ if len(devicesErr) == 0 {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ devicesErrMaps := make(map[int]DeviceErr, len(devicesErr))
|
|
|
|
|
+ for _, game := range devicesErr {
|
|
|
|
|
+ devicesErrMaps[game.GameId] = game
|
|
|
|
|
+ }
|
|
|
|
|
+ return devicesErrMaps
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (exa *ServiceStatisticsLog) DeviceErrRateExcel(statistics []*log.DeviceStatisticsReply, filePath string) error {
|
|
|
|
|
+ excel := excelize.NewFile()
|
|
|
|
|
+ excel.SetSheetRow("Sheet1", "A1", &[]string{"游戏ID", "负责人", "留存设备异常", "留存设备id异常", "留存完成目标", "留存异常率", "留存设备id异常率", "新增设备异常", "新增设备id异常", "新增完成目标", "新增异常率", "新增设备id异常率", "统计日期"})
|
|
|
|
|
+ for i, statisticsLog := range statistics {
|
|
|
|
|
+ axis := fmt.Sprintf("A%d", i+2)
|
|
|
|
|
+ excel.SetSheetRow("Sheet1", axis, &[]interface{}{
|
|
|
|
|
+ statisticsLog.GameId,
|
|
|
|
|
+ statisticsLog.User,
|
|
|
|
|
+ statisticsLog.DeviceErrNum,
|
|
|
|
|
+ statisticsLog.RetainedDeviceIdErr,
|
|
|
|
|
+ statisticsLog.RetainedComplete,
|
|
|
|
|
+ statisticsLog.DeviceErrRate,
|
|
|
|
|
+ statisticsLog.RetainedDeviceIdRate,
|
|
|
|
|
+ statisticsLog.AccountErrNum,
|
|
|
|
|
+ statisticsLog.NewDeviceIdErr,
|
|
|
|
|
+ statisticsLog.NewComplete,
|
|
|
|
|
+ statisticsLog.AccountErrRate,
|
|
|
|
|
+ statisticsLog.NewDeviceIdRate,
|
|
|
|
|
+ statisticsLog.CreateDate[:10],
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
+ err := excel.SaveAs(filePath)
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (s *ServiceStatisticsLog) GetDeviceStatistics(ctx context.Context, api log.DeviceStatistics, info request.PageInfo, order string, desc bool) (statistics []*log.DeviceStatistics, total int64, err error) {
|
|
|
|
|
|
|
+func (s *ServiceStatisticsLog) GetDeviceStatistics(ctx context.Context, api log.DeviceStatistics, info request.PageInfo, order string, desc bool) (statistics []*log.DeviceStatisticsReply, total int64, err error) {
|
|
|
if api.CreateDate == "" {
|
|
if api.CreateDate == "" {
|
|
|
api.CreateDate = time.Now().Format("2006-01-02")
|
|
api.CreateDate = time.Now().Format("2006-01-02")
|
|
|
}
|
|
}
|
|
|
- db := global.GVA_DB.Model(&log.DeviceStatistics{})
|
|
|
|
|
- db = db.Where("create_date = ?", api.CreateDate)
|
|
|
|
|
|
|
+ db := global.GVA_DB.Table("device_statistics ds")
|
|
|
|
|
+
|
|
|
|
|
+ db = db.Joins("left join game_task gt on gt.task_id = ds.game_id")
|
|
|
|
|
+ db = db.Where("ds.create_date = ?", api.CreateDate)
|
|
|
if api.GameId != 0 {
|
|
if api.GameId != 0 {
|
|
|
- db = db.Where("game_id = ?", api.GameId)
|
|
|
|
|
|
|
+ db = db.Where("ds.game_id = ?", api.GameId)
|
|
|
}
|
|
}
|
|
|
err = db.Count(&total).Error
|
|
err = db.Count(&total).Error
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
return nil, 0, err
|
|
|
}
|
|
}
|
|
|
|
|
+ db = db.Select("ds.*,user")
|
|
|
limit := info.PageSize
|
|
limit := info.PageSize
|
|
|
offset := info.PageSize * (info.Page - 1)
|
|
offset := info.PageSize * (info.Page - 1)
|
|
|
db = db.Limit(limit).Offset(offset)
|
|
db = db.Limit(limit).Offset(offset)
|
|
|
if order != "" {
|
|
if order != "" {
|
|
|
var OrderStr string
|
|
var OrderStr string
|
|
|
- orderMap := make(map[string]bool, 3)
|
|
|
|
|
|
|
+ orderMap := make(map[string]bool, 7)
|
|
|
orderMap["device_err_num"] = true
|
|
orderMap["device_err_num"] = true
|
|
|
orderMap["game_id"] = true
|
|
orderMap["game_id"] = true
|
|
|
orderMap["account_err_num"] = true
|
|
orderMap["account_err_num"] = true
|
|
|
|
|
+ orderMap["device_err_rate"] = true
|
|
|
|
|
+ orderMap["account_err_rate"] = true
|
|
|
|
|
+ orderMap["retained_device_id_rate"] = true
|
|
|
|
|
+ orderMap["new_device_id_rate"] = true
|
|
|
if orderMap[order] {
|
|
if orderMap[order] {
|
|
|
if desc {
|
|
if desc {
|
|
|
- OrderStr = order + " desc"
|
|
|
|
|
|
|
+ OrderStr = "ds." + order + " desc"
|
|
|
} else {
|
|
} else {
|
|
|
- OrderStr = order
|
|
|
|
|
|
|
+ OrderStr = "ds." + order
|
|
|
}
|
|
}
|
|
|
} else { // didn't matched any order key in `orderMap`
|
|
} else { // didn't matched any order key in `orderMap`
|
|
|
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
|
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
|
@@ -1494,6 +1594,54 @@ func (s *ServiceStatisticsLog) GetDeviceInfo(ctx context.Context, api log.Device
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (s *ServiceStatisticsLog) GetDeviceIdErr(ctx context.Context, api log.ScriptDeviceErr, info request.PageInfo, order string, desc bool) (deviceLogs []*log.ScriptDeviceErr, total int64, err error) {
|
|
|
|
|
+ if api.CreateDate == "" {
|
|
|
|
|
+ api.CreateDate = time.Now().Format("2006-01-02")
|
|
|
|
|
+ }
|
|
|
|
|
+ db := global.GVA_DB.Model(&log.ScriptDeviceErr{})
|
|
|
|
|
+ if api.GameId != 0 {
|
|
|
|
|
+ db = db.Where("current_game_id = ?", api.GameId)
|
|
|
|
|
+ }
|
|
|
|
|
+ if api.Operator != "" {
|
|
|
|
|
+ db = db.Where("operator = ?", api.Operator)
|
|
|
|
|
+ }
|
|
|
|
|
+ if api.Status != 0 {
|
|
|
|
|
+ db = db.Where("status = ?", api.Status)
|
|
|
|
|
+ }
|
|
|
|
|
+ db = db.Where("create_date = ?", api.CreateDate)
|
|
|
|
|
+ err = db.Count(&total).Error
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, 0, err
|
|
|
|
|
+ }
|
|
|
|
|
+ limit := info.PageSize
|
|
|
|
|
+ offset := info.PageSize * (info.Page - 1)
|
|
|
|
|
+ db = db.Limit(limit).Offset(offset)
|
|
|
|
|
+ if order != "" {
|
|
|
|
|
+ var OrderStr string
|
|
|
|
|
+ // 设置有效排序key 防止sql注入
|
|
|
|
|
+ // 感谢 Tom4t0 提交漏洞信息
|
|
|
|
|
+ orderMap := make(map[string]bool, 3)
|
|
|
|
|
+ orderMap["game_id"] = true
|
|
|
|
|
+ if orderMap[order] {
|
|
|
|
|
+ if desc {
|
|
|
|
|
+ OrderStr = order + " desc"
|
|
|
|
|
+ } else {
|
|
|
|
|
+ OrderStr = order
|
|
|
|
|
+ }
|
|
|
|
|
+ } else { // didn't matched any order key in `orderMap`
|
|
|
|
|
+ global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
|
|
|
|
+ return deviceLogs, total, err
|
|
|
|
|
+ }
|
|
|
|
|
+ err = db.Order(OrderStr).Find(&deviceLogs).Error
|
|
|
|
|
+ } else {
|
|
|
|
|
+ err = db.Order("id").Find(&deviceLogs).Error
|
|
|
|
|
+ }
|
|
|
|
|
+ for _, statistic := range deviceLogs {
|
|
|
|
|
+ statistic.CreateDate = api.CreateDate
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (s *ServiceStatisticsLog) GetDeviceContrastInfo(ctx context.Context, api log.DeviceLog) (deviceLogs []log.DeviceLog, err error) {
|
|
func (s *ServiceStatisticsLog) GetDeviceContrastInfo(ctx context.Context, api log.DeviceLog) (deviceLogs []log.DeviceLog, err error) {
|
|
|
db := global.GVA_DB.Model(&log.DeviceLog{})
|
|
db := global.GVA_DB.Model(&log.DeviceLog{})
|
|
|
var device log.DeviceLog
|
|
var device log.DeviceLog
|