영상관리파일싱크 추가
This commit is contained in:
@@ -2,7 +2,6 @@ package com.kamco.cd.kamcoback.common.utils;
|
||||
|
||||
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 java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -162,7 +161,7 @@ public class FIleChecker {
|
||||
// 윈도우용
|
||||
|
||||
command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
|
||||
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
|
||||
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
|
||||
command.add("gdalinfo");
|
||||
command.add(filePath);
|
||||
command.add("|");
|
||||
@@ -207,7 +206,6 @@ public class FIleChecker {
|
||||
return hasDriver;
|
||||
}
|
||||
|
||||
|
||||
@Schema(name = "File Basic", description = "파일 기본 정보")
|
||||
@Getter
|
||||
public static class Basic {
|
||||
@@ -221,13 +219,13 @@ public class FIleChecker {
|
||||
private final String lastModified;
|
||||
|
||||
public Basic(
|
||||
String fileNm,
|
||||
String parentFolderNm,
|
||||
String parentPath,
|
||||
String fullPath,
|
||||
String extension,
|
||||
long fileSize,
|
||||
String lastModified) {
|
||||
String fileNm,
|
||||
String parentFolderNm,
|
||||
String parentPath,
|
||||
String fullPath,
|
||||
String extension,
|
||||
long fileSize,
|
||||
String lastModified) {
|
||||
this.fileNm = fileNm;
|
||||
this.parentFolderNm = parentFolderNm;
|
||||
this.parentPath = parentPath;
|
||||
@@ -238,9 +236,14 @@ public class FIleChecker {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<Basic> getFilesFromAllDepth(String dir, String targetFileNm, String extension, int maxDepth, String sortType, int startPos, int limit) {
|
||||
public static List<Basic> getFilesFromAllDepth(
|
||||
String dir,
|
||||
String targetFileNm,
|
||||
String extension,
|
||||
int maxDepth,
|
||||
String sortType,
|
||||
int startPos,
|
||||
int limit) {
|
||||
|
||||
Path startPath = Paths.get(dir);
|
||||
String dirPath = dir;
|
||||
@@ -256,39 +259,36 @@ public class FIleChecker {
|
||||
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
|
||||
|
||||
fileList =
|
||||
stream
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(
|
||||
p ->
|
||||
extension == null
|
||||
|| extension.equals("")
|
||||
|| extension.equals("*")
|
||||
|| targetExtensions.contains(extractExtension(p)))
|
||||
.sorted(getFileComparator(sortType))
|
||||
.filter(
|
||||
p -> p.getFileName().toString().contains(targetFileNm)
|
||||
)
|
||||
.skip(startPos)
|
||||
.limit(limit)
|
||||
.map(
|
||||
path -> {
|
||||
//int depth = path.getNameCount();
|
||||
stream
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(
|
||||
p ->
|
||||
extension == null
|
||||
|| extension.equals("")
|
||||
|| extension.equals("*")
|
||||
|| targetExtensions.contains(extractExtension(p)))
|
||||
.sorted(getFileComparator(sortType))
|
||||
.filter(p -> p.getFileName().toString().contains(targetFileNm))
|
||||
.skip(startPos)
|
||||
.limit(limit)
|
||||
.map(
|
||||
path -> {
|
||||
// int depth = path.getNameCount();
|
||||
|
||||
String fileNm = path.getFileName().toString();
|
||||
String ext = FilenameUtils.getExtension(fileNm);
|
||||
String parentFolderNm = path.getParent().getFileName().toString();
|
||||
String parentPath = path.getParent().toString();
|
||||
String fullPath = path.toAbsolutePath().toString();
|
||||
String fileNm = path.getFileName().toString();
|
||||
String ext = FilenameUtils.getExtension(fileNm);
|
||||
String parentFolderNm = path.getParent().getFileName().toString();
|
||||
String parentPath = path.getParent().toString();
|
||||
String fullPath = path.toAbsolutePath().toString();
|
||||
|
||||
File file = new File(fullPath);
|
||||
long fileSize = file.length();
|
||||
String lastModified = dttmFormat.format(new Date(file.lastModified()));
|
||||
|
||||
return new Basic(
|
||||
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
File file = new File(fullPath);
|
||||
long fileSize = file.length();
|
||||
String lastModified = dttmFormat.format(new Date(file.lastModified()));
|
||||
|
||||
return new Basic(
|
||||
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("파일 I/O 오류 발생: " + e.getMessage());
|
||||
@@ -297,7 +297,6 @@ public class FIleChecker {
|
||||
return fileList;
|
||||
}
|
||||
|
||||
|
||||
public static Set<String> createExtensionSet(String extensionString) {
|
||||
if (extensionString == null || extensionString.isBlank()) {
|
||||
return Set.of();
|
||||
@@ -305,10 +304,10 @@ public class FIleChecker {
|
||||
|
||||
// "java, class" -> ["java", " class"] -> [".java", ".class"]
|
||||
return Arrays.stream(extensionString.split(","))
|
||||
.map(ext -> ext.trim())
|
||||
.filter(ext -> !ext.isEmpty())
|
||||
.map(ext -> "." + ext.toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
.map(ext -> ext.trim())
|
||||
.filter(ext -> !ext.isEmpty())
|
||||
.map(ext -> "." + ext.toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static String extractExtension(Path path) {
|
||||
@@ -328,17 +327,17 @@ public class FIleChecker {
|
||||
|
||||
// 파일 이름 비교 기본 Comparator (대소문자 무시)
|
||||
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.comparing(
|
||||
path -> {
|
||||
try {
|
||||
return Files.getLastModifiedTime(path);
|
||||
} catch (IOException e) {
|
||||
return FileTime.fromMillis(0);
|
||||
}
|
||||
});
|
||||
Comparator.comparing(
|
||||
path -> {
|
||||
try {
|
||||
return Files.getLastModifiedTime(path);
|
||||
} catch (IOException e) {
|
||||
return FileTime.fromMillis(0);
|
||||
}
|
||||
});
|
||||
|
||||
if ("name desc".equalsIgnoreCase(sortType)) {
|
||||
return nameComparator.reversed();
|
||||
@@ -350,5 +349,4 @@ public class FIleChecker {
|
||||
return nameComparator;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,5 +15,4 @@ public class FileConfig {
|
||||
private String rootSyncDir = "D:\\app\\original-images";
|
||||
// private String rootSyncDir = "/app/original-images";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,12 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
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.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 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.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -30,7 +17,7 @@ public class MapSheetMngFileJobCoreService {
|
||||
private final MapSheetMngFileJobRepository mapSheetMngFileJobRepository;
|
||||
|
||||
public Page<MapSheetMngDto.MngDto> findMapSheetMngList(
|
||||
MapSheetMngDto.@Valid MngSearchReq searchReq) {
|
||||
MapSheetMngDto.@Valid MngSearchReq searchReq) {
|
||||
return mapSheetMngFileJobRepository.findMapSheetMngList(searchReq);
|
||||
}
|
||||
|
||||
@@ -38,14 +25,14 @@ public class MapSheetMngFileJobCoreService {
|
||||
return mapSheetMngFileJobRepository.findTargetMapSheetFileList(targetNum, pageSize);
|
||||
}
|
||||
|
||||
public MapSheetMngDto.DmlReturn mngHstDataSyncStateUpdate(@Valid MapSheetMngDto.MngHstDto updateReq) {
|
||||
public MapSheetMngDto.DmlReturn mngHstDataSyncStateUpdate(
|
||||
@Valid MapSheetMngDto.MngHstDto 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) {
|
||||
|
||||
MapSheetMngFileEntity entity = new MapSheetMngFileEntity();
|
||||
@@ -60,9 +47,8 @@ public class MapSheetMngFileJobCoreService {
|
||||
entity.setFileState(addReq.getFileState());
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,4 +50,9 @@ public class MapSheetMngFileEntity {
|
||||
|
||||
@Column(name = "file_size")
|
||||
private Long fileSize;
|
||||
|
||||
@Size(max = 20)
|
||||
@Column(name = "file_state", length = 20)
|
||||
private String fileState;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
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.repository.mapsheet.MapSheetMngRepositoryCustom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface MapSheetMngFileJobRepository
|
||||
|
||||
@@ -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.MngHstDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface MapSheetMngFileJobRepositoryCustom {
|
||||
@@ -15,6 +12,4 @@ public interface MapSheetMngFileJobRepositoryCustom {
|
||||
void mngHstDataSyncStateUpdate(MapSheetMngDto.MngHstDto updateReq);
|
||||
|
||||
List<MngHstDto> findTargetMapSheetFileList(long targetNum, int pageSize);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -106,72 +106,63 @@ public class MapSheetMngFileJobRepositoryImpl extends QuerydslRepositorySupport
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
}
|
||||
|
||||
|
||||
public void mngHstDataSyncStateUpdate(MapSheetMngDto.MngHstDto updateReq) {
|
||||
|
||||
if( updateReq.getSyncState().equals("DONE") ) {
|
||||
if (updateReq.getSyncState().equals("DONE")) {
|
||||
long updateCount =
|
||||
queryFactory
|
||||
.update(mapSheetMngHstEntity)
|
||||
.set(mapSheetMngHstEntity.dataState, updateReq.getDataState())
|
||||
.set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now())
|
||||
.set(mapSheetMngHstEntity.syncState, updateReq.getSyncState())
|
||||
.set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now())
|
||||
.where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid()))
|
||||
.execute();
|
||||
}
|
||||
else {
|
||||
queryFactory
|
||||
.update(mapSheetMngHstEntity)
|
||||
.set(mapSheetMngHstEntity.dataState, updateReq.getDataState())
|
||||
.set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now())
|
||||
.set(mapSheetMngHstEntity.syncState, updateReq.getSyncState())
|
||||
.set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now())
|
||||
.where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid()))
|
||||
.execute();
|
||||
} else {
|
||||
long updateCount =
|
||||
queryFactory
|
||||
.update(mapSheetMngHstEntity)
|
||||
.set(mapSheetMngHstEntity.dataState, updateReq.getDataState())
|
||||
.set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now())
|
||||
.set(mapSheetMngHstEntity.syncState, updateReq.getSyncState())
|
||||
.set(mapSheetMngHstEntity.syncStrtDttm, ZonedDateTime.now())
|
||||
.set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now())
|
||||
.where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid()))
|
||||
.execute();
|
||||
queryFactory
|
||||
.update(mapSheetMngHstEntity)
|
||||
.set(mapSheetMngHstEntity.dataState, updateReq.getDataState())
|
||||
.set(mapSheetMngHstEntity.dataStateDttm, ZonedDateTime.now())
|
||||
.set(mapSheetMngHstEntity.syncState, updateReq.getSyncState())
|
||||
.set(mapSheetMngHstEntity.syncStrtDttm, ZonedDateTime.now())
|
||||
.set(mapSheetMngHstEntity.syncEndDttm, ZonedDateTime.now())
|
||||
.where(mapSheetMngHstEntity.hstUid.eq(updateReq.getHstUid()))
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<MngHstDto> findTargetMapSheetFileList(long targetNum, int pageSize)
|
||||
{
|
||||
//Pageable pageable = searchReq.toPageable();
|
||||
public List<MngHstDto> findTargetMapSheetFileList(long targetNum, int pageSize) {
|
||||
// Pageable pageable = searchReq.toPageable();
|
||||
|
||||
List<MngHstDto> foundContent =
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
MngHstDto.class,
|
||||
mapSheetMngHstEntity.hstUid,
|
||||
mapSheetMngHstEntity.mngYyyy,
|
||||
mapSheetMngHstEntity.mapSheetNum,
|
||||
mapSheetMngHstEntity.refMapSheetNum,
|
||||
mapSheetMngHstEntity.dataState,
|
||||
mapSheetMngHstEntity.syncState,
|
||||
mapSheetMngHstEntity.syncCheckState,
|
||||
mapSheetMngHstEntity.syncStrtDttm,
|
||||
mapSheetMngHstEntity.syncEndDttm,
|
||||
mapSheetMngHstEntity.syncCheckStrtDttm,
|
||||
mapSheetMngHstEntity.syncCheckEndDttm,
|
||||
|
||||
mapSheetMngEntity.mngPath
|
||||
))
|
||||
.from(mapSheetMngHstEntity)
|
||||
.join(mapSheetMngEntity).on(mapSheetMngEntity.mngYyyy.eq(mapSheetMngHstEntity.mngYyyy))
|
||||
.where(
|
||||
mapSheetMngHstEntity.syncState.eq("NOTYET"),
|
||||
mapSheetMngHstEntity.hstUid.mod(10L).eq(targetNum)
|
||||
).limit(pageSize)
|
||||
.orderBy(mapSheetMngHstEntity.hstUid.asc())
|
||||
.fetch();
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
MngHstDto.class,
|
||||
mapSheetMngHstEntity.hstUid,
|
||||
mapSheetMngHstEntity.mngYyyy,
|
||||
mapSheetMngHstEntity.mapSheetNum,
|
||||
mapSheetMngHstEntity.refMapSheetNum,
|
||||
mapSheetMngHstEntity.dataState,
|
||||
mapSheetMngHstEntity.syncState,
|
||||
mapSheetMngHstEntity.syncCheckState,
|
||||
mapSheetMngHstEntity.syncStrtDttm,
|
||||
mapSheetMngHstEntity.syncEndDttm,
|
||||
mapSheetMngHstEntity.syncCheckStrtDttm,
|
||||
mapSheetMngHstEntity.syncCheckEndDttm,
|
||||
mapSheetMngEntity.mngPath))
|
||||
.from(mapSheetMngHstEntity)
|
||||
.join(mapSheetMngEntity)
|
||||
.on(mapSheetMngEntity.mngYyyy.eq(mapSheetMngHstEntity.mngYyyy))
|
||||
.where(
|
||||
mapSheetMngHstEntity.syncState.eq("NOTYET"),
|
||||
mapSheetMngHstEntity.hstUid.mod(10L).eq(targetNum))
|
||||
.limit(pageSize)
|
||||
.orderBy(mapSheetMngHstEntity.hstUid.asc())
|
||||
.fetch();
|
||||
|
||||
return foundContent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -40,14 +39,11 @@ public class MapSheetMngFileJobApiController {
|
||||
})
|
||||
@PutMapping("/mng-sync-job")
|
||||
public ApiResponseDto<String> mngSyncOnOff(
|
||||
@RequestParam boolean jobStart,
|
||||
@RequestParam int pageSize) {
|
||||
@RequestParam boolean jobStart, @RequestParam int pageSize) {
|
||||
|
||||
mapSheetMngFileJobController.setSchedulerEnabled(jobStart);
|
||||
mapSheetMngFileJobController.setMngSyncPageSize(pageSize);
|
||||
|
||||
return ApiResponseDto.createOK("OK");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,15 +13,13 @@ public class MapSheetMngFileJobController {
|
||||
private final MapSheetMngFileJobService mapSheetMngFileJobService;
|
||||
|
||||
// 현재 상태 확인용 Getter
|
||||
@Getter
|
||||
private boolean isSchedulerEnabled = false;
|
||||
@Getter
|
||||
private int mngSyncPageSize = 20;
|
||||
@Getter private boolean isSchedulerEnabled = false;
|
||||
@Getter private int mngSyncPageSize = 20;
|
||||
|
||||
// 매일 새벽 3시에 실행 (초 분 시 일 월 요일)
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob00() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(0, mngSyncPageSize);
|
||||
@@ -29,7 +27,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob01() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob01 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(1, mngSyncPageSize);
|
||||
@@ -37,7 +35,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob02() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(2, mngSyncPageSize);
|
||||
@@ -45,7 +43,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob03() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob03 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(3, mngSyncPageSize);
|
||||
@@ -53,7 +51,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob04() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob04 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(4, mngSyncPageSize);
|
||||
@@ -61,7 +59,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob05() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob05 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(5, mngSyncPageSize);
|
||||
@@ -69,7 +67,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob06() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob06 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(6, mngSyncPageSize);
|
||||
@@ -77,7 +75,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob07() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob07 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(7, mngSyncPageSize);
|
||||
@@ -85,7 +83,7 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob08() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob08 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(8, mngSyncPageSize);
|
||||
@@ -93,24 +91,20 @@ public class MapSheetMngFileJobController {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void mngFileSyncJob09() {
|
||||
if( !isSchedulerEnabled ) return;
|
||||
if (!isSchedulerEnabled) return;
|
||||
|
||||
System.out.println("mngFileSyncJob09 === " + System.currentTimeMillis());
|
||||
mapSheetMngFileJobService.checkMapSheetFileProcess(9, mngSyncPageSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 3. 외부에서 플래그를 변경할 수 있는 Setter 메서드
|
||||
public void setSchedulerEnabled(boolean enabled) {
|
||||
this.isSchedulerEnabled = enabled;
|
||||
System.out.println("스케줄러 상태 변경됨: "+( enabled ? "ON" : "OFF"));
|
||||
System.out.println("스케줄러 상태 변경됨: " + (enabled ? "ON" : "OFF"));
|
||||
}
|
||||
|
||||
public void setMngSyncPageSize(int pageSize) {
|
||||
this.mngSyncPageSize = pageSize;
|
||||
System.out.println("스케줄러 처리 개수 변경됨: "+pageSize);
|
||||
System.out.println("스케줄러 처리 개수 변경됨: " + pageSize);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.scheduler.dto;
|
||||
|
||||
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 java.time.ZonedDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -10,7 +9,6 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
public class MapSheetMngDto {
|
||||
|
||||
@@ -78,7 +76,6 @@ public class MapSheetMngDto {
|
||||
private String syncMngPath;
|
||||
}
|
||||
|
||||
|
||||
@Schema(name = "MngFileAddReq", description = "영상관리파일 등록 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -113,9 +110,6 @@ public class MapSheetMngDto {
|
||||
private Long fileSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Schema(name = "DmlReturn", description = "영상관리 DML 수행 후 리턴")
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -125,5 +119,4 @@ public class MapSheetMngDto {
|
||||
private String flag;
|
||||
private String message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,19 +2,12 @@ package com.kamco.cd.kamcoback.scheduler.service;
|
||||
|
||||
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.NameValidator;
|
||||
import com.kamco.cd.kamcoback.config.FileConfig;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MapSheetMngFileJobCoreService;
|
||||
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.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -34,7 +27,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -59,45 +51,56 @@ public class MapSheetMngFileJobService {
|
||||
|
||||
for (MngHstDto item : mapSheetFileNotYetList) {
|
||||
|
||||
//도엽별 파일 체크 진행중으로 변경
|
||||
// 도엽별 파일 체크 진행중으로 변경
|
||||
item.setDataState("PROCESSING");
|
||||
mngHstDataSyncStateUpdate(item);
|
||||
|
||||
// 1. MngHstDto 객체의 필드 값에 접근
|
||||
//hstUid = item.getHstUid();
|
||||
//syncState = item.getSyncState();
|
||||
// hstUid = item.getHstUid();
|
||||
// syncState = item.getSyncState();
|
||||
|
||||
srchDto.setMaxDepth(10);
|
||||
srchDto.setDirPath(item.getSyncMngPath());
|
||||
srchDto.setExtension("tif,tfw");
|
||||
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 = FIleChecker.getFilesFromAllDepth(srchDto.getDirPath(), srchDto.getFileNm(),
|
||||
srchDto.getExtension(), srchDto.getMaxDepth(), srchDto.getSortType(), 0, 100);
|
||||
// 도엽번호로 파일 찾기
|
||||
// basicList = this.getFilesDepthAll(srchDto);
|
||||
|
||||
basicList =
|
||||
FIleChecker.getFilesFromAllDepth(
|
||||
srchDto.getDirPath(),
|
||||
srchDto.getFileNm(),
|
||||
srchDto.getExtension(),
|
||||
srchDto.getMaxDepth(),
|
||||
srchDto.getSortType(),
|
||||
0,
|
||||
100);
|
||||
|
||||
int tfwCnt =
|
||||
(int)
|
||||
basicList.stream()
|
||||
.filter(dto -> dto.getExtension().toString().equals("tfw"))
|
||||
.count();
|
||||
(int)
|
||||
basicList.stream().filter(dto -> dto.getExtension().toString().equals("tfw")).count();
|
||||
|
||||
int tifCnt =
|
||||
(int)
|
||||
basicList.stream()
|
||||
.filter(dto -> dto.getExtension().toString().equals("tif"))
|
||||
.count();
|
||||
(int)
|
||||
basicList.stream().filter(dto -> dto.getExtension().toString().equals("tif")).count();
|
||||
|
||||
syncState = "";
|
||||
syncCheckState = "";
|
||||
|
||||
if( tfwCnt == 0 && tifCnt == 0)syncState="NOFILE";
|
||||
if (tfwCnt == 0 && tifCnt == 0) syncState = "NOFILE";
|
||||
|
||||
for (FIleChecker.Basic item2 : basicList) {
|
||||
System.out.println("path: " + item2.getParentPath());
|
||||
@@ -115,47 +118,59 @@ public class MapSheetMngFileJobService {
|
||||
addReq.setHstUid(item.getHstUid());
|
||||
|
||||
fileState = "DONE";
|
||||
if(item2.getExtension().equals("tfw") ) {
|
||||
if( tifCnt == 0){fileState = "NOTPAIR";syncState = fileState;}
|
||||
else if( tfwCnt > 1){fileState = "DUPLICATE";syncState = fileState;}
|
||||
else if( item2.getFileSize() == 0 ){fileState = "SIZEERROR";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;}
|
||||
if (item2.getExtension().equals("tfw")) {
|
||||
if (tifCnt == 0) {
|
||||
fileState = "NOTPAIR";
|
||||
syncState = fileState;
|
||||
} else if (tfwCnt > 1) {
|
||||
fileState = "DUPLICATE";
|
||||
syncState = fileState;
|
||||
} else if (item2.getFileSize() == 0) {
|
||||
fileState = "SIZEERROR";
|
||||
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);
|
||||
MapSheetMngDto.DmlReturn DmlReturn = mngDataSave(addReq);
|
||||
|
||||
}
|
||||
|
||||
//도엽별 파일 체크 완료로 변경
|
||||
// 도엽별 파일 체크 완료로 변경
|
||||
item.setDataState("DONE");
|
||||
if(syncState.isEmpty())syncState="DONE";
|
||||
if (syncState.isEmpty()) syncState = "DONE";
|
||||
item.setSyncState(syncState);
|
||||
mngHstDataSyncStateUpdate(item);
|
||||
|
||||
//srchDto.
|
||||
// srchDto.
|
||||
|
||||
// 2. 출력
|
||||
//System.out.println("UID: " + hstUid + ", 상태: " + syncState + ", 관리경로: " + item.getSyncMngPath());
|
||||
// System.out.println("UID: " + hstUid + ", 상태: " + syncState + ", 관리경로: " +
|
||||
// item.getSyncMngPath());
|
||||
|
||||
// 3. (필요하다면) 다른 로직 수행
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int checkIsNoFile(List<FileDto.Basic> basicList)
|
||||
{
|
||||
if( basicList == null || basicList.size() == 0 )
|
||||
{
|
||||
public int checkIsNoFile(List<FileDto.Basic> basicList) {
|
||||
if (basicList == null || basicList.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -174,7 +189,6 @@ public class MapSheetMngFileJobService {
|
||||
return mapSheetMngFileJobCoreService.mngFileSave(AddReq);
|
||||
}
|
||||
|
||||
|
||||
public List<FileDto.Basic> getFilesDepthAll(SrchFilesDepthDto srchDto) {
|
||||
|
||||
Path startPath = Paths.get(srchDto.getDirPath());
|
||||
@@ -199,41 +213,39 @@ public class MapSheetMngFileJobService {
|
||||
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
|
||||
|
||||
fileDtoList =
|
||||
stream
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(
|
||||
p ->
|
||||
extension == null
|
||||
|| extension.equals("")
|
||||
|| extension.equals("*")
|
||||
|| targetExtensions.contains(extractExtension(p)))
|
||||
.sorted(getFileComparator(sortType))
|
||||
.filter(
|
||||
p -> p.getFileName().toString().contains(targetFileNm)
|
||||
)
|
||||
.skip(startPos)
|
||||
.limit(limit)
|
||||
.map(
|
||||
path -> {
|
||||
int depth = path.getNameCount();
|
||||
stream
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(
|
||||
p ->
|
||||
extension == null
|
||||
|| extension.equals("")
|
||||
|| extension.equals("*")
|
||||
|| targetExtensions.contains(extractExtension(p)))
|
||||
.sorted(getFileComparator(sortType))
|
||||
.filter(p -> p.getFileName().toString().contains(targetFileNm))
|
||||
.skip(startPos)
|
||||
.limit(limit)
|
||||
.map(
|
||||
path -> {
|
||||
int depth = path.getNameCount();
|
||||
|
||||
String fileNm = path.getFileName().toString();
|
||||
String ext = FilenameUtils.getExtension(fileNm);
|
||||
String parentFolderNm = path.getParent().getFileName().toString();
|
||||
String parentPath = path.getParent().toString();
|
||||
String fullPath = path.toAbsolutePath().toString();
|
||||
String fileNm = path.getFileName().toString();
|
||||
String ext = FilenameUtils.getExtension(fileNm);
|
||||
String parentFolderNm = path.getParent().getFileName().toString();
|
||||
String parentPath = path.getParent().toString();
|
||||
String fullPath = path.toAbsolutePath().toString();
|
||||
|
||||
File file = new File(fullPath);
|
||||
long fileSize = file.length();
|
||||
String lastModified = dttmFormat.format(new Date(file.lastModified()));
|
||||
File file = new File(fullPath);
|
||||
long fileSize = file.length();
|
||||
String lastModified = dttmFormat.format(new Date(file.lastModified()));
|
||||
|
||||
return new FileDto.Basic(
|
||||
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return new FileDto.Basic(
|
||||
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//fileTotCnt = fileDtoList.size();
|
||||
//fileTotSize = fileDtoList.stream().mapToLong(FileDto.Basic::getFileSize).sum();
|
||||
// fileTotCnt = fileDtoList.size();
|
||||
// fileTotSize = fileDtoList.stream().mapToLong(FileDto.Basic::getFileSize).sum();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("파일 I/O 오류 발생: " + e.getMessage());
|
||||
@@ -242,7 +254,6 @@ public class MapSheetMngFileJobService {
|
||||
return fileDtoList;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> createExtensionSet(String extensionString) {
|
||||
if (extensionString == null || extensionString.isBlank()) {
|
||||
return Set.of();
|
||||
@@ -250,10 +261,10 @@ public class MapSheetMngFileJobService {
|
||||
|
||||
// "java, class" -> ["java", " class"] -> [".java", ".class"]
|
||||
return Arrays.stream(extensionString.split(","))
|
||||
.map(ext -> ext.trim())
|
||||
.filter(ext -> !ext.isEmpty())
|
||||
.map(ext -> "." + ext.toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
.map(ext -> ext.trim())
|
||||
.filter(ext -> !ext.isEmpty())
|
||||
.map(ext -> "." + ext.toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public String extractExtension(Path path) {
|
||||
@@ -273,17 +284,17 @@ public class MapSheetMngFileJobService {
|
||||
|
||||
// 파일 이름 비교 기본 Comparator (대소문자 무시)
|
||||
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.comparing(
|
||||
path -> {
|
||||
try {
|
||||
return Files.getLastModifiedTime(path);
|
||||
} catch (IOException e) {
|
||||
return FileTime.fromMillis(0);
|
||||
}
|
||||
});
|
||||
Comparator.comparing(
|
||||
path -> {
|
||||
try {
|
||||
return Files.getLastModifiedTime(path);
|
||||
} catch (IOException e) {
|
||||
return FileTime.fromMillis(0);
|
||||
}
|
||||
});
|
||||
|
||||
if ("name desc".equalsIgnoreCase(sortType)) {
|
||||
return nameComparator.reversed();
|
||||
@@ -295,5 +306,4 @@ public class MapSheetMngFileJobService {
|
||||
return nameComparator;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user