Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

wangbin 2 anni fa
parent
commit
04faaf9b65
4 ha cambiato i file con 96 aggiunte e 3 eliminazioni
  1. 1 0
      config.yaml
  2. 6 1
      initialize/timer.go
  3. 47 2
      service/log/log_ip.go
  4. 42 0
      service/system/sys_robot.go

+ 1 - 0
config.yaml

@@ -160,6 +160,7 @@ zap:
   log-in-console: true
 send-url:
   computer-send-url: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7d095d5b-8240-45fd-a68c-baff3628d83b111"
+#  computer-send-url: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=89460a48-e1a1-4181-86c0-533bad342628"
   keyword-send-url: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=34cbfa5a-c31d-464f-baf8-8363d6f4ac6a111"
   send-url-one: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5ccfb180-c062-48b5-ae18-0c96f7c19f0b111" #深圳群
   get-url-arpu: "http://sy.8888888.com/v2/optimize/arpu"

+ 6 - 1
initialize/timer.go

@@ -200,8 +200,13 @@ func Timer() {
 	//	fmt.Println("add RemindSendOne timer error:", err)
 	//}
 
+	//半小时同步一次IP信息,播报是否有异常
+	_, err := global.GVA_Timer.AddTaskByFunc("SyncIPMessage", "0 */30 * * * ? ", robotService.SyncIPMessage)
+	if err != nil {
+		fmt.Println("add SyncIPMessage timer error:", err)
+	}
 	//定时查看延迟更新的镜像是否到期
-	_, err := global.GVA_Timer.AddTaskByFunc("CheckPushTime", "35 0/2 * * * *", serviceFileQiniu.CheckPushTime)
+	_, err = global.GVA_Timer.AddTaskByFunc("CheckPushTime", "35 0/2 * * * *", serviceFileQiniu.CheckPushTime)
 	if err != nil {
 		fmt.Println("add CheckPushTime timer error:", err)
 	}

+ 47 - 2
service/log/log_ip.go

@@ -159,7 +159,9 @@ func (s *ServiceIpLog) GetGameIpList(api log.GameIpRequest, info request.PageInf
 		successIp := float64(apiList[i].SuccessIp)
 		taskCount := float64(apiList[i].TaskCount)
 		apiList[i].IpRepetitionRate, _ =  strconv.ParseFloat(fmt.Sprintf("%.2f", (countDistinctIp/ successIp) *100), 64)
-		apiList[i].AverageIpRepetitionRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (countDistinctIp / taskCount) *100), 64)
+		if taskCount != 0 {
+			apiList[i].AverageIpRepetitionRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (countDistinctIp / taskCount) *100), 64)
+		}
 	}
 	return apiList, total, err
 }
@@ -218,4 +220,47 @@ func (s *ServiceIpLog) GameIpListExcel(infoList []log.GameIpResponse, filePath s
 	}
 	err := excel.SaveAs(filePath)
 	return err
