|
|
@@ -13,6 +13,7 @@ import (
|
|
|
"log-server/model/task"
|
|
|
"log-server/model/task/control"
|
|
|
request2 "log-server/model/task/request"
|
|
|
+ "log-server/service/cache"
|
|
|
"log-server/utils"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
@@ -20,6 +21,7 @@ import (
|
|
|
|
|
|
type SyncData struct {
|
|
|
GameTask GameTask
|
|
|
+ cache cache.Cache
|
|
|
}
|
|
|
|
|
|
func (s *SyncData) SyncXmyGameData(date string) (mps map[int]control.XmyPayRequestReplyData, err error) {
|
|
|
@@ -255,3 +257,457 @@ func (s *SyncData) DayTargetDataStatistics() {
|
|
|
}
|
|
|
global.GVA_DB.Omit("update_time").Create(gameTargetDates)
|
|
|
}
|
|
|
+
|
|
|
+var LastMsgSendTimeKey = "%s:lastMsgSendTime"
|
|
|
+var LastNewCompletedKey = "%s:msgSendInfo:%d:lastNewCompleted"
|
|
|
+var LastPayCompletedKey = "%s:msgSendInfo:%d:lastPayCompleted"
|
|
|
+var LastRetainedCompletedKey = "%s:msgSendInfo:%d:lastRetainedCompleted"
|
|
|
+var LastNewCompletedUpdateTimeKey = "%s:msgSendInfo:%d:lastNewCompletedUpdateTime"
|
|
|
+var LastPayCompletedUpdateTimeKey = "%s:msgSendInfo:%d:lastPayCompletedUpdateTime"
|
|
|
+var LastRetainedCompletedUpdateTimeKey = "%s:msgSendInfo:%d:lastRetainedCompletedUpdateTime"
|
|
|
+var LastPayAddUpdateTimeKey = "%s:msgSendInfo:%d:lastPayAddUpdateTime"
|
|
|
+var TaskCompletedStatusKey = "%s:taskCompletedStatus"
|
|
|
+var LastFreeMsgSendTimeKey = "%s:lastFreeMsgSendTime"
|
|
|
+
|
|
|
+type CompletedInfo struct {
|
|
|
+ AlsoTarget int //剩余数量
|
|
|
+ Rate int //时间段做的任务数
|
|
|
+ TimeRate int // 完成任务数据更新时间
|
|
|
+ TaskId int
|
|
|
+ AddPayUpdateTime int
|
|
|
+}
|
|
|
+
|
|
|
+// 获取未完成的任务数据
|
|
|
+func (s *SyncData) TaskNoCompleteDate(date string) (completesInfo []task.GameTargetComplete, err error) {
|
|
|
+ db := global.GVA_DB.Table("game_target_complete")
|
|
|
+ db = db.Where("is_complete = ?", -1)
|
|
|
+ db = db.Where("create_date = ?", date)
|
|
|
+ err = db.Find(&completesInfo).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (s *SyncData) TaskMsgSendInitData(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, taskCompletedStatusKey, lastMsgSendTimeKey string) {
|
|
|
+ for _, complete := range completesInfo {
|
|
|
+ lastNewCompletedKey := fmt.Sprintf(LastNewCompletedKey, date, complete.TaskId)
|
|
|
+ lastPayCompletedKey := fmt.Sprintf(LastPayCompletedKey, date, complete.TaskId)
|
|
|
+ lastRetainedCompletedKey := fmt.Sprintf(LastRetainedCompletedKey, date, complete.TaskId)
|
|
|
+ lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, complete.TaskId)
|
|
|
+ lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, complete.TaskId)
|
|
|
+ lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, complete.TaskId)
|
|
|
+ lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, complete.TaskId)
|
|
|
+ lastNewCompleted := complete.NewComplete + complete.HandNewComplete //上次新增完成数
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastNewCompletedKey, lastNewCompleted)
|
|
|
+ lastPayCompleted := complete.PayComplete + complete.HandPayComplete //上次支付完成数
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastPayCompletedKey, lastPayCompleted)
|
|
|
+ lastRetainedCompleted := complete.RetainedComplete + complete.HandRetainedComplete //上次活跃完成数
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedKey, lastRetainedCompleted)
|
|
|
+ //lastNewCompletedUpdateTime := complete.NewComplete //上次新增完成更新时间
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime)
|
|
|
+ //lastPayCompletedUpdateTime := complete.NewComplete //上次支付完成更新时间
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime)
|
|
|
+ //lastRetainedCompletedUpdateTime := complete.NewComplete //上次留存完成更新时间
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime)
|
|
|
+ //lastPayAddUpdateTime := complete.NewComplete //上次付费增加更新时间
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastPayAddUpdateTimeKey, ctime)
|
|
|
+ }
|
|
|
+ _ = s.cache.SetCacheStr(ctx, taskCompletedStatusKey, -1)
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastMsgSendTimeKey, time.Now().Unix())
|
|
|
+}
|
|
|
+
|
|
|
+func (s *SyncData) TaskMsgSendRetainedData(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 = "活跃播报 " + time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ if len(mps) == 0 {
|
|
|
+ global.GVA_LOG.Warn(retained)
|
|
|
+ }
|
|
|
+ var errMsg = "以下游戏目标效率为零:"
|
|
|
+ var errMsgZ = ""
|
|
|
+ var sendMsg = 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 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)
|
|
|
+ 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)
|
|
|
+ if info.Rate == 0 {
|
|
|
+ retainedErr = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5分钟数据没动报异常数据
|
|
|
+ if newErr && nm > 4 {
|
|
|
+ errMsgZ += "\n"
|
|
|
+ errMsgZ += taskStatistics.GameName
|
|
|
+ errMsgZ += ",新增"
|
|
|
+ if nm >= 60 {
|
|
|
+ errMsgZ += "("
|
|
|
+ errMsgZ += strconv.Itoa(nm / 60)
|
|
|
+ errMsgZ += "小时内)"
|
|
|
+ } else {
|
|
|
+ errMsgZ += "("
|
|
|
+ errMsgZ += strconv.Itoa(nm)
|
|
|
+ errMsgZ += "分钟内)"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if retainedErr && rm > 4 {
|
|
|
+ if !newErr {
|
|
|
+ errMsgZ += "\n"
|
|
|
+ errMsgZ += taskStatistics.GameName
|
|
|
+ }
|
|
|
+ errMsgZ += ",活跃"
|
|
|
+ if rm >= 60 {
|
|
|
+ errMsgZ += "("
|
|
|
+ errMsgZ += strconv.Itoa(rm / 60)
|
|
|
+ errMsgZ += "小时内)"
|
|
|
+ } else {
|
|
|
+ errMsgZ += "("
|
|
|
+ errMsgZ += strconv.Itoa(rm)
|
|
|
+ errMsgZ += "分钟内)"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sendMsg[name] += ","
|
|
|
+ if m >= 60 {
|
|
|
+ sendMsg[name] += strconv.Itoa(m / 60)
|
|
|
+ sendMsg[name] += "小时内完成"
|
|
|
+ } else {
|
|
|
+ sendMsg[name] += strconv.Itoa(m)
|
|
|
+ sendMsg[name] += "分钟内完成"
|
|
|
+ }
|
|
|
+ sendMsg[name] += rate
|
|
|
+ }
|
|
|
+
|
|
|
+ for name, msg := range sendMsg {
|
|
|
+ retained += "\n"
|
|
|
+ retained += name
|
|
|
+ retained += msg
|
|
|
+ }
|
|
|
+ msg := retained
|
|
|
+ if errMsgZ != "" {
|
|
|
+ msg += "\n"
|
|
|
+ msg += errMsg + errMsgZ
|
|
|
+ }
|
|
|
+ global.GVA_LOG.Warn(msg)
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastMsgSendTimeKey, time.Now().Unix())
|
|
|
+}
|
|
|
+
|
|
|
+func (s *SyncData) TaskMsgSendFreeData(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 = "付费播报 " + 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
|
|
|
+ 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)
|
|
|
+
|
|
|
+ if data.TimeRate > 60*60*24 {
|
|
|
+ lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, data.TaskId)
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
|
|
|
+ }
|
|
|
+ // 5分钟数据没动报异常数据
|
|
|
+ if data.TimeRate/60 >= 4 {
|
|
|
+ if data.Rate == 0 {
|
|
|
+ errMsgZ += "\n"
|
|
|
+ errMsgZ += taskStatistics.GameName
|
|
|
+ errMsgZ += "("
|
|
|
+ if data.TimeRate/60 >= 60 {
|
|
|
+ errMsgZ += strconv.Itoa(data.TimeRate / 60 / 60)
|
|
|
+ errMsgZ += "小时内)"
|
|
|
+ } else {
|
|
|
+ errMsgZ += strconv.Itoa(data.TimeRate / 60)
|
|
|
+ errMsgZ += "分钟内)"
|
|
|
+ }
|
|
|
+ errMsgZ += ","
|
|
|
+ errMsgZ += "最后加付费时间 "
|
|
|
+ t := time.Unix(int64(data.AddPayUpdateTime), 0)
|
|
|
+ errMsgZ += t.Format("15:04:05")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ for name, msg := range sendMsg {
|
|
|
+ retained += "\n"
|
|
|
+ retained += name
|
|
|
+ retained += msg
|
|
|
+ }
|
|
|
+ msg := retained
|
|
|
+ if errMsgZ != "" {
|
|
|
+ msg += "\n"
|
|
|
+ msg += errMsg + errMsgZ
|
|
|
+ }
|
|
|
+ global.GVA_LOG.Warn(msg)
|
|
|
+ _ = s.cache.SetCacheStr(ctx, lastFreeMsgSendTimeKey, time.Now().Unix())
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//活跃新增数据推送
|
|
|
+func (s *SyncData) TaskMsgSend() {
|
|
|
+ date := time.Now().Format("2006-01-02")
|
|
|
+ ctx := context.Background()
|
|
|
+ taskCompletedStatusKey := fmt.Sprintf(TaskCompletedStatusKey, date)
|
|
|
+ taskCompletedStatus, _ := s.cache.GetCacheNum(ctx, taskCompletedStatusKey)
|
|
|
+ if taskCompletedStatus == 1 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ completesInfo, err := s.TaskNoCompleteDate(date)
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("TaskMsgSend查询任务数据报错", zap.Error(err))
|
|
|
+ }
|
|
|
+ if len(completesInfo) == 0 {
|
|
|
+ global.GVA_LOG.Info("TaskMsgSend没有查询到未完成数据")
|
|
|
+ }
|
|
|
+ lastMsgSendTimeKey := fmt.Sprintf(LastMsgSendTimeKey, date)
|
|
|
+ b, err := s.cache.ExistsKey(context.Background(), lastMsgSendTimeKey)
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("TaskMsgSend查询任务数据报错", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ctime := time.Now().Unix()
|
|
|
+ if !b {
|
|
|
+ s.TaskMsgSendInitData(ctx, completesInfo, ctime, date, taskCompletedStatusKey, lastMsgSendTimeKey)
|
|
|
+ } else {
|
|
|
+ lastMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastMsgSendTimeKey)
|
|
|
+ if int(ctime)-lastMsgSendTime < 60 {
|
|
|
+ global.GVA_LOG.Error("TaskMsgSend上次数据发送时间还没到5分钟", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ s.TaskMsgSendRetainedData(ctx, completesInfo, ctime, date, lastMsgSendTimeKey)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//活跃新增数据推送
|
|
|
+func (s *SyncData) TaskFreeMsgSend() {
|
|
|
+ date := time.Now().Format("2006-01-02")
|
|
|
+ ctx := context.Background()
|
|
|
+ taskCompletedStatusKey := fmt.Sprintf(TaskCompletedStatusKey, date)
|
|
|
+ taskCompletedStatus, _ := s.cache.GetCacheNum(ctx, taskCompletedStatusKey)
|
|
|
+ if taskCompletedStatus == 1 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ completesInfo, err := s.TaskNoCompleteDate(date)
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("TaskMsgSend查询任务数据报错", zap.Error(err))
|
|
|
+ }
|
|
|
+ if len(completesInfo) == 0 {
|
|
|
+ global.GVA_LOG.Info("TaskMsgSend没有查询到未完成数据")
|
|
|
+ }
|
|
|
+ lastFreeMsgSendTimeKey := fmt.Sprintf(LastFreeMsgSendTimeKey, date)
|
|
|
+
|
|
|
+ ctime := time.Now().Unix()
|
|
|
+ lastFreeMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastFreeMsgSendTimeKey)
|
|
|
+ if int(ctime)-lastFreeMsgSendTime < 60 {
|
|
|
+ global.GVA_LOG.Error("TaskMsgSend上次数据发送时间还没到5分钟", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var isOne = false
|
|
|
+ if lastFreeMsgSendTime == 0 {
|
|
|
+ isOne = true
|
|
|
+ }
|
|
|
+ s.TaskMsgSendFreeData(ctx, completesInfo, ctime, date, lastFreeMsgSendTimeKey, isOne)
|
|
|
+}
|
|
|
+
|
|
|
+func (s *SyncData) CheckTaskCompletedInfo() {
|
|
|
+ date := time.Now().Format("2006-01-02")
|
|
|
+ ctx := context.Background()
|
|
|
+ taskCompletedStatusKey := fmt.Sprintf(TaskCompletedStatusKey, date)
|
|
|
+ completesInfo, err := s.TaskNoCompleteDate(date)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ global.GVA_LOG.Error("CheckTaskCompletedInfo查询任务数据报错", zap.Error(err))
|
|
|
+ }
|
|
|
+ if len(completesInfo) == 0 {
|
|
|
+ global.GVA_LOG.Info("TaskMsgSend没有查询到未完成数据")
|
|
|
+ time.Sleep(time.Minute * 1)
|
|
|
+ _ = s.cache.SetCacheStr(ctx, taskCompletedStatusKey, 1)
|
|
|
+ }
|
|
|
+}
|