Explorar o código

Merge branch 'master' of http://10.8.230.114:3000/wangbin/log-server

maker %!s(int64=2) %!d(string=hai) anos
pai
achega
14c7902d6d

+ 14 - 0
api/v1/fileManager/file_qiniu.go

@@ -109,3 +109,17 @@ func (v *ApiFileQiniu) UpdateMirrorPushPolicy(c *gin.Context) {
 		response.OkWithMessage("修改镜像更新策略成功", c)
 	}
 }
+
+// CheckIsExistMirror 查询所有游戏任务下是否有镜像
+func (v *ApiFileQiniu) CheckIsExistMirror(c *gin.Context) {
+
+	if list, err := ServiceFileQiniu.CheckIsExistMirror(); err != nil {
+		//global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+	} else {
+		//响应结果
+		response.OkWithDetailed(response.PageResult{
+			List: list,
+		}, "获取成功", c)
+	}
+}

+ 69 - 0
api/v1/log/loging.go

@@ -12,7 +12,10 @@ import (
 	"log-server/service/log"
 	loging2 "log-server/service/log/loging"
 	"log-server/utils"
+	"net/url"
 	"strconv"
+	"strings"
+	"time"
 )
 
 type ApiLoging struct {
@@ -681,3 +684,69 @@ func (e *ApiLoging) GetErrDeviceLog(c *gin.Context) {
 		}, "获取成功", c)
 	}
 }
+
+// @Tags loging
+// @Summary 获取无忧token
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce  application/json
+// @Param data body log2.DeviceLog true "设备异常数据接口"
+// @Success 200
+// @Router /loging/getWuYToken [Get]
+func (e *ApiLoging) GetWuYToken(c *gin.Context) {
+	type Data struct {
+		Token string `json:"token"`
+	}
+	var data Data
+	key := fmt.Sprintf("%s:wuYToken", time.Now().Format("2006-01-02"))
+	t, _ := global.GVA_REDIS.Get(c, key).Result()
+	if t != "" {
+		data.Token = t
+		response.OkWithDetailed(data, "获取成功", c)
+		return
+	}
+	header := map[string]string{"Content-Type": "application/x-www-form-urlencoded"}
+	var (
+		params = url.Values{}
+	)
+	params.Set("username", "18408246387")
+	params.Set("password", "der123456")
+	params.Set("source", "3")
+	params.Set("auth", "none")
+	requestData := params.Encode()
+	reqUrl := "https://user.wuyouip.com/Sign/_In"
+	reqs, err := utils.Request("POST", reqUrl, strings.NewReader(requestData), header, nil)
+	if err != nil {
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+		return
+	}
+	token := reqs.Cookies()[1].Value
+	if token != "" {
+		token = "token=" + token
+		global.GVA_REDIS.Set(c, key, token, time.Hour*15)
+	}
+	data.Token = token
+	response.OkWithDetailed(data, "获取成功", c)
+	return
+}
+
+// @Tags loging
+// @Summary 中控上报异常信息
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Success 200 {object} response.Response{data=interface{}} "中控上报异常信息"
+// @Router /loging/supConErr [post]
+func (s *ApiLoging) SupConErr(c *gin.Context) {
+	var paramsInfo request.SupConErrRequest
+	_ = c.ShouldBindJSON(&paramsInfo)
+	if paramsInfo.PcCode == "" || paramsInfo.Describe == "" {
+		global.GVA_LOG.Error("参数错误!")
+		response.FailWithMessage("参数错误", c)
+		return
+	}
+	num := ServiceStatisticsLog.SupConErr(paramsInfo.PcCode, paramsInfo.Describe)
+	global.GVA_LOG.Warn(fmt.Sprintf("中控上报异常pc_code=%s 描述=%s", paramsInfo.PcCode, paramsInfo.Describe))
+	response.OkWithDetailed(num, "上报成功", c)
+}

+ 1 - 0
api/v1/task/game_task.go

