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 org.springframework.stereotype.*;
import cokr.xit.ens.core.exception.*; import cokr.xit.ens.core.exception.*;
import cokr.xit.ens.core.exception.code.*;
import cokr.xit.ens.core.utils.*; import cokr.xit.ens.core.utils.*;
import cokr.xit.ens.modules.kkotalk.model.*; import cokr.xit.ens.modules.kkotalk.model.*;
import lombok.*; import lombok.*;
@ -233,7 +234,7 @@ public class KkoTalkApiService {
ResponseEntity<String> resEntity = null; ResponseEntity<String> resEntity = null;
if(Checks.isEmpty(reqDTO.getProductCode())){ 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<>(); List<String> errors = new ArrayList<>();
@ -275,7 +276,7 @@ public class KkoTalkApiService {
} }
} }
if(!errors.isEmpty()){ 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) + "}"; String param = "{\"envelopes\":" + JsonUtils.toJson(envelopes) + "}";
return webClient.exchangeKkotalk( return webClient.exchangeKkotalk(

@ -93,7 +93,7 @@ public class KkoTalkSender extends SendProcTemplate {
sendRespBody = resp.getBody(); sendRespBody = resp.getBody();
if (resp.getStatusCode() != HttpStatus.OK) if (resp.getStatusCode() != HttpStatus.OK)
throw new EnsException(EnsErrCd.SEND620, String.format("전송요청 중.. %s %s", resp.getStatusCode().toString(), resp.getBody())); 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())) if (!EnsErrCd.OK.equals(mResponse.getErrCode()))
throw new EnsException(mResponse.getErrCode(), mResponse.getErrMsg()); throw new EnsException(mResponse.getErrCode(), mResponse.getErrMsg());
@ -305,12 +305,12 @@ public class KkoTalkSender extends SendProcTemplate {
}) })
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (Long) m.get("value"), (k1, k2) -> k1)); .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (Long) m.get("value"), (k1, k2) -> k1));
if(JsonUtils.isJson(respMsg)) {
EnsResponseVO<?> respVO = this.respMsgToMap(respMsg); EnsResponseVO<?> respVO = this.respMsgToMap(respMsg);
if (EnsErrCd.OK.equals(respVO.getErrCode())) { if (EnsErrCd.OK.equals(respVO.getErrCode())) {
Map<String, Object> mRespBody = (Map<String, Object>) respVO.getResultInfo(); Map<String, Object> mRespBody = (Map<String, Object>)respVO.getResultInfo();
List<Map<String, String>> documents = (List<Map<String, String>>) mRespBody.get("envelopeIds"); List<Map<String, String>> documents = (List<Map<String, String>>)mRespBody.get("envelopeIds");
Map<String, Map<String, String>> mRespMsg = documents.stream() Map<String, Map<String, String>> mRespMsg = documents.stream()
.map(row -> { .map(row -> {
Map<String, Object> m = new HashMap<>(); Map<String, Object> m = new HashMap<>();
@ -323,7 +323,9 @@ public class KkoTalkSender extends SendProcTemplate {
m.put("value", mValue); m.put("value", mValue);
return m; 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(row -> {
@ -368,6 +370,25 @@ public class KkoTalkSender extends SendProcTemplate {
}) })
.collect(Collectors.toList()); .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());
}
} }
private EnsResponseVO<?> respMsgToMap(String respMsg) { private EnsResponseVO<?> respMsgToMap(String respMsg) {
@ -377,7 +398,7 @@ public class KkoTalkSender extends SendProcTemplate {
try { try {
mResp = gson.fromJson(respMsg, Map.class); mResp = gson.fromJson(respMsg, Map.class);
if (CmmnUtil.isEmpty(mResp.get("envelopeIds"))) 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) { } catch (EnsException e) {
errCode = e.getErrCd(); errCode = e.getErrCd();
errMsg = e.getMessage(); errMsg = e.getMessage();

Loading…
Cancel
Save