feat: 카카오톡 반영

main
Jonguk. Lim 2 months ago
parent 38fa24fb04
commit 9196e6f3c4

@ -5,6 +5,8 @@ import java.util.Optional;
import org.apache.ibatis.annotations.Mapper;
import cokr.xit.ens.modules.common.domain.SendMast;
import cokr.xit.ens.modules.kkomydoc.domain.SendDetailKkoMydoc;
import cokr.xit.ens.modules.kkotalk.model.KkotalkDTO;
/**
@ -31,4 +33,8 @@ public interface IKkoTalkMapper {
List<KkotalkDTO.SendDetailKkoTalkDTO> findAllFetchBySendMastId(Long sendMastId);
Optional<KkotalkDTO.SendDetailKkoTalkDTO> findFetchByExternalIdAndEnvelopeId(String externalId, String envelopeId);
List<KkotalkDTO.SendDetailKkoTalkDTO> findAllBySendMastAndEnvlopeIdIsNotNull(SendMast sendMast);
Optional<SendDetailKkoMydoc> findByExternalId(String externalId);
}

@ -0,0 +1,20 @@
package cokr.xit.ens.modules.kkotalk.model;
import java.util.List;
import cokr.xit.ens.core.model.EnsRsltRespDTO;
import cokr.xit.ens.modules.kkomydoc.model.config.KkoMydocStat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.SuperBuilder;
@SuperBuilder
@Data
@Schema(name = "KkoTalkRsltRespDTO")
public class KkoTalkRsltRespDTO extends EnsRsltRespDTO {
@Schema(required = true, title = "발송마스터ID", example = " ")
private Long sendMastId;
@Schema(required = false, title = "발송요청문서", example = " ")
private List<KkoMydocStat> documents;
}

@ -129,7 +129,9 @@ public class KkotalkDTO extends KkotalkApiDTO {
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public static class SendDetailKkoTalkDTO extends Envelope {
private String envelopeId;
private String link;
private String status;
private Long sendDetailId;
private Long sendMastId;
private String errorCode;

@ -7,8 +7,6 @@ import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@ -21,7 +19,6 @@ import cokr.xit.ens.core.aop.EnsResponseVO;
import cokr.xit.ens.core.exception.EnsException;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import cokr.xit.ens.core.utils.CmmnUtil;
import cokr.xit.ens.core.utils.DateUtil;
import cokr.xit.ens.core.utils.MapDeserailizer;
import cokr.xit.ens.modules.common.biztmplt.ResultProcTemplate;
import cokr.xit.ens.modules.common.code.StatCd;
@ -37,7 +34,8 @@ import cokr.xit.ens.modules.kkomydoc.domain.SendDetailKkoMydocStatHist;
import cokr.xit.ens.modules.kkomydoc.domain.repository.SendDetailKkoMydocRepository;
import cokr.xit.ens.modules.kkomydoc.domain.repository.SendDetailKkoMydocStatHistRepository;
import cokr.xit.ens.modules.kkomydoc.model.KkoMydocApiRespVO;
import cokr.xit.ens.modules.kkomydoc.service.support.KkoMydocApiSpec;
import cokr.xit.ens.modules.kkotalk.mapper.IKkoTalkMapper;
import cokr.xit.ens.modules.kkotalk.model.KkotalkDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -51,19 +49,21 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
private final SendMastRepository sendMastRepository;
private final SendDetailKkoMydocRepository sendDetailKkoMydocRepository;
private final IKkoTalkMapper talkMapper;
private final SendDetailKkoMydocStatHistRepository sendDetailKkoMydocStatHistRepository;
private final OrgMngService orgMngService;
private final KkoMydocApiSpec kkoMydocApi;
private final IKkoTalkApiService kkoTalkApi;
//private final KkoMydocApiSpec kkoMydocApi;
@Value("${contract.kakao.pay.mydoc.api.bulksend-batch-unit}")
private int SEND_BATCH_UNIT;
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public EnsResponseVO execute(Long sendMastId) {
public EnsResponseVO<?> execute(Long sendMastId) {
SendMast sendMast = null;
List<SendDetailKkoMydoc> sendDetails = null;
List<KkotalkDTO.SendDetailKkoTalkDTO> sendDetails = null;
EnsResponseVO respVO = null;
Map<String, Long> resultInfo = new HashMap<>();
resultInfo.put("sendMastId", sendMastId);
@ -72,7 +72,8 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
throw new EnsException(EnsErrCd.RSLT410, "발송마스터ID(은)는 필수조건 입니다.");
sendMast = sendMastRepository.findById(sendMastId).orElseThrow(() -> new EnsException(EnsErrCd.RSLT404, String.format("일치하는 발송마스터 자료가 없습니다. [ sendMastId %s ]", sendMastId)));
sendDetails = sendDetailKkoMydocRepository.findAllBySendMastAndDocumentBinderUuidIsNotNull(sendMast);
sendDetails = talkMapper.findAllBySendMastAndEnvlopeIdIsNotNull(sendMast);
//sendDetails = sendDetailKkoMydocRepository.findAllBySendMastAndDocumentBinderUuidIsNotNull(sendMast);
OrgMng orgMng = orgMngService.find(sendMast.getOrgCd()).getResultInfo();
Lists.partition(sendDetails, SEND_BATCH_UNIT).stream()
@ -81,14 +82,41 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
String sendRespBody = null;
String jsonStr = null;
try {
List<String> envelopeIds = this.makeMessage(list);
KkotalkDTO.BulkStatusResponse resp = kkoTalkApi.findBulkStatus(
KkotalkDTO.BulkStatusRequest.builder()
.envelopes(envelopeIds)
.signguCode(orgMng.getOrgCd())
.ffnlgCode("11")
.build()
);
resp.getEnvelopeStatus().forEach(t -> {}
);
/*
list.stream().forEach(row ->
this.modifyStatInfoByDocumentBinderUuid(row, resp.getEnvelopeStatus())
);
List<Map<String, Object>> documents = (List<Map<String, Object>>) ((Map<String, Object>) mResponse.getResultInfo()).get("documents");
Map<String, KkoMydocApiRespVO> mApiRespVOByDocumentBinderUuid = documents.stream()
.map(row -> this.toApiRespVOMap(row))
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (KkoMydocApiRespVO) m.get("value"), (k1, k2) -> k1));
list.stream().forEach(row -> this.modifyStatInfoByDocumentBinderUuid(row, mApiRespVOByDocumentBinderUuid));
*/
/*
EnsResponseVO message = this.makeMessage(list);
if (!(EnsErrCd.OK.equals(message.getErrCode()) || null == message.getErrCode()))
throw new EnsException(message.getErrCode(), message.getErrMsg());
jsonStr = String.valueOf(message.getResultInfo());
ResponseEntity<String> resp = kkoMydocApi.bulkStatus(orgMng.getKkoMdAccessToken(), orgMng.getKkoMdContractUuid(), jsonStr);
if (log.isDebugEnabled()) {
StringBuffer sb = new StringBuffer();
@ -134,9 +162,11 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
.errorMessage(e.getMessage())
.build())
);
*/
} finally {
if (!CmmnUtil.isEmpty(jsonStr))
sendDetailKkoMydocStatHistRepository.saveAll(this.toSendDetailStatHist(list, sendRespBody));
// if (!CmmnUtil.isEmpty(jsonStr))
// sendDetailKkoMydocStatHistRepository.saveAll(this.toSendDetailStatHist(list, sendRespBody));
}
});
@ -154,9 +184,9 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
if (EnsErrCd.OK.equals(respVO.getErrCode())) {
sendMast.setError(FieldError.initBuilder().build());
// FIXME: 카카오톡 코드 반영 필요
Integer readCnt = sendDetails.stream()
.map(row -> KkoMydocStatusCd.READ.equals(row.getKkoDocStat()) ? 1 : 0)
.map(row -> KkoMydocStatusCd.READ.equals(row.getStatus()) ? 1 : 0)
.reduce(Integer::sum)
.orElseGet(() -> 0);
sendMast.setReadCnt(readCnt);
@ -192,37 +222,11 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
* @param list
* @return
*/
private EnsResponseVO makeMessage(List<SendDetailKkoMydoc> list) {
String result = null;
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
EnsResponseVO resp = null;
try {
private List<String> makeMessage(List<KkotalkDTO.SendDetailKkoTalkDTO> list) {
List<String> documentBinderUuids = list.stream()
.map(row -> row.getDocumentBinderUuid())
return list.stream()
.map(KkotalkDTO.SendDetailKkoTalkDTO::getEnvelopeId)
.collect(Collectors.toList());
Map<String, Object> mJson = new HashMap<>();
mJson.put("document_binder_uuids", documentBinderUuids);
result = gson.toJson(mJson);
resp = EnsResponseVO.okBuilder()
.resultInfo(result)
.build();
} catch (EnsException e) {
resp = EnsResponseVO.errBuilder()
.errCode(e.getErrCd())
.errMsg(e.getMessage())
.build();
} catch (Exception e) {
resp = EnsResponseVO.errBuilder()
.errCode(EnsErrCd.RSLT502)
.errMsg(String.format("요청 메시지 생성 중 오류 발생. %s", e.getMessage()))
.build();
}
return resp;
}
@ -250,12 +254,11 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
* (update)
* -. / Error
*
* @param row
* @param mMydocApiRespVOByDocumentBinderUuid
*/
private void modifyStatInfoByDocumentBinderUuid(SendDetailKkoMydoc row, Map<String, KkoMydocApiRespVO> mMydocApiRespVOByDocumentBinderUuid) {
KkoMydocApiRespVO apiRespVO = mMydocApiRespVOByDocumentBinderUuid.get(row.getDocumentBinderUuid());
if (CmmnUtil.isEmpty(apiRespVO.getError_code())) {
private void modifyStatInfoByDocumentBinderUuid(KkotalkDTO.SendDetailKkoTalkDTO row, List<KkotalkDTO.BulkStatusResponse> resList) {
/*
List<KkotalkApiDTO.EnvelopeStatusResponse> resList = response.getEnvelopeStatus();
if (CmmnUtil.isEmpty(envelopeStatus..getError_code())) {
Map<String, Object> statusData = (Map<String, Object>) apiRespVO.getData();
String docBoxStatus = statusData.containsKey("doc_box_status") ? (String) statusData.get("doc_box_status") : null;
@ -284,6 +287,8 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
.errorMessage(String.format("%s %s", apiRespVO.getError_code(), apiRespVO.getError_message()))
.build());
}
*/
}
/**

@ -16,10 +16,11 @@ import cokr.xit.ens.modules.common.biztmplt.EnsPhaseProcSupport;
import cokr.xit.ens.modules.common.code.StatCd;
import cokr.xit.ens.modules.common.domain.SendMast;
import cokr.xit.ens.modules.common.domain.repository.SendMastRepository;
import cokr.xit.ens.modules.kkomydoc.domain.SendDetailKkoMydoc;
import cokr.xit.ens.modules.kkomydoc.domain.repository.SendDetailKkoMydocRepository;
import cokr.xit.ens.modules.kkomydoc.model.KkoMydocRsltRespDTO;
import cokr.xit.ens.modules.kkomydoc.model.config.KkoMydocStat;
import cokr.xit.ens.modules.kkotalk.mapper.IKkoTalkMapper;
import cokr.xit.ens.modules.kkotalk.model.KkoTalkRsltRespDTO;
import cokr.xit.ens.modules.kkotalk.model.KkotalkDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -30,7 +31,8 @@ import lombok.extern.slf4j.Slf4j;
public class KkoTalkRsltProvider implements EnsPhaseProcSupport<EnsResponseVO, Long> {
private final SendMastRepository sendMastRepository;
private final SendDetailKkoMydocRepository sendDetailKkoMydocRepository;
private final IKkoTalkMapper talkMapper;
//private final SendDetailKkoMydocRepository sendDetailKkoMydocRepository;
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
@ -52,10 +54,11 @@ public class KkoTalkRsltProvider implements EnsPhaseProcSupport<EnsResponseVO, L
try {
SendMast sendMast = sendMastRepository.findById(sendMastId)
.orElseThrow(() -> new EnsException(EnsErrCd.PRVD404, String.format("일치하는 발송마스터 자료가 없습니다. [ sendMastId %s ]", sendMastId)));
List<SendDetailKkoMydoc> sendDetailKkoMydocs = sendDetailKkoMydocRepository.findAllBySendMast(sendMast);
List<KkotalkDTO.SendDetailKkoTalkDTO> sendDetailKkoTalks = talkMapper.findAllBySendMastId(sendMast.getSendMastId());
KkoMydocRsltRespDTO respDTO = KkoMydocRsltRespDTO.builder()
// FIXME: 카카오톡 적용 필요
KkoTalkRsltRespDTO respDTO = KkoTalkRsltRespDTO.builder()
.sendMastId(sendMast.getSendMastId())
.statCd(sendMast.getStatCd())
.orgCd(sendMast.getOrgCd())
@ -64,20 +67,20 @@ public class KkoTalkRsltProvider implements EnsPhaseProcSupport<EnsResponseVO, L
.sendDt(sendMast.getSendDt().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))
.closeDt(sendMast.getCloseDt().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))
.closeAt(this.getCloseAt(sendMast))
.documents(sendDetailKkoMydocs.stream()
.documents(sendDetailKkoTalks.stream()
.map(row -> KkoMydocStat.builder()
.sendDetailId(row.getSendDetailId())
.externalDocumentUuid(row.getPropExternalDocumentUuid())
.documentBinderUuid(row.getDocumentBinderUuid())
.kkoDocStat(row.getKkoDocStat())
.kkoDocSentDt(row.getKkoDocSentDt())
.kkoDocReceivedDt(row.getKkoDocReceivedDt())
.kkoDocAuthFrstDt(row.getKkoDocAuthFrstDt())
.kkoDocTokenVrfyFrstDt(row.getKkoDocTokenVrfyFrstDt())
.kkoDocReadFrstDt(row.getKkoDocReadFrstDt())
.kkoDocUserNotiedDt(row.getKkoDocUserNotiedDt())
.errorCode(CmmnUtil.isEmpty(row.getError()) ? null : row.getError().getErrorCode())
.errorMessage(CmmnUtil.isEmpty(row.getError()) ? null : row.getError().getErrorMessage())
// .externalDocumentUuid(row.getPropExternalDocumentUuid())
// .documentBinderUuid(row.getDocumentBinderUuid())
// .kkoDocStat(row.getKkoDocStat())
// .kkoDocSentDt(row.getKkoDocSentDt())
// .kkoDocReceivedDt(row.getKkoDocReceivedDt())
// .kkoDocAuthFrstDt(row.getKkoDocAuthFrstDt())
// .kkoDocTokenVrfyFrstDt(row.getKkoDocTokenVrfyFrstDt())
// .kkoDocReadFrstDt(row.getKkoDocReadFrstDt())
// .kkoDocUserNotiedDt(row.getKkoDocUserNotiedDt())
.errorCode(CmmnUtil.isEmpty(row.getErrorCode()) ? null : row.getErrorCode())
.errorMessage(CmmnUtil.isEmpty(row.getErrorMessage()) ? null : row.getErrorMessage())
.build())
.collect(Collectors.toList()))
.build();

@ -37,10 +37,8 @@ import cokr.xit.ens.modules.common.monitor.MessageByPhase;
import cokr.xit.ens.modules.kkomydoc.code.KkoMydocStatusCd;
import cokr.xit.ens.modules.kkomydoc.domain.SendDetailKkoMydoc;
import cokr.xit.ens.modules.kkomydoc.domain.SendDetailKkoMydocReqHist;
import cokr.xit.ens.modules.kkomydoc.domain.repository.SendDetailKkoMydocRepository;
import cokr.xit.ens.modules.kkomydoc.domain.repository.SendDetailKkoMydocReqHistRepository;
import cokr.xit.ens.modules.kkomydoc.model.KkoMydocApiRespVO;
import cokr.xit.ens.modules.kkomydoc.service.support.KkoMydocApiSpec;
import cokr.xit.ens.modules.kkotalk.mapper.IKkoTalkMapper;
import cokr.xit.ens.modules.kkotalk.model.KkotalkApiDTO;
import cokr.xit.ens.modules.kkotalk.model.KkotalkDTO;
@ -55,11 +53,11 @@ public class KkoTalkSender extends SendProcTemplate {
private final ApplicationEventPublisher applicationEventPublisher;
private final SendMastRepository sendMastRepository;
private final SendDetailKkoMydocRepository sendDetailKkoMydocRepository;
//private final SendDetailKkoMydocRepository sendDetailKkoMydocRepository;
private final IKkoTalkMapper talkMapper;
private final SendDetailKkoMydocReqHistRepository sendDetailKkoMydocReqHistRepository;
private final OrgMngService orgMngService;
private final KkoMydocApiSpec kkoMydocApi;
//private final KkoMydocApiSpec kkoMydocApi;
private final IKkoTalkApiService kkoTalkApi;
@Value("${contract.kakao.pay.mydoc.api.bulksend-batch-unit}")
private int SEND_BATCH_UNIT;

Loading…
Cancel
Save