할당 가능한 라벨러, 검수자 목록 API
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
package com.kamco.cd.kamcoback.label;
|
||||
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.TargetInspector;
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.TargetUser;
|
||||
import com.kamco.cd.kamcoback.label.service.LabelAllocateService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@@ -23,13 +31,38 @@ public class LabelAllocateApiController {
|
||||
|
||||
private final LabelAllocateService labelAllocateService;
|
||||
|
||||
@Operation(summary = "배정 가능한 사용자 목록 조회", description = "배정 가능한 사용자 목록 조회")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = CommonCodeDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping("/avail-user")
|
||||
public ApiResponseDto<List<LabelAllocateDto.UserList>> availUserList(@RequestParam @Schema() String role) {
|
||||
return ApiResponseDto.ok(labelAllocateService.availUserList(role));
|
||||
}
|
||||
|
||||
// 라벨링 수량 할당하는 로직 테스트
|
||||
@PostMapping("/allocate")
|
||||
public ApiResponseDto<Void> labelAllocate(@RequestBody LabelAllocateDto dto) {
|
||||
|
||||
List<TargetUser> targets =
|
||||
List.of(new TargetUser("1234567", 1000), new TargetUser("2345678", 400), new TargetUser("3456789", 440));
|
||||
List<TargetInspector> inspectors = List.of(new TargetInspector("9876543", 1000), new TargetInspector("8765432", 340), new TargetInspector("98765432", 500));
|
||||
List.of(
|
||||
new TargetUser("1234567", 1000),
|
||||
new TargetUser("2345678", 400),
|
||||
new TargetUser("3456789", 440));
|
||||
List<TargetInspector> inspectors =
|
||||
List.of(
|
||||
new TargetInspector("9876543", 1000),
|
||||
new TargetInspector("8765432", 340),
|
||||
new TargetInspector("98765432", 500));
|
||||
labelAllocateService.allocateAsc(targets, inspectors);
|
||||
|
||||
return ApiResponseDto.ok(null);
|
||||
|
||||
@@ -115,4 +115,14 @@ public class LabelAllocateDto {
|
||||
private ZonedDateTime createdDttm;
|
||||
private ZonedDateTime updatedDttm;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public static class UserList {
|
||||
|
||||
private String userRole;
|
||||
private String employeeNo;
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.label.service;
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
|
||||
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;
|
||||
import com.kamco.cd.kamcoback.postgres.core.LabelAllocateCoreService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.List;
|
||||
@@ -29,15 +30,15 @@ public class LabelAllocateService {
|
||||
public void allocateAsc(List<TargetUser> targetUsers, List<TargetInspector> targetInspectors) {
|
||||
Long lastId = null;
|
||||
|
||||
//geom 잔여건수 != 프론트에서 넘어 온 총 건수 -> return
|
||||
Long chargeCnt = labelAllocateCoreService.findLabelUnAssignedCnt(3L); //TODO
|
||||
// geom 잔여건수 != 프론트에서 넘어 온 총 건수 -> return
|
||||
Long chargeCnt = labelAllocateCoreService.findLabelUnAssignedCnt(3L); // TODO
|
||||
Long totalDemand = targetUsers.stream().mapToLong(TargetUser::getDemand).sum();
|
||||
if (!Objects.equals(chargeCnt, totalDemand)) {
|
||||
log.info("chargeCnt != totalDemand");
|
||||
return;
|
||||
}
|
||||
|
||||
//라벨러에게 건수만큼 할당
|
||||
// 라벨러에게 건수만큼 할당
|
||||
for (TargetUser target : targetUsers) {
|
||||
int remaining = target.getDemand();
|
||||
|
||||
@@ -50,15 +51,14 @@ public class LabelAllocateService {
|
||||
return; // 더이상 할당할 데이터가 없으면 return
|
||||
}
|
||||
|
||||
labelAllocateCoreService.assignOwner(
|
||||
ids, target.getUserId());
|
||||
labelAllocateCoreService.assignOwner(ids, target.getUserId());
|
||||
|
||||
remaining -= ids.size();
|
||||
lastId = ids.get(ids.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
//검수자에게 userCount명 만큼 할당
|
||||
// 검수자에게 userCount명 만큼 할당
|
||||
List<LabelAllocateDto.Basic> list = labelAllocateCoreService.findAssignedLabelerList(3L);
|
||||
int reviewerIndex = 0;
|
||||
int count = 0;
|
||||
@@ -66,7 +66,8 @@ public class LabelAllocateService {
|
||||
|
||||
for (LabelAllocateDto.Basic labeler : list) {
|
||||
TargetInspector inspector = targetInspectors.get(reviewerIndex);
|
||||
labelAllocateCoreService.assignInspector(labeler.getAssignmentUid(), inspector.getInspectorUid());
|
||||
labelAllocateCoreService.assignInspector(
|
||||
labeler.getAssignmentUid(), inspector.getInspectorUid());
|
||||
count++;
|
||||
|
||||
if (count == inspector.getUserCount()) {
|
||||
@@ -74,6 +75,9 @@ public class LabelAllocateService {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<UserList> availUserList(String role) {
|
||||
return labelAllocateCoreService.availUserList(role);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user