라벨러 목록조회 임시커밋

This commit is contained in:
DanielLee
2026-01-02 18:59:16 +09:00
parent 563d7b5768
commit 62c4b9e732
5 changed files with 555 additions and 17 deletions

View File

@@ -2,8 +2,11 @@ package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkProgressInfo;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerStatistics;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import com.kamco.cd.kamcoback.postgres.repository.label.LabelAllocateRepository;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
@@ -40,4 +43,23 @@ public class LabelAllocateCoreService {
public List<UserList> availUserList(String role) {
return labelAllocateRepository.availUserList(role);
}
public List<WorkerStatistics> findWorkerStatistics(
Long analUid,
String workerType,
String searchName,
String searchEmployeeNo,
String sortType) {
return labelAllocateRepository.findWorkerStatistics(
analUid, workerType, searchName, searchEmployeeNo, sortType);
}
public WorkProgressInfo findWorkProgressInfo(Long analUid) {
return labelAllocateRepository.findWorkProgressInfo(analUid);
}
public Long findDailyProcessedCount(
String workerId, String workerType, LocalDate date, Long analUid) {
return labelAllocateRepository.findDailyProcessedCount(workerId, workerType, date, analUid);
}
}

View File

@@ -1,7 +1,10 @@
package com.kamco.cd.kamcoback.postgres.repository.label;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkProgressInfo;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerStatistics;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
@@ -18,4 +21,14 @@ public interface LabelAllocateRepositoryCustom {
void assignInspector(UUID assignmentUid, String userId);
List<UserList> availUserList(String role);
// 작업자 통계 조회
List<WorkerStatistics> findWorkerStatistics(
Long analUid, String workerType, String searchName, String searchEmployeeNo, String sortType);
// 작업 진행 현황 조회
WorkProgressInfo findWorkProgressInfo(Long analUid);
// 작업자별 일일 처리량 조회
Long findDailyProcessedCount(String workerId, String workerType, LocalDate date, Long analUid);
}

View File

