|
@@ -13,8 +13,8 @@ import (
|
|
|
"log-server/model/log"
|
|
"log-server/model/log"
|
|
|
"log-server/model/log/request"
|
|
"log-server/model/log/request"
|
|
|
"log-server/model/log/response"
|
|
"log-server/model/log/response"
|
|
|
- "log-server/model/system"
|
|
|
|
|
loging2 "log-server/service/log/loging"
|
|
loging2 "log-server/service/log/loging"
|
|
|
|
|
+ "log-server/utils"
|
|
|
"math"
|
|
"math"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
"time"
|
|
"time"
|
|
@@ -591,6 +591,12 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
|
|
|
csReply.CreateDate = time.Now().Format("2006-01-02")
|
|
csReply.CreateDate = time.Now().Format("2006-01-02")
|
|
|
csReply.Status = 1
|
|
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) {
|
|
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("status = ?", -1).First(&log.LogComputer{}).Error, gorm.ErrRecordNotFound) {
|
|
|
|
|
+ err = global.GVA_DB.Table("log_computer").Where("create_date = ?", csReply.CreateDate).Where("pc_code = ?", csReply.PcCode).Update("status", 1).Error
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ global.GVA_LOG.Error("更新数据失败onlineComputerMpa", zap.Error(err))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
onlineComputer = append(onlineComputer, csReply)
|
|
onlineComputer = append(onlineComputer, csReply)
|
|
@@ -719,13 +725,14 @@ func (s *ServiceStatisticsLog) ComputerStatistics(ctx context.Context, api log.L
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 在线电脑
|
|
// 在线电脑
|
|
|
-func (s *ServiceStatisticsLog) OnlineComputerStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo, order string, desc bool) (interface{}, int64, error) {
|
|
|
|
|
|
|
+func (s *ServiceStatisticsLog) OnlineComputerStatistics(ctx context.Context, api log.LogComputer, info request.PageInfo, order string, desc bool) ([]*response.ComputerUseLogReply, int64, error) {
|
|
|
date := api.CreateDate
|
|
date := api.CreateDate
|
|
|
if date == "" {
|
|
if date == "" {
|
|
|
date = s.CurrentDate()
|
|
date = s.CurrentDate()
|
|
|
}
|
|
}
|
|
|
db := global.GVA_DB.Model(&log.LogComputer{})
|
|
db := global.GVA_DB.Model(&log.LogComputer{})
|
|
|
var total int64
|
|
var total int64
|
|
|
|
|
+ db = db.Select("SUM(pull_account_num) pull_account_total,SUM(enter_main) enter_main_total,operator,pc_code,status,create_date")
|
|
|
db = db.Where("create_date = ?", date)
|
|
db = db.Where("create_date = ?", date)
|
|
|
if api.Operator != "" {
|
|
if api.Operator != "" {
|
|
|
db = db.Where("operator = ?", api.Operator)
|
|
db = db.Where("operator = ?", api.Operator)
|
|
@@ -743,7 +750,7 @@ func (s *ServiceStatisticsLog) OnlineComputerStatistics(ctx context.Context, api
|
|
|
}
|
|
}
|
|
|
limit := info.PageSize
|
|
limit := info.PageSize
|
|
|
offset := info.PageSize * (info.Page - 1)
|
|
offset := info.PageSize * (info.Page - 1)
|
|
|
- var statisticsLogs []*log.LogComputer
|
|
|
|
|
|
|
+ var statisticsLogs []*response.ComputerUseLogReply
|
|
|
db = db.Limit(limit).Offset(offset)
|
|
db = db.Limit(limit).Offset(offset)
|
|
|
if order != "" {
|
|
if order != "" {
|
|
|
var OrderStr string
|
|
var OrderStr string
|
|
@@ -769,17 +776,12 @@ func (s *ServiceStatisticsLog) OnlineComputerStatistics(ctx context.Context, api
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
return nil, 0, err
|
|
|
}
|
|
}
|
|
|
- var statisticsLogsComputer []*response.ComputerStatisticsReply1
|
|
|
|
|
|
|
|
|
|
for _, statisticsLog := range statisticsLogs {
|
|
for _, statisticsLog := range statisticsLogs {
|
|
|
- statisticsLogComputer := new(response.ComputerStatisticsReply1)
|
|
|
|
|
- statisticsLogComputer.PcCode = statisticsLog.PcCode
|
|
|
|
|
- statisticsLogComputer.Operator = statisticsLog.Operator
|
|
|
|
|
- statisticsLogComputer.CreateDate = statisticsLog.CreateDate[:10]
|
|
|
|
|
- statisticsLogComputer.Status = statisticsLog.Status
|
|
|
|
|
- statisticsLogsComputer = append(statisticsLogsComputer, statisticsLogComputer)
|
|
|
|
|
|
|
+ statisticsLog.CreateDate = statisticsLog.CreateDate[:10]
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- return statisticsLogsComputer, total, err
|
|
|
|
|
|
|
+ return statisticsLogs, total, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//根据游戏id查询数据
|
|
//根据游戏id查询数据
|
|
@@ -965,7 +967,7 @@ func (s *ServiceStatisticsLog) ComputerTest(c context.Context) (interface{}, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 定时检查电脑情况
|
|
// 定时检查电脑情况
|
|
|
-func (s *ServiceStatisticsLog) RegularCheckPc() {
|
|
|
|
|
|
|
+func (s *ServiceStatisticsLog) RegularCheckPc1() {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
date := s.LogicalLog.CurrentDate()
|
|
date := s.LogicalLog.CurrentDate()
|
|
|
// 获取当天已上报的电脑数据
|
|
// 获取当天已上报的电脑数据
|
|
@@ -987,33 +989,116 @@ func (s *ServiceStatisticsLog) RegularCheckPc() {
|
|
|
}
|
|
}
|
|
|
// 未上报逻辑
|
|
// 未上报逻辑
|
|
|
var errReportingPc []string
|
|
var errReportingPc []string
|
|
|
- for pc, _ := range computers {
|
|
|
|
|
|
|
+ for pc, name := range computers {
|
|
|
|
|
+ if name == "备用" {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
errReportingPc = append(errReportingPc, pc)
|
|
errReportingPc = append(errReportingPc, pc)
|
|
|
}
|
|
}
|
|
|
|
|
+ var content string
|
|
|
if len(errReportingPc) != 0 {
|
|
if len(errReportingPc) != 0 {
|
|
|
// 发信息数据群里
|
|
// 发信息数据群里
|
|
|
- fmt.Println("异常上报数据: ", errReportingPc, len(errReportingPc))
|
|
|
|
|
|
|
+ content += fmt.Sprintf("异常租机数据<font color=\"warning\">%d台</font>: %s", len(errReportingPc), errReportingPc)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if len(noReportingPc) != 0 {
|
|
if len(noReportingPc) != 0 {
|
|
|
// 发信息数据群里
|
|
// 发信息数据群里
|
|
|
- fmt.Println("两小时内未检测到上报数据: ", noReportingPc, len(noReportingPc))
|
|
|
|
|
|
|
+ content += "\n"
|
|
|
|
|
+ content += fmt.Sprintf("两小时内未检测到中控数据<font color=\"warning\">%d台</font>: %s", len(noReportingPc), noReportingPc)
|
|
|
|
|
+ }
|
|
|
|
|
+ if content != "" {
|
|
|
|
|
+ var sendMsg SendMsg
|
|
|
|
|
+ sendMsg.MsgType = "markdown"
|
|
|
|
|
+ sendMsg.Markdown.Content = content
|
|
|
|
|
+ //c ,_ := json.Marshal(sendMsg)
|
|
|
|
|
+ url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
|
|
|
|
|
+ //url := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7d095d5b-8240-45fd-a68c-baff3628d83b"
|
|
|
|
|
+ _, err = s.SendMsgData(url, sendMsg)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (exa *ServiceStatisticsLog) ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error {
|
|
|
|
|
|
|
+// 定时检查电脑情况
|
|
|
|
|
+func (s *ServiceStatisticsLog) RegularCheckPc() {
|
|
|
|
|
+ ctx := context.Background()
|
|
|
|
|
+ var computer log.Computer
|
|
|
|
|
+ computers, err := computer.OnlinePcCodeCache()
|
|
|
|
|
+ //computersF, err := computer.OnlinePcCodeCache()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ global.GVA_LOG.Error("获取租机表数据失败", zap.Error(err))
|
|
|
|
|
+ }
|
|
|
|
|
+ // 查询两小时内上报的数据
|
|
|
|
|
+ var computersF = map[string]string{}
|
|
|
|
|
+ var noReportingPc []string
|
|
|
|
|
+ for pc, name := range computers {
|
|
|
|
|
+ computersF[pc] = name
|
|
|
|
|
+ if name == "备用" {
|
|
|
|
|
+ delete(computers, pc)
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ num := s.LogicalLog.GetPcReportingLog(ctx, pc)
|
|
|
|
|
+ delete(computers, pc)
|
|
|
|
|
+ if num == 0 {
|
|
|
|
|
+ noReportingPc = append(noReportingPc, pc)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var content string
|
|
|
|
|
+
|
|
|
|
|
+ if len(noReportingPc) != 0 {
|
|
|
|
|
+ content += fmt.Sprintf("两小时内未检测到中控数据<font color=\"warning\">%d台</font>:", len(noReportingPc))
|
|
|
|
|
+ for _, pc := range noReportingPc {
|
|
|
|
|
+ content += "\n"
|
|
|
|
|
+ name := computersF[pc]
|
|
|
|
|
+ content += name + " : " + pc
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if content != "" {
|
|
|
|
|
+ var sendMsg SendMsg
|
|
|
|
|
+ sendMsg.MsgType = "markdown"
|
|
|
|
|
+ sendMsg.Markdown.Content = content
|
|
|
|
|
+ //c ,_ := json.Marshal(sendMsg)
|
|
|
|
|
+ url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
|
|
|
|
|
+ //url := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7d095d5b-8240-45fd-a68c-baff3628d83b"
|
|
|
|
|
+ _, err = s.SendMsgData(url, sendMsg)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type SendMsg struct {
|
|
|
|
|
+ MsgType string `json:"msgtype"`
|
|
|
|
|
+ Markdown struct {
|
|
|
|
|
+ Content string `json:"content"`
|
|
|
|
|
+ } `json:"markdown"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (s *ServiceStatisticsLog) SendMsgData(url string, params interface{}) (result []byte, err error) {
|
|
|
|
|
+ result, err = utils.HttpPost(url, params)
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+var statusMps = map[int]string{
|
|
|
|
|
+ -1: "未上报",
|
|
|
|
|
+ 1: "中控上报",
|
|
|
|
|
+ 2: "任务上报",
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (exa *ServiceStatisticsLog) ParseInfoList2Excel(infoList []*response.ComputerUseLogReply, filePath string) error {
|
|
|
excel := excelize.NewFile()
|
|
excel := excelize.NewFile()
|
|
|
- excel.SetSheetRow("Sheet1", "A1", &[]string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"})
|
|
|
|
|
- for i, menu := range infoList {
|
|
|
|
|
|
|
+ excel.SetSheetRow("Sheet1", "A1", &[]string{"电脑编号", "使用者", "日期", "拉取账号", "进入主线", "主线成功率", "使用状态"})
|
|
|
|
|
+ for i, statisticsLog := range infoList {
|
|
|
axis := fmt.Sprintf("A%d", i+2)
|
|
axis := fmt.Sprintf("A%d", i+2)
|
|
|
|
|
+ var r interface{}
|
|
|
|
|
+ if statisticsLog.EnterMainTotal != 0 && statisticsLog.PullAccountTotal != 0 {
|
|
|
|
|
+ r = fmt.Sprintf("%.2f", float64(statisticsLog.EnterMainTotal)/float64(statisticsLog.PullAccountTotal)*100)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ r = "0.00"
|
|
|
|
|
+ }
|
|
|
excel.SetSheetRow("Sheet1", axis, &[]interface{}{
|
|
excel.SetSheetRow("Sheet1", axis, &[]interface{}{
|
|
|
- menu.ID,
|
|
|
|
|
- menu.Name,
|
|
|
|
|
- menu.Path,
|
|
|
|
|
- menu.Hidden,
|
|
|
|
|
- menu.ParentId,
|
|
|
|
|
- menu.Sort,
|
|
|
|
|
- menu.Component,
|
|
|
|
|
|
|
+ statisticsLog.PcCode,
|
|
|
|
|
+ statisticsLog.Operator,
|
|
|
|
|
+ statisticsLog.CreateDate[:10],
|
|
|
|
|
+ statisticsLog.PullAccountTotal,
|
|
|
|
|
+ statisticsLog.EnterMainTotal,
|
|
|
|
|
+ r,
|
|
|
|
|
+ statusMps[statisticsLog.Status],
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
err := excel.SaveAs(filePath)
|
|
err := excel.SaveAs(filePath)
|