Merge remote-tracking branch 'origin/feat/dev_251201' into feat/dev_251201

# Conflicts:
#	src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelWorkRepositoryImpl.java
This commit is contained in:
Moon
2026-01-02 21:52:25 +09:00
12 changed files with 405 additions and 277 deletions

View File

@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.postgres.core;
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.LabelerDetail;
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;
@@ -19,12 +20,12 @@ public class LabelAllocateCoreService {
private final LabelAllocateRepository labelAllocateRepository;
public List<Long> fetchNextIds(Long lastId, Long batchSize) {
return labelAllocateRepository.fetchNextIds(lastId, batchSize);
public List<Long> fetchNextIds(Long lastId, Long batchSize, Long analUid) {
return labelAllocateRepository.fetchNextIds(lastId, batchSize, analUid);
}
public void assignOwner(List<Long> ids, String userId) {
labelAllocateRepository.assignOwner(ids, userId);
public void assignOwner(List<Long> ids, String userId, Long analUid) {
labelAllocateRepository.assignOwner(ids, userId, analUid);
}
public List<LabelAllocateDto.Basic> findAssignedLabelerList(Long analUid) {
@@ -33,8 +34,8 @@ public class LabelAllocateCoreService {
.toList();
}
public Long findLabelUnAssignedCnt(Long analUid) {
return labelAllocateRepository.findLabelUnAssignedCnt(analUid);
public Long findLabelUnAssignedCnt(Long analUid, Integer stage) {
return labelAllocateRepository.findLabelUnAssignedCnt(analUid, stage);
}
public void assignInspector(UUID assignmentUid, String inspectorUid) {
@@ -71,4 +72,20 @@ public class LabelAllocateCoreService {
public InferenceDetail findInferenceDetail(Long analUid) {
return labelAllocateRepository.findInferenceDetail(analUid);
}
public Long findLabelUnCompleteCnt(Long analUid) {
return labelAllocateRepository.findLabelUnCompleteCnt(analUid);
}
public List<Long> fetchNextMoveIds(Long lastId, Long chargeCnt) {
return labelAllocateRepository.fetchNextMoveIds(lastId, chargeCnt);
}
public void assignOwnerMove(List<Long> sub, String userId) {
labelAllocateRepository.assignOwnerMove(sub, userId);
}
public LabelerDetail findLabelerDetail(String userId, Long analUid) {
return labelAllocateRepository.findLabelerDetail(userId, analUid);
}
}

View File

@@ -1,17 +1,8 @@
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.LabelWorkDto;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto.LabelWorkMng;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.ErrorDataDto;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import com.kamco.cd.kamcoback.postgres.repository.label.LabelAllocateRepository;
import com.kamco.cd.kamcoback.postgres.repository.label.LabelWorkRepository;
import jakarta.validation.Valid;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@@ -22,10 +13,7 @@ public class LabelWorkCoreService {
private final LabelWorkRepository labelWorkRepository;
public Page<LabelWorkMng> labelWorkMngList(LabelWorkDto.LabelWorkMngSearchReq searchReq) {
return labelWorkRepository.labelWorkMngList(searchReq);
}
}

View File

@@ -1,6 +1,7 @@
package com.kamco.cd.kamcoback.postgres.repository.label;
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.UserList;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkProgressInfo;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerStatistics;
@@ -11,13 +12,13 @@ import java.util.UUID;
public interface LabelAllocateRepositoryCustom {
List<Long> fetchNextIds(Long lastId, Long batchSize);
List<Long> fetchNextIds(Long lastId, Long batchSize, Long analUid);
void assignOwner(List<Long> ids, String userId);
void assignOwner(List<Long> ids, String userId, Long analUid);
List<LabelingAssignmentEntity> findAssignedLabelerList(Long analUid);
Long findLabelUnAssignedCnt(Long analUid);
Long findLabelUnAssignedCnt(Long analUid, Integer stage);
void assignInspector(UUID assignmentUid, String userId);
@@ -36,4 +37,12 @@ public interface LabelAllocateRepositoryCustom {
void assignInspectorBulk(List<UUID> assignmentUids, String inspectorUid);
InferenceDetail findInferenceDetail(Long analUid);
List<Long> fetchNextMoveIds(Long lastId, Long batchSize);
Long findLabelUnCompleteCnt(Long analUid);
void assignOwnerMove(List<Long> sub, String userId);
LabelerDetail findLabelerDetail(String userId, Long analUid);
}

View File

@@ -7,7 +7,9 @@ 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.InferenceDetail;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.InspectState;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelState;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelerDetail;
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;
@@ -23,6 +25,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
@@ -44,16 +47,25 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
@PersistenceContext private EntityManager em;
@Override
public List<Long> fetchNextIds(Long lastId, Long batchSize) {
public List<Long> fetchNextIds(Long lastId, Long batchSize, Long analUid) {
// analUid로 분석 정보 조회
MapSheetAnalEntity analEntity =
queryFactory
.selectFrom(mapSheetAnalEntity)
.where(mapSheetAnalEntity.id.eq(analUid))
.fetchOne();
if (Objects.isNull(analEntity)) {
throw new EntityNotFoundException("MapSheetAnalEntity not found for analUid: " + analUid);
}
return queryFactory
.select(mapSheetAnalDataInferenceGeomEntity.geoUid)
.from(mapSheetAnalDataInferenceGeomEntity)
.where(
// mapSheetAnalDataGeomEntity.pnu.isNotNull(), //TODO: Mockup 진행 이후 확인하기
lastId == null ? null : mapSheetAnalDataInferenceGeomEntity.geoUid.gt(lastId),
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(2022),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(2024),
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(analEntity.getCompareYyyy()),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(analEntity.getTargetYyyy()),
mapSheetAnalDataInferenceGeomEntity.labelState.isNull())
.orderBy(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.asc())
.limit(batchSize)
@@ -61,24 +73,26 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
}
@Override
public void assignOwner(List<Long> ids, String userId) {
public void assignOwner(List<Long> ids, String userId, Long analUid) {
// data_geom 테이블에 label state 를 ASSIGNED 로 update
queryFactory
.update(mapSheetAnalDataInferenceGeomEntity)
.set(mapSheetAnalDataInferenceGeomEntity.labelState, LabelState.ASSIGNED.getId())
.set(mapSheetAnalDataInferenceGeomEntity.labelStateDttm, ZonedDateTime.now())
.set(mapSheetAnalDataInferenceGeomEntity.testState, InspectState.UNCONFIRM.getId())
.set(mapSheetAnalDataInferenceGeomEntity.testStateDttm, ZonedDateTime.now())
.where(mapSheetAnalDataInferenceGeomEntity.geoUid.in(ids))
.execute();
// 라벨러 할당 테이블에 insert
String sql =
"""
insert into tb_labeling_assignment
(assignment_uid, inference_geom_uid, worker_uid,
work_state, assign_group_id, anal_uid)
values (?, ?, ?, ?, ?, ?)
""";
insert into tb_labeling_assignment
(assignment_uid, inference_geom_uid, worker_uid,
work_state, assign_group_id, anal_uid)
values (?, ?, ?, ?, ?, ?)
""";
for (Long geoUid : ids) {
em.createNativeQuery(sql)
@@ -87,7 +101,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.setParameter(3, userId)
.setParameter(4, LabelState.ASSIGNED.getId())
.setParameter(5, "")
.setParameter(6, 3)
.setParameter(6, analUid)
.executeUpdate();
}
@@ -108,7 +122,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
}
@Override
public Long findLabelUnAssignedCnt(Long analUid) {
public Long findLabelUnAssignedCnt(Long analUid, Integer stage) {
MapSheetAnalEntity entity =
queryFactory
.selectFrom(mapSheetAnalEntity)
@@ -116,7 +130,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.fetchOne();
if (Objects.isNull(entity)) {
throw new EntityNotFoundException();
throw new EntityNotFoundException("MapSheetAnalEntity not found for analUid: " + analUid);
}
return queryFactory
@@ -125,7 +139,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.where(
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(entity.getCompareYyyy()),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(entity.getTargetYyyy()),
mapSheetAnalDataInferenceGeomEntity.stage.eq(4), // TODO: 회차 컬럼을 가져와야 할 듯?
mapSheetAnalDataInferenceGeomEntity.stage.eq(stage),
mapSheetAnalDataInferenceGeomEntity.labelState.isNull())
.fetchOne();
}
@@ -149,7 +163,9 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
memberEntity.employeeNo,
memberEntity.name))
.from(memberEntity)
.where(memberEntity.userRole.eq(role), memberEntity.status.eq("ACTIVE"))
.where(
memberEntity.userRole.eq(role),
memberEntity.status.eq(com.kamco.cd.kamcoback.common.enums.StatusType.ACTIVE.getId()))
.orderBy(memberEntity.name.asc())
.fetch();
}
@@ -164,12 +180,12 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
// 작업자 유형에 따른 필드 선택
StringExpression workerIdField =
"INSPECTOR".equals(workerType)
"REVIEWER".equals(workerType)
? labelingAssignmentEntity.inspectorUid
: labelingAssignmentEntity.workerUid;
BooleanExpression workerCondition =
"INSPECTOR".equals(workerType)
"REVIEWER".equals(workerType)
? labelingAssignmentEntity.inspectorUid.isNotNull()
: labelingAssignmentEntity.workerUid.isNotNull();
@@ -223,7 +239,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.from(labelingAssignmentEntity)
.leftJoin(memberEntity)
.on(
"INSPECTOR".equals(workerType)
"REVIEWER".equals(workerType)
? memberEntity.employeeNo.eq(labelingAssignmentEntity.inspectorUid)
: memberEntity.employeeNo.eq(labelingAssignmentEntity.workerUid))
.where(labelingAssignmentEntity.analUid.eq(analUid), workerCondition, searchCondition)
@@ -364,7 +380,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
ZonedDateTime endOfDay = date.atTime(LocalTime.MAX).atZone(ZoneId.systemDefault());
BooleanExpression workerCondition =
"INSPECTOR".equals(workerType)
"REVIEWER".equals(workerType)
? labelingAssignmentEntity.inspectorUid.eq(workerId)
: labelingAssignmentEntity.workerUid.eq(workerId);
@@ -375,7 +391,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.where(
labelingAssignmentEntity.analUid.eq(analUid),
workerCondition,
labelingAssignmentEntity.workState.in("DONE", "SKIP"),
labelingAssignmentEntity.workState.in(
LabelState.DONE.getId(), LabelState.SKIP.getId()),
labelingAssignmentEntity.modifiedDate.between(startOfDay, endOfDay))
.fetchOne();
@@ -415,4 +432,122 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
mapSheetAnalEntity.detectingCnt)
.fetchOne();
}
@Override
public List<Long> fetchNextMoveIds(Long lastId, Long batchSize) {
MapSheetAnalEntity entity =
queryFactory
.selectFrom(mapSheetAnalEntity)
.where(mapSheetAnalEntity.id.eq(3L)) // TODO
.fetchOne();
if (Objects.isNull(entity)) {
throw new EntityNotFoundException();
}
return queryFactory
.select(mapSheetAnalDataInferenceGeomEntity.geoUid)
.from(mapSheetAnalDataInferenceGeomEntity)
.where(
// mapSheetAnalDataGeomEntity.pnu.isNotNull(), //TODO: Mockup 진행 이후 확인하기
lastId == null ? null : mapSheetAnalDataInferenceGeomEntity.geoUid.gt(lastId),
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(entity.getCompareYyyy()),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(entity.getTargetYyyy()),
mapSheetAnalDataInferenceGeomEntity.labelState.in(
LabelState.ASSIGNED.getId(), LabelState.SKIP.getId()))
.orderBy(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.asc())
.limit(batchSize)
.fetch();
}
@Override
public Long findLabelUnCompleteCnt(Long analUid) {
MapSheetAnalEntity entity =
queryFactory
.selectFrom(mapSheetAnalEntity)
.where(mapSheetAnalEntity.id.eq(analUid))
.fetchOne();
if (Objects.isNull(entity)) {
throw new EntityNotFoundException();
}
return queryFactory
.select(mapSheetAnalDataInferenceGeomEntity.geoUid.count())
.from(mapSheetAnalDataInferenceGeomEntity)
.where(
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(entity.getCompareYyyy()),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(entity.getTargetYyyy()),
mapSheetAnalDataInferenceGeomEntity.stage.eq(4), // TODO: 회차 컬럼을 가져와야 할 듯?
mapSheetAnalDataInferenceGeomEntity.labelState.in(
LabelState.ASSIGNED.getId(), LabelState.SKIP.getId()))
.fetchOne();
}
@Transactional
@Override
public void assignOwnerMove(List<Long> sub, String userId) {
queryFactory
.update(labelingAssignmentEntity)
.set(labelingAssignmentEntity.workerUid, userId)
.where(labelingAssignmentEntity.inferenceGeomUid.in(sub))
.execute();
em.clear();
}
@Override
public LabelerDetail findLabelerDetail(String userId, Long analUid) {
NumberExpression<Long> assignedCnt =
new CaseBuilder()
.when(labelingAssignmentEntity.workState.eq(LabelState.ASSIGNED.getId()))
.then(1L)
.otherwise((Long) null)
.count();
NumberExpression<Long> skipCnt =
new CaseBuilder()
.when(labelingAssignmentEntity.workState.eq(LabelState.SKIP.getId()))
.then(1L)
.otherwise((Long) null)
.count();
NumberExpression<Long> completeCnt =
new CaseBuilder()
.when(labelingAssignmentEntity.workState.eq(LabelState.COMPLETE.getId()))
.then(1L)
.otherwise((Long) null)
.count();
NumberExpression<Double> percent =
new CaseBuilder()
.when(completeCnt.eq(0L))
.then(0.0)
.otherwise(
Expressions.numberTemplate(
Double.class,
"round({0} / {1}, 2)",
labelingAssignmentEntity.count(),
completeCnt));
return queryFactory
.select(
Projections.constructor(
LabelerDetail.class,
memberEntity.userRole,
memberEntity.name,
memberEntity.employeeNo,
assignedCnt,
skipCnt,
completeCnt,
percent))
.from(memberEntity)
.innerJoin(labelingAssignmentEntity)
.on(
memberEntity.employeeNo.eq(labelingAssignmentEntity.workerUid),
labelingAssignmentEntity.analUid.eq(analUid))
.where(memberEntity.employeeNo.eq(userId))
.groupBy(memberEntity.userRole, memberEntity.name, memberEntity.employeeNo)
.fetchOne();
}
}

View File

@@ -4,5 +4,4 @@ import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataInferenceGeomEntit
import org.springframework.data.jpa.repository.JpaRepository;
public interface LabelWorkRepository
extends JpaRepository<MapSheetAnalDataInferenceGeomEntity, Long>,
LabelWorkRepositoryCustom {}
extends JpaRepository<MapSheetAnalDataInferenceGeomEntity, Long>, LabelWorkRepositoryCustom {}

View File

@@ -1,11 +1,7 @@
package com.kamco.cd.kamcoback.postgres.repository.label;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto.LabelWorkMng;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import java.util.List;
import java.util.UUID;
import org.springframework.data.domain.Page;
public interface LabelWorkRepositoryCustom {