@@ -536,6 +536,7 @@ func (e *GameTaskApi) TaskTargetExport(c *gin.Context) {
 func (e *GameTaskApi) TemporaryTask(c *gin.Context) {
 	var params request.GetTemporaryTaskRequest
 	_ = c.ShouldBindJSON(&params)
+	global.GVA_LOG.Warn(params.PcCode)
 	if params.PcCode == "" {
 		response.FailWithMessage("参数错误", c)
 		return

+ 10 - 10
initialize/timer.go

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

+ 5 - 0
model/log/request/log_statistics.go

@@ -24,6 +24,11 @@ type OnlineComputerRequest struct {
 	Operator string `json:"operator"`
 }
 
+type SupConErrRequest struct {
+	PcCode   string `json:"pc_code"`
+	Describe string `json:"describe"`
+}
+
 type TaskStatistics struct {
 	GameId                int    `json:"game_id"`
 	GameName              string `json:"game_name"`

+ 1 - 0
router/fileManager/file_qiniu.go

@@ -20,5 +20,6 @@ func (e *FileQiniuRouter) InitFileQiniuRouter(Router *gin.RouterGroup) {
 		excelRouter.POST("renameQiniuFileAndRecord", api.RenameQiniuFileAndRecord)  //删除单个文件
 		excelRouter.GET("getMirrorDownloadByTaskId", api.GetMirrorDownloadByTaskId) //根据任务id获取最新镜像下载链接
 		excelRouter.POST("updateMirrorPushPolicy", api.UpdateMirrorPushPolicy)      //删除单个文件
+		excelRouter.POST("checkIsExistMirror", api.CheckIsExistMirror)              //查询未上传镜像的游戏任务
 	}
 }

+ 2 - 0
router/log/loging.go

@@ -33,5 +33,7 @@ func (e *LogingRouter) InitLogingRouter(Router *gin.RouterGroup) {
 		excelRouter.POST("getErrDeviceLog", logApi.GetErrDeviceLog)
 		excelRouter.POST("getDeviceIdErr", logApi.GetDeviceIdErr)
 		excelRouter.POST("deviceErrRateExcel", logApi.DeviceErrRateExcel)
+		excelRouter.GET("getWuYToken", logApi.GetWuYToken)
+		excelRouter.POST("supConErr", logApi.SupConErr)
 	}
 }

+ 38 - 0
service/fileManager/file_qiniu.go

@@ -10,6 +10,7 @@ import (
 	"log-server/model/fileManager"
 	"log-server/model/fileManager/request"
 	"log-server/model/fileManager/response"
+	"log-server/model/task"
 	"strconv"
 	"strings"
 	"time"
@@ -76,6 +77,43 @@ func (s *ServiceFileQiniu) QueryFilesByParentId(parentId int) (interface{}, erro
 	return fileList, err
 }
 
+// CheckIsExistMirror 查询所有游戏任务下是否有镜像
+func (s *ServiceFileQiniu) CheckIsExistMirror() (interface{}, error) {
+	// 查询所有任务
+	var taskList []task.GameTask
+	db := global.GVA_DB.Model(&task.GameTask{}).Where("status = 1")
+	err := db.Order("user").Find(&taskList).Error
+	if err != nil {
+		return nil, err
+	}
+	// 查询所有镜像
+	var mirrorList []fileManager.FileQiniu
+	db2 := global.GVA_DB.Model(&fileManager.FileQiniu{}).Where(`file_name LIKE '%.ldbk' OR file_name LIKE '%.npbk'`)
+	err = db2.Order("id").Find(&mirrorList).Error
+	if err != nil {
+		return nil, err
+	}
+	var noMirrorList []task.GameTask
+	for _, gameTask := range taskList {
+		exist := false
+		for _, qiniu := range mirrorList {
+			if gameTask.TaskId == qiniu.TaskId {
+				exist = true
+				break
+			}
+		}
+		if exist == false {
+			noMirrorList = append(noMirrorList, gameTask)
+		}
+	}
+
+	//for _, gameTask := range noMirrorList {
+	//	global.GVA_LOG.Warn(gameTask.TaskName)
+	//}
+
+	return noMirrorList, err
+}
+
 // GetMirrorDownloadByTaskId 根据任务id获取最新镜像下载链接
 func (s *ServiceFileQiniu) GetMirrorDownloadByTaskId(taskId string) (interface{}, error) {
 	//SELECT * FROM file_qiniu WHERE task_id = 1000605 AND (file_type = 2 OR file_type = 4) AND push_policy = 1 ORDER BY file_version DESC LIMIT 1

+ 30 - 0
service/log/log_statistics.go

@@ -1709,3 +1709,33 @@ func (s *ServiceStatisticsLog) ComputerUpdateStatus() {
 		}
 	}
 }
+
+// 中控异常情况
+func (s *ServiceStatisticsLog) SupConErr(pcCode, describe string) (err error) {
+	var computer log.Computer
+	computers, err := computer.OnlinePcCodeCache()
+	//computersF, err := computer.OnlinePcCodeCache()
+	if err != nil {
+		global.GVA_LOG.Error("获取租机表数据失败", zap.Error(err))
+		return
+	}
+	if computers == nil {
+		global.GVA_LOG.Warn("电脑缓存数据获取失败TaskStatisticsDataCache")
+		return
+	}
+	name := computers[pcCode]
+	if strings.Contains(name, "备用") {
+		return
+	}
+	if name == "" {
+		return
+	}
+	c := "# 中控异常"
+	c += "\n"
+	ct := fmt.Sprintf("<font color=\"warning\">电脑%s; %s</font>", pcCode, describe)
+	ct = c + ct
+	global.GVA_LOG.Warn(ct)
+	mpsPerson, _ := s.Person.GetUserInfoData()
+	s.SendContent(ct, mpsPerson[name].Url)
+	return
+}

+ 3 - 0
service/task/game_task.go

@@ -1258,5 +1258,8 @@ func (apiService *GameTask) TemporaryTask(ctx context.Context, pcCode string) (t
 		return temporaryConf, errors.New("没有任务数据")
 	}
 	err = global.GVA_DB.Model(&task.CentralControlConf{}).Where("task_id", taskId).First(&temporaryConf).Error
+	if err == nil {
+		global.GVA_REDIS.Del(ctx, key)
+	}
 	return temporaryConf, err
 }

+ 10 - 10
service/task/urgent_task_conf.go

@@ -77,23 +77,23 @@ func (s *UrgentTaskService) DeleteUrgentTaskByIds(ids []int) (err error) {
 func (s *UrgentTaskService) UpdateUrgentTask(task1 task.UrgentTaskConf) (err error) {
 	//查找此task_id是否存在,如果存在不更新,否则更新
 	var entity task.UrgentTaskConf
-	err = global.GVA_DB.Model(&task.UrgentTaskConf{}).Where("task_id = ? and id != ? and create_date = ?", task1.TaskId, task1.Id, task1.CreateDate).First(&entity).Error
-	if !errors.Is(err, gorm.ErrRecordNotFound) {
-		return errors.New("已存在此task_id的任务,更新失败")
+	err = global.GVA_DB.Model(&task.UrgentTaskConf{}).Where("task_id = ? and id = ? and create_date = ?", task1.TaskId, task1.Id, task1.CreateDate).First(&entity).Error
+	if errors.Is(err, gorm.ErrRecordNotFound) {
+		return errors.New("没有找到数据")
+	}
+	upPcCode := ""
+	if task1.PcCode != "" {
+		upPcCode = task1.PcCode
+		task1.PcCode = entity.PcCode + "," + task1.PcCode
 	}
 	err = global.GVA_DB.Model(&task.UrgentTaskConf{}).Where("id", task1.Id).Updates(&task1).Error
 	if err != nil {
 		return err
 	}
 	date := entity.CreateDate[:10]
-	if entity.PcCode != task1.PcCode {
-		codeSplit := strings.Split(entity.PcCode, ",")
+	if upPcCode != "" {
 		ctx := context.Background()
-		for _, code := range codeSplit {
-			key := fmt.Sprintf(cache.TemporaryTaskPcCode, date, code)
-			global.GVA_REDIS.Del(ctx, key)
-		}
-		upCodeSplit := strings.Split(task1.PcCode, ",")
+		upCodeSplit := strings.Split(upPcCode, ",")
 		for _, upCode := range upCodeSplit {
 			key := fmt.Sprintf(cache.TemporaryTaskPcCode, date, upCode)
 			global.GVA_REDIS.Set(ctx, key, task1.TaskId, time.Hour*6)

+ 8 - 0
uploads/.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 8 - 0
uploads/.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/uploads.iml" filepath="$PROJECT_DIR$/.idea/uploads.iml" />
+    </modules>
+  </component>
+</project>

+ 9 - 0
uploads/.idea/uploads.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
uploads/.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
+  </component>
+</project>

+ 27 - 0
utils/requst_http.go

@@ -3,9 +3,11 @@ package utils
 import (
 	"encoding/json"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"net/http"
 	"strings"
+	"time"
 )
 
 func HttpGet(url string, params map[string]string) (result []byte, err error) {
@@ -161,3 +163,28 @@ func HttpDeleteReplyCode(url string, params interface{}) (result []byte, code in
 	result = body
 	return
 }
+
+func Request(method, urlPath string, reqBody io.Reader, header map[string]string, cookies []*http.Cookie) (resp *http.Response, err error) {
+	req, err := http.NewRequest(method, urlPath, reqBody)
+	if err != nil {
+		return
+	}
+	for k, v := range header {
+		req.Header.Set(k, v)
+	}
+	for _, v := range cookies {
+		req.AddCookie(v)
+	}
+	var (
+		client = http.Client{
+			Timeout: 15 * time.Second,
+			//Transport: &http.Transport{Proxy: http.ProxyURL(&url.URL{Host: "localhost:8888"})},
+		}
+	)
+	if resp, err = client.Do(req); err != nil {
+		return
+	}
+
+	defer resp.Body.Close()
+	return
+}