由于前端响应超时,历史对话用数据库数据
This commit is contained in:
@@ -16,6 +16,7 @@ import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Flux;
|
||||
import java.util.ArrayList;
|
||||
@@ -64,44 +65,35 @@ public class RagFlowApiUtil {
|
||||
//聊天助手下对话列表
|
||||
public List<Map<String,Object>> getChats(Map<String,Object> params) throws Exception{
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
String id = params.get("chatId").toString();
|
||||
List<String> chatIds = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(id)){
|
||||
List<Map<String,Object>> assistants = getChatAssistants("");
|
||||
for (Map<String, Object> map:assistants) {
|
||||
chatIds.add(map.get("id").toString());
|
||||
}
|
||||
}else {
|
||||
chatIds.add(id);
|
||||
}
|
||||
String chatId = params.get("chatId").toString();
|
||||
List<Map<String,Object>> list = new ArrayList();
|
||||
for (String chatId : chatIds){
|
||||
String page = params.get("page").toString();
|
||||
String pageSize = params.get("pageSize").toString();
|
||||
String sessionId = params.get("sessionId").toString();
|
||||
HttpGet get = new HttpGet(url+"/api/v1/chats/"+chatId+"/sessions?" +
|
||||
"page="+page+"&page_size="+pageSize+"&id="+sessionId+"&user_id="+ShiroUtils.getUId());
|
||||
get.setHeader("Authorization", authorization);
|
||||
get.setHeader("Content-Type", "application/json;chartset=utf-8");
|
||||
CloseableHttpResponse response = httpClient.execute(get);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode >= 400) {
|
||||
throw new RuntimeException("API调用失败,状态码:" + statusCode);
|
||||
}
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
String responseString = EntityUtils.toString(responseEntity, Consts.UTF_8);
|
||||
JSONObject jsonObject = JSONObject.parseObject(responseString);
|
||||
if ("0".equals(jsonObject.get("code").toString())){
|
||||
List l = jsonObject.getJSONArray("data");
|
||||
for (Object o : l) {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
Map<String,Object> m = (Map<String,Object>)o;
|
||||
map.put("id",m.get("id"));
|
||||
map.put("name",m.get("name"));
|
||||
map.put("messages",m.get("messages"));
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
String page = params.get("page").toString();
|
||||
String pageSize = params.get("pageSize").toString();
|
||||
String sessionId = params.get("sessionId").toString();
|
||||
HttpGet get = new HttpGet(url+"/api/v1/chats/"+chatId+"/sessions?" +
|
||||
"page="+page+"&page_size="+pageSize+"&id="+sessionId+"&user_id="+ShiroUtils.getUId());
|
||||
get.setHeader("Authorization", authorization);
|
||||
get.setHeader("Content-Type", "application/json;chartset=utf-8");
|
||||
CloseableHttpResponse response = httpClient.execute(get);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode >= 400) {
|
||||
throw new RuntimeException("API调用失败,状态码:" + statusCode);
|
||||
}
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
String responseString = EntityUtils.toString(responseEntity, Consts.UTF_8);
|
||||
JSONObject jsonObject = JSONObject.parseObject(responseString);
|
||||
if ("0".equals(jsonObject.get("code").toString())){
|
||||
List l = jsonObject.getJSONArray("data");
|
||||
list.addAll(l);
|
||||
// for (Object o : l) {
|
||||
// Map<String,Object> map = new HashMap<>();
|
||||
// Map<String,Object> m = (Map<String,Object>)o;
|
||||
// map.put("chatId",chatId);
|
||||
// map.put("id",m.get("id"));
|
||||
// map.put("name",m.get("name"));
|
||||
// map.put("messages",m.get("messages"));
|
||||
// list.add(map);
|
||||
// }
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -202,6 +194,7 @@ public class RagFlowApiUtil {
|
||||
});
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user