feat: master별 transaction 분리

dev
gitea-관리자 1 year ago
parent 5d2d19e292
commit 779f341d36

@ -1,7 +1,11 @@
package kr.xit.batch.ens.task;
import java.util.List;
import java.util.Map;
import kr.xit.batch.ens.task.cmm.TaskCmmUtils;
import kr.xit.biz.common.ApiConstants;
import kr.xit.biz.ens.model.EnsDTO;
import kr.xit.biz.ens.model.cmm.SndngMssageParam;
import kr.xit.biz.ens.service.IEnsBatchMakeService;
import kr.xit.core.spring.util.error.ErrorParse;
import lombok.RequiredArgsConstructor;
@ -37,15 +41,47 @@ public class SndngMakeTasklet implements Tasklet {
@JobScope
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
final String isSlackEnabled = contribution.getStepExecution().getJobParameters().getString("isSlackEnabled");
boolean isSuccess = false;
final String SNDNG_PROCESS_STTUS = "sndngProcessSttus";
final String UNITY_SNDNG_MST_ID = "unitySndngMastrId";
try {
service.make(
Map<String, List<SndngMssageParam>> tgtMap = service.findMakes(
EnsDTO.BatchEnsRequest.builder()
.signguCode(contribution.getStepExecution().getJobParameters().getString("signguCode"))
.ffnlgCode(contribution.getStepExecution().getJobParameters().getString("ffnlgCode"))
.sndngProcessSttus(contribution.getStepExecution().getJobParameters().getString("sndngProcessSttus"))
.build()
);
for(String key :tgtMap.keySet()){
List<SndngMssageParam> tgtList = tgtMap.get(key);
for(SndngMssageParam dto : tgtList) {
try{
dto.setProfile(ApiConstants.PROFILE);
if("tty1".equals(key)) {
MDC.put(UNITY_SNDNG_MST_ID, dto.getUnitySndngMastrId());
MDC.put(SNDNG_PROCESS_STTUS, "make-fail1");
dto.setProfile(ApiConstants.PROFILE);
dto.setSndngProcessSttus(contribution.getStepExecution().getJobParameters().getString("sndngProcessSttus"));
dto.setNewSndngProcessSttus(ApiConstants.SndngProcessStatus.MAKE_OK.getCode());
//FIXME: try1,try2,tr3이 있는 경우 try1 이전에 try2,3이 실행될 수 있는 경우???
dto.setTrySeq(1);
dto.setSndngCo(dto.getSndngCo());
dto.setSndngSeCode(dto.getTry1());
}
else if("tty2".equals(key)) {
if(!service.makeIsNext(dto)) continue;
}
service.make(dto);
isSuccess = true;
}catch(Exception e){
String errMsg = ErrorParse.extractError(e).getMessage();
log.error("SndngMakeTasklet error :: {}", e.getMessage());
@ -62,10 +98,14 @@ public class SndngMakeTasklet implements Tasklet {
errMsg,
isSlackEnabled
);
contribution.setExitStatus(ExitStatus.FAILED);
return RepeatStatus.FINISHED;
}
contribution.setExitStatus(ExitStatus.COMPLETED);
}
}
} finally {
if(!isSuccess) contribution.setExitStatus(ExitStatus.FAILED);
else contribution.setExitStatus(ExitStatus.COMPLETED);
return RepeatStatus.FINISHED;
}
}
}

