라벨 자동할당 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,6 +2,8 @@ package com.kamco.cd.kamcoback.label.service;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.Sheet;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.TargetUser;
import com.kamco.cd.kamcoback.postgres.core.LabelAllocateCoreService;
import jakarta.transaction.Transactional;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@@ -12,7 +14,19 @@ import org.springframework.stereotype.Service;
@Service
public class LabelAllocateService {
public static void allocate(List<Sheet> sheets, List<TargetUser> targetUsers) {
private final LabelAllocateCoreService labelAllocateCoreService;
public LabelAllocateService(LabelAllocateCoreService labelAllocateCoreService) {
this.labelAllocateCoreService = labelAllocateCoreService;
}
/**
* 도엽 count 수와 할당된 count 수를 비교해서 많은 수부터 먼저 배정하고 나머지를 분배 배정하는 로직
*
* @param sheets
* @param targetUsers
*/
public static void allocateSheetCount(List<Sheet> sheets, List<TargetUser> targetUsers) {
// 1⃣ 실제 도엽 기준 할당
allocateSheets(sheets, targetUsers);
@@ -75,4 +89,34 @@ public class LabelAllocateService {
t.setShortage(share);
}
}
/**
* 도엽 기준 asc sorting 해서 할당 수만큼 배정하는 로직
*
* @param targetUsers
*/
@Transactional
public void allocateAsc(List<TargetUser> targetUsers) {
Long lastId = null;
for (TargetUser target : targetUsers) {
int remaining = target.getDemand();
while (remaining > 0) {
int batchSize = Math.min(remaining, 500);
List<Long> ids = labelAllocateCoreService.fetchNextIds(lastId, batchSize);
if (ids.isEmpty()) {
return; // 더이상 할당할 데이터가 없으면 return
}
labelAllocateCoreService.assignOwner(
ids, Long.valueOf(target.getUserId())); // TODO : userId를 숫자값을 가져올지 사번을 가져올지 고민
remaining -= ids.size();
lastId = ids.get(ids.size() - 1);
}
}
}
}