ソースを参照

加redis读写

iks 3 日 前
コミット
c0cb060755
3 ファイル変更54 行追加0 行削除
  1. 22 0
      handler/metric_process.go
  2. 1 0
      routes/router.go
  3. 31 0
      service/metric_process_config.go

+ 22 - 0
handler/metric_process.go

@@ -2,6 +2,7 @@ package handler
 
 import (
 	"net/http"
+
 	"newaterobot-process/entity"
 
 	"github.com/gin-gonic/gin"
@@ -40,3 +41,24 @@ func MetricProcess(c *gin.Context) {
 		"data":    result,
 	})
 }
+
+func GetMete(c *gin.Context) {
+	cId := c.Query("conversation_id")
+	mId := c.Query("message_id")
+	// 调用服务处理指标
+	result, err := metricProcessConfigService.ProcessMate(cId, mId)
+	if err != nil {
+		c.JSON(http.StatusOK, gin.H{
+			"code":    500,
+			"message": "处理指标失败: " + err.Error(),
+		})
+		return
+	}
+
+	// 返回成功响应
+	c.JSON(http.StatusOK, gin.H{
+		"code":    200,
+		"message": "处理成功",
+		"data":    result,
+	})
+}

+ 1 - 0
routes/router.go

@@ -24,6 +24,7 @@ func InitRouter() *gin.Engine {
 	{
 		private.POST("/metric_process", handler.MetricProcess)
 		private.GET("/user/info", handler.GetUserInfo)
+		private.GET("/common/deepseek/get/meta", handler.GetMete)
 	}
 
 	return r

+ 31 - 0
service/metric_process_config.go

@@ -7,10 +7,12 @@ import (
 	"io"
 	"net/http"
 	"net/url"
+	"strconv"
 	"strings"
 	"text/template"
 	"time"
 
+	jsoniter "github.com/json-iterator/go"
 	"github.com/tidwall/gjson"
 	"newaterobot-process/entity"
 	"newaterobot-process/model"
@@ -69,6 +71,9 @@ func (s *MetricProcessConfigService) ProcessMetric(inputData entity.MetricProces
 		inputData.ETime = time.Now().AddDate(0, 0, 180).Format("2006-01-02")
 	} else if config.MetricType == 59 {
 		inputData.DateTime = strings.Split(inputData.DateTime, " ")[0]
+	} else if config.MetricType == 42 {
+		inputData.STime = strconv.Itoa(time.Now().Year())
+		inputData.ETime = strconv.Itoa(int(time.Now().Month()))
 	}
 	// 直接回复分支
 	templateVarMap := s.objToMap(inputData)
@@ -181,8 +186,34 @@ func (s *MetricProcessConfigService) ProcessMetric(inputData entity.MetricProces
 	}
 	ret.Flag = entity.HttpReply
 	ret.ReplyContext = replyContext
+
+	info := make(map[string]interface{})
+	info["pid"] = inputData.ID
+	info["metric_type"] = config.MetricType
+	info["datetime"] = inputData.DateTime
+	info["metric"] = replyContext
+	info["is_english"] = inputData.IsEnglish
+	info["type"] = config.Type
+	k := fmt.Sprintf("deepseek2:%s:%s", inputData.ConversationId, inputData.DialogueCount)
+	msg, _ := jsoniter.MarshalToString(info)
+	GetRedisService().SetObject(k, msg, 3600*24*7)
 	return ret, nil
 }
+
+func (s *MetricProcessConfigService) ProcessMate(cid string, mid string) (map[string]interface{}, error) {
+	k := fmt.Sprintf("deepseek2:%s:%s", cid, mid)
+	row, err := GetRedisService().GetString(k)
+	if err != nil {
+		return nil, err
+	}
+	info := make(map[string]interface{})
+	err = json.Unmarshal([]byte(row), &info)
+	if err != nil {
+		return nil, err
+	}
+	return info, nil
+}
+
 func (s *MetricProcessConfigService) objToMap(req entity.MetricProcessRequest) map[string]interface{} {
 	ret := make(map[string]interface{})
 	ret["name"] = req.Name