|
|
@@ -9,15 +9,14 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
-import java.net.URI;
|
|
|
-import java.net.http.HttpClient;
|
|
|
-import java.net.http.HttpRequest;
|
|
|
-import java.net.http.HttpResponse;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.MessageDigest;
|
|
|
import java.util.*;
|
|
|
@@ -40,11 +39,13 @@ public class ReportParserDispatchService {
|
|
|
@Resource
|
|
|
private ReportUnknownUploadMapper unknownUploadMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
@Value("${cfc.langgraph.url:http://localhost:9000}")
|
|
|
private String langgraphUrl;
|
|
|
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- private final HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
|
|
|
private static final int AUTO_LEARN_THRESHOLD = 3;
|
|
|
|
|
|
@@ -101,22 +102,16 @@ public class ReportParserDispatchService {
|
|
|
body.put("family_id", null);
|
|
|
body.put("user_id", null);
|
|
|
|
|
|
- String json = objectMapper.writeValueAsString(body);
|
|
|
-
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(url))
|
|
|
- .header("Content-Type", "application/json")
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(json, StandardCharsets.UTF_8))
|
|
|
- .timeout(java.time.Duration.ofSeconds(120))
|
|
|
- .build();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ HttpEntity<String> entity = new HttpEntity<>(objectMapper.writeValueAsString(body), headers);
|
|
|
|
|
|
- HttpResponse<String> response = httpClient.send(request,
|
|
|
- HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
|
|
|
+ ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
|
|
|
|
|
|
- if (response.statusCode() == 200) {
|
|
|
- return response.body();
|
|
|
+ if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
+ return response.getBody();
|
|
|
}
|
|
|
- throw new RuntimeException("LLM 返回状态码: " + response.statusCode());
|
|
|
+ throw new RuntimeException("LLM 返回状态码: " + response.getStatusCode());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -209,4 +204,4 @@ public class ReportParserDispatchService {
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|