라벨 자동할당 update 로직 -> 추후 라벨링 할당 테이블로 변경할 예정

This commit is contained in:
2025-12-31 12:20:10 +09:00
parent 3d3eedeec1
commit c65a3be807
6 changed files with 163 additions and 35 deletions

View File

@@ -2,11 +2,9 @@ package com.kamco.cd.kamcoback.label;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.Sheet;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.TargetUser;
import com.kamco.cd.kamcoback.label.service.LabelAllocateService;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -17,50 +15,46 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Tag(name = "라벨링 작업 관리", description = "라벨링 작업 관리")
@RequestMapping({"/api/label/mng"})
@RequestMapping({"/api/label"})
@RequiredArgsConstructor
@RestController
public class LabelAllocateApiController {
private final LabelAllocateService labelAllocateService;
// 라벨링 수량 할당하는 로직 테스트
@PostMapping("/allocate")
public ApiResponseDto<Void> labelAllocate(@RequestBody LabelAllocateDto dto) {
// 도엽별 카운트 쿼리
List<Sheet> sheets =
List.of(
new Sheet("1", 261),
new Sheet("2", 500),
new Sheet("3", 350),
new Sheet("4", 250),
new Sheet("5", 380),
new Sheet("6", 459));
// List<Sheet> sheets =
// List.of(
// new Sheet("1", 261),
// new Sheet("2", 500),
// new Sheet("3", 350),
// new Sheet("4", 250),
// new Sheet("5", 380),
// new Sheet("6", 459));
// 사용자별 할당 입력한 값
// List<TargetUser> targets =
// List.of(new TargetUser("A", 1000), new TargetUser("B", 500), new TargetUser("C", 700));
// LabelAllocateService.allocateSheetCount(new ArrayList<>(sheets), new
// ArrayList<>(targets));
// targets.forEach(
// t -> {
// log.info("[" + t.getUserId() + "]");
// t.getAssigned()
// .forEach(
// u -> {
// log.info(" - 도엽: " + u.getSheetId() + " (" + u.getCount() + ")");
// });
// });
List<TargetUser> targets =
List.of(new TargetUser("A", 1000), new TargetUser("B", 500), new TargetUser("C", 700));
LabelAllocateService.allocate(new ArrayList<>(sheets), new ArrayList<>(targets));
targets.forEach(
t -> {
log.info("[" + t.getUserId() + "]");
t.getAssigned()
.forEach(
u -> {
log.info(" - 도엽: " + u.getSheetId() + " (" + u.getCount() + ")");
});
});
/**
* [A] 입력한 수 : 1000 - 도엽: 2 (500) - 도엽: 6 (459) - 도엽: 5 (41)
*
* <p>[B] 입력한 수 : 500 - 도엽: 5 (339) - 도엽: 3 (161)
*
* <p>[C] 입력한 수 : 700 - 도엽: 3 (189) - 도엽: 1 (261) - 도엽: 4 (250)
*/
// A 에게 도엽 2 asc 해서 500건 할당 -> 도엽 6 asc 해서 459 할당 -> 도엽 5 asc 해서 41건 할당 -> insert
// B 에게 도엽 5 위에 41건 할당한 것 빼고 asc 해서 339건 할당 -> 도엽 3 asc 해서 161건 할당 -> insert
// .... for문에서 할당한 것 빼고 asc 해서 건수만큼 할당 insert 하고 다음 으로 넘어가기
List.of(new TargetUser("1", 1000), new TargetUser("2", 400), new TargetUser("3", 440));
labelAllocateService.allocateAsc(targets);
return ApiResponseDto.ok(null);
}