diff --git a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java index f8d5f05..fb7ddc6 100644 --- a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java +++ b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java @@ -11,6 +11,7 @@ import org.springframework.http.*; import org.springframework.stereotype.*; import cokr.xit.ens.core.exception.*; +import cokr.xit.ens.core.exception.code.*; import cokr.xit.ens.core.utils.*; import cokr.xit.ens.modules.kkotalk.model.*; import lombok.*; @@ -233,7 +234,7 @@ public class KkoTalkApiService { ResponseEntity resEntity = null; if(Checks.isEmpty(reqDTO.getProductCode())){ - return new ResponseEntity("상품 코드는 필수 입니다.", HttpStatus.BAD_REQUEST); + return new ResponseEntity("{\""+EnsErrCd.SEND405.getCode() +"\":\"상품 코드는 필수 입니다\"}", HttpStatus.BAD_REQUEST); } List errors = new ArrayList<>(); @@ -275,7 +276,7 @@ public class KkoTalkApiService { } } if(!errors.isEmpty()){ - return new ResponseEntity(errors.toString(), HttpStatus.BAD_REQUEST); + return new ResponseEntity("{\""+EnsErrCd.SEND405.getCode() +"\":" + errors.toString() +"}", HttpStatus.BAD_REQUEST); } String param = "{\"envelopes\":" + JsonUtils.toJson(envelopes) + "}"; return webClient.exchangeKkotalk( diff --git a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkSender.java b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkSender.java index 6e36e1f..c40431b 100644 --- a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkSender.java +++ b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkSender.java @@ -93,7 +93,7 @@ public class KkoTalkSender extends SendProcTemplate { sendRespBody = resp.getBody(); if (resp.getStatusCode() != HttpStatus.OK) throw new EnsException(EnsErrCd.SEND620, String.format("전송요청 중.. %s %s", resp.getStatusCode().toString(), resp.getBody())); - EnsResponseVO mResponse = this.respMsgToMap(resp.getBody()); + EnsResponseVO mResponse = this.respMsgToMap(sendRespBody); if (!EnsErrCd.OK.equals(mResponse.getErrCode())) throw new EnsException(mResponse.getErrCode(), mResponse.getErrMsg()); @@ -305,13 +305,13 @@ public class KkoTalkSender extends SendProcTemplate { }) .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (Long) m.get("value"), (k1, k2) -> k1)); - EnsResponseVO respVO = this.respMsgToMap(respMsg); + if(JsonUtils.isJson(respMsg)) { + EnsResponseVO respVO = this.respMsgToMap(respMsg); - - if (EnsErrCd.OK.equals(respVO.getErrCode())) { - Map mRespBody = (Map) respVO.getResultInfo(); - List> documents = (List>) mRespBody.get("envelopeIds"); - Map> mRespMsg = documents.stream() + if (EnsErrCd.OK.equals(respVO.getErrCode())) { + Map mRespBody = (Map)respVO.getResultInfo(); + List> documents = (List>)mRespBody.get("envelopeIds"); + Map> mRespMsg = documents.stream() .map(row -> { Map m = new HashMap<>(); m.put("key", String.valueOf(row.get("externalId"))); @@ -323,9 +323,11 @@ public class KkoTalkSender extends SendProcTemplate { m.put("value", mValue); return m; }) - .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (Map) m.get("value"), (k1, k2) -> k1)); + .collect( + Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (Map)m.get("value"), + (k1, k2) -> k1)); - return sendMsgList.stream() + return sendMsgList.stream() .map(row -> { // //Map property = (Map) row.get("property"); @@ -333,40 +335,59 @@ public class KkoTalkSender extends SendProcTemplate { boolean isSuccess = CmmnUtil.isEmpty(mRespMsg.get(externalId).get("errorCode")); return SendDetailKkoTalkReqHist.builder() - .sendDetailId(mSendDetailIds.get(externalId)) - .sendRawMsg(gson.toJson(row)) - .externalId(externalId) - .envelopeId(mRespMsg.get(externalId).get("envelopeId")) - .respRawMsg(mRespMsg.get(externalId).get("rawMsg")) - .error(FieldError.initBuilder() - .errorCode(isSuccess ? null : EnsErrCd.SEND620.getCode()) - .errorMessage(isSuccess ? null : String.format("%s %s" - , mRespMsg.get(externalId).get("errorCode") - , mRespMsg.get(externalId).get("errorMessage") - )) - .build()) - .build(); + .sendDetailId(mSendDetailIds.get(externalId)) + .sendRawMsg(gson.toJson(row)) + .externalId(externalId) + .envelopeId(mRespMsg.get(externalId).get("envelopeId")) + .respRawMsg(mRespMsg.get(externalId).get("rawMsg")) + .error(FieldError.initBuilder() + .errorCode(isSuccess ? null : EnsErrCd.SEND620.getCode()) + .errorMessage(isSuccess ? null : String.format("%s %s" + , mRespMsg.get(externalId).get("errorCode") + , mRespMsg.get(externalId).get("errorMessage") + )) + .build()) + .build(); }) .collect(Collectors.toList()); - } else { - return sendMsgList.stream() + } else { + return sendMsgList.stream() .map(row -> { //Map property = (Map) row.get("property"); String externalId = (String)row.get("externalId"); return SendDetailKkoTalkReqHist.builder() - .sendDetailId(mSendDetailIds.get(externalId)) - .sendRawMsg(gson.toJson(row)) - .externalId(externalId) - .respRawMsg(respMsg) - .error(FieldError.initBuilder() - .errorCode(respVO.getErrCode().getCode()) - .errorMessage(respVO.getErrMsg()) - .build()) - .build(); + .sendDetailId(mSendDetailIds.get(externalId)) + .sendRawMsg(gson.toJson(row)) + .externalId(externalId) + .respRawMsg(respMsg) + .error(FieldError.initBuilder() + .errorCode(respVO.getErrCode().getCode()) + .errorMessage(respVO.getErrMsg()) + .build()) + .build(); }) .collect(Collectors.toList()); + } + }else{ + return sendMsgList.stream() + .map(row -> { + //Map property = (Map) row.get("property"); + String externalId = (String)row.get("externalId"); + + return SendDetailKkoTalkReqHist.builder() + .sendDetailId(mSendDetailIds.get(externalId)) + .sendRawMsg(gson.toJson(row)) + .externalId(externalId) + .respRawMsg(respMsg) + .error(FieldError.initBuilder() + .errorCode("") + .errorMessage(respMsg) + .build()) + .build(); + }) + .collect(Collectors.toList()); } } @@ -377,7 +398,7 @@ public class KkoTalkSender extends SendProcTemplate { try { mResp = gson.fromJson(respMsg, Map.class); if (CmmnUtil.isEmpty(mResp.get("envelopeIds"))) - throw new EnsException(EnsErrCd.SEND620, String.format("전송요청API 오류. documents 키값이 없습니다. %s", respMsg)); + throw new EnsException(EnsErrCd.SEND620, String.format("전송요청API 오류. envelopeId 키값이 없습니다. %s", respMsg)); } catch (EnsException e) { errCode = e.getErrCd(); errMsg = e.getMessage();