diff --git a/src/main/java/com/kamco/cd/kamcoback/label/dto/LabelAllocateDto.java b/src/main/java/com/kamco/cd/kamcoback/label/dto/LabelAllocateDto.java index 6314bfff..db764638 100644 --- a/src/main/java/com/kamco/cd/kamcoback/label/dto/LabelAllocateDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/label/dto/LabelAllocateDto.java @@ -49,8 +49,7 @@ public class LabelAllocateDto { WAIT("대기"), ASSIGNED("배정"), SKIP("스킵"), - DONE("완료"), - COMPLETE("완료"); + DONE("완료"); private String desc; @@ -202,8 +201,6 @@ public class LabelAllocateDto { private Integer stage; private ZonedDateTime gukyuinDttm; private Long count; - private Long labelCnt; - private Long inspectorCnt; } @Getter @@ -235,10 +232,10 @@ public class LabelAllocateDto { @Schema( description = "이관할 라벨러", example = """ - [ - "87654321" - ] - """) + [ + "87654321" + ] + """) private List labelers; @Schema(description = "회차 마스터 key", example = "f97dc186-e6d3-4645-9737-3173dde8dc64") diff --git a/src/main/java/com/kamco/cd/kamcoback/label/service/LabelAllocateService.java b/src/main/java/com/kamco/cd/kamcoback/label/service/LabelAllocateService.java index a344561e..ac9bd2f3 100644 --- a/src/main/java/com/kamco/cd/kamcoback/label/service/LabelAllocateService.java +++ b/src/main/java/com/kamco/cd/kamcoback/label/service/LabelAllocateService.java @@ -12,9 +12,7 @@ import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.TargetUser; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList; import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerListResponse; import com.kamco.cd.kamcoback.postgres.core.LabelAllocateCoreService; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -123,7 +121,6 @@ public class LabelAllocateService { public ApiResponseDto.ResponseObj allocateMove( Integer totalCnt, String uuid, List targetUsers, String userId) { - Map result = new LinkedHashMap<>(); int userCount = targetUsers.size(); if (userCount <= 0) { return new ApiResponseDto.ResponseObj(ApiResponseCode.BAD_REQUEST, "재할당할 라벨러를 선택해주세요."); @@ -132,6 +129,11 @@ public class LabelAllocateService { int base = totalCnt / userCount; int remainder = totalCnt % userCount; + Long lastId = null; + List allIds = + labelAllocateCoreService.fetchNextMoveIds(lastId, totalCnt.longValue(), uuid, userId); + + int index = 0; for (int i = 0; i < userCount; i++) { int assignCount = base; @@ -140,11 +142,15 @@ public class LabelAllocateService { assignCount += remainder; } - result.put(targetUsers.get(i), assignCount); - // TODO: 재할당 테이블에 update 까지만 하고 나머지는 배치에서 처리하기? - labelAllocateCoreService.assignOwnerReAllocate( - uuid, userId, targetUsers.get(i), (long) assignCount); + // labelAllocateCoreService.assignOwnerReAllocate( + // uuid, userId, targetUsers.get(i), (long) assignCount); + + int end = index + assignCount; + List sub = allIds.subList(index, end); + + labelAllocateCoreService.assignOwnerMove(sub, targetUsers.get(i)); + index = end; } // Long lastId = null; diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/core/LabelAllocateCoreService.java b/src/main/java/com/kamco/cd/kamcoback/postgres/core/LabelAllocateCoreService.java index 9c2e2612..ff7c00ba 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/core/LabelAllocateCoreService.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/core/LabelAllocateCoreService.java @@ -87,15 +87,8 @@ public class LabelAllocateCoreService { return labelAllocateRepository.findInferenceDetail(uuid); } - public List fetchNextMoveIds( - Long lastId, - Long batchSize, - Integer compareYyyy, - Integer targetYyyy, - Integer stage, - String userId) { - return labelAllocateRepository.fetchNextMoveIds( - lastId, batchSize, compareYyyy, targetYyyy, stage, userId); + public List fetchNextMoveIds(Long lastId, Long batchSize, String uuid, String userId) { + return labelAllocateRepository.fetchNextMoveIds(lastId, batchSize, uuid, userId); } public void assignOwnerMove(List sub, String userId) { diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryCustom.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryCustom.java index a1279830..350b30c2 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryCustom.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryCustom.java @@ -54,13 +54,7 @@ public interface LabelAllocateRepositoryCustom { InferenceDetail findInferenceDetail(String uuid); - List fetchNextMoveIds( - Long lastId, - Long batchSize, - Integer compareYyyy, - Integer targetYyyy, - Integer stage, - String userId); + List fetchNextMoveIds(Long lastId, Long batchSize, String uuid, String userId); void assignOwnerMove(List sub, String userId); diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java index 4ab96086..6d64776a 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java @@ -7,6 +7,7 @@ import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataInferenceG import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalInferenceEntity.mapSheetAnalInferenceEntity; import static com.kamco.cd.kamcoback.postgres.entity.QMemberEntity.memberEntity; +import com.kamco.cd.kamcoback.common.enums.StatusType; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.AllocateInfoDto; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.InferenceDetail; @@ -493,38 +494,35 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto Projections.constructor( InferenceDetail.class, mapSheetAnalInferenceEntity.analTitle, - Expressions.numberTemplate(Integer.class, "{0}", 4), + mapSheetAnalInferenceEntity.stage, mapSheetAnalInferenceEntity.gukyuinApplyDttm, - mapSheetAnalInferenceEntity.detectingCnt, - labelingAssignmentEntity.workerUid.countDistinct(), - labelingAssignmentEntity.inspectorUid.countDistinct())) + mapSheetAnalDataInferenceGeomEntity.geoUid.count())) .from(mapSheetAnalInferenceEntity) - .innerJoin(labelingAssignmentEntity) - .on(mapSheetAnalInferenceEntity.id.eq(labelingAssignmentEntity.analUid)) + .leftJoin(mapSheetAnalDataInferenceGeomEntity) + .on( + mapSheetAnalInferenceEntity.compareYyyy.eq( + mapSheetAnalDataInferenceGeomEntity.compareYyyy), + mapSheetAnalInferenceEntity.targetYyyy.eq( + mapSheetAnalDataInferenceGeomEntity.targetYyyy), + mapSheetAnalInferenceEntity.stage.eq(mapSheetAnalDataInferenceGeomEntity.stage), + mapSheetAnalDataInferenceGeomEntity.pnu.gt(0), + mapSheetAnalDataInferenceGeomEntity.passYn.isFalse()) .where(mapSheetAnalInferenceEntity.id.eq(analEntity.getId())) .groupBy( mapSheetAnalInferenceEntity.analTitle, + mapSheetAnalInferenceEntity.stage, mapSheetAnalInferenceEntity.gukyuinApplyDttm, mapSheetAnalInferenceEntity.detectingCnt) .fetchOne(); } @Override - public List fetchNextMoveIds( - Long lastId, - Long batchSize, - Integer compareYyyy, - Integer targetYyyy, - Integer stage, - String userId) { + public List fetchNextMoveIds(Long lastId, Long batchSize, String uuid, String userId) { MapSheetAnalInferenceEntity analEntity = queryFactory .selectFrom(mapSheetAnalInferenceEntity) - .where( - mapSheetAnalInferenceEntity.compareYyyy.eq(compareYyyy), - mapSheetAnalInferenceEntity.targetYyyy.eq(targetYyyy), - mapSheetAnalInferenceEntity.stage.eq(stage)) + .where(mapSheetAnalInferenceEntity.uuid.eq(UUID.fromString(uuid))) .fetchOne(); if (Objects.isNull(analEntity)) { @@ -539,7 +537,9 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto labelingAssignmentEntity.workState.eq(LabelState.ASSIGNED.getId()), labelingAssignmentEntity.analUid.eq(analEntity.getId()), lastId == null ? null : labelingAssignmentEntity.inferenceGeomUid.gt(lastId)) - .orderBy(labelingAssignmentEntity.inferenceGeomUid.asc()) + .orderBy( + labelingAssignmentEntity.assignGroupId.asc(), + labelingAssignmentEntity.inferenceGeomUid.asc()) .limit(batchSize) .fetch(); } @@ -574,7 +574,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto NumberExpression completeCnt = new CaseBuilder() - .when(labelingAssignmentEntity.workState.eq(LabelState.COMPLETE.getId())) + .when(labelingAssignmentEntity.workState.eq(LabelState.DONE.getId())) .then(1L) .otherwise((Long) null) .count(); @@ -1050,7 +1050,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto .when( labelingAssignmentEntity .workState - .eq(LabelState.COMPLETE.getId()) + .eq(LabelState.DONE.getId()) .or(labelingAssignmentEntity.workState.eq(LabelState.SKIP.getId()))) .then(1L) .otherwise(0L) @@ -1103,7 +1103,9 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto percent)) .from(labelingAssignmentEntity) .innerJoin(memberEntity) - .on(labelingAssignmentEntity.workerUid.eq(memberEntity.employeeNo)) + .on( + labelingAssignmentEntity.workerUid.eq(memberEntity.employeeNo), + memberEntity.status.eq(StatusType.ACTIVE.getId())) .where( labelingAssignmentEntity.analUid.eq(analEntity.getId()), labelingAssignmentEntity.workerUid.ne(userId)) @@ -1112,7 +1114,10 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto completeCnt .multiply(2) .goe(totalCnt)) // 진행률 평균 이상인 것들만 조회 => percent 를 바로 쓰면 having절에 무리가 갈 수 있다고 함 - .orderBy(completeCnt.desc()) // TODO: 도엽번호? PNU? 로 정렬하여 보여주기? + .orderBy( + completeCnt + .desc()) // TODO: 현재는 잔여건수가 제일 적은(=완료건수가 높은) 순서로 desc, 추후 도엽번호? PNU? 로 정렬하여 + // 보여주기? .fetch(); return new MoveInfo(userChargeCnt, list);