Bläddra i källkod

Merge branch 'master' of http://10.8.230.114:3000/wangbin/log-server

maker 2 år sedan
förälder
incheckning
0ad3b38bbf
2 ändrade filer med 16 tillägg och 13 borttagningar
  1. 1 1
      model/log/device_log.go
  2. 15 12
      service/levelMonitor/image_record.go

+ 1 - 1
model/log/device_log.go

@@ -89,7 +89,7 @@ type GameAccount struct {
 	AccountHex         string    `json:"account_hex"`
 	CreateTime         time.Time `json:"create_time"` // 创建时间
 	UseNum             int       `json:"use_num"`     //账号登录成功次数
-	Identify           int       `json:"identify"`    //图片识别的内容
+	Identify           float64   `json:"identify"`    //图片识别的内容
 	UpdateTime         time.Time `json:"update_time"`
 }
 

+ 15 - 12
service/levelMonitor/image_record.go

@@ -16,6 +16,7 @@ import (
 	"log-server/service/cache"
 	"net/http"
 	"net/url"
+	"regexp"
 	"strconv"
 	"strings"
 	"time"
@@ -166,23 +167,25 @@ func (s *ImageRecordService) ImageIdentify(record levelMonitor.ImageRecord, key
 		return
 	}
 
-	identify := 0
+	identify := 0.00
 	if data.WordsResultNum == 0 {
 		s.UpdateImageRecordStatus(record.Id, string(body), -1, 0, 0)
 		return
 	}
-	if len(data.WordsResult) > 1 {
-		for _, words := range data.WordsResult {
-			i, err := strconv.Atoi(words.Words)
-			if err == nil {
-				identify = i
-				break
-			}
-		}
+	i, err := strconv.ParseFloat(data.WordsResult[0].Words, 64)
+	if err != nil {
+		// 定义价格提取的正则表达式模式
+		identifyPattern := `([0-9]+(?:\.[0-9]{1,2})?)`
+		// 编译正则表达式
+		re := regexp.MustCompile(identifyPattern)
+		// 使用正则表达式查找价格信息
+		level := re.FindAllString(data.WordsResult[0].Words, -1)
+		l, _ := strconv.ParseFloat(level[0], 64)
+		identify = l
 	} else {
-		i, _ := strconv.Atoi(data.WordsResult[0].Words)
 		identify = i
 	}
+
 	if identify == 0 {
 		s.UpdateImageRecordStatus(record.Id, string(body), -1, 0, 0)
 		return
@@ -196,7 +199,7 @@ func (s *ImageRecordService) ImageIdentify(record levelMonitor.ImageRecord, key
 	return
 }
 
-func (s *ImageRecordService) UpdateImageRecordStatus(id int, result string, status int, useNum, identify int) {
+func (s *ImageRecordService) UpdateImageRecordStatus(id int, result string, status int, useNum int, identify float64) {
 	update := map[string]interface{}{
 		"result":   result,
 		"status":   status,
@@ -241,7 +244,7 @@ func Request(baiduToken, content string) (body []byte, err error) {
 }
 
 // 更新game_acount
-func UpdateGameAccountIdentify(account string, gameId int, identify int) {
+func UpdateGameAccountIdentify(account string, gameId int, identify float64) {
 	global.GVA_DB.Table("game_account").Where("game_id", gameId).Where("account", account).Update("identify", identify)
 }