|
|
@@ -515,13 +515,9 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
var computer log.Computer
|
|
|
computerData, _ := computer.OnlinePcCodeCache()
|
|
|
var csReplys []*log.LogComputer
|
|
|
- // 不统计本地测试电脑
|
|
|
- notStatistics := map[string]int{
|
|
|
- "001": 1,
|
|
|
- "002": 1,
|
|
|
- }
|
|
|
for code, r := range codeMps {
|
|
|
- if _, ok := notStatistics[code]; ok {
|
|
|
+ // 不统计不在电脑列表里的
|
|
|
+ if _, ok := computerData[code]; !ok {
|
|
|
continue
|
|
|
}
|
|
|
accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
|
|
|
@@ -569,7 +565,7 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
csReply.ComputerHourAverageRate = csReply.TaskSuccessNum / runTime
|
|
|
csReply.Status = 2
|
|
|
global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Where("game_id = ?", 0).Delete(&log.LogComputer{})
|
|
|
- if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
|
|
|
+ if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Where("game_id = ?", gameId).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
|
|
|
// 已存在,更新
|
|
|
mp := make(map[string]interface{})
|
|
|
if csReply.Operator != "" {
|
|
|
@@ -583,7 +579,7 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
mp["game_fee_rate"] = csReply.GameFeeRate
|
|
|
mp["computer_hour_average_rate"] = csReply.ComputerHourAverageRate
|
|
|
mp["enter_main"] = csReply.EnterMain
|
|
|
- err = global.GVA_DB.Table("log_computer").Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Updates(mp).Error
|
|
|
+ err = global.GVA_DB.Table("log_computer").Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Where("game_id = ?", gameId).Updates(mp).Error
|
|
|
if err != nil {
|
|
|
global.GVA_LOG.Error("更新数据失败", zap.Error(err))
|
|
|
}
|
|
|
@@ -1248,3 +1244,74 @@ func (exa *ServiceStatisticsLog) ComputeRateList2Excel(infoList []*response.Comp
|
|
|
err := excel.SaveAs(filePath)
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+// 电脑效率七天数据查询
|
|
|
+func (s *ServiceStatisticsLog) ComputerSevenStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo, order string, desc bool) (statisticsLogsComputer []*response.ComputerStatisticsReply1, total int64, err error) {
|
|
|
+ date := api.CreateDate
|
|
|
+ endDate := ""
|
|
|
+ startDate := ""
|
|
|
+ if date == "" {
|
|
|
+ endDate = time.Now().Add(-time.Hour * 24).Format("2006-01-02")
|
|
|
+ startDate = time.Now().Add(-time.Hour * 24 * 8).Format("2006-01-02")
|
|
|
+ } else {
|
|
|
+ formatTime, _ := time.Parse("2006-01-02", date)
|
|
|
+ endDate = date
|
|
|
+ startDate = formatTime.Add(-time.Hour * 24 * 7).Format("2006-01-02")
|
|
|
+ }
|
|
|
+ db := global.GVA_DB.Model(&log.LogComputer{})
|
|
|
+ db = db.Where("create_date >= ? and create_date <= ?", startDate, endDate)
|
|
|
+ db = db.Where("pc_code = ?", api.PcCode)
|
|
|
+
|
|
|
+ err = db.Count(&total).Error
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ limit := info.PageSize
|
|
|
+ offset := info.PageSize * (info.Page - 1)
|
|
|
+ var statisticsLogs []*log.LogComputer
|
|
|
+ db = db.Limit(limit).Offset(offset)
|
|
|
+ db.Group("create_date")
|
|
|
+ if order != "" {
|
|
|
+ var OrderStr string
|
|
|
+ // 设置有效排序key 防止sql注入
|
|
|
+ // 感谢 Tom4t0 提交漏洞信息
|
|
|
+ orderMap := make(map[string]bool, 3)
|
|
|
+ orderMap["pc_code"] = true
|
|
|
+ orderMap["game_id"] = true
|
|
|
+ orderMap["operator"] = 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 statisticsLogsComputer, total, err
|
|
|
+ }
|
|
|
+ err = db.Order(OrderStr).Find(&statisticsLogs).Error
|
|
|
+ } else {
|
|
|
+ err = db.Order("id").Find(&statisticsLogs).Error
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, statisticsLog := range statisticsLogs {
|
|
|
+ statisticsLogComputer := new(response.ComputerStatisticsReply1)
|
|
|
+ statisticsLogComputer.PcCode = statisticsLog.PcCode
|
|
|
+ statisticsLogComputer.Operator = statisticsLog.Operator
|
|
|
+ statisticsLogComputer.CreateDate = statisticsLog.CreateDate[:10]
|
|
|
+ statisticsLogComputer.GameId = statisticsLog.GameId
|
|
|
+ statisticsLogComputer.PullAccountNum = statisticsLog.PullAccountNum
|
|
|
+ statisticsLogComputer.TaskSuccessNum = statisticsLog.TaskSuccessNum
|
|
|
+ statisticsLogComputer.TargetNum = statisticsLog.TargetNum
|
|
|
+ statisticsLogComputer.ComputerFreeTime = statisticsLog.ComputerFreeTime
|
|
|
+ statisticsLogComputer.ComputerFeeRate = statisticsLog.ComputerFeeRate
|
|
|
+ statisticsLogComputer.EnterMain = statisticsLog.EnterMain
|
|
|
+ statisticsLogComputer.ComputerFeeRate = statisticsLog.ComputerFeeRate
|
|
|
+ statisticsLogComputer.ComputerHourAverageRate = statisticsLog.ComputerHourAverageRate
|
|
|
+ statisticsLogsComputer = append(statisticsLogsComputer, statisticsLogComputer)
|
|
|
+ }
|
|
|
+ return statisticsLogsComputer, total, err
|
|
|
+}
|