|
|
|
|
@ -4,14 +4,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
|
|
import com.worker.domain.entity.*;
|
|
|
|
|
import com.worker.domain.repo.cp.CpEpostDelivResultRepository;
|
|
|
|
|
import com.worker.domain.repo.cp.CpEpostRceptResultRepository;
|
|
|
|
|
import com.worker.domain.repo.cp.CpGojiSendHistRepository;
|
|
|
|
|
import com.worker.domain.repo.cp.CpSetinfoRepository;
|
|
|
|
|
import com.worker.domain.repo.ep.EpEpostDelivResultRepository;
|
|
|
|
|
import com.worker.domain.repo.ep.EpEpostRceptResultRepository;
|
|
|
|
|
import com.worker.domain.repo.ep.EpGojiSendHistRepository;
|
|
|
|
|
import com.worker.domain.repo.ep.EpSetinfoRepository;
|
|
|
|
|
import com.worker.domain.repo.cp.*;
|
|
|
|
|
import com.worker.domain.repo.ep.*;
|
|
|
|
|
import com.worker.scheduler.epost.dto.EPostDto;
|
|
|
|
|
import com.worker.scheduler.epost.repository.EPostQueryDslRepository;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
@ -21,6 +15,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@ -34,12 +30,19 @@ public class EPostService {
|
|
|
|
|
|
|
|
|
|
private final CpSetinfoRepository cpSetinfoRepository;
|
|
|
|
|
private final EpSetinfoRepository epSetinfoRepository;
|
|
|
|
|
private final CpGojitRepository cpGojitRepository;
|
|
|
|
|
private final EpGojitRepository epGojitRepository;
|
|
|
|
|
private final CpGojiSendHistRepository cpGojiSendHistRepository;
|
|
|
|
|
private final EpGojiSendHistRepository epGojiSendHistRepository;
|
|
|
|
|
private final CpEpostRceptResultRepository cpEpostRceptResultRepository;
|
|
|
|
|
private final EpEpostRceptResultRepository epEpostRceptResultRepository;
|
|
|
|
|
private final CpEpostDelivResultRepository cpEpostDelivResultRepository;
|
|
|
|
|
private final EpEpostDelivResultRepository epEpostDelivResultRepository;
|
|
|
|
|
private final CpGojiSendHistRepository cpGojiSendHistRepository;
|
|
|
|
|
private final EpGojiSendHistRepository epGojiSendHistRepository;
|
|
|
|
|
private final CpEPostSenderDetailRepository cpEPostSenderDetailRepository;
|
|
|
|
|
private final EpEPostSenderDetailRepository epEPostSenderDetailRepository;
|
|
|
|
|
private final CpEPostSenderRegRepository cpEPostSenderRegRepository;
|
|
|
|
|
private final EpEPostSenderRegRepository epEPostSenderRegRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final EPostQueryDslRepository ePostQueryDslRepository;
|
|
|
|
|
|
|
|
|
|
@ -51,7 +54,10 @@ public class EPostService {
|
|
|
|
|
@Autowired
|
|
|
|
|
@Qualifier("epQueryFactory")
|
|
|
|
|
private JPAQueryFactory epQueryFactory;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CpGojiPrtRepository cpGojiPrtRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private EpGojiPrtRepository epGojiPrtRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void findEPostSendTarget() {
|
|
|
|
|
@ -112,7 +118,10 @@ public class EPostService {
|
|
|
|
|
log.info(epRecvs.toString());
|
|
|
|
|
|
|
|
|
|
if(cpDelivs != null && !cpDelivs.isEmpty()) {
|
|
|
|
|
|
|
|
|
|
insertDelivResults(cpDelivs, parseResult, "cp");
|
|
|
|
|
}
|
|
|
|
|
if (epDelivs != null && !epDelivs.isEmpty()) {
|
|
|
|
|
insertDelivResults(epDelivs, parseResult, "ep");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (delivs != null && !delivs.isEmpty()) insertDelivResults(delivs);
|
|
|
|
|
@ -123,37 +132,92 @@ public class EPostService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void insertDelivResults(List<EPostDto.SearchDelivTarget> delivs, List<EPostDto.EPostFileRead> parseResults) {
|
|
|
|
|
private void insertDelivResults(List<EPostDto.SearchDelivTarget> delivs, List<EPostDto.EPostFileRead> parseResults, String dbKind) {
|
|
|
|
|
|
|
|
|
|
List<CpGojiSendHist> finalCpResults = new ArrayList<>();
|
|
|
|
|
List<CpGojiSendHist> finalEpResults = new ArrayList<>();
|
|
|
|
|
List<CpGojiSendHist> cpGojiSendHists = new ArrayList<>();
|
|
|
|
|
List<EpostDelivResult> epostDelivResults = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
List<EPostDto.Deliv> delivFileResults = parseResults.stream()
|
|
|
|
|
.filter(r -> "deliv".equalsIgnoreCase(r.getKind()))
|
|
|
|
|
.flatMap(r -> ((List<EPostDto.Deliv>) r.getResult()).stream())
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delivFileResults.forEach(fileResult -> {
|
|
|
|
|
delivs.forEach(deliv -> {
|
|
|
|
|
Long resultTime = Long.valueOf(deliv.getGpSendDate() + deliv.getGpSendTime());
|
|
|
|
|
for(int i = 0; i < delivs.size(); i++) {
|
|
|
|
|
Long resultTime = Long.valueOf(delivs.get(i).getGpSendDate() + delivs.get(i).getGpSendTime());
|
|
|
|
|
Long fileTime = Long.valueOf( fileResult.getDelivymd() + fileResult.getDelivhhmi());
|
|
|
|
|
Long maxKey = findMaxKey(dbKind, delivs.get(i).getConKey()) + i;
|
|
|
|
|
|
|
|
|
|
String newState = null;
|
|
|
|
|
if(fileResult.getNondelivreasncdnm().equals("")) newState = "4";
|
|
|
|
|
else newState = "5";
|
|
|
|
|
|
|
|
|
|
Boolean isSkip = false;
|
|
|
|
|
if(resultTime > fileTime) isSkip = true;
|
|
|
|
|
if(Long.parseLong(delivs.get(i).getGpState()) > 5) isSkip = true;
|
|
|
|
|
|
|
|
|
|
if(!isSkip) {
|
|
|
|
|
|
|
|
|
|
//epost_sender_detail > deliv_result_code 업데이트 (where콘키,등기번호)
|
|
|
|
|
EpostSenderDetail epostSenderDetail = EpostSenderDetail.builder()
|
|
|
|
|
.delivResultCode(Math.toIntExact(maxKey))
|
|
|
|
|
.conKey(fileResult.getConKey())
|
|
|
|
|
.rgstNmbr(fileResult.getRegiNo())
|
|
|
|
|
.build();
|
|
|
|
|
//epost_sender_detail 업데이트
|
|
|
|
|
if(dbKind.equals("cp")) cpEPostSenderDetailRepository.save(epostSenderDetail);
|
|
|
|
|
else epEPostSenderDetailRepository.save(epostSenderDetail);
|
|
|
|
|
|
|
|
|
|
//cp_goji_prt 업데이트
|
|
|
|
|
CpGojiPrt cpGojiPrt = CpGojiPrt.builder()
|
|
|
|
|
.gpSggcode(delivs.get(i).getGpSggcode())
|
|
|
|
|
.gpSendDate(fileResult.getDelivymd())
|
|
|
|
|
.gpSendTime(fileResult.getDelivhhmi())
|
|
|
|
|
.gpReturnCd(fileResult.getNondelivreasncdnm())
|
|
|
|
|
.gpRecvName(fileResult.getSubrecprsnnm())
|
|
|
|
|
.gpRecvRelt(fileResult.getRelrecprsncdnm())
|
|
|
|
|
.gpState(newState)
|
|
|
|
|
.build();
|
|
|
|
|
//cp_goji_prt 업데이트
|
|
|
|
|
if(dbKind.equals("cp")) cpGojiPrtRepository.save(cpGojiPrt);
|
|
|
|
|
else epGojiPrtRepository.save(cpGojiPrt);
|
|
|
|
|
|
|
|
|
|
//deliv.getPostProcSt()가 95보다 작으면 처리상태 변경
|
|
|
|
|
//epost_send_reg의 post_proc_stt, cp_gojit의 tg_post_proc_stt 업데이트
|
|
|
|
|
if(Long.parseLong(delivs.get(i).getPostProcSt()) < 95) {
|
|
|
|
|
CpGojit gojit = CpGojit.builder()
|
|
|
|
|
.tgPostProcStt("95")
|
|
|
|
|
.tgCode(delivs.get(i).getGpCode())
|
|
|
|
|
.build();
|
|
|
|
|
if(dbKind.equals("cp")) cpGojitRepository.save(gojit);
|
|
|
|
|
else epGojitRepository.save(gojit);
|
|
|
|
|
|
|
|
|
|
EpostSenderReg epostSenderReg = EpostSenderReg.builder()
|
|
|
|
|
.postProcStt("95")
|
|
|
|
|
.conKey(delivs.get(i).getConKey())
|
|
|
|
|
.build();
|
|
|
|
|
if(dbKind.equals("cp")) cpEPostSenderRegRepository.save(epostSenderReg);
|
|
|
|
|
else epEPostSenderRegRepository.save(epostSenderReg);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CpGojiSendHist cpGojiSendHist = CpGojiSendHist.builder()
|
|
|
|
|
.ghCode("//맥스값 추출 + 1")
|
|
|
|
|
// .ghGpcode()
|
|
|
|
|
// .ghConKey()
|
|
|
|
|
// .ghRegino()
|
|
|
|
|
// .ghSendDate()
|
|
|
|
|
// .ghSendTime()
|
|
|
|
|
// .ghReturnCdStr()
|
|
|
|
|
// .ghRecvName()
|
|
|
|
|
// .ghRecvRelt()
|
|
|
|
|
// .ghResultCd()
|
|
|
|
|
// .ghReturnCd()
|
|
|
|
|
// .ghRecvReltCd()
|
|
|
|
|
.ghCode(makeGojiHistMaxKey(dbKind))
|
|
|
|
|
.ghGpcode(Math.toIntExact(delivs.get(i).getGpCode()))
|
|
|
|
|
.ghConKey(delivs.get(i).getConKey())
|
|
|
|
|
.ghRegino(fileResult.getRegiNo())
|
|
|
|
|
.ghSendDate(fileResult.getDelivymd())
|
|
|
|
|
.ghSendTime(fileResult.getDelivhhmi())
|
|
|
|
|
.ghReturnCdStr(fileResult.getNondelivreasncdnm())
|
|
|
|
|
.ghRecvName(fileResult.getSubrecprsnnm())
|
|
|
|
|
.ghRecvRelt(fileResult.getRelrecprsncdnm())
|
|
|
|
|
.ghResultCd(fileResult.getDelivrsltcd())
|
|
|
|
|
.ghReturnCd(fileResult.getNondelivreasncd())
|
|
|
|
|
.ghRecvReltCd(fileResult.getRelrecprsncd())
|
|
|
|
|
.build();
|
|
|
|
|
cpGojiSendHists.add(cpGojiSendHist);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EpostDelivResult epostDelivResult = EpostDelivResult.builder()
|
|
|
|
|
@ -168,13 +232,20 @@ public class EPostService {
|
|
|
|
|
.relRecPrsnCd(fileResult.getRelrecprsncd())
|
|
|
|
|
.relRecPrsnCdNm(fileResult.getRelrecprsncdnm())
|
|
|
|
|
.build();
|
|
|
|
|
epostDelivResults.add(epostDelivResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(dbKind.equals("cp")) {
|
|
|
|
|
cpGojiSendHistRepository.saveAll(cpGojiSendHists);
|
|
|
|
|
cpEpostDelivResultRepository.saveAll(epostDelivResults);
|
|
|
|
|
} else {
|
|
|
|
|
epGojiSendHistRepository.saveAll(cpGojiSendHists);
|
|
|
|
|
epEpostDelivResultRepository.saveAll(epostDelivResults);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -224,7 +295,29 @@ public class EPostService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Long findMaxKey(String dbKind, String conKey) {
|
|
|
|
|
Long maxKey = 0L;
|
|
|
|
|
if(dbKind.equals("cp")) maxKey = ePostQueryDslRepository.findEpostDelivResultMaxKey(cpQueryFactory, conKey);
|
|
|
|
|
else maxKey = ePostQueryDslRepository.findEpostDelivResultMaxKey(epQueryFactory, conKey);
|
|
|
|
|
return maxKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String makeGojiHistMaxKey(String dbKind) {
|
|
|
|
|
String maxKey = "";
|
|
|
|
|
|
|
|
|
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
|
|
String tempKeyByNow = LocalDateTime.now().format(dtf);
|
|
|
|
|
|
|
|
|
|
if(dbKind.equals("cp")) maxKey = ePostQueryDslRepository.findGojiHistMAxKey(cpQueryFactory, tempKeyByNow);
|
|
|
|
|
else maxKey = ePostQueryDslRepository.findGojiHistMAxKey(cpQueryFactory, tempKeyByNow);
|
|
|
|
|
|
|
|
|
|
if(maxKey != null && maxKey.length() > 0) {
|
|
|
|
|
Long maxKetLong = Long.parseLong(maxKey) + 1L;
|
|
|
|
|
maxKey = maxKetLong.toString();
|
|
|
|
|
} else maxKey = tempKeyByNow + "0001";
|
|
|
|
|
|
|
|
|
|
return maxKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|