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

@ -6,6 +6,7 @@ import java.util.stream.*;
import org.apache.commons.lang3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.*;
import org.springframework.http.*;
import org.springframework.stereotype.*;
import org.springframework.transaction.annotation.*;
@ -54,7 +55,7 @@ public class KkoTalkSender extends SendProcTemplate {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public EnsResponseVO execute(Long sendMastId) {
public EnsResponseVO<?> execute(Long sendMastId) {
SendMast sendMast = null;
List<KkotalkDTO.SendDetailKkoTalkDTO> sendDetails = null;
@ -63,83 +64,99 @@ public class KkoTalkSender extends SendProcTemplate {
if (CmmnUtil.isEmpty(sendMastId))
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());
OrgMng orgMng = orgMngService.find(sendMast.getOrgCd()).getResultInfo();
Lists.partition(sendDetails, SEND_BATCH_UNIT).stream()
.forEach(list -> {
String resp = null;
List<KkotalkApiDTO.Envelope> envelopes = null;
try {
envelopes = this.makeMessage(list);
resp = kkoTalkApi.requestSendBulk2(
KkotalkDTO.BulkSendRequest.builder()
.envelopes(envelopes)
.signguCode(orgMng.getOrgCd())
.ffnlgCode("11")
.build()
);
EnsResponseVO<?> mResponse = this.respMsgToMap(resp);
if (!EnsErrCd.OK.equals(mResponse.getErrCode()))
throw new EnsException(mResponse.getErrCode(), mResponse.getErrMsg());
List<Map<String, Object>> documents = (List<Map<String, Object>>) ((Map<String, Object>) mResponse.getResultInfo()).get("envelopeIds");
Map<String, KkoTalkApiRespVO> mApiResp = documents.stream()
.map(this::toApiRespVOMap)
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (KkoTalkApiRespVO) m.get("value"), (k1, k2) -> k1));
list.stream()
.forEach(row -> this.modifyTalkSendRsltByExtDocUuid(row, mApiResp));
} catch (EnsException e) {
list.stream()
.forEach(row -> {
row.setStatus(KkoTalkStatusCd.SENT_FAIL);
row.setErrorCode(e.getErrCd().getCode());
row.setErrorMessage(e.getMessage());
});
} catch (Exception e) {
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), resp));
}
});
.forEach(list -> {
List<KkotalkApiDTO.Envelope> envelopes = null;
String sendRespBody = null;
try {
envelopes = this.makeMessage(list);
ResponseEntity<String> resp = kkoTalkApi.requestSendBulk2(
KkotalkDTO.BulkSendRequest.builder()
// FIXME: 카카오톡 신규 추가 - 테스트를 위해 임시로 넣음
.productCode("D10_2")
.envelopes(envelopes)
.signguCode(orgMng.getOrgCd())
.ffnlgCode("11")
.build()
);
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());
if (!EnsErrCd.OK.equals(mResponse.getErrCode()))
throw new EnsException(mResponse.getErrCode(), mResponse.getErrMsg());
List<Map<String, Object>> documents = (List<Map<String, Object>>)((Map<String, Object>)mResponse.getResultInfo()).get(
"envelopeIds");
Map<String, KkoTalkApiRespVO> mApiResp = documents.stream()
.map(this::toApiRespVOMap)
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")),
m -> (KkoTalkApiRespVO)m.get("value"), (k1, k2) -> k1));
list.stream()
.forEach(row -> this.modifyTalkSendRsltByExtDocUuid(row, mApiResp));
} catch (EnsException e) {
list.stream()
.forEach(row -> {
row.setStatus(KkoTalkStatusCd.SENT_FAIL);
row.setErrorCode(e.getErrCd().getCode());
row.setErrorMessage(e.getMessage());
});
} catch (Exception e) {
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()
.map(row -> CmmnUtil.isEmpty(row.getErrorCode()) ? 1 : 0)
.reduce(Integer::sum);
.map(row -> CmmnUtil.isEmpty(row.getErrorCode()) ? 1 : 0)
.reduce(Integer::sum);
if (cntSuccess.get() > 0)
respVO = EnsResponseVO.okBuilder()
.resultInfo(sendDetails.stream()
.map(row -> this.toResultInfo(row))
.collect(Collectors.toList()))
.build();
.resultInfo(sendDetails.stream()
.map(row -> this.toResultInfo(row))
.collect(Collectors.toList()))
.build();
else
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();
} catch (Exception e) {
} catch (Exception e) {
respVO = EnsResponseVO.errBuilder().errCode(EnsErrCd.SEND500).errMsg(e.getMessage()).build();
} finally {
if (!CmmnUtil.isEmpty(sendMast)) {
if (EnsErrCd.OK.equals(respVO.getErrCode())) {
@ -278,9 +295,7 @@ public class KkoTalkSender extends SendProcTemplate {
* @return
*/
private List<SendDetailKkoTalkReqHist> toSendDetailReqHist(List<KkotalkDTO.SendDetailKkoTalkDTO> list, String sendMsg, String respMsg) {
List<Map<String, Object>> sendMsgList = (List<Map<String, Object>>) gson.fromJson(sendMsg, Map.class).get("envelopes");
List<Map> sendMsgList = JsonUtils.toObjectList(sendMsg, Map.class);
Map<String, Long> mSendDetailIds = list.stream()
.map(row -> {
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));
EnsResponseVO respVO = this.respMsgToMap(respMsg);
EnsResponseVO<?> respVO = this.respMsgToMap(respMsg);
if (EnsErrCd.OK.equals(respVO.getErrCode())) {

Loading…
Cancel
Save