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

- mapper SQL 반영
main
Jonguk. Lim 2 months ago
parent 178d546ee4
commit 1af0e0fded

@ -229,9 +229,11 @@ public class KkoTalkApiService {
* @param reqDTO KkotalkDTO.BulkSendRequest * @param reqDTO KkotalkDTO.BulkSendRequest
* @return KkotalkDTO.BulkSendResponse * @return KkotalkDTO.BulkSendResponse
*/ */
public String requestSendBulk2(final KkotalkDTO.BulkSendRequest reqDTO) { public ResponseEntity<String> requestSendBulk2(final KkotalkDTO.BulkSendRequest reqDTO) {
ResponseEntity<String> resEntity = null;
if(Checks.isEmpty(reqDTO.getProductCode())){ if(Checks.isEmpty(reqDTO.getProductCode())){
throw BizRuntimeException.create("상품 코드는 필수 입니다."); return new ResponseEntity<String>("상품 코드는 필수 입니다.", HttpStatus.BAD_REQUEST);
} }
List<String> errors = new ArrayList<>(); List<String> errors = new ArrayList<>();
@ -273,14 +275,14 @@ public class KkoTalkApiService {
} }
} }
if(!errors.isEmpty()){ if(!errors.isEmpty()){
throw BizRuntimeException.create(errors.toString()); return new ResponseEntity<String>(errors.toString(), HttpStatus.BAD_REQUEST);
} }
String param = "{\"envelopes\":" + JsonUtils.toJson(envelopes) + "}"; String param = "{\"envelopes\":" + JsonUtils.toJson(envelopes) + "}";
return webClient.exchangeKkotalk( return webClient.exchangeKkotalk(
HOST + API_BULKSEND[0].replace("{PRODUCT_CODE}", reqDTO.getProductCode()), HOST + API_BULKSEND[0].replace("{PRODUCT_CODE}", reqDTO.getProductCode()),
HttpMethod.valueOf(API_BULKSEND[1]), HttpMethod.valueOf(API_BULKSEND[1]),
param, param,
String.class, ResponseEntity.class,
getRlaybsnmInfo(reqDTO)); getRlaybsnmInfo(reqDTO));
} }

@ -6,6 +6,7 @@ import java.util.stream.*;
import org.apache.commons.lang3.*; import org.apache.commons.lang3.*;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.*; import org.springframework.context.*;
import org.springframework.http.*;
import org.springframework.stereotype.*; import org.springframework.stereotype.*;
import org.springframework.transaction.annotation.*; import org.springframework.transaction.annotation.*;
@ -54,7 +55,7 @@ public class KkoTalkSender extends SendProcTemplate {
@Override @Override
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public EnsResponseVO execute(Long sendMastId) { public EnsResponseVO<?> execute(Long sendMastId) {
SendMast sendMast = null; SendMast sendMast = null;
List<KkotalkDTO.SendDetailKkoTalkDTO> sendDetails = null; List<KkotalkDTO.SendDetailKkoTalkDTO> sendDetails = null;
@ -63,83 +64,99 @@ public class KkoTalkSender extends SendProcTemplate {
if (CmmnUtil.isEmpty(sendMastId)) if (CmmnUtil.isEmpty(sendMastId))
throw new EnsException(EnsErrCd.SEND410, "발송마스터ID(은)는 필수조건 입니다."); throw new EnsException(EnsErrCd.SEND410, "발송마스터ID(은)는 필수조건 입니다.");
sendMast = sendMastRepository.findById(sendMastId).orElseThrow(() -> new EnsException(EnsErrCd.SEND404, String.format("일치하는 발송마스터 자료가 없습니다. [ sendMastId %s ]", sendMastId))); sendMast = sendMastRepository.findById(sendMastId)
.orElseThrow(() -> new EnsException(EnsErrCd.SEND404,
String.format("일치하는 발송마스터 자료가 없습니다. [ sendMastId %s ]", sendMastId)));
sendDetails = talkMapper.findAllFetchBySendMastId(sendMast.getSendMastId()); sendDetails = talkMapper.findAllFetchBySendMastId(sendMast.getSendMastId());
OrgMng orgMng = orgMngService.find(sendMast.getOrgCd()).getResultInfo(); OrgMng orgMng = orgMngService.find(sendMast.getOrgCd()).getResultInfo();
Lists.partition(sendDetails, SEND_BATCH_UNIT).stream() Lists.partition(sendDetails, SEND_BATCH_UNIT).stream()
.forEach(list -> { .forEach(list -> {
String resp = null; List<KkotalkApiDTO.Envelope> envelopes = null;
List<KkotalkApiDTO.Envelope> envelopes = null; String sendRespBody = null;
try { try {
envelopes = this.makeMessage(list); envelopes = this.makeMessage(list);
resp = kkoTalkApi.requestSendBulk2( ResponseEntity<String> resp = kkoTalkApi.requestSendBulk2(
KkotalkDTO.BulkSendRequest.builder() KkotalkDTO.BulkSendRequest.builder()
.envelopes(envelopes) // FIXME: 카카오톡 신규 추가 - 테스트를 위해 임시로 넣음
.signguCode(orgMng.getOrgCd()) .productCode("D10_2")
.ffnlgCode("11") .envelopes(envelopes)
.signguCode(orgMng.getOrgCd())
.build() .ffnlgCode("11")
);
.build()
EnsResponseVO<?> mResponse = this.respMsgToMap(resp); );
if (!EnsErrCd.OK.equals(mResponse.getErrCode()))
throw new EnsException(mResponse.getErrCode(), mResponse.getErrMsg()); sendRespBody = resp.getBody();
List<Map<String, Object>> documents = (List<Map<String, Object>>) ((Map<String, Object>) mResponse.getResultInfo()).get("envelopeIds"); if (resp.getStatusCode() != HttpStatus.OK)
throw new EnsException(EnsErrCd.SEND620, String.format("전송요청 중.. %s %s", resp.getStatusCode().toString(), resp.getBody()));
Map<String, KkoTalkApiRespVO> mApiResp = documents.stream() EnsResponseVO mResponse = this.respMsgToMap(resp.getBody());
.map(this::toApiRespVOMap) if (!EnsErrCd.OK.equals(mResponse.getErrCode()))
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (KkoTalkApiRespVO) m.get("value"), (k1, k2) -> k1)); throw new EnsException(mResponse.getErrCode(), mResponse.getErrMsg());
list.stream()
.forEach(row -> this.modifyTalkSendRsltByExtDocUuid(row, mApiResp)); List<Map<String, Object>> documents = (List<Map<String, Object>>)((Map<String, Object>)mResponse.getResultInfo()).get(
"envelopeIds");
} catch (EnsException e) {
Map<String, KkoTalkApiRespVO> mApiResp = documents.stream()
list.stream() .map(this::toApiRespVOMap)
.forEach(row -> { .collect(Collectors.toMap(m -> String.valueOf(m.get("key")),
row.setStatus(KkoTalkStatusCd.SENT_FAIL); m -> (KkoTalkApiRespVO)m.get("value"), (k1, k2) -> k1));
row.setErrorCode(e.getErrCd().getCode());
row.setErrorMessage(e.getMessage()); list.stream()
}); .forEach(row -> this.modifyTalkSendRsltByExtDocUuid(row, mApiResp));
} catch (Exception e) {
} catch (EnsException e) {
list.stream()
.forEach(row -> { list.stream()
row.setStatus(KkoTalkStatusCd.SENT_FAIL); .forEach(row -> {
row.setErrorCode(EnsErrCd.SEND500.getCode()); row.setStatus(KkoTalkStatusCd.SENT_FAIL);
row.setErrorMessage(e.getMessage()); row.setErrorCode(e.getErrCd().getCode());
}); row.setErrorMessage(e.getMessage());
} finally { });
if (!CmmnUtil.isEmpty(envelopes)) } catch (Exception e) {
sendDetailKkoTalkReqHistRepository.saveAll(this.toSendDetailReqHist(list, JsonUtils.toJson(envelopes), resp));
} list.stream()
.forEach(row -> {
}); row.setStatus(KkoTalkStatusCd.SENT_FAIL);
row.setErrorCode(EnsErrCd.SEND500.getCode());
row.setErrorMessage(e.getMessage());
});
} finally {
if (!CmmnUtil.isEmpty(envelopes))
sendDetailKkoTalkReqHistRepository.saveAll(
this.toSendDetailReqHist(list, JsonUtils.toJson(envelopes), sendRespBody));
}
});
Optional<Integer> cntSuccess = sendDetails.stream() Optional<Integer> cntSuccess = sendDetails.stream()
.map(row -> CmmnUtil.isEmpty(row.getErrorCode()) ? 1 : 0) .map(row -> CmmnUtil.isEmpty(row.getErrorCode()) ? 1 : 0)
.reduce(Integer::sum); .reduce(Integer::sum);
if (cntSuccess.get() > 0) if (cntSuccess.get() > 0)
respVO = EnsResponseVO.okBuilder() respVO = EnsResponseVO.okBuilder()
.resultInfo(sendDetails.stream() .resultInfo(sendDetails.stream()
.map(row -> this.toResultInfo(row)) .map(row -> this.toResultInfo(row))
.collect(Collectors.toList())) .collect(Collectors.toList()))
.build(); .build();
else else
throw new EnsException(EnsErrCd.SEND500, String.format("전체건수 전송 실패(총 %d 건)", sendDetails.size())); throw new EnsException(EnsErrCd.SEND500, String.format("전체건수 전송 실패(총 %d 건)", sendDetails.size()));
} catch (EnsException e) { } catch (BizRuntimeException be){
respVO = EnsResponseVO.errBuilder()
.errCode(EnsErrCd.SEND500)
.errMsg(be.getMessage())
.build();
} catch (EnsException e) {
respVO = EnsResponseVO.errBuilder().errCode(e.getErrCd()).errMsg(e.getMessage()).build(); respVO = EnsResponseVO.errBuilder().errCode(e.getErrCd()).errMsg(e.getMessage()).build();
} catch (Exception e) {
} catch (Exception e) {
respVO = EnsResponseVO.errBuilder().errCode(EnsErrCd.SEND500).errMsg(e.getMessage()).build(); respVO = EnsResponseVO.errBuilder().errCode(EnsErrCd.SEND500).errMsg(e.getMessage()).build();
} finally { } finally {
if (!CmmnUtil.isEmpty(sendMast)) { if (!CmmnUtil.isEmpty(sendMast)) {
if (EnsErrCd.OK.equals(respVO.getErrCode())) { if (EnsErrCd.OK.equals(respVO.getErrCode())) {
@ -278,9 +295,7 @@ public class KkoTalkSender extends SendProcTemplate {
* @return * @return
*/ */
private List<SendDetailKkoTalkReqHist> toSendDetailReqHist(List<KkotalkDTO.SendDetailKkoTalkDTO> list, String sendMsg, String respMsg) { private List<SendDetailKkoTalkReqHist> toSendDetailReqHist(List<KkotalkDTO.SendDetailKkoTalkDTO> list, String sendMsg, String respMsg) {
List<Map> sendMsgList = JsonUtils.toObjectList(sendMsg, Map.class);
List<Map<String, Object>> sendMsgList = (List<Map<String, Object>>) gson.fromJson(sendMsg, Map.class).get("envelopes");
Map<String, Long> mSendDetailIds = list.stream() Map<String, Long> mSendDetailIds = list.stream()
.map(row -> { .map(row -> {
Map<String, Object> m = new HashMap<>(); Map<String, Object> m = new HashMap<>();
@ -290,7 +305,7 @@ 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));
EnsResponseVO respVO = this.respMsgToMap(respMsg); EnsResponseVO<?> respVO = this.respMsgToMap(respMsg);
if (EnsErrCd.OK.equals(respVO.getErrCode())) { if (EnsErrCd.OK.equals(respVO.getErrCode())) {

Loading…
Cancel
Save