@@ -8,38 +8,39 @@ import static com.kamco.cd.kamcoback.postgres.entity.QMemberEntity.memberEntity;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelState;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkProgressInfo;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerStatistics;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataGeomEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalEntity;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.NumberExpression;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import org.springframework.stereotype.Repository;
@Slf4j
@Repository
public class LabelAllocateRepositoryImpl extends QuerydslRepositorySupport
implements LabelAllocateRepositoryCustom {
@RequiredArgsConstructor
public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
@PersistenceContext private EntityManager em;
public LabelAllocateRepositoryImpl(JPAQueryFactory queryFactory) {
super(MapSheetAnalDataGeomEntity.class);
this.queryFactory = queryFactory;
}
@Override
public List<Long> fetchNextIds(Long lastId, int batchSize) {
@@ -150,4 +151,232 @@ public class LabelAllocateRepositoryImpl extends QuerydslRepositorySupport
.orderBy(memberEntity.name.asc())
.fetch();
}
@Override
public List<WorkerStatistics> findWorkerStatistics(
Long analUid,
String workerType,
String searchName,
String searchEmployeeNo,
String sortType) {
// 작업자 유형에 따른 필드 선택
StringExpression workerIdField =
"INSPECTOR".equals(workerType)
? labelingAssignmentEntity.inspectorUid
: labelingAssignmentEntity.workerUid;
BooleanExpression workerCondition =
"INSPECTOR".equals(workerType)
? labelingAssignmentEntity.inspectorUid.isNotNull()
: labelingAssignmentEntity.workerUid.isNotNull();
// 검색 조건
BooleanExpression searchCondition = null;
if (searchName != null && !searchName.isEmpty()) {
searchCondition = memberEntity.name.contains(searchName);
}
if (searchEmployeeNo != null && !searchEmployeeNo.isEmpty()) {
BooleanExpression empCondition = memberEntity.employeeNo.contains(searchEmployeeNo);
searchCondition = searchCondition == null ? empCondition : searchCondition.and(empCondition);
}
// 완료, 스킵, 남은 작업 계산
NumberExpression<Long> completedSum =
new CaseBuilder()
.when(labelingAssignmentEntity.workState.eq("DONE"))
.then(1L)
.otherwise(0L)
.sum();
NumberExpression<Long> skippedSum =
new CaseBuilder()
.when(labelingAssignmentEntity.workState.eq("SKIP"))
.then(1L)
.otherwise(0L)
.sum();
NumberExpression<Long> remainingSum =
new CaseBuilder()
.when(
labelingAssignmentEntity
.workState
.notIn("DONE", "SKIP")
.and(labelingAssignmentEntity.workState.isNotNull()))
.then(1L)
.otherwise(0L)
.sum();
// 기본 통계 조회 쿼리
var baseQuery =
queryFactory
.select(
workerIdField,
memberEntity.name,
workerIdField.count(),
completedSum,
skippedSum,
remainingSum,
labelingAssignmentEntity.stagnationYn.max())
.from(labelingAssignmentEntity)
.leftJoin(memberEntity)
.on(
"INSPECTOR".equals(workerType)
? memberEntity.employeeNo.eq(labelingAssignmentEntity.inspectorUid)
: memberEntity.employeeNo.eq(labelingAssignmentEntity.workerUid))
.where(labelingAssignmentEntity.analUid.eq(analUid), workerCondition, searchCondition)
.groupBy(workerIdField, memberEntity.name);
// 정렬 조건 적용
if (sortType != null) {
switch (sortType) {
case "REMAINING_DESC":
baseQuery.orderBy(remainingSum.desc());
break;
case "REMAINING_ASC":
baseQuery.orderBy(remainingSum.asc());
break;
case "NAME_ASC":
baseQuery.orderBy(memberEntity.name.asc());
break;
case "NAME_DESC":
baseQuery.orderBy(memberEntity.name.desc());
break;
default:
baseQuery.orderBy(memberEntity.name.asc());
}
} else {
baseQuery.orderBy(memberEntity.name.asc());
}
// 결과를 DTO로 변환
return baseQuery.fetch().stream()
.map(
tuple -> {
Character maxStagnationYn = tuple.get(labelingAssignmentEntity.stagnationYn.max());
return WorkerStatistics.builder()
.workerId(tuple.get(workerIdField))
.workerName(tuple.get(memberEntity.name))
.workerType(workerType)
.totalAssigned(tuple.get(workerIdField.count()))
.completed(tuple.get(completedSum))
.skipped(tuple.get(skippedSum))
.remaining(tuple.get(remainingSum))
.history(null) // 3일 이력은 Service에서 채움
.isStagnated(maxStagnationYn != null && maxStagnationYn == 'Y')
.build();
})
.toList();
}
@Override
public WorkProgressInfo findWorkProgressInfo(Long analUid) {
// 전체 배정 건수
Long totalAssigned =
queryFactory
.select(labelingAssignmentEntity.count())
.from(labelingAssignmentEntity)
.where(labelingAssignmentEntity.analUid.eq(analUid))
.fetchOne();
// 완료 + 스킵 건수
Long completedCount =
queryFactory
.select(labelingAssignmentEntity.count())
.from(labelingAssignmentEntity)
.where(
labelingAssignmentEntity.analUid.eq(analUid),
labelingAssignmentEntity.workState.in("DONE", "SKIP"))
.fetchOne();
// 투입된 라벨러 수 (고유한 worker_uid 수)
Long labelerCount =
queryFactory
.select(labelingAssignmentEntity.workerUid.countDistinct())
.from(labelingAssignmentEntity)
.where(
labelingAssignmentEntity.analUid.eq(analUid),
labelingAssignmentEntity.workerUid.isNotNull())
.fetchOne();
// 남은 라벨링 작업 데이터 수
Long remainingLabelCount =
queryFactory
.select(labelingAssignmentEntity.count())
.from(labelingAssignmentEntity)
.where(
labelingAssignmentEntity.analUid.eq(analUid),
labelingAssignmentEntity.workerUid.isNotNull(),
labelingAssignmentEntity.workState.notIn("DONE", "SKIP"))
.fetchOne();
// 투입된 검수자 수 (고유한 inspector_uid 수)
Long inspectorCount =
queryFactory
.select(labelingAssignmentEntity.inspectorUid.countDistinct())
.from(labelingAssignmentEntity)
.where(
labelingAssignmentEntity.analUid.eq(analUid),
labelingAssignmentEntity.inspectorUid.isNotNull())
.fetchOne();
// 남은 검수 작업 데이터 수
Long remainingInspectCount =
queryFactory
.select(labelingAssignmentEntity.count())
.from(labelingAssignmentEntity)
.where(
labelingAssignmentEntity.analUid.eq(analUid),
labelingAssignmentEntity.inspectorUid.isNotNull(),
labelingAssignmentEntity.workState.notIn("DONE"))
.fetchOne();
// 진행률 계산
double progressRate = 0.0;
if (totalAssigned != null && totalAssigned > 0) {
progressRate =
(completedCount != null ? completedCount.doubleValue() : 0.0) / totalAssigned * 100;
}
// 작업 상태 판단 (간단하게 진행률 100%면 종료, 아니면 진행중)
String workStatus = (progressRate >= 100.0) ? "종료" : "진행중";
return WorkProgressInfo.builder()
.labelingProgressRate(progressRate)
.workStatus(workStatus)
.completedCount(completedCount != null ? completedCount : 0L)
.totalAssignedCount(totalAssigned != null ? totalAssigned : 0L)
.labelerCount(labelerCount != null ? labelerCount : 0L)
.remainingLabelCount(remainingLabelCount != null ? remainingLabelCount : 0L)
.inspectorCount(inspectorCount != null ? inspectorCount : 0L)
.remainingInspectCount(remainingInspectCount != null ? remainingInspectCount : 0L)
.build();
}
@Override
public Long findDailyProcessedCount(
String workerId, String workerType, LocalDate date, Long analUid) {
// 해당 날짜의 시작과 끝 시간
ZonedDateTime startOfDay = date.atStartOfDay(ZoneId.systemDefault());
ZonedDateTime endOfDay = date.atTime(LocalTime.MAX).atZone(ZoneId.systemDefault());
BooleanExpression workerCondition =
"INSPECTOR".equals(workerType)
? labelingAssignmentEntity.inspectorUid.eq(workerId)
: labelingAssignmentEntity.workerUid.eq(workerId);
Long count =
queryFactory
.select(labelingAssignmentEntity.count())
.from(labelingAssignmentEntity)
.where(
labelingAssignmentEntity.analUid.eq(analUid),
workerCondition,
labelingAssignmentEntity.workState.in("DONE", "SKIP"),
labelingAssignmentEntity.modifiedDate.between(startOfDay, endOfDay))
.fetchOne();
return count != null ? count : 0L;
}
}