parent
b840989ee0
commit
91b28e38cf
@ -0,0 +1,31 @@
|
|||||||
|
package com.worker.domain.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(
|
||||||
|
name = "epost_rgst_nmbr",
|
||||||
|
indexes = {
|
||||||
|
@Index(name = "EPOST_RGST_NMBR_IDX1", columnList = "PCURSOR")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class EpostRgstNmbr {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "RGST_NMBR", columnDefinition = "char(13)", nullable = false)
|
||||||
|
private String rgstNmbr;
|
||||||
|
|
||||||
|
@Column(name = "RGST_NMBR_NEXT", columnDefinition = "char(13)")
|
||||||
|
private String rgstNmbrNext;
|
||||||
|
|
||||||
|
@Column(name = "PCURSOR", columnDefinition = "char(1)")
|
||||||
|
private String pcursor;
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.worker.domain.repo.cp;
|
||||||
|
|
||||||
|
import com.worker.domain.entity.EpostRgstNmbr;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CpEPostRgstNmbr extends JpaRepository<EpostRgstNmbr, Integer> {
|
||||||
|
EpostRgstNmbr findByPcursor(String cursor);
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.worker.domain.repo.ep;
|
||||||
|
|
||||||
|
import com.worker.domain.entity.EpostRgstNmbr;
|
||||||
|
import com.worker.domain.repo.cp.CpEPostRgstNmbr;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface EpEPostRgstNmbr extends JpaRepository<EpostRgstNmbr, Integer> {
|
||||||
|
EpostRgstNmbr findByPcursor(String number);
|
||||||
|
}
|
||||||
@ -1,4 +1,99 @@
|
|||||||
package com.worker.util.zipFileMaker;
|
package com.worker.util.zipFileMaker;
|
||||||
|
|
||||||
|
import com.worker.scheduler.epost.dto.EPostDto;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class ZipMaker {
|
public class ZipMaker {
|
||||||
|
|
||||||
|
private static final List<String> SUFFIXES = Arrays.asList("A", "B", "C", "D");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CP/EP 디렉토리에서.jpeg 가 존재하는 것만 ZIP에 담는다.
|
||||||
|
*/
|
||||||
|
public void generateZipFile(List<String> cpMmCodes, List<String> epMmCodes, EPostDto.SetInfo setInfo) throws IOException {
|
||||||
|
|
||||||
|
Objects.requireNonNull(setInfo, "setInfo is null");
|
||||||
|
String cpPath = setInfo.getCpSetinfo().getStrValue5();
|
||||||
|
String epPath = setInfo.getEpSetinfo().getStrValue5();
|
||||||
|
String cpZipPath = setInfo.getCpSetinfo().getStrValue4();
|
||||||
|
String epZipPath = setInfo.getCpSetinfo().getStrValue4();
|
||||||
|
|
||||||
|
// ZIP 저장 디렉토리 없으면 생성
|
||||||
|
File cpZipFile = new File(cpZipPath);
|
||||||
|
File epZipFile = new File(epZipPath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileOutputStream fosCp = new FileOutputStream(cpZipFile);
|
||||||
|
FileOutputStream fosEp = new FileOutputStream(epZipFile);
|
||||||
|
ZipOutputStream zosCp = new ZipOutputStream(fosCp);
|
||||||
|
ZipOutputStream zosEp = new ZipOutputStream(fosEp);
|
||||||
|
|
||||||
|
// 1) CP
|
||||||
|
for (String code : safeList(cpMmCodes)) {
|
||||||
|
List<File> files = findExistingJpegs(cpPath, code);
|
||||||
|
addFilesToZip(zosCp, files, code + "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) EP
|
||||||
|
for (String code : safeList(epMmCodes)) {
|
||||||
|
List<File> files = findExistingJpegs(epPath, code);
|
||||||
|
addFilesToZip(zosEp, files, code + "/");
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
log.error("ZIP 객체 생성 실패 : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** baseDir/code + (A|B|C|D).jpeg 중 존재하는 파일만 수집 */
|
||||||
|
private List<File> findExistingJpegs(String baseDir, String code) {
|
||||||
|
List<File> found = new ArrayList<>();
|
||||||
|
if (isBlank(baseDir) || isBlank(code)) return found;
|
||||||
|
|
||||||
|
for (String sfx : SUFFIXES) {
|
||||||
|
String filename = code + sfx + ".jpeg";
|
||||||
|
File f = new File(baseDir, filename);
|
||||||
|
if (f.isFile()) {
|
||||||
|
found.add(f); // 존재하는 것만 담음 (A/B만 있으면 A,B만)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ZIP에 파일 추가 */
|
||||||
|
private void addFilesToZip(ZipOutputStream zos, List<File> files, String zipFolderPrefix) throws IOException {
|
||||||
|
for (File file : files) {
|
||||||
|
String entryName = zipFolderPrefix + file.getName();
|
||||||
|
zos.putNextEntry(new ZipEntry(entryName));
|
||||||
|
|
||||||
|
try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
|
||||||
|
byte[] buf = new byte[8192];
|
||||||
|
int n;
|
||||||
|
while ((n = in.read(buf)) != -1) {
|
||||||
|
zos.write(buf, 0, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zos.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> List<T> safeList(List<T> list) {
|
||||||
|
return list == null ? Collections.emptyList() : list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isBlank(String s) {
|
||||||
|
return s == null || s.trim().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue