This commit is contained in:
2026-01-05 13:36:15 +09:00
parent d86e70e27e
commit 8c149605e5
8 changed files with 295 additions and 371 deletions

View File

@@ -5,6 +5,7 @@ import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.InferenceDetail; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.InferenceDetail;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelerDetail; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelerDetail;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelingStatDto;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerListResponse; import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerListResponse;
import com.kamco.cd.kamcoback.label.service.LabelAllocateService; import com.kamco.cd.kamcoback.label.service.LabelAllocateService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@@ -18,6 +19,7 @@ import jakarta.validation.Valid;
import java.util.List; import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -93,19 +95,16 @@ public class LabelAllocateApiController {
defaultValue = "NAME_ASC")) defaultValue = "NAME_ASC"))
@RequestParam(required = false) @RequestParam(required = false)
String sort, String sort,
@Parameter(description = "페이지 번호 (0부터 시작)", example = "0") @Parameter(description = "페이지 번호 (0부터 시작)", example = "0") @RequestParam(defaultValue = "0")
@RequestParam(defaultValue = "0")
Integer page, Integer page,
@Parameter(description = "페이지 크기", example = "20") @Parameter(description = "페이지 크기", example = "20") @RequestParam(defaultValue = "20")
@RequestParam(defaultValue = "20")
Integer size) { Integer size) {
// type이 null이면 기본값으로 LABELER 설정 // type이 null이면 기본값으로 LABELER 설정
String workerType = (type == null || type.isEmpty()) ? RoleType.LABELER.name() : type; String workerType = (type == null || type.isEmpty()) ? RoleType.LABELER.name() : type;
return ApiResponseDto.ok( return ApiResponseDto.ok(
labelAllocateService.getWorkerStatistics( labelAllocateService.getWorkerStatistics(null, workerType, search, sort, page, size));
null, workerType, search, sort, page, size));
} }
@Operation(summary = "라벨링작업 관리 > 작업 배정", description = "라벨링작업 관리 > 작업 배정") @Operation(summary = "라벨링작업 관리 > 작업 배정", description = "라벨링작업 관리 > 작업 배정")
@@ -168,10 +167,9 @@ public class LabelAllocateApiController {
@Schema( @Schema(
allowableValues = {"LABELER", "REVIEWER"}, allowableValues = {"LABELER", "REVIEWER"},
defaultValue = "LABELER") defaultValue = "LABELER")
@Parameter( @Parameter(description = "라벨러/검수자(LABELER/REVIEWER)", required = true)
description = "라벨러/검수자(LABELER/REVIEWER)", @RequestParam
required = true) @RequestParam String type String type) {
) {
return ApiResponseDto.ok(labelAllocateService.findUserDetail(userId, uuid, type)); return ApiResponseDto.ok(labelAllocateService.findUserDetail(userId, uuid, type));
} }
@@ -223,18 +221,14 @@ public class LabelAllocateApiController {
example = "8584e8d4-53b3-4582-bde2-28a81495a626") example = "8584e8d4-53b3-4582-bde2-28a81495a626")
@RequestParam @RequestParam
String uuid, String uuid,
@Parameter( @Parameter(description = "사번", required = true, example = "123456") @RequestParam
description = "사번", String userId,
required = true,
example = "123456")
@RequestParam String userId,
@Schema( @Schema(
allowableValues = {"LABELER", "REVIEWER"}, allowableValues = {"LABELER", "REVIEWER"},
defaultValue = "LABELER") defaultValue = "LABELER")
@Parameter( @Parameter(description = "라벨러/검수자(LABELER/REVIEWER)", required = true)
description = "라벨러/검수자(LABELER/REVIEWER)", @RequestParam
required = true) @RequestParam String type String type) {
) {
LabelAllocateDto.searchReq searchReq = new LabelAllocateDto.searchReq(page, size, ""); LabelAllocateDto.searchReq searchReq = new LabelAllocateDto.searchReq(page, size, "");
return ApiResponseDto.ok(labelAllocateService.findDaliyList(searchReq, uuid, userId, type)); return ApiResponseDto.ok(labelAllocateService.findDaliyList(searchReq, uuid, userId, type));
} }

