feat: 하나의 엑셀에 unitySndngMastrId 여러개일 경우 동일한 unitySndngMastrId Row만 처리하도록 수정

dev
sjh88 12 months ago
parent cf5d85f35d
commit 921e0bd1bf

@ -11,6 +11,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.Validation; import javax.validation.Validation;
import javax.validation.Validator; import javax.validation.Validator;
@ -81,6 +82,7 @@ public class BizSisulService extends AbstractService implements IBizSisulService
@Transactional @Transactional
@Override @Override
public String fmcExcelUpload(FmcExcelUpload fileReq) { public String fmcExcelUpload(FmcExcelUpload fileReq) {
String rtnMsg = "";
final Set<ConstraintViolation<FmcExcelUpload>> errors = validator.validate(fileReq); final Set<ConstraintViolation<FmcExcelUpload>> errors = validator.validate(fileReq);
if (!errors.isEmpty()) { if (!errors.isEmpty()) {
throw BizRuntimeException.create(errors.stream() throw BizRuntimeException.create(errors.stream()
@ -92,27 +94,64 @@ public class BizSisulService extends AbstractService implements IBizSisulService
final List<FmcInfExcel> fmcExcels = parsingFmcExcel(fileReq.getFiles()[0]); final List<FmcInfExcel> fmcExcels = parsingFmcExcel(fileReq.getFiles()[0]);
checkValidated(fmcExcels); checkValidated(fmcExcels);
final TmplatManage tmpDTO = mapper.selectDeptInfoByTmplId( //23.11.22 jhseo: 하나의 엑셀에 unitySndngMastrId 여러개일 경우 동일한 unitySndngMastrId Row만 처리
fmcExcels.get(0).getTmplatId()) List<String> unitySndngMastrIds = fmcExcels.stream().map(FmcInfExcel::getUnitySndngMastrId).collect(Collectors.toList());
.orElseThrow(() -> BizRuntimeException.create("템플릿 정보를 찾을 수 없습니다.")); for (String unitySndngMastrId : unitySndngMastrIds){
String tmplatId = "";
int excelCnt = 0;
for(FmcInfExcel dto : fmcExcels){
if(unitySndngMastrId.equals(dto.getUnitySndngMastrId())){
excelCnt++;
if("".equals(tmplatId)) tmplatId = dto.getTmplatId();
}
}
// Ci 변환 final TmplatManage tmpDTO = mapper.selectDeptInfoByTmplId(tmplatId)
fileReq.setSignguCode(tmpDTO.getSignguCode()); .orElseThrow(() -> BizRuntimeException.create("템플릿 정보를 찾을 수 없습니다."));
fileReq.setFfnlgCode(tmpDTO.getFfnlgCode());
fileReq.setTry1(tmpDTO.getTry1());
fileReq.setPostDlvrSe(tmpDTO.getPostDlvrSe());
fileReq.setPostTmplatCode(tmpDTO.getPostTmplatCode());
List<FmcInfExcelRslt> ciRslts = null; // Ci 변환
if(Pattern.matches("([\\w]{4}[1-2])", fmcExcels.get(0).getTmplatId())) { fileReq.setSignguCode(tmpDTO.getSignguCode());
ciRslts = getConvertCis(fileReq, fmcExcels); fileReq.setFfnlgCode(tmpDTO.getFfnlgCode());
} fileReq.setTry1(tmpDTO.getTry1());
fileReq.setPostDlvrSe(tmpDTO.getPostDlvrSe());
fileReq.setPostTmplatCode(tmpDTO.getPostTmplatCode());
// CNTC 테이블 insert List<FmcInfExcelRslt> ciRslts = null;
final String rtnMsg = makeCntc(ciRslts, fmcExcels, fileReq); if(Pattern.matches("([\\w]{4}[1-2])", tmplatId)) {
fileReq.setPostDlvrSe(null); ciRslts = getConvertCis(fileReq, fmcExcels, unitySndngMastrId, excelCnt);
fileReq.setSignguCode(null); }
fileReq.setFfnlgCode(null);
// CNTC 테이블 insert
final String rtnMsgSub = makeCntc(ciRslts, fmcExcels, fileReq, unitySndngMastrId, excelCnt);
fileReq.setSignguCode(null);
fileReq.setFfnlgCode(null);
fileReq.setTry1(null);
fileReq.setPostDlvrSe(null);
fileReq.setPostTmplatCode(null);
if("".equals(rtnMsg)) rtnMsg = unitySndngMastrId + ":" + rtnMsgSub;
if(!"".equals(rtnMsg)) rtnMsg = rtnMsg + ", " + unitySndngMastrId + ":" + rtnMsgSub;
}
// final TmplatManage tmpDTO = mapper.selectDeptInfoByTmplId(
// fmcExcels.get(0).getTmplatId())
// .orElseThrow(() -> BizRuntimeException.create("템플릿 정보를 찾을 수 없습니다."));
//
// // Ci 변환
// fileReq.setSignguCode(tmpDTO.getSignguCode());
// fileReq.setFfnlgCode(tmpDTO.getFfnlgCode());
// fileReq.setTry1(tmpDTO.getTry1());
// fileReq.setPostDlvrSe(tmpDTO.getPostDlvrSe());
// fileReq.setPostTmplatCode(tmpDTO.getPostTmplatCode());
//
// List<FmcInfExcelRslt> ciRslts = null;
// if(Pattern.matches("([\\w]{4}[1-2])", fmcExcels.get(0).getTmplatId())) {
// ciRslts = getConvertCis(fileReq, fmcExcels);
// }
//
// // CNTC 테이블 insert
// final String rtnMsg = makeCntc(ciRslts, fmcExcels, fileReq);
// fileReq.setPostDlvrSe(null);
// fileReq.setSignguCode(null);
// fileReq.setFfnlgCode(null);
return rtnMsg; return rtnMsg;
} }
@ -265,47 +304,49 @@ public class BizSisulService extends AbstractService implements IBizSisulService
* @return List<FmcInfExcelRslt> * @return List<FmcInfExcelRslt>
* </pre> * </pre>
*/ */
private List<FmcInfExcelRslt> getConvertCis(final FmcExcelUpload fileReq, final List<FmcInfExcel> fmcExcels){ private List<FmcInfExcelRslt> getConvertCis(final FmcExcelUpload fileReq, final List<FmcInfExcel> fmcExcels, final String unitySndngMastrId, final int excelCnt){
List<FmcInfExcelRslt> rslts = new ArrayList<>(); List<FmcInfExcelRslt> rslts = new ArrayList<>();
int errCnt = 0; int errCnt = 0;
for(FmcInfExcel dto : fmcExcels) { for(FmcInfExcel dto : fmcExcels) {
//23.11.22 jhseo: 하나의 엑셀에 unitySndngMastrId 여러개일 경우 동일한 unitySndngMastrId Row만 처리
try { if(unitySndngMastrId.equals(dto.getUnitySndngMastrId())){
IpinCiResDataBody dataBody = niceCiService.requestCi( try {
NiceCiRequest.builder() IpinCiResDataBody dataBody = niceCiService.requestCi(
.signguCode(fileReq.getSignguCode()) NiceCiRequest.builder()
.ffnlgCode(fileReq.getFfnlgCode()) .signguCode(fileReq.getSignguCode())
.juminId(dto.getRecveJuminno()) .ffnlgCode(fileReq.getFfnlgCode())
.build() .juminId(dto.getRecveJuminno())
); .build()
IpinCiResEncData resEncData = dataBody.toEncData(); );
rslts.add( IpinCiResEncData resEncData = dataBody.toEncData();
FmcInfExcelRslt.builder() rslts.add(
.unitySndngDetailId(dto.getUnitySndngDetailId()) FmcInfExcelRslt.builder()
.ci1(resEncData.getCi1()) .unitySndngDetailId(dto.getUnitySndngDetailId())
.ci2(resEncData.getCi2()) .ci1(resEncData.getCi1())
.resultCd(dataBody.getResultCd()) .ci2(resEncData.getCi2())
.message(CmmNiceCiUtils.getFromResultCd(NiceCiWrkDiv.CI, dataBody.getResultCd())) .resultCd(dataBody.getResultCd())
.build() .message(CmmNiceCiUtils.getFromResultCd(NiceCiWrkDiv.CI, dataBody.getResultCd()))
); .build()
} catch (BizRuntimeException e){ );
errCnt++; } catch (BizRuntimeException e){
rslts.add( errCnt++;
FmcInfExcelRslt.builder() rslts.add(
.unitySndngDetailId(dto.getUnitySndngDetailId()) FmcInfExcelRslt.builder()
.resultCd(e.getCode()) .unitySndngDetailId(dto.getUnitySndngDetailId())
.message(e.getMessage()) .resultCd(e.getCode())
.build() .message(e.getMessage())
); .build()
);
}
} }
} }
fileReq.setSndngCo(fmcExcels.size()); fileReq.setSndngCo(excelCnt);
if(fmcExcels.size() != rslts.size()) throw BizRuntimeException.create( if(excelCnt != rslts.size()) throw BizRuntimeException.create(
String.format( String.format(
"CI 전환 오류[변환대상-%d건, 변환완료-%d건, 변환오류-%d건]", "CI 전환 오류[변환대상-%d건, 변환완료-%d건, 변환오류-%d건]",
fmcExcels.size(), excelCnt,
rslts.size()-errCnt, rslts.size()-errCnt,
errCnt) errCnt)
); );
@ -320,79 +361,81 @@ public class BizSisulService extends AbstractService implements IBizSisulService
* @return String * @return String
* </pre> * </pre>
*/ */
private String makeCntc(final List<FmcInfExcelRslt> ciRslts, final List<FmcInfExcel> fmcExcels, FmcExcelUpload fileReq){ private String makeCntc(final List<FmcInfExcelRslt> ciRslts, final List<FmcInfExcel> fmcExcels, FmcExcelUpload fileReq, final String unitySndngMastrId, final int excelCnt){
int mst = 0; int mst = 0;
int errCnt = 0; int errCnt = 0;
String mpc = null; String mpc = null;
final int excelCnt = fmcExcels.size();
final String register = StringUtils.defaultString(fileReq.getRegister(),""); final String register = StringUtils.defaultString(fileReq.getRegister(),"");
String unitySndngMastrId = ""; // String unitySndngMastrId = "";
String[] ppMasterJson = new String[2]; String[] ppMasterJson = new String[2];
for(FmcInfExcel dto : fmcExcels){ for(FmcInfExcel dto : fmcExcels){
//최초 1회 CNTC master 생성 //23.11.22 jhseo: 하나의 엑셀에 unitySndngMastrId 여러개일 경우 동일한 unitySndngMastrId Row만 처리
if(StringUtils.isNotEmpty(dto.getUnitySndngMastrId()) && mst == 0){ if(unitySndngMastrId.equals(dto.getUnitySndngMastrId())){
unitySndngMastrId = dto.getUnitySndngMastrId(); //최초 1회 CNTC master 생성
fileReq.setUnitySndngMastrId(unitySndngMastrId); // if(StringUtils.isNotEmpty(dto.getUnitySndngMastrId()) && mst == 0){
mapper.insertCntcSndngMst( // unitySndngMastrId = dto.getUnitySndngMastrId();
CntcDTO.SndngMst.builder() if(mst == 0){
.unitySndngMastrId(dto.getUnitySndngMastrId()) fileReq.setUnitySndngMastrId(unitySndngMastrId);
.tmplatId(dto.getTmplatId()) mapper.insertCntcSndngMst(
.sndngDt(dto.getSndngDt()) CntcDTO.SndngMst.builder()
.closDt(dto.getNapPd() + "235959") .unitySndngMastrId(dto.getUnitySndngMastrId())
.sndngCo(excelCnt) .tmplatId(dto.getTmplatId())
.sndngProcessSttus(ApiConstants.SndngProcessStatus.ACCEPT.getCode()) .sndngDt(dto.getSndngDt())
.register(register) .closDt(dto.getNapPd() + "235959")
.build() .sndngCo(excelCnt)
); .sndngProcessSttus(ApiConstants.SndngProcessStatus.ACCEPT.getCode())
} .register(register)
mst++; .build()
);
// POST-PLUS(전자우편) 일 경우 tb_ens_post_plus_json 테이블 insert }
if("POST-PLUS".equals(fileReq.getTry1())){ mst++;
//최초 1회 POST-PLUS master json 생성
if(mst == 1){ // POST-PLUS(전자우편) 일 경우 tb_ens_post_plus_json 테이블 insert
ppMasterJson = PPMasterJson(dto, fileReq, excelCnt); if("POST-PLUS".equals(fileReq.getTry1())){
//최초 1회 POST-PLUS master json 생성
if(mst == 1){
ppMasterJson = PPMasterJson(dto, fileReq, excelCnt);
}
String ppDetailJson[] = PPDetailJson(Integer.toString(mst),dto, fileReq.getSignguCode());
mapper.insertPostPlusJson(
CntcDTO.PostPlusJson.builder()
.unitySndngDetailId(dto.getUnitySndngDetailId())
.serviceCd("PST")
.conKey(unitySndngMastrId)
.sn(Integer.toString(mst))
.masterCols(ppMasterJson[0])
.masterRows(ppMasterJson[1])
.detailCols(ppDetailJson[0])
.detailRows(jasyptStringEncryptor.encrypt(ppDetailJson[1]))
.register(register)
.build()
);
}else {
switch (fileReq.getSignguCode()) {
case "88328": //교통시설운영처
mpc = jsonCn1(dto);
break;
case "88316": //추모시설운영처
mpc = jsonCn2(dto);
break;
default:
break;
}
} }
String ppDetailJson[] = PPDetailJson(Integer.toString(mst),dto, fileReq.getSignguCode()); //CNTC detail 생성
mapper.insertPostPlusJson( mapper.insertCntcSndngDtl(
CntcDTO.PostPlusJson.builder() CntcDTO.SndngDtl.builder()
.unitySndngMastrId(unitySndngMastrId)
.unitySndngDetailId(dto.getUnitySndngDetailId()) .unitySndngDetailId(dto.getUnitySndngDetailId())
.serviceCd("PST") .tmplatId(dto.getTmplatId())
.conKey(unitySndngMastrId) .mainCode(dto.getTaxNum1()+dto.getTaxNum2()+dto.getTaxNum3()+dto.getTaxNum4()) // 납세번호로 자료 찾기
.sn(Integer.toString(mst)) .tmpltMsgData(dto.getNapAmountTotal()) // 고객사 요청 사항 납부금액 표기
.masterCols(ppMasterJson[0]) .useInsttIdntfcId(dto.getGojiDetailNm()) // 교통시설운영처 제목 가변 항목
.masterRows(ppMasterJson[1]) .mobilePageCn(mpc)
.detailCols(ppDetailJson[0])
.detailRows(jasyptStringEncryptor.encrypt(ppDetailJson[1]))
.register(register) .register(register)
.build() .build()
); );
}else {
switch (fileReq.getSignguCode()) {
case "88328": //교통시설운영처
mpc = jsonCn1(dto);
break;
case "88316": //추모시설운영처
mpc = jsonCn2(dto);
break;
default:
break;
}
} }
//CNTC detail 생성
mapper.insertCntcSndngDtl(
CntcDTO.SndngDtl.builder()
.unitySndngMastrId(unitySndngMastrId)
.unitySndngDetailId(dto.getUnitySndngDetailId())
.tmplatId(dto.getTmplatId())
.mainCode(dto.getTaxNum1()+dto.getTaxNum2()+dto.getTaxNum3()+dto.getTaxNum4()) // 납세번호로 자료 찾기
.tmpltMsgData(dto.getNapAmountTotal()) // 고객사 요청 사항 납부금액 표기
.useInsttIdntfcId(dto.getGojiDetailNm()) // 교통시설운영처 제목 가변 항목
.mobilePageCn(mpc)
.register(register)
.build()
);
} }
if(Checks.isNotEmpty(ciRslts)) { if(Checks.isNotEmpty(ciRslts)) {
@ -404,10 +447,11 @@ public class BizSisulService extends AbstractService implements IBizSisulService
} }
} }
return String.format( return String.format(
"전자고지 대상 %d건 Upload[완료-%d건, 오류-%d건]", "전자고지 대상 %d건 Upload[완료-%d건, 오류-%d건]",
fmcExcels.size(), excelCnt,
fmcExcels.size()-errCnt, excelCnt-errCnt,
errCnt); errCnt);
} }

Loading…
Cancel
Save