|
|
@@ -6,12 +6,14 @@ import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
"go.uber.org/zap"
|
|
|
"gorm.io/gorm"
|
|
|
"log-server/global"
|
|
|
"log-server/model/log"
|
|
|
"log-server/model/log/request"
|
|
|
"log-server/model/log/response"
|
|
|
+ "log-server/model/system"
|
|
|
loging2 "log-server/service/log/loging"
|
|
|
"math"
|
|
|
"strconv"
|
|
|
@@ -488,6 +490,7 @@ func (s *ServiceStatisticsLog) EveryDayResetStatisticsCache() {
|
|
|
global.GVA_LOG.Info("游戏重置缓存完成!")
|
|
|
}
|
|
|
|
|
|
+// 添加和更新电脑指标数据
|
|
|
func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
ctx := context.Background()
|
|
|
codeMps, err := s.LogicalLog.GetComputerCache(ctx, s.LogicalLog.CurrentDate())
|
|
|
@@ -499,7 +502,8 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
}
|
|
|
key := fmt.Sprintf(taskStatistics, s.LogicalLog.CurrentDate())
|
|
|
onlineComputerMpa, _ := s.LogicalLog.GetOnlineComputerNumCache(ctx, s.LogicalLog.CurrentDate())
|
|
|
- fmt.Println(onlineComputerMpa)
|
|
|
+ var computer log.Computer
|
|
|
+ computerData, _ := computer.OnlinePcCodeCache()
|
|
|
var csReplys []*log.LogComputer
|
|
|
for code, r := range codeMps {
|
|
|
accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
|
|
|
@@ -514,13 +518,13 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
if err != nil {
|
|
|
continue
|
|
|
}
|
|
|
-
|
|
|
+ delete(computerData, code)
|
|
|
for gameId, num := range accountMps {
|
|
|
csReply := new(log.LogComputer)
|
|
|
+ csReply.PcCode = code
|
|
|
if _, ok := onlineComputerMpa[csReply.PcCode]; ok {
|
|
|
delete(onlineComputerMpa, csReply.PcCode)
|
|
|
}
|
|
|
- csReply.PcCode = code
|
|
|
csReply.Operator = r
|
|
|
data, err := global.GVA_REDIS.HGet(ctx, key, gameId).Result()
|
|
|
if err != nil {
|
|
|
@@ -545,6 +549,7 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
csReply.GameFeeRate = s.GetStatisticsFeeRate(ctx, csReply.GameId)
|
|
|
runTime := time.Now().Hour() + 1 - csReply.ComputerFreeTime
|
|
|
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) {
|
|
|
// 已存在,更新
|
|
|
@@ -579,10 +584,34 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
if len(onlineComputerMpa) != 0 {
|
|
|
var onlineComputer []*log.LogComputer
|
|
|
for pcCode, op := range onlineComputerMpa {
|
|
|
+ delete(computerData, pcCode)
|
|
|
csReply := new(log.LogComputer)
|
|
|
csReply.PcCode = pcCode
|
|
|
csReply.Operator = op
|
|
|
csReply.CreateDate = time.Now().Format("2006-01-02")
|
|
|
+ csReply.Status = 1
|
|
|
+ if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ onlineComputer = append(onlineComputer, csReply)
|
|
|
+ }
|
|
|
+ if len(onlineComputer) != 0 {
|
|
|
+ err = global.GVA_DB.Table("log_computer").Create(onlineComputer).Error
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("更新数据失败", zap.Error(err))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 没记录电脑数据
|
|
|
+ if len(computerData) != 0 {
|
|
|
+ var onlineComputer []*log.LogComputer
|
|
|
+ for pcCode, op := range computerData {
|
|
|
+ csReply := new(log.LogComputer)
|
|
|
+ csReply.PcCode = pcCode
|
|
|
+ csReply.Operator = op
|
|
|
+ csReply.CreateDate = time.Now().Format("2006-01-02")
|
|
|
+ csReply.Status = -1
|
|
|
if !errors.Is(global.GVA_DB.Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
|
|
|
continue
|
|
|
}
|
|
|
@@ -704,6 +733,9 @@ func (s *ServiceStatisticsLog) OnlineComputerStatistics(ctx context.Context, api
|
|
|
if api.PcCode != "" {
|
|
|
db = db.Where("pc_code = ?", api.PcCode)
|
|
|
}
|
|
|
+ if api.Status != 0 {
|
|
|
+ db = db.Where("status = ?", api.Status)
|
|
|
+ }
|
|
|
db = db.Group("pc_code")
|
|
|
err := db.Count(&total).Error
|
|
|
if err != nil {
|
|
|
@@ -744,14 +776,7 @@ func (s *ServiceStatisticsLog) OnlineComputerStatistics(ctx context.Context, api
|
|
|
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.ComputerHourAverageRate = statisticsLog.ComputerHourAverageRate
|
|
|
+ statisticsLogComputer.Status = statisticsLog.Status
|
|
|
statisticsLogsComputer = append(statisticsLogsComputer, statisticsLogComputer)
|
|
|
}
|
|
|
return statisticsLogsComputer, total, err
|
|
|
@@ -923,6 +948,10 @@ func (s *ServiceStatisticsLog) GetComputerNum(date string) int64 {
|
|
|
// 在线电脑接口
|
|
|
func (s *ServiceStatisticsLog) ComputerHeartbeat(c context.Context, onlineComputer request.OnlineComputerRequest) error {
|
|
|
err := s.LogicalLog.SetOnlineComputerNumCache(c, s.LogicalLog.CurrentDate(), onlineComputer.PcCode, onlineComputer.Operator)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ s.LogicalLog.SetPcReportingLog(c, onlineComputer.PcCode, onlineComputer.Operator)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -934,3 +963,59 @@ func (s *ServiceStatisticsLog) ComputerTest(c context.Context) (interface{}, err
|
|
|
}
|
|
|
return mps, err
|
|
|
}
|
|
|
+
|
|
|
+// 定时检查电脑情况
|
|
|
+func (s *ServiceStatisticsLog) RegularCheckPc() {
|
|
|
+ ctx := context.Background()
|
|
|
+ date := s.LogicalLog.CurrentDate()
|
|
|
+ // 获取当天已上报的电脑数据
|
|
|
+ onlineComputerMpa, _ := s.LogicalLog.GetOnlineComputerNumCache(ctx, date)
|
|
|
+ // 获取数据库的数据
|
|
|
+ var computer log.Computer
|
|
|
+ computers, err := computer.OnlinePcCodeCache()
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("获取租机表数据失败", zap.Error(err))
|
|
|
+ }
|
|
|
+ // 查询两小时内上报的数据
|
|
|
+ var noReportingPc []string
|
|
|
+ for pc, _ := range onlineComputerMpa {
|
|
|
+ num := s.LogicalLog.GetPcReportingLog(ctx, pc)
|
|
|
+ delete(computers, pc)
|
|
|
+ if num == 0 {
|
|
|
+ noReportingPc = append(noReportingPc, pc)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 未上报逻辑
|
|
|
+ var errReportingPc []string
|
|
|
+ for pc, _ := range computers {
|
|
|
+ errReportingPc = append(errReportingPc, pc)
|
|
|
+ }
|
|
|
+ if len(errReportingPc) != 0 {
|
|
|
+ // 发信息数据群里
|
|
|
+ fmt.Println("异常上报数据: ", errReportingPc, len(errReportingPc))
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(noReportingPc) != 0 {
|
|
|
+ // 发信息数据群里
|
|
|
+ fmt.Println("两小时内未检测到上报数据: ", noReportingPc, len(noReportingPc))
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (exa *ServiceStatisticsLog) ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error {
|
|
|
+ excel := excelize.NewFile()
|
|
|
+ excel.SetSheetRow("Sheet1", "A1", &[]string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"})
|
|
|
+ for i, menu := range infoList {
|
|
|
+ axis := fmt.Sprintf("A%d", i+2)
|
|
|
+ excel.SetSheetRow("Sheet1", axis, &[]interface{}{
|
|
|
+ menu.ID,
|
|
|
+ menu.Name,
|
|
|
+ menu.Path,
|
|
|
+ menu.Hidden,
|
|
|
+ menu.ParentId,
|
|
|
+ menu.Sort,
|
|
|
+ menu.Component,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ err := excel.SaveAs(filePath)
|
|
|
+ return err
|
|
|
+}
|