wangbin лет назад: 3
Родитель
Сommit
034b47df95
2 измененных файлов с 453 добавлено и 4 удалено
  1. 20 4
      model/typeManage/responsiblePerson.go
  2. 433 0
      service/task/sync_data.go

+ 20 - 4
model/typeManage/responsiblePerson.go

@@ -12,12 +12,12 @@ type ResponsiblePerson struct {
 	DepartmentName    string    `json:"department_name"`
 	MobilePhoneNumber string    `json:"mobile_phone_number"`
 	GameCounts        int64     `json:"game_counts"`
-	Custodians		  string	`json:"custodians"`
+	Custodians        string    `json:"custodians"`
 	Remark            string    `json:"remark"`
-	StartTime		  int64		`json:"start_time"`
-	Url				  string	`json:"url"`
+	StartTime         int64     `json:"start_time"`
+	Url               string    `json:"url"`
 	State             int8      `json:"state"`
-	PushStatus		  int8		`json:"push_status"`
+	PushStatus        int8      `json:"push_status"`
 	CreateTime        LocalTime `gorm:"column:create_time;" json:"createTime"`
 	UpdateTime        LocalTime `gorm:"column:update_time;" json:"updateTime"`
 }
@@ -43,3 +43,19 @@ func (m *ResponsiblePerson) GetUserInfo() (mps map[string]string, err error) {
 	}
 	return mp, err
 }
+
+func (m *ResponsiblePerson) GetUserInfoData() (mps map[string]ResponsiblePerson, err error) {
+	var person []ResponsiblePerson
+	err = global.GVA_DB.Table("responsible_person").Where("state = ?", 1).Find(&person).Error
+	if err != nil {
+		return
+	}
+	if len(person) == 0 {
+		return
+	}
+	var mp = map[string]ResponsiblePerson{}
+	for _, pc := range person {
+		mp[pc.Name] = pc
+	}
+	return mp, err
+}

+ 433 - 0
service/task/sync_data.go

@@ -860,3 +860,436 @@ func (s *SyncData) CheckTaskCompletedInfo() {
 		s.SendMsgData(url, sendData)
 	}
 }