View File

@@ -301,5 +301,4 @@ public class LabelAllocateDto {
return PageRequest.of(page, size); return PageRequest.of(page, size);
} }
} }
} }

View File

@@ -67,23 +67,17 @@ public class WorkerStatsDto {
private Boolean isStagnated; private Boolean isStagnated;
// 레거시 필드 (기존 호환성 유지) // 레거시 필드 (기존 호환성 유지)
@Deprecated @Deprecated private Long doneCnt; // completed로 대체
private Long doneCnt; // completed로 대체
@Deprecated @Deprecated private Long skipCnt; // skipped로 대체
private Long skipCnt; // skipped로 대체
@Deprecated @Deprecated private Long remainingCnt; // remaining으로 대체
private Long remainingCnt; // remaining으로 대체
@Deprecated @Deprecated private Long day3AgoDoneCnt; // history.day3Ago로 대체
private Long day3AgoDoneCnt; // history.day3Ago로 대체
@Deprecated @Deprecated private Long day2AgoDoneCnt; // history.day2Ago로 대체
private Long day2AgoDoneCnt; // history.day2Ago로 대체
@Deprecated @Deprecated private Long day1AgoDoneCnt; // history.day1Ago로 대체
private Long day1AgoDoneCnt; // history.day1Ago로 대체
} }
@Getter @Getter
@@ -107,7 +101,6 @@ public class WorkerStatsDto {
private Long average; private Long average;
} }
@Getter @Getter
@Setter @Setter
@Builder @Builder

View File

@@ -124,12 +124,7 @@ public class LabelAllocateService {
* @return 작업자 목록 및 통계 * @return 작업자 목록 및 통계
*/ */
public WorkerListResponse getWorkerStatistics( public WorkerListResponse getWorkerStatistics(
Long analUid, Long analUid, String workerType, String search, String sortType, Integer page, Integer size) {
String workerType,
String search,
String sortType,
Integer page,
Integer size) {
// 프로젝트 정보 조회 (analUid가 있을 때만) // 프로젝트 정보 조회 (analUid가 있을 때만)
var projectInfo = labelAllocateCoreService.findProjectInfo(analUid); var projectInfo = labelAllocateCoreService.findProjectInfo(analUid);
@@ -139,8 +134,7 @@ public class LabelAllocateService {
// 작업자 통계 조회 // 작업자 통계 조회
List<WorkerStatistics> workers = List<WorkerStatistics> workers =
labelAllocateCoreService.findWorkerStatistics( labelAllocateCoreService.findWorkerStatistics(analUid, workerType, search, sortType);
analUid, workerType, search, sortType);
// 각 작업자별 3일치 처리량 조회 // 각 작업자별 3일치 처리량 조회
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
@@ -234,7 +228,8 @@ public class LabelAllocateService {
} }
} }
public Page<LabelingStatDto> findDaliyList(LabelAllocateDto.searchReq searchReq, String uuid, String userId, String type) { public Page<LabelingStatDto> findDaliyList(
LabelAllocateDto.searchReq searchReq, String uuid, String userId, String type) {
if (type.equals("LABELER")) { if (type.equals("LABELER")) {
return labelAllocateCoreService.findLabelerDailyStat(searchReq, uuid, userId); return labelAllocateCoreService.findLabelerDailyStat(searchReq, uuid, userId);
} else { } else {

View File

@@ -57,12 +57,8 @@ public class LabelAllocateCoreService {
} }
public List<WorkerStatistics> findWorkerStatistics( public List<WorkerStatistics> findWorkerStatistics(
Long analUid, Long analUid, String workerType, String search, String sortType) {
String workerType, return labelAllocateRepository.findWorkerStatistics(analUid, workerType, search, sortType);
String search,
String sortType) {
return labelAllocateRepository.findWorkerStatistics(
analUid, workerType, search, sortType);
} }
public WorkProgressInfo findWorkProgressInfo(Long analUid) { public WorkProgressInfo findWorkProgressInfo(Long analUid) {
@@ -104,11 +100,13 @@ public class LabelAllocateCoreService {
labelAllocateRepository.insertInspector(analUid, inspector); labelAllocateRepository.insertInspector(analUid, inspector);
} }
public Page<LabelingStatDto> findLabelerDailyStat(searchReq searchReq, String uuid, String userId) { public Page<LabelingStatDto> findLabelerDailyStat(
searchReq searchReq, String uuid, String userId) {
return labelAllocateRepository.findLabelerDailyStat(searchReq, uuid, userId); return labelAllocateRepository.findLabelerDailyStat(searchReq, uuid, userId);
} }
public Page<LabelingStatDto> findInspectorDailyStat(searchReq searchReq, String uuid, String userId) { public Page<LabelingStatDto> findInspectorDailyStat(
searchReq searchReq, String uuid, String userId) {
return labelAllocateRepository.findInspectorDailyStat(searchReq, uuid, userId); return labelAllocateRepository.findInspectorDailyStat(searchReq, uuid, userId);
} }

View File

@@ -65,7 +65,6 @@ public class LabelingAssignmentEntity extends CommonDateEntity {
super.getModifiedDate(), super.getModifiedDate(),
this.inspectState, this.inspectState,
this.workStatDttm, this.workStatDttm,
this.inspectStatDttm this.inspectStatDttm);
);
} }
} }

