feat: master별 transaction 분리

dev
gitea-관리자 1 year ago
parent 53782b574d
commit 5d2d19e292

@ -1,8 +1,10 @@
package kr.xit.batch.ens.task;
import java.util.List;
import java.util.UUID;
import kr.xit.batch.ens.task.cmm.TaskCmmUtils;
import kr.xit.biz.ens.model.EnsDTO;
import kr.xit.biz.ens.model.cmm.SndngMssageParam;
import kr.xit.biz.ens.service.IEnsBatchSendService;
import kr.xit.core.spring.util.error.ErrorParse;
import lombok.RequiredArgsConstructor;
@ -38,39 +40,73 @@ public class SndngSendBulksTasklet implements Tasklet {
@JobScope
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
final String isSlackEnabled = contribution.getStepExecution().getJobParameters().getString("isSlackEnabled");
boolean isSuccess = false;
try {
MDC.put("request_trace_batch_id", UUID.randomUUID().toString().replace("-", ""));
//MDC.put("uri", "/v1/documents/bulk");
MDC.put("method", "POST");
service.sendBulks(
List<SndngMssageParam> tgtList = service.findBulks(
EnsDTO.BatchEnsRequest.builder()
.signguCode(contribution.getStepExecution().getJobParameters().getString("signguCode"))
.ffnlgCode(contribution.getStepExecution().getJobParameters().getString("ffnlgCode"))
.sndngProcessSttus(contribution.getStepExecution().getJobParameters().getString("sndngProcessSttus"))
.signguCode(
contribution.getStepExecution().getJobParameters().getString("signguCode"))
.ffnlgCode(
contribution.getStepExecution().getJobParameters().getString("ffnlgCode"))
.sndngProcessSttus(contribution.getStepExecution().getJobParameters()
.getString("sndngProcessSttus"))
.build()
);
}catch(Exception e){
String errMsg = ErrorParse.extractError(e).getMessage();
log.error("SndngSendBulksTasklet error :: {}", e.getMessage());
MDC.put("service_error_msg", errMsg);
TaskCmmUtils.taskBatchErrorLog(
contribution.getStepExecution().getJobExecution().getJobInstance().getJobName(),
errMsg,
isSlackEnabled
);
for(SndngMssageParam dto : tgtList) {
try {
dto.setSndngProcessSttus(contribution.getStepExecution().getJobParameters()
.getString("sndngProcessSttus"));
service.sendBulks(dto);
isSuccess = true;
} catch (Exception e) {
String errMsg = ErrorParse.extractError(e).getMessage();
log.error("SndngSendBulksTasklet error :: {}", e.getMessage());
MDC.put("service_error_msg", errMsg);
TaskCmmUtils.taskEnsBatchServiceUpdateErrorLog(
contribution.getStepExecution().getJobExecution().getJobInstance().getJobName(),
errMsg,
isSlackEnabled
);
contribution.setExitStatus(ExitStatus.FAILED);
TaskCmmUtils.taskBatchErrorLog(
contribution.getStepExecution().getJobExecution().getJobInstance()
.getJobName(),
errMsg,
isSlackEnabled
);
TaskCmmUtils.taskEnsBatchServiceUpdateErrorLog(
contribution.getStepExecution().getJobExecution().getJobInstance()
.getJobName(),
errMsg,
isSlackEnabled
);
}
}
// } catch (Exception e) {
// String errMsg = ErrorParse.extractError(e).getMessage();
// log.error("SndngSendBulksTasklet error :: {}", e.getMessage());
// MDC.put("service_error_msg", errMsg);
//
// TaskCmmUtils.taskBatchErrorLog(
// contribution.getStepExecution().getJobExecution().getJobInstance()
// .getJobName(),
// errMsg,
// isSlackEnabled
// );
//
// TaskCmmUtils.taskEnsBatchServiceUpdateErrorLog(
// contribution.getStepExecution().getJobExecution().getJobInstance()
// .getJobName(),
// errMsg,
// isSlackEnabled
// );
} finally {
if(!isSuccess) contribution.setExitStatus(ExitStatus.FAILED);
else contribution.setExitStatus(ExitStatus.COMPLETED);
return RepeatStatus.FINISHED;
}
contribution.setExitStatus(ExitStatus.COMPLETED);
return RepeatStatus.FINISHED;
}
}