+
+func (s *SyncData) TaskMsgSendRetainedDataUpdate(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, lastMsgSendTimeKey string) {
+	var mps = make(map[int]map[string]CompletedInfo)
+	lastMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastMsgSendTimeKey)
+	for _, complete := range completesInfo {
+		lastNewCompletedKey := fmt.Sprintf(LastNewCompletedKey, date, complete.TaskId)
+		lastRetainedCompletedKey := fmt.Sprintf(LastRetainedCompletedKey, date, complete.TaskId)
+		lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, complete.TaskId)
+		lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, complete.TaskId)
+		currentNewCompleted := complete.NewComplete + complete.HandNewComplete
+		currentRetainedCompleted := complete.RetainedComplete + complete.HandRetainedComplete
+		var RateMp = make(map[string]CompletedInfo)
+		var newBool = false
+		var retainedBoll = false
+		// 处理新增
+		if complete.NewTarget > currentNewCompleted {
+			lastNewCompleted, _ := s.cache.GetCacheNum(ctx, lastNewCompletedKey)
+			alsoNewTarget := complete.NewTarget - currentNewCompleted
+			newRate := 0
+			lastNewCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastNewCompletedUpdateTimeKey)
+			timeRate := int(ctime) - lastNewCompletedUpdateTime
+			if lastNewCompleted < currentNewCompleted {
+				newRate = currentNewCompleted - lastNewCompleted
+				_ = s.cache.SetCacheStr(ctx, lastNewCompletedKey, currentNewCompleted)
+				_ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
+			}
+			RateMp["newRate"] = CompletedInfo{
+				AlsoTarget: alsoNewTarget,
+				Rate:       newRate,
+				TimeRate:   timeRate,
+				TaskId:     complete.TaskId,
+			}
+		} else {
+			newBool = true
+			// 如果当前新增为0,或者完成也更新时间
+			_ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
+		}
+		// 处理留存
+		if complete.RetainedTarget > currentRetainedCompleted {
+			lastRetainedCompleted, _ := s.cache.GetCacheNum(ctx, lastRetainedCompletedKey)
+			alsoRetainedTarget := complete.RetainedTarget - currentRetainedCompleted
+			retainedRate := 0
+			lastRetainedCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastRetainedCompletedUpdateTimeKey)
+			timeRate := int(ctime) - lastRetainedCompletedUpdateTime
+			if lastRetainedCompleted < currentRetainedCompleted {
+				retainedRate = currentRetainedCompleted - lastRetainedCompleted
+				_ = s.cache.SetCacheStr(ctx, lastRetainedCompletedKey, currentRetainedCompleted)
+				_ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
+			}
+			RateMp["retainedRate"] = CompletedInfo{
+				AlsoTarget: alsoRetainedTarget,
+				Rate:       retainedRate,
+				TimeRate:   timeRate,
+				TaskId:     complete.TaskId,
+			}
+		} else {
+			retainedBoll = true
+			// 如果当前留存为0,或者完成也更新时间
+			_ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
+		}
+		if !newBool || !retainedBoll {
+			mps[complete.TaskId] = RateMp
+		}
+	}
+
+	var taskStatistics = "%s:taskStatistics"
+	var retained = "# 活跃播报 "
+	if len(mps) == 0 {
+		global.GVA_LOG.Warn(retained)
+	}
+	retained += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
+	var errMsg = "**以下游戏目标效率为零:**"
+	var errMsgZ = ""
+	var sendMsg = map[string]string{}
+	var errSendMsg = map[string]string{}
+	var m int // 时间内
+	m = (int(ctime) - lastMsgSendTime) / 60
+	for taskId, data := range mps {
+		key := fmt.Sprintf(taskStatistics, date)
+		gameIdStr := strconv.Itoa(taskId)
+		gameTask, err := global.GVA_REDIS.HGet(ctx, key, gameIdStr).Result()
+		if err != nil {
+			if err == redis.Nil {
+				continue
+			} else {
+				global.GVA_LOG.Error("TaskMsgSendRetainedData获取缓存任务数据失败", zap.Error(err))
+				continue
+			}
+		}
+		var taskStatistics request.TaskStatistics
+		_ = json.Unmarshal([]byte(gameTask), &taskStatistics)
+		var eMsg = "" //单条异常数据
+		var isNew = false
+		var nm int      //新增时间内
+		var rm int      //存时间内
+		var rate string //效率
+		var newErr = false
+		var retainedErr = false
+		var name = taskStatistics.Remark
+		if info, ok := data["newRate"]; ok {
+			sendMsg[name] += "\n"
+			sendMsg[name] += taskStatistics.GameName
+			sendMsg[name] += ",新增差"
+			//sendMsg[name] += strconv.Itoa(info.AlsoTarget)
+			sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", info.AlsoTarget)
+			isNew = true
+			if info.TimeRate > 60*60*24 {
+				lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, info.TaskId)
+				_ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
+				nm = 1
+			} else {
+				nm = info.TimeRate / 60
+			}
+			rate = strconv.Itoa(info.Rate)
+			if info.Rate == 0 {
+				newErr = true
+			}
+		}
+		if info, ok := data["retainedRate"]; ok {
+			if !isNew {
+				sendMsg[name] += "\n"
+				sendMsg[name] += taskStatistics.GameName
+				rate = strconv.Itoa(info.Rate)
+				sendMsg[name] += "活跃差"
+			} else {
+				rate += "/" + strconv.Itoa(info.Rate)
+				sendMsg[name] += ",活跃差"
+			}
+			if info.TimeRate > 60*60*24 {
+				lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, info.TaskId)
+				_ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
+				rm = 1
+			} else {
+				rm = info.TimeRate / 60
+			}
+
+			//sendMsg[name] += strconv.Itoa(info.AlsoTarget)
+			sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", info.AlsoTarget)
+			if info.Rate == 0 {
+				retainedErr = true
+			}
+		}
+		// 5分钟数据没动报异常数据
+		if newErr && nm > 4 {
+			eMsg += "\n"
+			eMsg += taskStatistics.GameName
+			eMsg += ",新增"
+			if nm >= 60 {
+				eMsg += "("
+				eMsg += strconv.Itoa(nm / 60)
+				eMsg += "小时内)"
+			} else {
+				eMsg += "("
+				eMsg += strconv.Itoa(nm)
+				eMsg += "分钟内)"
+			}
+		}
+		if retainedErr && rm > 4 {
+			if !newErr {
+				eMsg += "\n"
+				eMsg += taskStatistics.GameName
+			}
+			eMsg += ",活跃"
+			if rm >= 60 {
+				eMsg += "("
+				eMsg += strconv.Itoa(rm / 60)
+				eMsg += "小时内)"
+			} else {
+				eMsg += "("
+				eMsg += strconv.Itoa(rm)
+				eMsg += "分钟内)"
+			}
+		}
+		if eMsg != "" {
+			errMsgZ += eMsg
+			errSendMsg[name] += eMsg
+		}
+		sendMsg[name] += ","
+		if m >= 60 {
+			sendMsg[name] += strconv.Itoa(m / 60)
+			sendMsg[name] += "小时内完成"
+		} else {
+			sendMsg[name] += strconv.Itoa(m)
+			sendMsg[name] += "分钟内完成"
+		}
+		//sendMsg[name] += rate
+		sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%s</font>", rate)
+	}
+	hour := time.Now().Hour()
+	msg := ""
+	mpsPerson, _ := s.Person.GetUserInfoData()
+	//b1 ,_ := json.Marshal(mpsPerson)
+	//global.GVA_LOG.Warn(string(b1))
+	var mobile []string
+	if hour >= 16 {
+		if len(sendMsg) == 0 {
+			return
+		}
+		if len(mps) != 0 && len(errSendMsg) != 0 {
+			for name, _ := range errSendMsg {
+				mobile = append(mobile, mpsPerson[name].MobilePhoneNumber)
+			}
+		}
+		for name, msg := range sendMsg {
+			retained += "\n"
+			retained += "**" + name + "**"
+			retained += msg
+		}
+		msg = retained
+		if errMsgZ != "" {
+			msg += "\n"
+			//msg += errMsg + errMsgZ
+			msg += fmt.Sprintf("<font color=\"warning\">%s</font>", errMsg+errMsgZ)
+		}
+		for pName, pMsg := range sendMsg {
+			if hour >= mpsPerson[pName].StartTime {
+				personMsg := pMsg
+				if _, ok := errSendMsg[pName]; ok {
+					personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", errSendMsg[pName])
+				}
+				url := mpsPerson[pName].Url
+				var sendPersonData SendMsg
+				sendPersonData.MsgType = "markdown"
+				sendPersonData.Markdown.Content = personMsg
+				s.SendMsgData(url, sendPersonData)
+			}
+		}
+	} else {
+		if errMsgZ != "" {
+			//msg += errMsg + errMsgZ
+		}
+		if len(mps) != 0 && len(errSendMsg) != 0 {
+			msg += "# 活跃播报 "
+			msg += errMsg
+			for name, m := range errSendMsg {
+				mobile = append(mobile, mpsPerson[name].MobilePhoneNumber)
+				msg += "\n"
+				msg += "**" + name + "**"
+				msg += fmt.Sprintf("<font color=\"warning\">%s</font>", m)
+			}
+		}
+		for pName, pMsg := range sendMsg {
+			if hour >= mpsPerson[pName].StartTime {
+				personMsg := pMsg
+				if _, ok := errSendMsg[pName]; ok {
+					personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", errSendMsg[pName])
+				}
+				url := mpsPerson[pName].Url
+				var sendPersonData SendMsg
+				sendPersonData.MsgType = "markdown"
+				sendPersonData.Markdown.Content = personMsg
+				s.SendMsgData(url, sendPersonData)
+			}
+		}
+	}
+	//global.GVA_LOG.Warn(msg)
+	_ = s.cache.SetCacheStr(ctx, lastMsgSendTimeKey, time.Now().Unix())
+	if msg == "" {
+		return
+	}
+	url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
+	var sendData SendMsg
+	sendData.MsgType = "markdown"
+	sendData.Markdown.Content = msg
+	s.SendMsgData(url, sendData)
+
+	if len(mobile) != 0 {
+		var sendTextData SendTextMsg
+		sendTextData.MsgType = "text"
+		sendTextData.Text.MentionedMobileList = mobile
+		//b ,_ := json.Marshal(sendTextData)
+		//global.GVA_LOG.Warn(string(b))
+		s.SendMsgData(url, sendTextData)
+	}
+}
+
+func (s *SyncData) TaskMsgSendFreeDataUpdate(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, lastFreeMsgSendTimeKey string, isOne bool) {
+	var RateMp = make(map[int]CompletedInfo)
+	lastFreeMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastFreeMsgSendTimeKey)
+	for _, complete := range completesInfo {
+		lastPayCompletedKey := fmt.Sprintf(LastPayCompletedKey, date, complete.TaskId)
+		lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, complete.TaskId)
+		lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, complete.TaskId)
+		currentPayCompleted := complete.PayComplete + complete.HandPayComplete
+		// 付费处理
+		if complete.PayTarget != 0 && complete.PayTarget > currentPayCompleted {
+			lastPayCompleted, _ := s.cache.GetCacheNum(ctx, lastPayCompletedKey)
+			alsoPayTarget := complete.PayTarget - currentPayCompleted
+			payRate := 0
+			lastPayCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastPayCompletedUpdateTimeKey)
+			lastPayAddUpdateTime, _ := s.cache.GetCacheNum(ctx, lastPayAddUpdateTimeKey)
+			timeRate := int(ctime) - lastPayCompletedUpdateTime
+			if lastPayCompleted < currentPayCompleted {
+				payRate = currentPayCompleted - lastPayCompleted
+				_ = s.cache.SetCacheStr(ctx, lastPayCompletedKey, currentPayCompleted)
+				_ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
+			}
+			RateMp[complete.TaskId] = CompletedInfo{
+				AlsoTarget:       alsoPayTarget,
+				Rate:             payRate,
+				TimeRate:         timeRate,
+				TaskId:           complete.TaskId,
+				AddPayUpdateTime: lastPayAddUpdateTime,
+			}
+		} else {
+			// 如果当前付费为0,或者完成也更新时间
+			_ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
+		}
+	}
+	if isOne {
+		_ = s.cache.SetCacheStr(ctx, lastFreeMsgSendTimeKey, time.Now().Unix())
+		return
+	}
+	if len(RateMp) == 0 {
+		global.GVA_LOG.Info("TaskMsgSendFreeData没有查询到未完成付费数据")
+		return
+	}
+	var taskStatistics = "%s:taskStatistics"
+	var retained = "付费播报 "
+	retained += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
+	var errMsg = "**以下游戏付费效率为零:**"
+	var errMsgZ = ""
+	var sendMsg = map[string]string{}
+	var m int //时间内
+	m = (int(ctime) - lastFreeMsgSendTime) / 60
+	mpsPerson, _ := s.Person.GetUserInfoData()
+	var mobile []string
+	for taskId, data := range RateMp {
+		if data.AlsoTarget <= 0 {
+			continue
+		}
+		key := fmt.Sprintf(taskStatistics, date)
+		gameIdStr := strconv.Itoa(taskId)
+		gameTask, err := global.GVA_REDIS.HGet(ctx, key, gameIdStr).Result()
+		if err != nil {
+			if err == redis.Nil {
+				continue
+			} else {
+				global.GVA_LOG.Error("TaskMsgSendRetainedData获取缓存任务数据失败", zap.Error(err))
+				continue
+			}
+		}
+		var taskStatistics request.TaskStatistics
+		_ = json.Unmarshal([]byte(gameTask), &taskStatistics)
+
+		var name = taskStatistics.Remark
+		sendMsg[name] += "\n"
+		sendMsg[name] += taskStatistics.GameName
+		sendMsg[name] += ",付费差"
+		//sendMsg[name] += strconv.Itoa(data.AlsoTarget)
+		sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", data.AlsoTarget)
+
+		if data.TimeRate > 60*60*24 {
+			lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, data.TaskId)
+			_ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
+			data.TimeRate = 60 * 60 * 2
+		}
+		// 5分钟数据没动报异常数据
+		if data.TimeRate/60 >= 2 {
+			if data.Rate == 0 {
+				lastPayAddNumKey := fmt.Sprintf(LastPayAddNumKey, date, data.TaskId)
+				payErrAddNumKey := fmt.Sprintf(PayErrAddNumKey, date, data.TaskId)
+				numErr, _ := s.cache.GetCacheNum(context.Background(), payErrAddNumKey)
+				lastAddFeeNumErr, _ := s.cache.GetCacheNum(context.Background(), lastPayAddNumKey)
+				errMsgZ += "\n"
+				errMsgZ += taskStatistics.GameName
+				errMsgZ += "("
+				if data.TimeRate/60 >= 60 {
+					errMsgZ += strconv.Itoa(data.TimeRate / 60 / 60)
+					errMsgZ += "小时内(+" + strconv.Itoa(numErr) + "))"
+				} else {
+					errMsgZ += strconv.Itoa(data.TimeRate / 60)
+					errMsgZ += "分钟内(+" + strconv.Itoa(numErr) + "))"
+				}
+				errMsgZ += ","
+				errMsgZ += "最后加付费时间 "
+				t := time.Unix(int64(data.AddPayUpdateTime), 0)
+				errMsgZ += t.Format("15:04:05")
+				errMsgZ += "(+" + strconv.Itoa(lastAddFeeNumErr) + ")"
+				if _, ok := mpsPerson[name]; ok {
+					mobile = append(mobile, mpsPerson[name].MobilePhoneNumber)
+				}
+			}
+		}
+		sendMsg[name] += ","
+		if m >= 60 {
+			sendMsg[name] += strconv.Itoa(m / 60)
+			sendMsg[name] += "分钟内完成"
+		} else {
+			sendMsg[name] += strconv.Itoa(m)
+			sendMsg[name] += "分钟内完成"
+		}
+		//sendMsg[name] += strconv.Itoa(data.Rate)
+		sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", data.Rate)
+	}
+	if len(sendMsg) == 0 {
+		return
+	}
+	hour := time.Now().Hour()
+	for name, msg := range sendMsg {
+		retained += "\n"
+		retained += name
+		retained += msg
+		if hour >= mpsPerson[name].StartTime {
+			personMsg := msg
+			url := mpsPerson[name].Url
+			var sendPersonData SendMsg
+			sendPersonData.MsgType = "markdown"
+			sendPersonData.Markdown.Content = personMsg
+			s.SendMsgData(url, sendPersonData)
+		}
+	}
+	msg := retained
+	if errMsgZ != "" {
+		msg += "\n"
+		//msg += errMsg + errMsgZ
+		msg += fmt.Sprintf("<font color=\"warning\">%s</font>", errMsg+errMsgZ)
+	}
+	global.GVA_LOG.Warn(msg)
+	_ = s.cache.SetCacheStr(ctx, lastFreeMsgSendTimeKey, time.Now().Unix())
+	url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
+	var sendData SendMsg
+	sendData.MsgType = "markdown"
+	sendData.Markdown.Content = msg
+	s.SendMsgData(url, sendData)
+	if len(mobile) != 0 {
+		var sendTextData SendTextMsg
+		sendTextData.MsgType = "text"
+		sendTextData.Text.MentionedMobileList = mobile
+		s.SendMsgData(url, sendTextData)
+	}
+	return
+}