라벨 자동할당 로직 임시 커밋

This commit is contained in:
2025-12-31 09:10:11 +09:00
parent ff2c54d38e
commit 0f7dda261b
3 changed files with 214 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
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;
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.RestController;
@Slf4j
@Tag(name = "라벨링 작업 관리", description = "라벨링 작업 관리")
@RequestMapping({"/api/label/mng"})
@RequiredArgsConstructor
@RestController
public class LabelAllocateApiController {
// 라벨링 수량 할당하는 로직 테스트
@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<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)
*
* [B] 입력한 수 : 500
* - 도엽: 5 (339)
* - 도엽: 3 (161)
*
* [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 하고 다음 으로 넘어가기
return ApiResponseDto.ok(null);
}
}