라벨 이관, 상세정보 API 추가
This commit is contained in:
@@ -4,10 +4,13 @@ import com.kamco.cd.kamcoback.common.enums.RoleType;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
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.WorkerStatsDto.WorkerListResponse;
|
||||
import com.kamco.cd.kamcoback.label.service.LabelAllocateService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
@@ -97,12 +100,59 @@ public class LabelAllocateApiController {
|
||||
analUid, workerType, searchName, searchEmployeeNo, sort));
|
||||
}
|
||||
|
||||
@Operation(summary = "라벨링 작업 배정", description = "라벨러 및 검수자에게 작업을 배정합니다.")
|
||||
@Operation(summary = "작업 배정", description = "작업 배정")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(responseCode = "200", description = "배정 성공"),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터"),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류")
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "등록 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Long.class),
|
||||
examples = {@ExampleObject(
|
||||
name = "라벨러 할당 예시",
|
||||
description = "라벨러 할당 예시",
|
||||
value =
|
||||
"""
|
||||
{
|
||||
"autoType": "AUTO",
|
||||
"stage": 4,
|
||||
"labelers": [
|
||||
{
|
||||
"userId": "123456",
|
||||
"demand": 1000
|
||||
},
|
||||
{
|
||||
"userId": "010222297501",
|
||||
"demand": 400
|
||||
},
|
||||
{
|
||||
"userId": "01022223333",
|
||||
"demand": 440
|
||||
}
|
||||
],
|
||||
"inspectors": [
|
||||
{
|
||||
"inspectorUid": "K20251216001",
|
||||
"userCount": 1000
|
||||
},
|
||||
{
|
||||
"inspectorUid": "01022225555",
|
||||
"userCount": 340
|
||||
},
|
||||
{
|
||||
"inspectorUid": "K20251212001",
|
||||
"userCount": 500
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
""")}
|
||||
)),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PostMapping("/allocate")
|
||||
public ApiResponseDto<Void> labelAllocate(@RequestBody LabelAllocateDto.AllocateDto dto) {
|
||||
@@ -123,10 +173,69 @@ public class LabelAllocateApiController {
|
||||
@ApiResponse(responseCode = "404", description = "데이터를 찾을 수 없음"),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류")
|
||||
})
|
||||
@GetMapping
|
||||
@GetMapping("/stage-detail")
|
||||
public ApiResponseDto<InferenceDetail> findInferenceDetail(
|
||||
@Parameter(description = "분석 ID", required = true, example = "3") @RequestParam
|
||||
Long analUid) {
|
||||
return ApiResponseDto.ok(labelAllocateService.findInferenceDetail(analUid));
|
||||
}
|
||||
|
||||
@Operation(summary = "작업이관 > 라벨러 상세 정보", description = "작업이관 > 라벨러 상세 정보")
|
||||
@GetMapping("/labeler-detail")
|
||||
public ApiResponseDto<LabelerDetail> findLabelerDetail(@RequestParam(defaultValue = "01022223333") String userId, @RequestParam(defaultValue = "3") Long analUid) {
|
||||
return ApiResponseDto.ok(labelAllocateService.findLabelerDetail(userId, analUid));
|
||||
}
|
||||
|
||||
@Operation(summary = "작업 이관", description = "작업 이관")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "등록 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Long.class),
|
||||
examples = {@ExampleObject(
|
||||
name = "라벨러 할당 예시",
|
||||
description = "라벨러 할당 예시",
|
||||
value =
|
||||
"""
|
||||
{
|
||||
"autoType": "AUTO",
|
||||
"stage": 4,
|
||||
"labelers": [
|
||||
{
|
||||
"userId": "123456",
|
||||
"demand": 10
|
||||
},
|
||||
{
|
||||
"userId": "010222297501",
|
||||
"demand": 5
|
||||
}
|
||||
]
|
||||
}
|
||||
""")}
|
||||
)),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PostMapping("/allocate-move")
|
||||
public ApiResponseDto<Void> labelAllocateMove(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "라벨링 이관",
|
||||
required = true,
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = LabelAllocateDto.AllocateMoveDto.class)))
|
||||
@RequestBody
|
||||
LabelAllocateDto.AllocateMoveDto dto) {
|
||||
|
||||
labelAllocateService.allocateMove(
|
||||
dto.getAutoType(), dto.getStage(), dto.getLabelers());
|
||||
|
||||
return ApiResponseDto.ok(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,4 +169,34 @@ public class LabelAllocateDto {
|
||||
private Long labelCnt;
|
||||
private Long inspectorCnt;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public static class LabelerDetail {
|
||||
|
||||
private String roleType;
|
||||
private String name;
|
||||
private String userId; //사번
|
||||
private Long count;
|
||||
private Long completeCnt;
|
||||
private Long skipCnt;
|
||||
private Double percent;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public static class AllocateMoveDto {
|
||||
|
||||
@Schema(description = "자동/수동여부(AUTO/MANUAL)", example = "AUTO")
|
||||
private String autoType;
|
||||
|
||||
@Schema(description = "회차", example = "4")
|
||||
private Integer stage;
|
||||
|
||||
@Schema(description = "라벨러 할당 목록")
|
||||
private List<TargetUser> labelers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.label.service;
|
||||
|
||||
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.TargetInspector;
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.TargetUser;
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
|
||||
@@ -18,7 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
@Transactional
|
||||
public class LabelAllocateService {
|
||||
|
||||
private static final int STAGNATION_THRESHOLD = 10; // 정체 판단 기준 (3일 평균 처리량)
|
||||
@@ -156,4 +157,29 @@ public class LabelAllocateService {
|
||||
public InferenceDetail findInferenceDetail(Long analUid) {
|
||||
return labelAllocateCoreService.findInferenceDetail(analUid);
|
||||
}
|
||||
|
||||
public void allocateMove(String autoType, Integer stage, List<TargetUser> targetUsers) {
|
||||
Long lastId = null;
|
||||
|
||||
Long chargeCnt = targetUsers.stream().mapToLong(TargetUser::getDemand).sum();
|
||||
|
||||
if (chargeCnt <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Long> allIds = labelAllocateCoreService.fetchNextMoveIds(lastId, chargeCnt);
|
||||
int index = 0;
|
||||
for (TargetUser target : targetUsers) {
|
||||
int end = index + target.getDemand();
|
||||
List<Long> sub = allIds.subList(index, end);
|
||||
|
||||
labelAllocateCoreService.assignOwnerMove(sub, target.getUserId());
|
||||
index = end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public LabelerDetail findLabelerDetail(String userId, Long analUid) {
|
||||
return labelAllocateCoreService.findLabelerDetail(userId, analUid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -41,7 +44,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
|
||||
@PersistenceContext private EntityManager em;
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
public List<Long> fetchNextIds(Long lastId, Long batchSize, Long analUid) {
|
||||
@@ -77,6 +81,8 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
|
||||
.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();
|
||||
|
||||
@@ -175,12 +181,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();
|
||||
|
||||
@@ -234,7 +240,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)
|
||||
@@ -375,7 +381,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);
|
||||
|
||||
@@ -427,4 +433,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()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user