diff --git a/src/main/java/cokr/xit/adds/biz/iros/service/BizIrosService.java b/src/main/java/cokr/xit/adds/biz/iros/service/BizIrosService.java new file mode 100644 index 0000000..1dc91d4 --- /dev/null +++ b/src/main/java/cokr/xit/adds/biz/iros/service/BizIrosService.java @@ -0,0 +1,24 @@ +package cokr.xit.adds.biz.iros.service; + +import java.util.List; + +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; + +/** + *
+ * description : + * packageName : cokr.xit.adds.biz.iros.service + * fileName : BizIrosService + * author : limju + * date : 2024-04-29 + * ====================================================================== + * 변경일 변경자 변경 내용 + * ---------------------------------------------------------------------- + * 2024-04-29 limju 최초 생성 + * + *+ */ +public interface BizIrosService { + List
+ * description : + * packageName : cokr.xit.adds.biz.iros.service.bean + * fileName : BizIrosServiceBean + * author : limju + * date : 2024-04-29 + * ====================================================================== + * 변경일 변경자 변경 내용 + * ---------------------------------------------------------------------- + * 2024-04-29 limju 최초 생성 + * + *+ */ +@Slf4j +@RequiredArgsConstructor +@Service +public class BizIrosServiceBean extends AbstractServiceBean implements BizIrosService { + private final InfIrosService infIrosService; + + @Override + public List
+ * description : + * packageName : cokr.xit.adds.biz.iros.web + * fileName : BizIrosController + * author : limju + * date : 2024-04-29 + * ====================================================================== + * 변경일 변경자 변경 내용 + * ---------------------------------------------------------------------- + * 2024-04-29 limju 최초 생성 + * + *+ */ +@Tag(name = "BizIrosController", description = "공공데이타포탈 업무 API") +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/biz/iros/v1") +public class BizIrosController { + private final BizIrosService bizIrosService; + + @Operation(summary = "의약 제품 주성분 상세 정보 조회", description = "의약 제품 주성분 상세 정보 조회") + @PostMapping("/getDrugPrdtMcpnDtls") + public ApiBaseResponse
@@ -18,31 +17,78 @@ import com.fasterxml.jackson.annotation.JsonProperty; * **/ -@JsonInclude(JsonInclude.Include.NON_EMPTY) +//@JsonInclude(JsonInclude.Include.NON_EMPTY) public record DrugPrdtMcpnDtl( - @JsonProperty("ENTRPS_PRMISN_NO") + /** + * 업체 허가 번호 + */ + @JsonAlias("ENTRPS_PRMISN_NO") String entrpsPrmisnNo, - @JsonProperty("ENTRPS") + + /** + * 제품명 + */ + @JsonAlias("ENTRPS") String entrps, - @JsonProperty("PRDUCT") + + /** + * 제품명(한글) + */ + @JsonAlias("PRDUCT") String prduct, - @JsonProperty("MTRAL_SN") + + /** + * 일련 번호 + */ + @JsonAlias("MTRAL_SN") String mtralSn, - @JsonProperty("MTRAL_CODE") + + /** + * 원료 코드 + */ + @JsonAlias("MTRAL_CODE") String mtralCode, - @JsonProperty("MTRAL_NM") + + /** + * 원료명 + */ + @JsonAlias("MTRAL_NM") String mtralNm, - @JsonProperty("QNT") + + /** + * 분량 + */ + @JsonAlias("QNT") String qnt, - @JsonProperty("INGD_UNIT_CD") + + /** + * 분량 단위 정보 + */ + @JsonAlias("INGD_UNIT_CD") String ingdUnitCd, - @JsonProperty("ITEM_SEQ") + + /** + * 품목 기준 코드 + */ + @JsonAlias("ITEM_SEQ") String itemSeq, - @JsonProperty("MAIN_INGR_ENG") + + /** + * 영문 성분명 + */ + @JsonAlias("MAIN_INGR_ENG") String mainIngrEng, - @JsonProperty("BIZRNO") + + /** + * 사업자 등록 번호 + */ + @JsonAlias("BIZRNO") String bizrno, - @JsonProperty("CPNT_CTNT_CONT") + + /** + * 세부 구성 항목 + */ + @JsonAlias("CPNT_CTNT_CONT") String cpntCtntCont ) { } diff --git a/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java b/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java index 0d6bd65..b921093 100644 --- a/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java +++ b/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java @@ -1,12 +1,17 @@ package cokr.xit.adds.inf.iros.model; -import java.util.Objects; +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import cokr.xit.adds.core.util.ApiUtil; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; /** *
@@ -23,108 +28,58 @@ import lombok.Builder; * **/ +@Schema(name = "DrugPrdtMcpnDtlRequest", description = "의약 제품 주성분 상세 정보 조회 request") @JsonInclude(JsonInclude.Include.NON_EMPTY) +@Data +@NoArgsConstructor +@AllArgsConstructor @Builder public class DrugPrdtMcpnDtlRequest { + @Schema(requiredMode = REQUIRED, title = "서비스 키", description = "서비스 키", example = "0fTkYnZU6XjaAPAp6GzKW9Q6fYq8iaoSH9wKUZwz2PBjRXGM04aUgtO3a61xYGjL8nFZn4fjLGS9XErhMSXq%2Bw%3D%3D") + @NotEmpty(message = "서비스 키는 필수 입니다") private String serviceKey; - private Integer pageNo; - private Integer numOfRows; - private String type; - private String entrpsPrmisnNo; - private String prduct; - private String entrps; - private String bizrno; - - public DrugPrdtMcpnDtlRequest() { - } - public DrugPrdtMcpnDtlRequest( - String serviceKey, - Integer pageNo, - Integer numOfRows, - String type, - String entrpsPrmisnNo, - String prduct, - String entrps, - String bizrno - ) { - this.serviceKey = serviceKey; - this.pageNo = pageNo; - this.numOfRows = numOfRows; - this.type = type; - this.entrpsPrmisnNo = ApiUtil.getUtf8UrlEncoding(entrpsPrmisnNo); - this.prduct = ApiUtil.getUtf8UrlEncoding(prduct); - this.entrps = ApiUtil.getUtf8UrlEncoding(entrps); - this.bizrno = bizrno; - } - - public String serviceKey() { - return serviceKey; - } - public Integer pageNo() { - return pageNo; - } + @Schema(requiredMode = REQUIRED, title = "페이지 번호", description = "페이지 번호", example = "1") + @Pattern(regexp = "[0-9]{1,}", message = "페이지 번호는 필수 입니다") + private String pageNo; - public Integer numOfRows() { - return numOfRows; - } + @Schema(requiredMode = REQUIRED, title = "페이지당 갯수", description = "페이지당 갯수", example = "10") + @Pattern(regexp = "[0-9]{1,}", message = "페이지당 갯수는 필수 입니다") + private String numOfRows; - public String type() { - return type; - } - - @JsonProperty("Entrps_prmisn_no") - public String entrpsPrmisnNo() { - return entrpsPrmisnNo; - } - - @JsonProperty("Prduct") - public String prduct() { - return prduct; - } + @Schema(requiredMode = REQUIRED, title = "타입", description = "타입(json | xml)", allowableValues = {"json", "xml"}, example = "json") + @NotEmpty(message = "타입(json | xml)은 필수 입니다") + private String type; - @JsonProperty("Entrps") - public String entrps() { - return entrps; - } + @Schema(title = "업체허가번호", description = "업체허가번호", example = " ") + private String entrpsPrmisnNo; - @JsonProperty("Bizrno") - public String bizrno() { - return bizrno; - } + @Schema(title = "제품명", description = "제품명", example = "포도당주사액") + private String prduct; - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || obj.getClass() != this.getClass()) - return false; - var that = (DrugPrdtMcpnDtlRequest)obj; - return Objects.equals(this.serviceKey, that.serviceKey) && - Objects.equals(this.pageNo, that.pageNo) && - Objects.equals(this.numOfRows, that.numOfRows) && - Objects.equals(this.type, that.type) && - Objects.equals(this.entrpsPrmisnNo, that.entrpsPrmisnNo) && - Objects.equals(this.prduct, that.prduct) && - Objects.equals(this.entrps, that.entrps) && - Objects.equals(this.bizrno, that.bizrno); - } + @Schema(title = "업체명", description = "업체명", example = " ") + private String entrps; - @Override - public int hashCode() { - return Objects.hash(serviceKey, pageNo, numOfRows, type, entrpsPrmisnNo, prduct, entrps, bizrno); - } + @Schema(title = "사업자등록번호", description = "사업자등록번호", example = " ") + private String bizrno; - @Override - public String toString() { - return "DrugPrdtMcpnDtlRequest[" + - "serviceKey=" + serviceKey + ", " + - "pageNo=" + pageNo + ", " + - "numOfRows=" + numOfRows + ", " + - "type=" + type + ", " + - "entrpsPrmisnNo=" + entrpsPrmisnNo + ", " + - "prduct=" + prduct + ", " + - "entrps=" + entrps + ", " + - "bizrno=" + bizrno + ']'; - } + // public DrugPrdtMcpnDtlRequest( + // String serviceKey, + // String pageNo, + // String numOfRows, + // String type, + // String entrpsPrmisnNo, + // String prduct, + // String entrps, + // String bizrno + // ) { + // this.serviceKey = serviceKey; + // this.pageNo = pageNo; + // this.numOfRows = numOfRows; + // this.type = type; + // this.entrpsPrmisnNo = ApiUtil.getUtf8UrlEncoding(entrpsPrmisnNo); + // this.prduct = ApiUtil.getUtf8UrlEncoding(prduct); + // this.entrps = ApiUtil.getUtf8UrlEncoding(entrps); + // this.bizrno = bizrno; + // } } diff --git a/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java b/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java index ab3905a..fd37291 100644 --- a/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java +++ b/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java @@ -1,6 +1,18 @@ package cokr.xit.adds.inf.iros.model; import java.util.List; +import java.util.Objects; + +import org.apache.commons.lang3.ObjectUtils; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +import cokr.xit.adds.core.model.ResultCode; +import cokr.xit.adds.core.spring.exception.ApiCustomException; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; /** *
@@ -17,21 +29,82 @@ import java.util.List; * **/ -public record IrosResponse
* description : @@ -15,5 +19,6 @@ package cokr.xit.adds.inf.iros.service; * **/ -public class InfIrosService { +public interface InfIrosService { + IrosResponse
+ * description : + * packageName : cokr.xit.adds.inf.iros.service.bean + * fileName : InfIrosServiceBean + * author : limju + * date : 2024-04-29 + * ====================================================================== + * 변경일 변경자 변경 내용 + * ---------------------------------------------------------------------- + * 2024-04-29 limju 최초 생성 + * + *+ */ +@Slf4j +@RequiredArgsConstructor +@Service +public class InfIrosServiceBean extends AbstractServiceBean implements InfIrosService { + private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + private static JSON json = new JSON(); + + @Value("${app.inf.iros.url}") + private String irosUrl; + + @Value("${app.inf.iros.api-key}") + private String irosApiKey; + + @Value("${app.inf.iros.api.drugPrdtMcpnDtlInq}") + private String drugPrdtMcpnDtlInq; + + @Override + public IrosResponse
+ * Gateway Error Parsing + * + *+ */ + private static void gatewayErrorParsing(String rslt) { + XML xml = new XML(); + Map+ * + * + *SERVICE ERROR + *SERVICE_KEY_IS_NOT_REGISTERED_ERROR + *30 + *+ * @param rslt + *
* description : @@ -15,6 +29,18 @@ package cokr.xit.adds.inf.iros.web; * **/ -public class InfIrosController -{ +@Tag(name = "InfIrosController", description = "공공데이타포탈 Interface API - Api Interface call Test(테스트용)") +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/inf/iros/v1") +public class InfIrosController { + private final InfIrosService infIrosService; + + @Operation(summary = "의약 제품 주성분 상세 정보 조회", description = "의약 제품 주성분 상세 정보 조회") + @PostMapping("/getDrugPrdtMcpnDtls") + public ApiBaseResponse
* description : @@ -39,43 +34,39 @@ import cokr.xit.adds.inf.iros.model.IrosResponse; @ExtendWith(SpringExtension.class) @AutoConfigureMockMvc public class IrosRestfulTest { - private static final String url = "http://apis.data.go.kr/1471000/DrugPrdtPrmsnInfoService05/getDrugPrdtMcpnDtlInq04"; - private static final String serviceKey = "0fTkYnZU6XjaAPAp6GzKW9Q6fYq8iaoSH9wKUZwz2PBjRXGM04aUgtO3a61xYGjL8nFZn4fjLGS9XErhMSXq+w=="; - - TestRestTemplate testRestTemplate = new TestRestTemplate(); + private static final String uri = "http://apis.data.go.kr/1471000/DrugPrdtPrmsnInfoService05/getDrugPrdtMcpnDtlInq04"; + private static final String serviceKey = "0fTkYnZU6XjaAPAp6GzKW9Q6fYq8iaoSH9wKUZwz2PBjRXGM04aUgtO3a61xYGjL8nFZn4fjLGS9XErhMSXq%2Bw%3D%3D"; @DisplayName("의약품 성분조회 테스트") @Test public void testDrugPrdtMcpnDtl() { - final Listheaders = Lists.newArrayList(new BasicHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)); - final CloseableHttpClient httpClient = HttpClients.custom().setDefaultHeaders(headers).build(); - testRestTemplate.getRestTemplate().setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); - final DrugPrdtMcpnDtlRequest request = DrugPrdtMcpnDtlRequest.builder() + final DrugPrdtMcpnDtlRequest param = DrugPrdtMcpnDtlRequest.builder() .serviceKey(serviceKey) - .pageNo(1) - .numOfRows(10) + .pageNo("1") + .numOfRows("10") .type("json") - .prduct("중외20%포도당주사액") + .prduct("포도당주사액") .build(); - final String urlParam = String.format( - "?serviceKey=%s&pageNo=%d&numOfRows=%d&type=%s&Prduct=%s", - request.serviceKey(), - request.pageNo(), - request.numOfRows(), - request.type(), - request.prduct()); - final IrosResponse irosResponse = testRestTemplate.getForObject(url + urlParam, IrosResponse.class); - Assertions.assertThat(irosResponse).isNotNull(); - Assertions.assertThat(irosResponse.header().resultCode()).isEqualTo("00"); - Assertions.assertThat(irosResponse.header().resultMsg()).isEqualTo("NORMAL SERVICE."); - Assertions.assertThat(irosResponse.body().pageNo()).isEqualTo("1"); - Assertions.assertThat(irosResponse.body().numOfRows()).isEqualTo("10"); - Assertions.assertThat(irosResponse.body().totalCount()).isEqualTo("1"); - //HttpEntity requestEntity = new HttpEntity<>(request); - //ResponseEntity > forEntity = testRestTemplate.exchange(url, HttpMethod.GET, requestEntity, new ParameterizedTypeReference >() {}); - //Assertions.assertThat(forEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + HttpResponse rslt = new WebClient().get(request -> { + String urlParam = String.format( + "?serviceKey=%s&pageNo=%s&numOfRows=%s&type=%s&Prduct=%s", + param.getServiceKey(), + param.getPageNo(), + param.getNumOfRows(), + param.getType(), + param.getPrduct() + ); + request.header("Content-Type", "application/json"); + request.contentType(WebClient.Request.ContentType.FORM); + request.uri(uri + urlParam); + }); + + IrosResponse parse = new JSON().parse(rslt.body(), + new TypeReference >() { + }); + System.out.println(parse); } }