Merge pull request 'RestTemplateConfig 수정, 추론실행 수정' (#19) from feat/infer_dev_260107 into develop
Reviewed-on: #19
This commit was merged in pull request #19.
This commit is contained in:
@@ -5,11 +5,9 @@ import java.net.InetAddress;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
public class NetUtils {
|
||||
|
||||
@@ -56,9 +54,8 @@ public class NetUtils {
|
||||
|
||||
public HttpHeaders jsonHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
|
||||
headers.set(HttpHeaders.ACCEPT, "application/json;charset=UTF-8");
|
||||
headers.set(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.kamco.cd.kamcoback.config.resttemplate;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.BufferingClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Log4j2
|
||||
@@ -18,8 +20,12 @@ public class RestTemplateConfig {
|
||||
baseFactory.setConnectTimeout(2000);
|
||||
baseFactory.setReadTimeout(3000);
|
||||
|
||||
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
|
||||
jsonConverter.setDefaultCharset(StandardCharsets.UTF_8);
|
||||
|
||||
return builder
|
||||
.requestFactory(() -> new BufferingClientHttpRequestFactory(baseFactory))
|
||||
.messageConverters(jsonConverter)
|
||||
.additionalInterceptors(new RetryInterceptor())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.kamco.cd.kamcoback.config.resttemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
|
||||
@Log4j2
|
||||
public class RetryInterceptor implements ClientHttpRequestInterceptor {
|
||||
|
||||
private static final int MAX_RETRY = 3;
|
||||
@@ -20,21 +23,25 @@ public class RetryInterceptor implements ClientHttpRequestInterceptor {
|
||||
|
||||
for (int attempt = 1; attempt <= MAX_RETRY; attempt++) {
|
||||
try {
|
||||
// HTTP 응답을 받으면(2xx/4xx/5xx 포함) 그대로 반환
|
||||
return execution.execute(request, body);
|
||||
log.info("[WIRE-REQ] {} {}", request.getMethod(), request.getURI());
|
||||
log.info("[WIRE-REQ-HEADERS] {}", request.getHeaders());
|
||||
log.info("[WIRE-REQ-BODY] {}", new String(body, StandardCharsets.UTF_8));
|
||||
|
||||
ClientHttpResponse response = execution.execute(request, body);
|
||||
|
||||
log.info("[WIRE-RES-STATUS] {}", response.getStatusCode());
|
||||
return response;
|
||||
|
||||
} catch (IOException e) {
|
||||
// 네트워크/타임아웃 등 I/O 예외만 재시도
|
||||
lastException = e;
|
||||
log.error("[WIRE-IO-ERR] attempt={} msg={}", attempt, e.getMessage(), e);
|
||||
}
|
||||
|
||||
// 마지막 시도가 아니면 대기
|
||||
if (attempt < MAX_RETRY) {
|
||||
sleep();
|
||||
}
|
||||
}
|
||||
|
||||
// 마지막 예외를 그대로 던져서 원인이 로그에 남게 함
|
||||
throw lastException;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,12 @@ import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@@ -81,23 +83,28 @@ public class InferenceResultCoreService {
|
||||
* @param req
|
||||
*/
|
||||
public UUID saveInferenceInfo(InferenceResultDto.RegReq req, List<MngListDto> targetList) {
|
||||
String firstMapSheetName = null;
|
||||
String mapSheetName = "";
|
||||
int detectingCnt = 0;
|
||||
List<MngListDto> distinctList =
|
||||
targetList.stream()
|
||||
.filter(dto -> dto.getMapSheetName() != null && !dto.getMapSheetName().isBlank())
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
MngListDto::getMapSheetName,
|
||||
dto -> dto,
|
||||
(existing, duplicate) -> existing,
|
||||
LinkedHashMap::new))
|
||||
.values()
|
||||
.stream()
|
||||
.toList();
|
||||
|
||||
for (MngListDto dto : targetList) {
|
||||
if (detectingCnt == 0) {
|
||||
firstMapSheetName = dto.getMapSheetName();
|
||||
}
|
||||
detectingCnt++;
|
||||
}
|
||||
int detectingCnt = distinctList.size();
|
||||
|
||||
String mapSheetName;
|
||||
if (detectingCnt == 0) {
|
||||
mapSheetName = "";
|
||||
} else if (detectingCnt == 1) {
|
||||
mapSheetName = firstMapSheetName + " 1건";
|
||||
mapSheetName = distinctList.get(0).getMapSheetName() + " 1건";
|
||||
} else {
|
||||
mapSheetName = firstMapSheetName + " 외 " + (detectingCnt - 1) + "건";
|
||||
mapSheetName = distinctList.get(0).getMapSheetName() + " 외 " + (detectingCnt - 1) + "건";
|
||||
}
|
||||
|
||||
MapSheetLearnEntity mapSheetLearnEntity = new MapSheetLearnEntity();
|
||||
|
||||
Reference in New Issue
Block a user