|
|
@@ -12,6 +12,7 @@ import (
|
|
|
"log-server/model/common/request"
|
|
|
"log-server/model/levelMonitor"
|
|
|
levelRequest "log-server/model/levelMonitor/request"
|
|
|
+ "log-server/model/log"
|
|
|
"log-server/service/cache"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
@@ -47,8 +48,7 @@ func (s *ImageRecordService) CreateImageRecord(record levelMonitor.ImageRecord)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- s.cache.SetCacheNum(ctx, key)
|
|
|
- go s.ImageIdentify(record)
|
|
|
+ go s.ImageIdentify(record, key)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -66,7 +66,7 @@ func (s *ImageRecordService) UploadOrNot(record levelMonitor.ImageRecord) (err e
|
|
|
//删除三日前的图片记录
|
|
|
func (s *ImageRecordService) DeleteExpireImageRecord() {
|
|
|
markTime := time.Now().Add(-time.Hour * 48).Format("2006-01-02")
|
|
|
- err := global.GVA_DB.Model(&levelMonitor.ImageRecord{}).Delete("create_date < ?", markTime).Error
|
|
|
+ err := global.GVA_DB.Where("create_date < ?", markTime).Delete(&levelMonitor.ImageRecord{}).Error
|
|
|
if err != nil {
|
|
|
global.GVA_LOG.Info("删除图片信息失败:" + err.Error() + time.Now().Format("2006-01-02 15:04:05"))
|
|
|
}
|
|
|
@@ -129,17 +129,17 @@ const API_KEY = "z9GNcyrC7VeV3g1xXEj3YL1s"
|
|
|
const SECRET_KEY = "VASRBsEzeVsyKduSkkflfL87r5yqoqvj"
|
|
|
const BAIDU_IDENTIFY = "baiduIdentifyToken"
|
|
|
|
|
|
-func (s *ImageRecordService) ImageIdentify(record levelMonitor.ImageRecord) {
|
|
|
+func (s *ImageRecordService) ImageIdentify(record levelMonitor.ImageRecord, key string) {
|
|
|
token, err := GetAccessToken()
|
|
|
if err != nil {
|
|
|
global.GVA_LOG.Error("get token fail", zap.Error(err))
|
|
|
- s.UpdateImageRecordStatus(record.Id, "get token fail", -1)
|
|
|
+ s.UpdateImageRecordStatus(record.Id, "get token fail", -1, 0, 0)
|
|
|
return
|
|
|
}
|
|
|
body, err := Request(token, record.ImageBase64)
|
|
|
if err != nil {
|
|
|
global.GVA_LOG.Error("Read Body Fail", zap.Error(err))
|
|
|
- s.UpdateImageRecordStatus(record.Id, err.Error(), -1)
|
|
|
+ s.UpdateImageRecordStatus(record.Id, err.Error(), -1, 0, 0)
|
|
|
return
|
|
|
}
|
|
|
type Data struct {
|
|
|
@@ -153,11 +153,15 @@ func (s *ImageRecordService) ImageIdentify(record levelMonitor.ImageRecord) {
|
|
|
err = json.Unmarshal(body, &data)
|
|
|
if err != nil {
|
|
|
global.GVA_LOG.Error("Read Body Fail", zap.Error(err))
|
|
|
- s.UpdateImageRecordStatus(record.Id, "Read Body Fail", -1)
|
|
|
+ s.UpdateImageRecordStatus(record.Id, "Read Body Fail", -1, 0, 0)
|
|
|
return
|
|
|
}
|
|
|
- s.UpdateImageRecordStatus(record.Id, string(body), 1)
|
|
|
+
|
|
|
identify := 0
|
|
|
+ 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)
|
|
|
@@ -171,16 +175,24 @@ func (s *ImageRecordService) ImageIdentify(record levelMonitor.ImageRecord) {
|
|
|
identify = i
|
|
|
}
|
|
|
if identify == 0 {
|
|
|
+ s.UpdateImageRecordStatus(record.Id, string(body), -1, 0, 0)
|
|
|
return
|
|
|
}
|
|
|
+ var gameAccount log.GameAccount
|
|
|
+ global.GVA_DB.Where("game_id", record.TaskId).Where("account", record.Account).First(&gameAccount)
|
|
|
+ s.UpdateImageRecordStatus(record.Id, string(body), 1, gameAccount.UseNum, identify)
|
|
|
UpdateGameAccountIdentify(record.Account, record.TaskId, identify)
|
|
|
+ ctx := context.Background()
|
|
|
+ s.cache.SetCacheNum(ctx, key)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (s *ImageRecordService) UpdateImageRecordStatus(id int, result string, status int) {
|
|
|
+func (s *ImageRecordService) UpdateImageRecordStatus(id int, result string, status int, useNum, identify int) {
|
|
|
update := map[string]interface{}{
|
|
|
- "result": result,
|
|
|
- "status": status,
|
|
|
+ "result": result,
|
|
|
+ "status": status,
|
|
|
+ "use_num": useNum,
|
|
|
+ "identify": identify,
|
|
|
}
|
|
|
global.GVA_DB.Model(&levelMonitor.ImageRecord{}).Where("id", id).Updates(update)
|
|
|
}
|