feat: 카카오톡 추가 반영 - send

- 에러처리 반영
main
Jonguk. Lim 2 months ago
parent 1af0e0fded
commit d5ff0a88ae

@ -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<String> resEntity = null;
if(Checks.isEmpty(reqDTO.getProductCode())){
return new ResponseEntity<String>("상품 코드는 필수 입니다.", HttpStatus.BAD_REQUEST);
return new ResponseEntity<String>("{\""+EnsErrCd.SEND405.getCode() +"\":\"상품 코드는 필수 입니다\"}", HttpStatus.BAD_REQUEST);
}
List<String> errors = new ArrayList<>();
@ -275,7 +276,7 @@ public class KkoTalkApiService {
}
}
if(!errors.isEmpty()){
return new ResponseEntity<String>(errors.toString(), HttpStatus.BAD_REQUEST);
return new ResponseEntity<String>("{\""+EnsErrCd.SEND405.getCode() +"\":" + errors.toString() +"}", HttpStatus.BAD_REQUEST);
}
String param = "{\"envelopes\":" + JsonUtils.toJson(envelopes) + "}";
return webClient.exchangeKkotalk(

@ -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<String, Object> mRespBody = (Map<String, Object>) respVO.getResultInfo();
List<Map<String, String>> documents = (List<Map<String, String>>) mRespBody.get("envelopeIds");
Map<String, Map<String, String>> mRespMsg = documents.stream()
if (EnsErrCd.OK.equals(respVO.getErrCode())) {
Map<String, Object> mRespBody = (Map<String, Object>)respVO.getResultInfo();
List<Map<String, String>> documents = (List<Map<String, String>>)mRespBody.get("envelopeIds");
Map<String, Map<String, String>> mRespMsg = documents.stream()
.map(row -> {
Map<String, Object> 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<String, String>) m.get("value"), (k1, k2) -> k1));
.collect(
Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (Map<String, String>)m.get("value"),
(k1, k2) -> k1));
return sendMsgList.stream()
return sendMsgList.stream()
.map(row -> {
//
//Map<String, String> property = (Map<String, String>) 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<String, String> property = (Map<String, String>) 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<String, String> property = (Map<String, String>) 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();

Loading…
Cancel
Save