zwxi 8 kuukautta sitten
vanhempi
commit
f6c56957d0
1 muutettua tiedostoa jossa 52 lisäystä ja 28 poistoa
  1. 52 28
      controllers/ai/ai_summary.go

+ 52 - 28
controllers/ai/ai_summary.go

@@ -1066,6 +1066,9 @@ func (this *AiController) GenerateAiSummary() {
 		//	"周度数据显示,成品油现货市场价格跟随原油下跌,但近期相对抗跌,裂解价差走扩。批零价差方面汽油收窄,柴油走扩",
 		//	"出口利润在原油下跌海外成品油矛盾更大的情况下汽柴油出口窗口完全关闭",
 		//	"汽油需求在经历五一假期的一段高峰后将回归平稳,总体没有明显矛盾,后期我们担心更多的还是柴油。"}
+		//获取主题下的所有信息
+		//AiChatTopicId
+
 		//获取主题下的所有信息
 		//AiChatTopicId
 		historyList, err := aimod.GetAiChatList(req.AiChatTopicId)
@@ -1074,6 +1077,7 @@ func (this *AiController) GenerateAiSummary() {
 			br.ErrMsg = "获取主题历史数据失败,Err:" + err.Error()
 			return
 		}
+
 		historyChatList := make([]aimod.HistoryChat, 0)
 		for _, v := range historyList {
 			historyChat := new(aimod.HistoryChat)
@@ -1093,34 +1097,54 @@ func (this *AiController) GenerateAiSummary() {
 		resp.Answer = answer
 		resp.Model = req.Model
 
-		topic := new(aimod.AiChatTopic)
-		topic.TopicName = ask
-		topic.SysUserId = this.SysUser.AdminId
-		topic.SysUserRealName = this.SysUser.RealName
-		topic.CreateTime = time.Now()
-		topic.ModifyTime = time.Now()
-		topicId, err := aimod.AddAiChatTopic(topic)
-		if err != nil {
-			br.Msg = "获取数据失败!"
-			br.ErrMsg = "生成话题失败,Err:" + err.Error()
-			return
-		}
-		resp.AiChatTopicId = int(topicId)
-		chatItem := new(aimod.AiChat)
-		chatItem.AiChatTopicId = resp.AiChatTopicId
-		chatItem.Ask = ask
-		chatItem.AskUuid = utils.MD5(ask)
-		chatItem.Answer = answer
-		chatItem.Model = EnabledModelsForMap[req.Model]
-		chatItem.SysUserId = this.SysUser.AdminId
-		chatItem.SysUserRealName = this.SysUser.RealName
-		chatItem.CreateTime = time.Now()
-		chatItem.ModifyTime = time.Now()
-		_, err = aimod.AddAiChat(chatItem)
-		if err != nil {
-			br.Msg = "获取数据失败!"
-			br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
-			return
+		if req.AiChatTopicId <= 0 { //新增
+			topic := new(aimod.AiChatTopic)
+			topic.TopicName = ask
+			topic.SysUserId = this.SysUser.AdminId
+			topic.SysUserRealName = this.SysUser.RealName
+			topic.CreateTime = time.Now()
+			topic.ModifyTime = time.Now()
+			topicId, err := aimod.AddAiChatTopic(topic)
+			if err != nil {
+				br.Msg = "获取数据失败!"
+				br.ErrMsg = "生成话题失败,Err:" + err.Error()
+				return
+			}
+			resp.AiChatTopicId = int(topicId)
+			chatItem := new(aimod.AiChat)
+			chatItem.AiChatTopicId = resp.AiChatTopicId
+			chatItem.Ask = ask
+			chatItem.AskUuid = utils.MD5(ask)
+			chatItem.Answer = answer
+			chatItem.Model = EnabledModelsForMap[req.Model]
+			chatItem.SysUserId = this.SysUser.AdminId
+			chatItem.SysUserRealName = this.SysUser.RealName
+			chatItem.CreateTime = time.Now()
+			chatItem.ModifyTime = time.Now()
+			_, err = aimod.AddAiChat(chatItem)
+			if err != nil {
+				br.Msg = "获取数据失败!"
+				br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
+				return
+			}
+		} else {
+			resp.AiChatTopicId = req.AiChatTopicId
+			chatItem := new(aimod.AiChat)
+			chatItem.AiChatTopicId = resp.AiChatTopicId
+			chatItem.Ask = ask
+			chatItem.AskUuid = utils.MD5(ask)
+			chatItem.Answer = answer
+			chatItem.Model = EnabledModelsForMap[req.Model]
+			chatItem.SysUserId = this.SysUser.AdminId
+			chatItem.SysUserRealName = this.SysUser.RealName
+			chatItem.CreateTime = time.Now()
+			chatItem.ModifyTime = time.Now()
+			_, err = aimod.AddAiChat(chatItem)
+			if err != nil {
+				br.Msg = "获取数据失败!"
+				br.ErrMsg = "生成话题记录失败,Err:" + err.Error()
+				return
+			}
 		}
 
 	} else if len(req.OpenaiFileId) > 0 {