AiUserAgentQuestionThread.java
3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.xly.thread;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xly.config.OperableChatMemoryProvider;
import com.xly.config.SpringContextHolder;
import com.xly.entity.UserSceneSession;
import com.xly.service.DynamicExeDbService;
import dev.langchain4j.data.message.ChatMessage;
import dev.langchain4j.data.message.ChatMessageType;
import jnr.ffi.annotations.In;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AiUserAgentQuestionThread implements Runnable {
private UserSceneSession session;
private String sSqlContent;
private String sQuestion;
List<ChatMessage> userMessage;
public final String sProName="Sp_Ai_AiUserAgentQuestionThread";
public AiUserAgentQuestionThread(UserSceneSession session,String sQuestion,String sSqlContent, List<ChatMessage> userMessage ) {
this.session = session;
this.sSqlContent = sSqlContent;
this.sQuestion = sQuestion;
this.userMessage = userMessage;
}
@Override
public void run() {
sQuestion = sQuestion.replace("用户输入:",StrUtil.EMPTY);
String sSceneId = session.getCurrentScene().getSId();
String sMethodId = session.getCurrentTool().getSId();
DynamicExeDbService dynamicExeDbService = SpringContextHolder.getBean(DynamicExeDbService.class);
String sQuestionGroupNo = session.getSUserQuestionList().get(0);
Integer bRedis = (session.getSUserQuestionList().size()==1)?1:0;
Map<String, Object> data = getMap(sSceneId, sMethodId,bRedis,sQuestionGroupNo);
data.put("sQuestion",getsQuestion(session.getSUserQuestionList()));
Map<String, Object> searMap = dynamicExeDbService.getDoProMap(sProName, data);
dynamicExeDbService.getCallPro(searMap, sProName);
}
private String getsQuestion(List<String> sUserQuestionList){
return String.join(",", sUserQuestionList);
}
//获取组ID
private String getQuestionGroupNo(){
String sQuestionGroupNo = userMessage.stream()
.filter(one -> one.type().equals(ChatMessageType.USER) && !"用户输入:initAiService".equals(one.text()))
.findFirst()
.map(one->one.text())
.orElse(StrUtil.EMPTY);
sQuestionGroupNo = sQuestionGroupNo.replace("用户输入:",StrUtil.EMPTY);
sQuestionGroupNo = sQuestionGroupNo.replace(" ",StrUtil.EMPTY);
sQuestionGroupNo = sQuestionGroupNo.replace("\\t",StrUtil.EMPTY);
sQuestionGroupNo = sQuestionGroupNo.replace("\\n",StrUtil.EMPTY);
sQuestionGroupNo = sQuestionGroupNo.toLowerCase();
return sQuestionGroupNo;
}
/***
* @Author 钱豹
* @Date 4:22 2026/3/15
* @Param [sSceneId, sMethodId]
* @return java.util.Map<java.lang.String,java.lang.Object>
* @Description 获取执行的动态Map
**/
private Map<String, Object> getMap(String sSceneId, String sMethodId,Integer bRedis,String sQuestionGroupNo) {
Map<String,Object> data = new HashMap<>(16);
data.put("sSceneId", sSceneId);
data.put("sMethodId", sMethodId);
data.put("sSqlContent",sSqlContent);
data.put("sBrId",session.getSBrandsId());
data.put("sBrandsId",session.getSBrandsId());
data.put("sSuId",session.getSSubsidiaryId());
data.put("sSubsidiaryId",session.getSSubsidiaryId());
data.put("sLoginId",session.getUserName());
data.put("sUserName",session.getUserName());
data.put("sUserId",session.getUserId());
data.put("bRedis",bRedis);
data.put("sQuestionGroupNo",sQuestionGroupNo);
return data;
}
}