ソースを参照

付费推送服务接口迁移到数优后端

wangbin 2 年 前
コミット
6360ac656c

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

@@ -380,6 +380,28 @@ func (s *ApiLoging) GetGameIdStatistics(c *gin.Context) {
 }
 
 // @Tags loging
+// @Summary 通过GameId获取电脑数据
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Success 200 {object} response.Response{data=interface{}} "获取统计数据通过GameId"
+// @Router /loging/getTaskComputer [post]
+func (s *ApiLoging) GetTaskComputer(c *gin.Context) {
+	var paramsInfo request.IdDateReply
+	_ = c.ShouldBindJSON(&paramsInfo)
+	list, total, err := ServiceStatisticsLog.TaskComputerNumInfo(c, paramsInfo)
+	if err != nil {
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+	} else {
+		response.OkWithDetailed(response.PageResult{
+			List:  list,
+			Total: total,
+		}, "获取成功", c)
+	}
+}
+
+// @Tags loging
 // @Summary 获取统计电脑数量
 // @Security ApiKeyAuth
 // @accept application/json

+ 17 - 18
api/v1/task/central_control_conf.go

@@ -12,11 +12,10 @@ import (
 )
 
 type CentralControlApi struct {
-
 }
 
 //创建中控配置
-func (a *CentralControlApi) CreateCentralControlConf (c *gin.Context)  {
+func (a *CentralControlApi) CreateCentralControlConf(c *gin.Context) {
 	var conf task.CentralControlConf
 	_ = c.ShouldBindJSON(&conf)
 	if conf.Mirror == "" {
@@ -31,7 +30,7 @@ func (a *CentralControlApi) CreateCentralControlConf (c *gin.Context)  {
 		response.FailWithMessage(err.Error(), c)
 		return
 	}
-	if err := centralControlService.CreateCentralControlConf(conf);err != nil {
+	if err := centralControlService.CreateCentralControlConf(conf); err != nil {
 		global.GVA_LOG.Error("创建失败!", zap.Error(err))
 		response.FailWithMessage("创建失败", c)
 	} else {
@@ -42,13 +41,13 @@ func (a *CentralControlApi) CreateCentralControlConf (c *gin.Context)  {
 //删除配置列表
 func (a *CentralControlApi) DeleteCentralControlConf(c *gin.Context) {
 	var conf task.CentralControlConf
-	 _ = c.ShouldBindJSON(&conf)
+	_ = c.ShouldBindJSON(&conf)
 
-	 //数据校验
-	 if err := utils.Verify(conf, utils.CentralControlConfVerify); err != nil {
-		 response.FailWithMessage(err.Error(), c)
-		 return
-	 }
+	//数据校验
+	if err := utils.Verify(conf, utils.CentralControlConfVerify); err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
 	if err := centralControlService.DeleteCentralControlConf(conf); err != nil {
 		global.GVA_LOG.Error("删除失败!", zap.Error(err))
 		response.FailWithMessage("删除失败", c)
@@ -70,14 +69,14 @@ func (a *CentralControlApi) DeleteCentralControlConfByIds(c *gin.Context) {
 }
 
 //更新中控配置
-func (a *CentralControlApi) UpdateCentralControlConf (c *gin.Context)  {
+func (a *CentralControlApi) UpdateCentralControlConf(c *gin.Context) {
 	var conf task.CentralControlConf
 	_ = c.ShouldBindJSON(&conf)
-	if err := utils.Verify(conf, utils.CentralControlConfVerify); err != nil{
+	if err := utils.Verify(conf, utils.CentralControlConfVerify); err != nil {
 		response.FailWithMessage(err.Error(), c)
 		return
 	}
-	if err := centralControlService.UpdateCentralControlConf(conf); err != nil{
+	if err := centralControlService.UpdateCentralControlConf(conf); err != nil {
 		global.GVA_LOG.Error("更新失败!", zap.Error(err))
 		response.FailWithMessage("更新失败", c)
 	} else {
@@ -86,14 +85,14 @@ func (a *CentralControlApi) UpdateCentralControlConf (c *gin.Context)  {
 }
 
 //id获取中控配置
-func (a *CentralControlApi) GetCentralControlConfById (c *gin.Context)  {
+func (a *CentralControlApi) GetCentralControlConfById(c *gin.Context) {
 	var id request.GetById
 	_ = c.ShouldBindJSON(&id)
 	if err := utils.Verify(id, utils.IdVerify); err != nil {
 		response.FailWithMessage(err.Error(), c)
 		return
 	}
-	if conf, err := centralControlService.GetCentralControlConfById(id.ID); err != nil{
+	if conf, err := centralControlService.GetCentralControlConfById(id.ID); err != nil {
 		global.GVA_LOG.Error("获取失败!", zap.Error(err))
 		response.FailWithMessage("获取失败", c)
 	} else {
@@ -102,16 +101,16 @@ func (a *CentralControlApi) GetCentralControlConfById (c *gin.Context)  {
 }
 
 //获取中控配置列表
-func (a *CentralControlApi) GetCentralControlConfList (c *gin.Context)  {
+func (a *CentralControlApi) GetCentralControlConfList(c *gin.Context) {
 	//获取前端传值并校验
 	var pageInfo taskRequest.SearchCentralControlConfParams
 	_ = c.ShouldBindJSON(&pageInfo)
 	//页面信息校验
-	if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil{
+	if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
 		response.FailWithMessage(err.Error(), c)
 		return
 	}
-	if list, total, err := centralControlService.GetCentralControlConfList(pageInfo.CentralControlConf, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil{
+	if list, total, err := centralControlService.GetCentralControlConfList(pageInfo.CentralControlConfList, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
 		global.GVA_LOG.Error("获取失败!", zap.Error(err))
 		response.FailWithMessage("获取失败", c)
 	} else {
@@ -125,7 +124,7 @@ func (a *CentralControlApi) GetCentralControlConfList (c *gin.Context)  {
 }
 
 //获取云中控配置列表
-func (a *CentralControlApi) GetCloudConfList(c *gin.Context)  {
+func (a *CentralControlApi) GetCloudConfList(c *gin.Context) {
 	list, err := centralControlService.GetCloudConfList()
 	if err != nil {
 		global.GVA_LOG.Error("获取失败!", zap.Error(err))

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

@@ -9,6 +9,7 @@ import (
 	taskResponse "log-server/model/task/response"
 	"log-server/utils"
 	"net/http"
+	"strconv"
 	"time"
 )
 
@@ -547,3 +548,19 @@ func (e *GameTaskApi) TemporaryTask(c *gin.Context) {
 		response.OkWithDetailed(data, "获取成功", c)
 	}
 }
+
+func (e *GameTaskApi) GetSheepPay(c *gin.Context) {
+	money := c.Query("money")
+	gameid := c.Query("gameid")
+	payTime := c.Query("pay_time")
+	global.GVA_LOG.Info(money)
+	global.GVA_LOG.Info(gameid)
+	global.GVA_LOG.Info(payTime)
+	if money == "" || gameid == "" || payTime == "" {
+		response.FailWithMessage("参数错误", c)
+		return
+	}
+	moneyInt, _ := strconv.Atoi(money)
+	taskService.GetSheepPay(c, moneyInt, gameid, payTime)
+	response.OkWithDetailed("", "收到数据", c)
+}

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

@@ -17,6 +17,11 @@ type CreateDateReply struct {
 	CreateDate string `json:"create_date"` // 日期
 }
 
+type IdDateReply struct {
+	GetById
+	CreateDateReply
+}
+
 func (r *GetById) Uint() uint {
 	return uint(r.ID)
 }

+ 6 - 0
model/log/response/loging.go

@@ -98,3 +98,9 @@ type DeviceInfoReply struct {
 	AccountErrNum uint8  `json:"account_err_num"`
 	CreateDate    string `json:"create_date"`
 }
+
+type TaskComputerInfoReply struct {
+	PcCode   string `json:"pc_code"`
+	PcMac    string `json:"pc_mac"`
+	Operator string `json:"operator"`
+}

+ 5 - 0
model/task/central_control_conf.go

@@ -29,3 +29,8 @@ type CentralControlConf struct {
 func (CentralControlConf) TableName() string {
 	return "central_control_conf"
 }
+
+type CentralControlConfList struct {
+	CentralControlConf
+	User string `json:"user"`
+}

+ 1 - 2
model/task/request/search_central_control_conf_params.go

@@ -6,9 +6,8 @@ import (
 )
 
 type SearchCentralControlConfParams struct {
-	task.CentralControlConf
+	task.CentralControlConfList
 	request.PageInfo
 	OrderKey string `json:"orderKey"` // 排序
 	Desc     bool   `json:"desc"`     // 排序方式:升序false(默认)|降序true
 }
-

+ 13 - 0
model/task/sheep_pay.go

@@ -0,0 +1,13 @@
+package task
+
+type SheepPay struct {
+	Id      int    `json:"id"`
+	GameId  string `json:"game_id"`
+	PayDate string `json:"pay_date"`
+	PayTime string `json:"pay_time"`
+	Money   int    `json:"money"`
+}
+
+func (SheepPay) TableName() string {
+	return "sheep_pay"
+}

+ 1 - 0
router/log/loging.go

@@ -35,5 +35,6 @@ func (e *LogingRouter) InitLogingRouter(Router *gin.RouterGroup) {
 		excelRouter.POST("deviceErrRateExcel", logApi.DeviceErrRateExcel)
 		excelRouter.GET("getWuYToken", logApi.GetWuYToken)
 		excelRouter.POST("supConErr", logApi.SupConErr)
+		excelRouter.POST("getTaskComputer", logApi.GetTaskComputer)
 	}
 }

+ 1 - 0
router/task/game_task.go

@@ -28,6 +28,7 @@ func (e *GameTaskRouter) InitGameTaskRouter(Router *gin.RouterGroup) {
 		GameTaskRouter.POST("taskTargetExport", GameTaskApi.TaskTargetExport)
 		GameTaskRouter.POST("getXmyTaskList", GameTaskApi.GetXmyTaskList) //获取小绵羊任务列表
 		GameTaskRouter.POST("temporaryTask", GameTaskApi.TemporaryTask)
+		GameTaskRouter.GET("sheepPay", GameTaskApi.GetSheepPay)
 	}
 	GameTaskRouter1 := Router.Group("gameTask").Use(middleware.OperationRecord())
 	{

+ 29 - 0
service/log/log_statistics.go

@@ -578,6 +578,9 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 		operator := computerData[code]
 		delete(computerData, code)
 		for gameId, num := range accountMps {
+			if gameId == "0" {
+				continue
+			}
 			csReply := new(log.LogComputer)
 			csReply.PcCode = code
 			if _, ok := onlineComputerMpa[csReply.PcCode]; ok {
@@ -988,6 +991,32 @@ func (s *ServiceStatisticsLog) GameStatistics(ctx context.Context, api log.LogCo
 	return statisticsLogsByGameId, total, err
 }
 
+func (s *ServiceStatisticsLog) TaskComputerNumInfo(ctx context.Context, reply request.IdDateReply) (interface{}, int64, error) {
+	if reply.ID == 0 {
+		return nil, 0, errors.New("参数错误")
+	}
+	createDate := time.Now().Format("2006-01-02")
+	if reply.CreateDate == "" {
+		createDate = time.Now().Format("2006-01-02")
+	} else {
+		createDate = reply.CreateDate
+	}
+
+	splitTime := strings.Split(createDate, "-")
+	table := "loging_" + splitTime[0] + "-" + splitTime[1]
+	fmt.Println(table)
+	db := global.GVA_DB.Table(table)
+	db = db.Select("pc_code,operator,pc_mac")
+	db = db.Where("create_date = ?", createDate)
+	db = db.Where("game_id = ?", reply.ID)
+	db = db.Group("pc_mac")
+	var total int64
+	db.Count(&total)
+	var computerInfos []response.TaskComputerInfoReply
+	db.Find(&computerInfos)
+	return computerInfos, total, nil
+}
+
 func (s *ServiceStatisticsLog) GameTargetInfo(ctx context.Context, date string, gameId string) (taskStatistics1 request.TaskStatistics) {
 	key := fmt.Sprintf(taskStatistics, date)
 	data, err := global.GVA_REDIS.HGet(ctx, key, gameId).Result()

+ 17 - 12
service/task/central_control_conf.go

@@ -10,7 +10,6 @@ import (
 )
 
 type CentralControlService struct {
-
 }
 
 //创建配置记录
@@ -27,7 +26,7 @@ func (s *CentralControlService) CreateCentralControlConf(conf task.CentralContro
 }
 
 //删除中控配置记录
-func (s *CentralControlService) DeleteCentralControlConf(conf task.CentralControlConf) (err error)  {
+func (s *CentralControlService) DeleteCentralControlConf(conf task.CentralControlConf) (err error) {
 	var entity task.CentralControlConf
 	err = global.GVA_DB.Model(&task.CentralControlConf{}).Where("id", conf.Id).First(&entity).Error
 	if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -59,30 +58,36 @@ func (s *CentralControlService) GetCentralControlConfById(id int) (conf task.Cen
 }
 
 //获取配置列表
-func (s *CentralControlService) GetCentralControlConfList(conf task.CentralControlConf, info request.PageInfo, order string, desc bool) (list interface{}, total int64, err error){
+func (s *CentralControlService) GetCentralControlConfList(conf task.CentralControlConfList, info request.PageInfo, order string, desc bool) (list interface{}, total int64, err error) {
 	//获取limit和offset
 	limit := info.PageSize
 	offset := (info.Page - 1) * info.PageSize
 	db := global.GVA_DB.Model(&task.CentralControlConf{})
-	var confList []task.CentralControlConf
+	var confList []task.CentralControlConfList
 
+	db = db.Select("central_control_conf.*, game_task.user")
+	db = db.Joins("left join game_task on central_control_conf.task_id = game_task.task_id")
 	//先条件过滤
 	if conf.TaskId != 0 {
 		//条件过滤记录数
-		db = db.Where("task_id", conf.TaskId)
+		db = db.Where("central_control_conf.task_id", conf.TaskId)
+	}
+
+	if conf.User != "" {
+		db = db.Where("game_task.user LIKE ?", "%"+conf.User+"%")
 	}
 
 	err = db.Count(&total).Error
-	if err != nil{
+	if err != nil {
 		//如果出错直接返回
 		return confList, total, err
 	} else {
 		//先分页再排序
 		db = db.Limit(limit).Offset(offset)
-		if order != ""{
+		if order != "" {
 			//传入排序字段,进行排序
 			//定义orderStr存储完整的排序字段
-			var  orderStr string
+			var orderStr string
 			//为了避免sql注入,自己创建数组匹配
 			orderMap := make(map[string]bool, 3)
 			orderMap["task_id"] = true
@@ -90,7 +95,7 @@ func (s *CentralControlService) GetCentralControlConfList(conf task.CentralContr
 			orderMap["update_time"] = true
 			if orderMap[order] {
 				if desc {
-					orderStr = order + " desc"
+					orderStr = "central_control_conf." + order + " desc"
 				} else {
 					orderStr = order
 				}
@@ -103,7 +108,7 @@ func (s *CentralControlService) GetCentralControlConfList(conf task.CentralContr
 			err = db.Order(orderStr).Find(&confList).Error
 		} else {
 			//没有传入排序字段,默认按照类型名称降序排序
-			err = db.Order("id desc").Find(&confList).Error
+			err = db.Order("central_control_conf.id desc").Find(&confList).Error
 		}
 	}
 	//是因为只有切片能排序,model没办法排序;还是说为了将数组返回至前端才find扫描至切片呢?
@@ -111,8 +116,8 @@ func (s *CentralControlService) GetCentralControlConfList(conf task.CentralContr
 }
 
 //获取云配置列表
-func (s *CentralControlService) GetCloudConfList() (dataList []task.CentralControlConf, err error)  {
+func (s *CentralControlService) GetCloudConfList() (dataList []task.CentralControlConf, err error) {
 	//获取所有的中控配置列表
 	err = global.GVA_DB.Model(&task.CentralControlConf{}).Find(&dataList).Error
 	return
-}
+}

+ 14 - 0
service/task/game_task.go

@@ -1263,3 +1263,17 @@ func (apiService *GameTask) TemporaryTask(ctx context.Context, pcCode string) (t
 	}
 	return temporaryConf, err
 }
+
+func (apiService *GameTask) GetSheepPay(ctx context.Context, money int, gameId string, payTime string) {
+	//formatTime, _ := time.Parse("2006-01-02 15:04:05", payTime)
+	//payDate := formatTime.Format("2006-01-02")
+	var sheepPay task.SheepPay
+	sheepPay.PayDate = payTime
+	sheepPay.PayTime = time.Now().Format("2006-01-02 15:04:05")
+	sheepPay.Money = money
+	sheepPay.GameId = gameId
+	err := global.GVA_DB.Create(&sheepPay).Error
+	if err != nil {
+		global.GVA_LOG.Error("保存SheepPay错误", zap.Error(err))
+	}
+}

+ 25 - 14
service/task/sync_data.go

@@ -171,11 +171,11 @@ func (s *SyncData) SyncTaskData() {
 		global.GVA_LOG.Error("CompleteTaskData get data fail", zap.Error(err))
 		return
 	}
-	wslData, err := s.SyncWslGameData(date)
-	if err != nil {
-		global.GVA_LOG.Error("SyncWslGameData get wsl data fail", zap.Error(err))
-		return
-	}
+	//wslData, err := s.SyncWslGameData(date)
+	//if err != nil {
+	//	global.GVA_LOG.Error("SyncWslGameData get wsl data fail", zap.Error(err))
+	//	//return
+	//}
 	for _, gameTask := range apiList {
 		var gameTarget task.GameTargetComplete
 		roomData, _ := s.SyncRoomData(date, gameTask.TaskId)
@@ -232,8 +232,9 @@ func (s *SyncData) SyncTaskData() {
 				GameId = "rose-" + taskId
 				gameTarget.PayComplete = roomData.PayComplete
 			}
-			if _, ok := wslData[GameId]; ok {
-				gameTarget.PayTarget = wslData[GameId]
+			b, sheepPay := s.SelectSheepPay(date, GameId)
+			if b {
+				gameTarget.PayTarget = sheepPay.Money
 				if gameTarget.PayTarget > completeTaskData[gameTask.TaskId].PayTarget {
 					lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, gameTask.TaskId)
 					_ = s.cache.SetCacheStr(context.Background(), lastPayAddUpdateTimeKey, time.Now().Unix())
@@ -265,6 +266,15 @@ func (s *SyncData) SyncTaskData() {
 	return
 }
 
+func (s *SyncData) SelectSheepPay(date string, gameId string) (b bool, sheepPay task.SheepPay) {
+	b = false
+	global.GVA_DB.Model(&task.SheepPay{}).Where("pay_date = ?", date).Where("game_id = ?", gameId).Order("id desc").Find(&sheepPay)
+	if sheepPay.Id != 0 {
+		b = true
+	}
+	return
+}
+
 // 定时同步机房群控、小绵羊数据
 func (s *SyncData) YesterdaySyncTaskData() {
 	db := global.GVA_DB.Model(&task.GameTask{})
@@ -291,11 +301,11 @@ func (s *SyncData) YesterdaySyncTaskData() {
 		global.GVA_LOG.Error("CompleteTaskData get data fail", zap.Error(err))
 		return
 	}
-	wslData, err := s.SyncWslGameData(date)
-	if err != nil {
-		global.GVA_LOG.Error("SyncWslGameData get wsl data fail", zap.Error(err))
-		return
-	}
+	//wslData, err := s.SyncWslGameData(date)
+	//if err != nil {
+	//	global.GVA_LOG.Error("SyncWslGameData get wsl data fail", zap.Error(err))
+	//	return
+	//}
 	for _, gameTask := range apiList {
 		var gameTarget task.GameTargetComplete
 		roomData, _ := s.SyncRoomData(date, gameTask.TaskId)
@@ -352,8 +362,9 @@ func (s *SyncData) YesterdaySyncTaskData() {
 				GameId = "rose-" + taskId
 				gameTarget.PayComplete = roomData.PayComplete
 			}
-			if _, ok := wslData[GameId]; ok {
-				gameTarget.PayTarget = wslData[GameId]
+			b, sheepPay := s.SelectSheepPay(date, GameId)
+			if b {
+				gameTarget.PayTarget = sheepPay.Money
 				if gameTarget.PayTarget > completeTaskData[gameTask.TaskId].PayTarget {
 					lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, gameTask.TaskId)
 					_ = s.cache.SetCacheStr(context.Background(), lastPayAddUpdateTimeKey, time.Now().Unix())