2 次代码提交 1ddfc7c462 ... 27446a39ee

作者 SHA1 备注 提交日期
  wangbin 27446a39ee Merge remote-tracking branch 'origin/master' 2 年之前
  wangbin 3a623d9656 等级上报统计 2 年之前
共有 2 个文件被更改,包括 141 次插入1 次删除
  1. 74 1
      model/levelMonitor/image_record.go
  2. 67 0
      service/levelMonitor/image_record.go

+ 74 - 1
model/levelMonitor/image_record.go

@@ -1,6 +1,8 @@
 package levelMonitor
 
-import "log-server/model/typeManage"
+import (
+	"log-server/model/typeManage"
+)
 
 type ImageRecord struct {
 	Id          int                  `json:"id"`
@@ -19,3 +21,74 @@ type ImageRecord struct {
 func (ImageRecord) TableName() string {
 	return "image_record"
 }
+
+type ImageRecordStatistics struct {
+	Id          int     `json:"id"`
+	TaskId      int     `json:"task_id"`     //任务id
+	CreateDate  string  `json:"create_date"` //创建日期
+	Two         float64 `json:"two"`
+	Three       float64 `json:"three"`
+	Four        float64 `json:"four"`
+	Five        float64 `json:"five"`
+	Six         float64 `json:"six"`
+	Seven       float64 `json:"seven"`
+	Eight       float64 `json:"eight"`
+	Nine        float64 `json:"nine"`
+	Ten         float64 `json:"ten"`
+	Eleven      float64 `json:"eleven"`
+	Twelve      float64 `json:"twelve"`
+	Thirteen    float64 `json:"thirteen"`
+	Fourteen    float64 `json:"fourteen"`
+	Fifteen     float64 `json:"fifteen"`
+	Sixteen     float64 `json:"sixteen"`
+	Seventeen   float64 `json:"seventeen"`
+	Eighteen    float64 `json:"eighteen"`
+	Nineteen    float64 `json:"nineteen"`
+	Twenty      float64 `json:"twenty"`
+	TwentyOne   float64 `json:"twenty_one"`
+	TwentyTwo   float64 `json:"twenty_two"`
+	TwentyThree float64 `json:"twenty_three"`
+	TwentyFour  float64 `json:"twenty_four"`
+	TwentyFive  float64 `json:"twenty_five"`
+	TwentySix   float64 `json:"twenty_six"`
+	TwentySeven float64 `json:"twenty_seven"`
+	TwentyEight float64 `json:"twenty_eight"`
+	TwentyNine  float64 `json:"twenty_nine"`
+	Thirty      float64 `json:"thirty"`
+}
+
+func (ImageRecordStatistics) TableName() string {
+	return "image_record_statistics"
+}
+
+var R = map[int]string{
+	2:  "two",
+	3:  "three",
+	4:  "four",
+	5:  "five",
+	6:  "six",
+	7:  "seven",
+	8:  "eight",
+	9:  "nine",
+	10: "ten",
+	11: "eleven",
+	12: "twelve",
+	13: "thirteen",
+	14: "fourteen",
+	15: "fifteen",
+	16: "sixteen",
+	17: "seventeen",
+	18: "eighteen",
+	19: "nineteen",
+	20: "twenty",
+	21: "twenty_one",
+	22: "twenty_two",
+	23: "twenty_three",
+	24: "twenty_four",
+	25: "twenty_five",
+	26: "twenty_six",
+	27: "twenty_seven",
+	28: "twenty_eight",
+	29: "twenty_nine",
+	30: "thirty",
+}

+ 67 - 0
service/levelMonitor/image_record.go

@@ -264,3 +264,70 @@ func GetAccessToken() (string, error) {
 	}
 	return token, err
 }
+
+func (s *ImageRecordService) YesterdayStatistics() {
+	date := time.Now().Add(-time.Hour * 24).Format("2006-01-02")
+	s.ImageRecordStatistics(date)
+}
+
+func (s *ImageRecordService) TodayStatistics() {
+	date := time.Now().Format("2006-01-02")
+	s.ImageRecordStatistics(date)
+}
+
+func (s *ImageRecordService) ImageRecordStatistics(date string) {
+	type Data struct {
+		TaskId int `json:"task_id"`
+	}
+
+	var taskIds []Data
+	global.GVA_DB.Model(&levelMonitor.ImageRecord{}).Where("create_date = ?", date).Distinct("task_id").Find(&taskIds)
+	if len(taskIds) == 0 {
+		global.GVA_LOG.Warn("没有等级上报的数据")
+		return
+	}
+	type StatisticsData struct {
+		UseNum     int `json:"use_num"`
+		AccountNum int `json:"account_num"`
+		LevelNum   int `json:"level_num"`
+	}
+	for _, taskId := range taskIds {
+		var statisticsData []StatisticsData
+		global.GVA_DB.Model(&levelMonitor.ImageRecord{}).
+			Select("use_num,COUNT(*) as account_num,SUM(identify) as level_num").
+			Where("create_date = ?", date).
+			Where("task_id = ?", taskId.TaskId).
+			Where("status = ?", 1).
+			Group("use_num").
+			Order("use_num").
+			Find(&statisticsData)
+		if len(statisticsData) == 0 {
+			continue
+		}
+		var imageRecordStatistics = make(map[string]interface{})
+		b := false
+		for _, data := range statisticsData {
+			if _, ok := levelMonitor.R[data.UseNum]; ok {
+				imageRecordStatistics[levelMonitor.R[data.UseNum]] = float64(data.LevelNum) / float64(data.AccountNum)
+				b = true
+			}
+		}
+		if b {
+			s.CreateImageRecordStatistics(taskId.TaskId, imageRecordStatistics, date)
+		}
+	}
+}
+
+func (s *ImageRecordService) CreateImageRecordStatistics(taskId int, imageRecordStatistics map[string]interface{}, date string) {
+	err := global.GVA_DB.Where("create_date = ?", date).Where("task_id = ?", taskId).First(&levelMonitor.ImageRecordStatistics{}).Error
+	if errors.Is(err, gorm.ErrRecordNotFound) {
+		imageRecordStatistics["task_id"] = taskId
+		imageRecordStatistics["create_date"] = time.Now().Format("2006-01-02")
+		global.GVA_DB.Model(&levelMonitor.ImageRecordStatistics{}).Create(imageRecordStatistics)
+		return
+	}
+	global.GVA_DB.Model(&levelMonitor.ImageRecordStatistics{}).
+		Where("create_date = ?", date).
+		Where("task_id = ?", taskId).
+		Updates(imageRecordStatistics)
+}