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.config.api.ApiResponseDto.ResponseObj; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingGeometryInfo; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingListDto; import com.kamco.cd.kamcoback.trainingdata.service.TrainingDataLabelService; import io.swagger.v3.oas.annotations.Hidden; 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.PostMapping; 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; @Tag(name = "라벨링 툴 > 라벨러", description = "라벨링 툴 > 라벨러 API") @RestController @RequiredArgsConstructor @RequestMapping("/api/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> findLabelingAssignedList( @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size, @RequestParam(defaultValue = "01022223333") String userId, @RequestParam(defaultValue = "ASSIGNED,SKIP,DONE", required = false) String status) { TrainingDataLabelDto.searchReq searchReq = new TrainingDataLabelDto.searchReq(page, size, ""); return ApiResponseDto.ok( trainingDataLabelService.findLabelingAssignedList(searchReq, userId, status)); } @Hidden @Operation(summary = "상세 Geometry 조회", description = "라벨 할당 상세 Geometry 조회") @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("/geom-info") public ApiResponseDto findLabelingAssignedGeom( @RequestParam(defaultValue = "4f9ebc8b-6635-4177-b42f-7efc9c7b4c02") String assignmentUid) { return ApiResponseDto.ok(trainingDataLabelService.findLabelingAssignedGeom(assignmentUid)); } @Operation(summary = "Geometry 저장", description = "Geometry 저장") @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) }) @PostMapping public ApiResponseDto saveLabelingFeature( @RequestBody TrainingDataLabelDto.GeoFeatureRequest request) { return ApiResponseDto.okObject(trainingDataLabelService.saveLabelingFeature(request)); } @Operation(summary = "작업 통계 조회", description = "라벨러의 작업 현황 통계를 조회합니다. (전체/미작업/Today 건수)") @ApiResponses( value = { @ApiResponse( responseCode = "200", description = "조회 성공", content = @Content( mediaType = "application/json", schema = @Schema(implementation = TrainingDataLabelDto.SummaryRes.class))), @ApiResponse(responseCode = "400", description = "잘못된 요청", content = @Content), @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) @GetMapping("/summary") public ApiResponseDto getSummary( @io.swagger.v3.oas.annotations.Parameter( description = "라벨러 사번", required = true, example = "01022223333") @RequestParam String userId) { try { System.out.println("[Controller] getSummary called with userId: " + userId); TrainingDataLabelDto.SummaryRes result = trainingDataLabelService.getSummary(userId); System.out.println("[Controller] getSummary result: " + result); return ApiResponseDto.ok(result); } catch (Exception e) { System.err.println("[Controller] getSummary ERROR: " + e.getMessage()); e.printStackTrace(); // 예외 발생 시에도 빈 통계 반환 return ApiResponseDto.ok( TrainingDataLabelDto.SummaryRes.builder() .totalCnt(0L) .undoneCnt(0L) .todayCnt(0L) .build()); } } @Operation(summary = "변화탐지정보 및 실태조사결과 조회", description = "선택한 작업의 변화탐지정보 및 실태조사결과를 조회합니다.") @ApiResponses( value = { @ApiResponse( responseCode = "200", description = "조회 성공", content = @Content( mediaType = "application/json", schema = @Schema(implementation = TrainingDataLabelDto.DetailRes.class))), @ApiResponse(responseCode = "400", description = "잘못된 요청", content = @Content), @ApiResponse(responseCode = "404", description = "데이터를 찾을 수 없음", content = @Content), @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) @GetMapping("/detail") public ApiResponseDto getDetail( @io.swagger.v3.oas.annotations.Parameter( description = "작업 배정 ID (UUID)", required = true, example = "93c56be8-0246-4b22-b976-2476549733cc") @RequestParam java.util.UUID assignmentUid) { return ApiResponseDto.ok(trainingDataLabelService.getDetail(assignmentUid)); } }