@ -90,6 +90,49 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
private final ApiWebClientUtil apiWebClient;
private final IEnsBatchMapper mapper;
@Override
@Transactional(readOnly = true)
public List<SndngMssageParam> findBulks(final EnsDTO.BatchEnsRequest reqDTO) {
// 발송/통합발송 마스터에서 대상 조회
reqDTO.setBatchPeriod(batchSendPeriod);
return mapper.selectSendBulkTgts(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 -> sendBulkKakaoMyDocs(dto);
// case KT_BC -> sendBulkKtBc(dto);
// case PPLUS -> sendBulkPplus(dto);
// case E_GREEN -> extractService.sendEgreen(dto);
// case SMS -> extractService.sendSms(dto);
// default -> throw BizRuntimeException.create(String.format("정의 되지 않은 문서 중개자[%s] 입니다", seCode));
// }
// }
}
/**
* <pre>
* () send bulks - send
@ -110,14 +153,14 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void sendBulks(final EnsDTO.BatchEnsRequest reqDTO) {
public void sendBulks(final SndngMssageParam dto) {
// 발송/통합발송 마스터에서 대상 조회
reqDTO.setBatchPeriod(batchSendPeriod);
final List<SndngMssageParam> tgtList = mapper.selectSendBulkTgts(reqDTO);
for (SndngMssageParam dto : tgtList) {
dto.setSignguCode(reqDTO.getSignguCode());
dto.setFfnlgCode(reqDTO.getFfnlgCode());
//reqDTO.setBatchPeriod(batchSendPeriod);
//final List<SndngMssageParam> tgtList = mapper.selectSendBulkTgts(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());
@ -131,7 +174,7 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
};
// 마스터 상태 변경값을 파라메터에서 받은 상태값으로 set
dto.setNewSndngProcessSttus(reqDTO.getSndngProcessSttus());
dto.setNewSndngProcessSttus(dto.getSndngProcessSttus());
final String seCode = tryVal[dto.getTrySeq() - 1];
// 업무 문서 구분에 따른 분기
@ -148,7 +191,7 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
case SMS -> extractService.sendSms(dto);
default -> throw BizRuntimeException.create(String.format("정의 되지 않은 문서 중개자[%s] 입니다", seCode));
}
}
//}
}
//-----------------------------------------------------------------------------------------------------------------
@ -186,6 +229,7 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
// validation check
try {
if(true)throw BizRuntimeException.create("$$$$$$$$$$$#########");
validatedKkoMyDocSendBulks(bulkList);
} catch (Exception e) {
extractService.updateSndngMstFailStatus(mstId, SndngSeCode.KAKAO, "", e.getMessage(), "[send]카카오 문서 발송(bulks)요청 실패(파라메터 오류)");
@ -193,6 +237,7 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
}
final List<List<BulkSendReq>> partitions = ListUtils.partition(bulkList, bulkKkoMaxCnt);
//noinspection rawtypes
final List<ApiResponseDTO> apiResults = partitions.stream()
.map(bulkSendList -> apiWebClient.exchange(
url,
@ -210,6 +255,7 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
final List<BulkSendResponses> resList = new ArrayList<>();
boolean isSuccess = false;
String errMsg = null;
//noinspection rawtypes
for(ApiResponseDTO apiResult : apiResults) {
if(apiResult.getData() != null) {
resList.add(toObjByObj(apiResult.getData(), BulkSendResponses.class));

@ -1,6 +1,8 @@
package kr.xit.biz.ens.service;
import java.util.List;
import kr.xit.biz.ens.model.EnsDTO;
import kr.xit.biz.ens.model.cmm.SndngMssageParam;
/**
* <pre>
@ -18,5 +20,6 @@ import kr.xit.biz.ens.model.EnsDTO;
* </pre>
*/
public interface IEnsBatchSendService {
void sendBulks(final EnsDTO.BatchEnsRequest reqDTO);
List<SndngMssageParam> findBulks(final EnsDTO.BatchEnsRequest reqDTO);
void sendBulks(final SndngMssageParam dto);
}

@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import kr.xit.biz.ens.model.EnsDTO;
import kr.xit.biz.ens.model.cmm.SndngMssageParam;
import kr.xit.biz.ens.service.IEnsBatchAcceptService;
import kr.xit.biz.ens.service.IEnsBatchCloseService;
import kr.xit.biz.ens.service.IEnsBatchMakeService;
@ -117,7 +118,10 @@ public class EnsBatchController {
})
@PostMapping(value = "/sendBulks", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse sendBulks(@RequestBody final EnsDTO.BatchEnsRequest reqDTO){
sendService.sendBulks(reqDTO);
for(SndngMssageParam bulk : sendService.findBulks(reqDTO)) {
bulk.setSndngProcessSttus(reqDTO.getSndngProcessSttus());
sendService.sendBulks(bulk);
}
return ApiResponseDTO.success();
}

@ -581,6 +581,8 @@
, tesm.sndng_co
, tesm.try_seq
, tesm.sndng_process_sttus
, tesm.signgu_code
, tesm.ffnlg_code
, teusm.try1
, teusm.try2
, teusm.try3

Loading…
Cancel
Save