영상관리파일싱크 추가

This commit is contained in:
Moon
2025-12-16 09:24:31 +09:00
parent ddb24dfaa8
commit bfcaa5e586
11 changed files with 240 additions and 275 deletions

View File

@@ -2,7 +2,6 @@ package com.kamco.cd.kamcoback.common.utils;
import static java.lang.String.CASE_INSENSITIVE_ORDER; import static java.lang.String.CASE_INSENSITIVE_ORDER;
import com.kamco.cd.kamcoback.scheduler.dto.FileDto;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@@ -162,7 +161,7 @@ public class FIleChecker {
// 윈도우용 // 윈도우용
command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행 command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션 command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
command.add("gdalinfo"); command.add("gdalinfo");
command.add(filePath); command.add(filePath);
command.add("|"); command.add("|");
@@ -207,7 +206,6 @@ public class FIleChecker {
return hasDriver; return hasDriver;
} }
@Schema(name = "File Basic", description = "파일 기본 정보") @Schema(name = "File Basic", description = "파일 기본 정보")
@Getter @Getter
public static class Basic { public static class Basic {
@@ -221,13 +219,13 @@ public class FIleChecker {
private final String lastModified; private final String lastModified;
public Basic( public Basic(
String fileNm, String fileNm,
String parentFolderNm, String parentFolderNm,
String parentPath, String parentPath,
String fullPath, String fullPath,
String extension, String extension,
long fileSize, long fileSize,
String lastModified) { String lastModified) {
this.fileNm = fileNm; this.fileNm = fileNm;
this.parentFolderNm = parentFolderNm; this.parentFolderNm = parentFolderNm;
this.parentPath = parentPath; this.parentPath = parentPath;
@@ -238,9 +236,14 @@ public class FIleChecker {
} }
} }
public static List<Basic> getFilesFromAllDepth(
String dir,
public static List<Basic> getFilesFromAllDepth(String dir, String targetFileNm, String extension, int maxDepth, String sortType, int startPos, int limit) { String targetFileNm,
String extension,
int maxDepth,
String sortType,
int startPos,
int limit) {
Path startPath = Paths.get(dir); Path startPath = Paths.get(dir);
String dirPath = dir; String dirPath = dir;
@@ -256,39 +259,36 @@ public class FIleChecker {
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) { try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
fileList = fileList =
stream stream
.filter(Files::isRegularFile) .filter(Files::isRegularFile)
.filter( .filter(
p -> p ->
extension == null extension == null
|| extension.equals("") || extension.equals("")
|| extension.equals("*") || extension.equals("*")
|| targetExtensions.contains(extractExtension(p))) || targetExtensions.contains(extractExtension(p)))
.sorted(getFileComparator(sortType)) .sorted(getFileComparator(sortType))
.filter( .filter(p -> p.getFileName().toString().contains(targetFileNm))
p -> p.getFileName().toString().contains(targetFileNm) .skip(startPos)
) .limit(limit)
.skip(startPos) .map(
.limit(limit) path -> {
.map( // int depth = path.getNameCount();
path -> {
//int depth = path.getNameCount();
String fileNm = path.getFileName().toString(); String fileNm = path.getFileName().toString();
String ext = FilenameUtils.getExtension(fileNm); String ext = FilenameUtils.getExtension(fileNm);
String parentFolderNm = path.getParent().getFileName().toString(); String parentFolderNm = path.getParent().getFileName().toString();
String parentPath = path.getParent().toString(); String parentPath = path.getParent().toString();
String fullPath = path.toAbsolutePath().toString(); String fullPath = path.toAbsolutePath().toString();
File file = new File(fullPath); File file = new File(fullPath);
long fileSize = file.length(); long fileSize = file.length();
String lastModified = dttmFormat.format(new Date(file.lastModified())); String lastModified = dttmFormat.format(new Date(file.lastModified()));
return new Basic(
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
})
.collect(Collectors.toList());
return new Basic(
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
})
.collect(Collectors.toList());
} catch (IOException e) { } catch (IOException e) {
System.err.println("파일 I/O 오류 발생: " + e.getMessage()); System.err.println("파일 I/O 오류 발생: " + e.getMessage());
@@ -297,7 +297,6 @@ public class FIleChecker {
return fileList; return fileList;
} }
public static Set<String> createExtensionSet(String extensionString) { public static Set<String> createExtensionSet(String extensionString) {
if (extensionString == null || extensionString.isBlank()) { if (extensionString == null || extensionString.isBlank()) {
return Set.of(); return Set.of();
@@ -305,10 +304,10 @@ public class FIleChecker {
// "java, class" -> ["java", " class"] -> [".java", ".class"] // "java, class" -> ["java", " class"] -> [".java", ".class"]
return Arrays.stream(extensionString.split(",")) return Arrays.stream(extensionString.split(","))
.map(ext -> ext.trim()) .map(ext -> ext.trim())
.filter(ext -> !ext.isEmpty()) .filter(ext -> !ext.isEmpty())
.map(ext -> "." + ext.toLowerCase()) .map(ext -> "." + ext.toLowerCase())
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
public static String extractExtension(Path path) { public static String extractExtension(Path path) {
@@ -328,17 +327,17 @@ public class FIleChecker {
// 파일 이름 비교 기본 Comparator (대소문자 무시) // 파일 이름 비교 기본 Comparator (대소문자 무시)
Comparator<Path> nameComparator = Comparator<Path> nameComparator =
Comparator.comparing(path -> path.getFileName().toString(), CASE_INSENSITIVE_ORDER); Comparator.comparing(path -> path.getFileName().toString(), CASE_INSENSITIVE_ORDER);
Comparator<Path> dateComparator = Comparator<Path> dateComparator =
Comparator.comparing( Comparator.comparing(
path -> { path -> {
try { try {
return Files.getLastModifiedTime(path); return Files.getLastModifiedTime(path);
} catch (IOException e) { } catch (IOException e) {
return FileTime.fromMillis(0); return FileTime.fromMillis(0);
} }
}); });
if ("name desc".equalsIgnoreCase(sortType)) { if ("name desc".equalsIgnoreCase(sortType)) {
return nameComparator.reversed(); return nameComparator.reversed();
@@ -350,5 +349,4 @@ public class FIleChecker {
return nameComparator; return nameComparator;
} }
} }
} }

View File

@@ -15,5 +15,4 @@ public class FileConfig {
private String rootSyncDir = "D:\\app\\original-images"; private String rootSyncDir = "D:\\app\\original-images";
// private String rootSyncDir = "/app/original-images"; // private String rootSyncDir = "/app/original-images";
} }

View File

@@ -1,25 +1,12 @@
package com.kamco.cd.kamcoback.postgres.core; package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity; import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity;
import com.kamco.cd.kamcoback.postgres.repository.scheduler.MapSheetMngFileJobRepository;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto; import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto.MngHstDto; import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto.MngHstDto;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
import com.kamco.cd.kamcoback.postgres.repository.scheduler.MapSheetMngFileJobRepository;
import jakarta.persistence.EntityNotFoundException;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -30,7 +17,7 @@ public class MapSheetMngFileJobCoreService {
private final MapSheetMngFileJobRepository mapSheetMngFileJobRepository; private final MapSheetMngFileJobRepository mapSheetMngFileJobRepository;
public Page<MapSheetMngDto.MngDto> findMapSheetMngList( public Page<MapSheetMngDto.MngDto> findMapSheetMngList(
MapSheetMngDto.@Valid MngSearchReq searchReq) { MapSheetMngDto.@Valid MngSearchReq searchReq) {
return mapSheetMngFileJobRepository.findMapSheetMngList(searchReq); return mapSheetMngFileJobRepository.findMapSheetMngList(searchReq);
} }
@@ -38,14 +25,14 @@ public class MapSheetMngFileJobCoreService {
return mapSheetMngFileJobRepository.findTargetMapSheetFileList(targetNum, pageSize); return mapSheetMngFileJobRepository.findTargetMapSheetFileList(targetNum, pageSize);
} }
public MapSheetMngDto.DmlReturn mngHstDataSyncStateUpdate(@Valid MapSheetMngDto.MngHstDto updateReq) { public MapSheetMngDto.DmlReturn mngHstDataSyncStateUpdate(
@Valid MapSheetMngDto.MngHstDto updateReq) {
mapSheetMngFileJobRepository.mngHstDataSyncStateUpdate(updateReq); mapSheetMngFileJobRepository.mngHstDataSyncStateUpdate(updateReq);
return new MapSheetMngDto.DmlReturn("success", updateReq.getHstUid()+""); return new MapSheetMngDto.DmlReturn("success", updateReq.getHstUid() + "");
} }
public MapSheetMngDto.DmlReturn mngFileSave(@Valid MapSheetMngDto.MngFileAddReq addReq) { public MapSheetMngDto.DmlReturn mngFileSave(@Valid MapSheetMngDto.MngFileAddReq addReq) {
MapSheetMngFileEntity entity = new MapSheetMngFileEntity(); MapSheetMngFileEntity entity = new MapSheetMngFileEntity();
@@ -60,9 +47,8 @@ public class MapSheetMngFileJobCoreService {
entity.setFileState(addReq.getFileState()); entity.setFileState(addReq.getFileState());
MapSheetMngFileEntity saved = mapSheetMngFileJobRepository.save(entity); MapSheetMngFileEntity saved = mapSheetMngFileJobRepository.save(entity);
//int hstCnt = mapSheetMngRepository.insertMapSheetOrgDataToMapSheetMngHst(saved.getMngYyyy()); // int hstCnt = mapSheetMngRepository.insertMapSheetOrgDataToMapSheetMngHst(saved.getMngYyyy());
return new MapSheetMngDto.DmlReturn("success", saved.getFileUid().toString()); return new MapSheetMngDto.DmlReturn("success", saved.getFileUid().toString());
} }
} }

View File

@@ -50,4 +50,9 @@ public class MapSheetMngFileEntity {
@Column(name = "file_size") @Column(name = "file_size")
private Long fileSize; private Long fileSize;
@Size(max = 20)
@Column(name = "file_state", length = 20)
private String fileState;
} }

View File

@@ -1,8 +1,6 @@
package com.kamco.cd.kamcoback.postgres.repository.scheduler; package com.kamco.cd.kamcoback.postgres.repository.scheduler;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity; import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity;
import com.kamco.cd.kamcoback.postgres.repository.mapsheet.MapSheetMngRepositoryCustom;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface MapSheetMngFileJobRepository public interface MapSheetMngFileJobRepository

View File

@@ -2,10 +2,7 @@ package com.kamco.cd.kamcoback.postgres.repository.scheduler;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto; import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto.MngHstDto; import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto.MngHstDto;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
import jakarta.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
public interface MapSheetMngFileJobRepositoryCustom { public interface MapSheetMngFileJobRepositoryCustom {
@@ -15,6 +12,4 @@ public interface MapSheetMngFileJobRepositoryCustom {
void mngHstDataSyncStateUpdate(MapSheetMngDto.MngHstDto updateReq); void mngHstDataSyncStateUpdate(MapSheetMngDto.MngHstDto updateReq);
List<MngHstDto> findTargetMapSheetFileList(long targetNum, int pageSize); List<MngHstDto> findTargetMapSheetFileList(long targetNum, int pageSize);
} }

View File

@@ -106,72 +106,63 @@ public class MapSheetMngFileJobRepositoryImpl extends QuerydslRepositorySupport
return new PageImpl<>(foundContent, pageable, countQuery); return new PageImpl<>(foundContent, pageable, countQuery);
} }
public void mngHstDataSyncStateUpdate(MapSheetMngDto.MngHstDto updateReq) { public void mngHstDataSyncStateUpdate(MapSheetMngDto.MngHstDto updateReq) {
if( updateReq.getSyncState().equals("DONE") ) { if (updateReq.getSyncState().equals("DONE")) {
long updateCount = long updateCount =
queryFactory queryFactory
.update(mapSheetMngHstEntity) .update(mapSheetMngHstEntity)
.set(mapSheetMngHstEntity.dataState, updateReq.getDataState()) .set(mapSheetMngHstEntity.dataState, updateReq.getDataState())
.set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now()) .set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now())
.set(mapSheetMngHstEntity.syncState, updateReq.getSyncState()) .set(mapSheetMngHstEntity.syncState, updateReq.getSyncState())
.set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now()) .set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now())
.where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid())) .where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid()))
.execute(); .execute();
} } else {
else {
long updateCount = long updateCount =
queryFactory queryFactory
.update(mapSheetMngHstEntity) .update(mapSheetMngHstEntity)
.set(mapSheetMngHstEntity.dataState, updateReq.getDataState()) .set(mapSheetMngHstEntity.dataState, updateReq.getDataState())
.set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now()) .set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now())
.set(mapSheetMngHstEntity.syncState, updateReq.getSyncState()) .set(mapSheetMngHstEntity.syncState, updateReq.getSyncState())
.set(mapSheetMngHstEntity.syncStrtDttm, ZonedDateTime.now()) .set(mapSheetMngHstEntity.syncStrtDttm, ZonedDateTime.now())
.set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now()) .set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now())
.where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid())) .where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid()))
.execute(); .execute();
} }
} }
@Override @Override
public List<MngHstDto> findTargetMapSheetFileList(long targetNum, int pageSize) public List<MngHstDto> findTargetMapSheetFileList(long targetNum, int pageSize) {
{ // Pageable pageable = searchReq.toPageable();
//Pageable pageable = searchReq.toPageable();
List<MngHstDto> foundContent = List<MngHstDto> foundContent =
queryFactory queryFactory
.select( .select(
Projections.constructor( Projections.constructor(
MngHstDto.class, MngHstDto.class,
mapSheetMngHstEntity.hstUid, mapSheetMngHstEntity.hstUid,
mapSheetMngHstEntity.mngYyyy, mapSheetMngHstEntity.mngYyyy,
mapSheetMngHstEntity.mapSheetNum, mapSheetMngHstEntity.mapSheetNum,
mapSheetMngHstEntity.refMapSheetNum, mapSheetMngHstEntity.refMapSheetNum,
mapSheetMngHstEntity.dataState, mapSheetMngHstEntity.dataState,
mapSheetMngHstEntity.syncState, mapSheetMngHstEntity.syncState,
mapSheetMngHstEntity.syncCheckState, mapSheetMngHstEntity.syncCheckState,
mapSheetMngHstEntity.syncStrtDttm, mapSheetMngHstEntity.syncStrtDttm,
mapSheetMngHstEntity.syncEndDttm, mapSheetMngHstEntity.syncEndDttm,
mapSheetMngHstEntity.syncCheckStrtDttm, mapSheetMngHstEntity.syncCheckStrtDttm,
mapSheetMngHstEntity.syncCheckEndDttm, mapSheetMngHstEntity.syncCheckEndDttm,
mapSheetMngEntity.mngPath))
mapSheetMngEntity.mngPath .from(mapSheetMngHstEntity)
)) .join(mapSheetMngEntity)
.from(mapSheetMngHstEntity) .on(mapSheetMngEntity.mngYyyy.eq(mapSheetMngHstEntity.mngYyyy))
.join(mapSheetMngEntity).on(mapSheetMngEntity.mngYyyy.eq(mapSheetMngHstEntity.mngYyyy)) .where(
.where( mapSheetMngHstEntity.syncState.eq("NOTYET"),
mapSheetMngHstEntity.syncState.eq("NOTYET"), mapSheetMngHstEntity.hstUid.mod(10L).eq(targetNum))
mapSheetMngHstEntity.hstUid.mod(10L).eq(targetNum) .limit(pageSize)
).limit(pageSize) .orderBy(mapSheetMngHstEntity.hstUid.asc())
.orderBy(mapSheetMngHstEntity.hstUid.asc()) .fetch();
.fetch();
return foundContent; return foundContent;
} }
} }

