|
|
@ -7,8 +7,6 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
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.EnsException;
|
|
|
|
import cokr.xit.ens.core.exception.code.EnsErrCd;
|
|
|
|
import cokr.xit.ens.core.exception.code.EnsErrCd;
|
|
|
|
import cokr.xit.ens.core.utils.CmmnUtil;
|
|
|
|
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.core.utils.MapDeserailizer;
|
|
|
|
import cokr.xit.ens.modules.common.biztmplt.ResultProcTemplate;
|
|
|
|
import cokr.xit.ens.modules.common.biztmplt.ResultProcTemplate;
|
|
|
|
import cokr.xit.ens.modules.common.code.StatCd;
|
|
|
|
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.SendDetailKkoMydocRepository;
|
|
|
|
import cokr.xit.ens.modules.kkomydoc.domain.repository.SendDetailKkoMydocStatHistRepository;
|
|
|
|
import cokr.xit.ens.modules.kkomydoc.domain.repository.SendDetailKkoMydocStatHistRepository;
|
|
|
|
import cokr.xit.ens.modules.kkomydoc.model.KkoMydocApiRespVO;
|
|
|
|
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.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
|
@ -51,19 +49,21 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
|
|
|
|
|
|
|
|
|
|
|
|
private final SendMastRepository sendMastRepository;
|
|
|
|
private final SendMastRepository sendMastRepository;
|
|
|
|
private final SendDetailKkoMydocRepository sendDetailKkoMydocRepository;
|
|
|
|
private final SendDetailKkoMydocRepository sendDetailKkoMydocRepository;
|
|
|
|
|
|
|
|
private final IKkoTalkMapper talkMapper;
|
|
|
|
private final SendDetailKkoMydocStatHistRepository sendDetailKkoMydocStatHistRepository;
|
|
|
|
private final SendDetailKkoMydocStatHistRepository sendDetailKkoMydocStatHistRepository;
|
|
|
|
private final OrgMngService orgMngService;
|
|
|
|
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}")
|
|
|
|
@Value("${contract.kakao.pay.mydoc.api.bulksend-batch-unit}")
|
|
|
|
private int SEND_BATCH_UNIT;
|
|
|
|
private int SEND_BATCH_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
@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<SendDetailKkoMydoc> sendDetails = null;
|
|
|
|
List<KkotalkDTO.SendDetailKkoTalkDTO> sendDetails = null;
|
|
|
|
EnsResponseVO respVO = null;
|
|
|
|
EnsResponseVO respVO = null;
|
|
|
|
Map<String, Long> resultInfo = new HashMap<>();
|
|
|
|
Map<String, Long> resultInfo = new HashMap<>();
|
|
|
|
resultInfo.put("sendMastId", sendMastId);
|
|
|
|
resultInfo.put("sendMastId", sendMastId);
|
|
|
@ -72,7 +72,8 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
|
|
|
|
throw new EnsException(EnsErrCd.RSLT410, "발송마스터ID(은)는 필수조건 입니다.");
|
|
|
|
throw new EnsException(EnsErrCd.RSLT410, "발송마스터ID(은)는 필수조건 입니다.");
|
|
|
|
|
|
|
|
|
|
|
|
sendMast = sendMastRepository.findById(sendMastId).orElseThrow(() -> new EnsException(EnsErrCd.RSLT404, String.format("일치하는 발송마스터 자료가 없습니다. [ sendMastId %s ]", sendMastId)));
|
|
|
|
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();
|
|
|
|
OrgMng orgMng = orgMngService.find(sendMast.getOrgCd()).getResultInfo();
|
|
|
|
|
|
|
|
|
|
|
|
Lists.partition(sendDetails, SEND_BATCH_UNIT).stream()
|
|
|
|
Lists.partition(sendDetails, SEND_BATCH_UNIT).stream()
|
|
|
@ -81,14 +82,41 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
|
|
|
|
String sendRespBody = null;
|
|
|
|
String sendRespBody = null;
|
|
|
|
String jsonStr = null;
|
|
|
|
String jsonStr = null;
|
|
|
|
try {
|
|
|
|
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);
|
|
|
|
EnsResponseVO message = this.makeMessage(list);
|
|
|
|
if (!(EnsErrCd.OK.equals(message.getErrCode()) || null == message.getErrCode()))
|
|
|
|
if (!(EnsErrCd.OK.equals(message.getErrCode()) || null == message.getErrCode()))
|
|
|
|
throw new EnsException(message.getErrCode(), message.getErrMsg());
|
|
|
|
throw new EnsException(message.getErrCode(), message.getErrMsg());
|
|
|
|
jsonStr = String.valueOf(message.getResultInfo());
|
|
|
|
jsonStr = String.valueOf(message.getResultInfo());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResponseEntity<String> resp = kkoMydocApi.bulkStatus(orgMng.getKkoMdAccessToken(), orgMng.getKkoMdContractUuid(), jsonStr);
|
|
|
|
ResponseEntity<String> resp = kkoMydocApi.bulkStatus(orgMng.getKkoMdAccessToken(), orgMng.getKkoMdContractUuid(), jsonStr);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
@ -134,9 +162,11 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
|
|
|
|
.errorMessage(e.getMessage())
|
|
|
|
.errorMessage(e.getMessage())
|
|
|
|
.build())
|
|
|
|
.build())
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (!CmmnUtil.isEmpty(jsonStr))
|
|
|
|
// if (!CmmnUtil.isEmpty(jsonStr))
|
|
|
|
sendDetailKkoMydocStatHistRepository.saveAll(this.toSendDetailStatHist(list, sendRespBody));
|
|
|
|
// sendDetailKkoMydocStatHistRepository.saveAll(this.toSendDetailStatHist(list, sendRespBody));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -154,9 +184,9 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
|
|
|
|
if (EnsErrCd.OK.equals(respVO.getErrCode())) {
|
|
|
|
if (EnsErrCd.OK.equals(respVO.getErrCode())) {
|
|
|
|
sendMast.setError(FieldError.initBuilder().build());
|
|
|
|
sendMast.setError(FieldError.initBuilder().build());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: 카카오톡 코드 반영 필요
|
|
|
|
Integer readCnt = sendDetails.stream()
|
|
|
|
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)
|
|
|
|
.reduce(Integer::sum)
|
|
|
|
.orElseGet(() -> 0);
|
|
|
|
.orElseGet(() -> 0);
|
|
|
|
sendMast.setReadCnt(readCnt);
|
|
|
|
sendMast.setReadCnt(readCnt);
|
|
|
@ -192,37 +222,11 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate {
|
|
|
|
* @param list
|
|
|
|
* @param list
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private EnsResponseVO makeMessage(List<SendDetailKkoMydoc> list) {
|
|
|
|
private List<String> makeMessage(List<KkotalkDTO.SendDetailKkoTalkDTO> list) {
|
|
|
|
String result = null;
|
|
|
|
|
|
|
|
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
|
|
|
|
|
|
|
EnsResponseVO resp = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> documentBinderUuids = list.stream()
|
|
|
|
return list.stream()
|
|
|
|
.map(row -> row.getDocumentBinderUuid())
|
|
|
|
.map(KkotalkDTO.SendDetailKkoTalkDTO::getEnvelopeId)
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.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)
|
|
|
|
* 문서상태조회결과 갱신(update)
|
|
|
|
* -. 성공/실패 여부에 따라 상태정보 및 Error 필드 갱신
|
|
|
|
* -. 성공/실패 여부에 따라 상태정보 및 Error 필드 갱신
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param row
|
|
|
|
|
|
|
|
* @param mMydocApiRespVOByDocumentBinderUuid
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void modifyStatInfoByDocumentBinderUuid(SendDetailKkoMydoc row, Map<String, KkoMydocApiRespVO> mMydocApiRespVOByDocumentBinderUuid) {
|
|
|
|
private void modifyStatInfoByDocumentBinderUuid(KkotalkDTO.SendDetailKkoTalkDTO row, List<KkotalkDTO.BulkStatusResponse> resList) {
|
|
|
|
KkoMydocApiRespVO apiRespVO = mMydocApiRespVOByDocumentBinderUuid.get(row.getDocumentBinderUuid());
|
|
|
|
/*
|
|
|
|
if (CmmnUtil.isEmpty(apiRespVO.getError_code())) {
|
|
|
|
List<KkotalkApiDTO.EnvelopeStatusResponse> resList = response.getEnvelopeStatus();
|
|
|
|
|
|
|
|
if (CmmnUtil.isEmpty(envelopeStatus..getError_code())) {
|
|
|
|
Map<String, Object> statusData = (Map<String, Object>) apiRespVO.getData();
|
|
|
|
Map<String, Object> statusData = (Map<String, Object>) apiRespVO.getData();
|
|
|
|
|
|
|
|
|
|
|
|
String docBoxStatus = statusData.containsKey("doc_box_status") ? (String) statusData.get("doc_box_status") : null;
|
|
|
|
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()))
|
|
|
|
.errorMessage(String.format("%s %s", apiRespVO.getError_code(), apiRespVO.getError_message()))
|
|
|
|
.build());
|
|
|
|
.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|