feat : xml파일 처리 로직 처리중
parent
47667374a3
commit
ddda6b4ca9
@ -0,0 +1,33 @@
|
||||
package com.worker.dto;
|
||||
|
||||
import com.worker.entity.CpMain;
|
||||
import jakarta.persistence.Lob;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SinmungoDto {
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class ParseResult {
|
||||
private CpMain cpMain;
|
||||
private List<ImgParser> imgParsers;
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class ImgParser {
|
||||
private String fileName;
|
||||
@Lob
|
||||
private byte[] imageBytes;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
package com.worker.scheduler.smg;
|
||||
|
||||
import com.worker.entity.CpMain;
|
||||
import com.worker.entity.CpSetinfo;
|
||||
import com.worker.entity.CpSetinfoId;
|
||||
import com.worker.entity.CpSetinfoRepository;
|
||||
import com.worker.util.fileReader.XmlReader;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class SinmongoInOutScheduler {
|
||||
|
||||
private final CpSetinfoRepository cpSetinfoRepository;
|
||||
private final XmlReader xmlReader;
|
||||
|
||||
// esb에이전트 xml파일 읽기
|
||||
@Scheduled(fixedRate = 10 * 60 * 1000) // 10분
|
||||
// @Scheduled(fixedRate = 1000) // 10초
|
||||
public void sinmongoInOutScheduler() {
|
||||
//setinfo 테이블에서 esb에이전트 정보 조회
|
||||
Optional<CpSetinfo> esbImgDir = cpSetinfoRepository.findById(
|
||||
CpSetinfoId.builder()
|
||||
.codeName("SERVER_INFO")
|
||||
.groupCode("DIRECTORY")
|
||||
.detailCode("IMAGE")
|
||||
.build()
|
||||
);
|
||||
|
||||
Optional<CpSetinfo> esbXmlDir = cpSetinfoRepository.findById(
|
||||
CpSetinfoId.builder()
|
||||
.codeName("국민신문고")
|
||||
.groupCode("정보")
|
||||
.detailCode("test")
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
//파일읽기
|
||||
List<CpMain> parseResult = xmlReader.findXml(esbXmlDir.get().getStrValue4());
|
||||
log.info(parseResult.toString());
|
||||
|
||||
//sinmongo 디렉토리로 파일 이동
|
||||
|
||||
//db폴링
|
||||
|
||||
//파일백업으로 이동
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 90일이 초과한 백업 파일들 삭제
|
||||
public void sinmongoInOutFileRemoveScheduler() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.worker.scheduler.smg;
|
||||
|
||||
import com.worker.dto.SinmungoDto;
|
||||
import com.worker.entity.*;
|
||||
import com.worker.util.fileReader.XmlReader;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class SinmungoInOutScheduler {
|
||||
private final CpMainRepository cpMainRepository;
|
||||
|
||||
private final CpSetinfoRepository cpSetinfoRepository;
|
||||
private final XmlReader xmlReader;
|
||||
|
||||
// esb에이전트 xml파일 읽기
|
||||
@Scheduled(fixedRate = 10 * 60 * 1000) // 10분
|
||||
@Transactional
|
||||
public void sinmungoInOutScheduler() throws IOException {
|
||||
//setinfo 테이블에서 esb에이전트 정보 조회
|
||||
Optional<CpSetinfo> esbXmlDir = cpSetinfoRepository.findById(
|
||||
CpSetinfoId.builder()
|
||||
.codeName("국민신문고")
|
||||
.groupCode("정보")
|
||||
.detailCode("test")
|
||||
.build()
|
||||
);
|
||||
|
||||
Optional<CpSetinfo> esbBackupDir = cpSetinfoRepository.findById(
|
||||
CpSetinfoId.builder()
|
||||
.codeName("SERVER_INFO")
|
||||
.groupCode("DIRECTORY")
|
||||
.detailCode("IMAGEtest")
|
||||
.build()
|
||||
);
|
||||
|
||||
// 국민신문고 esb에이전트 pull path 정의
|
||||
Path esbRcvPath = Paths.get(esbXmlDir.get().getStrValue4());
|
||||
Path esbSendPath = Paths.get(esbXmlDir.get().getStrValue5());
|
||||
|
||||
// 백업 디렉토리
|
||||
Path localImgPath = Paths.get(esbBackupDir.get().getStrValue1()); //img
|
||||
Path localXmlPath = Paths.get(esbBackupDir.get().getStrValue2()); //sinmungo path 는 하드코딩 되어있었음
|
||||
|
||||
//파일읽기
|
||||
List<SinmungoDto.ParseResult> parseResult = xmlReader.findXml(esbXmlDir.get().getStrValue4());
|
||||
log.info(parseResult.toString());
|
||||
|
||||
// cpMain만 추출
|
||||
List<CpMain> cpMainList = parseResult.stream()
|
||||
.map(SinmungoDto.ParseResult::getCpMain)
|
||||
.collect(Collectors.toList());
|
||||
// db폴링
|
||||
// cpMainRepository.saveAll(cpMainList);
|
||||
|
||||
// 파일백업으로 이동
|
||||
// xml은 HP_ROOT/PROGRAM/BATCH/sinmungo 로 백업?
|
||||
// xml안에 있던 이미지 바이너리는 HP_ROOT/DATA/IMAGE/${담당자번호?}/2025 로 백업?
|
||||
Files.move(esbRcvPath, localXmlPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
List<SinmungoDto.ImgParser> imgParsers = parseResult.stream()
|
||||
.flatMap(result -> result.getImgParsers().stream())
|
||||
.collect(Collectors.toList());
|
||||
xmlReader.imgLocalSave(localImgPath, imgParsers);
|
||||
|
||||
}
|
||||
|
||||
// 90일이 초과한 백업 파일들 삭제
|
||||
public void sinmungoInOutFileRemoveScheduler() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue