parent
05f9c76134
commit
182aea57bb
@ -0,0 +1,35 @@
|
||||
package kr.xit.biz.ens.cmm;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description :
|
||||
*
|
||||
* packageName : kr.xit.biz.ens.cmm
|
||||
* fileName : CmmEnsBizUtils
|
||||
* author : limju
|
||||
* date : 2023-10-31
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-10-31 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
public class CmmEnsBizUtils {
|
||||
|
||||
/**
|
||||
* API 서버 호출을 위한 헤더 set
|
||||
* @return Map<String,String>
|
||||
*/
|
||||
public static Map<String,String> getHeadeMap(){
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
//map.put(HttpHeaders.AUTHORIZATION, "");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,206 @@
|
||||
package kr.xit.biz.ens.service;
|
||||
|
||||
import static kr.xit.core.support.utils.JsonUtils.toObjByObj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import kr.xit.biz.common.ApiConstants;
|
||||
import kr.xit.biz.common.ApiConstants.SndngSeCode;
|
||||
import kr.xit.biz.ens.cmm.CmmEnsBizUtils;
|
||||
import kr.xit.biz.ens.mapper.IEnsBatchMapper;
|
||||
import kr.xit.biz.ens.model.EnsDTO;
|
||||
import kr.xit.biz.ens.model.EnsDTO.SndngMssageParam;
|
||||
import kr.xit.biz.ens.model.cntc.CntcDTO;
|
||||
import kr.xit.biz.ens.model.kakao.KkopayDocBulkDTO.BulkStatusRequests;
|
||||
import kr.xit.biz.ens.model.kakao.KkopayDocBulkDTO.BulkStatusResponses;
|
||||
import kr.xit.biz.ens.model.pplus.PplusDTO.PpStatusRequest;
|
||||
import kr.xit.biz.ens.model.pplus.PplusDTO.PpStatusResponse;
|
||||
import kr.xit.core.exception.BizRuntimeException;
|
||||
import kr.xit.core.model.ApiResponseDTO;
|
||||
import kr.xit.core.spring.util.ApiWebClientUtil;
|
||||
import kr.xit.core.support.utils.Checks;
|
||||
import kr.xit.core.support.utils.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description : 모바일 전자고지 배치 서비스
|
||||
* - 배치에서 호출되는 클래스로 배치 로그등 Transaction 분리 필요
|
||||
* - 메소드 트랜잭션 Transactional(propagation = Propagation.REQUIRES_NEW)로 선언
|
||||
* packageName : kr.xit.biz.ens.service
|
||||
* fileName : EnsBatchService
|
||||
* author : limju
|
||||
* date : 2023-08-31
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-08-31 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class EnsBatchStatusService extends EgovAbstractServiceImpl implements IEnsBatchStatusService {
|
||||
@Value("${contract.host}")
|
||||
private String apiHost;
|
||||
@Value("${contract.kakao.api.bulkstatus}")
|
||||
private String apiKkoBulkStatus;
|
||||
|
||||
@Value("${contract.pplus.api.bulkstatus}")
|
||||
private String apiPplusBulkStatus;
|
||||
|
||||
private final EnsBatchRequireNewService requireNewService;
|
||||
private final ApiWebClientUtil apiWebClient;
|
||||
private final IEnsBatchMapper mapper;
|
||||
|
||||
private static final Validator validator = Validation.buildDefaultValidatorFactory()
|
||||
.getValidator();
|
||||
|
||||
@Value("${contract.kakao.bulk-max-cnt}")
|
||||
private int bulkKkoMaxCnt;
|
||||
|
||||
private static final String SNDNG_PROCESS_STTUS = "sndngProcessSttus";
|
||||
private static final String UNITY_SNDNG_MST_ID = "unitySndngMastrId";
|
||||
private static final String YMDHMS = ApiConstants.FMT_DT_EMPTY_DLT;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 문서중개자 전송후 상태 조회
|
||||
*
|
||||
* @param reqDTO BatchEnsRequest
|
||||
* </pre>
|
||||
*/
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void statusBulks(final EnsDTO.BatchEnsRequest reqDTO) {
|
||||
final String url = apiHost + apiKkoBulkStatus;
|
||||
|
||||
final List<SndngMssageParam> tgtList = mapper.selectStatusBulkTgts(reqDTO);
|
||||
for (SndngMssageParam dto : tgtList) {
|
||||
dto.setSignguCode(reqDTO.getSignguCode());
|
||||
dto.setFfnlgCode(reqDTO.getFfnlgCode());
|
||||
dto.setProfile(ApiConstants.PROFILE);
|
||||
|
||||
MDC.put(UNITY_SNDNG_MST_ID, dto.getUnitySndngMastrId());
|
||||
MDC.put("sndngMastrId", dto.getSndngMastrId());
|
||||
//MDC.put(SNDNG_PROCESS_STTUS, "send-fail" + dto.getTrySeq());
|
||||
|
||||
final String[] tryVal = {
|
||||
Checks.checkVal(dto.getTry1(), ""),
|
||||
Checks.checkVal(dto.getTry2(), ""),
|
||||
Checks.checkVal(dto.getTry3(), "")
|
||||
};
|
||||
|
||||
// 마스터 상태 변경값을 파라메터에서 받은 상태값으로 set
|
||||
//dto.setNewSndngProcessSttus(reqDTO.getSndngProcessSttus());
|
||||
final String seCode = tryVal[dto.getTrySeq() - 1];
|
||||
|
||||
// 업무 문서 구분에 따른 분기
|
||||
switch (SndngSeCode.compare(seCode)) {
|
||||
/*
|
||||
* 카카오페이 연계 결과 반영 : tb_ens_kakao_my_doc
|
||||
* 모바일 페이지 생성 : tb_ens_mobile_page_manage
|
||||
* 연계발송결과 생성 : tb_cntc_sndng_result
|
||||
*/
|
||||
case KAKAO -> statusKakao(dto);
|
||||
case PPLUS -> statusBulkPplus(dto);
|
||||
case KT_BC, SMS, E_GREEN -> {
|
||||
return;
|
||||
}
|
||||
default -> throw BizRuntimeException.create(String.format("정의 되지 않은 문서 중개자[%s] 입니다", seCode));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------
|
||||
// status
|
||||
//-----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 문서중개자 전송후 상태 조회
|
||||
*
|
||||
* @param reqDTO BatchEnsRequest
|
||||
* </pre>
|
||||
*/
|
||||
private void statusKakao(final SndngMssageParam reqDTO) {
|
||||
final String url = apiHost + apiKkoBulkStatus;
|
||||
|
||||
final List<String> docsBinderUuids = mapper.selectKakaoStatusTgts(reqDTO);
|
||||
final List<List<String>> partitions = ListUtils.partition(docsBinderUuids, bulkKkoMaxCnt);
|
||||
|
||||
final List<ApiResponseDTO> apiResults = partitions.stream()
|
||||
.map(uuids -> apiWebClient.exchange(
|
||||
url,
|
||||
HttpMethod.POST,
|
||||
BulkStatusRequests.builder()
|
||||
.signguCode(reqDTO.getSignguCode())
|
||||
.ffnlgCode(reqDTO.getFfnlgCode())
|
||||
.document_binder_uuids(uuids)
|
||||
.build(),
|
||||
ApiResponseDTO.class,
|
||||
CmmEnsBizUtils.getHeadeMap())
|
||||
).toList();
|
||||
|
||||
final List<BulkStatusResponses> resList = new ArrayList<>();
|
||||
for(ApiResponseDTO apiResult : apiResults) {
|
||||
if(apiResult.getData() != null) {
|
||||
resList.add(toObjByObj(apiResult.getData(), BulkStatusResponses.class));
|
||||
}
|
||||
}
|
||||
|
||||
// 결과 반영
|
||||
resList.forEach(o ->
|
||||
o.getDocuments().forEach(t -> {
|
||||
mapper.updateKakaoStatusInfo(t);
|
||||
mapper.updateCntcSndngResultByKkoMyDoc(CntcDTO.SndngResult.builder()
|
||||
.documentBinderUuid(t.getDocument_binder_uuid())
|
||||
.sndngResultSttus(StringUtils.defaultString(String.valueOf(t.getStatus_data().getDoc_box_status()), "FAIL"))
|
||||
.requstDt(Checks.isEmpty(t.getStatus_data().getDoc_box_sent_at())? null: t.getStatus_data().getDoc_box_sent_at().toString())
|
||||
.inqireDt(Checks.isEmpty(t.getStatus_data().getDoc_box_received_at())? null: t.getStatus_data().getDoc_box_received_at().toString())
|
||||
.readngDt(Checks.isEmpty(t.getStatus_data().getDoc_box_read_at())? null: t.getStatus_data().getDoc_box_read_at().toString())
|
||||
.errorCn(t.getError_message())
|
||||
.build());
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 문서중개자 전송후 상태 조회
|
||||
*
|
||||
* @param reqDTO BatchEnsRequest
|
||||
* </pre>
|
||||
*/
|
||||
private void statusBulkPplus(final SndngMssageParam reqDTO) {
|
||||
final String url = apiHost + apiPplusBulkStatus;
|
||||
|
||||
ApiResponseDTO apiResult = apiWebClient.exchange(
|
||||
url,
|
||||
HttpMethod.POST,
|
||||
PpStatusRequest.builder()
|
||||
.signguCode(reqDTO.getSignguCode())
|
||||
.ffnlgCode(reqDTO.getFfnlgCode())
|
||||
.build(),
|
||||
ApiResponseDTO.class,
|
||||
CmmEnsBizUtils.getHeadeMap());
|
||||
|
||||
if(apiResult.getData() != null) {
|
||||
PpStatusResponse resDTO = JsonUtils.toObjByObj(apiResult.getData(), PpStatusResponse.class);
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package kr.xit.biz.ens.service;
|
||||
|
||||
import kr.xit.biz.ens.model.EnsDTO;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description : 모바일 전자고지 배치 서비스
|
||||
*
|
||||
* packageName : kr.xit.biz.ens.service
|
||||
* fileName : IEnsBatchService
|
||||
* author : limju
|
||||
* date : 2023-08-31
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-08-31 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
public interface IEnsBatchStatusService {
|
||||
void statusBulks(final EnsDTO.BatchEnsRequest reqDTO);
|
||||
}
|
||||
Loading…
Reference in New Issue