You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
VIPS/src/main/java/go/kr/project/api/controller/VehicleInterfaceController....

154 lines
8.1 KiB
Java

package go.kr.project.api.controller;
import go.kr.project.api.model.request.BasicRequest;
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.model.VehicleApiResponseVO;
import go.kr.project.api.service.VehicleInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
/**
* 자동차 정보 연계 REST 컨트롤러 (Swagger 문서화 및 테스트용)
*
* <p>설정(vmis.integration.mode)에 따라 Internal/External 모드로 분기하여 호출합니다.</p>
* <p>중요: 모드별 분기는 VehicleInfoService 구현체가 자동으로 처리하므로, 컨트롤러는 단순히 서비스에 위임합니다.</p>
*
* <h3>모드별 자동 분기:</h3>
* <ul>
* <li><strong>Internal Mode:</strong> 내부 VMIS 모듈 직접 호출 (정부 API 형식 유지)</li>
* <li><strong>External Mode:</strong> 외부 VMIS-interface REST API 호출</li>
* </ul>
*
* <h3>API 경로:</h3>
* <ul>
* <li>POST /api/v1/vehicles/info.ajax - 자동차 기본정보+등록원부 통합 조회</li>
* <li>POST /api/v1/vehicles/basic.ajax - 자동차 기본사항만 조회</li>
* <li>POST /api/v1/vehicles/ledger.ajax - 자동차 등록원부(갑)만 조회</li>
* </ul>
*
* 중요: 이 컨트롤러는 Swagger 문서/테스트용으로 제공됩니다.
*/
@RestController
@RequestMapping("/api/v1/vehicles")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "VMIS 차량정보 (Swagger)", description = "vmis.integration.mode에 따라 내부/외부 분기 호출")
public class VehicleInterfaceController {
private final VehicleInfoService vehicleInfoService; // 모드별 구현체 자동 주입
/**
* 자동차 기본정보 + 등록원부(갑) 통합 조회
* - Internal/External 공통 진입점 (VehicleInfoService 사용)
* - 요청은 Envelope<BasicRequest> 형식으로 VHRNO(차량번호) 및 추가 파라미터 포함
*/
@PostMapping(value = "/info.ajax", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "자동차 통합 조회 (기본+등록원부)",
description = "vmis.integration.mode 값에 따라 내부 모듈 또는 외부 REST API를 통해 통합 조회 수행",
requestBody = @RequestBody(
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
examples = @ExampleObject(
name = "통합 조회 예제",
value = "{\"data\": [{\"VHRNO\": \"12가3456\",\"LEVY_STDDE\": \"20250101\"}]}"
)
)
)
)
public ResponseEntity<Envelope<VehicleApiResponseVO>> info(
@org.springframework.web.bind.annotation.RequestBody Envelope<BasicRequest> envelope
) {
// 중요 로직: Swagger 요청 Envelope에서 BasicRequest 추출 (차량번호 및 필수 파라미터 포함)
BasicRequest request = (envelope != null && !envelope.getData().isEmpty()) ? envelope.getData().get(0) : null;
if (request == null || request.getVhrno() == null || request.getVhrno().trim().isEmpty()) {
// 간단한 검증 실패 시 빈 데이터로 반환
return ResponseEntity.ok(new Envelope<>(Collections.emptyList()));
}
// VehicleInfoService는 모드에 따라 구현체가 자동 주입됨
VehicleApiResponseVO resp = vehicleInfoService.getVehicleInfo(request);
Envelope<VehicleApiResponseVO> out = new Envelope<>(resp);
return ResponseEntity.ok(out);
}
/**
* 자동차 기본사항만 조회
* - 중요 로직: VehicleInfoService에 완전히 위임하여 모드별 분기는 서비스 구현체가 자동 처리
*/
@PostMapping(value = "/basic.ajax", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "자동차기본사항조회 (단독)",
description = "vmis.integration.mode에 따라 내부 모듈 또는 외부 REST API를 통해 기본정보만 조회",
requestBody = @RequestBody(
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
examples = @ExampleObject(
name = "기본사항조회 예제 (자동차번호)",
value = "{\"data\": [{\"VHRNO\": \"12가3456\",\"LEVY_STDDE\": \"20250101\"}]}"
)
)
)
)
public ResponseEntity<Envelope<BasicResponse>> basic(
@org.springframework.web.bind.annotation.RequestBody Envelope<BasicRequest> envelope
) {
// 중요 로직: Swagger 요청 Envelope에서 BasicRequest 추출 (차량번호 및 필수 파라미터 포함)
BasicRequest request = (envelope != null && !envelope.getData().isEmpty()) ? envelope.getData().get(0) : null;
if (request == null || request.getVhrno() == null || request.getVhrno().trim().isEmpty()) {
return ResponseEntity.ok(new Envelope<>(Collections.emptyList()));
}
// VehicleInfoService는 모드에 따라 구현체가 자동 주입되어 분기 처리
BasicResponse basic = vehicleInfoService.getBasicInfo(request);
Envelope<BasicResponse> out = (basic != null) ? new Envelope<>(basic) : new Envelope<>(Collections.emptyList());
return ResponseEntity.ok(out);
}
/**
* 자동차 등록원부(갑)만 조회
* - 중요 로직: VehicleInfoService에 완전히 위임하여 모드별 분기는 서비스 구현체가 자동 처리
*/
@PostMapping(value = "/ledger.ajax", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "자동차등록원부(갑) 조회 (단독)",
description = "vmis.integration.mode에 따라 내부 모듈 또는 외부 REST API를 통해 등록원부만 조회",
requestBody = @RequestBody(
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
examples = @ExampleObject(
name = "등록원부 조회 예제",
value = "{\"data\": [{\"VHRNO\": \"12가3456\",\"ONES_INFORMATION_OPEN\": \"1\",\"CPTTR_NM\": \"홍길동\",\"CPTTR_IHIDNUM\": \"8801011234567\",\"CPTTR_LEGALDONG_CODE\": \"1111011700\",\"DETAIL_EXPRESSION\": \"1\",\"INQIRE_SE_CODE\": \"1\"}]}"
)
)
)
)
public ResponseEntity<Envelope<LedgerResponse>> ledger(
@org.springframework.web.bind.annotation.RequestBody Envelope<LedgerRequest> envelope
) {
// 중요 로직: Swagger 요청 Envelope에서 LedgerRequest 추출 (차량번호 및 필수 파라미터 포함)
LedgerRequest request = (envelope != null && !envelope.getData().isEmpty()) ? envelope.getData().get(0) : null;
if (request == null || request.getVhrno() == null || request.getVhrno().trim().isEmpty()) {
return ResponseEntity.ok(new Envelope<>(Collections.emptyList()));
}
// VehicleInfoService는 모드에 따라 구현체가 자동 주입되어 분기 처리
LedgerResponse ledger = vehicleInfoService.getLedgerInfo(request);
Envelope<LedgerResponse> out = (ledger != null) ? new Envelope<>(ledger) : new Envelope<>(Collections.emptyList());
return ResponseEntity.ok(out);
}
}