@ -44,7 +44,6 @@ public class SndngSendBulksTasklet implements Tasklet {
try {
MDC.put("request_trace_batch_id", UUID.randomUUID().toString().replace("-", ""));
//MDC.put("uri", "/v1/documents/bulk");
MDC.put("method", "POST");
List<SndngMssageParam> tgtList = service.findBulks(
@ -84,24 +83,6 @@ public class SndngSendBulksTasklet implements Tasklet {
);
}
}
// } 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);

@ -1,6 +1,8 @@
package kr.xit.biz.ens.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kr.xit.biz.common.ApiConstants;
import kr.xit.biz.common.ApiConstants.SignguCode;
import kr.xit.biz.common.ApiConstants.SndngSeCode;
@ -48,63 +50,47 @@ public class EnsBatchMakeService extends EgovAbstractServiceImpl implements IEns
/**
* <pre>
* make() -
* - 'accept-ok', 'sending1', 'sending2'
* - 'sending1,2' 2,3(sndng_dt_2,3)
* - : , ( )
* , 'make-ok'
* - : , 'make-fail1,2,3'
*
* 1.
* - (accept-ok)
* - 1, 2 (sending1, sending2)
* -> {@link IEnsBatchMapper#selectMakeTgts selectMakeTgts}
* - tb_ens_unity_sndng_mastr
*
* 2. : {@link #makeMstStatusUpdate}
* 2-1. : tb_ens_sndng_mastr
* 2-2.
* 2-3. /
* - - make-ok
* 1 : try_seq - 1,
* - 릿 try1
* 2 : try_seq - 2
* - 릿 try2
* - 2 ({@link IEnsBatchMapper#selectSendOkTgts selectSendOkTgts})
* @param reqDTO BatchEnsRequest
* @param reqDTO
* @return Map<String, List<SndngMssageParam>> 'tty1', 'tty2', 'tty3' put
* </pre>
*/
/**
*
* @param reqDTO
* @return
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void make(final EnsDTO.BatchEnsRequest reqDTO) {
@Transactional(readOnly = true)
public Map<String, List<SndngMssageParam>> findMakes(final EnsDTO.BatchEnsRequest reqDTO) {
final Map<String, List<SndngMssageParam>> tgtMap = new HashMap<>();
final String sndngProcessSttus2 = ApiConstants.SndngProcessStatus.SENDING1.getCode();
final String sndngProcessSttus3 = ApiConstants.SndngProcessStatus.SENDING2.getCode();
final List<SndngMssageParam> list = mapper.selectMakeTgts(reqDTO);
final List<SndngMssageParam> list2 = mapper.selectMakeTgts(sndngProcessSttus2);
for (SndngMssageParam dto : list) {
MDC.put(UNITY_SNDNG_MST_ID, dto.getUnitySndngMastrId());
MDC.put(SNDNG_PROCESS_STTUS, "make-fail1");
dto.setSignguCode(reqDTO.getSignguCode());
dto.setFfnlgCode(reqDTO.getFfnlgCode());
dto.setProfile(ApiConstants.PROFILE);
dto.setSndngProcessSttus(reqDTO.getSndngProcessSttus());
dto.setNewSndngProcessSttus(ApiConstants.SndngProcessStatus.MAKE_OK.getCode());
//FIXME: try1,try2,tr3이 있는 경우 try1 이전에 try2,3이 실행될 수 있는 경우???
dto.setTrySeq(1);
dto.setSndngSeCode(dto.getTry1());
makeMstStatusUpdate(dto);
tgtMap.put("tty1", mapper.selectMakeTgts(reqDTO));
tgtMap.put("tty2", mapper.selectMakeTgts(sndngProcessSttus2));
//tgtMap.put("tty3", mapper.selectMakeTgts(sndngProcessSttus3));
return tgtMap;
}
for (SndngMssageParam dto : list2) {
/**
* <pre>
* 2 or 3
* , send-ok
* 2 or 3 true return
* @param dto SndngMssageParam
* @return boolean 2 or 3 true
* </pre>
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean makeIsNext(final SndngMssageParam dto) {
MDC.put(UNITY_SNDNG_MST_ID, dto.getUnitySndngMastrId());
MDC.put(SNDNG_PROCESS_STTUS, "make-fail2");
dto.setSignguCode(reqDTO.getSignguCode());
dto.setFfnlgCode(reqDTO.getFfnlgCode());
dto.setProfile(ApiConstants.PROFILE);
//try2 발송 대상이 있는지 확인
@ -120,28 +106,17 @@ public class EnsBatchMakeService extends EgovAbstractServiceImpl implements IEns
if (mapper.updateProcessSttusUnitySndngMst(dto) != 1) {
throw BizRuntimeException.create("[make]통합 발송 마스터 상태변경 실패");
}
} else {
return false;
}
//있으면 make
dto.setSndngProcessSttus(sndngProcessSttus2);
dto.setSndngProcessSttus(ApiConstants.SndngProcessStatus.SENDING1.getCode());
dto.setNewSndngProcessSttus(ApiConstants.SndngProcessStatus.MAKE_OK.getCode());
dto.setTrySeq(2);
dto.setSndngCo(sendCnt);
dto.setSndngSeCode(dto.getTry2());
makeMstStatusUpdate(dto);
}
}
//TODO:: GS 인증 시험에서 카카오, E-GREEN만 있어서 3단계는 필요 시 구현
return true;
}
//*************************************************************************
// private method
//*************************************************************************
//-----------------------------------------------------------------------------------------------------------------
// make
//-----------------------------------------------------------------------------------------------------------------
/**
* <pre>
* make
@ -159,7 +134,9 @@ public class EnsBatchMakeService extends EgovAbstractServiceImpl implements IEns
* @param dto SndngMssageParam
* </pre>
*/
private void makeMstStatusUpdate(SndngMssageParam dto) {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void make(SndngMssageParam dto) {
// 1. master
if (mapper.insertSndngMst(dto) != 1) {
throw BizRuntimeException.create("[make]데이타 생성(마스터) 실패");
@ -182,6 +159,14 @@ public class EnsBatchMakeService extends EgovAbstractServiceImpl implements IEns
}
}
//*************************************************************************
// private method
//*************************************************************************
//-----------------------------------------------------------------------------------------------------------------
// make
//-----------------------------------------------------------------------------------------------------------------
/**
* <pre>
* make :
@ -211,7 +196,10 @@ public class EnsBatchMakeService extends EgovAbstractServiceImpl implements IEns
final String seCode = tryVal[dto.getTrySeq() - 1];
return switch (SndngSeCode.compare(seCode)) {
case KAKAO -> mapper.insertKakaoMyDocs(dto);
case KAKAO -> {
if(true) throw BizRuntimeException.create("####make error#######");
yield mapper.insertKakaoMyDocs(dto);
}
case E_GREEN -> mapper.insertPostSndng(dto);
case SMS -> mapper.insertSmsSndng(dto);
case KT_BC -> {

@ -90,6 +90,11 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
private final ApiWebClientUtil apiWebClient;
private final IEnsBatchMapper mapper;
/**
*
* @param reqDTO BatchEnsRequest
* @return List<SndngMssageParam>
*/
@Override
@Transactional(readOnly = true)
public List<SndngMssageParam> findBulks(final EnsDTO.BatchEnsRequest reqDTO) {
@ -97,40 +102,6 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
// 발송/통합발송 마스터에서 대상 조회
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));
// }
// }
}
/**
@ -142,25 +113,17 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
* , , - 'send-ok'
* - : , , 'send-fail1,2,3'
*
* 1. : {@link IEnsBatchMapper#selectSendBulkTgts selectSendBulkTgts}
* 2. send
* 2-1.
* send
* -
* - : tb_ens_kakao_my_doc
* - : tb_ens_mobile_page_manage
* - : tb_cntc_sndng_result
* @param reqDTO BatchEnsRequest
* @param dto SndngMssageParam
* </pre>
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
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());
dto.setProfile(ApiConstants.PROFILE);
MDC.put(UNITY_SNDNG_MST_ID, dto.getUnitySndngMastrId());
@ -191,7 +154,6 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
case SMS -> extractService.sendSms(dto);
default -> throw BizRuntimeException.create(String.format("정의 되지 않은 문서 중개자[%s] 입니다", seCode));
}
//}
}
//-----------------------------------------------------------------------------------------------------------------
@ -229,7 +191,6 @@ 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)요청 실패(파라메터 오류)");

@ -1,6 +1,9 @@
package kr.xit.biz.ens.service;
import java.util.List;
import java.util.Map;
import kr.xit.biz.ens.model.EnsDTO;
import kr.xit.biz.ens.model.cmm.SndngMssageParam;
/**
* <pre>
@ -18,5 +21,7 @@ import kr.xit.biz.ens.model.EnsDTO;
* </pre>
*/
public interface IEnsBatchMakeService {
void make(final EnsDTO.BatchEnsRequest reqDTO);
Map<String, List<SndngMssageParam>> findMakes(final EnsDTO.BatchEnsRequest reqDTO);
boolean makeIsNext(final SndngMssageParam dto);
void make(SndngMssageParam dto);
}

