|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.baiye.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import com.baiye.constant.DefaultNumberConstants;
|
|
|
|
|
import com.baiye.http.CommonResponse;
|
|
|
|
@ -14,7 +15,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Enzo
|
|
|
|
@ -41,21 +44,28 @@ public class AssignDataService {
|
|
|
|
|
if (sum != DefaultNumberConstants.ONE_HUNDRED) {
|
|
|
|
|
return CommonResponse.createByErrorMessage(ResponseCode.DECRYPTION_FAILED.getDesc());
|
|
|
|
|
}
|
|
|
|
|
// 进行排序保证最大比例在后
|
|
|
|
|
Map<Long, Double> deptMap =
|
|
|
|
|
deptIds.stream().collect(Collectors.toMap(key -> key, key -> weights.get(deptIds.indexOf(key))));
|
|
|
|
|
Map<Long, Double> longDoubleMap = MapUtil.sortByValue(deptMap, Boolean.FALSE);
|
|
|
|
|
CopyOnWriteArrayList<String> value;
|
|
|
|
|
List<DistributeResponseDTO> list = new ArrayList<>();
|
|
|
|
|
DistributeResponseDTO distributeResponseDTO;
|
|
|
|
|
for (int i = DefaultNumberConstants.ZERO_NUMBER; i < deptIds.size(); i++) {
|
|
|
|
|
Double aDouble = weights.get(i);
|
|
|
|
|
int num = DefaultNumberConstants.ZERO_NUMBER;
|
|
|
|
|
for (Map.Entry<Long, Double> longDoubleEntry : longDoubleMap.entrySet()) {
|
|
|
|
|
Long key = longDoubleEntry.getKey();
|
|
|
|
|
Double aDouble = longDoubleEntry.getValue();
|
|
|
|
|
distributeResponseDTO = new DistributeResponseDTO();
|
|
|
|
|
if (size - DefaultNumberConstants.ONE_NUMBER > i) {
|
|
|
|
|
if (size - DefaultNumberConstants.ONE_NUMBER > num) {
|
|
|
|
|
num++;
|
|
|
|
|
double div = NumberUtil.div(aDouble,
|
|
|
|
|
Double.valueOf(DefaultNumberConstants.ONE_HUNDRED), DefaultNumberConstants.TWO_HUNDRED);
|
|
|
|
|
int count = (int) Math.floor(NumberUtil.mul(resourceSize, div));
|
|
|
|
|
if (count == DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
int middle = (int) Math.floor(copyOnWriteArrayList.size() / 2);
|
|
|
|
|
int middle = copyOnWriteArrayList.size() / DefaultNumberConstants.TWO_NUMBER;
|
|
|
|
|
value = Lists.newCopyOnWriteArrayList(Lists.newArrayList(copyOnWriteArrayList.get(middle)));
|
|
|
|
|
distributeResponseDTO.setResponseList(value);
|
|
|
|
|
distributeResponseDTO.setDeptId(deptIds.get(i));
|
|
|
|
|
distributeResponseDTO.setDeptId(key);
|
|
|
|
|
list.add(distributeResponseDTO);
|
|
|
|
|
copyOnWriteArrayList.remove(middle);
|
|
|
|
|
continue;
|
|
|
|
@ -63,13 +73,13 @@ public class AssignDataService {
|
|
|
|
|
value = Lists.newCopyOnWriteArrayList
|
|
|
|
|
(copyOnWriteArrayList.subList(DefaultNumberConstants.ZERO_NUMBER, count));
|
|
|
|
|
distributeResponseDTO.setResponseList(value);
|
|
|
|
|
distributeResponseDTO.setDeptId(deptIds.get(i));
|
|
|
|
|
distributeResponseDTO.setDeptId(key);
|
|
|
|
|
list.add(distributeResponseDTO);
|
|
|
|
|
copyOnWriteArrayList.removeAll(value);
|
|
|
|
|
} else {
|
|
|
|
|
value = Lists.newCopyOnWriteArrayList(Lists.newArrayList(copyOnWriteArrayList));
|
|
|
|
|
distributeResponseDTO.setResponseList(value);
|
|
|
|
|
distributeResponseDTO.setDeptId(deptIds.get(i));
|
|
|
|
|
distributeResponseDTO.setDeptId(longDoubleEntry.getKey());
|
|
|
|
|
list.add(distributeResponseDTO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|