View File

@@ -58,9 +58,11 @@ public interface LabelAllocateRepositoryCustom {
void insertInspector(Long analUid, String inspector); void insertInspector(Long analUid, String inspector);
Page<LabelingStatDto> findLabelerDailyStat(LabelAllocateDto.searchReq searchReq, String uuid, String userId); Page<LabelingStatDto> findLabelerDailyStat(
LabelAllocateDto.searchReq searchReq, String uuid, String userId);
Page<LabelingStatDto> findInspectorDailyStat(LabelAllocateDto.searchReq searchReq, String uuid, String userId); Page<LabelingStatDto> findInspectorDailyStat(
LabelAllocateDto.searchReq searchReq, String uuid, String userId);
LabelerDetail findInspectorDetail(String userId, String uuid); LabelerDetail findInspectorDetail(String userId, String uuid);
} }

View File

@@ -197,10 +197,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
@Override @Override
public List<WorkerStatistics> findWorkerStatistics( public List<WorkerStatistics> findWorkerStatistics(
Long analUid, Long analUid, String workerType, String search, String sortType) {
String workerType,
String search,
String sortType) {
// 작업자 유형에 따른 필드 선택 // 작업자 유형에 따른 필드 선택
StringExpression workerIdField = StringExpression workerIdField =
@@ -216,8 +213,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
// 검색 조건 (이름 또는 사번으로 검색) // 검색 조건 (이름 또는 사번으로 검색)
BooleanExpression searchCondition = null; BooleanExpression searchCondition = null;
if (search != null && !search.isEmpty()) { if (search != null && !search.isEmpty()) {
searchCondition = memberEntity.name.contains(search) searchCondition =
.or(memberEntity.employeeNo.contains(search)); memberEntity.name.contains(search).or(memberEntity.employeeNo.contains(search));
} }
// 완료, 스킵, 남은 작업 계산 // 완료, 스킵, 남은 작업 계산
@@ -247,7 +244,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.sum(); .sum();
// 기본 통계 조회 쿼리 // 기본 통계 조회 쿼리
BooleanExpression analUidCondition = analUid != null ? labelingAssignmentEntity.analUid.eq(analUid) : null; BooleanExpression analUidCondition =
analUid != null ? labelingAssignmentEntity.analUid.eq(analUid) : null;
var baseQuery = var baseQuery =
queryFactory queryFactory
@@ -318,7 +316,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
@Override @Override
public WorkProgressInfo findWorkProgressInfo(Long analUid) { public WorkProgressInfo findWorkProgressInfo(Long analUid) {
BooleanExpression analUidCondition = analUid != null ? labelingAssignmentEntity.analUid.eq(analUid) : null; BooleanExpression analUidCondition =
analUid != null ? labelingAssignmentEntity.analUid.eq(analUid) : null;
// 전체 배정 건수 // 전체 배정 건수
Long totalAssigned = Long totalAssigned =
@@ -344,9 +343,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
queryFactory queryFactory
.select(labelingAssignmentEntity.count()) .select(labelingAssignmentEntity.count())
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(analUidCondition, labelingAssignmentEntity.workState.eq("SKIP"))
analUidCondition,
labelingAssignmentEntity.workState.eq("SKIP"))
.fetchOne(); .fetchOne();
// 투입된 라벨러 수 // 투입된 라벨러 수
@@ -354,9 +351,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
queryFactory queryFactory
.select(labelingAssignmentEntity.workerUid.countDistinct()) .select(labelingAssignmentEntity.workerUid.countDistinct())
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(analUidCondition, labelingAssignmentEntity.workerUid.isNotNull())
analUidCondition,
labelingAssignmentEntity.workerUid.isNotNull())
.fetchOne(); .fetchOne();
// === 검수 통계 === // === 검수 통계 ===
@@ -365,9 +360,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
queryFactory queryFactory
.select(labelingAssignmentEntity.count()) .select(labelingAssignmentEntity.count())
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(analUidCondition, labelingAssignmentEntity.workState.eq("DONE"))
analUidCondition,
labelingAssignmentEntity.workState.eq("DONE"))
.fetchOne(); .fetchOne();
// 투입된 검수자 수 // 투입된 검수자 수
@@ -375,9 +368,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
queryFactory queryFactory
.select(labelingAssignmentEntity.inspectorUid.countDistinct()) .select(labelingAssignmentEntity.inspectorUid.countDistinct())
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(analUidCondition, labelingAssignmentEntity.inspectorUid.isNotNull())
analUidCondition,
labelingAssignmentEntity.inspectorUid.isNotNull())
.fetchOne(); .fetchOne();
// 남은 작업 건수 계산 // 남은 작업 건수 계산
@@ -437,7 +428,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
? labelingAssignmentEntity.inspectorUid.eq(workerId) ? labelingAssignmentEntity.inspectorUid.eq(workerId)
: labelingAssignmentEntity.workerUid.eq(workerId); : labelingAssignmentEntity.workerUid.eq(workerId);
BooleanExpression analUidCondition = analUid != null ? labelingAssignmentEntity.analUid.eq(analUid) : null; BooleanExpression analUidCondition =
analUid != null ? labelingAssignmentEntity.analUid.eq(analUid) : null;
Long count = Long count =
queryFactory queryFactory
@@ -638,14 +630,14 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
return null; return null;
} }
var result = queryFactory var result =
queryFactory
.select( .select(
mapSheetAnalEntity.compareYyyy, mapSheetAnalEntity.compareYyyy,
mapSheetAnalEntity.targetYyyy, mapSheetAnalEntity.targetYyyy,
mapSheetAnalEntity.analTitle, mapSheetAnalEntity.analTitle,
mapSheetAnalEntity.gukyuinApplyDttm, mapSheetAnalEntity.gukyuinApplyDttm,
mapSheetAnalEntity.analStrtDttm mapSheetAnalEntity.analStrtDttm)
)
.from(mapSheetAnalEntity) .from(mapSheetAnalEntity)
.where(mapSheetAnalEntity.id.eq(analUid)) .where(mapSheetAnalEntity.id.eq(analUid))
.fetchOne(); .fetchOne();
@@ -661,9 +653,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
ZonedDateTime analStrtDttm = result.get(mapSheetAnalEntity.analStrtDttm); ZonedDateTime analStrtDttm = result.get(mapSheetAnalEntity.analStrtDttm);
// 변화탐지년도 생성 // 변화탐지년도 생성
String detectionYear = (compareYyyy != null && targetYyyy != null) String detectionYear =
? compareYyyy + "-" + targetYyyy (compareYyyy != null && targetYyyy != null) ? compareYyyy + "-" + targetYyyy : null;
: null;
// 회차 추출 (예: "8회차" → "8") // 회차 추출 (예: "8회차" → "8")
String round = extractRoundFromTitle(analTitle); String round = extractRoundFromTitle(analTitle);
@@ -676,10 +667,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.build(); .build();
} }
/** /** 제목에서 회차 숫자 추출 예: "8회차", "제8회차" → "8" */
* 제목에서 회차 숫자 추출
* 예: "8회차", "제8회차" → "8"
*/
private String extractRoundFromTitle(String title) { private String extractRoundFromTitle(String title) {
if (title == null || title.isEmpty()) { if (title == null || title.isEmpty()) {
return null; return null;
@@ -691,9 +679,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
return matcher.find() ? matcher.group(1) : null; return matcher.find() ? matcher.group(1) : null;
} }
/** /** ZonedDateTime을 "yyyy-MM-dd" 형식으로 변환 */
* ZonedDateTime을 "yyyy-MM-dd" 형식으로 변환
*/
private String formatDate(ZonedDateTime dateTime) { private String formatDate(ZonedDateTime dateTime) {
if (dateTime == null) { if (dateTime == null) {
return null; return null;
@@ -702,58 +688,38 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
} }
@Override @Override
public Page<LabelingStatDto> findLabelerDailyStat(LabelAllocateDto.searchReq searchReq, String uuid, String userId) { public Page<LabelingStatDto> findLabelerDailyStat(
LabelAllocateDto.searchReq searchReq, String uuid, String userId) {
// 날짜 포맷 // 날짜 포맷
Expression<String> workDate = Expression<String> workDate =
Expressions.stringTemplate( Expressions.stringTemplate(
"TO_CHAR({0}, 'YYYY-MM-DD')", "TO_CHAR({0}, 'YYYY-MM-DD')", labelingAssignmentEntity.workStatDttm);
labelingAssignmentEntity.workStatDttm
);
// 날짜별 전체 건수 // 날짜별 전체 건수
Expression<Long> dailyTotalCnt = Expression<Long> dailyTotalCnt = Expressions.numberTemplate(Long.class, "COUNT(*)");
Expressions.numberTemplate(
Long.class,
"COUNT(*)"
);
// ⭐ 전체 기간 총 건수 (윈도우 함수) // ⭐ 전체 기간 총 건수 (윈도우 함수)
Expression<Long> totalCnt = Expression<Long> totalCnt = Expressions.numberTemplate(Long.class, "SUM(COUNT(*)) OVER ()");
Expressions.numberTemplate(
Long.class,
"SUM(COUNT(*)) OVER ()"
);
// 상태별 카운트 (Postgres FILTER 사용) // 상태별 카운트 (Postgres FILTER 사용)
Expression<Long> assignedCnt = Expression<Long> assignedCnt =
Expressions.numberTemplate( Expressions.numberTemplate(
Long.class, Long.class,
"COUNT(*) FILTER (WHERE {0} = 'ASSIGNED')", "COUNT(*) FILTER (WHERE {0} = 'ASSIGNED')",
labelingAssignmentEntity.workState labelingAssignmentEntity.workState);
);
Expression<Long> skipCnt = Expression<Long> skipCnt =
Expressions.numberTemplate( Expressions.numberTemplate(
Long.class, Long.class, "COUNT(*) FILTER (WHERE {0} = 'SKIP')", labelingAssignmentEntity.workState);
"COUNT(*) FILTER (WHERE {0} = 'SKIP')",
labelingAssignmentEntity.workState
);
Expression<Long> completeCnt = Expression<Long> completeCnt =
Expressions.numberTemplate( Expressions.numberTemplate(
Long.class, Long.class,
"COUNT(*) FILTER (WHERE {0} = 'COMPLETE')", "COUNT(*) FILTER (WHERE {0} = 'COMPLETE')",
labelingAssignmentEntity.workState labelingAssignmentEntity.workState);
);
Expression<Long> remainCnt = Expression<Long> remainCnt =
Expressions.numberTemplate( Expressions.numberTemplate(Long.class, "({0} - {1} - {2})", totalCnt, skipCnt, completeCnt);
Long.class,
"({0} - {1} - {2})",
totalCnt,
skipCnt,
completeCnt
);
// analUid로 분석 정보 조회 // analUid로 분석 정보 조회
MapSheetAnalInferenceEntity analEntity = MapSheetAnalInferenceEntity analEntity =
@@ -767,7 +733,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
} }
Pageable pageable = searchReq.toPageable(); Pageable pageable = searchReq.toPageable();
List<LabelingStatDto> foundContent = queryFactory List<LabelingStatDto> foundContent =
queryFactory
.select( .select(
Projections.constructor( Projections.constructor(
LabelingStatDto.class, LabelingStatDto.class,
@@ -777,27 +744,24 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
assignedCnt, assignedCnt,
skipCnt, skipCnt,
completeCnt, completeCnt,
remainCnt remainCnt))
)
)
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(
labelingAssignmentEntity.workerUid.eq(userId), labelingAssignmentEntity.workerUid.eq(userId),
labelingAssignmentEntity.analUid.eq(analEntity.getId()) labelingAssignmentEntity.analUid.eq(analEntity.getId()))
)
.groupBy(workDate) .groupBy(workDate)
.orderBy(labelingAssignmentEntity.workStatDttm.min().asc()) .orderBy(labelingAssignmentEntity.workStatDttm.min().asc())
.offset(pageable.getOffset()) .offset(pageable.getOffset())
.limit(pageable.getPageSize()) .limit(pageable.getPageSize())
.fetch(); .fetch();
Long countQuery = queryFactory Long countQuery =
queryFactory
.select(workDate) .select(workDate)
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(
labelingAssignmentEntity.workerUid.eq(userId), labelingAssignmentEntity.workerUid.eq(userId),
labelingAssignmentEntity.analUid.eq(analEntity.getId()) labelingAssignmentEntity.analUid.eq(analEntity.getId()))
)
.distinct() .distinct()
.fetch() .fetch()
.stream() .stream()
@@ -807,58 +771,40 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
} }
@Override @Override
public Page<LabelingStatDto> findInspectorDailyStat(searchReq searchReq, String uuid, String userId) { public Page<LabelingStatDto> findInspectorDailyStat(
searchReq searchReq, String uuid, String userId) {
// 날짜 포맷 // 날짜 포맷
Expression<String> workDate = Expression<String> workDate =
Expressions.stringTemplate( Expressions.stringTemplate(
"TO_CHAR({0}, 'YYYY-MM-DD')", "TO_CHAR({0}, 'YYYY-MM-DD')", labelingAssignmentEntity.inspectStatDttm);
labelingAssignmentEntity.inspectStatDttm
);
// 날짜별 전체 건수 // 날짜별 전체 건수
Expression<Long> dailyTotalCnt = Expression<Long> dailyTotalCnt = Expressions.numberTemplate(Long.class, "COUNT(*)");
Expressions.numberTemplate(
Long.class,
"COUNT(*)"
);
// ⭐ 전체 기간 총 건수 (윈도우 함수) // ⭐ 전체 기간 총 건수 (윈도우 함수)
Expression<Long> totalCnt = Expression<Long> totalCnt = Expressions.numberTemplate(Long.class, "SUM(COUNT(*)) OVER ()");
Expressions.numberTemplate(
Long.class,
"SUM(COUNT(*)) OVER ()"
);
// 상태별 카운트 (Postgres FILTER 사용) // 상태별 카운트 (Postgres FILTER 사용)
Expression<Long> assignedCnt = Expression<Long> assignedCnt =
Expressions.numberTemplate( Expressions.numberTemplate(
Long.class, Long.class,
"COUNT(*) FILTER (WHERE {0} = 'UNCONFIRM')", "COUNT(*) FILTER (WHERE {0} = 'UNCONFIRM')",
labelingAssignmentEntity.inspectState labelingAssignmentEntity.inspectState);
);
Expression<Long> skipCnt = Expression<Long> skipCnt =
Expressions.numberTemplate( Expressions.numberTemplate(
Long.class, Long.class,
"COUNT(*) FILTER (WHERE {0} = 'EXCEPT')", "COUNT(*) FILTER (WHERE {0} = 'EXCEPT')",
labelingAssignmentEntity.inspectState labelingAssignmentEntity.inspectState);
);
Expression<Long> completeCnt = Expression<Long> completeCnt =
Expressions.numberTemplate( Expressions.numberTemplate(
Long.class, Long.class,
"COUNT(*) FILTER (WHERE {0} = 'COMPLETE')", "COUNT(*) FILTER (WHERE {0} = 'COMPLETE')",
labelingAssignmentEntity.inspectState labelingAssignmentEntity.inspectState);
);
Expression<Long> remainCnt = Expression<Long> remainCnt =
Expressions.numberTemplate( Expressions.numberTemplate(Long.class, "({0} - {1} - {2})", totalCnt, skipCnt, completeCnt);
Long.class,
"({0} - {1} - {2})",
totalCnt,
skipCnt,
completeCnt
);
// analUid로 분석 정보 조회 // analUid로 분석 정보 조회
MapSheetAnalInferenceEntity analEntity = MapSheetAnalInferenceEntity analEntity =
@@ -872,7 +818,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
} }
Pageable pageable = searchReq.toPageable(); Pageable pageable = searchReq.toPageable();
List<LabelingStatDto> foundContent = queryFactory List<LabelingStatDto> foundContent =
queryFactory
.select( .select(
Projections.constructor( Projections.constructor(
LabelingStatDto.class, LabelingStatDto.class,
@@ -882,27 +829,24 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
assignedCnt, assignedCnt,
skipCnt, skipCnt,
completeCnt, completeCnt,
remainCnt remainCnt))
)
)
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(
labelingAssignmentEntity.inspectorUid.eq(userId), labelingAssignmentEntity.inspectorUid.eq(userId),
labelingAssignmentEntity.analUid.eq(analEntity.getId()) labelingAssignmentEntity.analUid.eq(analEntity.getId()))
)
.groupBy(workDate) .groupBy(workDate)
.orderBy(labelingAssignmentEntity.inspectStatDttm.min().asc()) .orderBy(labelingAssignmentEntity.inspectStatDttm.min().asc())
.offset(pageable.getOffset()) .offset(pageable.getOffset())
.limit(pageable.getPageSize()) .limit(pageable.getPageSize())
.fetch(); .fetch();
Long countQuery = queryFactory Long countQuery =
queryFactory
.select(workDate) .select(workDate)
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.where( .where(
labelingAssignmentEntity.inspectorUid.eq(userId), labelingAssignmentEntity.inspectorUid.eq(userId),
labelingAssignmentEntity.analUid.eq(analEntity.getId()) labelingAssignmentEntity.analUid.eq(analEntity.getId()))
)
.distinct() .distinct()
.fetch() .fetch()
.stream() .stream()