@ -5,11 +5,8 @@ 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;
import kr.xit.biz.ens.service.IEnsBatchSendService;
import kr.xit.biz.ens.service.IEnsBatchStatusService;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.model.IApiResponse;
@ -35,14 +32,12 @@ import org.springframework.web.bind.annotation.RestController;
*
* </pre>
*/
@Tag(name = "EnsBatchController", description = "전자고지 통합발송 연계 서비스(배치) 테스트")
@Tag(name = "EnsBatchController", description = "전자고지 배치 테스트")
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/batch/ens/v1")
public class EnsBatchController {
private final IEnsBatchAcceptService acceptService;
private final IEnsBatchMakeService makeService;
private final IEnsBatchSendService sendService;
private final IEnsBatchStatusService statusService;
private final IEnsBatchCloseService closeService;
@ -65,25 +60,6 @@ public class EnsBatchController {
return ApiResponseDTO.success();
}
@Operation(summary = "통합문서 발송 데이타 생성", description = "통합문서 발송데이타 생성")
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(mediaType = "application/json", examples = {
@ExampleObject(value = """
{
"signguCode": "88328",
"ffnlgCode": "11",
"sndngProcessSttus": "accept-ok"
}
"""
)
})
})
@PostMapping(value = "/make", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse make(@RequestBody final EnsDTO.BatchEnsRequest reqDTO){
makeService.make(reqDTO);
return ApiResponseDTO.success();
}
@Operation(summary = "통합문서 발송 데이타 종료", description = "통합문서 발송 데이타 종료")
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(mediaType = "application/json", examples = {
@ -103,28 +79,6 @@ public class EnsBatchController {
return ApiResponseDTO.success();
}
@Operation(summary = "통합문서(bulk) 발송 요청", description = "통합문서 발송 요청")
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(mediaType = "application/json", examples = {
@ExampleObject(value = """
{
"signguCode": "88328",
"ffnlgCode": "11",
"sndngProcessSttus": "make-ok"
}
"""
)
})
})
@PostMapping(value = "/sendBulks", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse sendBulks(@RequestBody final EnsDTO.BatchEnsRequest reqDTO){
for(SndngMssageParam bulk : sendService.findBulks(reqDTO)) {
bulk.setSndngProcessSttus(reqDTO.getSndngProcessSttus());
sendService.sendBulks(bulk);
}
return ApiResponseDTO.success();
}
@Operation(summary = "통합문서(bulk) 상태 조회", description = "통합문서 상태 조회")
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(mediaType = "application/json", examples = {

@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.RestController;
*
* </pre>
*/
@Tag(name = " EnsCctvFileController", description = "전자고지 CCTV 파일 연계 서비스")
@Tag(name = " EnsCctvFileController", description = "전자고지 CCTV 파일 연계 테스트")
@RequiredArgsConstructor
@RestController
@RequestMapping("/batch/ens/v1")

@ -148,6 +148,8 @@
, try3
, try_cnt
, sndng_process_sttus
, signgu_code
, ffnlg_code
FROM tb_ens_unity_sndng_mastr
WHERE sndng_process_sttus = #{sndngProcessSttus}
AND signgu_code = #{signguCode}

Loading…
Cancel
Save