공공데이타포탈 의약 제품 주성분 상세정보 API 반영
parent
a7c77316b1
commit
95bcc8994a
@ -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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description :
|
||||
* packageName : cokr.xit.adds.biz.iros.service
|
||||
* fileName : BizIrosService
|
||||
* author : limju
|
||||
* date : 2024-04-29
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2024-04-29 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
public interface BizIrosService {
|
||||
List<DrugPrdtMcpnDtl> getDrugPrdtMcpnDtls(DrugPrdtMcpnDtlRequest dto);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package cokr.xit.adds.biz.iros.service.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import cokr.xit.adds.biz.iros.service.BizIrosService;
|
||||
import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl;
|
||||
import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest;
|
||||
import cokr.xit.adds.inf.iros.model.IrosResponse;
|
||||
import cokr.xit.adds.inf.iros.service.InfIrosService;
|
||||
import cokr.xit.foundation.component.AbstractServiceBean;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description :
|
||||
* packageName : cokr.xit.adds.biz.iros.service.bean
|
||||
* fileName : BizIrosServiceBean
|
||||
* author : limju
|
||||
* date : 2024-04-29
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2024-04-29 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class BizIrosServiceBean extends AbstractServiceBean implements BizIrosService {
|
||||
private final InfIrosService infIrosService;
|
||||
|
||||
@Override
|
||||
public List<DrugPrdtMcpnDtl> getDrugPrdtMcpnDtls(DrugPrdtMcpnDtlRequest dto) {
|
||||
IrosResponse<DrugPrdtMcpnDtl> rslt = infIrosService.getDrugPrdtMcpnDtls(dto);
|
||||
|
||||
return rslt.getResultOrThrow();
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package cokr.xit.adds.biz.iros.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import cokr.xit.adds.biz.iros.service.BizIrosService;
|
||||
import cokr.xit.adds.core.model.ApiBaseResponse;
|
||||
import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl;
|
||||
import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description :
|
||||
* packageName : cokr.xit.adds.biz.iros.web
|
||||
* fileName : BizIrosController
|
||||
* author : limju
|
||||
* date : 2024-04-29
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2024-04-29 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@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<List<DrugPrdtMcpnDtl>> getDrugPrdtMcpnDtls(
|
||||
@RequestBody DrugPrdtMcpnDtlRequest dto
|
||||
) {
|
||||
return ApiBaseResponse.of(bizIrosService.getDrugPrdtMcpnDtls(dto));
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package cokr.xit.adds.inf.iros.service.bean;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import cokr.xit.adds.core.spring.exception.ApiCustomException;
|
||||
import cokr.xit.adds.core.util.ApiUtil;
|
||||
import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl;
|
||||
import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest;
|
||||
import cokr.xit.adds.inf.iros.model.IrosResponse;
|
||||
import cokr.xit.adds.inf.iros.service.InfIrosService;
|
||||
import cokr.xit.foundation.component.AbstractServiceBean;
|
||||
import cokr.xit.foundation.data.JSON;
|
||||
import cokr.xit.foundation.data.XML;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description :
|
||||
* packageName : cokr.xit.adds.inf.iros.service.bean
|
||||
* fileName : InfIrosServiceBean
|
||||
* author : limju
|
||||
* date : 2024-04-29
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2024-04-29 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@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<DrugPrdtMcpnDtl> getDrugPrdtMcpnDtls(DrugPrdtMcpnDtlRequest dto) {
|
||||
dto.setServiceKey(irosApiKey);
|
||||
ApiUtil.validate(dto, null, validator);
|
||||
|
||||
if(isEmpty(dto.getEntrpsPrmisnNo())
|
||||
&& isEmpty(dto.getPrduct())
|
||||
&& isEmpty(dto.getEntrps())
|
||||
&& isEmpty(dto.getBizrno())
|
||||
) throw ApiCustomException.create("업체허가번호, 제품명, 업체명, 사업자번호 중 하나는 필수 입니다");
|
||||
|
||||
String params = String.format(
|
||||
"?serviceKey=%s&pageNo=%s&numOfRows=%s&type=%s&Entrps_prmisn_no=%s&Prduct=%s&Entrps=%s&Bizrno=%s",
|
||||
dto.getServiceKey(),
|
||||
dto.getPageNo(),
|
||||
dto.getNumOfRows(),
|
||||
dto.getType(),
|
||||
dto.getEntrpsPrmisnNo(),
|
||||
dto.getPrduct(),
|
||||
dto.getEntrps(),
|
||||
dto.getBizrno());
|
||||
|
||||
String rslt = ApiUtil.callIrosApi(irosUrl + drugPrdtMcpnDtlInq, params);
|
||||
IrosResponse<DrugPrdtMcpnDtl> result = null;
|
||||
try {
|
||||
result = json.parse(rslt, new TypeReference<IrosResponse<DrugPrdtMcpnDtl>>() {});
|
||||
} catch (Exception e) {
|
||||
|
||||
if(!isEmpty(e.getCause())){
|
||||
//System.out.println("JsonParseException" + je.getMessage());
|
||||
gatewayErrorParsing(rslt);
|
||||
}
|
||||
throw ApiCustomException.create(e.getMessage());
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Gateway Error Parsing
|
||||
*
|
||||
* <OpenAPI ServiceResponse>
|
||||
* <cmmMsgHeader>
|
||||
* <errMsg>SERVICE ERROR</errMsg>
|
||||
* <returnAuthMsg>SERVICE_KEY_IS_NOT_REGISTERED_ERROR</returnAuthMsg>
|
||||
* <returnReasonCode>30</returnReasonCode>
|
||||
* </cmmMsgHeader>
|
||||
* <OpenAPI ServiceResponse>
|
||||
* @param rslt
|
||||
* </pre>
|
||||
*/
|
||||
private static void gatewayErrorParsing(String rslt) {
|
||||
XML xml = new XML();
|
||||
Map<String, Map<String, String>> map = xml.parse(rslt, Map.class);
|
||||
Map<String, String> hMap = map.get("cmmMsgHeader");
|
||||
if(!isEmpty(hMap)) {
|
||||
throw ApiCustomException.create(Integer.valueOf(hMap.get("returnReasonCode")),
|
||||
String.format("%s[%s]", hMap.get("errMsg"), hMap.get("returnAuthMsg")));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue