refactor: VMIS 모드 분기 로직 간소화 및 서비스 계층 위임

- 내부/외부 모드 분기 로직 제거, VehicleInfoService로 위임
- 컨트롤러 메서드 간결화 및 모드 의존성 제거
- Swagger API 설명 및 예제 수정
- application-local.yml 기본 모드 external로 변경
internalApi
박성영 1 month ago
parent 4ca218151e
commit a1687070fd

@ -5,9 +5,6 @@ import go.kr.project.api.model.response.BasicResponse;
import go.kr.project.api.model.Envelope;
import go.kr.project.api.model.request.LedgerRequest;
import go.kr.project.api.model.response.LedgerResponse;
import go.kr.project.api.internal.service.VmisCarBassMatterInqireService;
import go.kr.project.api.internal.service.VmisCarLedgerFrmbkService;
import go.kr.project.api.config.properties.VmisProperties;
import go.kr.project.api.model.VehicleApiResponseVO;
import go.kr.project.api.service.VehicleInfoService;
import io.swagger.v3.oas.annotations.Operation;
@ -27,6 +24,7 @@ import java.util.Collections;
* REST (Swagger )
*
* <p>(vmis.integration.mode) Internal/External .</p>
* <p>: VehicleInfoService , .</p>
*
* <h3> :</h3>
* <ul>
@ -50,15 +48,7 @@ import java.util.Collections;
@Tag(name = "VMIS 차량정보 (Swagger)", description = "vmis.integration.mode에 따라 내부/외부 분기 호출")
public class VehicleInterfaceController {
private final VmisCarBassMatterInqireService carBassMatterInqireService; // Internal 전용 서비스
private final VmisCarLedgerFrmbkService carLedgerFrmbkService; // Internal 전용 서비스
private final VehicleInfoService vehicleInfoService; // 모드별 구현체 주입 (통합 조회)
private final VmisProperties vmisProperties; // 모드 확인용
// 내부 유틸: 현재 External 모드 여부
private boolean isExternalMode() {
return "external".equalsIgnoreCase(vmisProperties.getIntegration().getMode());
}
private final VehicleInfoService vehicleInfoService; // 모드별 구현체 자동 주입
/**
* + ()
@ -97,19 +87,18 @@ public class VehicleInterfaceController {
/**
*
* - Internal: API
* - External: VehicleInfoService BasicResponse Envelope
* - : VehicleInfoService
*/
@PostMapping(value = "/basic.ajax", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "자동차기본사항조회 (단독)",
description = "Internal 모드는 정부 API 형식 그대로, External 모드는 외부 REST 결과에서 기본정보만 반환",
description = "vmis.integration.mode에 따라 내부 모듈 또는 외부 REST API를 통해 기본정보만 조회",
requestBody = @RequestBody(
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
examples = @ExampleObject(
name = "기본사항조회 예제",
value = "{\"data\": [{\"INFO_SYS_ID\": \"41-345\", \"VHRNO\": \"12가3456\"}]}"
value = "{\"data\": [{\"VHRNO\": \"12가3456\"}]}"
)
)
)
@ -117,16 +106,13 @@ public class VehicleInterfaceController {
public ResponseEntity<Envelope<BasicResponse>> basic(
@org.springframework.web.bind.annotation.RequestBody Envelope<BasicRequest> envelope
) {
if (!isExternalMode()) {
// Internal 모드: 정부 API 형식 그대로 위임
return carBassMatterInqireService.basic(envelope);
}
// External 모드: 통합 서비스에서 기본정보만 추출하여 Envelope 형태로 반환
// 중요 로직: Swagger 요청 Envelope에서 차량번호 추출
String vhrno = (envelope != null && !envelope.getData().isEmpty()) ? envelope.getData().get(0).getVhrno() : null;
if (vhrno == null || vhrno.trim().isEmpty()) {
return ResponseEntity.ok(new Envelope<>(Collections.emptyList()));
}
// 외부 모드: 서비스 계층의 단독 메서드를 직접 호출하여 반환 (주먹구구식 분리 제거)
// VehicleInfoService는 모드에 따라 구현체가 자동 주입되어 분기 처리
BasicResponse basic = vehicleInfoService.getBasicInfo(vhrno);
Envelope<BasicResponse> out = (basic != null) ? new Envelope<>(basic) : new Envelope<>(Collections.emptyList());
return ResponseEntity.ok(out);
@ -134,19 +120,18 @@ public class VehicleInterfaceController {
/**
* ()
* - Internal: API
* - External: VehicleInfoService LedgerResponse Envelope
* - : VehicleInfoService
*/
@PostMapping(value = "/ledger.ajax", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "자동차등록원부(갑) 조회 (단독)",
description = "Internal 모드는 정부 API 형식 그대로, External 모드는 외부 REST 결과에서 등록원부만 반환",
description = "vmis.integration.mode에 따라 내부 모듈 또는 외부 REST API를 통해 등록원부만 조회",
requestBody = @RequestBody(
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
examples = @ExampleObject(
name = "등록원부 조회 예제",
value = "{\"data\": [{\"INFO_SYS_ID\": \"41-345\", \"VHRNO\": \"12가3456\"}]}"
value = "{\"data\": [{\"VHRNO\": \"12가3456\"}]}"
)
)
)
@ -154,16 +139,13 @@ public class VehicleInterfaceController {
public ResponseEntity<Envelope<LedgerResponse>> ledger(
@org.springframework.web.bind.annotation.RequestBody Envelope<LedgerRequest> envelope
) {
if (!isExternalMode()) {
// Internal 모드: 정부 API 형식 그대로 위임
return carLedgerFrmbkService.ledger(envelope);
}
// External 모드: 통합 서비스에서 등록원부만 추출하여 Envelope 형태로 반환
// 중요 로직: Swagger 요청 Envelope에서 차량번호 추출
String vhrno = (envelope != null && !envelope.getData().isEmpty()) ? envelope.getData().get(0).getVhrno() : null;
if (vhrno == null || vhrno.trim().isEmpty()) {
return ResponseEntity.ok(new Envelope<>(Collections.emptyList()));
}
// 외부 모드: 서비스 계층의 단독 메서드를 직접 호출하여 반환 (주먹구구식 분리 제거)
// VehicleInfoService는 모드에 따라 구현체가 자동 주입되어 분기 처리
LedgerResponse ledger = vehicleInfoService.getLedgerInfo(vhrno);
Envelope<LedgerResponse> out = (ledger != null) ? new Envelope<>(ledger) : new Envelope<>(Collections.emptyList());
return ResponseEntity.ok(out);

@ -163,7 +163,7 @@ juso:
# ===== VMIS 통합 설정 (Local 환경) =====
vmis:
integration:
mode: internal # internal: 내부 VMIS 모듈 직접 호출, external: 외부 REST API 호출
mode: external # internal: 내부 VMIS 모듈 직접 호출, external: 외부 REST API 호출
# RestTemplate 설정 (모드별 분기)
rest-template:

Loading…
Cancel
Save