[KC-151] 재할당 이전 로직으로 수정

This commit is contained in:
2026-01-08 18:08:09 +09:00
parent be69fe274d
commit 8e8c09f2f6
5 changed files with 48 additions and 53 deletions

View File

@@ -49,8 +49,7 @@ public class LabelAllocateDto {
WAIT("대기"), WAIT("대기"),
ASSIGNED("배정"), ASSIGNED("배정"),
SKIP("스킵"), SKIP("스킵"),
DONE("완료"), DONE("완료");
COMPLETE("완료");
private String desc; private String desc;
@@ -202,8 +201,6 @@ public class LabelAllocateDto {
private Integer stage; private Integer stage;
private ZonedDateTime gukyuinDttm; private ZonedDateTime gukyuinDttm;
private Long count; private Long count;
private Long labelCnt;
private Long inspectorCnt;
} }
@Getter @Getter
@@ -235,10 +232,10 @@ public class LabelAllocateDto {
@Schema( @Schema(
description = "이관할 라벨러", description = "이관할 라벨러",
example = """ example = """
[ [
"87654321" "87654321"
] ]
""") """)
private List<String> labelers; private List<String> labelers;
@Schema(description = "회차 마스터 key", example = "f97dc186-e6d3-4645-9737-3173dde8dc64") @Schema(description = "회차 마스터 key", example = "f97dc186-e6d3-4645-9737-3173dde8dc64")

View File

@@ -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.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerListResponse; import com.kamco.cd.kamcoback.label.dto.WorkerStatsDto.WorkerListResponse;
import com.kamco.cd.kamcoback.postgres.core.LabelAllocateCoreService; import com.kamco.cd.kamcoback.postgres.core.LabelAllocateCoreService;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -123,7 +121,6 @@ public class LabelAllocateService {
public ApiResponseDto.ResponseObj allocateMove( public ApiResponseDto.ResponseObj allocateMove(
Integer totalCnt, String uuid, List<String> targetUsers, String userId) { Integer totalCnt, String uuid, List<String> targetUsers, String userId) {
Map<String, Integer> result = new LinkedHashMap<>();
int userCount = targetUsers.size(); int userCount = targetUsers.size();
if (userCount <= 0) { if (userCount <= 0) {
return new ApiResponseDto.ResponseObj(ApiResponseCode.BAD_REQUEST, "재할당할 라벨러를 선택해주세요."); return new ApiResponseDto.ResponseObj(ApiResponseCode.BAD_REQUEST, "재할당할 라벨러를 선택해주세요.");
@@ -132,6 +129,11 @@ public class LabelAllocateService {
int base = totalCnt / userCount; int base = totalCnt / userCount;
int remainder = totalCnt % userCount; int remainder = totalCnt % userCount;
Long lastId = null;
List<Long> allIds =
labelAllocateCoreService.fetchNextMoveIds(lastId, totalCnt.longValue(), uuid, userId);
int index = 0;
for (int i = 0; i < userCount; i++) { for (int i = 0; i < userCount; i++) {
int assignCount = base; int assignCount = base;
@@ -140,11 +142,15 @@ public class LabelAllocateService {
assignCount += remainder; assignCount += remainder;
} }
result.put(targetUsers.get(i), assignCount);
// TODO: 재할당 테이블에 update 까지만 하고 나머지는 배치에서 처리하기? // TODO: 재할당 테이블에 update 까지만 하고 나머지는 배치에서 처리하기?
labelAllocateCoreService.assignOwnerReAllocate( // labelAllocateCoreService.assignOwnerReAllocate(
uuid, userId, targetUsers.get(i), (long) assignCount); // uuid, userId, targetUsers.get(i), (long) assignCount);
int end = index + assignCount;
List<Long> sub = allIds.subList(index, end);
labelAllocateCoreService.assignOwnerMove(sub, targetUsers.get(i));
index = end;
} }
// Long lastId = null; // Long lastId = null;

View File

@@ -87,15 +87,8 @@ public class LabelAllocateCoreService {
return labelAllocateRepository.findInferenceDetail(uuid); return labelAllocateRepository.findInferenceDetail(uuid);
} }
public List<Long> fetchNextMoveIds( public List<Long> fetchNextMoveIds(Long lastId, Long batchSize, String uuid, String userId) {
Long lastId, return labelAllocateRepository.fetchNextMoveIds(lastId, batchSize, uuid, userId);
Long batchSize,
Integer compareYyyy,
Integer targetYyyy,
Integer stage,
String userId) {
return labelAllocateRepository.fetchNextMoveIds(
lastId, batchSize, compareYyyy, targetYyyy, stage, userId);
} }
public void assignOwnerMove(List<Long> sub, String userId) { public void assignOwnerMove(List<Long> sub, String userId) {

View File

@@ -54,13 +54,7 @@ public interface LabelAllocateRepositoryCustom {
InferenceDetail findInferenceDetail(String uuid); InferenceDetail findInferenceDetail(String uuid);
List<Long> fetchNextMoveIds( List<Long> fetchNextMoveIds(Long lastId, Long batchSize, String uuid, String userId);
Long lastId,
Long batchSize,
Integer compareYyyy,
Integer targetYyyy,
Integer stage,
String userId);
void assignOwnerMove(List<Long> sub, String userId); void assignOwnerMove(List<Long> sub, String userId);

View File

@@ -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.QMapSheetAnalInferenceEntity.mapSheetAnalInferenceEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMemberEntity.memberEntity; 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;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.AllocateInfoDto; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.AllocateInfoDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.InferenceDetail; import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.InferenceDetail;
@@ -493,38 +494,35 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
Projections.constructor( Projections.constructor(
InferenceDetail.class, InferenceDetail.class,
mapSheetAnalInferenceEntity.analTitle, mapSheetAnalInferenceEntity.analTitle,
Expressions.numberTemplate(Integer.class, "{0}", 4), mapSheetAnalInferenceEntity.stage,
mapSheetAnalInferenceEntity.gukyuinApplyDttm, mapSheetAnalInferenceEntity.gukyuinApplyDttm,
mapSheetAnalInferenceEntity.detectingCnt, mapSheetAnalDataInferenceGeomEntity.geoUid.count()))
labelingAssignmentEntity.workerUid.countDistinct(),
labelingAssignmentEntity.inspectorUid.countDistinct()))
.from(mapSheetAnalInferenceEntity) .from(mapSheetAnalInferenceEntity)
.innerJoin(labelingAssignmentEntity) .leftJoin(mapSheetAnalDataInferenceGeomEntity)
.on(mapSheetAnalInferenceEntity.id.eq(labelingAssignmentEntity.analUid)) .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())) .where(mapSheetAnalInferenceEntity.id.eq(analEntity.getId()))
.groupBy( .groupBy(
mapSheetAnalInferenceEntity.analTitle, mapSheetAnalInferenceEntity.analTitle,
mapSheetAnalInferenceEntity.stage,
mapSheetAnalInferenceEntity.gukyuinApplyDttm, mapSheetAnalInferenceEntity.gukyuinApplyDttm,
mapSheetAnalInferenceEntity.detectingCnt) mapSheetAnalInferenceEntity.detectingCnt)
.fetchOne(); .fetchOne();
} }
@Override @Override
public List<Long> fetchNextMoveIds( public List<Long> fetchNextMoveIds(Long lastId, Long batchSize, String uuid, String userId) {
Long lastId,
Long batchSize,
Integer compareYyyy,
Integer targetYyyy,
Integer stage,
String userId) {
MapSheetAnalInferenceEntity analEntity = MapSheetAnalInferenceEntity analEntity =
queryFactory queryFactory
.selectFrom(mapSheetAnalInferenceEntity) .selectFrom(mapSheetAnalInferenceEntity)
.where( .where(mapSheetAnalInferenceEntity.uuid.eq(UUID.fromString(uuid)))
mapSheetAnalInferenceEntity.compareYyyy.eq(compareYyyy),
mapSheetAnalInferenceEntity.targetYyyy.eq(targetYyyy),
mapSheetAnalInferenceEntity.stage.eq(stage))
.fetchOne(); .fetchOne();
if (Objects.isNull(analEntity)) { if (Objects.isNull(analEntity)) {
@@ -539,7 +537,9 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
labelingAssignmentEntity.workState.eq(LabelState.ASSIGNED.getId()), labelingAssignmentEntity.workState.eq(LabelState.ASSIGNED.getId()),
labelingAssignmentEntity.analUid.eq(analEntity.getId()), labelingAssignmentEntity.analUid.eq(analEntity.getId()),
lastId == null ? null : labelingAssignmentEntity.inferenceGeomUid.gt(lastId)) lastId == null ? null : labelingAssignmentEntity.inferenceGeomUid.gt(lastId))
.orderBy(labelingAssignmentEntity.inferenceGeomUid.asc()) .orderBy(
labelingAssignmentEntity.assignGroupId.asc(),
labelingAssignmentEntity.inferenceGeomUid.asc())
.limit(batchSize) .limit(batchSize)
.fetch(); .fetch();
} }
@@ -574,7 +574,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
NumberExpression<Long> completeCnt = NumberExpression<Long> completeCnt =
new CaseBuilder() new CaseBuilder()
.when(labelingAssignmentEntity.workState.eq(LabelState.COMPLETE.getId())) .when(labelingAssignmentEntity.workState.eq(LabelState.DONE.getId()))
.then(1L) .then(1L)
.otherwise((Long) null) .otherwise((Long) null)
.count(); .count();
@@ -1050,7 +1050,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.when( .when(
labelingAssignmentEntity labelingAssignmentEntity
.workState .workState
.eq(LabelState.COMPLETE.getId()) .eq(LabelState.DONE.getId())
.or(labelingAssignmentEntity.workState.eq(LabelState.SKIP.getId()))) .or(labelingAssignmentEntity.workState.eq(LabelState.SKIP.getId())))
.then(1L) .then(1L)
.otherwise(0L) .otherwise(0L)
@@ -1103,7 +1103,9 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
percent)) percent))
.from(labelingAssignmentEntity) .from(labelingAssignmentEntity)
.innerJoin(memberEntity) .innerJoin(memberEntity)
.on(labelingAssignmentEntity.workerUid.eq(memberEntity.employeeNo)) .on(
labelingAssignmentEntity.workerUid.eq(memberEntity.employeeNo),
memberEntity.status.eq(StatusType.ACTIVE.getId()))
.where( .where(
labelingAssignmentEntity.analUid.eq(analEntity.getId()), labelingAssignmentEntity.analUid.eq(analEntity.getId()),
labelingAssignmentEntity.workerUid.ne(userId)) labelingAssignmentEntity.workerUid.ne(userId))
@@ -1112,7 +1114,10 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
completeCnt completeCnt
.multiply(2) .multiply(2)
.goe(totalCnt)) // 진행률 평균 이상인 것들만 조회 => percent 를 바로 쓰면 having절에 무리가 갈 수 있다고 함 .goe(totalCnt)) // 진행률 평균 이상인 것들만 조회 => percent 를 바로 쓰면 having절에 무리가 갈 수 있다고 함
.orderBy(completeCnt.desc()) // TODO: 도엽번호? PNU? 로 정렬하여 보여주기? .orderBy(
completeCnt
.desc()) // TODO: 현재는 잔여건수가 제일 적은(=완료건수가 높은) 순서로 desc, 추후 도엽번호? PNU? 로 정렬하여
// 보여주기?
.fetch(); .fetch();
return new MoveInfo(userChargeCnt, list); return new MoveInfo(userChargeCnt, list);