Merge pull request 'feat/infer_dev_260107' (#170) from feat/infer_dev_260107 into develop

Reviewed-on: https://kamco.gitea.gs.dabeeo.com/dabeeo/kamco-dabeeo-backoffice/pulls/170
This commit is contained in:
2026-01-09 16:04:09 +09:00
15 changed files with 425 additions and 5 deletions

View File

@@ -5,6 +5,8 @@ import static java.lang.String.CASE_INSENSITIVE_ORDER;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
@@ -25,6 +27,8 @@ import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import lombok.Getter;
import org.apache.commons.io.FilenameUtils;
import org.geotools.coverage.grid.GridCoverage2D;
@@ -517,6 +521,61 @@ public class FIleChecker {
return true;
}
public static void unzip(String fileName, String destDirectory) throws IOException {
File destDir = new File(destDirectory);
if (!destDir.exists()) {
destDir.mkdirs(); // 대상 폴더가 없으면 생성
}
String zipFilePath = destDirectory + "/" + fileName;
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFilePath))) {
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry);
if (zipEntry.isDirectory()) {
if (!newFile.isDirectory() && !newFile.mkdirs()) {
throw new IOException("디렉토리 생성 실패: " + newFile);
}
} else {
// 상위 디렉토리가 없는 경우 생성
File parent = newFile.getParentFile();
if (!parent.exists() && !parent.mkdirs()) {
throw new IOException("상위 디렉토리 생성 실패: " + parent);
}
// 실제 파일 쓰기
try (FileOutputStream fos = new FileOutputStream(newFile)) {
byte[] buffer = new byte[1024];
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
}
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
}
}
public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());
String destDirPath = destinationDir.getCanonicalPath();
String destFilePath = destFile.getCanonicalPath();
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("엔트리가 대상 디렉토리를 벗어남: " + zipEntry.getName());
}
return destFile;
}
public static boolean checkExtensions(String fileName, String ext) {
if (fileName == null) return false;

View File

@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.model;
import com.kamco.cd.kamcoback.common.utils.zip.ZipUtils;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto.ModelUploadResDto;
import com.kamco.cd.kamcoback.model.service.ModelMngService;
import com.kamco.cd.kamcoback.upload.dto.UploadDto;
import io.swagger.v3.oas.annotations.Operation;
@@ -136,7 +137,7 @@ public class ModelMngApiController {
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping(value = "/file-chunk-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponseDto<UploadDto.UploadRes> fileChunkUpload(
public ApiResponseDto<ModelUploadResDto> fileChunkUpload(
@RequestParam("uuid") UUID uuid,
@RequestParam("fileName") String fileName,
@RequestParam("fileSize") long fileSize,

View File

@@ -65,6 +65,8 @@ public class ModelMngDto {
private String cdModelConfigFileName;
private String clsModelPath;
private String clsModelFileName;
private String clsModelVersion;
private double priority;
private String memo;
public Basic(
@@ -86,6 +88,8 @@ public class ModelMngDto {
String cdModelConfigFileName,
String clsModelPath,
String clsModelFileName,
String clsModelVersion,
double priority,
String memo) {
this.modelUid = modelUid;
this.modelVer = modelVer;
@@ -105,6 +109,8 @@ public class ModelMngDto {
this.cdModelConfigFileName = cdModelConfigFileName;
this.clsModelPath = clsModelPath;
this.clsModelFileName = clsModelFileName;
this.clsModelVersion = clsModelVersion;
this.priority = priority;
this.memo = memo;
}
}
@@ -128,6 +134,14 @@ public class ModelMngDto {
private String memo;
private Boolean deleted;
private UUID uuid;
private String cdModelPath;
private String cdModelFileName;
private String cdModelConfigPath;
private String cdModelConfigFileName;
private String clsModelPath;
private String clsModelFileName;
private String clsModelVersion;
private double priority;
}
@Schema(name = "ModelAddReq", description = "모델 등록 req")
@@ -149,6 +163,8 @@ public class ModelMngDto {
private String clsModelFileName;
private String memo;
@JsonIgnore private String clsModelVersion;
@JsonIgnore private double priority;
@JsonIgnore private UUID uuid;
}
@@ -190,4 +206,32 @@ public class ModelMngDto {
private double loss;
private double iou;
}
@Schema(name = "ModelUploadResDto", description = "모델 등록 req")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class ModelUploadResDto {
private String res;
private String resMsg;
private UUID uuid;
private String filePath;
private String fileName;
private String cdModelPath;
private String cdModelFileName;
private String cdModelConfigPath;
private String cdModelConfigFileName;
private String clsModelPath;
private String clsModelFileName;
private int chunkIndex;
private int chunkTotalIndex;
public double getUploadRate() {
if (this.chunkTotalIndex == 0) {
return 0.0;
}
return (double) (this.chunkIndex + 1) / (this.chunkTotalIndex + 1) * 100.0;
}
}
}

View File

@@ -1,12 +1,17 @@
package com.kamco.cd.kamcoback.model.service;
import com.kamco.cd.kamcoback.common.utils.FIleChecker;
import com.kamco.cd.kamcoback.common.utils.FIleChecker.Basic;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto.ModelMetricAddReq;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto.ModelUploadResDto;
import com.kamco.cd.kamcoback.postgres.core.ModelMngCoreService;
import com.kamco.cd.kamcoback.upload.dto.UploadDto;
import com.kamco.cd.kamcoback.upload.service.UploadService;
import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
@@ -63,6 +68,8 @@ public class ModelMngService {
public ApiResponseDto.ResponseObj insertModel(ModelMngDto.AddReq addReq) {
UUID uuid = UUID.randomUUID();
addReq.setUuid(uuid);
addReq.setClsModelVersion(addReq.getModelVer());
addReq.setPriority(0L);
Long modelUid = modelMngCoreService.insertModel(addReq);
ModelMetricAddReq modelMetricAddReq = new ModelMetricAddReq();
@@ -79,10 +86,63 @@ public class ModelMngService {
return new ApiResponseDto.ResponseObj(ApiResponseDto.ApiResponseCode.OK, "등록되었습니다.");
}
public UploadDto.UploadRes uploadChunkModelFile(
public ModelUploadResDto uploadChunkModelFile(
UploadDto.UploadAddReq upAddReqDto, MultipartFile chunkFile) {
UploadDto.UploadRes upRes = uploadService.uploadChunk(upAddReqDto, chunkFile);
return upRes;
ModelUploadResDto modelUploadResDto = new ModelUploadResDto();
modelUploadResDto.setRes(upRes.getRes());
modelUploadResDto.setResMsg(upRes.getResMsg());
modelUploadResDto.setUuid(upRes.getUuid());
modelUploadResDto.setFilePath(upRes.getFilePath());
modelUploadResDto.setFileName(upRes.getFileName());
modelUploadResDto.setChunkIndex(upRes.getChunkIndex());
modelUploadResDto.setChunkTotalIndex(upRes.getChunkTotalIndex());
// 압축풀기 (String zipFilePath, String destDirectory)
if (upRes.getChunkIndex() == upRes.getChunkTotalIndex()) {
try {
FIleChecker.unzip(upRes.getFileName(), upRes.getFilePath());
this.getUnzipModelFiles(upRes.getFilePath(), modelUploadResDto);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return modelUploadResDto;
}
public ModelUploadResDto getUnzipModelFiles(String dirPath, ModelUploadResDto modelUploadResDto) {
// String dirPath = srchDto.getDirPath();
int startPos = 0;
int endPos = 20;
List<Basic> files =
FIleChecker.getFilesFromAllDepth(dirPath, "*", "pth,py", 10, "name", startPos, endPos);
for (Basic dto : files) {
// 예: 파일명 출력 및 추가 작업
String foldNm = dto.getFullPath().replace(dto.getFileNm(), "");
if (dto.getExtension().equals("pth")) {
modelUploadResDto.setCdModelPath(foldNm);
modelUploadResDto.setCdModelFileName(dto.getFileNm());
} else if (dto.getExtension().equals("py")) {
modelUploadResDto.setCdModelConfigPath(foldNm);
modelUploadResDto.setCdModelConfigFileName(dto.getFileNm());
} else if (dto.getExtension().equals("json")) {
modelUploadResDto.setClsModelPath(foldNm);
modelUploadResDto.setClsModelFileName(dto.getFileNm());
}
}
// int fileListPos = 0;
// int fileTotCnt = files.size();
// long fileTotSize = FIleChecker.getFileTotSize(files);
return modelUploadResDto;
}
}

View File

@@ -4,6 +4,7 @@ import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.repository.model.ModelMngRepository;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
@@ -55,6 +56,9 @@ public class ModelMngCoreService {
addEntity.setClsModelPath(addReq.getClsModelPath());
addEntity.setClsModelFileName(addReq.getClsModelFileName());
addEntity.setDeleted(false);
addEntity.setClsModelVersion(addReq.getClsModelVersion());
addEntity.setPriority(addReq.getPriority());
addEntity.setCreateCompleteDttm(ZonedDateTime.now());
// modelMngRepository.insertModel(addReq);
ModelMngEntity entity = modelMngRepository.save(addEntity);

View File

@@ -0,0 +1,19 @@
package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.postgres.repository.trainingdata.TrainingDataLabelRepository;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingListDto;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.searchReq;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class TrainingDataLabelCoreService {
private final TrainingDataLabelRepository trainingDataLabelRepository;
public Page<LabelingListDto> findLabelingAssignedList(searchReq searchReq, String userId) {
return trainingDataLabelRepository.findLabelingAssignedList(searchReq, userId);
}
}

View File

@@ -12,6 +12,7 @@ import java.time.ZonedDateTime;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
@Getter
@Setter
@@ -81,6 +82,14 @@ public class ModelMngEntity extends CommonDateEntity {
@Column(name = "cls_model_file_name", length = 155)
private String clsModelFileName;
@Size(max = 100)
@Column(name = "cls_model_version", length = 100)
private String clsModelVersion;
@ColumnDefault("0")
@Column(name = "priority")
private Double priority;
public void deleted() {
this.deleted = true;
}

View File

@@ -81,7 +81,15 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
roundNumericToPercent(modelResultMetricEntity.iou),
modelMngEntity.memo,
modelMngEntity.deleted,
modelMngEntity.uuid))
modelMngEntity.uuid,
modelMngEntity.cdModelPath,
modelMngEntity.cdModelFileName,
modelMngEntity.cdModelConfigPath,
modelMngEntity.cdModelConfigFileName,
modelMngEntity.clsModelPath,
modelMngEntity.clsModelFileName,
modelMngEntity.clsModelVersion,
modelMngEntity.priority))
.from(modelMngEntity)
.innerJoin(modelResultMetricEntity)
.on(modelMngEntity.modelUid.eq(modelResultMetricEntity.modelUid))

View File

@@ -0,0 +1,7 @@
package com.kamco.cd.kamcoback.postgres.repository.trainingdata;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TrainingDataLabelRepository
extends JpaRepository<LabelingAssignmentEntity, Long>, TrainingDataLabelRepositoryCustom {}

View File

@@ -0,0 +1,10 @@
package com.kamco.cd.kamcoback.postgres.repository.trainingdata;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingListDto;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.searchReq;
import org.springframework.data.domain.Page;
public interface TrainingDataLabelRepositoryCustom {
Page<LabelingListDto> findLabelingAssignedList(searchReq searchReq, String userId);
}

View File

@@ -0,0 +1,74 @@
package com.kamco.cd.kamcoback.postgres.repository.trainingdata;
import static com.kamco.cd.kamcoback.postgres.entity.QLabelingAssignmentEntity.labelingAssignmentEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity.mapInkx5kEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataInferenceGeomEntity.mapSheetAnalDataInferenceGeomEntity;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingListDto;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.searchReq;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
public class TrainingDataLabelRepositoryImpl extends QuerydslRepositorySupport
implements TrainingDataLabelRepositoryCustom {
private final JPAQueryFactory queryFactory;
public TrainingDataLabelRepositoryImpl(JPAQueryFactory queryFactory) {
super(LabelingAssignmentEntity.class);
this.queryFactory = queryFactory;
}
@Override
public Page<LabelingListDto> findLabelingAssignedList(searchReq searchReq, String userId) {
Pageable pageable = PageRequest.of(searchReq.getPage(), searchReq.getSize());
List<LabelingListDto> list =
queryFactory
.select(
Projections.constructor(
LabelingListDto.class,
labelingAssignmentEntity.assignmentUid,
labelingAssignmentEntity.inferenceGeomUid,
labelingAssignmentEntity.workerUid,
labelingAssignmentEntity.workState,
labelingAssignmentEntity.assignGroupId,
mapInkx5kEntity.mapidNm,
mapSheetAnalDataInferenceGeomEntity.pnu))
.from(labelingAssignmentEntity)
.innerJoin(mapSheetAnalDataInferenceGeomEntity)
.on(
labelingAssignmentEntity.inferenceGeomUid.eq(
mapSheetAnalDataInferenceGeomEntity.geoUid))
.innerJoin(mapInkx5kEntity)
.on(labelingAssignmentEntity.assignGroupId.eq(mapInkx5kEntity.mapidcdNo))
.where(labelingAssignmentEntity.workerUid.eq(userId))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(
labelingAssignmentEntity.assignGroupId.asc(),
labelingAssignmentEntity.inferenceGeomUid.asc())
.fetch();
Long count =
queryFactory
.select(labelingAssignmentEntity.assignmentUid.count())
.from(labelingAssignmentEntity)
.innerJoin(mapSheetAnalDataInferenceGeomEntity)
.on(
labelingAssignmentEntity.inferenceGeomUid.eq(
mapSheetAnalDataInferenceGeomEntity.geoUid))
.innerJoin(mapInkx5kEntity)
.on(labelingAssignmentEntity.assignGroupId.eq(mapInkx5kEntity.mapidcdNo))
.where(labelingAssignmentEntity.workerUid.eq(userId))
.fetchOne();
return new PageImpl<>(list, pageable, count);
}
}

View File

@@ -0,0 +1,50 @@
package com.kamco.cd.kamcoback.trainingdata;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingListDto;
import com.kamco.cd.kamcoback.trainingdata.service.TrainingDataLabelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "라벨링 툴 > 라벨러", description = "라벨링 툴 > 라벨러 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/training-data/label")
public class TrainingDataLabelApiController {
private final TrainingDataLabelService trainingDataLabelService;
@Operation(summary = "목록 조회", description = "라벨 할당 목록 조회")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "조회 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = CommonCodeDto.Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@GetMapping
public ApiResponseDto<Page<LabelingListDto>> findLabelingAssignedList(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size,
@RequestParam(defaultValue = "20260105001") String userId) {
TrainingDataLabelDto.searchReq searchReq = new TrainingDataLabelDto.searchReq(page, size, "");
return ApiResponseDto.ok(trainingDataLabelService.findLabelingAssignedList(searchReq, userId));
}
}

View File

@@ -0,0 +1,54 @@
package com.kamco.cd.kamcoback.trainingdata.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Getter;
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 TrainingDataLabelDto {
@Schema(name = "LabelingListDto", description = "LabelingListDto")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class LabelingListDto {
private UUID assignmentUid;
private Long inferenceGeomUid;
private String workerUid;
private String workState;
private String mapSheetNum;
private String mapIdNm;
private Long pnu;
}
@Schema(name = "searchReq", description = "검색 요청")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class searchReq {
// 페이징 파라미터
private int page = 0;
private int size = 20;
private String sort;
public Pageable toPageable() {
if (sort != null && !sort.isEmpty()) {
String[] sortParams = sort.split(",");
String property = sortParams[0];
Sort.Direction direction =
sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC;
return PageRequest.of(page, size, Sort.by(direction, property));
}
return PageRequest.of(page, size);
}
}
}

View File

@@ -0,0 +1,21 @@
package com.kamco.cd.kamcoback.trainingdata.service;
import com.kamco.cd.kamcoback.postgres.core.TrainingDataLabelCoreService;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingListDto;
import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.searchReq;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@Service
public class TrainingDataLabelService {
private final TrainingDataLabelCoreService trainingDataLabelCoreService;
public TrainingDataLabelService(TrainingDataLabelCoreService trainingDataLabelCoreService) {
this.trainingDataLabelCoreService = trainingDataLabelCoreService;
}
public Page<LabelingListDto> findLabelingAssignedList(searchReq searchReq, String userId) {
return trainingDataLabelCoreService.findLabelingAssignedList(searchReq, userId);
}
}

View File

@@ -37,7 +37,7 @@ fileHash : <input id="fileHash" placeholder="fileHash"><br><br> -->
<div style="width:500px;height:30px;border:1px solid #cccccc;"><div id="prgssbar" style="width:100%;height:30px;background:#eeeeee;"></div></div>
<br><br>
* 결과메세지</br></br>
<div id="status" style="padding:20px;width:800px;height:300px;border:1px solid #000000;"></div>
<div id="status" style="padding:20px;width:1200px;height:600px;border:1px solid #000000;"></div>
<script>
async function startUpload() {