소스 검색

租机数据迁移

wangbin 3 년 전
부모
커밋
e228c12ca1
3개의 변경된 파일71개의 추가작업 그리고 67개의 파일을 삭제
  1. 1 17
      model/log/computer.go
  2. 17 50
      service/log/log_statistics.go
  3. 53 0
      service/task/regular_task.go

+ 1 - 17
model/log/computer.go

@@ -28,23 +28,7 @@ func (c *Computer) OnlinePcCodeCache() (mps map[string]string, err error) {
 		mps, err = global.GVA_REDIS.HGetAll(ctx, OnlinePcCode).Result()
 		return
 	}
-	var computers []*Computer
-	err = global.GVA_DB.Where("status = ?", 1).Find(&computers).Error
-	if err != nil {
-		return
-	}
-	if len(computers) == 0 {
-		return
-	}
-	var mp = map[string]string{}
-	for _, pc := range computers {
-		mp[pc.PcCode] = pc.User
-	}
-	err = global.GVA_REDIS.HSet(ctx, OnlinePcCode, mp).Err()
-	if err != nil {
-		return
-	}
-	return mp, err
+	return
 }
 
 // 更新单条缓存数据

+ 17 - 50
service/log/log_statistics.go

@@ -516,12 +516,20 @@ func (s *ServiceStatisticsLog) CreateComputerStatisticsData() {
 	onlineComputerMpa, _ := s.LogicalLog.GetOnlineComputerNumCache(ctx, s.LogicalLog.CurrentDate())
 	var computer log.Computer
 	computerData, _ := computer.OnlinePcCodeCache()
+	if computerData == nil {
+		global.GVA_LOG.Warn("电脑缓存数据获取失败TaskStatisticsDataCache")
+		return
+	}
 	var csReplys []*log.LogComputer
 	for code, r := range codeMps {
 		// 不统计不在电脑列表里的
 		if _, ok := computerData[code]; !ok {
 			continue
 		}
+		// 负责人为空的不统计
+		if computerData[code] == "" {
+			continue
+		}
 		accountMps, err := s.LogicalLog.GetComputerPullAccountNumCache(ctx, s.LogicalLog.CurrentDate(), code)
 		if err != nil {
 			continue
@@ -980,56 +988,6 @@ func (s *ServiceStatisticsLog) ComputerTest(c context.Context) (interface{}, err
 	return mps, err
 }
 
-// RegularCheckPc1 定时检查电脑情况
-func (s *ServiceStatisticsLog) RegularCheckPc1() {
-	ctx := context.Background()
-	date := s.LogicalLog.CurrentDate()
-	// 获取当天已上报的电脑数据
-	onlineComputerMpa, _ := s.LogicalLog.GetOnlineComputerNumCache(ctx, date)
-	// 获取数据库的数据
-	var computer log.Computer
-	computers, err := computer.OnlinePcCodeCache()
-	if err != nil {
-		global.GVA_LOG.Error("获取租机表数据失败", zap.Error(err))
-	}
-	// 查询两小时内上报的数据
-	var noReportingPc []string
-	for pc, _ := range onlineComputerMpa {
-		num := s.LogicalLog.GetPcReportingLog(ctx, pc)
-		delete(computers, pc)
-		if num == 0 {
-			noReportingPc = append(noReportingPc, pc)
-		}
-	}
-	// 未上报逻辑
-	var errReportingPc []string
-	for pc, name := range computers {
-		if name == "备用" {
-			continue
-		}
-		errReportingPc = append(errReportingPc, pc)
-	}
-	var content string
-	if len(errReportingPc) != 0 {
-		// 发信息数据群里
-		content += fmt.Sprintf("异常租机数据<font color=\"warning\">%d台</font>: %s", len(errReportingPc), errReportingPc)
-	}
-	if len(noReportingPc) != 0 {
-		// 发信息数据群里
-		content += "\n"
-		content += fmt.Sprintf("两小时内未检测到中控数据<font color=\"warning\">%d台</font>: %s", len(noReportingPc), noReportingPc)
-	}
-	if content != "" {
-		var sendMsg SendMsg
-		sendMsg.MsgType = "markdown"
-		sendMsg.Markdown.Content = content
-		//c ,_ := json.Marshal(sendMsg)
-		url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
-		//url := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7d095d5b-8240-45fd-a68c-baff3628d83b"
-		_, err = s.SendMsgData(url, sendMsg)
-	}
-}
-
 // 定时检查电脑情况
 func (s *ServiceStatisticsLog) RegularCheckPc() {
 	ctx := context.Background()
@@ -1038,6 +996,11 @@ func (s *ServiceStatisticsLog) RegularCheckPc() {
 	//computersF, err := computer.OnlinePcCodeCache()
 	if err != nil {
 		global.GVA_LOG.Error("获取租机表数据失败", zap.Error(err))
+		return
+	}
+	if computers == nil {
+		global.GVA_LOG.Warn("电脑缓存数据获取失败TaskStatisticsDataCache")
+		return
 	}
 	// 查询两小时内上报的数据
 	var computersF = map[string]string{}
@@ -1048,6 +1011,10 @@ func (s *ServiceStatisticsLog) RegularCheckPc() {
 			delete(computers, pc)
 			continue
 		}
+		if name == "" {
+			delete(computers, pc)
+			continue
+		}
 		num := s.LogicalLog.GetPcReportingLog(ctx, pc)
 		delete(computers, pc)
 		if num == 0 {

+ 53 - 0
service/task/regular_task.go

@@ -0,0 +1,53 @@
+package task
+
+import (
+	"context"
+	"go.uber.org/zap"
+	"log-server/global"
+	"log-server/model/rentComputer"
+)
+
+type ServiceRegularTask struct {
+}
+
+const OnlinePcCode = "Online:PcCode"
+
+func (s *ServiceRegularTask) OnlinePcCodeUpdateCache() {
+	ctx := context.Background()
+	isNull, err := global.GVA_REDIS.Exists(ctx, OnlinePcCode).Result()
+	mps := map[string]string{}
+	if isNull != 0 {
+		mps, err = global.GVA_REDIS.HGetAll(ctx, OnlinePcCode).Result()
+		if err != nil {
+			global.GVA_LOG.Error("OnlinePcCodeUpdateCache获取表失败", zap.Error(err))
+			return
+		}
+	}
+	var computers []*rentComputer.RentComputer
+	err = global.GVA_DB.Where("is_off_shelf = ?", 0).Find(&computers).Error
+	if err != nil {
+		global.GVA_LOG.Error("OnlinePcCodeUpdateCache获取表失败", zap.Error(err))
+		return
+	}
+	if len(computers) == 0 {
+		return
+	}
+	var mp = map[string]string{}
+	for _, pc := range computers {
+		mp[pc.PcNum] = pc.DirectorName
+		if _, ok := mps[pc.PcNum]; ok {
+			delete(mps, pc.PcNum)
+		}
+	}
+	err = global.GVA_REDIS.HSet(ctx, OnlinePcCode, mp).Err()
+	if err != nil {
+		global.GVA_LOG.Error("OnlinePcCodeUpdateCache更新缓存失败", zap.Error(err))
+		return
+	}
+	if mps != nil {
+		for code, _ := range mps {
+			global.GVA_REDIS.HDel(ctx, OnlinePcCode, code)
+		}
+	}
+	return
+}