-}
+}
+
+//获取异常ip数据
+func (s *ServiceIpLog) GetAbnormalIp() (list map[string]string, err error) {
+
+	db := global.GVA_DB.Model(&log.IpLog{})
+	startDate := time.Now().Format("2006-01-02")
+	endDate := time.Now().Format("2006-01-02")
+	var apiList []log.GameIpResponse
+
+	//筛选日期
+	db = db.Where("ip_log.create_date >= ? and ip_log.create_date <= ?", startDate, endDate)
+	//查找总ip上报次数
+	db = db.Joins("left join" + "(select count(*) as count, game_id, create_date from ip_log where create_date >= ? and create_date <= ? group by game_id, create_date)" + " as late on late.game_id = ip_log.game_id and late.create_date = ip_log.create_date",  startDate, endDate)
+
+	db = db.Where("ip_log.status = 2")
+
+	db = db.Select("ip_log.create_date,ip_log.game_id,late.count as count_total, task_name, user,  count(*) as success_ip , retained_complete as task_count, count(distinct(ip)) as count_distinct_ip")
+	//拼接任务完成表
+	db = db.Joins("left join game_target_complete as gtc on gtc.task_id = ip_log.game_id and gtc.create_date = ip_log.create_date")
+	//拼接game_task表获取任务名称和负责人名称
+	db = db.Joins("left join game_task as gt on gt.task_id = ip_log.game_id")
+	db = db.Group("ip_log.game_id, ip_log.create_date")
+
+	err = db.Order("ip_log.id").Find(&apiList).Error
+
+	var abnormalIpList = map[string]string{}
+	//遍历更改日期格式
+	for i, _ := range apiList {
+		apiList[i].CreateDate = apiList[i].CreateDate[:10]
+		err = global.GVA_DB.Model(&log.IpLog{}).Select("COUNT(1) as max_count").Where("game_id = ? and create_date = ? and status = 2", apiList[i].GameId, apiList[i].CreateDate).Group("ip").Order("max_count desc").Limit(1).Find(&apiList[i]).Error
+		global.GVA_DB.Model(&log.IpLog{}).Select("id,ip,count(*) ").Where("game_id = ? and create_date = ? and status = 2", apiList[i].GameId, apiList[i].CreateDate).Group("ip").Having("count(*) > 4").Count(&apiList[i].ExceedThree)
+		//获取平均重复率和ip重复率 并保留小数点后两位
+		countDistinctIp := float64(apiList[i].CountDistinctIp)
+		successIp := float64(apiList[i].SuccessIp)
+		taskCount := float64(apiList[i].TaskCount)
+		apiList[i].IpRepetitionRate, _ =  strconv.ParseFloat(fmt.Sprintf("%.2f", (countDistinctIp/ successIp) *100), 64)
+		apiList[i].AverageIpRepetitionRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (countDistinctIp / taskCount) *100), 64)
+		if apiList[i].IpRepetitionRate < 30 && apiList[i].SuccessIp > 10 {
+			abnormalIpList[apiList[i].User] = apiList[i].TaskName
+		}
+	}
+	return abnormalIpList, err
+}

+ 42 - 0
service/system/sys_robot.go

@@ -2,7 +2,10 @@ package system
 
 import (
 	"encoding/json"
+	"fmt"
 	"log-server/global"
+	"log-server/service/log"
+	"log-server/service/task"
 	"log-server/utils"
 	"strconv"
 	"time"
@@ -122,3 +125,42 @@ func (robotService *RobotService) RequestJfXmyNewAccount() (result []byte, err e
 	result, err = utils.HttpGet(jfUrl, jfParams)
 	return
 }
+
+// SyncIPMessage 定时判断ip
+func (robotService *RobotService) SyncIPMessage() {
+
+	//if keyWord != "" {
+	//	content += keyWord
+	//	url := global.GVA_CONFIG.SendUrl.KeyWordSendUrl
+	//	_, _ = robotService.PostRobotToEnterpriseWeChatByMarkdown(url, content)
+	//}
+	fmt.Println("ip定时任务")
+	msg := "# IP异常播报 \n "
+	var syncData task.SyncData
+	var ipService log.ServiceIpLog
+	abnormalIpList, _ := ipService.GetAbnormalIp()
+	var mobile []string
+	mpsPerson, _ := syncData.Person.GetUserInfo()
+	//fmt.Println(mpsPerson)
+	for k,_ := range abnormalIpList{
+		mobile = append(mobile, mpsPerson[k])
+		msg += "# " + k + " " + "\n"
+		msg += fmt.Sprintf("<font color=\"warning\">%s</font>", abnormalIpList[k])  + "\n"
+	}
+	url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
+	var sendData SendMsg
+	sendData.MsgType = "markdown"
+	sendData.Markdown.Content = msg
+	syncData.SendMsgData(url, sendData)
+
+	if len(mobile) != 0 {
+		var sendTextData task.SendTextMsg
+		sendTextData.MsgType = "text"
+		sendTextData.Text.MentionedMobileList = mobile
+		//fmt.Println(mobile)
+		//b ,_ := json.Marshal(sendTextData)
+		//global.GVA_LOG.Warn(string(b))
+		syncData.SendMsgData(url, sendTextData)
+	}
+	return
+}