View File

@@ -11,7 +11,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -40,14 +39,11 @@ public class MapSheetMngFileJobApiController {
}) })
@PutMapping("/mng-sync-job") @PutMapping("/mng-sync-job")
public ApiResponseDto<String> mngSyncOnOff( public ApiResponseDto<String> mngSyncOnOff(
@RequestParam boolean jobStart, @RequestParam boolean jobStart, @RequestParam int pageSize) {
@RequestParam int pageSize) {
mapSheetMngFileJobController.setSchedulerEnabled(jobStart); mapSheetMngFileJobController.setSchedulerEnabled(jobStart);
mapSheetMngFileJobController.setMngSyncPageSize(pageSize); mapSheetMngFileJobController.setMngSyncPageSize(pageSize);
return ApiResponseDto.createOK("OK"); return ApiResponseDto.createOK("OK");
} }
} }

View File

@@ -13,15 +13,13 @@ public class MapSheetMngFileJobController {
private final MapSheetMngFileJobService mapSheetMngFileJobService; private final MapSheetMngFileJobService mapSheetMngFileJobService;
// 현재 상태 확인용 Getter // 현재 상태 확인용 Getter
@Getter @Getter private boolean isSchedulerEnabled = false;
private boolean isSchedulerEnabled = false; @Getter private int mngSyncPageSize = 20;
@Getter
private int mngSyncPageSize = 20;
// 매일 새벽 3시에 실행 (초 분 시 일 월 요일) // 매일 새벽 3시에 실행 (초 분 시 일 월 요일)
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob00() { public void mngFileSyncJob00() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(0, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(0, mngSyncPageSize);
@@ -29,7 +27,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob01() { public void mngFileSyncJob01() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob01 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob01 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(1, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(1, mngSyncPageSize);
@@ -37,7 +35,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob02() { public void mngFileSyncJob02() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(2, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(2, mngSyncPageSize);
@@ -45,7 +43,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob03() { public void mngFileSyncJob03() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob03 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob03 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(3, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(3, mngSyncPageSize);
@@ -53,7 +51,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob04() { public void mngFileSyncJob04() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob04 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob04 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(4, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(4, mngSyncPageSize);
@@ -61,7 +59,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob05() { public void mngFileSyncJob05() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob05 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob05 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(5, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(5, mngSyncPageSize);
@@ -69,7 +67,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob06() { public void mngFileSyncJob06() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob06 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob06 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(6, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(6, mngSyncPageSize);
@@ -77,7 +75,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob07() { public void mngFileSyncJob07() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob07 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob07 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(7, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(7, mngSyncPageSize);
@@ -85,7 +83,7 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob08() { public void mngFileSyncJob08() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob08 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob08 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(8, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(8, mngSyncPageSize);
@@ -93,24 +91,20 @@ public class MapSheetMngFileJobController {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5000)
public void mngFileSyncJob09() { public void mngFileSyncJob09() {
if( !isSchedulerEnabled ) return; if (!isSchedulerEnabled) return;
System.out.println("mngFileSyncJob09 === " + System.currentTimeMillis()); System.out.println("mngFileSyncJob09 === " + System.currentTimeMillis());
mapSheetMngFileJobService.checkMapSheetFileProcess(9, mngSyncPageSize); mapSheetMngFileJobService.checkMapSheetFileProcess(9, mngSyncPageSize);
} }
// 3. 외부에서 플래그를 변경할 수 있는 Setter 메서드 // 3. 외부에서 플래그를 변경할 수 있는 Setter 메서드
public void setSchedulerEnabled(boolean enabled) { public void setSchedulerEnabled(boolean enabled) {
this.isSchedulerEnabled = enabled; this.isSchedulerEnabled = enabled;
System.out.println("스케줄러 상태 변경됨: "+( enabled ? "ON" : "OFF")); System.out.println("스케줄러 상태 변경됨: " + (enabled ? "ON" : "OFF"));
} }
public void setMngSyncPageSize(int pageSize) { public void setMngSyncPageSize(int pageSize) {
this.mngSyncPageSize = pageSize; this.mngSyncPageSize = pageSize;
System.out.println("스케줄러 처리 개수 변경됨: "+pageSize); System.out.println("스케줄러 처리 개수 변경됨: " + pageSize);
} }
} }

View File

@@ -1,7 +1,6 @@
package com.kamco.cd.kamcoback.scheduler.dto; package com.kamco.cd.kamcoback.scheduler.dto;
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm; import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
import com.kamco.cd.kamcoback.config.enums.EnumType;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -10,7 +9,6 @@ import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
public class MapSheetMngDto { public class MapSheetMngDto {
@@ -78,7 +76,6 @@ public class MapSheetMngDto {
private String syncMngPath; private String syncMngPath;
} }
@Schema(name = "MngFileAddReq", description = "영상관리파일 등록 요청") @Schema(name = "MngFileAddReq", description = "영상관리파일 등록 요청")
@Getter @Getter
@Setter @Setter
@@ -113,9 +110,6 @@ public class MapSheetMngDto {
private Long fileSize; private Long fileSize;
} }
@Schema(name = "DmlReturn", description = "영상관리 DML 수행 후 리턴") @Schema(name = "DmlReturn", description = "영상관리 DML 수행 후 리턴")
@Getter @Getter
@Setter @Setter
@@ -125,5 +119,4 @@ public class MapSheetMngDto {
private String flag; private String flag;
private String message; private String message;
} }
} }

View File

@@ -2,19 +2,12 @@ package com.kamco.cd.kamcoback.scheduler.service;
import static java.lang.String.CASE_INSENSITIVE_ORDER; import static java.lang.String.CASE_INSENSITIVE_ORDER;
import com.kamco.cd.kamcoback.scheduler.dto.FileDto;
import com.kamco.cd.kamcoback.scheduler.dto.FileDto.FilesDto;
import com.kamco.cd.kamcoback.scheduler.dto.FileDto.SrchFilesDepthDto;
import com.kamco.cd.kamcoback.scheduler.dto.FileDto.SrchFilesDto;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto.MngDto;
import com.kamco.cd.kamcoback.postgres.core.MapSheetMngFileJobCoreService;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto.MngHstDto;
import com.kamco.cd.kamcoback.common.utils.FIleChecker; import com.kamco.cd.kamcoback.common.utils.FIleChecker;
import com.kamco.cd.kamcoback.common.utils.NameValidator; import com.kamco.cd.kamcoback.postgres.core.MapSheetMngFileJobCoreService;
import com.kamco.cd.kamcoback.config.FileConfig; import com.kamco.cd.kamcoback.scheduler.dto.FileDto;
import com.kamco.cd.kamcoback.scheduler.dto.FileDto.SrchFilesDepthDto;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.scheduler.dto.MapSheetMngDto.MngHstDto;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@@ -34,7 +27,6 @@ import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@@ -59,45 +51,56 @@ public class MapSheetMngFileJobService {
for (MngHstDto item : mapSheetFileNotYetList) { for (MngHstDto item : mapSheetFileNotYetList) {
//도엽별 파일 체크 진행중으로 변경 // 도엽별 파일 체크 진행중으로 변경
item.setDataState("PROCESSING"); item.setDataState("PROCESSING");
mngHstDataSyncStateUpdate(item); mngHstDataSyncStateUpdate(item);
// 1. MngHstDto 객체의 필드 값에 접근 // 1. MngHstDto 객체의 필드 값에 접근
//hstUid = item.getHstUid(); // hstUid = item.getHstUid();
//syncState = item.getSyncState(); // syncState = item.getSyncState();
srchDto.setMaxDepth(10); srchDto.setMaxDepth(10);
srchDto.setDirPath(item.getSyncMngPath()); srchDto.setDirPath(item.getSyncMngPath());
srchDto.setExtension("tif,tfw"); srchDto.setExtension("tif,tfw");
srchDto.setFileNm(item.getMapSheetNum()); srchDto.setFileNm(item.getMapSheetNum());
//srchDto.setFileNm("34602047"); // srchDto.setFileNm("34602047");
System.out.println("UID: " + hstUid + ", 상태: " + syncState + ", 관리경로: " + item.getSyncMngPath() + ", 파일명 " + item.getMapSheetNum() + " .tif,tfw"); System.out.println(
"UID: "
+ hstUid
+ ", 상태: "
+ syncState
+ ", 관리경로: "
+ item.getSyncMngPath()
+ ", 파일명 "
+ item.getMapSheetNum()
+ " .tif,tfw");
//도엽번호로 파일 찾기 // 도엽번호로 파일 찾기
//basicList = this.getFilesDepthAll(srchDto); // basicList = this.getFilesDepthAll(srchDto);
basicList = FIleChecker.getFilesFromAllDepth(srchDto.getDirPath(), srchDto.getFileNm(),
srchDto.getExtension(), srchDto.getMaxDepth(), srchDto.getSortType(), 0, 100);
basicList =
FIleChecker.getFilesFromAllDepth(
srchDto.getDirPath(),
srchDto.getFileNm(),
srchDto.getExtension(),
srchDto.getMaxDepth(),
srchDto.getSortType(),
0,
100);
int tfwCnt = int tfwCnt =
(int) (int)
basicList.stream() basicList.stream().filter(dto -> dto.getExtension().toString().equals("tfw")).count();
.filter(dto -> dto.getExtension().toString().equals("tfw"))
.count();
int tifCnt = int tifCnt =
(int) (int)
basicList.stream() basicList.stream().filter(dto -> dto.getExtension().toString().equals("tif")).count();
.filter(dto -> dto.getExtension().toString().equals("tif"))
.count();
syncState = ""; syncState = "";
syncCheckState = ""; syncCheckState = "";
if( tfwCnt == 0 && tifCnt == 0)syncState="NOFILE"; if (tfwCnt == 0 && tifCnt == 0) syncState = "NOFILE";
for (FIleChecker.Basic item2 : basicList) { for (FIleChecker.Basic item2 : basicList) {
System.out.println("path: " + item2.getParentPath()); System.out.println("path: " + item2.getParentPath());
@@ -115,47 +118,59 @@ public class MapSheetMngFileJobService {
addReq.setHstUid(item.getHstUid()); addReq.setHstUid(item.getHstUid());
fileState = "DONE"; fileState = "DONE";
if(item2.getExtension().equals("tfw") ) { if (item2.getExtension().equals("tfw")) {
if( tifCnt == 0){fileState = "NOTPAIR";syncState = fileState;} if (tifCnt == 0) {
else if( tfwCnt > 1){fileState = "DUPLICATE";syncState = fileState;} fileState = "NOTPAIR";
else if( item2.getFileSize() == 0 ){fileState = "SIZEERROR";syncState = fileState;} syncState = fileState;
else if( ! FIleChecker.checkTfw(item2.getFullPath()) ){fileState = "TYPEERROR";syncState = fileState;} } else if (tfwCnt > 1) {
} fileState = "DUPLICATE";
else if(item2.getExtension().equals("tif") ){ syncState = fileState;
if( tfwCnt == 0){fileState = "NOTPAIR";syncState = fileState;} } else if (item2.getFileSize() == 0) {
else if( tifCnt > 1){fileState = "DUPLICATE";syncState = fileState;} fileState = "SIZEERROR";
else if( item2.getFileSize() == 0 ){fileState = "SIZEERROR";syncState = fileState;} syncState = fileState;
else if( ! FIleChecker.cmmndGdalInfo(item2.getFullPath()) ){fileState = "TYPEERROR";syncState = fileState;} } else if (!FIleChecker.checkTfw(item2.getFullPath())) {
fileState = "TYPEERROR";
syncState = fileState;
}
} else if (item2.getExtension().equals("tif")) {
if (tfwCnt == 0) {
fileState = "NOTPAIR";
syncState = fileState;
} else if (tifCnt > 1) {
fileState = "DUPLICATE";
syncState = fileState;
} else if (item2.getFileSize() == 0) {
fileState = "SIZEERROR";
syncState = fileState;
} else if (!FIleChecker.cmmndGdalInfo(item2.getFullPath())) {
fileState = "TYPEERROR";
syncState = fileState;
}
} }
addReq.setFileState(fileState); addReq.setFileState(fileState);
MapSheetMngDto.DmlReturn DmlReturn = mngDataSave(addReq); MapSheetMngDto.DmlReturn DmlReturn = mngDataSave(addReq);
} }
//도엽별 파일 체크 완료로 변경 // 도엽별 파일 체크 완료로 변경
item.setDataState("DONE"); item.setDataState("DONE");
if(syncState.isEmpty())syncState="DONE"; if (syncState.isEmpty()) syncState = "DONE";
item.setSyncState(syncState); item.setSyncState(syncState);
mngHstDataSyncStateUpdate(item); mngHstDataSyncStateUpdate(item);
//srchDto. // srchDto.
// 2. 출력 // 2. 출력
//System.out.println("UID: " + hstUid + ", 상태: " + syncState + ", 관리경로: " + item.getSyncMngPath()); // System.out.println("UID: " + hstUid + ", 상태: " + syncState + ", 관리경로: " +
// item.getSyncMngPath());
// 3. (필요하다면) 다른 로직 수행 // 3. (필요하다면) 다른 로직 수행
// ... // ...
} }
} }
public int checkIsNoFile(List<FileDto.Basic> basicList) public int checkIsNoFile(List<FileDto.Basic> basicList) {
{ if (basicList == null || basicList.size() == 0) {
if( basicList == null || basicList.size() == 0 )
{
return 0; return 0;
} }
@@ -174,7 +189,6 @@ public class MapSheetMngFileJobService {
return mapSheetMngFileJobCoreService.mngFileSave(AddReq); return mapSheetMngFileJobCoreService.mngFileSave(AddReq);
} }
public List<FileDto.Basic> getFilesDepthAll(SrchFilesDepthDto srchDto) { public List<FileDto.Basic> getFilesDepthAll(SrchFilesDepthDto srchDto) {
Path startPath = Paths.get(srchDto.getDirPath()); Path startPath = Paths.get(srchDto.getDirPath());
@@ -199,41 +213,39 @@ public class MapSheetMngFileJobService {
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) { try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
fileDtoList = fileDtoList =
stream stream
.filter(Files::isRegularFile) .filter(Files::isRegularFile)
.filter( .filter(
p -> p ->
extension == null extension == null
|| extension.equals("") || extension.equals("")
|| extension.equals("*") || extension.equals("*")
|| targetExtensions.contains(extractExtension(p))) || targetExtensions.contains(extractExtension(p)))
.sorted(getFileComparator(sortType)) .sorted(getFileComparator(sortType))
.filter( .filter(p -> p.getFileName().toString().contains(targetFileNm))
p -> p.getFileName().toString().contains(targetFileNm) .skip(startPos)
) .limit(limit)
.skip(startPos) .map(
.limit(limit) path -> {
.map( int depth = path.getNameCount();
path -> {
int depth = path.getNameCount();
String fileNm = path.getFileName().toString(); String fileNm = path.getFileName().toString();
String ext = FilenameUtils.getExtension(fileNm); String ext = FilenameUtils.getExtension(fileNm);
String parentFolderNm = path.getParent().getFileName().toString(); String parentFolderNm = path.getParent().getFileName().toString();
String parentPath = path.getParent().toString(); String parentPath = path.getParent().toString();
String fullPath = path.toAbsolutePath().toString(); String fullPath = path.toAbsolutePath().toString();
File file = new File(fullPath); File file = new File(fullPath);
long fileSize = file.length(); long fileSize = file.length();
String lastModified = dttmFormat.format(new Date(file.lastModified())); String lastModified = dttmFormat.format(new Date(file.lastModified()));
return new FileDto.Basic( return new FileDto.Basic(
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified); fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
//fileTotCnt = fileDtoList.size(); // fileTotCnt = fileDtoList.size();
//fileTotSize = fileDtoList.stream().mapToLong(FileDto.Basic::getFileSize).sum(); // fileTotSize = fileDtoList.stream().mapToLong(FileDto.Basic::getFileSize).sum();
} catch (IOException e) { } catch (IOException e) {
System.err.println("파일 I/O 오류 발생: " + e.getMessage()); System.err.println("파일 I/O 오류 발생: " + e.getMessage());
@@ -242,7 +254,6 @@ public class MapSheetMngFileJobService {
return fileDtoList; return fileDtoList;
} }
public Set<String> createExtensionSet(String extensionString) { public Set<String> createExtensionSet(String extensionString) {
if (extensionString == null || extensionString.isBlank()) { if (extensionString == null || extensionString.isBlank()) {
return Set.of(); return Set.of();
@@ -250,10 +261,10 @@ public class MapSheetMngFileJobService {
// "java, class" -> ["java", " class"] -> [".java", ".class"] // "java, class" -> ["java", " class"] -> [".java", ".class"]
return Arrays.stream(extensionString.split(",")) return Arrays.stream(extensionString.split(","))
.map(ext -> ext.trim()) .map(ext -> ext.trim())
.filter(ext -> !ext.isEmpty()) .filter(ext -> !ext.isEmpty())
.map(ext -> "." + ext.toLowerCase()) .map(ext -> "." + ext.toLowerCase())
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
public String extractExtension(Path path) { public String extractExtension(Path path) {
@@ -273,17 +284,17 @@ public class MapSheetMngFileJobService {
// 파일 이름 비교 기본 Comparator (대소문자 무시) // 파일 이름 비교 기본 Comparator (대소문자 무시)
Comparator<Path> nameComparator = Comparator<Path> nameComparator =
Comparator.comparing(path -> path.getFileName().toString(), CASE_INSENSITIVE_ORDER); Comparator.comparing(path -> path.getFileName().toString(), CASE_INSENSITIVE_ORDER);
Comparator<Path> dateComparator = Comparator<Path> dateComparator =
Comparator.comparing( Comparator.comparing(
path -> { path -> {
try { try {
return Files.getLastModifiedTime(path); return Files.getLastModifiedTime(path);
} catch (IOException e) { } catch (IOException e) {
return FileTime.fromMillis(0); return FileTime.fromMillis(0);
} }
}); });
if ("name desc".equalsIgnoreCase(sortType)) { if ("name desc".equalsIgnoreCase(sortType)) {
return nameComparator.reversed(); return nameComparator.reversed();
@@ -295,5 +306,4 @@ public class MapSheetMngFileJobService {
return nameComparator; return nameComparator;
} }
} }
} }